From 8d16ec493b83f1ab7aefb19339b7e89db1b0a40c Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Sun, 27 Sep 2026 01:44:39 -0400 Subject: [PATCH] fix(core): implement `Send` and `Sync` for `Device` manually Every resource holds an `Arc`, so evaluating their auto traits used to walk all of `Device`. This exceeded the default recursion limit on nightly for `wgpu::CoreCommandEncoder`. --- wgpu-core/src/device/resource.rs | 78 ++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 0daf1fadb..79f03aeb7 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -321,6 +321,84 @@ pub struct Device { pub(crate) trace: Mutex>>, } +#[cfg(send_sync)] +const _: () = { + // SAFETY: Bounds checked below + unsafe impl Send for Device {} + // SAFETY: Bounds checked below + unsafe impl Sync for Device {} + + fn _device_fields_are_send_sync(obj: &Device) { + fn _check_bound(_: &T) {} + let Device { + queue, + zero_buffer, + empty_bgl, + label, + command_allocator, + command_indices, + last_successful_submission_index, + fence, + snatchable_lock, + valid, + device_lost_closure, + error_sink, + trackers, + tracker_indices, + bgl_pool, + alignments, + limits, + features, + downlevel, + ordered_buffer_usages, + ordered_texture_usages, + instance_flags, + deferred_destroy, + deferred_buffer_map_pending_closures, + usage_scopes, + indirect_validation, + timestamp_normalizer, + default_external_texture_params_buffer, + raw, + adapter, + #[cfg(feature = "trace")] + trace, + } = obj; + _check_bound(queue); + _check_bound(zero_buffer); + _check_bound(empty_bgl); + _check_bound(label); + _check_bound(command_allocator); + _check_bound(command_indices); + _check_bound(last_successful_submission_index); + _check_bound(fence); + _check_bound(snatchable_lock); + _check_bound(valid); + _check_bound(device_lost_closure); + _check_bound(error_sink); + _check_bound(trackers); + _check_bound(tracker_indices); + _check_bound(bgl_pool); + _check_bound(alignments); + _check_bound(limits); + _check_bound(features); + _check_bound(downlevel); + _check_bound(ordered_buffer_usages); + _check_bound(ordered_texture_usages); + _check_bound(instance_flags); + _check_bound(deferred_destroy); + _check_bound(deferred_buffer_map_pending_closures); + _check_bound(usage_scopes); + _check_bound(indirect_validation); + _check_bound(timestamp_normalizer); + _check_bound(default_external_texture_params_buffer); + _check_bound(raw); + _check_bound(adapter); + #[cfg(feature = "trace")] + _check_bound(trace); + } +}; + pub(crate) enum DeferredDestroy { TextureViews(WeakVec), BindGroups(WeakVec),