<!--
{
  "availability" : [
    "iOS: 8.3.0 -",
    "iPadOS: 8.3.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLRenderCommandEncoder/setVertexBytes(_:length:index:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLRenderCommandEncoder(im)setVertexBytes:length:atIndex:"
  },
  "title" : "setVertexBytes(_:length:index:)"
}
-->

# setVertexBytes(_:length:index:)

Creates a buffer from bytes and assigns it to an entry in the vertex shader argument table.

```
func setVertexBytes(_ bytes: UnsafeRawPointer, length: Int, index: Int)
```

## Parameters

`bytes`

A pointer to argument data the method copies to an [`MTLBuffer`](/documentation/Metal/MTLBuffer) and assigns to an entry in the vertex shader argument table for buffers.

`length`

The number of bytes the method copies from the `bytes` pointer.

`index`

An integer that represents the entry in the vertex shader argument table for buffers that stores a record of the [`MTLBuffer`](/documentation/Metal/MTLBuffer) the method creates from `bytes`.

## Discussion

The method is equivalent to creating an [`MTLBuffer`](/documentation/Metal/MTLBuffer) instance that contains the same data as `bytes` and calling the [`setVertexBuffer(_:offset:index:)`](/documentation/Metal/MTLRenderCommandEncoder/setVertexBuffer(_:offset:index:)) method. However, this method avoids the overhead of creating a buffer to store your data; instead, Metal manages the data.

> Important:
> Only call this method for single-use data that’s smaller than 4 KB.

For data that’s more than 4 KB, create an [`MTLBuffer`](/documentation/Metal/MTLBuffer) instance and pass it to [`setVertexBuffer(_:offset:index:)`](/documentation/Metal/MTLRenderCommandEncoder/setVertexBuffer(_:offset:index:)).

By default, the buffer at each index is `nil`.

---

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)