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

# dispatchThreadgroups(indirectBuffer:indirectBufferOffset:threadsPerThreadgroup:)

Encodes a dispatch call for a compute pass, using an indirect buffer that defines the size of a grid that aligns to threadgroup boundaries.

## Declaration

```swift
func dispatchThreadgroups(indirectBuffer: any MTLBuffer, indirectBufferOffset: Int, threadsPerThreadgroup: MTLSize)
```

## Parameters

- `indirectBuffer`: An 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.
- `indirectBufferOffset`: Where the data begins, in bytes, from the start of the buffer. This value needs to be a multiple of 4.
- `threadsPerThreadgroup`: The number of threads in one threadgroup, in each dimension.

## Discussion

Discussion The GPU fetches parameters from the indirect buffer just before the thread grid starts. This process lets the compute function run based on GPU feedback, without latency from data transfer between the CPU and the GPU.

## See Also

### Dispatching from indirect command buffers

- [executeCommandsInBuffer(_:range:)](metal/mtlcomputecommandencoder/executecommandsinbuffer(_:range:).md)
- [executeCommandsInBuffer(_:indirectBuffer:offset:)](metal/mtlcomputecommandencoder/executecommandsinbuffer(_:indirectbuffer:offset:).md)
- [executeCommands(in:indirectBuffer:indirectBufferOffset:)](metal/mtlcomputecommandencoder/executecommands(in:indirectbuffer:indirectbufferoffset:).md)
- [executeCommands(in:with:)](metal/mtlcomputecommandencoder/executecommands(in:with:).md)
