Imagination PowerVR SDK Blog

Indexing of sampler arrays


#1

I'm running the OpenGL ES 2.0 PC Emulator v2.08.28.0634 and have found what I think is a bug in the shader compiler. This is example fragment shader code that triggers it:

#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D uni[8];
void main()
{
   vec4 c = vec4(0,0,0,0);
   for (int ii = 0; ii < 8; ++ii) {
     c += texture2D(uni[ii], vec2(0.5, 0.5));
   }
   gl_FragColor = c;
}

[/CODE]

Compiling this code with PVRUniSCo produces the following error:

[CODE]

ERROR: 0:9: '[ii]' : arrays of samplers may only be indexed by a constant integer expression
ERROR: 1 compilation errors. No code generated.
[/CODE]

The GLSL[1] spec mandates support for indexing arrays of samplers using "constant-index-expression", it also provides a definition of constant-index-expression as quoted below:

[QUOTE]

Definition:
constant-index-expressions are a superset of constant-expressions. Constant-index-expressions can include loop indices as defined in Appendix A section 4.
The following are constant-index-expressions:
• Constant expressions
• Loop indices as defined in section 4
• Expressions composed of both of the above
When used as an index, a constant-index-expression must have integral type.

[/QUOTE]

[1] http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf

So I think that since loop indices are used in the TC above it should not fail to compile. Or am I missing something here?

</p><p>#ifdef GL_ES<br>precision mediump float;<br>#endif<br>uniform sampler2D uni[8];<br>void main()<br>{<br>&nbsp; &nbsp;vec4 c = vec4(0,0,0,0);<br>&nbsp; &nbsp;for (int ii = 0; ii &lt; 8; ++ii) {<br>&nbsp; &nbsp; &nbsp;c += texture2D(uni[ii], vec2(0.5, 0.5));<br>&nbsp; &nbsp;}<br>&nbsp; &nbsp;gl_FragColor = c;<br>}</p><p>

Compiling this code with PVRUniSCo produces the following error:

ERROR: 0:9: ‘[ii]’ : arrays of samplers may only be indexed by a constant integer expression
ERROR: 1 compilation errors. No code generated.
[/CODE]

The GLSL[1] spec mandates support for indexing arrays of samplers using “constant-index-expression”, it also provides a definition of constant-index-expression as quoted below:

[QUOTE]

Definition:
constant-index-expressions are a superset of constant-expressions. Constant-index-expressions can include loop indices as defined in Appendix A section 4.
The following are constant-index-expressions:
• Constant expressions
• Loop indices as defined in section 4
• Expressions composed of both of the above
When used as an index, a constant-index-expression must have integral type.

[/QUOTE]

[1] http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf

So I think that since loop indices are used in the TC above it should not fail to compile. Or am I missing something here?

</p><p>ERROR: 0:9: '[ii]' : arrays of samplers may only be indexed by a constant integer expression<br>ERROR: 1 compilation errors. No code generated.<br>

The GLSL[1] spec mandates support for indexing arrays of samplers using “constant-index-expression”, it also provides a definition of constant-index-expression as quoted below:

Quote:

Definition:
constant-index-expressions are a superset of constant-expressions. Constant-index-expressions can include loop indices as defined in Appendix A section 4.
The following are constant-index-expressions:
• Constant expressions
• Loop indices as defined in section 4
• Expressions composed of both of the above
When used as an index, a constant-index-expression must have integral type.

[1] http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf

So I think that since loop indices are used in the TC above it should not fail to compile. Or am I missing something here?