Skip to content

Commit

Permalink
Remove Arc from core types
Browse files Browse the repository at this point in the history
They can impl Clone on ids

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
  • Loading branch information
sagudev committed Jan 3, 2025
1 parent cf20ac7 commit 8ecd8cf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
50 changes: 25 additions & 25 deletions wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,96 +419,96 @@ fn map_pass_channel<V: Copy>(ops: Option<&Operations<V>>) -> wgc::command::PassC
}
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreSurface {
pub(crate) context: ContextWgpuCore,
id: wgc::id::SurfaceId,
/// Configured device is needed to know which backend
/// code to execute when acquiring a new frame.
configured_device: Mutex<Option<wgc::id::DeviceId>>,
configured_device: Arc<Mutex<Option<wgc::id::DeviceId>>>,
/// The error sink with which to report errors.
/// `None` if the surface has not been configured.
error_sink: Mutex<Option<ErrorSink>>,
error_sink: Arc<Mutex<Option<ErrorSink>>>,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreAdapter {
pub(crate) context: ContextWgpuCore,
pub(crate) id: wgc::id::AdapterId,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreDevice {
pub(crate) context: ContextWgpuCore,
id: wgc::id::DeviceId,
error_sink: ErrorSink,
features: Features,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreBuffer {
pub(crate) context: ContextWgpuCore,
id: wgc::id::BufferId,
error_sink: ErrorSink,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreShaderModule {
pub(crate) context: ContextWgpuCore,
id: wgc::id::ShaderModuleId,
compilation_info: CompilationInfo,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreBindGroupLayout {
pub(crate) context: ContextWgpuCore,
id: wgc::id::BindGroupLayoutId,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreBindGroup {
pub(crate) context: ContextWgpuCore,
id: wgc::id::BindGroupId,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreTexture {
pub(crate) context: ContextWgpuCore,
id: wgc::id::TextureId,
error_sink: ErrorSink,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreTextureView {
pub(crate) context: ContextWgpuCore,
id: wgc::id::TextureViewId,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreSampler {
pub(crate) context: ContextWgpuCore,
id: wgc::id::SamplerId,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreQuerySet {
pub(crate) context: ContextWgpuCore,
id: wgc::id::QuerySetId,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CorePipelineLayout {
pub(crate) context: ContextWgpuCore,
id: wgc::id::PipelineLayoutId,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CorePipelineCache {
pub(crate) context: ContextWgpuCore,
id: wgc::id::PipelineCacheId,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreCommandBuffer {
pub(crate) context: ContextWgpuCore,
id: wgc::id::CommandBufferId,
Expand All @@ -521,26 +521,26 @@ pub struct CoreRenderBundleEncoder {
id: crate::cmp::Identifier,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreRenderBundle {
id: wgc::id::RenderBundleId,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreQueue {
pub(crate) context: ContextWgpuCore,
id: wgc::id::QueueId,
error_sink: ErrorSink,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreComputePipeline {
pub(crate) context: ContextWgpuCore,
id: wgc::id::ComputePipelineId,
error_sink: ErrorSink,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreRenderPipeline {
pub(crate) context: ContextWgpuCore,
id: wgc::id::RenderPipelineId,
Expand Down Expand Up @@ -571,21 +571,21 @@ pub struct CoreCommandEncoder {
open: bool,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreBlas {
pub(crate) context: ContextWgpuCore,
id: wgc::id::BlasId,
// error_sink: ErrorSink,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreTlas {
pub(crate) context: ContextWgpuCore,
id: wgc::id::TlasId,
// error_sink: ErrorSink,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CoreSurfaceOutputDetail {
context: ContextWgpuCore,
surface_id: wgc::id::SurfaceId,
Expand Down Expand Up @@ -813,8 +813,8 @@ impl dispatch::InstanceInterface for ContextWgpuCore {
Ok(CoreSurface {
context: self.clone(),
id,
configured_device: Mutex::default(),
error_sink: Mutex::default(),
configured_device: Arc::new(Mutex::default()),
error_sink: Arc::new(Mutex::default()),
}
.into())
}
Expand Down
12 changes: 6 additions & 6 deletions wgpu/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use crate::{WasmNotSend, WasmNotSendSync};

use std::{any::Any, fmt::Debug, future::Future, hash::Hash, ops::Range, pin::Pin, sync::Arc};
use std::{any::Any, fmt::Debug, future::Future, hash::Hash, ops::Range, pin::Pin};

use crate::backend;

Expand Down Expand Up @@ -564,9 +564,9 @@ macro_rules! dispatch_types_inner {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
pub enum $name {
#[cfg(wgpu_core)]
Core(Arc<<$wgpu_core_context as InterfaceTypes>::$subtype>),
Core(<$wgpu_core_context as InterfaceTypes>::$subtype),
#[cfg(webgpu)]
WebGPU(Arc<<$webgpu_context as InterfaceTypes>::$subtype>),
WebGPU(std::sync::Arc<<$webgpu_context as InterfaceTypes>::$subtype>),
}

impl $name {
Expand Down Expand Up @@ -615,15 +615,15 @@ macro_rules! dispatch_types_inner {
impl From<<$wgpu_core_context as InterfaceTypes>::$subtype> for $name {
#[inline]
fn from(value: <$wgpu_core_context as InterfaceTypes>::$subtype) -> Self {
Self::Core(Arc::new(value))
Self::Core(value)
}
}

#[cfg(webgpu)]
impl From<<$webgpu_context as InterfaceTypes>::$subtype> for $name {
#[inline]
fn from(value: <$webgpu_context as InterfaceTypes>::$subtype) -> Self {
Self::WebGPU(Arc::new(value))
Self::WebGPU(std::sync::Arc::new(value))
}
}

Expand All @@ -634,7 +634,7 @@ macro_rules! dispatch_types_inner {
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.as_ref(),
}
Expand Down

0 comments on commit 8ecd8cf

Please sign in to comment.