Set a storage mode that defines the memory location and access permissions of a resource.
Framework
- Metal
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 make
method and set its storage mode in the method’s options
parameter.
MTLResourceOptions bufferOptions = MTLResourceStorageModePrivate;
id <MTLBuffer> buffer = [_device newBufferWithLength:256
options:bufferOptions];
Note
The storage mode options in MTLResource
are equivalent to the storage mode values in MTLStorage
. When you create a new buffer, you can combine multiple resource options but you can set only one storage mode.
Set a Storage Mode for a Texture
Create a new MTLTexture
and set its storage mode in the descriptor’s storage
property. Then create a new MTLTexture
with the make
method.
let textureDescriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: .bgra8Unorm,
width: 256,
height: 256,
mipmapped: true)
textureDescriptor.storageMode = .private
let texture = device.makeTexture(descriptor: textureDescriptor)