A resource that stores data in a format defined by your app.
SDKs
- iOS 8.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- Metal
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:
new
creates aBuffer With Length: options: MTLBuffer
object with a new storage allocation.new
creates aBuffer With Bytes: length: options: MTLBuffer
object by copying data from an existing storage allocation into a new allocation.new
creates aBuffer With Bytes No Copy: length: options: deallocator: MTLBuffer
object that reuses an existing storage allocation and does not allocate any new storage.
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 (MTLStorage
), you must call did
to tell Metal to copy any changes to the GPU.