[Metal/hal] Add metal::Queue::add_wait_event / add_signal_event for synchronization with external APIs#9483
Open
AdrianEddy wants to merge 2 commits intogfx-rs:trunkfrom
Open
[Metal/hal] Add metal::Queue::add_wait_event / add_signal_event for synchronization with external APIs#9483AdrianEddy wants to merge 2 commits intogfx-rs:trunkfrom
metal::Queue::add_wait_event / add_signal_event for synchronization with external APIs#9483AdrianEddy wants to merge 2 commits intogfx-rs:trunkfrom
Conversation
…or interop with external APIs
metal::Queue::add_wait_event / add_signal_event for interop with external APIsmetal::Queue::add_wait_event / add_signal_event for synchronization with external APIs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds
add_wait_eventandadd_signal_event(with matchingremove_*companions) towgpu_hal::metal::Queue. They stageMTLCommandBuffer::encodeWaitForEvent/encodeSignalEventcalls on anMTLSharedEventfor the nextQueue::submit(), enabling GPU-side coordination with externally imported resources sharing the sameMTLSharedEvent) without a CPU wait. Mirrors the recently-added Vulkanadd_wait_semaphore(#9461) and DX12add_wait_fence/add_signal_fence(#9463).Signals are encoded after wgpu's own completion signal, so foreign waiters observe the submit as done. Waits are encoded onto a dedicated internal command buffer committed before the submit's user CBs.
Metal allows independent command buffers in the same queue to overlap on the GPU, so a wait CB does not strictly gate subsequent user CBs that share no Metal-tracked resources with it. Single-stream pipelines often serialize anyway because the GPU has no concurrent work to fill the slot, but mixed workloads (decode + compute + render) can race past the staged waits.
For strict ordering, callers can opt into
metal::Queue::enable_strict_event_sync(), which routes staged waits through a per-queue relayMTLSharedEvent. Everybegin_encodingpre-encodes a wait on the relay at the value the next submit will signal; every submit drains the staged foreign waits and then signals the relay, releasing all CBs encoded since the previous submit in lockstep. Costs one extraencodeWaitForEventper CB plus one extra internal CB per submit on that queue.Testing
Explain how this change is tested.
Squash
Squash
Checklist
wgpumay be affected behaviorally.CHANGELOG.mdentries for the user-facing effects of this change are present.