Limits of GLSL Arrays

In an earlier question, I asked about how to move more processing into the GPU.

I think that may have been too vague, so lets just ask:

  • How large an array can I build in the shader? Is there a gl query function?
  • Can I index into the array with a variable rather than constant? The GLSL reference is a bit vague.
  • Ditto for a for(init, condx, incr) loop. Can the condx be i<variable rather than i<const?


– Owen

The answer is it’s implementation dependent.

However, the usual trick is to pack large arrays into textures - which gives you a practical limit up in the millions. You can generally rely on having 2048x2048 by four (RGBA).