imageworks/OpenShadingLanguage — pull request #249 by lgritz (2013-05-09 17:42:39+00:00)
Title: Constant arrays

If you had a local variable in OSL, like:

float arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

It would actually generate very inefficient code, initializing every element of the array separately, each time the shader runs.

This patch recognizes arrays whose initializer lists consist only of literal values (ints, strings, or floats), and makes a legit "constant" for it, which at worst copies to the array all in one assignment rather than element-by-element. At best (that is, if it's the only assignment to the array), the runtime optimizer will elide the local array entirely and replace its reference to references to the constant array, removing any per-shader-invocation initialization.