Commit 605f8631 by Chris Forbes

Refactor framebuffer clear to be less redundant

Bug: b/119621736 Change-Id: I8a25e6a5dba7e05649c35dc65160f69300bf5791 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/35508Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Presubmit-Ready: Chris Forbes <chrisforbes@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 2e5042a3
...@@ -41,47 +41,29 @@ void Framebuffer::clear(const RenderPass* renderPass, uint32_t clearValueCount, ...@@ -41,47 +41,29 @@ void Framebuffer::clear(const RenderPass* renderPass, uint32_t clearValueCount,
ASSERT(attachmentCount == renderPass->getAttachmentCount()); ASSERT(attachmentCount == renderPass->getAttachmentCount());
const uint32_t count = std::min(clearValueCount, attachmentCount); const uint32_t count = std::min(clearValueCount, attachmentCount);
for(uint32_t i = 0; i < count; i++) for (uint32_t i = 0; i < count; i++)
{ {
if (!renderPass->isAttachmentUsed(i))
{
continue;
}
const VkAttachmentDescription attachment = renderPass->getAttachment(i); const VkAttachmentDescription attachment = renderPass->getAttachment(i);
const Format format(attachment.format);
bool isDepth = format.isDepth();
bool isStencil = format.isStencil();
if(isDepth || isStencil) VkImageAspectFlags aspectMask = Format(attachment.format).getAspects();
{ if (attachment.loadOp != VK_ATTACHMENT_LOAD_OP_CLEAR)
bool clearDepth = (isDepth && (attachment.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)); aspectMask &= VK_IMAGE_ASPECT_STENCIL_BIT;
bool clearStencil = (isStencil && (attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)); if (attachment.stencilLoadOp != VK_ATTACHMENT_LOAD_OP_CLEAR)
aspectMask &= ~VK_IMAGE_ASPECT_STENCIL_BIT;
if(clearDepth || clearStencil) if (!aspectMask || !renderPass->isAttachmentUsed(i))
{
auto aspectMask = (clearDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) |
(clearStencil ? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
if (renderPass->isMultiView())
{
attachments[i]->clearWithLayerMask(pClearValues[i], aspectMask, renderArea, renderPass->getAttachmentViewMask(i));
}
else
{ {
attachments[i]->clear(pClearValues[i], aspectMask, renderArea); continue;
}
}
} }
else if(attachment.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
{
if (renderPass->isMultiView()) if (renderPass->isMultiView())
{ {
attachments[i]->clearWithLayerMask(pClearValues[i], VK_IMAGE_ASPECT_COLOR_BIT, renderArea, renderPass->getAttachmentViewMask(i)); attachments[i]->clearWithLayerMask(pClearValues[i], aspectMask, renderArea,
renderPass->getAttachmentViewMask(i));
} }
else else
{ {
attachments[i]->clear(pClearValues[i], VK_IMAGE_ASPECT_COLOR_BIT, renderArea); attachments[i]->clear(pClearValues[i], aspectMask, renderArea);
}
} }
} }
} }
......
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