<div dir="ltr"><div><div>Hello,<br><br></div>in my opinion GLSL compiler in mesa is too restrictive when it comes to sampler arrays. The following code can not be compiled due to the "sampler arrays indexed with non-constant expressions is forbidden in GLSL 1.30 and later":<br>
<br></div>#define MAX_SHADOWS 2<br><div><br>varying vec4 v_ShadowProjVector[MAX_SHADOWS];<br><br>uniform sampler2DShadow u_ShadowmapTexture[MAX_SHADOWS];<br># define qfShadow2D(t,v) float(shadow2D(t,v))<br><br>uniform float u_ShadowAlpha;<br>
uniform float u_ShadowProjDistance[MAX_SHADOWS];<br>uniform vec4 u_ShadowmapTextureParams[MAX_SHADOWS];<br><br>void main(void)<br>{<br>    float finalcolor = 1.0;<br><br>    for (int i = 0; i < MAX_SHADOWS; i++)<br>    {<br>
        vec3 shadowmaptc = vec3(v_ShadowProjVector[i].xyz / v_ShadowProjVector[i].w);<br><br>        // this keeps shadows from appearing on surfaces behind frustum's nearplane<br>        float d = step(v_ShadowProjVector[i].w, 0.0);<br>
<br>        //shadowmaptc = (shadowmaptc + vec3 (1.0)) * vec3 (0.5);<br>        shadowmaptc.xy = shadowmaptc.xy * u_ShadowmapTextureParams[i].xy; // .x - texture width<br>        shadowmaptc.z = clamp(shadowmaptc.z, 0.0, 1.0);<br>
        shadowmaptc.xy = vec2(clamp(shadowmaptc.x, 0.0, u_ShadowmapTextureParams[i].x), clamp(shadowmaptc.y, 0.0, u_ShadowmapTextureParams[i].y));<br><br>        vec2 ShadowMap_TextureScale = u_ShadowmapTextureParams[i].zw;<br>
<br>        float f;<br><br>        f = qfShadow2D(u_ShadowmapTexture[i], vec3(shadowmaptc.xy * ShadowMap_TextureScale, shadowmaptc.z));<br>        <br>        finalcolor *= clamp(max(max(f, d), u_ShadowAlpha), 0.0, 1.0);<br>
    }<br><br>    gl_FragColor = vec4(vec3(finalcolor),1.0);<br>}<br><br clear="all"><div><div><br></div><div>Lines 159-136 of src/glsl/ast_array_index.cpp say:<br><br>    * This restriction was added in GLSL 1.30.  Shaders using earlier version<br>
    * of the language should not be rejected by the compiler front-end for<br>    * using this construct.  This allows useful things such as using a loop<br>    * counter as the index to an array of samplers.  If the loop in unrolled,<br>
    * the code should compile correctly.  Instead, emit a warning.<br></div><div><br></div><div>If compiler actually attempted to unroll the loop above, it would notice that the does compile correctly. Instead it just emits and error and in my opinion, contradicts the comment above but not allowing the "useful thing" in question.<br>
<br></div><div>Can the compiler be changed to _first_ attempt to unroll the loop and then check for sampler array indices being constants?<br></div><div><br>-- <br>Best regards,<br> Victor Luchitz
</div></div></div></div>