Skip to content

Commit

Permalink
chore: remove std::mem::* imports now unnecessary with Rust 1.80
Browse files Browse the repository at this point in the history
`std::mem::{size,align}_of{,_val}` was added to `std::prelude` in Rust
1.80; see
[`rust`#123168](rust-lang/rust#123168).
  • Loading branch information
ErichDonGubler committed Aug 23, 2024
1 parent c9e137c commit b8278cb
Show file tree
Hide file tree
Showing 39 changed files with 90 additions and 117 deletions.
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;
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};
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
2 changes: 1 addition & 1 deletion examples/src/hello_compute/mod.rs
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions examples/src/hello_synchronization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,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 +182,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};
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
2 changes: 0 additions & 2 deletions examples/src/repeated_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
//! hello-compute example does not such as mapping buffers
//! and why use the async channels.

use std::mem::size_of_val;

const OVERFLOW: u32 = 0xffffffff;

async fn run() {
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, 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
2 changes: 1 addition & 1 deletion examples/src/skybox/mod.rs
Original file line number Diff line number Diff line change
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
3 changes: 1 addition & 2 deletions examples/src/stencil_triangles/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bytemuck::{Pod, Zeroable};
use std::borrow::Cow;
use std::mem;
use wgpu::util::DeviceExt;

#[repr(C)]
Expand Down Expand Up @@ -31,7 +30,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
2 changes: 1 addition & 1 deletion examples/src/texture_arrays/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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
6 changes: 3 additions & 3 deletions examples/src/timestamp_queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,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 +164,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
2 changes: 1 addition & 1 deletion examples/src/uniform_values/mod.rs
Original file line number Diff line number Diff line change
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
18 changes: 9 additions & 9 deletions examples/src/water/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod point_gen;
use bytemuck::{Pod, Zeroable};
use glam::Vec3;
use nanorand::{Rng, WyRand};
use std::{borrow::Cow, f32::consts, iter, mem};
use std::{borrow::Cow, f32::consts, iter};
use wgpu::util::DeviceExt;

///
Expand Down Expand Up @@ -273,12 +273,12 @@ impl crate::framework::Example for Example {
queue: &wgpu::Queue,
) -> Self {
// Size of one water vertex
let water_vertex_size = mem::size_of::<point_gen::WaterVertexAttributes>();
let water_vertex_size = size_of::<point_gen::WaterVertexAttributes>();

let water_vertices = point_gen::HexWaterMesh::generate(SIZE).generate_points();

// Size of one terrain vertex
let terrain_vertex_size = mem::size_of::<point_gen::TerrainVertexAttributes>();
let terrain_vertex_size = size_of::<point_gen::TerrainVertexAttributes>();

// Noise generation
let terrain_noise = noise::OpenSimplex::default();
Expand Down Expand Up @@ -359,7 +359,7 @@ impl crate::framework::Example for Example {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: wgpu::BufferSize::new(
mem::size_of::<WaterUniforms>() as _,
size_of::<WaterUniforms>() as _,
),
},
count: None,
Expand Down Expand Up @@ -415,7 +415,7 @@ impl crate::framework::Example for Example {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: wgpu::BufferSize::new(
mem::size_of::<TerrainUniforms>() as _,
size_of::<TerrainUniforms>() as _
),
},
count: None,
Expand All @@ -440,21 +440,21 @@ impl crate::framework::Example for Example {

let water_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Water Uniforms"),
size: mem::size_of::<WaterUniforms>() as _,
size: size_of::<WaterUniforms>() as _,
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});

let terrain_normal_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Normal Terrain Uniforms"),
size: mem::size_of::<TerrainUniforms>() as _,
size: size_of::<TerrainUniforms>() as _,
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});

let terrain_flipped_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Flipped Terrain Uniforms"),
size: mem::size_of::<TerrainUniforms>() as _,
size: size_of::<TerrainUniforms>() as _,
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
Expand Down Expand Up @@ -712,7 +712,7 @@ impl crate::framework::Example for Example {
let (water_sin, water_cos) = ((self.current_frame as f32) / 600.0).sin_cos();
queue.write_buffer(
&self.water_uniform_buf,
mem::size_of::<[f32; 16]>() as wgpu::BufferAddress * 2,
size_of::<[f32; 16]>() as wgpu::BufferAddress * 2,
bytemuck::cast_slice(&[water_sin, water_cos]),
);

Expand Down
2 changes: 1 addition & 1 deletion naga/src/back/msl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,6 @@ pub fn write_string(

#[test]
fn test_error_size() {
use std::mem::size_of;
use size_of;
assert_eq!(size_of::<Error>(), 32);
}
2 changes: 1 addition & 1 deletion player/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl ExpectedData {
fn len(&self) -> usize {
match self {
ExpectedData::Raw(vec) => vec.len(),
ExpectedData::U64(vec) => vec.len() * std::mem::size_of::<u64>(),
ExpectedData::U64(vec) => vec.len() * size_of::<u64>(),
ExpectedData::File(_, size) => *size,
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/compute_pass_ownership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup {
source: wgpu::ShaderSource::Wgsl(SHADER_SRC.into()),
});

let buffer_size = 4 * std::mem::size_of::<f32>() as u64;
let buffer_size = 4 * size_of::<f32>() as u64;

let bgl = ctx
.device
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/occlusion_query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new()
// Resolve query set to buffer
let query_buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Query buffer"),
size: std::mem::size_of::<u64>() as u64 * 3,
size: size_of::<u64>() as u64 * 3,
usage: wgpu::BufferUsages::QUERY_RESOLVE | wgpu::BufferUsages::COPY_SRC,
mapped_at_creation: false,
});
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/render_pass_ownership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup {
source: wgpu::ShaderSource::Wgsl(SHADER_SRC.into()),
});

let buffer_size = 4 * std::mem::size_of::<f32>() as u64;
let buffer_size = 4 * size_of::<f32>() as u64;

let bgl = ctx
.device
Expand Down Expand Up @@ -418,7 +418,7 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup {
let vertex_buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
label: Some("vertex_buffer"),
usage: wgpu::BufferUsages::VERTEX,
size: std::mem::size_of::<u32>() as u64 * vertex_count as u64,
size: size_of::<u32>() as u64 * vertex_count as u64,
mapped_at_creation: false,
});

Expand Down
6 changes: 2 additions & 4 deletions tests/tests/subgroup_operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static SUBGROUP_OPERATIONS: GpuTestConfiguration = GpuTestConfiguration::new()

let storage_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: THREAD_COUNT * std::mem::size_of::<u32>() as u64,
size: THREAD_COUNT * size_of::<u32>() as u64,
usage: wgpu::BufferUsages::STORAGE
| wgpu::BufferUsages::COPY_DST
| wgpu::BufferUsages::COPY_SRC,
Expand All @@ -50,9 +50,7 @@ static SUBGROUP_OPERATIONS: GpuTestConfiguration = GpuTestConfiguration::new()
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only: false },
has_dynamic_offset: false,
min_binding_size: NonZeroU64::new(
THREAD_COUNT * std::mem::size_of::<u32>() as u64,
),
min_binding_size: NonZeroU64::new(THREAD_COUNT * size_of::<u32>() as u64),
},
count: None,
}],
Expand Down
Loading

0 comments on commit b8278cb

Please sign in to comment.