Article

Choosing a Resource Storage Mode in iOS and tvOS

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

Overview

All iOS and tvOS devices have a unified memory model in which the CPU and the GPU share system memory. However, CPU and GPU access to that memory depends on the chosen storage mode for your resources. The MTLStorageModeShared mode defines system memory accessible to both the CPU and the GPU, whereas the MTLStorageModePrivate mode defines system memory accessible only to the GPU.

The MTLStorageModeMemoryless mode defines tile memory within the GPU accessible only to the GPU. Tile memory has higher bandwidth, lower latency, and lower power consumption than system memory.

A system diagram of resource storage modes in iOS and tvOS, showing the memory location and access permissions for resources configured with a shared, private, or memoryless mode.

Choose a Resource Storage Mode for Buffers or Textures

For guidance on how to set a storage mode, see Setting Resource Storage Modes. Several options are available, depending on your resource’s access needs:

Populated and updated by the CPU. Choose the MTLStorageModeShared mode if your resource requires CPU access.

Accessed exclusively by the GPU. Choose the MTLStorageModePrivate mode if you populate your resource with the GPU through a compute, render, or blit pass. This case is common for render targets, intermediary resources, or texture streaming.

Populated once by the CPU and accessed frequently by a GPU. Use the CPU to create a resource with a MTLStorageModeShared mode and populate its contents. Then, use the GPU to copy the resource’s contents into another resource with a MTLStorageModePrivate mode.

Accessed exclusively by the GPU, and its contents are temporary (textures only). Choose the MTLStorageModeMemoryless mode if your texture is a memoryless render target that’s temporarily populated and accessed by the GPU. Memoryless render targets are render targets that exist only in tile memory and are not backed by system memory. An example is a depth or stencil texture thatʼs used only within a render pass and isnʼt needed before or after GPU execution.

For guidance on how to copy data to a private resource, see Copying Data to a Private Resource.

Create a Memoryless Render Target

To create a memoryless render target, set the storageMode property of a MTLTextureDescriptor to MTLStorageModeMemoryless and use this descriptor to create a new MTLTexture. Then set this new texture as the texture property of a MTLRenderPassAttachmentDescriptor.

MTLTextureDescriptor *memorylessDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR16Float
                                                                                                width:256
                                                                                               height:256
                                                                                            mipmapped:YES];
memorylessDescriptor.storageMode = MTLStorageModeMemoryless;
id <MTLTexture> memorylessTexture = [_device newTextureWithDescriptor:memorylessDescriptor];
    
MTLRenderPassDescriptor *renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
renderPassDescriptor.depthAttachment.texture = memorylessTexture;

See Deferred Lighting for an example of an app that uses a memoryless render target.

See Also

Resource Storage Modes by Platform

Choosing a Resource Storage Mode in macOS

Choose an appropriate storage mode for your macOS resources.