[dawn][native] Splits WaitForIdleForDestruction into impl function. - Renames the existing WaitForIdleForDestruction function to WaitForIdleForDestructionImpl and implements the former in ExecutionQueue directly. This change is necessary for the follow up refactor change to handle callbacks in the case of waiting for idle. Bug: 430401631, 412761228 Change-Id: I57d29a1e54c1dbcd5bf8de5a7546449635453b26 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/256677 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Brandon Jones <bajones@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn/native/ExecutionQueue.cpp b/src/dawn/native/ExecutionQueue.cpp index 8fd9c29..695c756 100644 --- a/src/dawn/native/ExecutionQueue.cpp +++ b/src/dawn/native/ExecutionQueue.cpp
@@ -66,6 +66,10 @@ return true; } +MaybeError ExecutionQueueBase::WaitForIdleForDestruction() { + return WaitForIdleForDestructionImpl(); +} + MaybeError ExecutionQueueBase::CheckPassedSerials() { ExecutionSerial completedSerial; DAWN_TRY_ASSIGN(completedSerial, CheckAndUpdateCompletedSerials());
diff --git a/src/dawn/native/ExecutionQueue.h b/src/dawn/native/ExecutionQueue.h index b4e4915..720dd45 100644 --- a/src/dawn/native/ExecutionQueue.h +++ b/src/dawn/native/ExecutionQueue.h
@@ -85,11 +85,10 @@ // Increment mLastSubmittedSerial when we submit the next serial void IncrementLastSubmittedCommandSerial(); - // WaitForIdleForDestruction waits for GPU to finish, checks errors and gets ready for - // destruction. This is only used when properly destructing the device. For a real - // device loss, this function doesn't need to be called since the driver already closed all - // resources. - virtual MaybeError WaitForIdleForDestruction() = 0; + // Waits for GPU to finish, checks errors and gets ready for destruction. This is only used when + // properly destructing the device. For a real device loss, this function doesn't need to be + // called since the driver already closed all resources. + MaybeError WaitForIdleForDestruction(); // Wait at most `timeout` synchronously for the ExecutionSerial to pass. Returns true // if the serial passed. @@ -130,6 +129,9 @@ virtual ResultOrError<ExecutionSerial> WaitForQueueSerialImpl(ExecutionSerial waitSerial, Nanoseconds timeout) = 0; + // Backend specific wait for idle function. + virtual MaybeError WaitForIdleForDestructionImpl() = 0; + // mCompletedSerial tracks the last completed command serial that the fence has returned. // mLastSubmittedSerial tracks the last submitted command serial. // During device removal, the serials could be artificially incremented
diff --git a/src/dawn/native/Queue.cpp b/src/dawn/native/Queue.cpp index a23ba0c..0da902c 100644 --- a/src/dawn/native/Queue.cpp +++ b/src/dawn/native/Queue.cpp
@@ -117,7 +117,7 @@ Nanoseconds timeout) override { DAWN_UNREACHABLE(); } - MaybeError WaitForIdleForDestruction() override { DAWN_UNREACHABLE(); } + MaybeError WaitForIdleForDestructionImpl() override { DAWN_UNREACHABLE(); } }; } // namespace
diff --git a/src/dawn/native/d3d11/QueueD3D11.cpp b/src/dawn/native/d3d11/QueueD3D11.cpp index 70d9013..5c71f18 100644 --- a/src/dawn/native/d3d11/QueueD3D11.cpp +++ b/src/dawn/native/d3d11/QueueD3D11.cpp
@@ -394,7 +394,7 @@ void Queue::ForceEventualFlushOfCommands() {} -MaybeError Queue::WaitForIdleForDestruction() { +MaybeError Queue::WaitForIdleForDestructionImpl() { if (!mPendingCommands->IsValid()) { return {}; }
diff --git a/src/dawn/native/d3d11/QueueD3D11.h b/src/dawn/native/d3d11/QueueD3D11.h index 42bddf3..6278cb5 100644 --- a/src/dawn/native/d3d11/QueueD3D11.h +++ b/src/dawn/native/d3d11/QueueD3D11.h
@@ -81,7 +81,7 @@ void DestroyImpl() override; bool HasPendingCommands() const override; void ForceEventualFlushOfCommands() override; - MaybeError WaitForIdleForDestruction() override; + MaybeError WaitForIdleForDestructionImpl() override; MaybeError SubmitPendingCommandsImpl() override; ResultOrError<ExecutionSerial> CheckAndUpdateCompletedSerials() override;
diff --git a/src/dawn/native/d3d12/QueueD3D12.cpp b/src/dawn/native/d3d12/QueueD3D12.cpp index c52f132..7c5e60e 100644 --- a/src/dawn/native/d3d12/QueueD3D12.cpp +++ b/src/dawn/native/d3d12/QueueD3D12.cpp
@@ -197,7 +197,7 @@ mPendingCommands.SetNeedsSubmit(); } -MaybeError Queue::WaitForIdleForDestruction() { +MaybeError Queue::WaitForIdleForDestructionImpl() { // Immediately forget about all pending commands mPendingCommands.Release();
diff --git a/src/dawn/native/d3d12/QueueD3D12.h b/src/dawn/native/d3d12/QueueD3D12.h index 261180d..b6cc747 100644 --- a/src/dawn/native/d3d12/QueueD3D12.h +++ b/src/dawn/native/d3d12/QueueD3D12.h
@@ -67,7 +67,7 @@ bool HasPendingCommands() const override; ResultOrError<ExecutionSerial> CheckAndUpdateCompletedSerials() override; void ForceEventualFlushOfCommands() override; - MaybeError WaitForIdleForDestruction() override; + MaybeError WaitForIdleForDestructionImpl() override; void SetEventOnCompletion(ExecutionSerial serial, HANDLE event) override;
diff --git a/src/dawn/native/metal/QueueMTL.h b/src/dawn/native/metal/QueueMTL.h index 4b6c3f1..dc23bf1 100644 --- a/src/dawn/native/metal/QueueMTL.h +++ b/src/dawn/native/metal/QueueMTL.h
@@ -69,7 +69,7 @@ MaybeError SubmitPendingCommandsImpl() override; ResultOrError<ExecutionSerial> CheckAndUpdateCompletedSerials() override; void ForceEventualFlushOfCommands() override; - MaybeError WaitForIdleForDestruction() override; + MaybeError WaitForIdleForDestructionImpl() override; void DestroyImpl() override; NSPRef<id<MTLCommandQueue>> mCommandQueue;
diff --git a/src/dawn/native/metal/QueueMTL.mm b/src/dawn/native/metal/QueueMTL.mm index 3aec347..b0ae5d8 100644 --- a/src/dawn/native/metal/QueueMTL.mm +++ b/src/dawn/native/metal/QueueMTL.mm
@@ -121,7 +121,7 @@ }); } -MaybeError Queue::WaitForIdleForDestruction() { +MaybeError Queue::WaitForIdleForDestructionImpl() { // Forget all pending commands. mCommandContext.AcquireCommands(); DAWN_TRY(CheckPassedSerials());
diff --git a/src/dawn/native/null/DeviceNull.cpp b/src/dawn/native/null/DeviceNull.cpp index 1788326..c1232cd 100644 --- a/src/dawn/native/null/DeviceNull.cpp +++ b/src/dawn/native/null/DeviceNull.cpp
@@ -471,7 +471,7 @@ return waitSerial; } -MaybeError Queue::WaitForIdleForDestruction() { +MaybeError Queue::WaitForIdleForDestructionImpl() { ToBackend(GetDevice())->ForgetPendingOperations(); return {}; }
diff --git a/src/dawn/native/null/DeviceNull.h b/src/dawn/native/null/DeviceNull.h index 197f7b1..126514f 100644 --- a/src/dawn/native/null/DeviceNull.h +++ b/src/dawn/native/null/DeviceNull.h
@@ -302,7 +302,7 @@ MaybeError SubmitPendingCommandsImpl() override; ResultOrError<ExecutionSerial> WaitForQueueSerialImpl(ExecutionSerial waitSerial, Nanoseconds timeout) override; - MaybeError WaitForIdleForDestruction() override; + MaybeError WaitForIdleForDestructionImpl() override; }; class ComputePipeline final : public ComputePipelineBase {
diff --git a/src/dawn/native/opengl/QueueGL.cpp b/src/dawn/native/opengl/QueueGL.cpp index 2e60702..4ce31ac 100644 --- a/src/dawn/native/opengl/QueueGL.cpp +++ b/src/dawn/native/opengl/QueueGL.cpp
@@ -312,7 +312,7 @@ mHasPendingCommands = true; } -MaybeError Queue::WaitForIdleForDestruction() { +MaybeError Queue::WaitForIdleForDestructionImpl() { const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL(); DAWN_GL_TRY(gl, Finish()); DAWN_TRY(CheckPassedSerials());
diff --git a/src/dawn/native/opengl/QueueGL.h b/src/dawn/native/opengl/QueueGL.h index 793926d..6375d45 100644 --- a/src/dawn/native/opengl/QueueGL.h +++ b/src/dawn/native/opengl/QueueGL.h
@@ -73,7 +73,7 @@ MaybeError SubmitPendingCommandsImpl() override; ResultOrError<ExecutionSerial> CheckAndUpdateCompletedSerials() override; void ForceEventualFlushOfCommands() override; - MaybeError WaitForIdleForDestruction() override; + MaybeError WaitForIdleForDestructionImpl() override; uint32_t mEGLSyncType; MutexProtected<std::deque<std::pair<Ref<WrappedEGLSync>, ExecutionSerial>>> mFencesInFlight;
diff --git a/src/dawn/native/vulkan/QueueVk.cpp b/src/dawn/native/vulkan/QueueVk.cpp index 4ae3c0f..04abfde 100644 --- a/src/dawn/native/vulkan/QueueVk.cpp +++ b/src/dawn/native/vulkan/QueueVk.cpp
@@ -158,7 +158,7 @@ mRecordingContext.needsSubmit |= mRecordingContext.used; } -MaybeError Queue::WaitForIdleForDestruction() { +MaybeError Queue::WaitForIdleForDestructionImpl() { // Immediately tag the recording context as unused so we don't try to submit it in Tick. // Move the mRecordingContext.used to mUnusedCommands so it can be cleaned up in // ShutDownImpl
diff --git a/src/dawn/native/vulkan/QueueVk.h b/src/dawn/native/vulkan/QueueVk.h index 0e2618f..c537945 100644 --- a/src/dawn/native/vulkan/QueueVk.h +++ b/src/dawn/native/vulkan/QueueVk.h
@@ -68,7 +68,7 @@ bool HasPendingCommands() const override; ResultOrError<ExecutionSerial> CheckAndUpdateCompletedSerials() override; void ForceEventualFlushOfCommands() override; - MaybeError WaitForIdleForDestruction() override; + MaybeError WaitForIdleForDestructionImpl() override; MaybeError SubmitPendingCommandsImpl() override; void DestroyImpl() override;
diff --git a/src/dawn/native/webgpu/QueueWGPU.cpp b/src/dawn/native/webgpu/QueueWGPU.cpp index 12216b4..3b4ea6d 100644 --- a/src/dawn/native/webgpu/QueueWGPU.cpp +++ b/src/dawn/native/webgpu/QueueWGPU.cpp
@@ -177,7 +177,7 @@ }); } -MaybeError Queue::WaitForIdleForDestruction() { +MaybeError Queue::WaitForIdleForDestructionImpl() { auto& wgpu = ToBackend(GetDevice())->wgpu; mFuturesInFlight.Use([&](auto futuresInFlight) { while (!futuresInFlight->empty()) {
diff --git a/src/dawn/native/webgpu/QueueWGPU.h b/src/dawn/native/webgpu/QueueWGPU.h index 3d346d9..bf1bff9 100644 --- a/src/dawn/native/webgpu/QueueWGPU.h +++ b/src/dawn/native/webgpu/QueueWGPU.h
@@ -56,7 +56,7 @@ MaybeError SubmitPendingCommandsImpl() override; ResultOrError<ExecutionSerial> WaitForQueueSerialImpl(ExecutionSerial waitSerial, Nanoseconds timeout) override; - MaybeError WaitForIdleForDestruction() override; + MaybeError WaitForIdleForDestructionImpl() override; MaybeError SubmitFutureSync(); MutexProtected<std::deque<std::pair<WGPUFuture, ExecutionSerial>>> mFuturesInFlight;
diff --git a/src/dawn/tests/unittests/native/mocks/QueueMock.h b/src/dawn/tests/unittests/native/mocks/QueueMock.h index 29820bb..5d15f8c 100644 --- a/src/dawn/tests/unittests/native/mocks/QueueMock.h +++ b/src/dawn/tests/unittests/native/mocks/QueueMock.h
@@ -60,7 +60,7 @@ MOCK_METHOD(bool, HasPendingCommands, (), (const, override)); MOCK_METHOD(MaybeError, SubmitPendingCommandsImpl, (), (override)); MOCK_METHOD(void, ForceEventualFlushOfCommands, (), (override)); - MOCK_METHOD(MaybeError, WaitForIdleForDestruction, (), (override)); + MOCK_METHOD(MaybeError, WaitForIdleForDestructionImpl, (), (override)); MOCK_METHOD(ResultOrError<ExecutionSerial>, WaitForQueueSerialImpl, (ExecutionSerial, Nanoseconds),