Choosing a resource storage mode for Apple GPUs
Select an appropriate storage mode for your textures and buffers on Apple GPUs.
Overview
Apple GPUs 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 storage mode you choose for your resources. The MTLStorageMode.shared mode defines system memory that both the CPU and the GPU can access. The MTLStorageMode.private mode defines system memory that only the GPU can access.
The MTLStorageMode.memoryless mode defines tile memory within the GPU that only the GPU can access. Tile memory has higher bandwidth, lower latency, and consumes less power than system memory.
[Image]
Choose a resource storage mode for buffers or textures
The storage mode you choose depends on how you plan to use Metal resources:
- Populate and update on the CPU
Data shared by the CPU and GPU. Use MTLStorageMode.shared. The CPU and GPU share data. This is the default for buffer and texture storage.
- Access exclusively on the GPU
Data owned by the GPU. Use MTLStorageMode.private. Choose the 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. For guidance on how to copy data to a private resource, see Copying data to a private resource.
- Populate on CPU and access frequently on GPU
Shared integrated memory for the CPU and GPU. Use MTLStorageMode.shared.
- Temporary texture contents for GPU passes
Memory held by the GPU for textures within or between passes. Use MTLStorageMode.memoryless. Memoryless mode only works for textures, and stores temporary resources in tiled memory for high performance. An example is a depth or stencil texture thatʼs used only within a single pass and isnʼt needed in an earlier or later rendering stage.
For information on setting storage modes in your app, see Setting resource storage modes.
Create a memoryless render target
To create a memoryless render target, set the storageMode property of an MTLTextureDescriptor to MTLStorageMode.memoryless and use this descriptor to create a new MTLTexture. Then set this new texture as the texture property of an MTLRenderPassAttachmentDescriptor.
See Rendering a scene with deferred lighting in Objective-C for an example of an app that uses a memoryless render target.