src/third_party/angle/src/tests/gl_tests/VulkanPerformanceCounterTest.cpp
// Tests that depth/stencil texture clear/load works correctly.
Tests that depth/stencil texture clear/load works correctly.
Tests that depth / stencil texture clear / load works correctly .
TEST_P(VulkanPerformanceCounterTest, DepthStencilTextureClearAndLoad)
{
    const rx::vk::PerfCounters &counters = hackANGLE();
    uint32_t expectedDepthClearCount     = counters.depthClears + 1;
    uint32_t expectedDepthLoadCount      = counters.depthLoads + 3;
    uint32_t expectedStencilClearCount   = counters.stencilClears + 1;
    uint32_t expectedStencilLoadCount    = counters.stencilLoads + 3;
    GLFramebuffer FBO;
    glBindFramebuffer(GL_FRAMEBUFFER, FBO);
    constexpr GLsizei kSize = 6;
    GLTexture color;
    glBindTexture(GL_TEXTURE_2D, color);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
    GLTexture depth;
    glBindTexture(GL_TEXTURE_2D, depth);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, kSize, kSize, 0, GL_DEPTH_STENCIL,
                 GL_UNSIGNED_INT_24_8_OES, nullptr);
    GLFramebuffer fbo;
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depth, 0);
    ASSERT_GL_NO_ERROR();
    GLTexture copyTex;
    glBindTexture(GL_TEXTURE_2D, copyTex);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
    glViewport(0, 0, kSize, kSize);
    glClearDepthf(1);
    glClearStencil(0x55);
    glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glDepthMask(GL_FALSE);
    glEnable(GL_STENCIL_TEST);
    glStencilFunc(GL_EQUAL, 0x55, 0xFF);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    glStencilMask(0xFF);
    ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
    glUseProgram(drawColor);
    GLint colorUniformLocation =
        glGetUniformLocation(drawColor, angle::essl1_shaders::ColorUniform());
    ASSERT_NE(colorUniformLocation, -1);
    glUniform4f(colorUniformLocation, 1.0f, 0.0f, 0.0f, 1.0f);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.0f);
    ASSERT_GL_NO_ERROR();
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, kSize / 2, kSize / 2);
    ASSERT_GL_NO_ERROR();
    glUniform4f(colorUniformLocation, 0.0f, 1.0f, 0.0f, 1.0f);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.0f);
    ASSERT_GL_NO_ERROR();
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, kSize / 2, 0, 0, 0, kSize / 2, kSize / 2);
    ASSERT_GL_NO_ERROR();
    glUniform4f(colorUniformLocation, 0.0f, 0.0f, 1.0f, 1.0f);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.0f);
    ASSERT_GL_NO_ERROR();
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, kSize / 2, 0, 0, kSize / 2, kSize / 2);
    ASSERT_GL_NO_ERROR();
    glUniform4f(colorUniformLocation, 1.0f, 1.0f, 0.0f, 1.0f);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.0f);
    ASSERT_GL_NO_ERROR();
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, kSize / 2, kSize / 2, 0, 0, kSize / 2, kSize / 2);
    ASSERT_GL_NO_ERROR();
    EXPECT_EQ(counters.depthClears, expectedDepthClearCount);
    EXPECT_EQ(counters.depthLoads, expectedDepthLoadCount);
    EXPECT_EQ(counters.stencilClears, expectedStencilClearCount);
    EXPECT_EQ(counters.stencilLoads, expectedStencilLoadCount);
    GLFramebuffer verifyFBO;
    glBindFramebuffer(GL_FRAMEBUFFER, verifyFBO);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, copyTex, 0);
    EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
    EXPECT_PIXEL_COLOR_EQ(kSize / 2, 0, GLColor::green);
    EXPECT_PIXEL_COLOR_EQ(0, kSize / 2, GLColor::blue);
    EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize / 2, GLColor::yellow);
}
TEST_P ( VulkanPerformanceCounterTest , DepthStencilTextureClearAndLoad ) { const rx :: vk :: PerfCounters & counters = hackANGLE ( ) ; uint32_t expectedDepthClearCount = counters . depthClears + 1 ; uint32_t expectedDepthLoadCount = counters . depthLoads + 3 ; uint32_t expectedStencilClearCount = counters . stencilClears + 1 ; uint32_t expectedStencilLoadCount = counters . stencilLoads + 3 ; GLFramebuffer FBO ; glBindFramebuffer ( GL_FRAMEBUFFER , FBO ) ; constexpr GLsizei kSize = 6 ; GLTexture color ; glBindTexture ( GL_TEXTURE_2D , color ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , kSize , kSize , 0 , GL_RGBA , GL_UNSIGNED_BYTE , nullptr ) ; GLTexture depth ; glBindTexture ( GL_TEXTURE_2D , depth ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_DEPTH24_STENCIL8 , kSize , kSize , 0 , GL_DEPTH_STENCIL , GL_UNSIGNED_INT_24_8_OES , nullptr ) ; GLFramebuffer fbo ; glBindFramebuffer ( GL_FRAMEBUFFER , fbo ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , color , 0 ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_STENCIL_ATTACHMENT , GL_TEXTURE_2D , depth , 0 ) ; ASSERT_GL_NO_ERROR ( ) ; GLTexture copyTex ; glBindTexture ( GL_TEXTURE_2D , copyTex ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , kSize , kSize , 0 , GL_RGBA , GL_UNSIGNED_BYTE , nullptr ) ; glViewport ( 0 , 0 , kSize , kSize ) ; glClearDepthf ( 1 ) ; glClearStencil ( 0x55 ) ; glClear ( GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ) ; glEnable ( GL_DEPTH_TEST ) ; glDepthFunc ( GL_LESS ) ; glDepthMask ( GL_FALSE ) ; glEnable ( GL_STENCIL_TEST ) ; glStencilFunc ( GL_EQUAL , 0x55 , 0xFF ) ; glStencilOp ( GL_KEEP , GL_KEEP , GL_KEEP ) ; glStencilMask ( 0xFF ) ; ANGLE_GL_PROGRAM ( drawColor , essl1_shaders :: vs :: Simple ( ) , essl1_shaders :: fs :: UniformColor ( ) ) ; glUseProgram ( drawColor ) ; GLint colorUniformLocation = glGetUniformLocation ( drawColor , angle :: essl1_shaders :: ColorUniform ( ) ) ; ASSERT_NE ( colorUniformLocation , -1 ) ; glUniform4f ( colorUniformLocation , 1.0f , 0.0f , 0.0f , 1.0f ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , 0.0f ) ; ASSERT_GL_NO_ERROR ( ) ; glCopyTexSubImage2D ( GL_TEXTURE_2D , 0 , 0 , 0 , 0 , 0 , kSize / 2 , kSize / 2 ) ; ASSERT_GL_NO_ERROR ( ) ; glUniform4f ( colorUniformLocation , 0.0f , 1.0f , 0.0f , 1.0f ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , 0.0f ) ; ASSERT_GL_NO_ERROR ( ) ; glCopyTexSubImage2D ( GL_TEXTURE_2D , 0 , kSize / 2 , 0 , 0 , 0 , kSize / 2 , kSize / 2 ) ; ASSERT_GL_NO_ERROR ( ) ; glUniform4f ( colorUniformLocation , 0.0f , 0.0f , 1.0f , 1.0f ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , 0.0f ) ; ASSERT_GL_NO_ERROR ( ) ; glCopyTexSubImage2D ( GL_TEXTURE_2D , 0 , 0 , kSize / 2 , 0 , 0 , kSize / 2 , kSize / 2 ) ; ASSERT_GL_NO_ERROR ( ) ; glUniform4f ( colorUniformLocation , 1.0f , 1.0f , 0.0f , 1.0f ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , 0.0f ) ; ASSERT_GL_NO_ERROR ( ) ; glCopyTexSubImage2D ( GL_TEXTURE_2D , 0 , kSize / 2 , kSize / 2 , 0 , 0 , kSize / 2 , kSize / 2 ) ; ASSERT_GL_NO_ERROR ( ) ; EXPECT_EQ ( counters . depthClears , expectedDepthClearCount ) ; EXPECT_EQ ( counters . depthLoads , expectedDepthLoadCount ) ; EXPECT_EQ ( counters . stencilClears , expectedStencilClearCount ) ; EXPECT_EQ ( counters . stencilLoads , expectedStencilLoadCount ) ; GLFramebuffer verifyFBO ; glBindFramebuffer ( GL_FRAMEBUFFER , verifyFBO ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , copyTex , 0 ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , 0 , GLColor :: red ) ; EXPECT_PIXEL_COLOR_EQ ( kSize / 2 , 0 , GLColor :: green ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , kSize / 2 , GLColor :: blue ) ; EXPECT_PIXEL_COLOR_EQ ( kSize / 2 , kSize / 2 , GLColor :: yellow ) ; }
Tests that depth/stencil texture clear/load works correctly.
Tests that depth / stencil texture clear / load works correctly .
// Create framebuffer to draw into, with both color and depth attachments. // Set up texture for copy operation that breaks the render pass // Set viewport and clear depth/stencil // If depth is not cleared to 1, rendering would fail. // If stencil is not clear to 0x55, rendering would fail. // Set up program // Draw red // Break the render pass // Draw green // Break the render pass // Draw blue // Break the render pass // Draw yellow // Break the render pass // Verify the counters // Verify that copies were done correctly.