Skip to content
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
3 changes: 2 additions & 1 deletion examples/features/src/big_compute_buffers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ pub async fn execute_gpu_inner(
for staging_buffer in &staging_buffers {
let slice = staging_buffer.slice(..);
let mapped = slice.get_mapped_range();
data.extend_from_slice(bytemuck::cast_slice(&mapped));
let chunk: Vec<f32> = bytemuck::allocation::pod_collect_to_vec(&mapped);
data.extend_from_slice(&chunk);
drop(mapped);
staging_buffer.unmap();
}
Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/cooperative_matrix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ async fn execute(

// Convert result back to f32 for comparison
let result: Vec<f32> = if use_f16 {
let result_f16: &[f16] = bytemuck::cast_slice(&data);
let result_f16: Vec<f16> = bytemuck::allocation::pod_collect_to_vec(&data);
result_f16.iter().map(|x| x.to_f32()).collect()
} else {
bytemuck::cast_slice::<_, f32>(&data).to_vec()
bytemuck::allocation::pod_collect_to_vec(&data)
};

// Compute reference result on CPU for verification
Expand Down
4 changes: 3 additions & 1 deletion examples/features/src/hello_synchronization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ async fn get_data<T: bytemuck::Pod>(
buffer_slice.map_async(wgpu::MapMode::Read, move |r| sender.send(r).unwrap());
device.poll(wgpu::PollType::wait_indefinitely()).unwrap();
receiver.recv_async().await.unwrap().unwrap();
output.copy_from_slice(bytemuck::cast_slice(&buffer_slice.get_mapped_range()[..]));
let data: Vec<T> =
bytemuck::allocation::pod_collect_to_vec(&buffer_slice.get_mapped_range()[..]);
output.copy_from_slice(&data);
staging_buffer.unmap();
}

Expand Down
4 changes: 3 additions & 1 deletion examples/features/src/hello_workgroups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ async fn get_data<T: bytemuck::Pod>(
buffer_slice.map_async(wgpu::MapMode::Read, move |r| sender.send(r).unwrap());
device.poll(wgpu::PollType::wait_indefinitely()).unwrap();
receiver.recv_async().await.unwrap().unwrap();
output.copy_from_slice(bytemuck::cast_slice(&buffer_slice.get_mapped_range()[..]));
let data: Vec<T> =
bytemuck::allocation::pod_collect_to_vec(&buffer_slice.get_mapped_range()[..]);
output.copy_from_slice(&data);
staging_buffer.unmap();
}

Expand Down
3 changes: 2 additions & 1 deletion examples/features/src/repeated_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ async fn compute(local_buffer: &mut [u32], context: &WgpuContext) {
// NOW we can call get_mapped_range.
{
let view = buffer_slice.get_mapped_range();
local_buffer.copy_from_slice(bytemuck::cast_slice(&view));
let data: Vec<u32> = bytemuck::allocation::pod_collect_to_vec(&view);
local_buffer.copy_from_slice(&data);
}
log::info!("Results written to local buffer.");
// We need to make sure all `BufferView`'s are dropped before we do what we're about
Expand Down
2 changes: 1 addition & 1 deletion examples/features/src/timestamp_queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl Queries {
.destination_buffer
.slice(..(size_of::<u64>() as wgpu::BufferAddress * self.num_queries))
.get_mapped_range();
bytemuck::cast_slice(&timestamp_view).to_vec()
bytemuck::allocation::pod_collect_to_vec(&timestamp_view)
};

self.destination_buffer.unmap();
Expand Down
2 changes: 1 addition & 1 deletion examples/standalone/01_hello_compute/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rust-version = "1.87"
publish = false

[dependencies]
bytemuck = "1.22.0"
bytemuck = { version = "1.22.0", features = ["extern_crate_alloc"] }
env_logger = "0.11"
pollster = "0.4"
wgpu = "29.0.0"
4 changes: 2 additions & 2 deletions examples/standalone/01_hello_compute/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ fn main() {

// We can now read the data from the buffer.
let data = buffer_slice.get_mapped_range();
// Convert the data back to a slice of f32.
let result: &[f32] = bytemuck::cast_slice(&data);
// Convert the data back to f32 via an aligned copy.
let result: Vec<f32> = bytemuck::allocation::pod_collect_to_vec(&data);

// Print out the result.
println!("Result: {result:?}");
Expand Down
Loading