spirv_std::byte_addressable_buffer

Struct ByteAddressableBuffer

Source
#[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]>

Source

pub fn from_slice(data: &'a [u32]) -> Self

Creates a ByteAddressableBuffer from the untyped blob of data.

Source

pub unsafe fn load<T>(&self, byte_index: u32) -> T

Loads an arbitrary type from the buffer. byte_index must be a multiple of 4.

§Safety

See Self.

Source

pub unsafe fn load_unchecked<T>(&self, byte_index: u32) -> T

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.

Source§

impl<'a> ByteAddressableBuffer<&'a mut [u32]>

Source

pub fn from_mut_slice(data: &'a mut [u32]) -> Self

Creates a ByteAddressableBuffer from the untyped blob of data.

Source

pub fn as_ref(&self) -> ByteAddressableBuffer<&[u32]>

Create a non-mutable ByteAddressableBuffer from this mutable one.

Source

pub unsafe fn load<T>(&self, byte_index: u32) -> T

Loads an arbitrary type from the buffer. byte_index must be a multiple of 4.

§Safety

See Self.

Source

pub unsafe fn load_unchecked<T>(&self, byte_index: u32) -> T

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.

Source

pub unsafe fn store<T>(&mut self, byte_index: u32, value: T)

Stores an arbitrary type into the buffer. byte_index must be a multiple of 4.

§Safety

See Self.

Source

pub unsafe fn store_unchecked<T>(&mut self, byte_index: u32, value: T)

Stores an arbitrary type into the buffer. byte_index must be a multiple of 4.

§Safety

See Self. Additionally, bounds or alignment checking is not performed.

Auto Trait Implementations§

§

impl<T> Freeze for ByteAddressableBuffer<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ByteAddressableBuffer<T>
where T: RefUnwindSafe,

§

impl<T> Send for ByteAddressableBuffer<T>
where T: Send,

§

impl<T> Sync for ByteAddressableBuffer<T>
where T: Sync,

§

impl<T> Unpin for ByteAddressableBuffer<T>
where T: Unpin,

§

impl<T> UnwindSafe for ByteAddressableBuffer<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.