<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLArgumentEncoder",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLArgumentEncoder"
  },
  "title" : "MTLArgumentEncoder"
}
-->

# MTLArgumentEncoder

An interface you can use to encode argument data into an argument buffer.

```
protocol MTLArgumentEncoder : NSObjectProtocol
```

## Overview

An [`MTLArgumentEncoder`](/documentation/Metal/MTLArgumentEncoder) instance encodes buffers, textures, samplers, and inlined constant data into an argument buffer. An [`MTLBuffer`](/documentation/Metal/MTLBuffer) instance represents the argument buffer that you set as the encoding destination by calling the [`setArgumentBuffer(_:offset:)`](/documentation/Metal/MTLArgumentEncoder/setArgumentBuffer(_:offset:)) method.

The recommended way to declare an argument buffer is to define its structure in your Metal shading language code. You can assign the argument buffer to a function’s specific buffer index. To create an encoder for this type of argument buffer, call one of the following [`MTLFunction`](/documentation/Metal/MTLFunction) methods:

- [`makeArgumentEncoder(bufferIndex:)`](/documentation/Metal/MTLFunction/makeArgumentEncoder(bufferIndex:))
- [`makeArgumentEncoder(bufferIndex:reflection:)`](/documentation/Metal/MTLFunction/makeArgumentEncoder(bufferIndex:reflection:))

If you construct your shaders dynamically at runtime, you can still construct argument buffers as parameters for the shader. Define each argument separately and then add it to an array of [`MTLArgumentDescriptor`](/documentation/Metal/MTLArgumentDescriptor) instances. To create an encoder for this type of argument buffer, call the [`makeArgumentEncoder(arguments:)`](/documentation/Metal/MTLDevice/makeArgumentEncoder(arguments:)) method of the [`MTLDevice`](/documentation/Metal/MTLDevice) class.

> Important:
> A runtime validation error occurs if you create a `MTLArgumentEncoder` instance using structures that don’t reference any other resources and don’t provide any `[[id()]]` annotation on any of their members.

## Topics

### Creating an argument buffer

[`setArgumentBuffer(_:offset:)`](/documentation/Metal/MTLArgumentEncoder/setArgumentBuffer(_:offset:))

Specifies the position in a buffer where the encoder writes argument data.

[`setArgumentBuffer(_:startOffset:arrayElement:)`](/documentation/Metal/MTLArgumentEncoder/setArgumentBuffer(_:startOffset:arrayElement:))

Specifies an array element within a buffer where the encoder writes argument data.

[`encodedLength`](/documentation/Metal/MTLArgumentEncoder/encodedLength)

The number of bytes required to store the encoded resources of an argument buffer.

### Encoding buffers

[`setBuffer(_:offset:index:)`](/documentation/Metal/MTLArgumentEncoder/setBuffer(_:offset:index:))

Encodes a reference to a buffer into the argument buffer.

[`setBuffers(_:offsets:range:)`](/documentation/Metal/MTLArgumentEncoder/setBuffers(_:offsets:range:))

Encodes references to an array of buffers into the argument buffer.

[`setBuffers:offsets:withRange:`](/documentation/Metal/MTLArgumentEncoder/setBuffers:offsets:withRange:)

Encodes references to an array of buffers into the argument buffer.

### Encoding textures

[`setTexture(_:index:)`](/documentation/Metal/MTLArgumentEncoder/setTexture(_:index:))

Encodes a reference to a texture into the argument buffer.

[`setTextures(_:range:)`](/documentation/Metal/MTLArgumentEncoder/setTextures(_:range:))

Encodes references to an array of textures into the argument buffer.

[`setTextures:withRange:`](/documentation/Metal/MTLArgumentEncoder/setTextures:withRange:)

Encodes references to an array of textures into the argument buffer.

### Encoding samplers

[`setSamplerState(_:index:)`](/documentation/Metal/MTLArgumentEncoder/setSamplerState(_:index:))

Encodes a sampler into the argument buffer.

[`setSamplerStates(_:range:)`](/documentation/Metal/MTLArgumentEncoder/setSamplerStates(_:range:))

Encodes an array of samplers into the argument buffer.

[`setSamplerStates:withRange:`](/documentation/Metal/MTLArgumentEncoder/setSamplerStates:withRange:)

Encodes an array of samplers into the argument buffer.

### Encoding pipeline states

[`setRenderPipelineState(_:index:)`](/documentation/Metal/MTLArgumentEncoder/setRenderPipelineState(_:index:))

Encodes a reference to a render pipeline state into the argument buffer.

