Skip to content

Commit 61dc7ec

Browse files
committed
Exit early when importing a resource without allocation.
1 parent b265749 commit 61dc7ec

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

include/gpgmm_d3d12.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,11 +1113,11 @@ namespace gpgmm::d3d12 {
11131113
const D3D12_CLEAR_VALUE* pClearValue,
11141114
IResourceAllocation** ppResourceAllocationOut) = 0;
11151115

1116-
/** \brief Imports an existing D3D12 resource.
1116+
/** \brief Use existing D3D12 resource as a resource allocation.
11171117
1118-
Allows externally created D3D12 resources to be used as a ResourceAllocation.
1118+
Returns a ResourceAllocation which represents an existing resource with a resource heap.
11191119
1120-
@param allocationDescriptor A reference to ALLOCATION_DESC structure that provides
1120+
@param allocationDescriptor A reference to ALLOCATION_DESC structure that provides.
11211121
properties for the resource allocation.
11221122
@param pCommittedResource A pointer to a committed ID3D12Resource.
11231123
@param[out] ppResourceAllocationOut Pointer to a memory block that receives a pointer to the

src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,11 @@ namespace gpgmm::d3d12 {
13051305
return E_INVALIDARG;
13061306
}
13071307

1308+
// If no resource allocation is to be created then only validate by returning early.
1309+
if (ppResourceAllocationOut == nullptr) {
1310+
return S_FALSE;
1311+
}
1312+
13081313
HEAP_DESC resourceHeapDesc = {};
13091314
resourceHeapDesc.SizeInBytes = resourceInfo.SizeInBytes;
13101315
resourceHeapDesc.Alignment = resourceInfo.Alignment;
@@ -1328,13 +1333,10 @@ namespace gpgmm::d3d12 {
13281333
allocationDesc.HeapOffset = kInvalidSize;
13291334
allocationDesc.SizeInBytes = allocationSize;
13301335
allocationDesc.Method = AllocationMethod::kStandalone;
1331-
allocationDesc.OffsetFromResource = 0;
13321336

1333-
if (ppResourceAllocationOut != nullptr) {
1334-
*ppResourceAllocationOut = new ResourceAllocation(
1335-
allocationDesc, nullptr, this, static_cast<Heap*>(resourceHeap.Detach()), nullptr,
1336-
std::move(resource));
1337-
}
1337+
*ppResourceAllocationOut = new ResourceAllocation(allocationDesc, nullptr, this,
1338+
static_cast<Heap*>(resourceHeap.Detach()),
1339+
nullptr, std::move(resource));
13381340

13391341
return S_OK;
13401342
}

0 commit comments

Comments
 (0)