Skip to content

Commit

Permalink
Implement Clone on Api Types and Arc Dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Dec 5, 2024
1 parent 4e139ed commit f01ebb7
Show file tree
Hide file tree
Showing 22 changed files with 162 additions and 51 deletions.
2 changes: 1 addition & 1 deletion wgpu/src/api/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::*;
/// Does not have to be kept alive.
///
/// Corresponds to [WebGPU `GPUAdapter`](https://gpuweb.github.io/gpuweb/#gpu-adapter).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Adapter {
pub(crate) inner: dispatch::DispatchAdapter,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/bind_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::*;
/// [`ComputePass`] with [`ComputePass::set_bind_group`].
///
/// Corresponds to [WebGPU `GPUBindGroup`](https://gpuweb.github.io/gpuweb/#gpubindgroup).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct BindGroup {
pub(crate) inner: dispatch::DispatchBindGroup,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/bind_group_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::*;
///
/// Corresponds to [WebGPU `GPUBindGroupLayout`](
/// https://gpuweb.github.io/gpuweb/#gpubindgrouplayout).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct BindGroupLayout {
pub(crate) inner: dispatch::DispatchBindGroupLayout,
}
Expand Down
4 changes: 2 additions & 2 deletions wgpu/src/api/blas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ pub struct BlasBuildEntry<'a> {
}
static_assertions::assert_impl_all!(BlasBuildEntry<'_>: WasmNotSendSync);

#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct BlasShared {
pub(crate) inner: dispatch::DispatchBlas,
}
static_assertions::assert_impl_all!(BlasShared: WasmNotSendSync);

#[derive(Debug)]
#[derive(Debug, Clone)]
/// Bottom Level Acceleration Structure (BLAS).
///
/// A BLAS is a device-specific raytracing acceleration structure that contains geometry data.
Expand Down
5 changes: 3 additions & 2 deletions wgpu/src/api/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
error, fmt,
ops::{Bound, Deref, DerefMut, Range, RangeBounds},
sync::Arc,
};

