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
impl Buffer
Sourcepub fn in_use(&self) -> bool
pub fn in_use(&self) -> bool
Whether submitted GPU work still uses (reads or writes) the buffer.
Sourcepub fn contents(&self) -> Result<&[u8]>
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.
Sourcepub fn contents_mut(&mut self) -> Result<&mut [u8]>
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.
Sourcepub fn unsynchronized_ptr(&self) -> Result<(NonNull<u8>, usize)>
pub fn unsynchronized_ptr(&self) -> Result<(NonNull<u8>, usize)>
The bytes’ address and length, for a CPU write that submitted GPU work is ordered
after by other means (an Event it waits for), so the in-flight
guards that contents_mut checks do not apply. Blocks first
until the previous owner’s GPU work on reused memory has completed. The caller
writes through it only while no GPU work accesses the bytes and no other CPU
reference to them exists.