Skip to content

Commit

Permalink
ByteAddressableBuffer: add as_ref() to convert mutable to read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
Firestar99 committed Oct 10, 2024
1 parent f624ef4 commit b326e41
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/spirv-std/src/byte_addressable_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,30 @@ impl<'a> ByteAddressableBuffer<&'a mut [u32]> {
Self { data }
}

/// Create a non-mutable `ByteAddressableBuffer` from this mutable one.
#[inline]
pub fn as_ref(&self) -> ByteAddressableBuffer<&[u32]> {
ByteAddressableBuffer { data: self.data }
}

/// Loads an arbitrary type from the buffer. `byte_index` must be a
/// multiple of 4.
///
/// # Safety
/// See [`Self`].
#[inline]
pub unsafe fn load<T>(&self, byte_index: u32) -> T {
bounds_check::<T>(self.data, byte_index);
buffer_load_intrinsic(self.data, byte_index)
self.as_ref().load(byte_index)
}

/// Loads an arbitrary type from the buffer. `byte_index` must be a
/// multiple of 4.
///
/// # Safety
/// See [`Self`]. Additionally, bounds or alignment checking is not performed.
#[inline]
pub unsafe fn load_unchecked<T>(&self, byte_index: u32) -> T {
buffer_load_intrinsic(self.data, byte_index)
self.as_ref().load_unchecked(byte_index)
}

/// Stores an arbitrary type into the buffer. `byte_index` must be a
Expand Down

0 comments on commit b326e41

Please sign in to comment.