Article

Setting Resource Storage Modes

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

Overview

By choosing an appropriate storage mode, you can configure a buffer or texture to benefit from fast memory access and driver-level performance optimizations. This article describes how to set the storage mode for a buffer or texture. For guidance on which mode to choose, see Choosing a Resource Storage Mode in iOS and tvOS and Choosing a Resource Storage Mode in macOS.

Set a Storage Mode for a Buffer

Create a new MTLBuffer with the newBufferWithLength:options: method and set its storage mode in the method’s options parameter.

let bufferOptions = MTLResourceOptions.storageModePrivate
let buffer = device.makeBuffer(length: 256,
                               options: bufferOptions)

Set a Storage Mode for a Texture

Create a new MTLTextureDescriptor and set its storage mode in the descriptor’s storageMode property. Then create a new MTLTexture with the newTextureWithDescriptor: method.

MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
                                                                                             width:256
                                                                                            height:256
                                                                                         mipmapped:YES];
textureDescriptor.storageMode = MTLStorageModePrivate;
id <MTLTexture> texture = [_device newTextureWithDescriptor:textureDescriptor];

Topics

Resource Storage Modes by Platform

Choosing a Resource Storage Mode in iOS and tvOS

Choose an appropriate storage mode for your iOS and tvOS resources.

Choosing a Resource Storage Mode in macOS

Choose an appropriate storage mode for your macOS resources.

See Also

Resources

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.

MTLResource

An allocation of memory that is accessible to a GPU.

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.

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.