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 <brandon1.jones@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn_native/Device.h b/src/dawn_native/Device.h
index ee73000..6408a90 100644
--- a/src/dawn_native/Device.h
+++ b/src/dawn_native/Device.h
@@ -238,6 +238,8 @@
// 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 @@
// 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<BindGroupBase*> CreateBindGroupImpl(
diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp
index 3b2689d..753d577 100644
--- a/src/dawn_native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn_native/d3d12/DeviceD3D12.cpp
@@ -228,8 +228,11 @@
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 @@
}
ExecutionSerial Device::CheckAndUpdateCompletedSerials() {
- return ExecutionSerial(mFence->GetCompletedValue());
+ ExecutionSerial completeSerial = ExecutionSerial(mFence->GetCompletedValue());
+
+ if (completeSerial <= GetCompletedCommandSerial()) {
+ return ExecutionSerial(0);
+ }
+
+ return completeSerial;
}
void Device::ReferenceUntilUnused(ComPtr<IUnknown> object) {
diff --git a/src/tests/white_box/D3D12DescriptorHeapTests.cpp b/src/tests/white_box/D3D12DescriptorHeapTests.cpp
index 341ca3f..b9bc8f7 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 @@
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<ID3D12DescriptorHeap> 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 @@
ComPtr<ID3D12DescriptorHeap> heap = allocator->GetShaderVisibleHeap();
EXPECT_TRUE(heaps.front() == heap);
heaps.pop_front();
- mD3DDevice->Tick();
+ mD3DDevice->CheckPassedSerials();
+ EXPECT_TRUE(mD3DDevice->NextSerial().IsSuccess());
}
EXPECT_TRUE(heaps.empty());