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 {}; }