useResources(_:usage:)
Ensures kernel calls that the system encodes in subsequent commands have access to multiple resources.
Declaration
func useResources(_ resources: [any MTLResource], usage: MTLResourceUsage)Parameters
- resources:
A list of Mtlresource instances used in one or more argument buffers.
- usage:
All the applicable access types for use of these resources, including Read and Write. Your resource usage type applies to all resources passed to this method call.
For applicable resources, you may be able to prevent the GPU from unnecessarily decompressing color attachments on some devices by setting
usageto Read.
Mentioned in
Discussion
You can make many resources resident (available in GPU memory) for the remaining duration of the compute pass by calling this method. Call the method before encoding function calls that may access these resources through an argument buffer. The method ensures the resource is in a format that’s compatible with the kernels that depend on it.
The method also informs Metal when to apply hazard tracking for a resource you create with MTLHazardTrackingMode.tracked. For a resource you create with MTLHazardTrackingMode.untracked, you need to apply an MTLFence or an MTLEvent to account for potential reading and writing hazards.
You can reconfigure an individual resource’s usage options for subsequent draw calls with the useResource(_:usage:) method.
Apps typically call this method for a resource in an argument buffer as a part of their bindless implementation. For more information about argument buffers and bindless implementations, see Improving CPU performance by using argument buffers and Go bindless with Metal 3, respectively.