<!--
{
  "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/constantData(at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLArgumentEncoder(im)constantDataAtIndex:"
  },
  "title" : "constantData(at:)"
}
-->

# constantData(at:)

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

```
func constantData(at index: Int) -> UnsafeMutableRawPointer
```

## Parameters

`index`

The index of an inline, constant-data argument within the argument buffer.
The value corresponds to either the index ID of a declaration in
Metal Shading Language (MSL) or the [`index`](/documentation/Metal/MTLArgumentDescriptor/index) property of
an [`MTLArgumentDescriptor`](/documentation/Metal/MTLArgumentDescriptor) instance.

## Return Value

A pointer to the location in the buffer to which you should write the constant data.

## Discussion

Constants declared contiguously in the Metal shading language (in an array or structure) are contiguous in memory. You can encode contiguous ranges of inlined constant data through a pointer to the first constant.

To encode inlined constant data into the argument buffer, perform a memory copy operation from your data’s source pointer to the returned destination pointer.

```swift
let sourceConstants: [SourceConstants] = [
    // Inlined constant data.
    /* ... */
]
let destinationPointer = abEncoder.constantData(: 0)
destinationPointer.copyBytes(from: sourceConstants, count: MemoryLayout<SourceConstants>.size)
```

---

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)