From 895f3fdd936b478afca520813879ee94229ee84a Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Sat, 22 Aug 2026 07:29:24 +0200 Subject: [PATCH] Remove one Arc level of indirection in Dispatch* by implementing clone on Core* Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- wgpu/src/backend/wgpu_core.rs | 38 +++++++++++++++++++---------------- wgpu/src/dispatch.rs | 11 +++++----- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index ba537bb00..06a254f24 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -303,6 +303,7 @@ fn map_pass_channel(ops: Option<&Operations>) -> wgc::command::PassC } } +#[derive(Clone)] pub struct CoreSurface { pub(crate) context: ContextWgpuCore, pub(crate) wgpu_surface: Arc, @@ -321,6 +322,7 @@ impl fmt::Debug for CoreSurface { } } +#[derive(Clone)] pub struct CoreAdapter { pub(crate) context: ContextWgpuCore, pub(crate) wgpu_adapter: Arc, @@ -335,67 +337,67 @@ impl fmt::Debug for CoreAdapter { } } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreDevice { pub(crate) context: ContextWgpuCore, pub(crate) wgpu_device: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreBuffer { pub(crate) context: ContextWgpuCore, pub(crate) wgpu_buffer: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreShaderModule { pub(crate) wgpu_shader_module: Arc, compilation_info: CompilationInfo, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreBindGroupLayout { pub(crate) wgpu_bind_group_layout: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreBindGroup { pub(crate) wgpu_bind_group: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreTexture { pub(crate) context: ContextWgpuCore, pub(crate) wgpu_texture: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreTextureView { pub(crate) context: ContextWgpuCore, pub(crate) wgpu_texture_view: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreExternalTexture { pub(crate) wgpu_external_texture: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreSampler { pub(crate) wgpu_sampler: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreQuerySet { pub(crate) wgpu_query_set: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CorePipelineLayout { pub(crate) wgpu_pipeline_layout: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CorePipelineCache { pub(crate) wgpu_pipeline_cache: Arc, } @@ -422,11 +424,12 @@ pub struct CoreRenderBundleEncoder { encoder: Box, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreRenderBundle { pub(crate) wgpu_render_bundle: Arc, } +#[derive(Clone)] pub struct CoreQueue { pub(crate) context: ContextWgpuCore, pub(crate) wgpu_queue: Arc, @@ -441,12 +444,12 @@ impl fmt::Debug for CoreQueue { } } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreComputePipeline { pub(crate) wgpu_compute_pipeline: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreRenderPipeline { pub(crate) wgpu_render_pipeline: Arc, } @@ -482,18 +485,19 @@ impl fmt::Debug for CoreCommandEncoder { } } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreBlas { pub(crate) context: ContextWgpuCore, pub(crate) wgpu_blas: Arc, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CoreTlas { pub(crate) context: ContextWgpuCore, pub(crate) wgpu_tlas: Arc, } +#[derive(Clone)] pub struct CoreSurfaceOutputDetail { pub(crate) context: ContextWgpuCore, wgpu_surface: Arc, diff --git a/wgpu/src/dispatch.rs b/wgpu/src/dispatch.rs index c3a679547..f28279074 100644 --- a/wgpu/src/dispatch.rs +++ b/wgpu/src/dispatch.rs @@ -693,8 +693,7 @@ pub trait BufferMappedRangeInterface: CommonTraits { /// a `DerefMut` implementation, and `as_*_mut` methods that return `&mut` references. /// This `D` does not implement `Clone`. /// -/// The macro's `ref type` form defines `D` to hold an `Arc` pointing to the backend type, -/// permitting `Clone` and `Deref`, but losing exclusive, mutable access. +/// The macro's `ref type` form defines `D` to be `Clone` and `Deref`, but losing exclusive, mutable access. /// /// For example: /// @@ -709,7 +708,7 @@ pub trait BufferMappedRangeInterface: CommonTraits { /// ```ignore /// pub enum DispatchBuffer { /// #[cfg(wgpu_core)] -/// Core(Arc), +/// Core(CoreBuffer), /// #[cfg(webgpu)] /// WebGPU(WebBuffer), /// #[cfg(custom)] @@ -748,7 +747,7 @@ macro_rules! dispatch_types { #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] pub enum $name { #[cfg(wgpu_core)] - Core(Arc<$core_type>), + Core($core_type), #[cfg(webgpu)] WebGPU($webgpu_type), #[allow(clippy::allow_attributes, private_interfaces)] @@ -818,7 +817,7 @@ macro_rules! dispatch_types { impl From<$core_type> for $name { #[inline] fn from(value: $core_type) -> Self { - Self::Core(Arc::new(value)) + Self::Core(value) } } @@ -837,7 +836,7 @@ macro_rules! dispatch_types { fn deref(&self) -> &Self::Target { match self { #[cfg(wgpu_core)] - Self::Core(value) => value.as_ref(), + Self::Core(value) => value, #[cfg(webgpu)] Self::WebGPU(value) => value, #[cfg(custom)]