---
title: MTLFunctionConstantValues
framework: metal
role: symbol
role_heading: Class
path: metal/mtlfunctionconstantvalues
---

# MTLFunctionConstantValues

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

## Declaration

```swift
class MTLFunctionConstantValues
```

## Overview

Overview An 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 for more information. With an 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 instance to multiple 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 instance and reuse it to create another MTLFunction instance. tip: See Using function specialization to build pipeline variants for a sample code project that applies function constant values.

## Topics

### Setting constant values

- [setConstantValue(_:type:index:)](metal/mtlfunctionconstantvalues/setconstantvalue(_:type:index:).md)
- [setConstantValue(_:type:withName:)](metal/mtlfunctionconstantvalues/setconstantvalue(_:type:withname:).md)
- [setConstantValues(_:type:range:)](metal/mtlfunctionconstantvalues/setconstantvalues(_:type:range:).md)

### Resetting constant values

- [reset()](metal/mtlfunctionconstantvalues/reset().md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Compile-time variant functions

- [MTLFunctionConstant](metal/mtlfunctionconstant.md)
