Hash :
89e38b57
        
        Author :
  
        
        Date :
2022-06-22T15:04:08
        
      
Refactor to use ANGLETest vs ANGLETestWithParam Bug: angleproject:6747 Change-Id: I72ad52d0268eae0e1a401f12f3e94cc5efa402f2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3719002 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// BindUniformLocationTest.cpp : Tests of the GL_CHROMIUM_bind_uniform_location extension.
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include <cmath>
using namespace angle;
namespace
{
class BindUniformLocationTest : public ANGLETest<>
{
  protected:
    BindUniformLocationTest()
    {
        setWindowWidth(128);
        setWindowHeight(128);
        setConfigRedBits(8);
        setConfigGreenBits(8);
        setConfigBlueBits(8);
        setConfigAlphaBits(8);
    }
    void testTearDown() override
    {
        if (mProgram != 0)
        {
            glDeleteProgram(mProgram);
        }
    }
    GLuint mProgram = 0;
};
// Test basic functionality of GL_CHROMIUM_bind_uniform_location
TEST_P(BindUniformLocationTest, Basic)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    constexpr char kFS[] = R"(precision mediump float;
uniform vec4 u_colorC;
uniform vec4 u_colorB[2];
uniform vec4 u_colorA;
void main()
{
    gl_FragColor = u_colorA + u_colorB[0] + u_colorB[1] + u_colorC;
})";
    GLint colorALocation = 3;
    GLint colorBLocation = 10;
    GLint colorCLocation = 5;
    mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS, [&](GLuint program) {
        glBindUniformLocationCHROMIUM(program, colorALocation, "u_colorA");
        glBindUniformLocationCHROMIUM(program, colorBLocation, "u_colorB[0]");
        glBindUniformLocationCHROMIUM(program, colorCLocation, "u_colorC");
    });
    ASSERT_NE(0u, mProgram);
    glUseProgram(mProgram);
    static const float colorB[] = {
        0.0f, 0.50f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f, 0.0f,
    };
    glUniform4f(colorALocation, 0.25f, 0.0f, 0.0f, 0.0f);
    glUniform4fv(colorBLocation, 2, colorB);
    glUniform4f(colorCLocation, 0.0f, 0.0f, 0.0f, 1.0f);
    drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f);
    EXPECT_GL_NO_ERROR();
    EXPECT_PIXEL_NEAR(0, 0, 64, 128, 192, 255, 1.0);
}
// Force a sampler location and make sure it samples the correct texture
TEST_P(BindUniformLocationTest, SamplerLocation)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    constexpr char kFS[] = R"(precision mediump float;
uniform vec4 u_colorA;
uniform vec4 u_colorB[2];
uniform sampler2D u_sampler;
void main()
{
    gl_FragColor = u_colorA + u_colorB[0] + u_colorB[1] + texture2D(u_sampler, vec2(0, 0));
})";
    GLint colorALocation  = 3;
    GLint colorBLocation  = 10;
    GLint samplerLocation = 1;
    mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS, [&](GLuint program) {
        glBindUniformLocationCHROMIUM(program, colorALocation, "u_colorA");
        glBindUniformLocationCHROMIUM(program, colorBLocation, "u_colorB[0]");
        glBindUniformLocationCHROMIUM(program, samplerLocation, "u_sampler");
    });
    ASSERT_NE(0u, mProgram);
    glUseProgram(mProgram);
    static const float colorB[] = {
        0.0f, 0.50f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f, 0.0f,
    };
    glUniform4f(colorALocation, 0.25f, 0.0f, 0.0f, 0.0f);
    glUniform4fv(colorBLocation, 2, colorB);
    // Point the texture at texture unit 2
    glUniform1i(samplerLocation, 2);
    GLTexture texture;
    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, texture);
    constexpr GLubyte kTextureData[] = {32, 32, 32, 255};
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, kTextureData);
    drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f);
    EXPECT_GL_NO_ERROR();
    EXPECT_PIXEL_NEAR(0, 0, 96, 160, 224, 255, 1.0);
}
// Test that conflicts are detected when two uniforms are bound to the same location
TEST_P(BindUniformLocationTest, ConflictsDetection)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    constexpr char kFS[] =
        R"(precision mediump float;
        uniform vec4 u_colorA;
        uniform vec4 u_colorB;
        void main()
        {
            gl_FragColor = u_colorA + u_colorB;
        })";
    GLint colorALocation = 3;
    GLint colorBLocation = 4;
    GLuint vs = CompileShader(GL_VERTEX_SHADER, essl1_shaders::vs::Simple());
    GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS);
    mProgram = glCreateProgram();
    glAttachShader(mProgram, vs);
    glDeleteShader(vs);
    glAttachShader(mProgram, fs);
    glDeleteShader(fs);
    glBindUniformLocationCHROMIUM(mProgram, colorALocation, "u_colorA");
    // Bind u_colorB to location a, causing conflicts, link should fail.
    glBindUniformLocationCHROMIUM(mProgram, colorALocation, "u_colorB");
    glLinkProgram(mProgram);
    GLint linked = 0;
    glGetProgramiv(mProgram, GL_LINK_STATUS, &linked);
    ASSERT_EQ(0, linked);
    // Bind u_colorB to location b, no conflicts, link should succeed.
    glBindUniformLocationCHROMIUM(mProgram, colorBLocation, "u_colorB");
    glLinkProgram(mProgram);
    linked = 0;
    glGetProgramiv(mProgram, GL_LINK_STATUS, &linked);
    EXPECT_EQ(1, linked);
}
// Test a use case of the chromium compositor
TEST_P(BindUniformLocationTest, Compositor)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    constexpr char kVS[] =
        R"(attribute vec4 a_position;
        attribute vec2 a_texCoord;
        uniform mat4 matrix;
        uniform vec2 color_a[4];
        uniform vec4 color_b;
        varying vec4 v_color;
        void main()
        {
            v_color.xy = color_a[0] + color_a[1];
            v_color.zw = color_a[2] + color_a[3];
            v_color += color_b;
            gl_Position = matrix * a_position;
        })";
    constexpr char kFS[] =
        R"(precision mediump float;
        varying vec4 v_color;
        uniform float alpha;
        uniform vec4 multiplier;
        uniform vec3 color_c[8];
        void main()
        {
            vec4 color_c_sum = vec4(0.0);
            color_c_sum.xyz += color_c[0];
            color_c_sum.xyz += color_c[1];
            color_c_sum.xyz += color_c[2];
            color_c_sum.xyz += color_c[3];
            color_c_sum.xyz += color_c[4];
            color_c_sum.xyz += color_c[5];
            color_c_sum.xyz += color_c[6];
            color_c_sum.xyz += color_c[7];
            color_c_sum.w = alpha;
            color_c_sum *= multiplier;
            gl_FragColor = v_color + color_c_sum;
        })";
    int counter            = 6;
    int matrixLocation     = counter++;
    int colorALocation     = counter++;
    int colorBLocation     = counter++;
    int alphaLocation      = counter++;
    int multiplierLocation = counter++;
    int colorCLocation     = counter++;
    mProgram = CompileProgram(kVS, kFS, [&](GLuint program) {
        glBindUniformLocationCHROMIUM(program, matrixLocation, "matrix");
        glBindUniformLocationCHROMIUM(program, colorALocation, "color_a");
        glBindUniformLocationCHROMIUM(program, colorBLocation, "color_b");
        glBindUniformLocationCHROMIUM(program, alphaLocation, "alpha");
        glBindUniformLocationCHROMIUM(program, multiplierLocation, "multiplier");
        glBindUniformLocationCHROMIUM(program, colorCLocation, "color_c");
    });
    ASSERT_NE(0u, mProgram);
    glUseProgram(mProgram);
    static const float colorA[] = {
        0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f,
    };
    static const float colorC[] = {
        0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f,
        0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f,
    };
    static const float identity[] = {
        1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1,
    };
    glUniformMatrix4fv(matrixLocation, 1, false, identity);
    glUniform2fv(colorALocation, 4, colorA);
    glUniform4f(colorBLocation, 0.2f, 0.2f, 0.2f, 0.2f);
    glUniform1f(alphaLocation, 0.8f);
    glUniform4f(multiplierLocation, 0.5f, 0.5f, 0.5f, 0.5f);
    glUniform3fv(colorCLocation, 8, colorC);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    drawQuad(mProgram, "a_position", 0.5f);
    EXPECT_PIXEL_EQ(0, 0, 204, 204, 204, 204);
}
// Test that unused uniforms don't conflict when bound to the same location
TEST_P(BindUniformLocationTest, UnusedUniformUpdate)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    ASSERT_NE(nullptr, glBindUniformLocationCHROMIUM);
    constexpr char kFS[] = R"(precision mediump float;
