pub struct Buffer(/* private fields */);Expand description
A buffer resource that stores data for shader access.
C++ equivalent: MTL::Buffer
Buffers can contain any type of data: vertex data, uniform data, texture data, or any other data that shaders need to access.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn length(&self) -> UInteger
pub fn length(&self) -> UInteger
Get the length of the buffer in bytes.
C++ equivalent: NS::UInteger length() const
Sourcepub fn contents(&self) -> Option<*mut c_void>
pub fn contents(&self) -> Option<*mut c_void>
Get a CPU-accessible pointer to the buffer’s contents.
Returns None if the buffer is not CPU-accessible (e.g., private storage mode).
C++ equivalent: void* contents()
Sourcepub fn did_modify_range(&self, location: UInteger, length: UInteger)
pub fn did_modify_range(&self, location: UInteger, length: UInteger)
Notify Metal that the CPU has modified the contents of the buffer.
Call this after modifying the buffer’s contents on the CPU to ensure the GPU sees the updated data.
C++ equivalent: void didModifyRange(NS::Range range)
Sourcepub fn gpu_address(&self) -> u64
pub fn gpu_address(&self) -> u64
Get the GPU address for bindless access.
This returns the virtual address of the buffer in GPU memory, which can be used for bindless resource access in shaders.
C++ equivalent: uint64_t gpuAddress() const
Sourcepub unsafe fn new_texture(
&self,
descriptor: *const c_void,
offset: UInteger,
bytes_per_row: UInteger,
) -> Option<Texture>
pub unsafe fn new_texture( &self, descriptor: *const c_void, offset: UInteger, bytes_per_row: UInteger, ) -> Option<Texture>
Create a texture that shares the buffer’s storage.
C++ equivalent: Texture* newTexture(const TextureDescriptor*, NS::UInteger offset, NS::UInteger bytesPerRow)
§Safety
The descriptor pointer must be valid.
Sourcepub fn new_tensor(
&self,
descriptor: &TensorDescriptor,
offset: UInteger,
bytes_per_row: UInteger,
) -> Option<Tensor>
pub fn new_tensor( &self, descriptor: &TensorDescriptor, offset: UInteger, bytes_per_row: UInteger, ) -> Option<Tensor>
Create a tensor that shares the buffer’s storage.
C++ equivalent: Tensor* newTensor(const TensorDescriptor*, NS::UInteger offset, NS::UInteger bytesPerRow)
Sourcepub fn add_debug_marker(
&self,
marker: &str,
location: UInteger,
length: UInteger,
)
pub fn add_debug_marker( &self, marker: &str, location: UInteger, length: UInteger, )
Add a debug marker to the buffer.
C++ equivalent: void addDebugMarker(const NS::String*, NS::Range)
Sourcepub fn remove_all_debug_markers(&self)
pub fn remove_all_debug_markers(&self)
Remove all debug markers from the buffer.
C++ equivalent: void removeAllDebugMarkers()
Sourcepub fn remote_storage_buffer(&self) -> Option<Buffer>
pub fn remote_storage_buffer(&self) -> Option<Buffer>
Get a remote storage buffer (for cross-process sharing).
C++ equivalent: Buffer* remoteStorageBuffer() const
Sourcepub fn new_remote_buffer_view_for_device(
&self,
device: &Device,
) -> Option<Buffer>
pub fn new_remote_buffer_view_for_device( &self, device: &Device, ) -> Option<Buffer>
Create a remote buffer for a remote device.
C++ equivalent: Buffer* newRemoteBufferViewForDevice(Device*)
Sourcepub fn gpu_resource_id(&self) -> ResourceID
pub fn gpu_resource_id(&self) -> ResourceID
Get the GPU resource ID for bindless access.
C++ equivalent: ResourceID gpuResourceID() const
Sourcepub fn sparse_buffer_tier(&self) -> BufferSparseTier
pub fn sparse_buffer_tier(&self) -> BufferSparseTier
Get the sparse buffer tier for this buffer.
C++ equivalent: BufferSparseTier sparseBufferTier() const
Sourcepub fn label(&self) -> Option<String>
pub fn label(&self) -> Option<String>
Get the label for this buffer.
C++ equivalent: NS::String* label() const
Sourcepub fn set_label(&self, label: &str)
pub fn set_label(&self, label: &str)
Set the label for this buffer.
C++ equivalent: void setLabel(const NS::String*)
Sourcepub fn device(&self) -> Device
pub fn device(&self) -> Device
Get the device that created this buffer.
C++ equivalent: Device* device() const
Sourcepub fn resource_options(&self) -> ResourceOptions
pub fn resource_options(&self) -> ResourceOptions
Get the resource options used to create this buffer.
C++ equivalent: ResourceOptions resourceOptions() const
Sourcepub fn allocated_size(&self) -> UInteger
pub fn allocated_size(&self) -> UInteger
Get the allocated size of this buffer.
C++ equivalent: NS::UInteger allocatedSize() const