diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index 616041cc0..971bae424 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -241,7 +241,7 @@ namespace gpgmm::d3d12 { // If the heap was never locked, nothing further should be done. if (!heap->IsResidencyLocked()) { - return S_FALSE; + return S_OK; } if (heap->IsInList()) { diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp index 43b2ce023..161081dbf 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp @@ -74,8 +74,8 @@ namespace gpgmm::d3d12 { // If the developer forgots to unlock the heap, do so now so the heap can be made eligable // for eviction. ResidencyHeap* residencyHeap = static_cast(GetMemory()); - if (residencyHeap->GetResidencyManager() != nullptr) { - residencyHeap->Unlock(); + if (residencyHeap->GetResidencyManager() != nullptr && + GPGMM_UNSUCCESSFUL(residencyHeap->Unlock())) { WarnLog(MessageId::kPerformanceWarning, this) << "Destroying a locked resource allocation is allowed but discouraged. Please " "call UnlockHeap the same number of times as LockHeap before releasing the " diff --git a/src/tests/end2end/D3D12ResidencyManagerTests.cpp b/src/tests/end2end/D3D12ResidencyManagerTests.cpp index ed33fdb06..b9f812d75 100644 --- a/src/tests/end2end/D3D12ResidencyManagerTests.cpp +++ b/src/tests/end2end/D3D12ResidencyManagerTests.cpp @@ -202,6 +202,16 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeapLocked) { ASSERT_FAILED(CreateResidencyHeap(lockedResidencyHeapDesc, nullptr, CreateResourceHeapCallbackContext::CreateHeap, &createHeapContext, nullptr)); + + ASSERT_SUCCEEDED(residencyManager->LockHeap(resourceHeap.Get())); + + // Unlocking a heap with another lock must return S_FALSE. + EXPECT_EQ(residencyManager->UnlockHeap(resourceHeap.Get()), S_FALSE); + EXPECT_TRUE(resourceHeap->GetInfo().IsLocked); + + // But unlocking the last lock must return S_OK. + EXPECT_EQ(residencyManager->UnlockHeap(resourceHeap.Get()), S_OK); + EXPECT_FALSE(resourceHeap->GetInfo().IsLocked); } TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) {