Don't include samplers in uniform vector count validation

Change-Id: Id2820643b70d3266c82eb10a5f05d3a5886e9323
Reviewed-on: https://chromium-review.googlesource.com/304871
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Tryjob-Request: Jamie Madill <jmadill@chromium.org>
Tested-by: Austin Kinross <aukinros@microsoft.com>
diff --git a/src/tests/gl_tests/GLSLTest.cpp b/src/tests/gl_tests/GLSLTest.cpp
index c915ec4..c19b873 100644
--- a/src/tests/gl_tests/GLSLTest.cpp
+++ b/src/tests/gl_tests/GLSLTest.cpp
@@ -346,6 +346,91 @@
         }
     }
 
+    void CompileGLSLWithUniformsAndSamplers(GLint vertexUniformCount,
+                                            GLint fragmentUniformCount,
+                                            GLint vertexSamplersCount,
+                                            GLint fragmentSamplersCount,
+                                            bool expectSuccess)
+    {
+        std::stringstream vertexShader;
+        std::stringstream fragmentShader;
+
+        // Generate the vertex shader
+        vertexShader << "precision mediump float;\n";
+
+        for (int i = 0; i < vertexUniformCount; i++)
+        {
+            vertexShader << "uniform vec4 v" << i << ";\n";
+        }
+
+        for (int i = 0; i < vertexSamplersCount; i++)
+        {
+            vertexShader << "uniform sampler2D s" << i << ";\n";
+        }
+
+        vertexShader << "void main()\n{\n";
+
+        for (int i = 0; i < vertexUniformCount; i++)
+        {
+            vertexShader << "    gl_Position +=  v" << i << ";\n";
+        }
+
+        for (int i = 0; i < vertexSamplersCount; i++)
+        {
+            vertexShader << "    gl_Position +=  texture2D(s" << i << ", vec2(0.0, 0.0));\n";
+        }
+
+        if (vertexUniformCount == 0 && vertexSamplersCount == 0)
+        {
+            vertexShader << "   gl_Position = vec4(0.0);\n";
+        }
+
+        vertexShader << "}\n";
+
+        // Generate the fragment shader
+        fragmentShader << "precision mediump float;\n";
+
+        for (int i = 0; i < fragmentUniformCount; i++)
+        {
+            fragmentShader << "uniform vec4 v" << i << ";\n";
+        }
+
+        for (int i = 0; i < fragmentSamplersCount; i++)
+        {
+            fragmentShader << "uniform sampler2D s" << i << ";\n";
+        }
+
+        fragmentShader << "void main()\n{\n";
+
+        for (int i = 0; i < fragmentUniformCount; i++)
+        {
+            fragmentShader << "    gl_FragColor +=  v" << i << ";\n";
+        }
+
+        for (int i = 0; i < fragmentSamplersCount; i++)
+        {
+            fragmentShader << "    gl_FragColor +=  texture2D(s" << i << ", vec2(0.0, 0.0));\n";
+        }
+
+        if (fragmentUniformCount == 0 && fragmentSamplersCount == 0)
+        {
+            fragmentShader << "    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n";
+        }
+
+        fragmentShader << "}\n";
+
+        GLuint program = CompileProgram(vertexShader.str(), fragmentShader.str());
+
+        if (expectSuccess)
+        {
+            EXPECT_NE(0u, program);
+        }
+        else
+        {
+            EXPECT_EQ(0u, program);
+        }
+    }
+
     std::string mSimpleVSSource;
 };
 
@@ -1132,160 +1217,78 @@
 // can actually be used.
 TEST_P(GLSLTest, VerifyMaxVertexUniformVectors)
 {
-    const std::string &fragmentShaderSource = SHADER_SOURCE
-    (
-        precision mediump float;
-        void main()
-        {
-            gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
-        }
-    );
-
     int maxUniforms = 10000;
     glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
     EXPECT_GL_NO_ERROR();
     std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl;
 
-    std::stringstream vshaderSource;
-    vshaderSource << "precision mediump float;\n";
+    CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, 0, 0, true);
+}
 
-    for (int i = 0; i < maxUniforms; i++)
-    {
-        vshaderSource << "uniform vec4 v" << i << ";\n";
-    }
+// Tests that the maximum uniforms count returned from querying GL_MAX_VERTEX_UNIFORM_VECTORS
+// can actually be used along with the maximum number of texture samplers.
+TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsWithSamplers)
+{
+    int maxUniforms = 10000;
+    glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
+    EXPECT_GL_NO_ERROR();
+    std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl;
 
-    vshaderSource << "void main()\n{\n";
+    int maxTextureImageUnits = 0;
+    glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);
 
