src/third_party/angle/src/tests/gl_tests/VulkanPerformanceCounterTest.cpp
// Ensures a read-only depth-stencil feedback loop works in a single RenderPass.
Ensures a read-only depth-stencil feedback loop works in a single RenderPass.
Ensures a read - only depth - stencil feedback loop works in a single RenderPass .
TEST_P(VulkanPerformanceCounterTest, ReadOnlyDepthStencilFeedbackLoopUsesSingleRenderPass)
{
    const rx::vk::PerfCounters &counters = hackANGLE();
    constexpr GLsizei kSize = 4;
    ANGLE_GL_PROGRAM(redProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
    ANGLE_GL_PROGRAM(texProgram, essl1_shaders::vs::Texture2D(), essl1_shaders::fs::Texture2D());
    GLTexture colorTexture;
    glBindTexture(GL_TEXTURE_2D, colorTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
    setupQuadVertexBuffer(0.5f, 1.0f);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(0);
    GLTexture depthTexture;
    glBindTexture(GL_TEXTURE_2D, depthTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, kSize, kSize, 0, GL_DEPTH_COMPONENT,
                 GL_UNSIGNED_INT, nullptr);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glBindTexture(GL_TEXTURE_2D, 0);
    GLFramebuffer depthAndColorFBO;
    glBindFramebuffer(GL_FRAMEBUFFER, depthAndColorFBO);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
    ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
    GLFramebuffer depthOnlyFBO;
    glBindFramebuffer(GL_FRAMEBUFFER, depthOnlyFBO);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
    ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
    glBindFramebuffer(GL_FRAMEBUFFER, depthOnlyFBO);
    glEnable(GL_DEPTH_TEST);
    glUseProgram(redProgram);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    ASSERT_GL_NO_ERROR();
    uint32_t expectedRenderPassCount = counters.renderPasses + 1;
    glBindFramebuffer(GL_FRAMEBUFFER, depthAndColorFBO);
    glDepthMask(false);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    ASSERT_GL_NO_ERROR();
    glBindTexture(GL_TEXTURE_2D, depthTexture);
    glUseProgram(texProgram);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    ASSERT_GL_NO_ERROR();
    glEnable(GL_DEPTH_TEST);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    ASSERT_GL_NO_ERROR();
    glUseProgram(redProgram);
    glBindTexture(GL_TEXTURE_2D, 0);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    ASSERT_GL_NO_ERROR();
    glUseProgram(texProgram);
    glDepthMask(GL_FALSE);
    glEnable(GL_DEPTH_TEST);
    glBindTexture(GL_TEXTURE_2D, depthTexture);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    ASSERT_GL_NO_ERROR();
    uint32_t actualRenderPassCount = counters.renderPasses;
    EXPECT_EQ(expectedRenderPassCount, actualRenderPassCount);
    glBindTexture(GL_TEXTURE_2D, 0);
    glDepthMask(GL_TRUE);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    ASSERT_GL_NO_ERROR();
}
TEST_P ( VulkanPerformanceCounterTest , ReadOnlyDepthStencilFeedbackLoopUsesSingleRenderPass ) { const rx :: vk :: PerfCounters & counters = hackANGLE ( ) ; constexpr GLsizei kSize = 4 ; ANGLE_GL_PROGRAM ( redProgram , essl1_shaders :: vs :: Simple ( ) , essl1_shaders :: fs :: Red ( ) ) ; ANGLE_GL_PROGRAM ( texProgram , essl1_shaders :: vs :: Texture2D ( ) , essl1_shaders :: fs :: Texture2D ( ) ) ; GLTexture colorTexture ; glBindTexture ( GL_TEXTURE_2D , colorTexture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , kSize , kSize , 0 , GL_RGBA , GL_UNSIGNED_BYTE , nullptr ) ; setupQuadVertexBuffer ( 0.5f , 1.0f ) ; glVertexAttribPointer ( 0 , 3 , GL_FLOAT , GL_FALSE , 0 , 0 ) ; glEnableVertexAttribArray ( 0 ) ; GLTexture depthTexture ; glBindTexture ( GL_TEXTURE_2D , depthTexture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_DEPTH_COMPONENT16 , kSize , kSize , 0 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT , nullptr ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; GLFramebuffer depthAndColorFBO ; glBindFramebuffer ( GL_FRAMEBUFFER , depthAndColorFBO ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , colorTexture , 0 ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , depthTexture , 0 ) ; ASSERT_GL_FRAMEBUFFER_COMPLETE ( GL_FRAMEBUFFER ) ; GLFramebuffer depthOnlyFBO ; glBindFramebuffer ( GL_FRAMEBUFFER , depthOnlyFBO ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , depthTexture , 0 ) ; ASSERT_GL_FRAMEBUFFER_COMPLETE ( GL_FRAMEBUFFER ) ; glBindFramebuffer ( GL_FRAMEBUFFER , depthOnlyFBO ) ; glEnable ( GL_DEPTH_TEST ) ; glUseProgram ( redProgram ) ; glDrawArrays ( GL_TRIANGLES , 0 , 6 ) ; ASSERT_GL_NO_ERROR ( ) ; uint32_t expectedRenderPassCount = counters . renderPasses + 1 ; glBindFramebuffer ( GL_FRAMEBUFFER , depthAndColorFBO ) ; glDepthMask ( false ) ; glDrawArrays ( GL_TRIANGLES , 0 , 6 ) ; ASSERT_GL_NO_ERROR ( ) ; glBindTexture ( GL_TEXTURE_2D , depthTexture ) ; glUseProgram ( texProgram ) ; glDrawArrays ( GL_TRIANGLES , 0 , 6 ) ; ASSERT_GL_NO_ERROR ( ) ; glEnable ( GL_DEPTH_TEST ) ; glDrawArrays ( GL_TRIANGLES , 0 , 6 ) ; ASSERT_GL_NO_ERROR ( ) ; glUseProgram ( redProgram ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glDrawArrays ( GL_TRIANGLES , 0 , 6 ) ; ASSERT_GL_NO_ERROR ( ) ; glUseProgram ( texProgram ) ; glDepthMask ( GL_FALSE ) ; glEnable ( GL_DEPTH_TEST ) ; glBindTexture ( GL_TEXTURE_2D , depthTexture ) ; glDrawArrays ( GL_TRIANGLES , 0 , 6 ) ; ASSERT_GL_NO_ERROR ( ) ; uint32_t actualRenderPassCount = counters . renderPasses ; EXPECT_EQ ( expectedRenderPassCount , actualRenderPassCount ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glDepthMask ( GL_TRUE ) ; glDrawArrays ( GL_TRIANGLES , 0 , 6 ) ; ASSERT_GL_NO_ERROR ( ) ; }
Ensures a read-only depth-stencil feedback loop works in a single RenderPass.
Ensures a read - only depth - stencil feedback loop works in a single RenderPass .
// Set up a depth texture and fill it with an arbitrary initial value. // Draw to a first FBO to initialize the depth buffer. // Start new RenderPass with depth write disabled and no loop. // Now set up the read-only feedback loop. // Tweak the bits to keep it read-only. // Render with just the depth attachment. // Rebind the depth texture. // Do a final write to depth to make sure we can switch out of read-only mode.