Commit d286daf1 by Jamie Madill Committed by Commit Bot

Vulkan: Track RP's read/write access for depth/stencil.

This generalizes the read tracking into read/write. Knowing the write access can let us determine if we can switch a RenderPass to a read- only mode. And switching to read-only will let us combine some RenderPasses in Manhattan. Bug: angleproject:4959 Change-Id: Ic97547e84fef4a2670437677000d4525006ef69f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2358771 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarIan Elliott <ianelliott@google.com>
parent 699bcde0
......@@ -283,6 +283,25 @@ EventName GetTraceEventName(const char *title, uint32_t counter)
snprintf(buf.data(), kMaxGpuEventNameLen - 1, "%s %u", title, counter);
return buf;
}
vk::ResourceAccess GetDepthAccess(const gl::DepthStencilState &dsState)
{
if (!dsState.depthTest)
{
return vk::ResourceAccess::Unused;
}
return dsState.depthMask ? vk::ResourceAccess::Write : vk::ResourceAccess::ReadOnly;
}
vk::ResourceAccess GetStencilAccess(const gl::DepthStencilState &dsState)
{
if (!dsState.stencilTest)
{
return vk::ResourceAccess::Unused;
}
// Simplify this check by returning write instead of checking the mask.
return vk::ResourceAccess::Write;
}
} // anonymous namespace
ANGLE_INLINE void ContextVk::flushDescriptorSetUpdates()
......@@ -2843,30 +2862,41 @@ angle::Result ContextVk::syncState(const gl::Context *context,
updateSampleMask(glState);
break;
case gl::State::DIRTY_BIT_DEPTH_TEST_ENABLED:
{
mGraphicsPipelineDesc->updateDepthTestEnabled(&mGraphicsPipelineTransition,
glState.getDepthStencilState(),
glState.getDrawFramebuffer());
if (mState.isDepthTestEnabled() && mRenderPassCommands->started())
{
mRenderPassCommands->setDepthTestEnabled();
vk::ResourceAccess access = GetDepthAccess(mState.getDepthStencilState());
mRenderPassCommands->onDepthAccess(access);
}
break;
}
case gl::State::DIRTY_BIT_DEPTH_FUNC:
mGraphicsPipelineDesc->updateDepthFunc(&mGraphicsPipelineTransition,
glState.getDepthStencilState());
break;
case gl::State::DIRTY_BIT_DEPTH_MASK:
{
mGraphicsPipelineDesc->updateDepthWriteEnabled(&mGraphicsPipelineTransition,
glState.getDepthStencilState(),
glState.getDrawFramebuffer());
if (mState.isDepthTestEnabled() && mRenderPassCommands->started())
{
vk::ResourceAccess access = GetDepthAccess(mState.getDepthStencilState());
mRenderPassCommands->onDepthAccess(access);
}
break;
}
case gl::State::DIRTY_BIT_STENCIL_TEST_ENABLED:
mGraphicsPipelineDesc->updateStencilTestEnabled(&mGraphicsPipelineTransition,
glState.getDepthStencilState(),
glState.getDrawFramebuffer());
if (mState.isStencilTestEnabled() && mRenderPassCommands->started())
{
mRenderPassCommands->setStencilTestEnabled();
vk::ResourceAccess access = GetStencilAccess(mState.getDepthStencilState());
mRenderPassCommands->onStencilAccess(access);
}
break;
case gl::State::DIRTY_BIT_STENCIL_FUNCS_FRONT:
......@@ -4437,11 +4467,13 @@ angle::Result ContextVk::startRenderPass(gl::Rectangle renderArea,
if (mState.isDepthTestEnabled())
{
mRenderPassCommands->setDepthTestEnabled();
vk::ResourceAccess access = GetDepthAccess(mState.getDepthStencilState());
mRenderPassCommands->onDepthAccess(access);
}
if (mState.isStencilTestEnabled())
{
mRenderPassCommands->setStencilTestEnabled();
vk::ResourceAccess access = GetStencilAccess(mState.getDepthStencilState());
mRenderPassCommands->onStencilAccess(access);
}
if (commandBufferOut)
......
......@@ -66,6 +66,14 @@ enum ResourceAccess
Write,
};
inline void UpdateAccess(ResourceAccess *oldAccess, ResourceAccess newAccess)
{
if (newAccess > *oldAccess)
{
*oldAccess = newAccess;
}
}
class alignas(4) RenderPassDesc final
{
public:
......
......@@ -565,8 +565,8 @@ CommandBufferHelper::CommandBufferHelper()
mRebindTransformFeedbackBuffers(false),
mIsRenderPassCommandBuffer(false),
mMergeBarriers(false),
mDepthTestEverEnabled(false),
mStencilTestEverEnabled(false),
mDepthStartAccess(ResourceAccess::Unused),
mStencilStartAccess(ResourceAccess::Unused),
mDepthStencilAttachmentIndex(kInvalidAttachmentIndex)
{}
......@@ -770,18 +770,23 @@ void CommandBufferHelper::endRenderPass()
// Depth/Stencil buffer optimization: if we are loading or clearing the buffer, but the
// buffer has not been used, and the data has also not been stored back into buffer, then
// just skip the load/clear op.
if (!mDepthTestEverEnabled &&
if (mDepthStartAccess == ResourceAccess::Unused &&
mAttachmentOps[mDepthStencilAttachmentIndex].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE)
{
mAttachmentOps[mDepthStencilAttachmentIndex].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
}
if (!mStencilTestEverEnabled && mAttachmentOps[mDepthStencilAttachmentIndex].stencilStoreOp ==
VK_ATTACHMENT_STORE_OP_DONT_CARE)
if (mStencilStartAccess == ResourceAccess::Unused &&
mAttachmentOps[mDepthStencilAttachmentIndex].stencilStoreOp ==
VK_ATTACHMENT_STORE_OP_DONT_CARE)
{
mAttachmentOps[mDepthStencilAttachmentIndex].stencilLoadOp =
VK_ATTACHMENT_LOAD_OP_DONT_CARE;
}
// Ensure we don't write to a read-only RenderPass. (ReadOnly -> !Write)
ASSERT((mRenderPassDesc.getDepthStencilAccess() != ResourceAccess::ReadOnly) ||
mDepthStartAccess != ResourceAccess::Write);
}
void CommandBufferHelper::beginTransformFeedback(size_t validBufferCount,
......@@ -970,8 +975,8 @@ void CommandBufferHelper::reset()
mRenderPassStarted = false;
mValidTransformFeedbackBufferCount = 0;
mRebindTransformFeedbackBuffers = false;
mDepthTestEverEnabled = false;
mStencilTestEverEnabled = false;
mDepthStartAccess = ResourceAccess::Unused;
mStencilStartAccess = ResourceAccess::Unused;
mDepthStencilAttachmentIndex = kInvalidAttachmentIndex;
mRenderPassUsedImages.clear();
}
......
......@@ -981,8 +981,8 @@ class CommandBufferHelper : angle::NonCopyable
// Dumping the command stream is disabled by default.
static constexpr bool kEnableCommandStreamDiagnostics = false;
void setDepthTestEnabled() { mDepthTestEverEnabled = true; }
void setStencilTestEnabled() { mStencilTestEverEnabled = true; }
void onDepthAccess(ResourceAccess access) { UpdateAccess(&mDepthStartAccess, access); }
void onStencilAccess(ResourceAccess access) { UpdateAccess(&mStencilStartAccess, access); }
private:
void addCommandDiagnostics(ContextVk *contextVk);
......@@ -1012,8 +1012,9 @@ class CommandBufferHelper : angle::NonCopyable
bool mIsRenderPassCommandBuffer;
bool mMergeBarriers;
bool mDepthTestEverEnabled;
bool mStencilTestEverEnabled;
ResourceAccess mDepthStartAccess;
ResourceAccess mStencilStartAccess;
uint32_t mDepthStencilAttachmentIndex;
// Tracks resources used in the command buffer.
......
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