---
title: MTLArgumentEncoder
framework: metal
role: symbol
role_heading: Protocol
path: metal/mtlargumentencoder
---

# MTLArgumentEncoder

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

## Declaration

```swift
protocol MTLArgumentEncoder : NSObjectProtocol
```

## Mentioned in

Improving CPU performance by using argument buffers

## Overview

Overview An MTLArgumentEncoder instance encodes buffers, textures, samplers, and inlined constant data into an argument buffer. An MTLBuffer instance represents the argument buffer that you set as the encoding destination by calling the 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 methods: makeArgumentEncoder(bufferIndex:) 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 instances. To create an encoder for this type of argument buffer, call the makeArgumentEncoder(arguments:) method of the 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:)](metal/mtlargumentencoder/setargumentbuffer(_:offset:).md)
- [setArgumentBuffer(_:startOffset:arrayElement:)](metal/mtlargumentencoder/setargumentbuffer(_:startoffset:arrayelement:).md)
- [encodedLength](metal/mtlargumentencoder/encodedlength.md)

### Encoding buffers

- [setBuffer(_:offset:index:)](metal/mtlargumentencoder/setbuffer(_:offset:index:).md)
- [setBuffers(_:offsets:range:)](metal/mtlargumentencoder/setbuffers(_:offsets:range:).md)

### Encoding textures

- [setTexture(_:index:)](metal/mtlargumentencoder/settexture(_:index:).md)
- [setTextures(_:range:)](metal/mtlargumentencoder/settextures(_:range:).md)

### Encoding samplers

- [setSamplerState(_:index:)](metal/mtlargumentencoder/setsamplerstate(_:index:).md)
- [setSamplerStates(_:range:)](metal/mtlargumentencoder/setsamplerstates(_:range:).md)

### Encoding pipeline states

- [setRenderPipelineState(_:index:)](metal/mtlargumentencoder/setrenderpipelinestate(_:index:).md)
- [setRenderPipelineStates(_:range:)](metal/mtlargumentencoder/setrenderpipelinestates(_:range:).md)
- [setComputePipelineState(_:index:)](metal/mtlargumentencoder/setcomputepipelinestate(_:index:).md)
- [setComputePipelineStates(_:with:)](metal/mtlargumentencoder/setcomputepipelinestates(_:with:).md)
- [setComputePipelineState(_:at:)](metal/mtlargumentencoder/setcomputepipelinestate(_:at:).md)
- [setComputePipelineStates(_:range:)](metal/mtlargumentencoder/setcomputepipelinestates(_:range:).md)

### Encoding inlined constant data

- [constantData(at:)](metal/mtlargumentencoder/constantdata(at:).md)

### Encoding indirect command buffers

- [setIndirectCommandBuffer(_:index:)](metal/mtlargumentencoder/setindirectcommandbuffer(_:index:).md)
- [setIndirectCommandBuffers(_:range:)](metal/mtlargumentencoder/setindirectcommandbuffers(_:range:).md)

### Encoding acceleration structures

- [setAccelerationStructure(_:index:)](metal/mtlargumentencoder/setaccelerationstructure(_:index:).md)

### Encoding function tables

- [setVisibleFunctionTable(_:index:)](metal/mtlargumentencoder/setvisiblefunctiontable(_:index:).md)
- [setIntersectionFunctionTable(_:index:)](metal/mtlargumentencoder/setintersectionfunctiontable(_:index:).md)
- [setIntersectionFunctionTables(_:range:)](metal/mtlargumentencoder/setintersectionfunctiontables(_:range:).md)
- [setVisibleFunctionTables(_:range:)](metal/mtlargumentencoder/setvisiblefunctiontables(_:range:).md)

### Creating a nested argument encoder

- [makeArgumentEncoderForBuffer(atIndex:)](metal/mtlargumentencoder/makeargumentencoderforbuffer(atindex:).md)

### Querying alignment

- [alignment](metal/mtlargumentencoder/alignment.md)

### Identifying the argument encoder

- [label](metal/mtlargumentencoder/label.md)
- [device](metal/mtlargumentencoder/device.md)

### Instance Methods

- [setDepthStencilState(_:index:)](metal/mtlargumentencoder/setdepthstencilstate(_:index:).md)
- [setDepthStencilStates(_:range:)](metal/mtlargumentencoder/setdepthstencilstates(_:range:).md)

## Relationships

### Inherits From

- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Argument buffers

- [Improving CPU performance by using argument buffers](metal/improving-cpu-performance-by-using-argument-buffers.md)
- [Managing groups of resources with argument buffers](metal/managing-groups-of-resources-with-argument-buffers.md)
- [Tracking the resource residency of argument buffers](metal/tracking-the-resource-residency-of-argument-buffers.md)
- [Indexing argument buffers](metal/indexing-argument-buffers.md)
- [Rendering terrain dynamically with argument buffers](metal/rendering-terrain-dynamically-with-argument-buffers.md)
- [Encoding argument buffers on the GPU](metal/encoding-argument-buffers-on-the-gpu.md)
- [Using argument buffers with resource heaps](metal/using-argument-buffers-with-resource-heaps.md)
- [MTLArgumentDescriptor](metal/mtlargumentdescriptor.md)
- [MTLAttributeStrideStatic](metal/mtlattributestridestatic.md)
