<!--
{
  "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/drawIndexedPrimitives(primitiveType:indexCount:indexType:indexBuffer:indexBufferLength:instanceCount:baseVertex:baseInstance:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTL4RenderCommandEncoder(im)drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferLength:instanceCount:baseVertex:baseInstance:"
  },
  "title" : "drawIndexedPrimitives(primitiveType:indexCount:indexType:indexBuffer:indexBufferLength:instanceCount:baseVertex:baseInstance:)"
}
-->

# drawIndexedPrimitives(primitiveType:indexCount:indexType:indexBuffer:indexBufferLength:instanceCount:baseVertex:baseInstance:)

Encodes a draw command that renders multiple instances of a geometric primitive with indexed vertices,
starting with a custom vertex and instance.

```
func drawIndexedPrimitives(primitiveType: MTLPrimitiveType, indexCount: Int, indexType: MTLIndexType, indexBuffer: MTLGPUAddress, indexBufferLength: Int, instanceCount: Int, baseVertex: Int, baseInstance: Int)
```

## Parameters

`primitiveType`

A [`MTLPrimitiveType`](/documentation/Metal/MTLPrimitiveType) representing how the command interprets vertex argument data.

`indexCount`

An integer that represents the number of vertices the command reads from `indexBuffer`.

`indexType`

A [`MTLIndexType`](/documentation/Metal/MTLIndexType) instance that represents the index format.

`indexBuffer`

GPUAddress of a [`MTLBuffer`](/documentation/Metal/MTLBuffer) instance that contains `indexCount` indices of `indexType` format.
You are responsible for ensuring this address is aligned to 2 bytes if the `indexType` format is
[`MTLIndexType.uint16`](/documentation/Metal/MTLIndexType/uint16), and aligned to 4 bytes if the format is
[`MTLIndexType.uint32`](/documentation/Metal/MTLIndexType/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 the `indexType` format is [`MTLIndexType.uint16`](/documentation/Metal/MTLIndexType/uint16),
and a multiple of 4 if the format is [`MTLIndexType.uint32`](/documentation/Metal/MTLIndexType/uint32).
If this draw call causes Metal to read indices at or beyond the `indexBufferLength`, Metal
continues to execute them assigning a value of `0` to the `vertex_id` attribute.

`instanceCount`

An integer that represents the number of times the command draws `primitiveType` with `indexCount`
vertices.

`baseVertex`

The lowest value the command passes to your vertex shader functions’s parameter with the `vertex_id`
attribute. Metal disregards this value and assigns `0` to the `vertex_id` attribute for all
primitives that require loading indices at a byte offset of `indexBufferLength` or greater.

`baseInstance`

The lowest value the command passes to your vertex shader’s parameter with the `instance_id` attribute.

## Discussion

Use this method to perform instanced indexed drawing, where an index buffer determines how Metal assembles primitives
whilst customizing the base vertex and base instance value Metal passes to the vertex shader function.

The command assigns each drawing instance a unique `instance_id` value that increases
from `baseInstance` through `(baseInstance + instanceCount - 1)`. Your shader can use this value
to identify which instance the vertex belongs to.

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`](/documentation/Metal/MTLIndexType/uint16) or [`MTLIndexType.uint32`](/documentation/Metal/MTLIndexType/uint32).

Use an instance of [`MTLResidencySet`](/documentation/Metal/MTLResidencySet) to mark residency of the index buffer the `indexBuffer` parameter references.

---

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)