---
title: "setBuffer(_:offset:attributeStride:index:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtlcomputecommandencoder/setbuffer(_:offset:attributestride:index:)"
---

# setBuffer(_:offset:attributeStride:index:)

Binds a buffer with a stride to the buffer argument table, allowing compute kernels to access its data on the GPU.

## Declaration

```swift
func setBuffer(_ buffer: any MTLBuffer, offset: Int, attributeStride stride: Int, index: Int)
```

## Parameters

- `buffer`: The doc://com.apple.metal/documentation/Metal/MTLBuffer instance to bind to the argument table.
- `offset`: The number of bytes to skip in the buffer before the first element of data.
- `stride`: The number of bytes between the start of one element and the start of the next.
- `index`: The index the buffer binds to in the argument table.

## Discussion

Discussion important: Only call this method when the buffer is part of stageInputDescriptor and has its stride set to MTLBufferLayoutStrideDynamic. For buffers binding to an argument using the device address space, align the offset to the data type’s size. The maximum size for an offset is 16 bytes. For buffers in the constant address space, the minimum alignment depends on the hardware running your app. See the Metal feature set tables (PDF) for information on each Apple GPU family. Rebinding an already bound buffer causes a Metal error.

## See Also

### Binding buffers

- [setBuffer(_:offset:index:)](metal/mtlcomputecommandencoder/setbuffer(_:offset:index:).md)
- [setBuffers(_:offsets:range:)](metal/mtlcomputecommandencoder/setbuffers(_:offsets:range:).md)
- [setBuffers(_:offsets:attributeStrides:range:)](metal/mtlcomputecommandencoder/setbuffers(_:offsets:attributestrides:range:).md)
- [setBufferOffset(_:index:)](metal/mtlcomputecommandencoder/setbufferoffset(_:index:).md)
- [setBufferOffset(offset:attributeStride:index:)](metal/mtlcomputecommandencoder/setbufferoffset(offset:attributestride:index:).md)