uniform vec4 u_colorA;
uniform float u_colorU;
uniform vec4 u_colorC;
void main()
{
    gl_FragColor = u_colorA + u_colorC;
})";
    const GLint colorULocation      = 1;
    const GLint nonexistingLocation = 5;
    const GLint unboundLocation     = 6;
    mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS, [&](GLuint program) {
        glBindUniformLocationCHROMIUM(program, colorULocation, "u_colorU");
        // The non-existing uniform should behave like existing, but optimized away
        // uniform.
        glBindUniformLocationCHROMIUM(program, nonexistingLocation, "nonexisting");
        // Let A and C be assigned automatic locations.
    });
    ASSERT_NE(0u, mProgram);
    glUseProgram(mProgram);
    // No errors on bound locations, since caller does not know
    // if the driver optimizes them away or not.
    glUniform1f(colorULocation, 0.25f);
    EXPECT_GL_NO_ERROR();
    // No errors on bound locations of names that do not exist
    // in the shader. Otherwise it would be inconsistent wrt the
    // optimization case.
    glUniform1f(nonexistingLocation, 0.25f);
    EXPECT_GL_NO_ERROR();
    // The above are equal to updating -1.
    glUniform1f(-1, 0.25f);
    EXPECT_GL_NO_ERROR();
    // No errors when updating with other type either.
    // The type can not be known with the non-existing case.
    glUniform2f(colorULocation, 0.25f, 0.25f);
    EXPECT_GL_NO_ERROR();
    glUniform2f(nonexistingLocation, 0.25f, 0.25f);
    EXPECT_GL_NO_ERROR();
    glUniform2f(-1, 0.25f, 0.25f);
    EXPECT_GL_NO_ERROR();
    // Ensure that driver or ANGLE has optimized the variable
    // away and the test tests what it is supposed to.
    EXPECT_EQ(-1, glGetUniformLocation(mProgram, "u_colorU"));
    // The bound location gets marked as used and the driver
    // does not allocate other variables to that location.
    EXPECT_NE(colorULocation, glGetUniformLocation(mProgram, "u_colorA"));
    EXPECT_NE(colorULocation, glGetUniformLocation(mProgram, "u_colorC"));
    EXPECT_NE(nonexistingLocation, glGetUniformLocation(mProgram, "u_colorA"));
    EXPECT_NE(nonexistingLocation, glGetUniformLocation(mProgram, "u_colorC"));
    // Unintuitive: while specifying value works, getting the value does not.
    GLfloat getResult = 0.0f;
    glGetUniformfv(mProgram, colorULocation, &getResult);
    EXPECT_GL_ERROR(GL_INVALID_OPERATION);
    glGetUniformfv(mProgram, nonexistingLocation, &getResult);
    EXPECT_GL_ERROR(GL_INVALID_OPERATION);
    glGetUniformfv(mProgram, -1, &getResult);
    EXPECT_GL_ERROR(GL_INVALID_OPERATION);
    // Updating an unbound, non-existing location still causes
    // an error.
    glUniform1f(unboundLocation, 0.25f);
    EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// GL backend optimizes away a uniform in the vertex shader if it's only used to
