Protocol

MTLResource

An allocation of memory that is accessible to a GPU.

Declaration

@protocol MTLResource

Overview

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.

Topics

Identifying the Resource

device

The device object that created the resource.

Required.

label

A string that identifies the resource.

Required.

Reading Memory and Storage Properties

cpuCacheMode

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

Required.

storageMode

The location and access permissions of the resource.

Required.

hazardTrackingMode

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

Required.

resourceOptions

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

Required.

MTLCPUCacheMode

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

MTLStorageMode

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

MTLHazardTrackingMode

The options you use to specify the hazard tracking mode.

Setting the Purgeable State of the Resource

- setPurgeableState:

Specifies or queries the resource’s purgeable state.

Required.

MTLPurgeableState

The purgeable state of the resource.

Managing Heap Resources

heapOffset

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.

Required.

heap

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

Required.

- makeAliasable

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

Required.

- isAliasable

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

Required.

Querying the Allocated Size

allocatedSize

The size of the resource, in bytes.

Required.

Setting the Behavior of a New Resource

MTLResourceOptions

Optional arguments used to set the behavior of a resource.

Relationships

Inherits From

See Also

Resources

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.

MTLBlitCommandEncoder

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

MTLResourceStateCommandEncoder

An encoder that encodes commands that modify resource configurations.

Buffers

Create and manipulate unstructured GPU resources.

Textures

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.

Heaps

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

Synchronization

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