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 (#3025)
  • Loading branch information
i509VCB authored Sep 16, 2022
1 parent 9e3efd7 commit b752c7d
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 @@ -1719,9 +1719,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 @@ -1951,7 +1953,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 @@ -1967,7 +1969,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 @@ -1981,7 +1983,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 @@ -1995,7 +1997,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 @@ -2011,7 +2013,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 @@ -2106,7 +2108,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 @@ -2118,13 +2120,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 b752c7d

Please sign in to comment.