From b6f4d53126d3f0ad522df5fc77da4ac919ea43f6 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Fri, 13 Nov 2020 02:11:12 +0000 Subject: [PATCH] Only Increment Serials When Necessary On D3D12 Only increments last submitted and last completed serials from the D3D12 backend when commands were submitted to the GPU. Bug: dawn:119 Change-Id: I01748b7f4ac90443adac4cdef29016184f992e9c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/32162 Commit-Queue: Brandon Jones Reviewed-by: Corentin Wallez --- src/dawn_native/Device.h | 4 ++-- src/dawn_native/d3d12/DeviceD3D12.cpp | 15 ++++++++++++--- src/tests/white_box/D3D12DescriptorHeapTests.cpp | 11 ++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/dawn_native/Device.h b/src/dawn_native/Device.h index ee73000608..6408a90a97 100644 --- a/src/dawn_native/Device.h +++ b/src/dawn_native/Device.h @@ -238,6 +238,8 @@ namespace dawn_native { // still check if we have pending work to take care of, rather than hanging and never // reaching the serial the work will be executed on. void AddFutureSerial(ExecutionSerial serial); + // Check for passed fences and set the new completed serial + void CheckPassedSerials(); virtual uint32_t GetOptimalBytesPerRowAlignment() const = 0; virtual uint64_t GetOptimalBufferToTextureCopyOffsetAlignment() const = 0; @@ -251,8 +253,6 @@ namespace dawn_native { // Incrememt mLastSubmittedSerial when we submit the next serial void IncrementLastSubmittedCommandSerial(); - // Check for passed fences and set the new completed serial - void CheckPassedSerials(); private: virtual ResultOrError CreateBindGroupImpl( diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index 3b2689d01a..753d5779dd 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -228,8 +228,11 @@ namespace dawn_native { namespace d3d12 { mRenderTargetViewAllocator->Tick(completedSerial); mDepthStencilViewAllocator->Tick(completedSerial); mUsedComObjectRefs.ClearUpTo(completedSerial); - DAWN_TRY(ExecutePendingCommandContext()); - DAWN_TRY(NextSerial()); + + if (mPendingCommands.IsOpen()) { + DAWN_TRY(ExecutePendingCommandContext()); + DAWN_TRY(NextSerial()); + } DAWN_TRY(CheckDebugLayerAndGenerateErrors()); @@ -256,7 +259,13 @@ namespace dawn_native { namespace d3d12 { } ExecutionSerial Device::CheckAndUpdateCompletedSerials() { - return ExecutionSerial(mFence->GetCompletedValue()); + ExecutionSerial completeSerial = ExecutionSerial(mFence->GetCompletedValue()); + + if (completeSerial <= GetCompletedCommandSerial()) { + return ExecutionSerial(0); + } + + return completeSerial; } void Device::ReferenceUntilUnused(ComPtr object) { diff --git a/src/tests/white_box/D3D12DescriptorHeapTests.cpp b/src/tests/white_box/D3D12DescriptorHeapTests.cpp index 341ca3f45a..b9bc8f723b 100644 --- a/src/tests/white_box/D3D12DescriptorHeapTests.cpp +++ b/src/tests/white_box/D3D12DescriptorHeapTests.cpp @@ -14,6 +14,7 @@ #include "tests/DawnTest.h" +#include "dawn_native/Device.h" #include "dawn_native/Toggles.h" #include "dawn_native/d3d12/BindGroupLayoutD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h" @@ -230,13 +231,16 @@ TEST_P(D3D12DescriptorHeapTests, PoolHeapsInMultipleSubmits) { EXPECT_EQ(allocator->GetShaderVisiblePoolSizeForTesting(), 0u); - // Allocate + Tick() up to |kFrameDepth| and ensure heaps are always unique. + // Allocate + increment internal serials up to |kFrameDepth| and ensure heaps are always unique. for (uint32_t i = 0; i < kFrameDepth; i++) { EXPECT_TRUE(allocator->AllocateAndSwitchShaderVisibleHeap().IsSuccess()); ComPtr heap = allocator->GetShaderVisibleHeap(); EXPECT_TRUE(std::find(heaps.begin(), heaps.end(), heap) == heaps.end()); heaps.push_back(heap); - mD3DDevice->Tick(); + // CheckPassedSerials() will update the last internally completed serial. + mD3DDevice->CheckPassedSerials(); + // NextSerial() will increment the last internally submitted serial. + EXPECT_TRUE(mD3DDevice->NextSerial().IsSuccess()); } // Repeat up to |kFrameDepth| again but ensure heaps are the same in the expected order @@ -247,7 +251,8 @@ TEST_P(D3D12DescriptorHeapTests, PoolHeapsInMultipleSubmits) { ComPtr heap = allocator->GetShaderVisibleHeap(); EXPECT_TRUE(heaps.front() == heap); heaps.pop_front(); - mD3DDevice->Tick(); + mD3DDevice->CheckPassedSerials(); + EXPECT_TRUE(mD3DDevice->NextSerial().IsSuccess()); } EXPECT_TRUE(heaps.empty());