Repository navigation
fix(native_surface): the Linux dmabuf importer stops and joins its read thread before releasing the device - #1620
Merged
Conversation
…ad thread before releasing the device
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.
What was wrong
native_surface/linux.rs:Importer::newspawned a detachedrune-dmabuf-readthread that owned a clone of thewgpu::Deviceand blocked inDevice::poll(Wait { .. })(up to 10 s) for each dmabuf copy. Nothing stopped or joined it: the thread exited only when the channel'sSenderdropped, andSurfaceRendererdropped itsdmabufimporter last, after its own device. So a poll in flight, or one still queued, could run while the device and Vulkan driver were torn down. #1500 fixed the same race for the video completion thread.What changed
pipeline/completion.rs: a newReadWorker<T>runs queued items in order on a named thread. Itsstoprefuses new items, discards queued ones, and joins the thread. LikeCompletionWorker, it handles caller unwinding, a callback panic, a lost device (the worker exits) and a drop from its own thread (it does not join itself).ReadWorker::spawn_deviceis the dmabuf wait. This code compiles on every platform, so its tests run on Windows.linux.rs:Importerholds aReadWorkerdeclared beforedevice, andDropstops it. When the worker has stopped,on_readgets an error instead of being dropped without a call.pipeline.rs:SurfaceRendererdeclaresdmabufbeforedeviceand stops the importer inDrop, after the completion worker.Verification
read_worker_*tests incompletion_tests.rscover these cases: idle drop, drop during an in-flight wait (it blocks, then discards queued items), lost device, callback panic, caller unwind, self-drop, idempotent stop, and a real headless wgpu wait that runson_readonrune-dmabuf-readand joins before drop returns. Ifstopdoes not join,read_worker_drop_waits_for_in_flight_wait_and_skips_queued_itemsandread_worker_device_notifies_on_read_and_drop_joins_in_flight_callbackfail.cargo test -p rune-media native_surface: 41 passed.read_workertests passed in 5 repeated runs.cargo check -p rune -p rune-kitpasses, and so doesscripts/file-size.sh.cargo check -p rune-media --testspasses for Linux aarch64 in a container.Not checked: a real dmabuf import on a Linux Vulkan GPU. The Linux code was only compiled, not run.