drawIndexedPrimitives(primitiveType:indexType:indexBuffer:indexBufferLength:indirectBuffer:)
Encodes a draw command that renders multiple instances of a geometric primitive with indexed vertices and indirect arguments.
Declaration
func drawIndexedPrimitives(primitiveType: MTLPrimitiveType, indexType: MTLIndexType, indexBuffer: MTLGPUAddress, indexBufferLength: Int, indirectBuffer: MTLGPUAddress)Parameters
- primitiveType:
A Mtlprimitivetype representing how the command interprets vertex argument data.
- indexType:
A Mtlindextype instance that represents the index format.
- indexBuffer:
GPUAddress of a Mtlbuffer instance that contains
indexCountindices ofindexTypeformat. You are responsible for ensuring this address is aligned to 2 bytes if theindexTypeformat is Uint16, and aligned to 4 bytes if the format is Uint32. - indexBufferLength:
An integer that represents the length of
indexBuffer, in bytes. You are responsible for ensuring this this size is a multiple of 2 if theindexTypeformat is Uint16, and a multiple of 4 if the format is Uint32. If this draw call causes Metal to read indices at or beyond theindexBufferLength, Metal continues to execute them assigning a value of0to thevertex_idattribute. - indirectBuffer:
GPUAddress of an Mtlbuffer instance with data that matches the layout of the Mtldrawindexedprimitivesindirectarguments structure. This address requires 4-byte alignment.
Discussion
When you use this function, Metal reads the parameters to the draw command from an MTLBuffer instance, allowing you to implement a GPU-driven workflow where a compute pipeline state determines the draw arguments.
Because this is an indexed draw call, Metal interprets the contents of the indirect buffer to match the layout of struct MTLDrawIndexedPrimitivesIndirectArguments, which includes indexStart and indexCount members, denoting a range within the index buffer you provide in the indexBuffer parameter.
The range of indices within the indexBuffer form the primitives Metal draws.
Metal imposes some restrictions on the index buffer’s address, which needs to be 2- or 4-byte aligned, and its length in bytes, which needs to be a multiple of 2 or 4, depending on whether the format of the index is MTLIndexType.uint16 or MTLIndexType.uint32.
Similarly, you are responsible for ensuring the indirect buffer’s address has 4-byte alignment.
Use an instance of MTLResidencySet to mark residency of the indirect buffer that the indirectBuffer parameter references, and of the index buffer the indexBuffer parameter references.
See Also
Drawing with indexed vertices
drawIndexedPrimitives(primitiveType:indexCount:indexType:indexBuffer:indexBufferLength:)drawIndexedPrimitives(primitiveType:indexCount:indexType:indexBuffer:indexBufferLength:instanceCount:)drawIndexedPrimitives(primitiveType:indexCount:indexType:indexBuffer:indexBufferLength:instanceCount:baseVertex:baseInstance:)