Commit ae24f28a by Charlie Lao Committed by Commit Bot

Vulkan: Move mReadOnlyDepth out of FramebufferDesc

The depth read only or not should not affect VkFramebuffer creation. RenderPasses with just depthstencil layout differences are considered compatible. This CL moves this out of FramebufferDesc into FramebufferVk. Bug: b/168953278 Change-Id: I5bd05b262b7b3b0dc70f9fb8fc4a3db5e7082916 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2425032 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent d2d9e682
......@@ -294,6 +294,7 @@ FramebufferVk::FramebufferVk(RendererVk *renderer,
mBackbuffer(backbuffer),
mFramebuffer(nullptr),
mActiveColorComponents(0),
mReadOnlyDepthStencilMode(false),
mReadOnlyDepthFeedbackLoopMode(false)
{
mReadPixelBuffer.init(renderer, VK_BUFFER_USAGE_TRANSFER_DST_BIT, kReadPixelsBufferAlignment,
......@@ -1636,6 +1637,7 @@ angle::Result FramebufferVk::syncState(const gl::Context *context,
ContextVk *contextVk = vk::GetImpl(context);
vk::FramebufferDesc priorFramebufferDesc = mCurrentFramebufferDesc;
bool priorReadOnlyDepthStencilMode = mReadOnlyDepthStencilMode;
// Only defer clears for whole draw framebuffer ops. If the scissor test is on and the scissor
// rect doesn't match the draw rect, forget it.
......@@ -1730,17 +1732,18 @@ angle::Result FramebufferVk::syncState(const gl::Context *context,
// We cannot use read-only depth mode for clears.
if (mDeferredClears.any())
{
mCurrentFramebufferDesc.updateReadOnlyDepth(false);
mReadOnlyDepthStencilMode = false;
}
// No-op redundant changes to prevent closing the RenderPass.
if (mCurrentFramebufferDesc == priorFramebufferDesc)
if (mCurrentFramebufferDesc == priorFramebufferDesc &&
mReadOnlyDepthStencilMode == priorReadOnlyDepthStencilMode)
{
return angle::Result::Continue;
}
// Default to writable depth on any Framebuffer change.
mCurrentFramebufferDesc.updateReadOnlyDepth(false);
mReadOnlyDepthStencilMode = false;
// The FBO's new attachment may have changed the renderable area
const gl::State &glState = context->getState();
......@@ -1810,7 +1813,7 @@ void FramebufferVk::updateRenderPassDesc()
if (depthStencilRenderTarget)
{
vk::ResourceAccess dsAccess =
isReadOnlyDepthMode() ? vk::ResourceAccess::ReadOnly : vk::ResourceAccess::Write;
mReadOnlyDepthStencilMode ? vk::ResourceAccess::ReadOnly : vk::ResourceAccess::Write;
mRenderPassDesc.packDepthStencilAttachment(
depthStencilRenderTarget->getImageForRenderPass().getFormat().intendedFormatID,
......@@ -2410,8 +2413,9 @@ angle::Result FramebufferVk::startNewRenderPass(ContextVk *contextVk,
VK_ATTACHMENT_LOAD_OP_CLEAR;
setReadOnlyDepthMode(depthStencilReadOnly);
vk::ImageLayout dsLayout = isReadOnlyDepthMode() ? vk::ImageLayout::DepthStencilReadOnly
: vk::ImageLayout::DepthStencilAttachment;
vk::ImageLayout dsLayout = mReadOnlyDepthStencilMode
? vk::ImageLayout::DepthStencilReadOnly
: vk::ImageLayout::DepthStencilAttachment;
renderPassAttachmentOps.setLayouts(depthStencilAttachmentIndex, dsLayout, dsLayout);
}
......@@ -2451,7 +2455,7 @@ angle::Result FramebufferVk::startNewRenderPass(ContextVk *contextVk,
// tracking content valid very loosely here that as long as it is attached, it assumes will
// have valid content. The only time it has undefined content is between swap and
// startNewRenderPass
depthStencilRenderTarget->onDepthStencilDraw(contextVk, isReadOnlyDepthMode());
depthStencilRenderTarget->onDepthStencilDraw(contextVk, mReadOnlyDepthStencilMode);
}
if (unresolveMask.any())
......@@ -2590,10 +2594,9 @@ angle::Result FramebufferVk::flushDeferredClears(ContextVk *contextVk,
void FramebufferVk::setReadOnlyDepthMode(bool readOnlyDepthEnabled)
{
if (isReadOnlyDepthMode() != readOnlyDepthEnabled)
if (mReadOnlyDepthStencilMode != readOnlyDepthEnabled)
{
mCurrentFramebufferDesc.updateReadOnlyDepth(readOnlyDepthEnabled);
mFramebuffer = nullptr;
mReadOnlyDepthStencilMode = readOnlyDepthEnabled;
ASSERT(getDepthStencilRenderTarget());
vk::ResourceAccess dsAccess =
......@@ -2611,7 +2614,7 @@ angle::Result FramebufferVk::updateRenderPassReadOnlyDepthMode(ContextVk *contex
bool readOnlyDepthStencil =
!getDepthStencilRenderTarget()->hasResolveAttachment() &&
(mReadOnlyDepthFeedbackLoopMode || !renderPass->hasDepthStencilWriteOrClear());
if (readOnlyDepthStencil == isReadOnlyDepthMode())
if (readOnlyDepthStencil == mReadOnlyDepthStencilMode)
{
return angle::Result::Continue;
}
......
......@@ -130,7 +130,7 @@ class FramebufferVk : public FramebufferImpl
vk::Framebuffer **framebufferOut,
const vk::ImageView *resolveImageViewIn);
bool isReadOnlyDepthMode() const { return mCurrentFramebufferDesc.isReadOnlyDepth(); }
bool isReadOnlyDepthMode() const { return mReadOnlyDepthStencilMode; }
bool hasDeferredClears() const { return !mDeferredClears.empty(); }
angle::Result flushDeferredClears(ContextVk *contextVk, const gl::Rectangle &renderArea);
......@@ -257,6 +257,8 @@ class FramebufferVk : public FramebufferImpl
vk::ClearValuesArray mDeferredClears;
// True if depth stencil buffer is read only.
bool mReadOnlyDepthStencilMode;
// Tracks if we are in depth feedback loop. Depth read only feedback loop is a special kind of
// depth stencil read only mode. When we are in feedback loop, we must flush renderpass to exit
// the loop instead of update the layout.
......
......@@ -2464,11 +2464,6 @@ void FramebufferDesc::updateDepthStencilResolve(ImageViewSubresourceSerial seria
update(kFramebufferDescDepthStencilResolveIndexOffset, serial);
}
void FramebufferDesc::updateReadOnlyDepth(bool readOnlyDepth)
{
mReadOnlyDepth = readOnlyDepth;
}
size_t FramebufferDesc::hash() const
{
return angle::ComputeGenericHash(&mSerials, sizeof(mSerials[0]) * mMaxIndex) ^
......@@ -2477,15 +2472,15 @@ size_t FramebufferDesc::hash() const
void FramebufferDesc::reset()
{
mMaxIndex = 0;
mReadOnlyDepth = false;
mMaxIndex = 0;
mPadding = 0;
mColorUnresolveAttachmentMask.reset();
memset(&mSerials, 0, sizeof(mSerials));
}
bool FramebufferDesc::operator==(const FramebufferDesc &other) const
{
if (mMaxIndex != other.mMaxIndex || mReadOnlyDepth != other.mReadOnlyDepth ||
if (mMaxIndex != other.mMaxIndex ||
mColorUnresolveAttachmentMask != other.mColorUnresolveAttachmentMask)
{
return false;
......
......@@ -1047,6 +1047,9 @@ constexpr size_t kFramebufferDescDepthStencilResolveIndexOffset =
constexpr size_t kFramebufferDescColorResolveIndexOffset =
kFramebufferDescDepthStencilResolveIndexOffset + 1;
// Enable struct padding warnings for the code below since it is used in caches.
ANGLE_ENABLE_STRUCT_PADDING_WARNINGS
class FramebufferDesc
{
public:
......@@ -1061,14 +1064,12 @@ class FramebufferDesc
void updateColorUnresolveMask(gl::DrawBufferMask colorUnresolveMask);
void updateDepthStencil(ImageViewSubresourceSerial serial);
void updateDepthStencilResolve(ImageViewSubresourceSerial serial);
void updateReadOnlyDepth(bool readOnlyDepth);
size_t hash() const;
void reset();
bool operator==(const FramebufferDesc &other) const;
uint32_t attachmentCount() const;
bool isReadOnlyDepth() const { return mReadOnlyDepth != 0; }
ImageViewSubresourceSerial getColorImageViewSerial(uint32_t index)
{
......@@ -1081,7 +1082,7 @@ class FramebufferDesc
// Note: this is an exclusive index. If there is one index it will be "1".
uint16_t mMaxIndex;
uint8_t mReadOnlyDepth;
uint8_t mPadding;
// If the render pass contains an initial subpass to unresolve a number of attachments, the
// subpass description is derived from the following mask, specifying which attachments need
......@@ -1091,6 +1092,9 @@ class FramebufferDesc
FramebufferAttachmentArray<ImageViewSubresourceSerial> mSerials;
};
// Disable warnings about struct padding.
ANGLE_DISABLE_STRUCT_PADDING_WARNINGS
// The SamplerHelper allows a Sampler to be coupled with a serial.
// Must be included before we declare SamplerCache.
class SamplerHelper final : angle::NonCopyable
......
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