src/third_party/angle/src/tests/gl_tests/UniformBufferTest.cpp
// Test two uniform blocks share the same uniform buffer. On D3D backend, a uniform
// block with a large array member will be translated to StructuredBuffer, and the
// other uniform block will be translated to cbuffer, this case verifies that update
// buffer data correctly.
Test two uniform blocks share the same uniform buffer. On D3D backend, a uniform
block with a large array member will be translated to StructuredBuffer, and the
other uniform block will be translated to cbuffer, this case verifies that update
buffer data correctly.
Test two uniform blocks share the same uniform buffer . On D3D backend a uniform block with a large array member will be translated to StructuredBuffer and the other uniform block will be translated to cbuffer this case verifies that update buffer data correctly .
TEST_P(UniformBlockWithOneLargeArrayMemberTest, SharedSameBufferWithOtherOne)
{
    ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX() && IsOpenGL());
    std::ostringstream stream;
    generateArraySizeAndDivisorsDeclaration(stream, false, true, false);
    const std::string &kFS =
        "#version 300 es\n"
        "precision highp float;\n" +
        stream.str() +
        "out vec4 my_FragColor;\n"
        "struct S { mat4 color;};\n"
        "layout(std140) uniform buffer { S s[arraySize]; };\n"
        "layout(std140) uniform buffer1 { vec4 factor; };\n"
        "void main()\n"
        "{\n"
        "    uvec2 coord = uvec2(floor(gl_FragCoord.xy));\n"
        "    uint index = coord.x +  coord.y * 128u;\n"
        "    uint index_x = index / divisor1;\n"
        "    uint index_y = (index % divisor1) / divisor2;\n"
        "    my_FragColor = s[index_x].color[index_y] + factor;\n"
        "}\n";
    GLint blockSize;
    ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS.c_str());
    GLint uniformBufferIndex = glGetUniformBlockIndex(program, "buffer");
    glGetActiveUniformBlockiv(program, uniformBufferIndex, GL_UNIFORM_BLOCK_DATA_SIZE, &blockSize);
    GLint uniformBufferIndex1 = glGetUniformBlockIndex(program, "buffer1");
    GLint alignment;
    glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &alignment);
    while (alignment >= 0 && alignment < 16)
    {
        alignment += alignment;
    }
    glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer);
    glBufferData(GL_UNIFORM_BUFFER, alignment + blockSize, nullptr, GL_STATIC_DRAW);
    const GLuint arraySize  = getArraySize();
    const GLuint floatCount = arraySize * kVectorPerMat * kFloatPerVector;
    std::vector<GLfloat> floatData(floatCount, 0.0f);
    std::vector<GLfloat> floatData1(4, 0.0f);
    setArrayValues(floatData, 0, arraySize, 16, 0, 4, 4, 0.0f, 0.0f, 0.5f, 0.5f);
    setArrayValues(floatData1, 0, 1, 4, 0, 1, 4, 1.0f, 0.0f, 0.5f, 0.5f);
    glBindBufferRange(GL_UNIFORM_BUFFER, 0, mUniformBuffer, 0, 4 * sizeof(float));
    glUniformBlockBinding(program, uniformBufferIndex1, 0);
    glBindBufferRange(GL_UNIFORM_BUFFER, 1, mUniformBuffer, alignment, floatCount * sizeof(float));
    glUniformBlockBinding(program, uniformBufferIndex, 1);
    glBufferSubData(GL_UNIFORM_BUFFER, alignment, floatCount * sizeof(GLfloat), floatData.data());
    glBufferSubData(GL_UNIFORM_BUFFER, 0, 4 * sizeof(GLfloat), floatData1.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::magenta, GLColor::magenta, GLColor::magenta, GLColor::magenta);
    setArrayValues(floatData, 0, arraySize, 16, 0, 4, 4, 0.0f, 0.5f, 0.0f, 0.5f);
    setArrayValues(floatData1, 0, 1, 4, 0, 1, 4, 0.0f, 0.5f, 0.0f, 0.5f);
    glBufferSubData(GL_UNIFORM_BUFFER, alignment, floatCount * sizeof(GLfloat), floatData.data());
    glBufferSubData(GL_UNIFORM_BUFFER, 0, 4 * sizeof(GLfloat), floatData1.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::green, GLColor::green, GLColor::green, GLColor::green);
}
TEST_P ( UniformBlockWithOneLargeArrayMemberTest , SharedSameBufferWithOtherOne ) { ANGLE_SKIP_TEST_IF ( IsIntel ( ) && IsOSX ( ) && IsOpenGL ( ) ) ; std :: ostringstream stream ; generateArraySizeAndDivisorsDeclaration ( stream , false , true , false ) ; const std :: string & kFS = " \n " " \n " + stream . str ( ) + " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " ; GLint blockSize ; ANGLE_GL_PROGRAM ( program , essl3_shaders :: vs :: Simple ( ) , kFS . c_str ( ) ) ; GLint uniformBufferIndex = glGetUniformBlockIndex ( program , " " ) ; glGetActiveUniformBlockiv ( program , uniformBufferIndex , GL_UNIFORM_BLOCK_DATA_SIZE , & blockSize ) ; GLint uniformBufferIndex1 = glGetUniformBlockIndex ( program , " " ) ; GLint alignment ; glGetIntegerv ( GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT , & alignment ) ; while ( alignment >= 0 && alignment < 16 ) { alignment += alignment ; } glBindBuffer ( GL_UNIFORM_BUFFER , mUniformBuffer ) ; glBufferData ( GL_UNIFORM_BUFFER , alignment + blockSize , nullptr , GL_STATIC_DRAW ) ; const GLuint arraySize = getArraySize ( ) ; const GLuint floatCount = arraySize * kVectorPerMat * kFloatPerVector ; std :: vector < GLfloat > floatData ( floatCount , 0.0f ) ; std :: vector < GLfloat > floatData1 ( 4 , 0.0f ) ; setArrayValues ( floatData , 0 , arraySize , 16 , 0 , 4 , 4 , 0.0f , 0.0f , 0.5f , 0.5f ) ; setArrayValues ( floatData1 , 0 , 1 , 4 , 0 , 1 , 4 , 1.0f , 0.0f , 0.5f , 0.5f ) ; glBindBufferRange ( GL_UNIFORM_BUFFER , 0 , mUniformBuffer , 0 , 4 * sizeof ( float ) ) ; glUniformBlockBinding ( program , uniformBufferIndex1 , 0 ) ; glBindBufferRange ( GL_UNIFORM_BUFFER , 1 , mUniformBuffer , alignment , floatCount * sizeof ( float ) ) ; glUniformBlockBinding ( program , uniformBufferIndex , 1 ) ; glBufferSubData ( GL_UNIFORM_BUFFER , alignment , floatCount * sizeof ( GLfloat ) , floatData . data ( ) ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , 4 * sizeof ( GLfloat ) , floatData1 . data ( ) ) ; drawQuad ( program . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; checkResults ( GLColor :: magenta , GLColor :: magenta , GLColor :: magenta , GLColor :: magenta ) ; setArrayValues ( floatData , 0 , arraySize , 16 , 0 , 4 , 4 , 0.0f , 0.5f , 0.0f , 0.5f ) ; setArrayValues ( floatData1 , 0 , 1 , 4 , 0 , 1 , 4 , 0.0f , 0.5f , 0.0f , 0.5f ) ; glBufferSubData ( GL_UNIFORM_BUFFER , alignment , floatCount * sizeof ( GLfloat ) , floatData . data ( ) ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , 4 * sizeof ( GLfloat ) , floatData1 . data ( ) ) ; drawQuad ( program . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; checkResults ( GLColor :: green , GLColor :: green , GLColor :: green , GLColor :: green ) ; }
Test two uniform blocks share the same uniform buffer.
Test two uniform blocks share the same uniform buffer .