src/third_party/angle/src/tests/gl_tests/VulkanPerformanceCounterTest.cpp
// Tests counters when multisampled-render-to-texture color/depth/stencil renderbuffers are
// invalidated.
Tests counters when multisampled-render-to-texture color/depth/stencil renderbuffers are
invalidated.
Tests counters when multisampled - render - to - texture color / depth / stencil renderbuffers are invalidated .
TEST_P(VulkanPerformanceCounterTest, RenderToTextureInvalidate)
{
    ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsVulkan());
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_multisampled_render_to_texture"));
    const rx::vk::PerfCounters &counters = hackANGLE();
    rx::vk::PerfCounters expected;
    setExpectedCountersForInvalidateTest(counters, 4, 1, 0, 0, 1, 0, 0, &expected);
    setExpectedCountersForUnresolveResolveTest(counters, 0, 0, 0, 0, 0, 0, &expected);
    GLFramebuffer FBO;
    glBindFramebuffer(GL_FRAMEBUFFER, FBO);
    constexpr GLsizei kSize = 6;
    GLTexture colorMS;
    glBindTexture(GL_TEXTURE_2D, colorMS);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
    GLRenderbuffer depthStencilMS;
    glBindRenderbuffer(GL_RENDERBUFFER, depthStencilMS);
    glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, kSize, kSize);
    GLFramebuffer fboMS;
    glBindFramebuffer(GL_FRAMEBUFFER, fboMS);
    glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
                                         colorMS, 0, 4);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
                              depthStencilMS);
    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);
    glClearColor(0, 0, 0, 1.0f);
    glClearDepthf(1);
    glClearStencil(0x55);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_ALWAYS);
    glEnable(GL_STENCIL_TEST);
    glStencilFunc(GL_ALWAYS, 0x55, 0xFF);
    glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
    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.75f);
    ASSERT_GL_NO_ERROR();
    const GLenum discards[] = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
    glInvalidateFramebuffer(GL_FRAMEBUFFER, 3, discards);
    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.5f);
    ASSERT_GL_NO_ERROR();
    glInvalidateFramebuffer(GL_FRAMEBUFFER, 3, discards);
    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.25f);
    ASSERT_GL_NO_ERROR();
    glInvalidateFramebuffer(GL_FRAMEBUFFER, 3, discards);
    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();
    glInvalidateFramebuffer(GL_FRAMEBUFFER, 3, discards);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, kSize / 2, kSize / 2, 0, 0, kSize / 2, kSize / 2);
    ASSERT_GL_NO_ERROR();
    compareLoadCountersForInvalidateTest(counters, expected);
    compareCountersForUnresolveResolveTest(counters, expected);
}
TEST_P ( VulkanPerformanceCounterTest , RenderToTextureInvalidate ) { ANGLE_SKIP_TEST_IF ( IsWindows ( ) && IsAMD ( ) && IsVulkan ( ) ) ; ANGLE_SKIP_TEST_IF ( ! EnsureGLExtensionEnabled ( " " ) ) ; const rx :: vk :: PerfCounters & counters = hackANGLE ( ) ; rx :: vk :: PerfCounters expected ; setExpectedCountersForInvalidateTest ( counters , 4 , 1 , 0 , 0 , 1 , 0 , 0 , & expected ) ; setExpectedCountersForUnresolveResolveTest ( counters , 0 , 0 , 0 , 0 , 0 , 0 , & expected ) ; GLFramebuffer FBO ; glBindFramebuffer ( GL_FRAMEBUFFER , FBO ) ; constexpr GLsizei kSize = 6 ; GLTexture colorMS ; glBindTexture ( GL_TEXTURE_2D , colorMS ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , kSize , kSize , 0 , GL_RGBA , GL_UNSIGNED_BYTE , nullptr ) ; GLRenderbuffer depthStencilMS ; glBindRenderbuffer ( GL_RENDERBUFFER , depthStencilMS ) ; glRenderbufferStorageMultisampleEXT ( GL_RENDERBUFFER , 4 , GL_DEPTH24_STENCIL8 , kSize , kSize ) ; GLFramebuffer fboMS ; glBindFramebuffer ( GL_FRAMEBUFFER , fboMS ) ; glFramebufferTexture2DMultisampleEXT ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , colorMS , 0 , 4 ) ; glFramebufferRenderbuffer ( GL_FRAMEBUFFER , GL_DEPTH_STENCIL_ATTACHMENT , GL_RENDERBUFFER , depthStencilMS ) ; 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 ) ; glClearColor ( 0 , 0 , 0 , 1.0f ) ; glClearDepthf ( 1 ) ; glClearStencil ( 0x55 ) ; glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ) ; glEnable ( GL_DEPTH_TEST ) ; glDepthFunc ( GL_ALWAYS ) ; glEnable ( GL_STENCIL_TEST ) ; glStencilFunc ( GL_ALWAYS , 0x55 , 0xFF ) ; glStencilOp ( GL_REPLACE , GL_REPLACE , GL_REPLACE ) ; 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.75f ) ; ASSERT_GL_NO_ERROR ( ) ; const GLenum discards [ ] = { GL_COLOR_ATTACHMENT0 , GL_DEPTH_ATTACHMENT , GL_STENCIL_ATTACHMENT } ; glInvalidateFramebuffer ( GL_FRAMEBUFFER , 3 , discards ) ; 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.5f ) ; ASSERT_GL_NO_ERROR ( ) ; glInvalidateFramebuffer ( GL_FRAMEBUFFER , 3 , discards ) ; 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.25f ) ; ASSERT_GL_NO_ERROR ( ) ; glInvalidateFramebuffer ( GL_FRAMEBUFFER , 3 , discards ) ; 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 ( ) ; glInvalidateFramebuffer ( GL_FRAMEBUFFER , 3 , discards ) ; glCopyTexSubImage2D ( GL_TEXTURE_2D , 0 , kSize / 2 , kSize / 2 , 0 , 0 , kSize / 2 , kSize / 2 ) ; ASSERT_GL_NO_ERROR ( ) ; compareLoadCountersForInvalidateTest ( counters , expected ) ; compareCountersForUnresolveResolveTest ( counters , expected ) ; }
Tests counters when multisampled-render-to-texture color/depth/stencil renderbuffers are
invalidated.
Tests counters when multisampled - render - to - texture color / depth / stencil renderbuffers are invalidated .
// http://anglebug.com/5083 // This test creates 4 render passes. In the first render pass, color, depth and stencil are // cleared.  After every render pass, the attachments are invalidated.  In the following render // passes thus they are not loaded (rather unresolved, as the attachments are // multisampled-render-to-texture).  Due to the invalidate call, neither of the 4 render passes // should resolve the attachments. // Expect rpCount+4, depth(Clears+1, Loads+0, Stores+0), stencil(Clears+1, Load+0, Stores+0) // Additionally, expect no resolve and unresolve. // Create multisampled 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 color, depth and stencil // Output depth/stencil, but disable testing so all draw calls succeed // Set up program // Draw red // Invalidate everything // Break the render pass // Draw green // Invalidate everything // Break the render pass // Draw blue // Invalidate everything // Break the render pass // Draw yellow // Invalidate everything // Break the render pass // Verify the counters