3

I plan on writing a program that will take some paraemeters as input and will generate its own fragment shader string which will then be compiled, linked and used as a fragment shader (it will only be done once at the start of a program). Im not an expert in computer graphics so I dont know if this is standard practice but I definitely think it has the potential for some interesting applications - not necessarily graphics applications but possibly computational ones.

My question is what is the code size limit of a shader in OpenGL i.e. how much memory can OpenGL reasonably allocate to a program on the graphics processor?

twerdster
  • 4,977
  • 3
  • 40
  • 70
  • I'm pretty sure it's implementation-defined, but why would you want such large *code* anyway? – Bartek Banachewicz Jan 30 '13 at 14:00
  • 3
    You have 512 guaranteed instruction slots and a guaranteed maximum of 65536 exectuted instructions in OpenGL 2.x -- see my more detailled answer [here](http://stackoverflow.com/a/5601884/572743). Note that "guaranteed maximum" doesn't mean your card couldn't have more, it's just that no more than that is guaranteed, everything else you must query first to be sure. – Damon Jan 30 '13 at 14:01

1 Answers1

3

There is no code size limit. OK, there is, but:

  1. OpenGL doesn't give you a way to query it because:
  2. Such a number would be meaningless, since it does not translate to anything you can directly control in GLSL.

A long GLSL shader might compile while a short shader can't. Why? Because the compiler may have been able to optimize the long shader down to size, while the short shader expanded to lots of opcodes. In short, GLSL is too high-level to be able to effectively quantify such limitations.

In any case, given the limitations of GL 2.x-class hardware, you probably won't hit any length limitations unless you're trying to do so or are doing GPGPU work.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982