Skip to content

Commit b2944fc

Browse files
ShabbyXCommit Bot
authored andcommitted
Vulkan: Don't break the RP on masked/scissored clears
Bug: b/166809097 Change-Id: Iedd10a6528808e859c5693a2d30c98aca1a1159c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2390862 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Charlie Lao <cclao@google.com> Reviewed-by: Tim Van Patten <timvp@google.com>
1 parent d0d523f commit b2944fc

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/libANGLE/renderer/vulkan/FramebufferVk.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,6 +1999,10 @@ angle::Result FramebufferVk::clearWithDraw(ContextVk *contextVk,
19991999

20002000
// Scissored-only clears are handled in clearImmediatelyWithRenderPassOp.
20012001
ASSERT(clearColorBuffers.any() || clearStencil);
2002+
2003+
// Force start a new render pass for the depth clear to take effect.
2004+
// UtilsVk::clearFramebuffer may not start a new render pass if there's one already started.
2005+
ANGLE_TRY(flushDeferredClears(contextVk, clearArea));
20022006
}
20032007

20042008
UtilsVk::ClearFramebufferParameters params = {};

src/libANGLE/renderer/vulkan/UtilsVk.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,9 +1142,19 @@ angle::Result UtilsVk::clearFramebuffer(ContextVk *contextVk,
11421142
ANGLE_TRY(ensureImageClearResourcesInitialized(contextVk));
11431143

11441144
const gl::Rectangle &scissoredRenderArea = params.clearArea;
1145-
1145+
vk::Framebuffer *currentFramebuffer = nullptr;
11461146
vk::CommandBuffer *commandBuffer;
1147-
ANGLE_TRY(contextVk->startRenderPass(scissoredRenderArea, &commandBuffer));
1147+
1148+
// Start a new render pass if not already started
1149+
ANGLE_TRY(framebuffer->getFramebuffer(contextVk, &currentFramebuffer, nullptr));
1150+
if (contextVk->hasStartedRenderPassWithFramebuffer(currentFramebuffer))
1151+
{
1152+
commandBuffer = &contextVk->getStartedRenderPassCommands().getCommandBuffer();
1153+
}
1154+
else
1155+
{
1156+
ANGLE_TRY(contextVk->startRenderPass(scissoredRenderArea, &commandBuffer));
1157+
}
11481158

11491159
ImageClearShaderParams shaderParams;
11501160
shaderParams.clearValue = params.colorClearValue;

src/tests/gl_tests/VulkanPerformanceCounterTest.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,46 @@ TEST_P(VulkanPerformanceCounterTest, SwapShouldInvalidateDepthAfterClear)
499499
EXPECT_EQ(expectedDepthClears, actualDepthClears);
500500
}
501501

502+
// Tests that masked color clears don't break the RP.
503+
TEST_P(VulkanPerformanceCounterTest, MaskedClearDoesNotBreakRenderPass)
504+
{
505+
const rx::vk::PerfCounters &counters = hackANGLE();
506+
507+
GLTexture texture;
508+
glBindTexture(GL_TEXTURE_2D, texture);
509+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
510+
511+
GLFramebuffer framebuffer;
512+
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
513+
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
514+
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
515+
ASSERT_GL_NO_ERROR();
516+
517+
uint32_t expectedRenderPassCount = counters.renderPasses + 1;
518+
519+
// Mask color channels and clear the framebuffer multiple times.
520+
glClearColor(0.25f, 0.25f, 0.25f, 0.25f);
521+
glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
522+
glClear(GL_COLOR_BUFFER_BIT);
523+
524+
glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
525+
glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
526+
glClear(GL_COLOR_BUFFER_BIT);
527+
528+
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
529+
glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE);
530+
glClear(GL_COLOR_BUFFER_BIT);
531+
532+
glClearColor(0.75f, 0.75f, 0.75f, 0.75f);
533+
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
534+
glClear(GL_COLOR_BUFFER_BIT);
535+
536+
uint32_t actualRenderPassCount = counters.renderPasses;
537+
EXPECT_EQ(expectedRenderPassCount, actualRenderPassCount);
538+
539+
EXPECT_PIXEL_NEAR(0, 0, 63, 127, 255, 191, 1);
540+
}
541+
502542
ANGLE_INSTANTIATE_TEST(VulkanPerformanceCounterTest, ES3_VULKAN());
503543
ANGLE_INSTANTIATE_TEST(VulkanPerformanceCounterTest_ES31, ES31_VULKAN());
504544

0 commit comments

Comments
 (0)