From eebed6f60bd0df088032506e40a55b80629f03d8 Mon Sep 17 00:00:00 2001
From: John Kessenich <cepheus@frii.com>
Date: Mon, 24 Jun 2013 21:52:41 +0000
Subject: [PATCH] Disallow variable indexing into sampler array for ES and
 desktop before version 400.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@22148 e7fa87d3-cd2b-0410-9028-fcbf551c1848
---
 Test/300.frag                        |  5 ++++-
 Test/400.frag                        | 12 ++++++++++++
 Test/testlist                        |  1 +
 glslang/MachineIndependent/glslang.y |  4 ++++
 4 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 Test/400.frag

diff --git a/Test/300.frag b/Test/300.frag
index 7419379d7..1e16a1459 100644
--- a/Test/300.frag
+++ b/Test/300.frag
@@ -48,6 +48,8 @@ in S2 s2;
 out vec3 sc;
 out float sf;
 
+uniform sampler2D arrayedSampler[5];
+
 void main()
 {
     float f;
@@ -57,13 +59,14 @@ void main()
     v = textureLod(s2DArray, c3D, 1.2);
     f = textureOffset(s2DShadow, c3D, ic2D, c1D);
     v = texelFetch(s3D, ic3D, ic1D);
-    v = texelFetchOffset(s2D, ic2D, 4, ic2D);
+    v = texelFetchOffset(arrayedSampler[2], ic2D, 4, ic2D);
     f = textureLodOffset(s2DShadow, c3D, c1D, ic2D);
     v = textureProjLodOffset(s2D, c3D, c1D, ic2D);
     v = textureGrad(sCube, c3D, c3D, c3D);
     f = textureGradOffset(s2DArrayShadow, c4D, c2D, c2D, ic2D);
     v = textureProjGrad(s3D, c4D, c3D, c3D);
     v = textureProjGradOffset(s2D, c3D, c2D, c2D, ic2D);
+    v = texture(arrayedSampler[ic1D], c2D);                 // ERROR
 
     ivec4 iv;
     iv = texture(is2D, c2D);
diff --git a/Test/400.frag b/Test/400.frag
new file mode 100644
index 000000000..f4288ab14
--- /dev/null
+++ b/Test/400.frag
@@ -0,0 +1,12 @@
+#version 330 core
+
+in vec2 c2D;
+flat in int i;
+
+uniform sampler2D arrayedSampler[5];
+
+void main()
+{
+    vec4 v;
+    v = texture(arrayedSampler[i], c2D);
+}
diff --git a/Test/testlist b/Test/testlist
index e67078981..f2df38d92 100644
--- a/Test/testlist
+++ b/Test/testlist
@@ -39,5 +39,6 @@ uint.frag
 switch.frag
 tokenLength.vert
 300scope.vert
+400.frag
 420.vert
 430scope.vert
diff --git a/glslang/MachineIndependent/glslang.y b/glslang/MachineIndependent/glslang.y
index 3cd084e24..3164ced0d 100644
--- a/glslang/MachineIndependent/glslang.y
+++ b/glslang/MachineIndependent/glslang.y
@@ -309,6 +309,10 @@ postfix_expression
                     parseContext.error($2.line, "", "[", "array must be redeclared with a size before being indexed with a variable");
                 if ($1->getBasicType() == EbtBlock)
                     parseContext.requireProfile($1->getLine(), static_cast<EProfileMask>(~EEsProfileMask), "variable indexing block array");
+                if ($1->getBasicType() == EbtSampler) {
+                    parseContext.requireProfile($1->getLine(), static_cast<EProfileMask>(ECoreProfileMask | ECompatibilityProfileMask), "variable indexing sampler array");
+                    parseContext.profileRequires($1->getLine(), ECoreProfile, 400, 0, "variable indexing sampler array");
+                }
 
                 $$ = parseContext.intermediate.addIndex(EOpIndexIndirect, $1, $3, $2.line);
             }
-- 
GitLab