Skip to content

Commit

Permalink
Fix mesh creation failing to copy index data. (#1473)
Browse files Browse the repository at this point in the history
* fix wrong index data size
* fix dubious `copy_to_buffer` copy size on `CpuWriteGpuReadBuffer`
Fixes #1467
  • Loading branch information
Wumpf authored Mar 2, 2023
1 parent faa65b6 commit 35ea4a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions crates/re_renderer/src/allocator/cpu_write_gpu_read_belt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,24 @@ where

/// Copies the entire buffer to another buffer and drops it.
pub fn copy_to_buffer(
mut self,
self,
encoder: &mut wgpu::CommandEncoder,
destination: &GpuBuffer,
destination_offset: wgpu::BufferAddress,
) {
let copy_size = (std::mem::size_of::<T>() * self.unwritten_element_range.start) as u64;

// Wgpu does validation as well, but in debug mode we want to panic if the buffer doesn't fit.
debug_assert!(copy_size <= destination_offset + destination.size(),
"Target buffer has a size of {}, can't write {copy_size} bytes with an offset of {destination_offset}!",
destination.size());

encoder.copy_buffer_to_buffer(
&self.chunk_buffer,
self.byte_offset_in_chunk_buffer,
destination,
destination_offset,
self.write_view.deref_mut().len() as u64,
copy_size,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl GpuMesh {
vertex_buffer_combined
};

let index_buffer_size = std::mem::size_of_val(data.indices.as_slice()) as u64;
let index_buffer_size = (std::mem::size_of::<u32>() * data.indices.len()) as u64;
let index_buffer = {
let index_buffer = pools.buffers.alloc(
device,
Expand Down

0 comments on commit 35ea4a3

Please sign in to comment.