Contents

useResource(_:usage:)

Ensures kernel calls that the system encodes in subsequent commands have access to a resource.

Declaration

func useResource(_ resource: any MTLResource, usage: MTLResourceUsage)

Parameters

  • resource:

    An Mtlresource instance used in an argument buffer.

  • usage:

    How the compute pass can access data, including Read and Write permission.

    For applicable resources, you may be able to prevent the GPU from unnecessarily decompressing color attachments on some devices by setting usage to Read.

Mentioned in

Discussion

You can make a resource 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 the resource 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 in the same render pass by calling this method again.

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.

See Also

Making indirect resources resident