Indirect command encoding
Store draw commands in Metal buffers and run them at a later time on the GPU, either once or repeatedly.
Overview
You can use an 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 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:
A compute kernel that identifies visible geometry and saves it to a result buffer
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 bufferSpecifying drawing and dispatch arguments indirectlyEncoding indirect command buffers on the CPUEncoding indirect command buffers on the GPUMTLIndirectCommandBufferMTLIndirectCommandBufferDescriptorMTLIndirectCommandTypeMTLIndirectCommandBufferExecutionRangeMTLIndirectCommandBufferExecutionRangeMake(_:_:)
Indirect compute commands
MTLIndirectComputeCommandMTLRegionMTLSizeMTLOriginMTLStageInRegionIndirectArgumentsMTLDispatchThreadgroupsIndirectArguments