From d97daae85e338c1dbd6dc086d4111fb87dd0deb7 Mon Sep 17 00:00:00 2001 From: Bryan Bernhart Date: Wed, 14 Sep 2022 16:49:57 -0700 Subject: [PATCH] Disable sub-allocation within with resource flags. --- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 3 ++- src/tests/end2end/D3D12ResourceAllocatorTests.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index d1b21f6d8..b3c9ca1c2 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -971,7 +971,8 @@ namespace gpgmm::d3d12 { if (allocationDescriptor.Flags & ALLOCATION_FLAG_ALLOW_SUBALLOCATE_WITHIN_RESOURCE && resourceInfo.Alignment > newResourceDesc.Width && newResourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER && - isCreatedResourceStateRequired && !neverSubAllocate) { + newResourceDesc.Flags == D3D12_RESOURCE_FLAG_NONE && isCreatedResourceStateRequired && + !neverSubAllocate) { allocator = mSmallBufferAllocatorOfType[static_cast(resourceHeapType)].get(); // GetResourceAllocationInfo() always rejects alignments smaller than 64KB. So if the diff --git a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp index 8c2aa6e27..cb6391842 100644 --- a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp +++ b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp @@ -887,6 +887,18 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { D3D12_RESOURCE_STATE_COMMON, nullptr, &smallBuffer)); EXPECT_NE(smallBuffer->GetMethod(), gpgmm::AllocationMethod::kSubAllocatedWithin); } + + // Resource flags are not allowed. + { + D3D12_RESOURCE_DESC resourceDescWithFlags = CreateBasicBufferDesc(3u); + resourceDescWithFlags.Flags = D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE; + + ComPtr smallBuffer; + ASSERT_SUCCEEDED(resourceAllocator->CreateResource( + baseAllocationDesc, resourceDescWithFlags, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, + &smallBuffer)); + EXPECT_NE(smallBuffer->GetMethod(), gpgmm::AllocationMethod::kSubAllocatedWithin); + } } TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinMany) {