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

Yet more preempting of Rust 1.80 lints #6180

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
4 changes: 2 additions & 2 deletions examples/src/boids/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// adapted from https://github.com/austinEng/webgpu-samples/blob/master/src/examples/computeBoids.ts

use nanorand::{Rng, WyRand};
use std::{borrow::Cow, mem};
use std::{borrow::Cow, mem::size_of};
use wgpu::util::DeviceExt;

// number of boid particles to simulate
Expand Down Expand Up @@ -82,7 +82,7 @@ impl crate::framework::Example for Example {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: wgpu::BufferSize::new(
(sim_param_data.len() * mem::size_of::<f32>()) as _,
(sim_param_data.len() * size_of::<f32>()) as _,
),
},
count: None,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/cube/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, f32::consts, mem};
use std::{borrow::Cow, f32::consts, mem::size_of};
use wgpu::util::DeviceExt;

#[repr(C)]
Expand Down Expand Up @@ -114,7 +114,7 @@ impl crate::framework::Example for Example {
queue: &wgpu::Queue,
) -> Self {
// Create the vertex and index buffers
let vertex_size = mem::size_of::<Vertex>();
let vertex_size = size_of::<Vertex>();
let (vertex_data, index_data) = create_vertices();

let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
Expand Down
4 changes: 2 additions & 2 deletions examples/src/hello_compute/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, str::FromStr};
use std::{borrow::Cow, mem::size_of_val, str::FromStr};
use wgpu::util::DeviceExt;

// Indicates a u32 overflow in an intermediate Collatz value
Expand Down Expand Up @@ -72,7 +72,7 @@ async fn execute_gpu_inner(
});

// Gets the size in bytes of the buffer.
let size = std::mem::size_of_val(numbers) as wgpu::BufferAddress;
let size = size_of_val(numbers) as wgpu::BufferAddress;

// Instantiates buffer without data.
// `usage` of buffer specifies how it can be used:
Expand Down
8 changes: 5 additions & 3 deletions examples/src/hello_synchronization/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::mem::size_of_val;

const ARR_SIZE: usize = 128;

struct ExecuteResults {
Expand Down Expand Up @@ -61,13 +63,13 @@ async fn execute(

let storage_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: std::mem::size_of_val(local_patient_workgroup_results.as_slice()) as u64,
size: size_of_val(local_patient_workgroup_results.as_slice()) as u64,
usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_SRC,
mapped_at_creation: false,
});
let output_staging_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: std::mem::size_of_val(local_patient_workgroup_results.as_slice()) as u64,
size: size_of_val(local_patient_workgroup_results.as_slice()) as u64,
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
mapped_at_creation: false,
});
Expand Down Expand Up @@ -182,7 +184,7 @@ async fn get_data<T: bytemuck::Pod>(
0,
staging_buffer,
0,
std::mem::size_of_val(output) as u64,
size_of_val(output) as u64,
);
queue.submit(Some(command_encoder.finish()));
let buffer_slice = staging_buffer.slice(..);
Expand Down
6 changes: 4 additions & 2 deletions examples/src/hello_workgroups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//!
//! Only parts specific to this example will be commented.

use std::mem::size_of_val;

use wgpu::util::DeviceExt;

async fn run() {
Expand Down Expand Up @@ -56,7 +58,7 @@ async fn run() {
});
let output_staging_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: std::mem::size_of_val(&local_a) as u64,
size: size_of_val(&local_a) as u64,
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
mapped_at_creation: false,
});
Expand Down Expand Up @@ -169,7 +171,7 @@ async fn get_data<T: bytemuck::Pod>(
0,
staging_buffer,
0,
std::mem::size_of_val(output) as u64,
size_of_val(output) as u64,
);
queue.submit(Some(command_encoder.finish()));
let buffer_slice = staging_buffer.slice(..);
Expand Down
9 changes: 4 additions & 5 deletions examples/src/mipmap/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, f32::consts, mem};
use std::{borrow::Cow, f32::consts, mem::size_of};
use wgpu::util::DeviceExt;

const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
Expand Down Expand Up @@ -54,8 +54,7 @@ type TimestampQueries = [TimestampData; MIP_PASS_COUNT as usize];
type PipelineStatisticsQueries = [u64; MIP_PASS_COUNT as usize];

fn pipeline_statistics_offset() -> wgpu::BufferAddress {
(mem::size_of::<TimestampQueries>() as wgpu::BufferAddress)
.max(wgpu::QUERY_RESOLVE_BUFFER_ALIGNMENT)
(size_of::<TimestampQueries>() as wgpu::BufferAddress).max(wgpu::QUERY_RESOLVE_BUFFER_ALIGNMENT)
}

