src/third_party/angle/src/tests/gl_tests/VulkanMultithreadingTest.cpp
// Test that multiple threads can draw and readback pixels successfully at the same time with small
// descriptor pools.
Test that multiple threads can draw and readback pixels successfully at the same time with small
descriptor pools.
Test that multiple threads can draw and readback pixels successfully at the same time with small descriptor pools .
TEST_P(VulkanMultithreadingTest, MultiContextDrawSmallDescriptorPools)
{
    ANGLE_SKIP_TEST_IF(!platformSupportsMultithreading());
    ASSERT_TRUE(IsGLExtensionEnabled(kExtensionName));
    limitMaxSets();
    auto testBody = [](EGLSurface surface, size_t thread) {
        constexpr size_t kIterationsPerThread = 16;
        constexpr size_t kDrawsPerIteration   = 16;
        ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
        glUseProgram(program);
        GLTexture copyTexture;
        glBindTexture(GL_TEXTURE_2D, copyTexture);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                     nullptr);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        ASSERT_GL_NO_ERROR();
        GLint colorLocation = glGetUniformLocation(program, essl1_shaders::ColorUniform());
        auto quadVertices = GetQuadVertices();
        GLBuffer vertexBuffer;
        glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
        glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 6, quadVertices.data(), GL_STATIC_DRAW);
        GLint positionLocation = glGetAttribLocation(program, essl1_shaders::PositionAttrib());
        glEnableVertexAttribArray(positionLocation);
        glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        std::vector<GLColor> actualData(kSize * kSize);
        for (size_t iteration = 0; iteration < kIterationsPerThread; iteration++)
        {
            const GLColor color(static_cast<GLubyte>(thread % 255),
                                static_cast<GLubyte>(iteration % 255), 0, 255);
            const angle::Vector4 floatColor = color.toNormalizedVector();
            glUniform4fv(colorLocation, 1, floatColor.data());
            for (size_t draw = 0; draw < kDrawsPerIteration; draw++)
            {
                glDrawArrays(GL_TRIANGLES, 0, 6);
                ASSERT_GL_NO_ERROR();
                glBindTexture(GL_TEXTURE_2D, copyTexture);
                glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, kSize, kSize, 0);
                ASSERT_GL_NO_ERROR();
            }
            if (IsGLExtensionEnabled(kExtensionName) && !(IsLinux() || IsWindows()))
            {
                glGetTexImageANGLE(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, actualData.data());
                EXPECT_GL_NO_ERROR();
                EXPECT_EQ(color, actualData[0]);
            }
        }
    };
    runMultithreadedGLTest(testBody, 4);
}
TEST_P ( VulkanMultithreadingTest , MultiContextDrawSmallDescriptorPools ) { ANGLE_SKIP_TEST_IF ( ! platformSupportsMultithreading ( ) ) ; ASSERT_TRUE ( IsGLExtensionEnabled ( kExtensionName ) ) ; limitMaxSets ( ) ; auto testBody = [ ] ( EGLSurface surface , size_t thread ) { constexpr size_t kIterationsPerThread = 16 ; constexpr size_t kDrawsPerIteration = 16 ; ANGLE_GL_PROGRAM ( program , essl1_shaders :: vs :: Simple ( ) , essl1_shaders :: fs :: UniformColor ( ) ) ; glUseProgram ( program ) ; GLTexture copyTexture ; glBindTexture ( GL_TEXTURE_2D , copyTexture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , kSize , kSize , 0 , GL_RGBA , GL_UNSIGNED_BYTE , nullptr ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ) ; ASSERT_GL_NO_ERROR ( ) ; GLint colorLocation = glGetUniformLocation ( program , essl1_shaders :: ColorUniform ( ) ) ; auto quadVertices = GetQuadVertices ( ) ; GLBuffer vertexBuffer ; glBindBuffer ( GL_ARRAY_BUFFER , vertexBuffer ) ; glBufferData ( GL_ARRAY_BUFFER , sizeof ( GLfloat ) * 3 * 6 , quadVertices . data ( ) , GL_STATIC_DRAW ) ; GLint positionLocation = glGetAttribLocation ( program , essl1_shaders :: PositionAttrib ( ) ) ; glEnableVertexAttribArray ( positionLocation ) ; glVertexAttribPointer ( positionLocation , 3 , GL_FLOAT , GL_FALSE , 0 , 0 ) ; glPixelStorei ( GL_PACK_ALIGNMENT , 1 ) ; std :: vector < GLColor > actualData ( kSize * kSize ) ; for ( size_t iteration = 0 ; iteration < kIterationsPerThread ; iteration ++ ) { const GLColor color ( static_cast < GLubyte > ( thread % 255 ) , static_cast < GLubyte > ( iteration % 255 ) , 0 , 255 ) ; const angle :: Vector4 floatColor = color . toNormalizedVector ( ) ; glUniform4fv ( colorLocation , 1 , floatColor . data ( ) ) ; for ( size_t draw = 0 ; draw < kDrawsPerIteration ; draw ++ ) { glDrawArrays ( GL_TRIANGLES , 0 , 6 ) ; ASSERT_GL_NO_ERROR ( ) ; glBindTexture ( GL_TEXTURE_2D , copyTexture ) ; glCopyTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , 0 , 0 , kSize , kSize , 0 ) ; ASSERT_GL_NO_ERROR ( ) ; } if ( IsGLExtensionEnabled ( kExtensionName ) && ! ( IsLinux ( ) || IsWindows ( ) ) ) { glGetTexImageANGLE ( GL_TEXTURE_2D , 0 , GL_RGBA , GL_UNSIGNED_BYTE , actualData . data ( ) ) ; EXPECT_GL_NO_ERROR ( ) ; EXPECT_EQ ( color , actualData [ 0 ] ) ; } } } ; runMultithreadedGLTest ( testBody , 4 ) ; }
Test that multiple threads can draw and readback pixels successfully at the same time with small
descriptor pools.
Test that multiple threads can draw and readback pixels successfully at the same time with small descriptor pools .
// Verify the extension is enabled. // Must be before program creation to limit the descriptor pool sizes when creating the pipeline // layout. // Pack pixels tightly. // Base the clear color on the thread and iteration indexes so every clear color is // unique // Perform CopyTexImage2D // There's a good chance this test will crash before failing, but if not we'll try and // verify the contents of the copied texture. // TODO(http://anglebug.com/5204): Need to re-enable for Linux/Windows. // Verify glCopyTexImage2D() was successful.