Skip to content

Commit b326e41

Browse files
committed
ByteAddressableBuffer: add as_ref() to convert mutable to read-only
1 parent f624ef4 commit b326e41

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

crates/spirv-std/src/byte_addressable_buffer.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,30 @@ impl<'a> ByteAddressableBuffer<&'a mut [u32]> {
116116
Self { data }
117117
}
118118

119+
/// Create a non-mutable `ByteAddressableBuffer` from this mutable one.
120+
#[inline]
121+
pub fn as_ref(&self) -> ByteAddressableBuffer<&[u32]> {
122+
ByteAddressableBuffer { data: self.data }
123+
}
124+
119125
/// Loads an arbitrary type from the buffer. `byte_index` must be a
120126
/// multiple of 4.
121127
///
122128
/// # Safety
123129
/// See [`Self`].
130+
#[inline]
124131
pub unsafe fn load<T>(&self, byte_index: u32) -> T {
125-
bounds_check::<T>(self.data, byte_index);
126-
buffer_load_intrinsic(self.data, byte_index)
132+
self.as_ref().load(byte_index)
127133
}
128134

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

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

0 commit comments

Comments
 (0)