Skip to content

Commit 85346df

Browse files
chore: use std::mem::size_of{,_val} s'more
As before, this is to minimize diffs. with Rust 1.80.
1 parent e1c0aed commit 85346df

File tree

30 files changed

+126
-111
lines changed

30 files changed

+126
-111
lines changed

examples/src/boids/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// adapted from https://github.com/austinEng/webgpu-samples/blob/master/src/examples/computeBoids.ts
33

44
use nanorand::{Rng, WyRand};
5-
use std::{borrow::Cow, mem};
5+
use std::{borrow::Cow, mem::size_of};
66
use wgpu::util::DeviceExt;
77

88
// number of boid particles to simulate
@@ -82,7 +82,7 @@ impl crate::framework::Example for Example {
8282
ty: wgpu::BufferBindingType::Uniform,
8383
has_dynamic_offset: false,
8484
min_binding_size: wgpu::BufferSize::new(
85-
(sim_param_data.len() * mem::size_of::<f32>()) as _,
85+
(sim_param_data.len() * size_of::<f32>()) as _,
8686
),
8787
},
8888
count: None,

examples/src/cube/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bytemuck::{Pod, Zeroable};
2-
use std::{borrow::Cow, f32::consts, mem};
2+
use std::{borrow::Cow, f32::consts, mem::size_of};
33
use wgpu::util::DeviceExt;
44

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

120120
let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {

examples/src/hello_compute/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{borrow::Cow, str::FromStr};
1+
use std::{borrow::Cow, mem::size_of_val, str::FromStr};
22
use wgpu::util::DeviceExt;
33

44
// Indicates a u32 overflow in an intermediate Collatz value
@@ -72,7 +72,7 @@ async fn execute_gpu_inner(
7272
});
7373

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

7777
// Instantiates buffer without data.
7878
// `usage` of buffer specifies how it can be used:

examples/src/hello_synchronization/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::mem::size_of_val;
2+
13
const ARR_SIZE: usize = 128;
24

