<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLFunctionConstantValues",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(cs)MTLFunctionConstantValues"
  },
  "title" : "MTLFunctionConstantValues"
}
-->

# MTLFunctionConstantValues

A set of constant values that specialize a graphics or compute GPU function.

```
class MTLFunctionConstantValues
```

## Overview

An [`MTLFunctionConstantValues`](/documentation/Metal/MTLFunctionConstantValues) instance sets constant values for function constants.
You declare function constants with the `[[ function_constant(index) ]]` attribute
in MSL (Metal Shading Language) source code.
See the
[Metal Shading Language specification](https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf)
for more information.

With an [`MTLFunctionConstantValues`](/documentation/Metal/MTLFunctionConstantValues) instance, you can set each constant value
individually with an index or a name, or set multiple constant values with an index range.

You can apply a single [`MTLFunctionConstantValues`](/documentation/Metal/MTLFunctionConstantValues) instance to multiple
[`MTLFunction`](/documentation/Metal/MTLFunction) instances of any kind, such as a vertex function and a fragment function.
When you create a specialized function, subsequent changes to its constant values
have no effect.
However, you can reset, add, or modify a constant value in your [`MTLFunctionConstantValues`](/documentation/Metal/MTLFunctionConstantValues)
instance and reuse it to create another [`MTLFunction`](/documentation/Metal/MTLFunction) instance.

> Tip:
> See <doc://com.apple.metal/documentation/Metal/using-function-specialization-to-build-pipeline-variants> for a sample
> code project that applies function constant values.

## Topics

### Setting constant values

[`setConstantValue(_:type:index:)`](/documentation/Metal/MTLFunctionConstantValues/setConstantValue(_:type:index:))

Sets a value for a function constant at a specific index.

[`setConstantValue(_:type:withName:)`](/documentation/Metal/MTLFunctionConstantValues/setConstantValue(_:type:withName:))

Sets a value for a function constant with a specific name.

[`setConstantValues(_:type:range:)`](/documentation/Metal/MTLFunctionConstantValues/setConstantValues(_:type:range:))

Sets values for a group of function constants within a specific index range.

[`setConstantValues:type:withRange:`](/documentation/Metal/MTLFunctionConstantValues/setConstantValues:type:withRange:)

Sets values for a group of function constants within a specific index range.

### Resetting constant values

[`reset()`](/documentation/Metal/MTLFunctionConstantValues/reset())

Deletes all previously set constant values.



---

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)