Vulkan: Bugfix in depth/stencil clearing
In the situation when we try to clear the depth OR the stencil
buffer but we have a packed depth/stencil attachment, we were still
clearing both of them since Vulkan doesn't allow setting just the depth
or the stencil image aspect bit on the clear call. The workaround is to
use the vkCmdClearAttachments command that allows us to clear one or
the other easily.
Bug: angleproject:2443
Change-Id: I6814e1927c019d9ec9255d79c6bc7b913a8c99e9
Reviewed-on: https://chromium-review.googlesource.com/997752
Commit-Queue: Luc Ferron <lucferron@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/FramebufferVk.cpp b/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
index 96230f7..312d450 100644
--- a/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
+++ b/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
@@ -134,7 +134,14 @@
bool clearColor = IsMaskFlagSet(static_cast<int>(mask), GL_COLOR_BUFFER_BIT);
- if (context->getGLState().isScissorTestEnabled())
+ const gl::FramebufferAttachment *depthStencilAttachment = mState.getDepthStencilAttachment();
+
+ // If we clear the depth OR the stencil but not both, and we have a packed depth stencil
+ // attachment, we need to use clearAttachment instead of clearDepthStencil since Vulkan won't
+ // allow us to clear one or the other separately.
+ bool isSingleClearOnPackedDepthStencilAttachment =
+ depthStencilAttachment && (clearDepth != clearStencil);
+ if (context->getGLState().isScissorTestEnabled() || isSingleClearOnPackedDepthStencilAttachment)
{
// With scissor test enabled, we clear very differently and we don't need to access
// the image inside each attachment we can just use clearCmdAttachments with our
@@ -153,7 +160,7 @@
contextVk->getClearDepthStencilValue().depthStencil;
// We only support packed depth/stencil, not separate.
- ASSERT(!(clearDepth && clearStencil) || mState.getDepthStencilAttachment());
+ ASSERT(!(clearDepth && clearStencil) || depthStencilAttachment);
const VkImageAspectFlags aspectFlags =
(depthAttachment ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) |