From the OpenGL ES spec section 2.10.4 (Shader Variables: Varying Variables):
The number of interpolators available for processing varying variables is given by the implementation-dependent constant
MAX_VARYING_VECTORS.This value represents the number of four-element floating-point vectors that can be interpolated; varying variables declared as matrices or arrays will consume multiple interpolators.
When a program is linked, any varying variable written by a vertex shader, or read by a fragment shader, will count against this limit.
A program whose shaders access more than
MAX_VARYING_VECTORSworth of varying variables may fail to link
In Chrome on my machine, gl.getParameter(gl.MAX_VARYING_VECTORS) returns 15, which means I can use 15 vec4 varyings in a shader.
I've verified this with a few tests. 15 vec4 varyings work OK, but when attempting to use 16, the program fails to link and gl.getProgramInfoLog() returns "Varyings over maximum register limit".
But how many varyings of type vec3, vec2 or float can be used?
The OpenGL ES spec seems to hint at this, without being explicit:
any varying variable ... will count against this limit.
A program whose shaders access more than
MAX_VARYING_VECTORSworth of varying variables may fail to link
I'm making two guesses:
- The maximum number of varying
floats is given by:
MAX_VARYING_VECTORS * 4
(4floats pervec4vector) - If (for example)
MAX_VARYING_VECTORSis8, then each of the following can safely be used without causing any linking errors:- 8
vec4varyings - 10
vec3varyings - 16
vec2varyings - 32
floatvaryings - 3
vec4, 3vec3, 3vec2and 5floatvaryings - 1
vec4varying array of length8 - 1
vec3varying array of length10 - 1
vec2varying array of length16 - 1
floatvarying array of length32 - Any other combination of
vec4/vec3/vec2/floatvariables or arrays, which uses a maximum of 32floats
- 8
So with my MAX_VARYING_VECTORS value of 15, I guess I can use a maximum of 60 floats.
My tests seem to confirm this.
For example, 30 vec2 varyings work OK on my machine, but 31 causes a "Varyings over maximum register limit" linking error.
So my questions are:
- Are my two guesses correct?
- If
MAX_VARYING_VECTORSis8, then is it safe to use 16vec2varyings? Is this guaranteed to always work?