---
title: "executeCommands(buffer:indirectBuffer:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtl4computecommandencoder/executecommands(buffer:indirectbuffer:)"
---

# executeCommands(buffer:indirectBuffer:)

Encodes an instruction to execute commands from an indirect command buffer, using an indirect buffer for arguments.

## Declaration

```swift
func executeCommands(buffer indirectCommandbuffer: any MTLIndirectCommandBuffer, indirectBuffer indirectRangeBuffer: MTLGPUAddress)
```

## Parameters

- `indirectCommandbuffer`: doc://com.apple.metal/documentation/Metal/MTLIndirectCommandBuffer instance containing the commands to execute.
- `indirectRangeBuffer`: GPUAddress of a doc://com.apple.metal/documentation/Metal/MTLBuffer containing the execution range. Lay out the data in this buffer as described in the doc://com.apple.metal/documentation/Metal/MTLIndirectCommandBufferExecutionRange structure. This address requires 4-byte alignment.

## Discussion

Discussion Use this method to indicate to Metal the span of indices in the command buffer to execute indirectly via an MTLBuffer instance you provide in the indirectRangeBuffer parameter. This allows you to calculate the span of commands Metal executes in the GPU timeline, enabling GPU-driven workflows. Metal requires that the contents of this buffer match the layout of struct MTLIndirectCommandBufferExecutionRange, which specifies a location and a length within the indirect command buffer. You are responsible for ensuring the address of this buffer has 4-byte alignment. Use an instance of MTLResidencySet to mark residency of the indirect buffer that the indirectRangeBuffer parameter references. note: If the indirectCommandBuffer parameter references any pipeline state objects, you are responsible for adding them to a MTLResidencySet instance in use when you commit the command buffer. An indirect compute command references a pipeline state when you pass it as an argument to the command’s setComputePipelineState(_:) method during CPU encoding, or set_compute_pipeline_state() during GPU encoding.

## See Also

### Encoding indirect command buffers

- [executeCommands(buffer:range:)](metal/mtl4computecommandencoder/executecommands(buffer:range:).md)
