Skip to main content

Buffer

Struct Buffer 

Source
pub struct Buffer { /* private fields */ }
Expand description

GPU memory in unified (shared) storage: the CPU reads and writes it in place.

Buffers come from the device’s caching allocator and return to it when dropped. Hazard tracking is disabled at the Metal level (as in MLX); nuvec orders accesses itself. CPU access is refused while submitted GPU work uses the buffer, and GPU writes require &mut Buffer, so the CPU and the GPU never race on it.

Implementations§

Source§

impl Buffer

Source

pub fn len(&self) -> usize

Size in bytes.

Source

pub fn is_empty(&self) -> bool

Whether the buffer holds no bytes.

Source

pub fn in_use(&self) -> bool

Whether submitted GPU work still uses (reads or writes) the buffer.

Source

pub fn contents(&self) -> Result<&[u8]>

The bytes, if no submitted GPU work writes the buffer (concurrent GPU reads are fine). For reused memory (Device::new_gpu_buffer) whose previous owner’s GPU work is still running, it first blocks until that work has completed.

Source

pub fn contents_mut(&mut self) -> Result<&mut [u8]>

The bytes, mutably, if no submitted GPU work uses (reads or writes) the buffer and it is not a read-only mapped file.

Source

pub fn is_mapped(&self) -> bool

Whether the buffer is a read-only mapped file.

Trait Implementations§

Source§

impl Debug for Buffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Buffer

Source§

fn drop(&mut self)

Returns the memory to the allocator’s cache at once, with the hazard state of GPU work that still uses it (only GPU work reuses it before that work completes). Runs in an autorelease pool: a Metal buffer’s deallocation autoreleases objects.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Buffer

Source§

impl Sync for Buffer

Auto Trait Implementations§

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> AutoreleaseSafe for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.