Skip to content

Commit

Permalink
comment & naming fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Apr 3, 2023
1 parent 1fba25d commit 6543207
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions crates/re_renderer/src/wgpu_resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Texture2DBufferInfo {

/// Removes the padding from a buffer containing gpu texture data.
///
/// The buffer have the expected size for a padded buffer to hold the texture data.
/// The passed in buffer is to be expected to be exactly of size [Texture2DBufferInfo::buffer_size_padded].
///
/// Note that if you're passing in gpu data, there no alignment guarantees on the returned slice,
/// do NOT convert it using [`bytemuck`]. Use [`Texture2DBufferInfo::remove_padding_and_convert`] instead.
Expand All @@ -189,7 +189,7 @@ impl Texture2DBufferInfo {

/// Removes the padding from a buffer containing gpu texture data and remove convert to a given type.
///
/// The buffer have the expected size for a padded buffer to hold the texture data.
/// The passed in buffer is to be expected to be exactly of size [Texture2DBufferInfo::buffer_size_padded].
///
/// The unpadded row size is expected to be a multiple of the size of the target type.
/// (Which means that, while uncommon, it technically doesn't need to be as big as a block in the pixel - this can be useful for e.g. packing wide bitfields)
Expand All @@ -207,13 +207,15 @@ impl Texture2DBufferInfo {
T::zeroed();
(self.num_rows() * self.bytes_per_row_unpadded / std::mem::size_of::<T>() as u32)
as usize
]; // Consider using unsafe set_len() instead of vec![] to avoid zeroing the memory.
let unpaadded_buffer_u8 = bytemuck::cast_slice_mut(&mut unpadded_buffer);
]; // TODO(andreas): Consider using unsafe set_len() instead of vec![] to avoid zeroing the memory.

// The copy has to happen on a u8 slice, because any other type would assume some alignment that we can't guarantee because of the above.
let unpadded_buffer_u8_view = bytemuck::cast_slice_mut(&mut unpadded_buffer);

for row in 0..self.num_rows() {
let offset_padded = (self.bytes_per_row_padded * row) as usize;
let offset_unpadded = (self.bytes_per_row_unpadded * row) as usize;
unpaadded_buffer_u8
unpadded_buffer_u8_view
[offset_unpadded..(offset_unpadded + self.bytes_per_row_unpadded as usize)]
.copy_from_slice(
&buffer[offset_padded..(offset_padded + self.bytes_per_row_unpadded as usize)],
Expand Down

0 comments on commit 6543207

Please sign in to comment.