Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable unsafe_ops_in_unsafe_fn lint in all workspaces #3044

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ both `raw_window_handle::HasRawWindowHandle` and `raw_window_handle::HasRawDispl
- Don't use `PhantomData` for `IdentityManager`'s `Input` type. By @jimblandy in [#2972](https://github.com/gfx-rs/wgpu/pull/2972)
- Changed Naga variant in ShaderSource to `Cow<'static, Module>`, to allow loading global variables by @daxpedda in [#2903](https://github.com/gfx-rs/wgpu/pull/2903)
- Updated the maximum binding index to match the WebGPU specification by @nical in [#2957](https://github.com/gfx-rs/wgpu/pull/2957)
- Add `unsafe_op_in_unsafe_fn` to Clippy lints in the entire workspace. By @ErichDonGubler in [#3044](https://github.com/gfx-rs/wgpu/pull/3044).

#### Metal

Expand Down
2 changes: 2 additions & 0 deletions deno_webgpu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

#![warn(unsafe_op_in_unsafe_fn)]

cwfitzgerald marked this conversation as resolved.
Show resolved Hide resolved
use deno_core::error::AnyError;
use deno_core::include_js_files;
use deno_core::op;
Expand Down
2 changes: 2 additions & 0 deletions player/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* so that we don't accidentally try to use the same ID.
!*/

#![warn(unsafe_op_in_unsafe_fn)]

use wgc::device::trace;

use std::{borrow::Cow, fmt::Debug, fs, marker::PhantomData, path::Path};
Expand Down
82 changes: 46 additions & 36 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ impl<A: HalApi> RenderBundle<A> {
let mut offsets = self.base.dynamic_offsets.as_slice();
let mut pipeline_layout_id = None::<id::Valid<id::PipelineLayoutId>>;
if let Some(ref label) = self.base.label {
raw.begin_debug_marker(label);
unsafe { raw.begin_debug_marker(label) };
}

for command in self.base.commands.iter() {
Expand All @@ -774,17 +774,19 @@ impl<A: HalApi> RenderBundle<A> {
bind_group_id,
} => {
let bind_group = bind_group_guard.get(bind_group_id).unwrap();
raw.set_bind_group(
&pipeline_layout_guard[pipeline_layout_id.unwrap()].raw,
index as u32,
&bind_group.raw,
&offsets[..num_dynamic_offsets as usize],
);
unsafe {
raw.set_bind_group(
&pipeline_layout_guard[pipeline_layout_id.unwrap()].raw,
index as u32,
&bind_group.raw,
&offsets[..num_dynamic_offsets as usize],
)
};
offsets = &offsets[num_dynamic_offsets as usize..];
}
RenderCommand::SetPipeline(pipeline_id) => {
let pipeline = pipeline_guard.get(pipeline_id).unwrap();
raw.set_render_pipeline(&pipeline.raw);
unsafe { raw.set_render_pipeline(&pipeline.raw) };

pipeline_layout_id = Some(pipeline.layout_id.value);
}
Expand All @@ -805,7 +807,7 @@ impl<A: HalApi> RenderBundle<A> {
offset,
size,
};
raw.set_index_buffer(bb, index_format);
unsafe { raw.set_index_buffer(bb, index_format) };
}
RenderCommand::SetVertexBuffer {
slot,
Expand All @@ -824,7 +826,7 @@ impl<A: HalApi> RenderBundle<A> {
offset,
size,
};
raw.set_vertex_buffer(slot, bb);
unsafe { raw.set_vertex_buffer(slot, bb) };
}
RenderCommand::SetPushConstant {
stages,
Expand All @@ -841,18 +843,22 @@ impl<A: HalApi> RenderBundle<A> {
let data_slice = &self.base.push_constant_data
[(values_offset as usize)..values_end_offset];

raw.set_push_constants(&pipeline_layout.raw, stages, offset, data_slice)
unsafe {
raw.set_push_constants(&pipeline_layout.raw, stages, offset, data_slice)
}
} else {
super::push_constant_clear(
offset,
size_bytes,
|clear_offset, clear_data| {
raw.set_push_constants(
&pipeline_layout.raw,
stages,
clear_offset,
clear_data,
);
unsafe {
raw.set_push_constants(
&pipeline_layout.raw,
stages,
clear_offset,
clear_data,
)
};
},
);
}
Expand All @@ -863,7 +869,7 @@ impl<A: HalApi> RenderBundle<A> {
first_vertex,
first_instance,
} => {
raw.draw(first_vertex, vertex_count, first_instance, instance_count);
unsafe { raw.draw(first_vertex, vertex_count, first_instance, instance_count) };
}
RenderCommand::DrawIndexed {
index_count,
Expand All @@ -872,13 +878,15 @@ impl<A: HalApi> RenderBundle<A> {
base_vertex,
first_instance,
} => {
raw.draw_indexed(
first_index,
index_count,
base_vertex,
first_instance,
instance_count,
);
unsafe {
raw.draw_indexed(
first_index,
index_count,
base_vertex,
first_instance,
instance_count,
)
};
}
RenderCommand::MultiDrawIndirect {
buffer_id,
Expand All @@ -892,7 +900,7 @@ impl<A: HalApi> RenderBundle<A> {
.raw
.as_ref()
.ok_or(ExecutionError::DestroyedBuffer(buffer_id))?;
raw.draw_indirect(buffer, offset, 1);
unsafe { raw.draw_indirect(buffer, offset, 1) };
}
RenderCommand::MultiDrawIndirect {
buffer_id,
Expand All @@ -906,7 +914,7 @@ impl<A: HalApi> RenderBundle<A> {
.raw
.as_ref()
.ok_or(ExecutionError::DestroyedBuffer(buffer_id))?;
raw.draw_indexed_indirect(buffer, offset, 1);
unsafe { raw.draw_indexed_indirect(buffer, offset, 1) };
}
RenderCommand::MultiDrawIndirect { .. }
| RenderCommand::MultiDrawIndirectCount { .. } => {
Expand All @@ -931,7 +939,7 @@ impl<A: HalApi> RenderBundle<A> {
}

if let Some(_) = self.base.label {
raw.end_debug_marker();
unsafe { raw.end_debug_marker() };
}

Ok(())
Expand Down Expand Up @@ -1439,13 +1447,15 @@ pub mod bundle_ffi {
offsets: *const DynamicOffset,
offset_length: usize,
) {
let redundant = bundle.current_bind_groups.set_and_check_redundant(
bind_group_id,
index,
&mut bundle.base.dynamic_offsets,
offsets,
offset_length,
);
let redundant = unsafe {
bundle.current_bind_groups.set_and_check_redundant(
bind_group_id,
index,
&mut bundle.base.dynamic_offsets,
offsets,
offset_length,
)
};

if redundant {
return;
Expand Down Expand Up @@ -1522,7 +1532,7 @@ pub mod bundle_ffi {
0,
"Push constant size must be aligned to 4 bytes."
);
let data_slice = slice::from_raw_parts(data, size_bytes as usize);
let data_slice = unsafe { slice::from_raw_parts(data, size_bytes as usize) };
let value_offset = pass.base.push_constant_data.len().try_into().expect(
"Ran out of push constant space. Don't set 4gb of push constants per RenderBundle.",
);
Expand Down
22 changes: 12 additions & 10 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,13 +800,15 @@ pub mod compute_ffi {
offsets: *const DynamicOffset,
offset_length: usize,
) {
let redundant = pass.current_bind_groups.set_and_check_redundant(
bind_group_id,
index,
&mut pass.base.dynamic_offsets,
offsets,
offset_length,
);
let redundant = unsafe {
pass.current_bind_groups.set_and_check_redundant(
bind_group_id,
index,
&mut pass.base.dynamic_offsets,
offsets,
offset_length,
)
};

if redundant {
return;
Expand Down Expand Up @@ -854,7 +856,7 @@ pub mod compute_ffi {
0,
"Push constant size must be aligned to 4 bytes."
);
let data_slice = slice::from_raw_parts(data, size_bytes as usize);
let data_slice = unsafe { slice::from_raw_parts(data, size_bytes as usize) };
let value_offset = pass.base.push_constant_data.len().try_into().expect(
"Ran out of push constant space. Don't set 4gb of push constants per ComputePass.",
);
Expand Down Expand Up @@ -905,7 +907,7 @@ pub mod compute_ffi {
label: RawString,
color: u32,
) {
let bytes = ffi::CStr::from_ptr(label).to_bytes();
let bytes = unsafe { ffi::CStr::from_ptr(label) }.to_bytes();
pass.base.string_data.extend_from_slice(bytes);

pass.base.commands.push(ComputeCommand::PushDebugGroup {
Expand All @@ -929,7 +931,7 @@ pub mod compute_ffi {
label: RawString,
color: u32,
) {
let bytes = ffi::CStr::from_ptr(label).to_bytes();
let bytes = unsafe { ffi::CStr::from_ptr(label) }.to_bytes();
pass.base.string_data.extend_from_slice(bytes);

pass.base.commands.push(ComputeCommand::InsertDebugMarker {
Expand Down
3 changes: 2 additions & 1 deletion wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ impl BindGroupStateChange {
if let Some(current_bind_group) = self.last_states.get_mut(index as usize) {
current_bind_group.reset();
}
dynamic_offsets.extend_from_slice(slice::from_raw_parts(offsets, offset_length));
dynamic_offsets
.extend_from_slice(unsafe { slice::from_raw_parts(offsets, offset_length) });
}
false
}
Expand Down
26 changes: 15 additions & 11 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2113,13 +2113,15 @@ pub mod render_ffi {
offsets: *const DynamicOffset,
offset_length: usize,
) {
let redundant = pass.current_bind_groups.set_and_check_redundant(
bind_group_id,
index,
&mut pass.base.dynamic_offsets,
offsets,
offset_length,
);
let redundant = unsafe {
pass.current_bind_groups.set_and_check_redundant(
bind_group_id,
index,
&mut pass.base.dynamic_offsets,
offsets,
offset_length,
)
};

if redundant {
return;
Expand Down Expand Up @@ -2239,7 +2241,7 @@ pub mod render_ffi {
0,
"Push constant size must be aligned to 4 bytes."
);
let data_slice = slice::from_raw_parts(data, size_bytes as usize);
let data_slice = unsafe { slice::from_raw_parts(data, size_bytes as usize) };
let value_offset = pass.base.push_constant_data.len().try_into().expect(
"Ran out of push constant space. Don't set 4gb of push constants per RenderPass.",
);
Expand Down Expand Up @@ -2402,7 +2404,7 @@ pub mod render_ffi {
label: RawString,
color: u32,
) {
let bytes = ffi::CStr::from_ptr(label).to_bytes();
let bytes = unsafe { ffi::CStr::from_ptr(label) }.to_bytes();
pass.base.string_data.extend_from_slice(bytes);

pass.base.commands.push(RenderCommand::PushDebugGroup {
Expand All @@ -2426,7 +2428,7 @@ pub mod render_ffi {
label: RawString,
color: u32,
) {
let bytes = ffi::CStr::from_ptr(label).to_bytes();
let bytes = unsafe { ffi::CStr::from_ptr(label) }.to_bytes();
pass.base.string_data.extend_from_slice(bytes);

pass.base.commands.push(RenderCommand::InsertDebugMarker {
Expand Down Expand Up @@ -2478,7 +2480,9 @@ pub mod render_ffi {
render_bundle_ids: *const id::RenderBundleId,
render_bundle_ids_length: usize,
) {
for &bundle_id in slice::from_raw_parts(render_bundle_ids, render_bundle_ids_length) {
for &bundle_id in
unsafe { slice::from_raw_parts(render_bundle_ids, render_bundle_ids_length) }
{
pass.base
.commands
.push(RenderCommand::ExecuteBundle(bundle_id));
Expand Down
20 changes: 10 additions & 10 deletions wgpu-core/src/device/life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,61 +132,61 @@ impl<A: hal::Api> NonReferencedResources<A> {
if !self.buffers.is_empty() {
profiling::scope!("destroy_buffers");
for raw in self.buffers.drain(..) {
device.destroy_buffer(raw);
unsafe { device.destroy_buffer(raw) };
}
}
if !self.textures.is_empty() {
profiling::scope!("destroy_textures");
for raw in self.textures.drain(..) {
device.destroy_texture(raw);
unsafe { device.destroy_texture(raw) };
}
}
if !self.texture_views.is_empty() {
profiling::scope!("destroy_texture_views");
for raw in self.texture_views.drain(..) {
device.destroy_texture_view(raw);
unsafe { device.destroy_texture_view(raw) };
}
}
if !self.samplers.is_empty() {
profiling::scope!("destroy_samplers");
for raw in self.samplers.drain(..) {
device.destroy_sampler(raw);
unsafe { device.destroy_sampler(raw) };
}
}
if !self.bind_groups.is_empty() {
profiling::scope!("destroy_bind_groups");
for raw in self.bind_groups.drain(..) {
device.destroy_bind_group(raw);
unsafe { device.destroy_bind_group(raw) };
}
}
if !self.compute_pipes.is_empty() {
profiling::scope!("destroy_compute_pipelines");
for raw in self.compute_pipes.drain(..) {
device.destroy_compute_pipeline(raw);
unsafe { device.destroy_compute_pipeline(raw) };
}
}
if !self.render_pipes.is_empty() {
profiling::scope!("destroy_render_pipelines");
for raw in self.render_pipes.drain(..) {
device.destroy_render_pipeline(raw);
unsafe { device.destroy_render_pipeline(raw) };
}
}
if !self.bind_group_layouts.is_empty() {
profiling::scope!("destroy_bind_group_layouts");
for raw in self.bind_group_layouts.drain(..) {
device.destroy_bind_group_layout(raw);
unsafe { device.destroy_bind_group_layout(raw) };
}
}
if !self.pipeline_layouts.is_empty() {
profiling::scope!("destroy_pipeline_layouts");
for raw in self.pipeline_layouts.drain(..) {
device.destroy_pipeline_layout(raw);
unsafe { device.destroy_pipeline_layout(raw) };
}
}
if !self.query_sets.is_empty() {
profiling::scope!("destroy_query_sets");
for raw in self.query_sets.drain(..) {
device.destroy_query_set(raw);
unsafe { device.destroy_query_set(raw) };
}
}
}
Expand Down
Loading