<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTL4ComputeCommandEncoder/dispatchThreadgroups(indirectBuffer:threadsPerThreadgroup:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTL4ComputeCommandEncoder(im)dispatchThreadgroupsWithIndirectBuffer:threadsPerThreadgroup:"
  },
  "title" : "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.

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

## Parameters

`indirectBuffer`

GPUAddress of a [`MTLBuffer`](/documentation/Metal/MTLBuffer) instance providing compute parameters.
Lay out the data in this buffer as described in the
[`MTLDispatchThreadgroupsIndirectArguments`](/documentation/Metal/MTLDispatchThreadgroupsIndirectArguments) structure. This address
requires 4-byte alignment.

`threadsPerThreadgroup`

A [`MTLSize`](/documentation/Metal/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`](/documentation/Metal/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`](/documentation/Metal/MTLDispatchThreadgroupsIndirectArguments).
You are responsible for ensuring this address aligns to 4-bytes.

Use an instance of [`MTLResidencySet`](/documentation/Metal/MTLResidencySet) to mark residency of the indirect buffer that the `indirectBuffer`
parameter references.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)