<!--
{
  "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/MTL4RenderCommandEncoder/executeCommands(buffer:indirectBuffer:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTL4RenderCommandEncoder(im)executeCommandsInBuffer:indirectBuffer:"
  },
  "title" : "executeCommands(buffer:indirectBuffer:)"
}
-->

# executeCommands(buffer:indirectBuffer:)

Encodes a command that runs an indirect range of commands from an indirect command buffer.

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

## Parameters

`indirectCommandBuffer`

A [`MTLIndirectCommandBuffer`](/documentation/Metal/MTLIndirectCommandBuffer) instance that contains other commands
the current command runs.

`indirectRangeBuffer`

GPUAddress of a [`MTLBuffer`](/documentation/Metal/MTLBuffer) instance with data that matches the layout of the
[`MTLIndirectCommandBufferExecutionRange`](/documentation/Metal/MTLIndirectCommandBufferExecutionRange) structure. This address requires 4-byte alignment.

## Discussion

Use this method to indicate to Metal the span of indices in the command buffer to execute indirectly via an
[`MTLBuffer`](/documentation/Metal/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`](/documentation/Metal/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`](/documentation/Metal/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 ``doc://com.apple.metal/documentation/Metal/MTLResidencySet`` instance in use when you commit the command buffer.
> 
> An indirect render command references a pipeline state when you pass it as an argument to the
> command’s ``doc://com.apple.metal/documentation/Metal/MTLIndirectRenderCommand/setRenderPipelineState(_:)`` method during CPU encoding, or
> `set_render_pipeline_state()` during GPU encoding.

---

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)