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


class 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

func setConstantValue(UnsafeRawPointer, type: MTLDataType, index: Int)

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

func setConstantValue(UnsafeRawPointer, type: MTLDataType, withName: String)

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

func setConstantValues(UnsafeRawPointer, type: MTLDataType, range: Range<Int>)

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

Resetting Constant Values

func reset()

Deletes all previously set constant values.


Inherits From

See Also

Function Variants

class MTLFunctionConstant

A constant used to specialize the behavior of a shader.