Reputation: 1406
I declare an array in my WebGL vertex shader:
attribute vec2 position;
void main() {
#define length 1024
float arr[length];
// use arr so that it doesn't get optimized away
This works, but if I increase length
to 2048 then gl.drawArrays
does nothing. There are no errors- shaders compile, program links and passes gl.validateProgram
. I'm guessing that I tried to use too much memory on the stack. Is there a better, programmatic way to discover this limit? Am I doing something else wrong?
Upvotes: 1
Views: 334
Reputation: 52166
There are no errors- shaders compile, program links and passes gl.validateProgram.
As guaranteed by the spec!
Section 2.10: "Vertex Shaders", page 42:
A shader should not fail to compile, and a program object should not fail to link due to lack of instruction space or lack of temporary variables.
The GLSL spec helpfully notes:
Appendix A, section 3: "Usage of Temporary Variables":
The maximum number of variables is defined by the conformance tests.
You can get your very own copy of the conformance tests for the low, low price of $14,000-$19,000.
However, you can at least detect this situation (Section 2.10, page 41):
It is not always possible to determine at link time if a program object actually will execute. Therefore validation is done when the first rendering command (DrawArrays or DrawElements) is issued, to determine if the currently active program object can be executed. If it cannot be executed then no fragments will be rendered, and the rendering command will generate the error
INVALID_OPERATION
.
Upvotes: 3