Contents

constantValues

Values for the function-constant inputs that the shader graph declares.

Declaration

var constantValues: MTLFunctionConstantValues

Discussion

Function constants are baked into the compiled shader at program creation time and can’t be changed afterward. Use them for values that don’t vary at runtime — for example, a feature flag that selects between two code paths — to eliminate runtime branching and produce a leaner shader. To vary a value across frames or instances, declare it as a regular graph input and supply it through inputValues or setParameter(name:value:) instead.

Two descriptors that share the same shader graph but differ in their function-constant values produce distinct compiled programs that don’t compare equal.

See Also

Configuring the shader program