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

var device: MTLDevice

The device object that created the resource.

Required.

var label: String?

A string that identifies the resource.

Required.

Reading Memory and Storage Properties

var cpuCacheMode: MTLCPUCacheMode

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

Required.

var storageMode: MTLStorageMode

The location and access permissions of the resource.

Required.

var hazardTrackingMode: MTLHazardTrackingMode

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

Required.

Beta
var resourceOptions: MTLResourceOptions

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

Required.

Beta
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.

Beta

Setting the Purgeable State of the Resource

func setPurgeableState(MTLPurgeableState) -> MTLPurgeableState

Specifies or queries the resource’s purgeable state.

Required.

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.

Required.

Beta
var heap: MTLHeap?

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

Required.

func makeAliasable()

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

Required.

func isAliasable() -> Bool

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

Required.

Querying the Allocated Size

var allocatedSize: Int

The size of the resource, in bytes.

Required.

Setting the Behavior of a New Resource

struct 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.

Transferring Data Between Connected GPUs

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

protocol MTLBlitCommandEncoder

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

Buffers

Create and manipulate unstructured GPU resources.

Textures

Create and manipulate structured GPU resources.

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.

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