use parking_lot::Mutex;
Expand Down Expand Up @@ -167,10 +168,10 @@ use crate::*;
/// [mac]: BufferDescriptor::mapped_at_creation
/// [`MAP_READ`]: BufferUsages::MAP_READ
/// [`MAP_WRITE`]: BufferUsages::MAP_WRITE
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Buffer {
pub(crate) inner: dispatch::DispatchBuffer,
pub(crate) map_context: Mutex<MapContext>,
pub(crate) map_context: Arc<Mutex<MapContext>>,
pub(crate) size: wgt::BufferAddress,
pub(crate) usage: BufferUsages,
// Todo: missing map_state https://www.w3.org/TR/webgpu/#dom-gpubuffer-mapstate
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/command_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::*;
/// a [`CommandEncoder`] and then calling [`CommandEncoder::finish`].
///
/// Corresponds to [WebGPU `GPUCommandBuffer`](https://gpuweb.github.io/gpuweb/#command-buffer).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CommandBuffer {
pub(crate) inner: Option<dispatch::DispatchCommandBuffer>,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/compute_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::*;
/// It can be created with [`Device::create_compute_pipeline`].
///
/// Corresponds to [WebGPU `GPUComputePipeline`](https://gpuweb.github.io/gpuweb/#compute-pipeline).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct ComputePipeline {
pub(crate) inner: dispatch::DispatchComputePipeline,
}
Expand Down
6 changes: 3 additions & 3 deletions wgpu/src/api/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::*;
/// A device may be requested from an adapter with [`Adapter::request_device`].
///
/// Corresponds to [WebGPU `GPUDevice`](https://gpuweb.github.io/gpuweb/#gpu-device).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Device {
pub(crate) inner: dispatch::DispatchDevice,
}
Expand Down Expand Up @@ -192,7 +192,7 @@ impl Device {

Buffer {
inner: buffer,
map_context: Mutex::new(map_context),
map_context: Arc::new(Mutex::new(map_context)),
size: desc.size,
usage: desc.usage,
}
Expand Down Expand Up @@ -273,7 +273,7 @@ impl Device {

Buffer {
inner: buffer.into(),
map_context: Mutex::new(map_context),
map_context: Arc::new(Mutex::new(map_context)),
size: desc.size,
usage: desc.usage,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::future::Future;
/// Does not have to be kept alive.
///
/// Corresponds to [WebGPU `GPU`](https://gpuweb.github.io/gpuweb/#gpu-interface).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Instance {
inner: dispatch::DispatchInstance,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/pipeline_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use crate::*;
/// This type is unique to the Rust API of `wgpu`.
///
/// [renaming]: std::fs::rename
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct PipelineCache {
pub(crate) inner: dispatch::DispatchPipelineCache,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/pipeline_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::*;
/// It can be created with [`Device::create_pipeline_layout`].
///
/// Corresponds to [WebGPU `GPUPipelineLayout`](https://gpuweb.github.io/gpuweb/#gpupipelinelayout).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct PipelineLayout {
pub(crate) inner: dispatch::DispatchPipelineLayout,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/query_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::*;
/// It can be created with [`Device::create_query_set`].
///
/// Corresponds to [WebGPU `GPUQuerySet`](https://gpuweb.github.io/gpuweb/#queryset).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct QuerySet {
pub(crate) inner: dispatch::DispatchQuerySet,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::*;
/// It can be created along with a [`Device`] by calling [`Adapter::request_device`].
///
/// Corresponds to [WebGPU `GPUQueue`](https://gpuweb.github.io/gpuweb/#gpu-queue).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Queue {
pub(crate) inner: dispatch::DispatchQueue,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/render_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::*;
/// using [`RenderPass::execute_bundles`].
///
/// Corresponds to [WebGPU `GPURenderBundle`](https://gpuweb.github.io/gpuweb/#render-bundle).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct RenderBundle {
pub(crate) inner: dispatch::DispatchRenderBundle,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/render_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::*;
/// buffers and targets. It can be created with [`Device::create_render_pipeline`].
///
/// Corresponds to [WebGPU `GPURenderPipeline`](https://gpuweb.github.io/gpuweb/#render-pipeline).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct RenderPipeline {
pub(crate) inner: dispatch::DispatchRenderPipeline,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::*;
/// It can be created with [`Device::create_sampler`].
///
/// Corresponds to [WebGPU `GPUSampler`](https://gpuweb.github.io/gpuweb/#sampler-interface).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Sampler {
pub(crate) inner: dispatch::DispatchSampler,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/surface_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::*;
/// This type is unique to the Rust API of `wgpu`. In the WebGPU specification,
/// the [`GPUCanvasContext`](https://gpuweb.github.io/gpuweb/#canvas-context) provides
/// a texture without any additional information.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct SurfaceTexture {
/// Accessible view of the frame.
pub texture: Texture,
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::*;
/// It can be created with [`Device::create_texture`].
///
/// Corresponds to [WebGPU `GPUTexture`](https://gpuweb.github.io/gpuweb/#texture-interface).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Texture {
pub(crate) inner: dispatch::DispatchTexture,
pub(crate) descriptor: TextureDescriptor<'static>,
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/texture_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::*;
/// [`RenderPipeline`] or [`BindGroup`].
///
/// Corresponds to [WebGPU `GPUTextureView`](https://gpuweb.github.io/gpuweb/#gputextureview).
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct TextureView {
pub(crate) inner: dispatch::DispatchTextureView,
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/api/tlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use wgt::WasmNotSendSync;
pub type CreateTlasDescriptor<'a> = wgt::CreateTlasDescriptor<Label<'a>>;
static_assertions::assert_impl_all!(CreateTlasDescriptor<'_>: Send, Sync);

#[derive(Debug)]
#[derive(Debug, Clone)]
/// Top Level Acceleration Structure (TLAS).
///
/// A TLAS contains a series of [TLAS instances], which are a reference to
Expand Down
5 changes: 3 additions & 2 deletions wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,11 +823,12 @@ impl dispatch::InstanceInterface for ContextWgpuCore {
},
}?;

Ok(dispatch::DispatchSurface::Core(CoreSurface {
Ok(CoreSurface {
context: self.clone(),
id,
configured_device: Mutex::default(),
}))
}
.into())
}

fn request_adapter(
Expand Down
Loading

0 comments on commit f01ebb7

Please sign in to comment.