In a complex shader with, for instance, the main fragment shader function calling sub-functions, those sub-functions might need access to data from the input parameters. Or even access to a value computed in the top level function.
Perhaps the function needs a float holding a value I want to compute only once. Or a texture which has useful data.
I am probably missing something, but the rigid scoping of the metal shader language seems to make that more difficult than in other shader languages.
When trying to access this stuff we see "use of undeclared identifier"
Most of the example code has only simple, single-function shaders, so obviously the problem does not present itself.
I tried nesting the sub-functions inside the main fragment shader (to share scope), but that is not allowed.
One solution would be to pass those values as function parameters all the way down. But that looks ugly and I am guessing that it would be inefficient.
I just wondered whether the MSL creators had a solution to this?