Contents

dispatchThreadgroups(indirectBuffer:threadsPerThreadgroup:)

Encodes a compute dispatch command with a grid that aligns to threadgroup boundaries, using an indirect buffer for arguments.

Declaration

func dispatchThreadgroups(indirectBuffer: MTLGPUAddress, threadsPerThreadgroup: MTLSize)

Parameters

  • indirectBuffer:

    GPUAddress of a Mtlbuffer instance providing compute parameters. Lay out the data in this buffer as described in the Mtldispatchthreadgroupsindirectarguments structure. This address requires 4-byte alignment.

  • threadsPerThreadgroup:

    A Mtlsize instance that represents the number of threads in one threadgroup, in each dimension.

Discussion

This method allows you to supply the threadgroups-per-grid counts indirectly via an MTLBuffer index. This enables you to calculate this value in the GPU timeline from a shader function, enabling GPU-driven workflows.

Metal assumes that the buffer contents correspond to the layout of struct MTLDispatchThreadgroupsIndirectArguments. You are responsible for ensuring this address aligns to 4-bytes.

Use an instance of MTLResidencySet to mark residency of the indirect buffer that the indirectBuffer parameter references.

See Also

Running dispatch commands