Instance Method


Encodes a command to optimize a range in the indirect command buffer to improve performance.


func optimizeIndirectCommandBuffer(_ buffer: MTLIndirectCommandBuffer, range: Range<Int>)



The indirect command buffer to optimize.


The range of commands to optimize.


Often, indirect command buffers are filled by compute functions executing on the GPU. Because compute functions are encoding commands in parallel, they must sometime reset commands or set the same parameter state in multiple commands. Optimizing an indirect command buffer removes some empty commands and redundant parameter state from the indirect command buffer, improving performance when commands in the indirect command buffer are executed.

Any range within a buffer that is optimized must be treated as opaque data. It is illegal to execute commands within the buffer with a start index that is inside the optimized range. Executing commands with any start index other than the start of the optimized region results in undefined behavior. It is legal to cross optimized ranges or to execute a range of commands that ends within an optimized range. You must reset the optimized range before new commands can be encoded into the buffer.

See Also

Working with Indirect Command Buffers

func copyIndirectCommandBuffer(MTLIndirectCommandBuffer, sourceRange: Range<Int>, destination: MTLIndirectCommandBuffer, destinationIndex: Int)

Encodes a command to copy commands from an indirect command buffer into another indirect command buffer.

func resetCommandsInBuffer(MTLIndirectCommandBuffer, range: Range<Int>)

Encodes a command to reset a range of commands in an indirect command buffer.