Expose Metal external buffer-write interop - #9933
Closed
jcwal1516 wants to merge 1 commit into
Closed
Conversation
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.
Summary
Motivation
A native asynchronous producer such as an image decoder needs to fill a
wgpu::Bufferdirectly and then return that allocation to an ordinary wgpu consumer. On Metal, the external submission must retain the native device, queue, and buffer beyond theas_halguard. Once the write has completed with the required queue ordering, wgpu must also learn that the exact written range is initialized so a later lazy clear does not overwrite it.The concrete downstream use case is a JPEG 2000/HTJ2K decoder writing directly into a Burn tensor backed by wgpu. Decoded pixels never make a host round trip. This API does not submit or synchronize work; synchronization remains the external producer's responsibility.
Safety contract
Buffer::mark_external_write_initializedchanges only initialization tracking and validates the requested range.Validation
cargo test -p wgpu-core device::external_write --libcargo test -p wgpu range_to_offset_size --libcargo test -p wgpu-hal --features metal retained_queue_and_buffer_handles_outlive_their_hal_wrappers --libcargo test -p wgpu-core --libcargo test -p wgpu --libcargo test -p wgpu-hal --features metal --libcargo xtask test -E 'test(/metal_external_buffer_write/)'on Apple M4 Procargo clippy -p wgpu-core -p wgpu-hal -p wgpu -p wgpu-test --tests -- -D warningscargo buildcargo fmt --all -- --checkgit diff --checkCloses #9928.
Related to #4067 and tracel-ai/cubecl#1443.