Commit 2197dc52 by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Implement masked depth & stencil clear

This commit also adds tests for clearing depth and stencil with mask/scissor. Bug: angleproject:2540 Change-Id: I30dd840afd6cdd4e3a38c50fcba4c8623513ceb0 Reviewed-on: https://chromium-review.googlesource.com/c/1307585Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent 580baf37
...@@ -178,6 +178,9 @@ angle::Result FramebufferVk::clear(const gl::Context *context, GLbitfield mask) ...@@ -178,6 +178,9 @@ angle::Result FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
bool clearDepth = (depthAttachment && (mask & GL_DEPTH_BUFFER_BIT) != 0); bool clearDepth = (depthAttachment && (mask & GL_DEPTH_BUFFER_BIT) != 0);
ASSERT(!clearDepth || depthAttachment->isAttached()); ASSERT(!clearDepth || depthAttachment->isAttached());
// If depth write is disabled, pretend that GL_DEPTH_BUFFER_BIT is not specified altogether.
clearDepth = clearDepth && contextVk->getGLState().getDepthStencilState().depthMask;
const gl::FramebufferAttachment *stencilAttachment = mState.getStencilAttachment(); const gl::FramebufferAttachment *stencilAttachment = mState.getStencilAttachment();
bool clearStencil = (stencilAttachment && (mask & GL_STENCIL_BUFFER_BIT) != 0); bool clearStencil = (stencilAttachment && (mask & GL_STENCIL_BUFFER_BIT) != 0);
ASSERT(!clearStencil || stencilAttachment->isAttached()); ASSERT(!clearStencil || stencilAttachment->isAttached());
...@@ -203,8 +206,6 @@ angle::Result FramebufferVk::clear(const gl::Context *context, GLbitfield mask) ...@@ -203,8 +206,6 @@ angle::Result FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
if (clearDepth || clearStencil) if (clearDepth || clearStencil)
{ {
// Masked stencil clears are currently not implemented.
// TODO(jmadill): Masked stencil clear. http://anglebug.com/2540
ANGLE_TRY(clearWithClearAttachments(contextVk, false, clearDepth, clearStencil)); ANGLE_TRY(clearWithClearAttachments(contextVk, false, clearDepth, clearStencil));
} }
return angle::Result::Continue(); return angle::Result::Continue();
...@@ -222,9 +223,6 @@ angle::Result FramebufferVk::clear(const gl::Context *context, GLbitfield mask) ...@@ -222,9 +223,6 @@ angle::Result FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
// With scissor test enabled, we clear very differently and we don't need to access // 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 // the image inside each attachment we can just use clearCmdAttachments with our
// scissor region instead. // scissor region instead.
// Masked stencil clears are currently not implemented.
// TODO(jmadill): Masked stencil clear. http://anglebug.com/2540
ANGLE_TRY(clearWithClearAttachments(contextVk, clearColor, clearDepth, clearStencil)); ANGLE_TRY(clearWithClearAttachments(contextVk, clearColor, clearDepth, clearStencil));
return angle::Result::Continue(); return angle::Result::Continue();
} }
...@@ -234,9 +232,13 @@ angle::Result FramebufferVk::clear(const gl::Context *context, GLbitfield mask) ...@@ -234,9 +232,13 @@ angle::Result FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
{ {
ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer)); ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer));
const VkClearDepthStencilValue &clearDepthStencilValue = VkClearDepthStencilValue clearDepthStencilValue =
contextVk->getClearDepthStencilValue().depthStencil; contextVk->getClearDepthStencilValue().depthStencil;
// Apply the stencil mask to the clear value.
clearDepthStencilValue.stencil &=
contextVk->getGLState().getDepthStencilState().stencilWritemask;
RenderTargetVk *renderTarget = mRenderTargetCache.getDepthStencil(); RenderTargetVk *renderTarget = mRenderTargetCache.getDepthStencil();
const angle::Format &format = renderTarget->getImageFormat().textureFormat(); const angle::Format &format = renderTarget->getImageFormat().textureFormat();
const VkImageAspectFlags aspectFlags = vk::GetDepthStencilAspectFlags(format); const VkImageAspectFlags aspectFlags = vk::GetDepthStencilAspectFlags(format);
...@@ -936,6 +938,16 @@ angle::Result FramebufferVk::clearWithClearAttachments(ContextVk *contextVk, ...@@ -936,6 +938,16 @@ angle::Result FramebufferVk::clearWithClearAttachments(ContextVk *contextVk,
} }
} }
VkClearValue depthStencilClearValue = contextVk->getClearDepthStencilValue();
// Apply the stencil mask to the clear value. Stencil mask is generally respected through the
// respective pipeline state, but clear uses its own special function.
if (clearStencil)
{
depthStencilClearValue.depthStencil.stencil &=
contextVk->getGLState().getDepthStencilState().stencilWritemask;
}
if (clearDepth && clearStencil && mState.getDepthStencilAttachment() != nullptr) if (clearDepth && clearStencil && mState.getDepthStencilAttachment() != nullptr)
{ {
// When we have a packed depth/stencil attachment we can do 1 clear for both when it // When we have a packed depth/stencil attachment we can do 1 clear for both when it
...@@ -943,7 +955,7 @@ angle::Result FramebufferVk::clearWithClearAttachments(ContextVk *contextVk, ...@@ -943,7 +955,7 @@ angle::Result FramebufferVk::clearWithClearAttachments(ContextVk *contextVk,
VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex];
clearAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; clearAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED;
clearAttachment.clearValue = contextVk->getClearDepthStencilValue(); clearAttachment.clearValue = depthStencilClearValue;
++clearAttachmentIndex; ++clearAttachmentIndex;
} }
else else
...@@ -953,7 +965,7 @@ angle::Result FramebufferVk::clearWithClearAttachments(ContextVk *contextVk, ...@@ -953,7 +965,7 @@ angle::Result FramebufferVk::clearWithClearAttachments(ContextVk *contextVk,
VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex];
clearAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; clearAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED;
clearAttachment.clearValue = contextVk->getClearDepthStencilValue(); clearAttachment.clearValue = depthStencilClearValue;
++clearAttachmentIndex; ++clearAttachmentIndex;
} }
...@@ -962,7 +974,7 @@ angle::Result FramebufferVk::clearWithClearAttachments(ContextVk *contextVk, ...@@ -962,7 +974,7 @@ angle::Result FramebufferVk::clearWithClearAttachments(ContextVk *contextVk,
VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex];
clearAttachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; clearAttachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED;
clearAttachment.clearValue = contextVk->getClearDepthStencilValue(); clearAttachment.clearValue = depthStencilClearValue;
++clearAttachmentIndex; ++clearAttachmentIndex;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment