Generally, there are four main scenarios to consider when choosing a storage mode:Ĭhoose MTLResourceStorageModePrivate for resources that are only ever read from and/or written to by the GPU. If you use the GPU to modify the contents of a managed resource and you wish to access the results with the CPU, then you must first synchronize the resource using the synchronizeResource: method or synchronizeTexture:slice:level: method. Managed textures are not available in iOS feature sets use MTLStorageModeShared instead.Īny time your app uses the CPU to directly modify the contents of a buffer, you must make a call to the didModifyRange: method to notify Metal that you have changed the contents of the resource indicated by the specific range. On GPUs with discrete memory, managed resources internally allocate both CPU-accessible and GPU-accessible memory. On GPUs without discrete memory, managed resources have only a single memory allocation accessible to both the CPU and GPU. Write to the private resource from a compute function. Render to the private resource from a fragment shader. Read from the private resource from any shader function. To access a private resource, your app may perform one or more of the following actions: GetBytes:bytesPerRow:bytesPerImage:fromRegion:mipmapLevel:slice: GetBytes:bytesPerRow:fromRegion:mipmapLevel: ReplaceRegion:mipmapLevel:slice:withBytes:bytesPerRow:bytesPerImage: ReplaceRegion:mipmapLevel:withBytes:bytesPerRow: The contents property of a buffer returns NULL and the MTLTexture methods listed below are illegal to call: Resources allocated with the private storage mode are stored in memory that is only accessible to the GPU.īuffers and textures allocated with private storage mode can only be accessed by the GPU. In the OSX_GPUFamily1_v1 feature set, textures cannot be allocated with the shared storage mode. In iOS feature sets, this is the default storage mode for textures. On devices with discrete memory, these resources are accessed directly from CPU local memory rather than being copied to GPU memory. Resources allocated with the shared storage mode are stored in memory that is accessible to both the CPU and the GPU. A description of the three new resource storage modes is summarized in the following sub-sections. IOS feature sets only support shared and private storage modes. MTLResourceStorageModePrivate = MTLStorageModePrivate << MTLResourceStorageModeShift, MTLResourceStorageModeManaged = MTLStorageModeManaged << MTLResourceStorageModeShift, MTLResourceStorageModeShared = MTLStorageModeShared << MTLResourceStorageModeShift, Typedef NS_ENUM(NSUInteger, MTLResourceOptions) Resource memory allocation is explicitly handled by selecting an appropriate storage mode value from the Listing 10-2 enum for textures and Listing 10-3 enum for buffers. The OSX_GPUFamily1_v1 feature set includes support for managing resources on GPUs that contain discrete memory. Resource Storage Modes and Device Memory Models You can query specific render and compute characteristics with the new supportsTextureSampleCount: method and maxThreadsPerThreadgroup property added to the MTLDevice protocol. To further obtain the characteristics of a single GPU in a multi-GPU system, query the headless property to find out if the GPU is attached to a display and query the lowPower property to find the lower-power GPU in an automatic graphics switching system. OSX_GPUFamily1_v1 feature set devices may have multiple GPUs, which you can obtain by calling the MTLCopyAllDevices function. Use the MTLCreateSystemDefaultDevice function to obtain the preferred GPU for your app. To find out which feature set is supported by a device, query the supportsFeatureSet: method of a MTLDevice object. See the MTLFeatureSet reference and iOS Device Compatibility Reference for more information. IOS devices that support Metal support a feature set determined by their GPU and OS versions. Typedef NS_ENUM(NSUInteger, MTLFeatureSet)Īll OS X devices that support Metal support the OSX_GPUFamily1_v1 feature set.