// compute a varying that is never referenced in the fragment shader.
TEST_P(BindUniformLocationTest, UnusedUniformUpdateComplex)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    ASSERT_NE(nullptr, glBindUniformLocationCHROMIUM);
    constexpr char kVS[] = R"(precision highp float;
attribute vec4 a_position;
varying vec4 v_unused;
uniform vec4 u_unused;
void main()
{
    gl_Position = a_position;
    v_unused = u_unused;
}
)";
    constexpr char kFS[] = R"(precision mediump float;
varying vec4 v_unused;
void main()
{
    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
})";
    const GLint unusedLocation = 1;
    mProgram = CompileProgram(kVS, kFS, [&](GLuint program) {
        glBindUniformLocationCHROMIUM(program, unusedLocation, "u_unused");
    });
    ASSERT_NE(0u, mProgram);
    glUseProgram(mProgram);
    // No errors on bound locations of names that do not exist
    // in the shader. Otherwise it would be inconsistent wrt the
    // optimization case.
    glUniform4f(unusedLocation, 0.25f, 0.25f, 0.25f, 0.25f);
    EXPECT_GL_NO_ERROR();
}
// Test for a bug where using a sampler caused GL error if the mProgram had
// uniforms that were optimized away by the driver. This was only a problem with
// glBindUniformLocationCHROMIUM implementation. This could be reproed by
// binding the sampler to a location higher than the amount of active uniforms.
TEST_P(BindUniformLocationTest, UseSamplerWhenUnusedUniforms)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    constexpr char kFS[] =
        R"(uniform sampler2D tex;
        void main()
        {
            gl_FragColor = texture2D(tex, vec2(1));
        })";
    const GLuint texLocation = 54;
    mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS, [&](GLuint program) {
        glBindUniformLocationCHROMIUM(program, texLocation, "tex");
    });
    ASSERT_NE(0u, mProgram);
    glUseProgram(mProgram);
    glUniform1i(texLocation, 0);
    EXPECT_GL_NO_ERROR();
}
// Test for binding a statically used uniform to the same location as a non-statically used uniform.
// This is valid according to the extension spec.
TEST_P(BindUniformLocationTest, SameLocationForUsedAndUnusedUniform)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    constexpr char kFS[] =
        R"(precision mediump float;
        uniform vec4 a;
        uniform vec4 b;
        void main()
        {
            gl_FragColor = a;
        })";
    const GLuint location = 54;
    mProgram = CompileProgram(essl1_shaders::vs::Zero(), kFS, [&](GLuint program) {
        glBindUniformLocationCHROMIUM(program, location, "a");
        glBindUniformLocationCHROMIUM(program, location, "b");
    });
    ASSERT_NE(0u, mProgram);
    glUseProgram(mProgram);
    glUniform4f(location, 0.0, 1.0, 0.0, 1.0);
    EXPECT_GL_NO_ERROR();
}
class BindUniformLocationES31Test : public BindUniformLocationTest
{
  protected:
    BindUniformLocationES31Test() : BindUniformLocationTest() {}
    void linkProgramWithUniformLocation(const char *vs,
                                        const char *fs,
                                        const char *uniformName,
                                        GLint uniformLocation)
    {
        mProgram = CompileProgram(vs, fs, [&](GLuint program) {
            glBindUniformLocationCHROMIUM(program, uniformLocation, uniformName);
        });
    }
};
// Test for when the shader specifies an explicit uniform location with a layout qualifier and the
// bindUniformLocation API sets a consistent location.
TEST_P(BindUniformLocationES31Test, ConsistentWithLocationLayoutQualifier)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    constexpr char kFS[] =
        "#version 310 es\n"
        "uniform layout(location=2) highp sampler2D tex;\n"
        "out highp vec4 my_FragColor;\n"
        "void main()\n"
        "{\n"
        "    my_FragColor = texture(tex, vec2(1));\n"
        "}\n";
    const GLuint texLocation = 2;
    linkProgramWithUniformLocation(essl31_shaders::vs::Zero(), kFS, "tex", texLocation);
    GLint linked = GL_FALSE;
    glGetProgramiv(mProgram, GL_LINK_STATUS, &linked);
    ASSERT_GL_TRUE(linked);
    EXPECT_EQ(static_cast<GLint>(texLocation), glGetUniformLocation(mProgram, "tex"));
    glUseProgram(mProgram);
    glUniform1i(texLocation, 0);
    EXPECT_GL_NO_ERROR();
}
// Test for when the shader specifies an explicit uniform location with a layout qualifier and the
// bindUniformLocation API sets a conflicting location for the same variable. The shader-set
// location should prevail.
TEST_P(BindUniformLocationES31Test, LocationLayoutQualifierOverridesAPIBinding)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    constexpr char kFS[] =
        "#version 310 es\n"
        "uniform layout(location=2) highp sampler2D tex;\n"
        "out highp vec4 my_FragColor;\n"
        "void main()\n"
        "{\n"
        "    my_FragColor = texture(tex, vec2(1));\n"
        "}\n";
    const GLuint shaderTexLocation = 2;
    const GLuint texLocation       = 3;
    linkProgramWithUniformLocation(essl31_shaders::vs::Zero(), kFS, "tex", texLocation);
    GLint linked = GL_FALSE;
    glGetProgramiv(mProgram, GL_LINK_STATUS, &linked);
    ASSERT_GL_TRUE(linked);
    EXPECT_EQ(static_cast<GLint>(shaderTexLocation), glGetUniformLocation(mProgram, "tex"));
    glUseProgram(mProgram);
    glUniform1i(shaderTexLocation, 1);
    EXPECT_GL_NO_ERROR();
    glUniform1i(texLocation, 2);
    EXPECT_GL_NO_ERROR();
}
// Test for when the shader specifies an explicit uniform location with a layout qualifier and the
// bindUniformLocation API sets a conflicting location for a different variable. Linking should
// fail.
TEST_P(BindUniformLocationES31Test, LocationLayoutQualifierConflictsWithAPIBinding)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    constexpr char kFS[] =
        "#version 310 es\n"
        "uniform layout(location=2) highp sampler2D tex;\n"
        "uniform highp sampler2D tex2;\n"
        "out highp vec4 my_FragColor;\n"
        "void main()\n"
        "{\n"
        "    my_FragColor = texture(tex2, vec2(1));\n"
        "}\n";
    const GLuint tex2Location = 2;
    linkProgramWithUniformLocation(essl31_shaders::vs::Zero(), kFS, "tex2", tex2Location);
    GLint linked = GL_FALSE;
    glGetProgramiv(mProgram, GL_LINK_STATUS, &linked);
    ASSERT_GL_FALSE(linked);
}
// Test for binding a location for an array of arrays uniform.
TEST_P(BindUniformLocationES31Test, ArrayOfArrays)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_CHROMIUM_bind_uniform_location"));
    constexpr char kFS[] =
        R"(#version 310 es
        precision highp float;
        uniform vec4 sourceColor[2][1];
        out highp vec4 my_FragColor;
        void main()
        {
            my_FragColor = sourceColor[1][0];
        })";
    const GLuint location = 8;
    linkProgramWithUniformLocation(essl31_shaders::vs::Simple(), kFS, "sourceColor[1]", location);
    GLint linked = GL_FALSE;
    glGetProgramiv(mProgram, GL_LINK_STATUS, &linked);
    ASSERT_GL_TRUE(linked);
    glUseProgram(mProgram);
    glUniform4f(location, 0.0f, 1.0f, 0.0f, 1.0f);
    drawQuad(mProgram, essl31_shaders::PositionAttrib(), 0.5f);
    EXPECT_GL_NO_ERROR();
    EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against.
ANGLE_INSTANTIATE_TEST_ES2(BindUniformLocationTest);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BindUniformLocationES31Test);
ANGLE_INSTANTIATE_TEST_ES31(BindUniformLocationES31Test);
}  // namespace