Skip to content

Commit

Permalink
statically assert public wgpu types appropriately implement Send and …
Browse files Browse the repository at this point in the history
…Sync

Although we still have some gaps and disagreements between Web and Native whether some types are Send + Sync and a few safety concerns, this pull request should help prevent accidentally making types no longer Send + Sync when the types should be and vice versa.
  • Loading branch information
i509VCB committed Sep 16, 2022
1 parent 94ce763 commit 9b53e96
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ the same every time it is rendered, we now warn if it is missing.
- Improve the validation and error reporting of buffer mappings by @nical in [#2848](https://github.com/gfx-rs/wgpu/pull/2848)
- Fix compilation errors when using wgpu-core in isolation while targetting `wasm32-unknown-unknown` by @Seamooo in [#2922](https://github.com/gfx-rs/wgpu/pull/2922)
- Fixed opening of RenderDoc library by @abuffseagull in [#2930](https://github.com/gfx-rs/wgpu/pull/2930)
- Fixed `CommandEncoder` not being `Send` and `Sync` on web by @i509VCB in [#3025](https://github.com/gfx-rs/wgpu/pull/3025)

#### Metal
- Add the missing `msg_send![view, retain]` call within `from_view` by @jinleili in [#2976](https://github.com/gfx-rs/wgpu/pull/2976)
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ parking_lot = ">=0.11,<0.13"
raw-window-handle = "0.5"
serde = { version = "1", features = ["derive"], optional = true }
smallvec = "1"
static_assertions = "1.1.0"

[dev-dependencies]
bitflags = "1"
Expand Down
28 changes: 15 additions & 13 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ impl crate::Context for Context {
type PipelineLayoutId = Sendable<web_sys::GpuPipelineLayout>;
type RenderPipelineId = Sendable<web_sys::GpuRenderPipeline>;
type ComputePipelineId = Sendable<web_sys::GpuComputePipeline>;
type CommandEncoderId = web_sys::GpuCommandEncoder;
type CommandEncoderId = Sendable<web_sys::GpuCommandEncoder>;
type ComputePassId = ComputePass;
type RenderPassId = RenderPass;
type CommandBufferId = Sendable<web_sys::GpuCommandBuffer>;
Expand Down Expand Up @@ -1718,9 +1718,11 @@ impl crate::Context for Context {
if let Some(label) = desc.label {
mapped_desc.label(label);
}
device
.0
.create_command_encoder_with_descriptor(&mapped_desc)
Sendable(
device
.0
.create_command_encoder_with_descriptor(&mapped_desc),
)
}

fn device_create_render_bundle_encoder(
Expand Down Expand Up @@ -1950,7 +1952,7 @@ impl crate::Context for Context {
destination_offset: wgt::BufferAddress,
copy_size: wgt::BufferAddress,
) {
encoder.copy_buffer_to_buffer_with_f64_and_f64_and_f64(
encoder.0.copy_buffer_to_buffer_with_f64_and_f64_and_f64(
&source.0,
source_offset as f64,
&destination.0,
Expand All @@ -1966,7 +1968,7 @@ impl crate::Context for Context {
destination: crate::ImageCopyTexture,
copy_size: wgt::Extent3d,
) {
encoder.copy_buffer_to_texture_with_gpu_extent_3d_dict(
encoder.0.copy_buffer_to_texture_with_gpu_extent_3d_dict(
&map_buffer_copy_view(source),
&map_texture_copy_view(destination),
&map_extent_3d(copy_size),
Expand All @@ -1980,7 +1982,7 @@ impl crate::Context for Context {
destination: crate::ImageCopyBuffer,
copy_size: wgt::Extent3d,
) {
encoder.copy_texture_to_buffer_with_gpu_extent_3d_dict(
encoder.0.copy_texture_to_buffer_with_gpu_extent_3d_dict(
&map_texture_copy_view(source),
&map_buffer_copy_view(destination),
&map_extent_3d(copy_size),
Expand All @@ -1994,7 +1996,7 @@ impl crate::Context for Context {
destination: crate::ImageCopyTexture,
copy_size: wgt::Extent3d,
) {
encoder.copy_texture_to_texture_with_gpu_extent_3d_dict(
encoder.0.copy_texture_to_texture_with_gpu_extent_3d_dict(
&map_texture_copy_view(source),
&map_texture_copy_view(destination),
&map_extent_3d(copy_size),
Expand All @@ -2010,7 +2012,7 @@ impl crate::Context for Context {
if let Some(label) = desc.label {
mapped_desc.label(label);
}
ComputePass(encoder.begin_compute_pass_with_descriptor(&mapped_desc))
ComputePass(encoder.0.begin_compute_pass_with_descriptor(&mapped_desc))
}

fn command_encoder_end_compute_pass(
Expand Down Expand Up @@ -2105,7 +2107,7 @@ impl crate::Context for Context {
mapped_desc.depth_stencil_attachment(&mapped_depth_stencil_attachment);
}

RenderPass(encoder.begin_render_pass(&mapped_desc))
RenderPass(encoder.0.begin_render_pass(&mapped_desc))
}

fn command_encoder_end_render_pass(
Expand All @@ -2117,13 +2119,13 @@ impl crate::Context for Context {
}

fn command_encoder_finish(&self, encoder: Self::CommandEncoderId) -> Self::CommandBufferId {
let label = encoder.label();
let label = encoder.0.label();
Sendable(if label.is_empty() {
encoder.finish()
encoder.0.finish()
} else {
let mut mapped_desc = web_sys::GpuCommandBufferDescriptor::new();
mapped_desc.label(&label);
encoder.finish_with_descriptor(&mapped_desc)
encoder.0.finish_with_descriptor(&mapped_desc)
})
}

Expand Down
Loading

0 comments on commit 9b53e96

Please sign in to comment.