35
struct ExecuteResults {
@@ -61,13 +63,13 @@ async fn execute(
6163

6264
let storage_buffer = device.create_buffer(&wgpu::BufferDescriptor {
6365
label: None,
64-
size: std::mem::size_of_val(local_patient_workgroup_results.as_slice()) as u64,
66+
size: size_of_val(local_patient_workgroup_results.as_slice()) as u64,
6567
usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_SRC,
6668
mapped_at_creation: false,
6769
});
6870
let output_staging_buffer = device.create_buffer(&wgpu::BufferDescriptor {
6971
label: None,
70-
size: std::mem::size_of_val(local_patient_workgroup_results.as_slice()) as u64,
72+
size: size_of_val(local_patient_workgroup_results.as_slice()) as u64,
7173
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
7274
mapped_at_creation: false,
7375
});
@@ -182,7 +184,7 @@ async fn get_data<T: bytemuck::Pod>(
182184
0,
183185
staging_buffer,
184186
0,
185-
std::mem::size_of_val(output) as u64,
187+
size_of_val(output) as u64,
186188
);
187189
queue.submit(Some(command_encoder.finish()));
188190
let buffer_slice = staging_buffer.slice(..);

examples/src/hello_workgroups/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//!
88
//! Only parts specific to this example will be commented.
99
10+
use std::mem::size_of_val;
11+
1012
use wgpu::util::DeviceExt;
1113

1214
async fn run() {
@@ -56,7 +58,7 @@ async fn run() {
5658
});
5759
let output_staging_buffer = device.create_buffer(&wgpu::BufferDescriptor {
5860
label: None,
59-
size: std::mem::size_of_val(&local_a) as u64,
61+
size: size_of_val(&local_a) as u64,
6062
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
6163
mapped_at_creation: false,
6264
});
@@ -169,7 +171,7 @@ async fn get_data<T: bytemuck::Pod>(
169171
0,
170172
staging_buffer,
171173
0,
172-
std::mem::size_of_val(output) as u64,
174+
size_of_val(output) as u64,
173175
);
174176
queue.submit(Some(command_encoder.finish()));
175177
let buffer_slice = staging_buffer.slice(..);

examples/src/mipmap/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bytemuck::{Pod, Zeroable};
2-
use std::{borrow::Cow, f32::consts, mem};
2+
use std::{borrow::Cow, f32::consts, mem::size_of};
33
use wgpu::util::DeviceExt;
44

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

5656
fn pipeline_statistics_offset() -> wgpu::BufferAddress {
57-
(mem::size_of::<TimestampQueries>() as wgpu::BufferAddress)
58-
.max(wgpu::QUERY_RESOLVE_BUFFER_ALIGNMENT)
57+
(size_of::<TimestampQueries>() as wgpu::BufferAddress).max(wgpu::QUERY_RESOLVE_BUFFER_ALIGNMENT)
5958
}
6059

6160
struct Example {
@@ -363,7 +362,7 @@ impl crate::framework::Example for Example {
363362
// This databuffer has to store all of the query results, 2 * passes timestamp queries
364363
// and 1 * passes statistics queries. Each query returns a u64 value.
365364
let buffer_size = pipeline_statistics_offset()
366-
+ mem::size_of::<PipelineStatisticsQueries>() as wgpu::BufferAddress;
365+
+ size_of::<PipelineStatisticsQueries>() as wgpu::BufferAddress;
367366
let data_buffer = device.create_buffer(&wgpu::BufferDescriptor {
368367
label: Some("query buffer"),
369368
size: buffer_size,
@@ -420,7 +419,7 @@ impl crate::framework::Example for Example {
420419
// This is guaranteed to be ready.
421420
let timestamp_view = query_sets
422421
.mapping_buffer
423-
.slice(..mem::size_of::<TimestampQueries>() as wgpu::BufferAddress)
422+
.slice(..size_of::<TimestampQueries>() as wgpu::BufferAddress)
424423
.get_mapped_range();
425424
let pipeline_stats_view = query_sets
426425
.mapping_buffer

examples/src/msaa_line/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! * Set the primitive_topology to PrimitiveTopology::LineList.
88
//! * Vertices and Indices describe the two points that make up a line.
99
10-
use std::{borrow::Cow, iter};
10+
use std::{borrow::Cow, iter, mem::size_of};
1111

1212
use bytemuck::{Pod, Zeroable};
1313
use wgpu::util::DeviceExt;
@@ -56,7 +56,7 @@ impl Example {
5656
entry_point: Some("vs_main"),
5757
compilation_options: Default::default(),
5858
buffers: &[wgpu::VertexBufferLayout {
59-
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
59+
array_stride: size_of::<Vertex>() as wgpu::BufferAddress,
6060
step_mode: wgpu::VertexStepMode::Vertex,
6161
attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4],
6262
}],

examples/src/shadow/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{borrow::Cow, f32::consts, iter, mem, ops::Range, sync::Arc};
1+
use std::{borrow::Cow, f32::consts, iter, mem::size_of, ops::Range, sync::Arc};
22

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

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

286-
let entity_uniform_size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
286+
let entity_uniform_size = size_of::<EntityUniforms>() as wgpu::BufferAddress;
287287
let num_entities = 1 + cube_descs.len() as wgpu::BufferAddress;
288288
// Make the `uniform_alignment` >= `entity_uniform_size` and aligned to `min_uniform_buffer_offset_alignment`.
289289
let uniform_alignment = {
@@ -427,8 +427,7 @@ impl crate::framework::Example for Example {
427427
target_view: shadow_target_views[1].take().unwrap(),
428428
},
429429
];
430-
let light_uniform_size =
431-
(Self::MAX_LIGHTS * mem::size_of::<LightRaw>()) as wgpu::BufferAddress;
430+
let light_uniform_size = (Self::MAX_LIGHTS * size_of::<LightRaw>()) as wgpu::BufferAddress;
432431
let light_storage_buf = device.create_buffer(&wgpu::BufferDescriptor {
433432
label: None,
434433
size: light_uniform_size,
@@ -454,7 +453,7 @@ impl crate::framework::Example for Example {
454453
});
455454

456455
let shadow_pass = {
457-
let uniform_size = mem::size_of::<GlobalUniforms>() as wgpu::BufferAddress;
456+
let uniform_size = size_of::<GlobalUniforms>() as wgpu::BufferAddress;
458457
// Create pipeline layout
459458
let bind_group_layout =
460459
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@@ -548,7 +547,7 @@ impl crate::framework::Example for Example {
548547
ty: wgpu::BufferBindingType::Uniform,
549548
has_dynamic_offset: false,
550549
min_binding_size: wgpu::BufferSize::new(
551-
mem::size_of::<GlobalUniforms>() as _,
550+
size_of::<GlobalUniforms>() as _,
552551
),
553552
},
554553
count: None,
@@ -737,7 +736,7 @@ impl crate::framework::Example for Example {
737736
for (i, light) in self.lights.iter().enumerate() {
738737
queue.write_buffer(
739738
&self.light_storage_buf,
740-
(i * mem::size_of::<LightRaw>()) as wgpu::BufferAddress,
739+
(i * size_of::<LightRaw>()) as wgpu::BufferAddress,
741740
bytemuck::bytes_of(&light.to_raw()),
742741
);
743742
}
@@ -757,7 +756,7 @@ impl crate::framework::Example for Example {
757756
// let's just copy it over to the shadow uniform buffer.
758757
encoder.copy_buffer_to_buffer(
759758
&self.light_storage_buf,
760-
(i * mem::size_of::<LightRaw>()) as wgpu::BufferAddress,
759+
(i * size_of::<LightRaw>()) as wgpu::BufferAddress,
761760
&self.shadow_pass.uniform_buf,
762761
0,
763762
64,

examples/src/skybox/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bytemuck::{Pod, Zeroable};
2-
use std::{borrow::Cow, f32::consts};
2+
use std::{borrow::Cow, f32::consts, mem::size_of};
33
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};
44

55
const IMAGE_SIZE: u32 = 256;
@@ -231,7 +231,7 @@ impl crate::framework::Example for Example {
231231
entry_point: Some("vs_entity"),
232232
compilation_options: Default::default(),
233233
buffers: &[wgpu::VertexBufferLayout {
234-
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
234+
array_stride: size_of::<Vertex>() as wgpu::BufferAddress,
235235
step_mode: wgpu::VertexStepMode::Vertex,
236236
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3],
237237
}],

examples/src/stencil_triangles/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bytemuck::{Pod, Zeroable};
22
use std::borrow::Cow;
3-
use std::mem;
3+
use std::mem::size_of;
44
use wgpu::util::DeviceExt;
55

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

0 commit comments

Comments
 (0)