Last updated: 2026-09-07

Metal Runtime

Metal Buffer

All API Sections

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 2 methods src/metal/buffer.zig

6 exports shown

struct

MetalBuffer

#
pub const MetalBuffer = struct

Metal buffer handle plus CPU visibility metadata used throughout the backend.

src/metal/buffer.zig:11

Methods

2

method

MetalBuffer.contents

#
pub fn contents(self: *const MetalBuffer) ?[*]u8

Return the raw CPU-visible pointer for shared-mode buffers.

src/metal/buffer.zig:24

method

MetalBuffer.mapped

#
pub fn mapped(self: *const MetalBuffer) ?[*]u8

Mapped pointer alias kept for compatibility with the Vulkan buffer interface pattern.

src/metal/buffer.zig:29

function

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.

src/metal/buffer.zig:35

function

createPrivateBuffer

#
pub fn createPrivateBuffer(ctx: ?*shim.MetalCtx, size: usize) !MetalBuffer

Allocate a GPU-private Metal buffer without a CPU mapping.

src/metal/buffer.zig:48

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.

src/metal/buffer.zig:60

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.

src/metal/buffer.zig:73

function

freeBuffer

#
pub fn freeBuffer(buf: *MetalBuffer) void

Free a Metal buffer handle and clear it from the wrapper.

src/metal/buffer.zig:85