A set of constant values used to specialize a graphics or compute function.


@interface MTLFunctionConstantValues : NSObject


A MTLFunctionConstantValues object sets constant values for function constants. Function constants are declared with the [[ function_constant(index) ]] attribute in Metal shading language source code. Refer to the Metal Shading Language Guide for more information.

Single constant values can be set individually by index or name. Multiple constant values can be set together with an index range.

A single MTLFunctionConstantValues object can be applied to multiple MTLFunction objects (for example, a vertex function and a fragment function). After a specialized function has been created, any changes to its constant values have no further effect on it. However, you can reset, add, or modify any constant values in the MTLFunctionConstantValues object and reuse it to create another MTLFunction object.


Setting Constant Values

- setConstantValue:type:atIndex:

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

- setConstantValue:type:withName:

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

- setConstantValues:type:withRange:

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

Resetting Constant Values

- reset

Deletes all previously set constant values.


Inherits From

Conforms To

See Also

Function Variants


A constant used to specialize the behavior of a shader.