From 85e6337027b82c5aefdca1cdefe897db6728df66 Mon Sep 17 00:00:00 2001 From: Sunny Sachanandani Date: Fri, 23 Sep 2022 00:52:56 +0000 Subject: [PATCH] d3d12: Move NextSerial out of ExecuteCommandList Reverts to the code flow before fences were implemented. NextSerial is now the reponsibility of the caller of ExecutePendingCommandContext like it was before. We now use GetPendingCommandSerial to store the signal fence value instead of GetLastSubmittedCommandSerial and check that the signal fence value was submitted in EndAccess. Bug: dawn:576 Change-Id: I616840a0932ec17f77fcab38058773006dfae32f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/103501 Commit-Queue: Sunny Sachanandani Auto-Submit: Sunny Sachanandani Reviewed-by: Austin Eng Kokoro: Kokoro --- src/dawn/native/d3d12/CommandRecordingContext.cpp | 2 -- src/dawn/native/d3d12/DeviceD3D12.cpp | 2 +- src/dawn/native/d3d12/DeviceD3D12.h | 1 - src/dawn/native/d3d12/TextureD3D12.cpp | 12 ++++++------ 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/dawn/native/d3d12/CommandRecordingContext.cpp b/src/dawn/native/d3d12/CommandRecordingContext.cpp index 7c9cf0e73b..cd44e4aed1 100644 --- a/src/dawn/native/d3d12/CommandRecordingContext.cpp +++ b/src/dawn/native/d3d12/CommandRecordingContext.cpp @@ -123,8 +123,6 @@ MaybeError CommandRecordingContext::ExecuteCommandList(Device* device) { ID3D12CommandList* d3d12CommandList = GetCommandList(); device->GetCommandQueue()->ExecuteCommandLists(1, &d3d12CommandList); - DAWN_TRY(device->NextSerial()); - for (Texture* texture : mSharedTextures) { DAWN_TRY(texture->SynchronizeImportedTextureAfterUse()); } diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp index 9bfb03e9cf..9aa1627857 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.cpp +++ b/src/dawn/native/d3d12/DeviceD3D12.cpp @@ -338,8 +338,8 @@ MaybeError Device::TickImpl() { mUsedComObjectRefs.ClearUpTo(completedSerial); if (mPendingCommands.IsOpen()) { - // CommandRecordingContext::ExecuteCommandList() calls NextSerial(). DAWN_TRY(ExecutePendingCommandContext()); + DAWN_TRY(NextSerial()); } DAWN_TRY(CheckDebugLayerAndGenerateErrors()); diff --git a/src/dawn/native/d3d12/DeviceD3D12.h b/src/dawn/native/d3d12/DeviceD3D12.h index 6b56d1a59f..d122fd1582 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.h +++ b/src/dawn/native/d3d12/DeviceD3D12.h @@ -91,7 +91,6 @@ class Device final : public DeviceBase { void ReferenceUntilUnused(ComPtr object); - // Execute pending CommandRecordingContext, and increment last submitted serial if needed. MaybeError ExecutePendingCommandContext(); ResultOrError> CreateStagingBuffer(size_t size) override; diff --git a/src/dawn/native/d3d12/TextureD3D12.cpp b/src/dawn/native/d3d12/TextureD3D12.cpp index 02588c2259..f17e995cdb 100644 --- a/src/dawn/native/d3d12/TextureD3D12.cpp +++ b/src/dawn/native/d3d12/TextureD3D12.cpp @@ -691,19 +691,19 @@ ResultOrError Texture::EndAccess() { // Needed to ensure that command allocator doesn't get destroyed before pending commands // are submitted due to calling NextSerial(). No-op if there are no pending commands. DAWN_TRY(ToBackend(GetDevice())->ExecutePendingCommandContext()); - // If there were pending commands that used this texture mSignalFenceValue will be set, // but if it's still not set, generate a signal fence after waiting on wait fences. if (!mSignalFenceValue.has_value()) { DAWN_TRY(SynchronizeImportedTextureBeforeUse()); - DAWN_TRY(ToBackend(GetDevice())->NextSerial()); DAWN_TRY(SynchronizeImportedTextureAfterUse()); - ASSERT(mSignalFenceValue.has_value()); } + DAWN_TRY(ToBackend(GetDevice())->NextSerial()); + ASSERT(mSignalFenceValue.has_value()); } - // Explicitly call reset() since std::move() on optional doesn't make it std::nullopt. ExecutionSerial ret = mSignalFenceValue.value(); + ASSERT(ret <= GetDevice()->GetLastSubmittedCommandSerial()); + // Explicitly call reset() since std::move() on optional doesn't make it std::nullopt. mSignalFenceValue.reset(); return ret; } @@ -760,8 +760,8 @@ MaybeError Texture::SynchronizeImportedTextureAfterUse() { if (mD3D11on12Resource != nullptr) { DAWN_TRY(mD3D11on12Resource->ReleaseKeyedMutex()); } else { - // CommandRecordingContext will call NextSerial() to increment the fence before this call. - mSignalFenceValue = ToBackend(GetDevice())->GetLastSubmittedCommandSerial(); + // NextSerial() will be called after this - this is also checked in EndAccess(). + mSignalFenceValue = ToBackend(GetDevice())->GetPendingCommandSerial(); } return {}; }