And OUCH. Replacing one of my uniform-arrays with such a const vec4 dropped framerate from 93fps to 2fps :S.
Removing the “const” makes it run at 8fps.
Replacing the “const” with “uniform” (again, no curly brackets) restores it to 93fps.
I try to make whatever is constant const, so the compiler will fold it into the code when possible (even if it’s lame at dead code elimination). For instance, if I use a constant index to look into the above array, which I would make const, then only a stupid compiler isn’t going to generate the maximally efficient code there and just pretend that was a reference to that color specifically in-line in the code.
But alas, like switch statements originally, seems GLSL doesn’t believe in const arrays yet…
Yeah, that works, but there are two disadvantages:
[ol][li] uniforms have to be at global scope (so you can’t define these convenience lookups inside the only function that uses them), and [*] because they’re uniform (i.e. parameters), then compiler cannot fold the array completely out of the code in the case of indexing with a constant[/ol][/li]And I too can confirm that unlike non-uniform arrays, seems the C array initializer syntax “can” be used for uniform arrays defined at the global scope (on NVidia at least). This is a bug I gather.
No dice here. That won’t compile, either in a function or at the global scope. The error is:
error C7516: OpenGL does not allow constant arrays
Wow. Weird. And on NVidia too, with recent GPU/drivers. Let me try some tests…
Ok, here on NVidia GTX285 / 190.32 (Linux), neither the GLSL array initializer or C initializer cases dropped my perf, but using the uniform forms seemed not to honor the initializers. Always got black.