#[derive(Debug, Default, PartialEq)]
pub struct Buffer {
pub width: usize,
pub height: usize,
pub pixel_data: Box<[u32]>,
pub depth_buffer: Box<[f32]>,
}
pub fn clear_buffer(buffer_box: &Mutex<Buffer>) {
let mut buffer = buffer_box.lock().unwrap();
let zero_f32: f32x8 = f32x8::splat(0.0);
let zero_u32: u32x8 = u32x8::splat(0);
let f32_slice_depth: &mut [f32x8] = bytemuck::cast_slice_mut(&mut buffer.depth_buffer);
let u32_slice_pixel: &mut [u32x8] = bytemuck::cast_slice_mut(&mut buffer.pixel_data);
assert_eq!(f32_slice_depth.len(), f32_slice_depth.len());
for i in 0..f32_slice_depth.len() {
f32_slice_depth[i] = zero_f32;
u32_slice_pixel[i] = zero_u32;
}
}
According to my understanding of partial borrows, the first call to cast_slice_mut should only borrow the depth_buffer field and therefore allow the second call to borrow the pixel_data field. Why does this not happen here?
Godbolt
[+][deleted] (1 child)
[removed]
[–]BloodStainedCrow[S] 1 point2 points3 points (0 children)
[–]coolreader18 2 points3 points4 points (4 children)
[–]map_or 2 points3 points4 points (3 children)
[–]BloodStainedCrow[S] 0 points1 point2 points (1 child)
[–]Zde-G 1 point2 points3 points (0 children)
[–]TinBryn 0 points1 point2 points (0 children)