Contents

MTLBuffer

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

Declaration

protocol MTLBuffer : MTLResource

Mentioned in

Overview

An MTLBuffer instance 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 instances:

The Metal framework doesn’t know anything about the contents of an 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 need to call didModifyRange: to tell Metal to copy any changes to the GPU.

Topics

Creating a texture that shares buffer data

Reading the buffer’s data on the CPU

Synchronizing data to the GPU for managed buffers

Debugging buffers

Reading buffer length

Creating views of buffers on other GPUs

Instance Properties

Instance Methods