[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Public WebGL] Making GLSL uniform array behavior more consistant

An issue has come up with large uniform arrays.

You can make a shader like this

uniform vec4 array[1000000];  // too many uniforms

void main() {
  gl_FragColor = array[1];

This will work on some drivers and fail on others. My reading of the spec says it's supposed to work. The ES spec 2.10.4 page 37

If one or more elements of an array are active, GetActiveUniform will return
the name of the array in name, subject to the restrictions listed above. The type of
the array is returned in type. The size parameter contains the highest array element
index used, plus one. The compiler or linker determines the highest index used.

There will be only one active uniform reported by the GL per uniform array.

This same language is in the OpenGL 2.1 (not ES) spec. haven't checked the OpenGL 4.3 spec.

Some people interpret that to mean it's implementation dependent. 

For WebGL I feel we should be more strict we should either fail all such shaders (shaders that declare more uniforms than could possibly fit even if not using every element) or we should require all such shaders to work.

The GLSL spec declares a minimum packing algorithm which we could apply if we choose must fail. I think that one is arguably easier than must pass since array indices could go through some complex math even if all the inputs are constant or include a loop index (which also has the const restriction)

It seesm to me developers shouldn't have to worry that their shader which works on a truncating driver will fail on a non-truncating driver. Modulo the maximum uniforms for that card the same shader should succeed everywhere or fail everywhere.