Instance Method


Encodes a compute command using a grid aligned to threadgroup boundaries.



func dispatchThreadgroups(_ threadgroupsPerGrid: MTLSize, threadsPerThreadgroup: MTLSize)



The number of threadgroups in the grid, in each dimension.


The number of threads in one threadgroup, in each dimension.


Metal calculates the number of threads in a grid by multiplying the size of a threadgroup (threadsPerThreadgroup) by the number of threadgroups (threadgroupsPerGrid).

If the size of your data doesn't match the size of the grid, you may have to perform boundary checks in your compute function. See Calculating Threadgroup and Grid Sizes for an example.

When the compute command is encoded, any necessary references to parameters or resources previously set on the encoder are recorded as part of the command. After encoding a command, you can safely change the encoding state to set up parameters needed to encode other commands.

See Also

Executing a Compute Function Directly

func dispatchThreads(MTLSize, threadsPerThreadgroup: MTLSize)

Encodes a compute command using an arbitrarily sized grid.