GLSL ES 3.0 - uniform in both vertex and fragment shader, and max vertex/fragment uniform vectors

StackOverflow https://stackoverflow.com/questions/20533601

Question

In OpenGL ES 3.0, we have the minimum number of uniform vectors available in both the vertex and fragment shaders:

const mediump int gl_MaxVertexUniformVectors = 256;
const mediump int gl_MaxFragmentUniformVectors = 224;

If we have a uniform that is defined the same in both the vertex and fragment shaders, does it exist within the compiled program only once, and if so which of these limits does it's storage space negate from?

Was it helpful?

Solution

The ES 3.0 spec. needlessly complicates the discussion of uniform storage (hence, I referenced the 2.0 spec). In a nutshell this limit refers to the amount of uniform space an individual stage has on reserve. A GLSL program may store more than 256 uniform locations total, but no individual stage is required to be able to use more than 256 at a time.

OpenGL ES 2.0 Specification - 2.10 Vertex Shaders (Uniform Variables) - pp. 35

The amount of storage available for uniform variables accessed by a vertex shader is specified by the implementation-dependent constant MAX_VERTEX_UNIFORM_VECTORS. This value represents the number of four-element floating-point, integer, or boolean vectors that can be held in uniform variable storage for a vertex shader. A link error will be generated if an attempt is made to utilize more than the space available for vertex shader uniform variables.

Though it is highly implementation specific, you could think of the set of uniforms as overall program storage and then within each stage those uniforms have to be assigned to a limited set of registers from the GPU's register file before they can be used. This is one good thing about establishing active vs. inactive uniforms statically at compile/link time, it can significantly reduce the storage requirements for each stage for a linked program with inactive code paths.

By the way, if this were a limit that applied to all stages, following normal GL nomenclature the limit would most likely be named: ..._MAX_COMBINED_... and would not include the name of a particular stage.

OTHER TIPS

Simply by the fact that they are different numbers tells me two things:

1) If they were shared, then you couldn't have 256 vertex vectors and 224 fragment vectors (480 vectors total). Which is clearly a valid configuration. 2) If they were shared, I would expect them to have the same max value, or for that matter, it would make no sense to have separate max values for vertex and fragment shaders.

I know it's not an official answer, and by all means post one if you can find it. All the best playing with triangles! :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top