Setting resource storage modes
Set a storage mode that defines the memory location and access permissions of a resource.
Overview
Storage modes are only set when creating an instance, and the system default allows for access to memory from both the CPU and GPU. Metal selects the default mode for resources depending on hardware.
For Apple silicon GPUs the default is MTLStorageMode.shared.
For Intel-based Mac computers, the default is MTLStorageMode.managed for all MTLTexture instances and MTLBuffer instances attached to discrete GPUs. MTLBuffer instances using the integrated GPU have MTLStorageMode.shared as their default.
You perform the same synchronization tasks to ensure GPU and CPU memory coherency in both default modes. To check for GPU architecture and capabilities, use the supportsFamily(_:) method instead of the storageMode property. See Detecting GPU features and Metal software versions for more information.
Use MTLStorageMode.memoryless, only available on Apple silicon, when you manage your own storage, or want to run a GPU task that requires temporary resources. For tasks that share memory on the GPU, use MTLStorageMode.private storage. This article includes examples of how to set the storage mode for a buffer or texture.
For more guidance on which mode to choose, see Choosing a resource storage mode for Apple GPUs and Choosing a resource storage mode for Intel and AMD GPUs.
Set a storage mode for a buffer
Create a new MTLBuffer with the makeBuffer(length:options:) method and set its storage mode in the method’s options parameter.
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 makeTexture(descriptor:) method.