From dfaeb429f8f52ba2351d5fe1a181453167bec2e5 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Wed, 10 May 2023 18:51:52 +0000 Subject: [PATCH] Add test for D3D12 descriptor heap allocation lifetimes Adds a white box test to ensure that D3D12 descriptor heap allocations only are valid during the serial they are created on. Bug: dawn:1701 Change-Id: I1e1587ab602d5472fbba9e751bf3cd1e6e5ead11 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132266 Kokoro: Kokoro Reviewed-by: Austin Eng Commit-Queue: Brandon1 Jones Reviewed-by: Corentin Wallez --- .../white_box/D3D12DescriptorHeapTests.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/dawn/tests/white_box/D3D12DescriptorHeapTests.cpp b/src/dawn/tests/white_box/D3D12DescriptorHeapTests.cpp index a2ea860727..75e9d10fc5 100644 --- a/src/dawn/tests/white_box/D3D12DescriptorHeapTests.cpp +++ b/src/dawn/tests/white_box/D3D12DescriptorHeapTests.cpp @@ -1043,6 +1043,26 @@ TEST_P(D3D12DescriptorHeapTests, AllocateDeallocateMany) { } } +// Verifies that gpu descriptor heap allocations are only valid during the serial they were created +// on. +TEST_P(D3D12DescriptorHeapTests, InvalidateAllocationAfterSerial) { + Device* d3dDevice = reinterpret_cast(device.Get()); + ShaderVisibleDescriptorAllocator* gpuAllocator = + d3dDevice->GetViewShaderVisibleDescriptorAllocator(); + + GPUDescriptorHeapAllocation gpuHeapDescAllocation; + + D3D12_CPU_DESCRIPTOR_HANDLE baseCPUDescriptor; + gpuAllocator->AllocateGPUDescriptors(1, d3dDevice->GetPendingCommandSerial(), + &baseCPUDescriptor, &gpuHeapDescAllocation); + + EXPECT_TRUE(gpuAllocator->IsAllocationStillValid(gpuHeapDescAllocation)); + + EXPECT_TRUE(d3dDevice->NextSerial().IsSuccess()); + + EXPECT_FALSE(gpuAllocator->IsAllocationStillValid(gpuHeapDescAllocation)); +} + DAWN_INSTANTIATE_TEST(D3D12DescriptorHeapTests, D3D12Backend(), D3D12Backend({"use_d3d12_small_shader_visible_heap"}));