[`setRenderPipelineStates(_:range:)`](/documentation/Metal/MTLArgumentEncoder/setRenderPipelineStates(_:range:))

Encodes references to an array of render pipeline states into the argument buffer.

[`setRenderPipelineStates:withRange:`](/documentation/Metal/MTLArgumentEncoder/setRenderPipelineStates:withRange:)

Encodes references to an array of render pipeline states into the argument buffer.

[`setComputePipelineState(_:index:)`](/documentation/Metal/MTLArgumentEncoder/setComputePipelineState(_:index:))

Encodes a reference to a compute pipeline state into the argument buffer.

[`setComputePipelineStates(_:with:)`](/documentation/Metal/MTLArgumentEncoder/setComputePipelineStates(_:with:))

Encodes references to an array of compute pipeline states into the argument buffer.

[`setComputePipelineState(_:at:)`](/documentation/Metal/MTLArgumentEncoder/setComputePipelineState(_:at:))

Encodes a reference to a compute pipeline state into the argument buffer.

[`setComputePipelineStates(_:range:)`](/documentation/Metal/MTLArgumentEncoder/setComputePipelineStates(_:range:))

Encodes references to an array of compute pipeline states into the argument buffer.

[`setComputePipelineStates:withRange:`](/documentation/Metal/MTLArgumentEncoder/setComputePipelineStates:withRange:)

Encodes references to an array of compute pipeline states into the argument buffer.

### Encoding inlined constant data

[`constantData(at:)`](/documentation/Metal/MTLArgumentEncoder/constantData(at:))

Returns a pointer to an inline, constant-data argument within the argument buffer.

### Encoding indirect command buffers

[`setIndirectCommandBuffer(_:index:)`](/documentation/Metal/MTLArgumentEncoder/setIndirectCommandBuffer(_:index:))

Encodes a reference to an indirect command buffer into the argument buffer.

[`setIndirectCommandBuffers(_:range:)`](/documentation/Metal/MTLArgumentEncoder/setIndirectCommandBuffers(_:range:))

Encodes an array of indirect command buffers into the argument buffer.

[`setIndirectCommandBuffers:withRange:`](/documentation/Metal/MTLArgumentEncoder/setIndirectCommandBuffers:withRange:)

Encodes an array of indirect command buffers into the argument buffer.

### Encoding acceleration structures

[`setAccelerationStructure(_:index:)`](/documentation/Metal/MTLArgumentEncoder/setAccelerationStructure(_:index:))

Encodes a reference to an acceleration structure into the argument buffer.

### Encoding function tables

[`setVisibleFunctionTable(_:index:)`](/documentation/Metal/MTLArgumentEncoder/setVisibleFunctionTable(_:index:))

Encodes a reference to a visible-function table into the argument buffer.

[`setVisibleFunctionTables:withRange:`](/documentation/Metal/MTLArgumentEncoder/setVisibleFunctionTables:withRange:)

Encodes references to an array of visible function tables into the argument buffer.

[`setIntersectionFunctionTable(_:index:)`](/documentation/Metal/MTLArgumentEncoder/setIntersectionFunctionTable(_:index:))

Encodes a reference to a ray-tracing intersection-function table into the argument buffer.

[`setIntersectionFunctionTables(_:range:)`](/documentation/Metal/MTLArgumentEncoder/setIntersectionFunctionTables(_:range:))

Encodes references to an array of ray-tracing intersection-function tables into the argument buffer.

[`setVisibleFunctionTables(_:range:)`](/documentation/Metal/MTLArgumentEncoder/setVisibleFunctionTables(_:range:))

Encodes references to an array of ray-tracing intersection-function tables into the argument buffer.

[`setIntersectionFunctionTables:withRange:`](/documentation/Metal/MTLArgumentEncoder/setIntersectionFunctionTables:withRange:)

Encodes references to an array of ray-tracing intersection-function tables into the argument buffer.

### Creating a nested argument encoder

[`makeArgumentEncoderForBuffer(atIndex:)`](/documentation/Metal/MTLArgumentEncoder/makeArgumentEncoderForBuffer(atIndex:))

Creates a new argument encoder for a nested argument buffer.

### Querying alignment

[`alignment`](/documentation/Metal/MTLArgumentEncoder/alignment)

The alignment, in bytes, required for storing the encoded resources of an argument buffer.

### Identifying the argument encoder

[`label`](/documentation/Metal/MTLArgumentEncoder/label)

A string that identifies the argument buffer.

[`device`](/documentation/Metal/MTLArgumentEncoder/device)

The device object that created the argument encoder.



---

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)