Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResourceAllocation*>(allocation.Get()));
Expand Down Expand Up @@ -1331,16 +1333,18 @@ namespace gpgmm::d3d12 {

// Since residency is per heap, every committed resource is wrapped in a heap object.
ComPtr<IHeap> resourceHeap;
ComPtr<ID3D12Resource> 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<ID3D12Resource> committedResource;
ReturnIfFailed(resourceHeap.As(&committedResource));

*commitedResourceOut = committedResource.Detach();
}

Expand Down Expand Up @@ -1501,7 +1505,6 @@ namespace gpgmm::d3d12 {

CreateCommittedResourceCallbackContext::CreateCommittedResourceCallbackContext(
ID3D12Device* device,
ComPtr<ID3D12Resource> resource,
D3D12_HEAP_PROPERTIES* heapProperties,
D3D12_HEAP_FLAGS heapFlags,
const D3D12_RESOURCE_DESC* resourceDescriptor,
Expand All @@ -1512,7 +1515,6 @@ namespace gpgmm::d3d12 {
mInitialResourceState(initialResourceState),
mHeapFlags(heapFlags),
mHeapProperties(heapProperties),
mResource(resource),
mResourceDescriptor(resourceDescriptor) {
}

Expand All @@ -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<ID3D12Resource> committedResource;
ReturnIfFailed(mDevice->CreateCommittedResource(
mHeapProperties, mHeapFlags, mResourceDescriptor, mInitialResourceState, mClearValue,
IID_PPV_ARGS(&committedResource)));

ComPtr<ID3D12Pageable> pageable;
ReturnIfFailed(mResource.As(&pageable));
*ppPageableOut = pageable.Detach();
*ppPageableOut = committedResource.Detach();
return S_OK;
}

Expand Down
2 changes: 0 additions & 2 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ namespace gpgmm::d3d12 {
class CreateCommittedResourceCallbackContext {
public:
CreateCommittedResourceCallbackContext(ID3D12Device* device,
ComPtr<ID3D12Resource> resource,
D3D12_HEAP_PROPERTIES* heapProperties,
D3D12_HEAP_FLAGS heapFlags,
const D3D12_RESOURCE_DESC* resourceDescriptor,
Expand All @@ -66,7 +65,6 @@ namespace gpgmm::d3d12 {
D3D12_RESOURCE_STATES mInitialResourceState;
D3D12_HEAP_FLAGS mHeapFlags;
D3D12_HEAP_PROPERTIES* mHeapProperties;
ComPtr<ID3D12Resource> mResource;
const D3D12_RESOURCE_DESC* mResourceDescriptor;
};

Expand Down
9 changes: 9 additions & 0 deletions src/tests/end2end/D3D12ResourceAllocatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,15 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAlwaysCommitted) {
ComPtr<IHeap> resourceHeap = allocation->GetMemory();
ASSERT_NE(resourceHeap, nullptr);

EXPECT_NE(allocation->GetResource(), nullptr);

ComPtr<ID3D12Pageable> resourceAsPageable;
ASSERT_SUCCEEDED(allocation->GetResource()->QueryInterface(IID_PPV_ARGS(&resourceAsPageable)));

ComPtr<ID3D12Pageable> implicitHeap;
ASSERT_SUCCEEDED(resourceHeap.As(&implicitHeap));
EXPECT_EQ(resourceAsPageable, implicitHeap);

ComPtr<ID3D12Heap> heap;
ASSERT_FAILED(resourceHeap.As(&heap));

Expand Down