Protocol

MTLBuffer

A resource that stores data in a format defined by your app.

Declaration

protocol MTLBuffer

Overview

A MTLBuffer object can be used only with the MTLDevice that created it. Don’t implement this protocol yourself; instead, use the following MTLDevice methods to create MTLBuffer objects:

The Metal framework doesn’t know anything about the contents of a MTLBuffer, just its size. You define the format of the data in the buffer and ensure that your app and your shaders know how to read and write the data. For example, you might create a struct in your shader that defines the data you want to store in the buffer and its memory layout.

If you create a buffer with a managed resource storage mode (MTLStorageMode.managed), you must call didModifyRange(_:) to tell Metal to copy any changes to the GPU.

Topics

Creating a Texture That Shares Buffer Data

func makeTexture(descriptor: MTLTextureDescriptor, offset: Int, bytesPerRow: Int) -> MTLTexture?

Creates a texture that shares its storage with the buffer.

Required.

Reading the Buffer's Data on the CPU

func contents() -> UnsafeMutableRawPointer

Gets the system address of the buffer’s storage allocation.

Required.

Synchronizing Data to the GPU for Managed Buffers

func didModifyRange(Range<Int>)

Informs the GPU that the CPU has modified a section of the buffer.

Debugging Buffers

func addDebugMarker(String, range: Range<Int>)

Adds a debug marker string to a specific buffer range.

func removeAllDebugMarkers()

Removes all debug marker strings from the buffer.

Required.

Reading Buffer Length

var length: Int

The logical size of the buffer, in bytes.

Required.

Creating Views of Buffers on Other GPUs

func makeRemoteBufferView(MTLDevice) -> MTLBuffer?

Creates a remote view of the buffer for another GPU in the same peer group.

Required.

var remoteStorageBuffer: MTLBuffer?

The buffer on another GPU that the buffer was created from, if any.

Required.

Relationships

Inherits From

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software