An allocation of memory that is accessible to a GPU.


protocol MTLResource


When you execute commands on the GPU, those commands can only affect memory allocated as MTLResource objects. These Metal resources can only be modified by the MTLDevice that created them. Different resource types have different uses. The most common resource types are buffers (MTLBuffer), which are linear allocations of memory, and textures (MTLTexture), which hold structured image data. Don’t implement this protocol yourself; instead, create resources by calling methods on MTLDevice, MTLBuffer, or MTLTexture.


Identifying the Resource

var device: MTLDevice

The device object that created the resource.


var label: String?

A string that identifies the resource.


Reading Memory and Storage Properties

var cpuCacheMode: MTLCPUCacheMode

The CPU cache mode that defines the CPU mapping of the resource.


var storageMode: MTLStorageMode

The location and access permissions of the resource.


var hazardTrackingMode: MTLHazardTrackingMode

A mode that determines whether Metal tracks and synchronizes resource access.


var resourceOptions: MTLResourceOptions

The storage mode, CPU cache mode, and hazard tracking mode of the resource.


enum MTLCPUCacheMode

Options for the CPU cache mode that define the CPU mapping of the resource.

enum MTLStorageMode

Options for the memory location and access permissions for a resource.

enum MTLHazardTrackingMode

The options you use to specify the hazard tracking mode.

Setting the Purgeable State of the Resource

func setPurgeableState(MTLPurgeableState) -> MTLPurgeableState

Specifies or queries the resource’s purgeable state.


enum MTLPurgeableState

The purgeable state of the resource.

Managing Heap Resources

var heapOffset: Int

The distance, in bytes, from the beginning of the heap to the first byte of the resource, if you allocated the resource on a heap.


var heap: MTLHeap?

The heap on which the resource is allocated, if any.


func makeAliasable()

Allows future heap resource allocations to alias against the resource’s memory.


func isAliasable() -> Bool

A Boolean value that indicates whether future heap resource allocations may alias against the resource’s memory.


Querying the Allocated Size

var allocatedSize: Int

The size of the resource, in bytes.


Setting the Behavior of a New Resource

struct MTLResourceOptions

Optional arguments used to set the behavior of a resource.


Inherits From

See Also


Setting Resource Storage Modes

Set a storage mode that defines the memory location and access permissions of a resource.

Copying Data to a Private Resource

Use a blit command encoder to copy buffer or texture data to a private resource.

Synchronizing a Managed Resource

Synchronize the contents of a managed resource for the CPU or GPU.

Transferring Data Between Connected GPUs

Use high-speed connections between GPUs to transfer data quickly.

Reducing the Memory Footprint of Metal Apps

Learn best practices for using memory efficiently in iOS and tvOS.

protocol MTLBlitCommandEncoder

An encoder that encodes memory copying, filtering, and fill commands.

protocol MTLResourceStateCommandEncoder

An encoder that encodes commands that modify resource configurations.


Create and manipulate unstructured GPU resources.


Create and manipulate structured GPU resources.

Indirect Command Buffers

Recoup encoding time by reusing commands, or create a GPU-driven rendering pipeline by generating commands on the GPU.


Create a single allocation of memory from which you can suballocate resources.


Manage access to resources in your app to avoid data hazards.