Constant Data in Shaders#
If used correctly, the const
keyword can provide a significant performance boost. For example, a shader that declares a const
array outside of the main()
block can perform significantly better than the same shader with the array not marked as const
, even if the array could be treated as such.
Another example is the use of a const
value to reference an array member. In this example, if the value is const
, the graphics core can know ahead of time that the number will not change, and data can be pre-fetched prior to the shader being run.