From 61dc7ec2fd185ff3136d00ab7cf5627c62b9886c Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Fri, 27 Jan 2023 11:12:24 -0800 Subject: [PATCH] Exit early when importing a resource without allocation. --- include/gpgmm_d3d12.h | 6 +++--- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/gpgmm_d3d12.h b/include/gpgmm_d3d12.h index f2f90ff2a..5ddb2648a 100644 --- a/include/gpgmm_d3d12.h +++ b/include/gpgmm_d3d12.h @@ -1113,11 +1113,11 @@ namespace gpgmm::d3d12 { const D3D12_CLEAR_VALUE* pClearValue, IResourceAllocation** ppResourceAllocationOut) = 0; - /** \brief Imports an existing D3D12 resource. + /** \brief Use existing D3D12 resource as a resource allocation. - Allows externally created D3D12 resources to be used as a ResourceAllocation. + Returns a ResourceAllocation which represents an existing resource with a resource heap. - @param allocationDescriptor A reference to ALLOCATION_DESC structure that provides + @param allocationDescriptor A reference to ALLOCATION_DESC structure that provides. properties for the resource allocation. @param pCommittedResource A pointer to a committed ID3D12Resource. @param[out] ppResourceAllocationOut Pointer to a memory block that receives a pointer to the diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 2d4eaf446..80c3a0e5f 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -1305,6 +1305,11 @@ namespace gpgmm::d3d12 { return E_INVALIDARG; } + // If no resource allocation is to be created then only validate by returning early. + if (ppResourceAllocationOut == nullptr) { + return S_FALSE; + } + HEAP_DESC resourceHeapDesc = {}; resourceHeapDesc.SizeInBytes = resourceInfo.SizeInBytes; resourceHeapDesc.Alignment = resourceInfo.Alignment; @@ -1328,13 +1333,10 @@ namespace gpgmm::d3d12 { allocationDesc.HeapOffset = kInvalidSize; allocationDesc.SizeInBytes = allocationSize; allocationDesc.Method = AllocationMethod::kStandalone; - allocationDesc.OffsetFromResource = 0; - if (ppResourceAllocationOut != nullptr) { - *ppResourceAllocationOut = new ResourceAllocation( - allocationDesc, nullptr, this, static_cast(resourceHeap.Detach()), nullptr, - std::move(resource)); - } + *ppResourceAllocationOut = new ResourceAllocation(allocationDesc, nullptr, this, + static_cast(resourceHeap.Detach()), + nullptr, std::move(resource)); return S_OK; }