---
title: "dispatchThreadgroups(indirectBuffer:threadsPerThreadgroup:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtl4computecommandencoder/dispatchthreadgroups(indirectbuffer:threadsperthreadgroup:)"
---

# dispatchThreadgroups(indirectBuffer:threadsPerThreadgroup:)

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

## Declaration

```swift
func dispatchThreadgroups(indirectBuffer: MTLGPUAddress, threadsPerThreadgroup: MTLSize)
```

## Parameters

- `indirectBuffer`: GPUAddress of a doc://com.apple.metal/documentation/Metal/MTLBuffer instance providing compute parameters. Lay out the data in this buffer as described in the doc://com.apple.metal/documentation/Metal/MTLDispatchThreadgroupsIndirectArguments structure. This address requires 4-byte alignment.
- `threadsPerThreadgroup`: A doc://com.apple.metal/documentation/Metal/MTLSize instance that represents the number of threads in one threadgroup, in each dimension.

## Discussion

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

- [dispatchThreads(threadsPerGrid:threadsPerThreadgroup:)](metal/mtl4computecommandencoder/dispatchthreads(threadspergrid:threadsperthreadgroup:).md)
- [dispatchThreads(indirectBuffer:)](metal/mtl4computecommandencoder/dispatchthreads(indirectbuffer:).md)
- [dispatchThreadgroups(threadgroupsPerGrid:threadsPerThreadgroup:)](metal/mtl4computecommandencoder/dispatchthreadgroups(threadgroupspergrid:threadsperthreadgroup:).md)
