Last updated: 2026-09-07
Metal Runtime
Metal Buffer
Metal buffer wrapper — shared-mode GPU buffers with zero-copy mmap support.
The Metal backend allocates shared-storage buffers so CPU code, the model loader, and GPU kernels can all see the same memory without an explicit staging copy. This module owns that wrapper and its mmap integration.
6 exports shown
struct
MetalBuffer
pub const MetalBuffer = struct Metal buffer handle plus CPU visibility metadata used throughout the backend.
Methods
2function
createBuffer
pub fn createBuffer(ctx: ?*shim.MetalCtx, size: usize) !MetalBuffer Allocate a shared-storage Metal buffer that is visible to both CPU and GPU code.
function
createPrivateBuffer
pub fn createPrivateBuffer(ctx: ?*shim.MetalCtx, size: usize) !MetalBuffer Allocate a GPU-private Metal buffer without a CPU mapping.
function
wrapMmap
pub fn wrapMmap(ctx: ?*shim.MetalCtx, ptr: [*]u8, size: usize) !MetalBuffer Wrap an existing mmap region as a Metal buffer without copying its contents.
function
aliasBuffer
pub fn aliasBuffer(base: *const MetalBuffer, offset: usize, size: usize) MetalBuffer Create a lightweight view into an existing buffer.
The returned handle is not retained and must not be freed independently of the owner.
function
freeBuffer
pub fn freeBuffer(buf: *MetalBuffer) void Free a Metal buffer handle and clear it from the wrapper.