-    for (int i = 0; i < maxUniforms; i++)
-    {
-        vshaderSource << "    gl_Position +=  v" << i << ";\n";
-    }
-
-    vshaderSource << "}\n";
-
-    GLuint program = CompileProgram(vshaderSource.str(), fragmentShaderSource);
-    EXPECT_NE(0u, program);
+    CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, maxTextureImageUnits, 0, true);
 }
 
 // Tests that the maximum uniforms count + 1 from querying GL_MAX_VERTEX_UNIFORM_VECTORS
 // fails shader compilation.
 TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsExceeded)
 {
-    const std::string &fragmentShaderSource = SHADER_SOURCE
-    (
-        precision mediump float;
-        void main()
-        {
-            gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
-        }
-    );
-
     int maxUniforms = 10000;
     glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
     EXPECT_GL_NO_ERROR();
-    // Add 1 more to exceed the reported max count
-    maxUniforms += 1;
-    std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS + 1 = " << maxUniforms << std::endl;
+    std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS + 1 = " << maxUniforms + 1 << std::endl;
 
-    std::stringstream vshaderSource;
-    vshaderSource << "precision mediump float;\n";
-
-    for (int i = 0; i < maxUniforms; i++)
-    {
-        vshaderSource << "uniform vec4 v" << i << ";\n";
-    }
-
-    vshaderSource << "void main()\n{\n";
-
-    for (int i = 0; i < maxUniforms; i++)
-    {
-        vshaderSource << "    gl_Position +=  v" << i << ";\n";
-    }
-
-    vshaderSource << "}\n";
-
-    GLuint program = CompileProgram(vshaderSource.str(), fragmentShaderSource);
-    EXPECT_EQ(0u, program);
+    CompileGLSLWithUniformsAndSamplers(maxUniforms + 1, 0, 0, 0, false);
 }
 
 // Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
 // can actually be used.
-TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsFragment)
+TEST_P(GLSLTest, VerifyMaxFragmentUniformVectors)
 {
-    const std::string &vertexShaderSource = SHADER_SOURCE
-    (
-        precision mediump float;
-        void main()
-        {
-            gl_Position = vec4(0.0);
-        }
-    );
-
     int maxUniforms = 10000;
     glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
     EXPECT_GL_NO_ERROR();
     std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS = " << maxUniforms << std::endl;
 
-    std::stringstream fshaderSource;
-    fshaderSource << "precision mediump float;\n";
+    CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, 0, true);
+}
 
-    for (int i = 0; i < maxUniforms; i++)
-    {
-        fshaderSource << "uniform vec4 v" << i << ";\n";
-    }
+// Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
+// can actually be used along with the maximum number of texture samplers.
+TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsWithSamplers)
+{
+    int maxUniforms = 10000;
+    glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
+    EXPECT_GL_NO_ERROR();
 
-    fshaderSource << "void main()\n{\n";
+    int maxTextureImageUnits = 0;
+    glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);
 
-    for (int i = 0; i < maxUniforms; i++)
-    {
-        fshaderSource << "    gl_FragColor +=  v" << i << ";\n";
-    }
-
-    fshaderSource << "}\n";
-
-    GLuint program = CompileProgram(vertexShaderSource, fshaderSource.str());
-    EXPECT_NE(0u, program);
+    CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, maxTextureImageUnits, true);
 }
 
 // Tests that the maximum uniforms count + 1 from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
 // fails shader compilation.
-TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsFragmentExceeded)
+TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsExceeded)
 {
-    const std::string &vertexShaderSource = SHADER_SOURCE
-    (
-        precision mediump float;
-        void main()
-        {
-            gl_Position = vec4(0.0);
-        }
-    );
-
     int maxUniforms = 10000;
     glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
     EXPECT_GL_NO_ERROR();
-    // Add 1 more to exceed the reported max count
-    maxUniforms += 1;
-    std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS + 1 = " << maxUniforms << std::endl;
+    std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS + 1 = " << maxUniforms + 1
+              << std::endl;
 
-    std::stringstream fshaderSource;
-    fshaderSource << "precision mediump float;\n";
-
-    for (int i = 0; i < maxUniforms; i++)
-    {
-        fshaderSource << "uniform vec4 v" << i << ";\n";
-    }
-
-    fshaderSource << "void main()\n{\n";
-
-    for (int i = 0; i < maxUniforms; i++)
-    {
-        fshaderSource << "    gl_FragColor +=  v" << i << ";\n";
-    }
-
-    fshaderSource << "}\n";
-
-    GLuint program = CompileProgram(vertexShaderSource, fshaderSource.str());
-    EXPECT_EQ(0u, program);
+    CompileGLSLWithUniformsAndSamplers(0, maxUniforms + 1, 0, 0, false);
 }
 
 // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.