diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 650348705..6e8a4b5ed 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -882,6 +882,8 @@ namespace gpgmm::d3d12 { ReturnIfFailed(CreateResourceInternal(allocationDescriptor, resourceDescriptor, initialResourceState, pClearValue, &allocation)); + ASSERT(allocation->GetResource() != nullptr); + if (GPGMM_UNLIKELY(mDebugAllocator)) { ReturnIfFailed(allocation->SetDebugName(allocationDescriptor.DebugName)); mDebugAllocator->AddLiveAllocation(static_cast(allocation.Get())); @@ -1331,16 +1333,18 @@ namespace gpgmm::d3d12 { // Since residency is per heap, every committed resource is wrapped in a heap object. ComPtr resourceHeap; - ComPtr committedResource; - CreateCommittedResourceCallbackContext callbackContext( - mDevice.Get(), committedResource, &heapProperties, heapFlags, resourceDescriptor, - clearValue, initialResourceState); + CreateCommittedResourceCallbackContext callbackContext(mDevice.Get(), &heapProperties, + heapFlags, resourceDescriptor, + clearValue, initialResourceState); ReturnIfFailed(Heap::CreateHeap(resourceHeapDesc, mResidencyManager.Get(), CreateCommittedResourceCallbackContext::CreateHeap, &callbackContext, &resourceHeap)); if (commitedResourceOut != nullptr) { + ComPtr committedResource; + ReturnIfFailed(resourceHeap.As(&committedResource)); + *commitedResourceOut = committedResource.Detach(); } @@ -1501,7 +1505,6 @@ namespace gpgmm::d3d12 { CreateCommittedResourceCallbackContext::CreateCommittedResourceCallbackContext( ID3D12Device* device, - ComPtr resource, D3D12_HEAP_PROPERTIES* heapProperties, D3D12_HEAP_FLAGS heapFlags, const D3D12_RESOURCE_DESC* resourceDescriptor, @@ -1512,7 +1515,6 @@ namespace gpgmm::d3d12 { mInitialResourceState(initialResourceState), mHeapFlags(heapFlags), mHeapProperties(heapProperties), - mResource(resource), mResourceDescriptor(resourceDescriptor) { } @@ -1537,13 +1539,12 @@ namespace gpgmm::d3d12 { mHeapProperties->MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN; } - ReturnIfFailed(mDevice->CreateCommittedResource(mHeapProperties, mHeapFlags, - mResourceDescriptor, mInitialResourceState, - mClearValue, IID_PPV_ARGS(&mResource))); + ComPtr committedResource; + ReturnIfFailed(mDevice->CreateCommittedResource( + mHeapProperties, mHeapFlags, mResourceDescriptor, mInitialResourceState, mClearValue, + IID_PPV_ARGS(&committedResource))); - ComPtr pageable; - ReturnIfFailed(mResource.As(&pageable)); - *ppPageableOut = pageable.Detach(); + *ppPageableOut = committedResource.Detach(); return S_OK; } diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index b7b939628..23024d0f1 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -49,7 +49,6 @@ namespace gpgmm::d3d12 { class CreateCommittedResourceCallbackContext { public: CreateCommittedResourceCallbackContext(ID3D12Device* device, - ComPtr resource, D3D12_HEAP_PROPERTIES* heapProperties, D3D12_HEAP_FLAGS heapFlags, const D3D12_RESOURCE_DESC* resourceDescriptor, @@ -66,7 +65,6 @@ namespace gpgmm::d3d12 { D3D12_RESOURCE_STATES mInitialResourceState; D3D12_HEAP_FLAGS mHeapFlags; D3D12_HEAP_PROPERTIES* mHeapProperties; - ComPtr mResource; const D3D12_RESOURCE_DESC* mResourceDescriptor; }; diff --git a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp index 9de329d2a..e6dd16c8a 100644 --- a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp +++ b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp @@ -889,6 +889,15 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAlwaysCommitted) { ComPtr resourceHeap = allocation->GetMemory(); ASSERT_NE(resourceHeap, nullptr); + EXPECT_NE(allocation->GetResource(), nullptr); + + ComPtr resourceAsPageable; + ASSERT_SUCCEEDED(allocation->GetResource()->QueryInterface(IID_PPV_ARGS(&resourceAsPageable))); + + ComPtr implicitHeap; + ASSERT_SUCCEEDED(resourceHeap.As(&implicitHeap)); + EXPECT_EQ(resourceAsPageable, implicitHeap); + ComPtr heap; ASSERT_FAILED(resourceHeap.As(&heap));