src/third_party/angle/src/tests/gl_tests/MultithreadingTest.cpp
// Test that multiple threads can draw and read back pixels correctly.
// Using eglSwapBuffers stresses race conditions around use of QueueSerials.
Test that multiple threads can draw and read back pixels correctly.
Using eglSwapBuffers stresses race conditions around use of QueueSerials.
Test that multiple threads can draw and read back pixels correctly . Using eglSwapBuffers stresses race conditions around use of QueueSerials .
TEST_P(MultithreadingTest, MultiContextDrawWithSwapBuffers)
{
    ANGLE_SKIP_TEST_IF(!platformSupportsMultithreading());
    ANGLE_SKIP_TEST_IF(IsAndroid() && IsOpenGLES());
    EGLWindow *window = getEGLWindow();
    EGLDisplay dpy    = window->getDisplay();
    auto testBody = [dpy](EGLSurface surface, size_t thread) {
        constexpr size_t kIterationsPerThread = 100;
        constexpr size_t kDrawsPerIteration   = 10;
        ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
        glUseProgram(program);
        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);
        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);
            }
            EXPECT_EGL_TRUE(eglSwapBuffers(dpy, surface));
            EXPECT_EGL_SUCCESS();
            EXPECT_PIXEL_COLOR_EQ(0, 0, color);
        }
    };
    runMultithreadedGLTest(testBody, 32);
}
TEST_P ( MultithreadingTest , MultiContextDrawWithSwapBuffers ) { ANGLE_SKIP_TEST_IF ( ! platformSupportsMultithreading ( ) ) ; ANGLE_SKIP_TEST_IF ( IsAndroid ( ) && IsOpenGLES ( ) ) ; EGLWindow * window = getEGLWindow ( ) ; EGLDisplay dpy = window -> getDisplay ( ) ; auto testBody = [ dpy ] ( EGLSurface surface , size_t thread ) { constexpr size_t kIterationsPerThread = 100 ; constexpr size_t kDrawsPerIteration = 10 ; ANGLE_GL_PROGRAM ( program , essl1_shaders :: vs :: Simple ( ) , essl1_shaders :: fs :: UniformColor ( ) ) ; glUseProgram ( program ) ; 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 ) ; 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 ) ; } EXPECT_EGL_TRUE ( eglSwapBuffers ( dpy , surface ) ) ; EXPECT_EGL_SUCCESS ( ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , 0 , color ) ; } } ; runMultithreadedGLTest ( testBody , 32 ) ; }
Test that multiple threads can draw and read back pixels correctly.
Test that multiple threads can draw and read back pixels correctly .
// http://anglebug.com/5099 // Base the clear color on the thread and iteration indexes so every clear color is // unique