# Indexing of sampler arrays

**URL:** <https://forums.imgtec.com/t/indexing-of-sampler-arrays/1070>\
**Category:** PowerVR Insider\
**Created:** [May 6, 2011, 8:35am UTC](https://forums.imgtec.com/t/indexing-of-sampler-arrays/1070 "2011-05-06T08:35:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunet-2](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@sunet-2](https://forums.imgtec.com/u/sunet-2)\
**Post date:** [May 6, 2011, 8:35am UTC](https://forums.imgtec.com/t/indexing-of-sampler-arrays/1070/1 "2011-05-06T08:35:34Z")

</div>

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()  
{  
&nbsp; &nbsp;vec4 c = vec4(0,0,0,0);  
&nbsp; &nbsp;for (int ii = 0; ii \< 8; ++ii) {  
&nbsp; &nbsp; &nbsp;c += texture2D(uni[ii], vec2(0.5, 0.5));  
&nbsp; &nbsp;}  
&nbsp; &nbsp;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](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](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](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?
