#[repr(transparent)]pub struct ByteAddressableBuffer<T> {
pub data: T,
}
Expand description
ByteAddressableBuffer
is a view to an untyped blob of data, allowing
loads and stores of arbitrary basic data types at arbitrary indices.
§Alignment
All data must be aligned to size 4, each element within the data (e.g.
struct fields) must have a size and alignment of a multiple of 4, and the
byte_index
passed to load and store must be a multiple of 4. Technically
it is not a byte addressable buffer, but rather a word buffer, but this
naming and behavior was inherited from HLSL (where it’s UB to pass in an
index not a multiple of 4).
§Safety
Using these functions allows reading a different type from the buffer than
was originally written (by a previous store()
or the host API), allowing
all sorts of safety guarantees to be bypassed, making it effectively a
transmute.
Fields§
§data: T
The underlying array of bytes, able to be directly accessed.
Implementations§
Source§impl<'a> ByteAddressableBuffer<&'a [u32]>
impl<'a> ByteAddressableBuffer<&'a [u32]>
Sourcepub fn from_slice(data: &'a [u32]) -> Self
pub fn from_slice(data: &'a [u32]) -> Self
Creates a ByteAddressableBuffer
from the untyped blob of data.
Sourcepub unsafe fn load_unchecked<T>(&self, byte_index: u32) -> T
pub unsafe fn load_unchecked<T>(&self, byte_index: u32) -> T
Source§impl<'a> ByteAddressableBuffer<&'a mut [u32]>
impl<'a> ByteAddressableBuffer<&'a mut [u32]>
Sourcepub fn from_mut_slice(data: &'a mut [u32]) -> Self
pub fn from_mut_slice(data: &'a mut [u32]) -> Self
Creates a ByteAddressableBuffer
from the untyped blob of data.
Sourcepub fn as_ref(&self) -> ByteAddressableBuffer<&[u32]>
pub fn as_ref(&self) -> ByteAddressableBuffer<&[u32]>
Create a non-mutable ByteAddressableBuffer
from this mutable one.