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


@protocol MTLBuffer


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 (MTLStorageModeManaged), you must call didModifyRange: to tell Metal to copy any changes to the GPU.


Creating a Texture That Shares Buffer Data

- newTextureWithDescriptor:offset:bytesPerRow:

Creates a texture that shares its storage with the buffer.


Reading the Buffer's Data on the CPU

- contents

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


Synchronizing Data to the GPU for Managed Buffers

- didModifyRange:

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


Debugging Buffers

- addDebugMarker:range:

Adds a debug marker string to a specific buffer range.


- removeAllDebugMarkers

Removes all debug marker strings from the buffer.


Reading Buffer Length


The logical size of the buffer, in bytes.



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