Skip to content

Commit

Permalink
Another attempt at a fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dfellis committed Nov 7, 2024
1 parent 5a94996 commit 80482c3
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions alan_std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,11 +958,7 @@ pub fn gpu_run(gg: &GPGPU) {

pub fn read_buffer<T: std::clone::Clone>(b: &GBuffer) -> Vec<T> {
let g = gpu();
let temp_buffer = create_empty_buffer(
&mut map_read_buffer_type(),
&mut b.size().try_into().unwrap(),
&1, // We are getting the size in bytes above
);
let temp_buffer = create_empty_buffer(&map_read_buffer_type(), &bufferlen(b), &b.element_size);
let mut encoder = g
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
Expand All @@ -976,8 +972,9 @@ pub fn read_buffer<T: std::clone::Clone>(b: &GBuffer) -> Vec<T> {
let data = temp_slice.get_mapped_range();
let data_ptr = data.as_ptr();
let data_len = data.len() / (b.element_size as usize);
let data_i32: &[T] = unsafe { std::slice::from_raw_parts(data_ptr as *const T, data_len) };
let result = data_i32.to_vec();
let data_slice: &[T] =
unsafe { std::slice::from_raw_parts(data_ptr as *const T, data_len) };
let result = data_slice.to_vec();
drop(data);
temp_buffer.unmap();
result
Expand Down

0 comments on commit 80482c3

Please sign in to comment.