struct Example {
Expand Down Expand Up @@ -363,7 +362,7 @@ impl crate::framework::Example for Example {
// This databuffer has to store all of the query results, 2 * passes timestamp queries
// and 1 * passes statistics queries. Each query returns a u64 value.
let buffer_size = pipeline_statistics_offset()
+ mem::size_of::<PipelineStatisticsQueries>() as wgpu::BufferAddress;
+ size_of::<PipelineStatisticsQueries>() as wgpu::BufferAddress;
let data_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("query buffer"),
size: buffer_size,
Expand Down Expand Up @@ -420,7 +419,7 @@ impl crate::framework::Example for Example {
// This is guaranteed to be ready.
let timestamp_view = query_sets
.mapping_buffer
.slice(..mem::size_of::<TimestampQueries>() as wgpu::BufferAddress)
.slice(..size_of::<TimestampQueries>() as wgpu::BufferAddress)
.get_mapped_range();
let pipeline_stats_view = query_sets
.mapping_buffer
Expand Down
4 changes: 2 additions & 2 deletions examples/src/msaa_line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! * Set the primitive_topology to PrimitiveTopology::LineList.
//! * Vertices and Indices describe the two points that make up a line.

use std::{borrow::Cow, iter};
use std::{borrow::Cow, iter, mem::size_of};

use bytemuck::{Pod, Zeroable};
use wgpu::util::DeviceExt;
Expand Down Expand Up @@ -56,7 +56,7 @@ impl Example {
entry_point: Some("vs_main"),
compilation_options: Default::default(),
buffers: &[wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
array_stride: size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4],
}],
Expand Down
17 changes: 8 additions & 9 deletions examples/src/shadow/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, f32::consts, iter, mem, ops::Range, sync::Arc};
use std::{borrow::Cow, f32::consts, iter, mem::size_of, ops::Range, sync::Arc};

use bytemuck::{Pod, Zeroable};
use wgpu::util::{align_to, DeviceExt};
Expand Down Expand Up @@ -219,7 +219,7 @@ impl crate::framework::Example for Example {
&& device.limits().max_storage_buffers_per_shader_stage > 0;

// Create the vertex and index buffers
let vertex_size = mem::size_of::<Vertex>();
let vertex_size = size_of::<Vertex>();
let (cube_vertex_data, cube_index_data) = create_cube();
let cube_vertex_buf = Arc::new(device.create_buffer_init(
&wgpu::util::BufferInitDescriptor {
Expand Down Expand Up @@ -283,7 +283,7 @@ impl crate::framework::Example for Example {
},
];

let entity_uniform_size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
let entity_uniform_size = size_of::<EntityUniforms>() as wgpu::BufferAddress;
let num_entities = 1 + cube_descs.len() as wgpu::BufferAddress;
// Make the `uniform_alignment` >= `entity_uniform_size` and aligned to `min_uniform_buffer_offset_alignment`.
let uniform_alignment = {
Expand Down Expand Up @@ -427,8 +427,7 @@ impl crate::framework::Example for Example {
target_view: shadow_target_views[1].take().unwrap(),
},
];
let light_uniform_size =
(Self::MAX_LIGHTS * mem::size_of::<LightRaw>()) as wgpu::BufferAddress;
let light_uniform_size = (Self::MAX_LIGHTS * size_of::<LightRaw>()) as wgpu::BufferAddress;
let light_storage_buf = device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: light_uniform_size,
Expand All @@ -454,7 +453,7 @@ impl crate::framework::Example for Example {
});

let shadow_pass = {
let uniform_size = mem::size_of::<GlobalUniforms>() as wgpu::BufferAddress;
let uniform_size = size_of::<GlobalUniforms>() as wgpu::BufferAddress;
// Create pipeline layout
let bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
Expand Down Expand Up @@ -548,7 +547,7 @@ impl crate::framework::Example for Example {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: wgpu::BufferSize::new(
mem::size_of::<GlobalUniforms>() as _,
size_of::<GlobalUniforms>() as _,
),
},
count: None,
Expand Down Expand Up @@ -737,7 +736,7 @@ impl crate::framework::Example for Example {
for (i, light) in self.lights.iter().enumerate() {
queue.write_buffer(
&self.light_storage_buf,
(i * mem::size_of::<LightRaw>()) as wgpu::BufferAddress,
(i * size_of::<LightRaw>()) as wgpu::BufferAddress,
bytemuck::bytes_of(&light.to_raw()),
);
}
Expand All @@ -757,7 +756,7 @@ impl crate::framework::Example for Example {
// let's just copy it over to the shadow uniform buffer.
encoder.copy_buffer_to_buffer(
&self.light_storage_buf,
(i * mem::size_of::<LightRaw>()) as wgpu::BufferAddress,
(i * size_of::<LightRaw>()) as wgpu::BufferAddress,
&self.shadow_pass.uniform_buf,
0,
64,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/skybox/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, f32::consts};
use std::{borrow::Cow, f32::consts, mem::size_of};
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};

const IMAGE_SIZE: u32 = 256;
Expand Down Expand Up @@ -231,7 +231,7 @@ impl crate::framework::Example for Example {
entry_point: Some("vs_entity"),
compilation_options: Default::default(),
buffers: &[wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
array_stride: size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3],
}],
Expand Down
4 changes: 2 additions & 2 deletions examples/src/stencil_triangles/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytemuck::{Pod, Zeroable};
use std::borrow::Cow;
use std::mem;
use std::mem::size_of;
use wgpu::util::DeviceExt;

#[repr(C)]
Expand Down Expand Up @@ -31,7 +31,7 @@ impl crate::framework::Example for Example {
_queue: &wgpu::Queue,
) -> Self {
// Create the vertex and index buffers
let vertex_size = mem::size_of::<Vertex>();
let vertex_size = size_of::<Vertex>();
let outer_vertices = [vertex(-1.0, -1.0), vertex(1.0, -1.0), vertex(0.0, 1.0)];
let mask_vertices = [vertex(-0.5, 0.0), vertex(0.0, -1.0), vertex(0.5, 0.0)];

Expand Down
4 changes: 3 additions & 1 deletion examples/src/storage_texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//! A lot of things aren't explained here via comments. See hello-compute and
//! repeated-compute for code that is more thoroughly commented.

use std::mem::size_of_val;

#[cfg(not(target_arch = "wasm32"))]
use crate::utils::output_image_native;
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -64,7 +66,7 @@ async fn run(_path: Option<String>) {
let storage_texture_view = storage_texture.create_view(&wgpu::TextureViewDescriptor::default());
let output_staging_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: std::mem::size_of_val(&texture_data[..]) as u64,
size: size_of_val(&texture_data[..]) as u64,
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
mapped_at_creation: false,
});
Expand Down
7 changes: 5 additions & 2 deletions examples/src/texture_arrays/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use bytemuck::{Pod, Zeroable};
use std::num::{NonZeroU32, NonZeroU64};
use std::{
mem::size_of,
num::{NonZeroU32, NonZeroU64},
};
use wgpu::util::DeviceExt;

#[repr(C)]
Expand Down Expand Up @@ -124,7 +127,7 @@ impl crate::framework::Example for Example {

println!("Using fragment entry point '{fragment_entry_point}'");

let vertex_size = std::mem::size_of::<Vertex>();
let vertex_size = size_of::<Vertex>();
let vertex_data = create_vertices();
let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Vertex Buffer"),
Expand Down
8 changes: 5 additions & 3 deletions examples/src/timestamp_queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
//! The period, i.e. the unit of time, of the timestamps in wgpu is undetermined and needs to be queried with `wgpu::Queue::get_timestamp_period`
//! in order to get comparable results.

use std::mem::size_of;

use wgpu::util::DeviceExt;

struct Queries {
Expand Down Expand Up @@ -123,13 +125,13 @@ impl Queries {
}),
resolve_buffer: device.create_buffer(&wgpu::BufferDescriptor {
label: Some("query resolve buffer"),
size: std::mem::size_of::<u64>() as u64 * num_queries,
size: size_of::<u64>() as u64 * num_queries,
usage: wgpu::BufferUsages::COPY_SRC | wgpu::BufferUsages::QUERY_RESOLVE,
mapped_at_creation: false,
}),
destination_buffer: device.create_buffer(&wgpu::BufferDescriptor {
label: Some("query dest buffer"),
size: std::mem::size_of::<u64>() as u64 * num_queries,
size: size_of::<u64>() as u64 * num_queries,
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
mapped_at_creation: false,
}),
Expand Down Expand Up @@ -164,7 +166,7 @@ impl Queries {
let timestamps = {
let timestamp_view = self
.destination_buffer
.slice(..(std::mem::size_of::<u64>() as wgpu::BufferAddress * self.num_queries))
.slice(..(size_of::<u64>() as wgpu::BufferAddress * self.num_queries))
.get_mapped_range();
bytemuck::cast_slice(&timestamp_view).to_vec()
};
Expand Down
4 changes: 2 additions & 2 deletions examples/src/uniform_values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! The usage of the uniform buffer within the shader itself is pretty self-explanatory given
//! some understanding of WGSL.

use std::sync::Arc;
use std::{mem::size_of, sync::Arc};
// We won't bring StorageBuffer into scope as that might be too easy to confuse
// with actual GPU-allocated WGPU storage buffers.
use encase::ShaderType;
Expand Down Expand Up @@ -132,7 +132,7 @@ impl WgpuContext {
// (2)
let uniform_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: std::mem::size_of::<AppState>() as u64,
size: size_of::<AppState>() as u64,
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
Expand Down
Loading
Loading