<!--
{
  "documentType" : "article",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/indirect-command-encoding",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Indirect command encoding"
}
-->

# Indirect command encoding

Store draw commands in Metal buffers and run them at a later time on the GPU, either once or repeatedly.

## Discussion

You can use an [`MTLIndirectCommandBuffer`](/documentation/Metal/MTLIndirectCommandBuffer) instance to store draw commands and invoke them at a later time. Metal executes all the draw commands in an indirect command buffer each time you submit it. This means you can use indirect command buffers multiple times, unlike [`MTLCommandBuffer`](/documentation/Metal/MTLCommandBuffer) instances, which are all single-use.

You can encode an indirect command buffer to run on either the CPU or the GPU. However, the GPU gives you the ability to immediately use the output of one pass as the input of a subsequent pass. For example, you can create an indirect command buffer with commands that conditionally draw visible items by running:

1. A compute kernel that identifies visible geometry and saves it to a result buffer
2. An indirect command buffer that uses the result buffer as its input to make decisions on what to draw

## Topics

### Indirect command buffers

[Creating an indirect command buffer](/documentation/Metal/creating-an-indirect-command-buffer)

Configure a descriptor to specify the properties of an indirect command buffer.

[Specifying drawing and dispatch arguments indirectly](/documentation/Metal/specifying-drawing-and-dispatch-arguments-indirectly)

Use indirect commands if you don’t know your draw or dispatch call arguments when you encode the command.

[Encoding indirect command buffers on the CPU](/documentation/Metal/encoding-indirect-command-buffers-on-the-cpu)

Reduce CPU overhead and simplify your command execution by reusing commands.

[Encoding indirect command buffers on the GPU](/documentation/Metal/encoding-indirect-command-buffers-on-the-gpu)

Maximize CPU to GPU parallelization by generating render commands on the GPU.

[`MTLIndirectCommandBuffer`](/documentation/Metal/MTLIndirectCommandBuffer)

A command buffer containing reusable commands, encoded either on the CPU or GPU.

[`MTLIndirectCommandBufferDescriptor`](/documentation/Metal/MTLIndirectCommandBufferDescriptor)

A configuration you create to customize an indirect command buffer.

[`MTLIndirectCommandType`](/documentation/Metal/MTLIndirectCommandType)

The types of commands that you can encode into the indirect command buffer.

[`MTLIndirectCommandBufferExecutionRange`](/documentation/Metal/MTLIndirectCommandBufferExecutionRange)

A range of commands in an indirect command buffer.

[`MTLIndirectCommandBufferExecutionRangeMake(_:_:)`](/documentation/Metal/MTLIndirectCommandBufferExecutionRangeMake(_:_:))

Creates a command execution range.

### Indirect compute commands

[`MTLIndirectComputeCommand`](/documentation/Metal/MTLIndirectComputeCommand)

A compute command in an indirect command buffer.

[`MTLRegion`](/documentation/Metal/MTLRegion)

The bounds for a subset of an instance’s elements.

[`MTLSize`](/documentation/Metal/MTLSize)

A type that represents one, two, or three dimensions of a type instance, such as an array or texture.

[`MTLOrigin`](/documentation/Metal/MTLOrigin)

The coordinates for the front upper-left corner of a region.

[`MTLStageInRegionIndirectArguments`](/documentation/Metal/MTLStageInRegionIndirectArguments)

The data layout required for the arguments needed to specify the stage-in region.

[`MTLDispatchThreadgroupsIndirectArguments`](/documentation/Metal/MTLDispatchThreadgroupsIndirectArguments)

The data layout required for arguments needed to specify the size of threadgroups.

### Render compute commands

[`MTLIndirectRenderCommand`](/documentation/Metal/MTLIndirectRenderCommand)

A render command in an indirect command buffer.

[`MTLDrawPatchIndirectArguments`](/documentation/Metal/MTLDrawPatchIndirectArguments)

The data layout required for drawing patches via indirect buffer calls.

[`MTLDrawPrimitivesIndirectArguments`](/documentation/Metal/MTLDrawPrimitivesIndirectArguments)

The data layout required for drawing primitives via indirect buffer calls.

[`MTLDrawIndexedPrimitivesIndirectArguments`](/documentation/Metal/MTLDrawIndexedPrimitivesIndirectArguments)

The data layout required for drawing indexed primitives via indirect buffer calls.



---

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)