Skip to content

Commit 33a45e1

Browse files
a1phyrErichDonGubler
authored andcommitted
wgpu: Remove Arc in WebGPU backend
1 parent 1bef4ff commit 33a45e1

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

wgpu/src/backend/webgpu.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ macro_rules! impl_send_sync {
5151
};
5252
}
5353

54+
#[derive(Clone)]
5455
pub struct ContextWebGpu {
5556
/// `None` if browser does not advertise support for WebGPU.
5657
gpu: Option<DefinedNonNullJsValue<webgpu_sys::Gpu>>,
@@ -86,7 +87,7 @@ impl crate::Error {
8687
}
8788
}
8889

89-
#[derive(Debug)]
90+
#[derive(Debug, Clone)]
9091
pub struct WebShaderModule {
9192
module: webgpu_sys::GpuShaderModule,
9293
compilation_info: WebShaderCompilationInfo,
@@ -1107,7 +1108,7 @@ extern "C" {
11071108
fn worker(this: &Global) -> JsValue;
11081109
}
11091110

1110-
#[derive(Debug)]
1111+
#[derive(Debug, Clone)]
11111112
pub enum Canvas {
11121113
Canvas(web_sys::HtmlCanvasElement),
11131114
Offscreen(web_sys::OffscreenCanvas),
@@ -1147,49 +1148,49 @@ pub fn get_browser_gpu_property(
11471148
Ok(DefinedNonNullJsValue::new(maybe_undefined_gpu))
11481149
}
11491150

1150-
#[derive(Debug)]
1151+
#[derive(Debug, Clone)]
11511152
pub struct WebAdapter {
11521153
pub(crate) inner: webgpu_sys::GpuAdapter,
11531154
/// Unique identifier for this Adapter.
11541155
ident: crate::cmp::Identifier,
11551156
}
11561157

1157-
#[derive(Debug)]
1158+
#[derive(Debug, Clone)]
11581159
pub struct WebDevice {
11591160
pub(crate) inner: webgpu_sys::GpuDevice,
11601161
/// Unique identifier for this Device.
11611162
ident: crate::cmp::Identifier,
11621163
}
11631164

1164-
#[derive(Debug)]
1165+
#[derive(Debug, Clone)]
11651166
pub struct WebQueue {
11661167
pub(crate) inner: webgpu_sys::GpuQueue,
11671168
/// Unique identifier for this Queue.
11681169
ident: crate::cmp::Identifier,
11691170
}
11701171

1171-
#[derive(Debug)]
1172+
#[derive(Debug, Clone)]
11721173
pub struct WebBindGroupLayout {
11731174
pub(crate) inner: webgpu_sys::GpuBindGroupLayout,
11741175
/// Unique identifier for this BindGroupLayout.
11751176
ident: crate::cmp::Identifier,
11761177
}
11771178

1178-
#[derive(Debug)]
1179+
#[derive(Debug, Clone)]
11791180
pub struct WebBindGroup {
11801181
pub(crate) inner: webgpu_sys::GpuBindGroup,
11811182
/// Unique identifier for this BindGroup.
11821183
ident: crate::cmp::Identifier,
11831184
}
11841185

1185-
#[derive(Debug)]
1186+
#[derive(Debug, Clone)]
11861187
pub struct WebTextureView {
11871188
pub(crate) inner: webgpu_sys::GpuTextureView,
11881189
/// Unique identifier for this TextureView.
11891190
ident: crate::cmp::Identifier,
11901191
}
11911192

1192-
#[derive(Debug)]
1193+
#[derive(Debug, Clone)]
11931194
pub struct WebSampler {
11941195
pub(crate) inner: webgpu_sys::GpuSampler,
11951196
/// Unique identifier for this Sampler.
@@ -1198,7 +1199,7 @@ pub struct WebSampler {
11981199

11991200
/// Remembers which portion of a buffer has been mapped, along with a reference
12001201
/// to the mapped portion.
1201-
#[derive(Debug)]
1202+
#[derive(Debug, Clone)]
12021203
struct WebBufferMapState {
12031204
/// The mapped memory of the buffer.
12041205
pub mapped_buffer: Option<js_sys::ArrayBuffer>,
@@ -1210,7 +1211,7 @@ struct WebBufferMapState {
12101211
/// The WebGPU specification forbids calling `getMappedRange` on a `webgpu_sys::GpuBuffer` more than
12111212
/// once, so this struct stores the initial mapped range and re-uses it, allowing for multiple `get_mapped_range`
12121213
/// calls on the Rust-side.
1213-
#[derive(Debug)]
1214+
#[derive(Debug, Clone)]
12141215
pub struct WebBuffer {
12151216
/// The associated GPU buffer.
12161217
inner: webgpu_sys::GpuBuffer,
@@ -1258,66 +1259,66 @@ impl WebBuffer {
12581259
}
12591260
}
12601261

1261-
#[derive(Debug)]
1262+
#[derive(Debug, Clone)]
12621263
pub struct WebTexture {
12631264
pub(crate) inner: webgpu_sys::GpuTexture,
12641265
/// Unique identifier for this Texture.
12651266
ident: crate::cmp::Identifier,
12661267
}
12671268

1268-
#[derive(Debug)]
1269+
#[derive(Debug, Clone)]
12691270
pub struct WebExternalTexture {
12701271
/// Unique identifier for this ExternalTexture.
12711272
ident: crate::cmp::Identifier,
12721273
}
12731274

1274-
#[derive(Debug)]
1275+
#[derive(Debug, Clone)]
12751276
pub struct WebBlas {
12761277
/// Unique identifier for this Blas.
12771278
ident: crate::cmp::Identifier,
12781279
}
12791280

1280-
#[derive(Debug)]
1281+
#[derive(Debug, Clone)]
12811282
pub struct WebTlas {
12821283
/// Unique identifier for this Blas.
12831284
ident: crate::cmp::Identifier,
12841285
}
12851286

1286-
#[derive(Debug)]
1287+
#[derive(Debug, Clone)]
12871288
pub struct WebQuerySet {
12881289
pub(crate) inner: webgpu_sys::GpuQuerySet,
12891290
/// Unique identifier for this QuerySet.
12901291
ident: crate::cmp::Identifier,
12911292
}
12921293

1293-
#[derive(Debug)]
1294+
#[derive(Debug, Clone)]
12941295
pub struct WebPipelineLayout {
12951296
pub(crate) inner: webgpu_sys::GpuPipelineLayout,
12961297
/// Unique identifier for this PipelineLayout.
12971298
ident: crate::cmp::Identifier,
12981299
}
12991300

1300-
#[derive(Debug)]
1301+
#[derive(Debug, Clone)]
13011302
pub struct WebRenderPipeline {
13021303
pub(crate) inner: webgpu_sys::GpuRenderPipeline,
13031304
/// Unique identifier for this RenderPipeline.
13041305
ident: crate::cmp::Identifier,
13051306
}
13061307

1307-
#[derive(Debug)]
1308+
#[derive(Debug, Clone)]
13081309
pub struct WebComputePipeline {
13091310
pub(crate) inner: webgpu_sys::GpuComputePipeline,
13101311
/// Unique identifier for this ComputePipeline.
13111312
ident: crate::cmp::Identifier,
13121313
}
13131314

1314-
#[derive(Debug)]
1315+
#[derive(Debug, Clone)]
13151316
pub struct WebPipelineCache {
13161317
/// Unique identifier for this PipelineCache.
13171318
ident: crate::cmp::Identifier,
13181319
}
13191320

1320-
#[derive(Debug)]
1321+
#[derive(Debug, Clone)]
13211322
pub struct WebCommandEncoder {
13221323
pub(crate) inner: webgpu_sys::GpuCommandEncoder,
13231324
/// Unique identifier for this CommandEncoder.
@@ -1345,21 +1346,21 @@ pub struct WebCommandBuffer {
13451346
ident: crate::cmp::Identifier,
13461347
}
13471348

1348-
#[derive(Debug)]
1349+
#[derive(Debug, Clone)]
13491350
pub struct WebRenderBundleEncoder {
13501351
pub(crate) inner: webgpu_sys::GpuRenderBundleEncoder,
13511352
/// Unique identifier for this RenderBundleEncoder.
13521353
ident: crate::cmp::Identifier,
13531354
}
13541355

1355-
#[derive(Debug)]
1356+
#[derive(Debug, Clone)]
13561357
pub struct WebRenderBundle {
13571358
pub(crate) inner: webgpu_sys::GpuRenderBundle,
13581359
/// Unique identifier for this RenderBundle.
13591360
ident: crate::cmp::Identifier,
13601361
}
13611362

1362-
#[derive(Debug)]
1363+
#[derive(Debug, Clone)]
13631364
pub struct WebSurface {
13641365
gpu: Option<DefinedNonNullJsValue<webgpu_sys::Gpu>>,
13651366
canvas: Canvas,
@@ -1368,7 +1369,7 @@ pub struct WebSurface {
13681369
ident: crate::cmp::Identifier,
13691370
}
13701371

1371-
#[derive(Debug)]
1372+
#[derive(Debug, Clone)]
13721373
pub struct WebSurfaceOutputDetail {
13731374
/// Unique identifier for this SurfaceOutputDetail.
13741375
ident: crate::cmp::Identifier,

wgpu/src/cmp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use core::{num::NonZeroU64, sync::atomic::Ordering};
1313

1414
static NEXT_ID: AtomicU64 = AtomicU64::new(1);
1515

16-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
16+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1717
pub struct Identifier {
1818
inner: NonZeroU64,
1919
}

wgpu/src/dispatch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ macro_rules! dispatch_types {
596596
#[cfg(wgpu_core)]
597597
Core(Arc<$core_type>),
598598
#[cfg(webgpu)]
599-
WebGPU(Arc<$webgpu_type>),
599+
WebGPU($webgpu_type),
600600
#[allow(clippy::allow_attributes, private_interfaces)]
601601
#[cfg(custom)]
602602
Custom($custom_type),
@@ -672,7 +672,7 @@ macro_rules! dispatch_types {
672672
impl From<$webgpu_type> for $name {
673673
#[inline]
674674
fn from(value: $webgpu_type) -> Self {
675-
Self::WebGPU(Arc::new(value))
675+
Self::WebGPU(value)
676676
}
677677
}
678678

@@ -685,7 +685,7 @@ macro_rules! dispatch_types {
685685
#[cfg(wgpu_core)]
686686
Self::Core(value) => value.as_ref(),
687687
#[cfg(webgpu)]
688-
Self::WebGPU(value) => value.as_ref(),
688+
Self::WebGPU(value) => value,
689689
#[cfg(custom)]
690690
Self::Custom(value) => value.deref(),
691691
#[cfg(not(any(wgpu_core, webgpu)))]

0 commit comments

Comments
 (0)