@@ -561,10 +561,10 @@ CommandBufferHelper::CommandBufferHelper()
561561 mIsRenderPassCommandBuffer(false ),
562562 mDepthStartAccess(ResourceAccess::Unused),
563563 mStencilStartAccess(ResourceAccess::Unused),
564- mDepthEnabled( false ),
565- mDepthInvalidatedState(NeverInvalidated ),
566- mStencilEnabled( false ),
567- mStencilInvalidatedState(NeverInvalidated ),
564+ mDepthCmdSizeInvalidated( kInfiniteCmdSize ),
565+ mDepthCmdSizeDisabled( kInfiniteCmdSize ),
566+ mStencilCmdSizeInvalidated( kInfiniteCmdSize ),
567+ mStencilCmdSizeDisabled( kInfiniteCmdSize ),
568568 mDepthStencilAttachmentIndex(kInvalidAttachmentIndex )
569569{}
570570
@@ -704,70 +704,67 @@ void CommandBufferHelper::imageWrite(ResourceUseList *resourceUseList,
704704 }
705705}
706706
707- void CommandBufferHelper::onDepthAccess (ResourceAccess access)
707+ bool CommandBufferHelper::onDepthAccess (ResourceAccess access)
708708{
709- // TODO(ianelliott): Rework the handling of invalidated attachments in a follow-up CL, using
710- // the count of commands in the SecondaryCommandBuffer.
711- // See https://issuetracker.google.com/issues/163854287
712- InvalidatedState invalidatedState;
713-
714- if (access == vk::ResourceAccess::Write)
715- {
716- // This handles various scenarios that an app/test can do with valid GLES usage. For
717- // example, consider an app that invalidates, doesn't disable the functionality, and draws
718- // again. In that case, the drawing that occurs after the invalidate means that there is
719- // once again valid content in the attachment (i.e. that should not be discarded). Since
720- // we don't track draws, we must be conservative and assume that a draw may have occured
721- // since invalidation unless the functionality has also been disabled and the re-enabled.
722- invalidatedState = (!mDepthEnabled ) ? NoLongerInvalidated : Invalidated;
723- // Keep track of whether depth functionality is enabled
724- mDepthEnabled = true ;
725- }
726- else
727- {
728- invalidatedState = Invalidated;
729- // Keep track of whether depth functionality is enabled
730- mDepthEnabled = false ;
731- }
732-
733709 // Update the access for optimizing this render pass's loadOp
734710 UpdateAccess (&mDepthStartAccess , access);
735711 ASSERT ((mRenderPassDesc .getDepthStencilAccess () != ResourceAccess::ReadOnly) ||
736712 mDepthStartAccess != ResourceAccess::Write);
713+
737714 // Update the invalidate state for optimizing this render pass's storeOp
738- UpdateInvalidatedState (& mDepthInvalidatedState , invalidatedState );
715+ return onDepthStencilAccess (access, & mDepthCmdSizeInvalidated , & mDepthCmdSizeDisabled );
739716}
740717
741- void CommandBufferHelper::onStencilAccess (ResourceAccess access)
718+ bool CommandBufferHelper::onStencilAccess (ResourceAccess access)
742719{
743- // TODO(ianelliott): Rework the handling of invalidated attachments in a follow-up CL, using
744- // the count of commands in the SecondaryCommandBuffer.
745- // See https://issuetracker.google.com/issues/163854287
746- InvalidatedState invalidatedState;
720+ // Update the access for optimizing this render pass's loadOp
721+ UpdateAccess (&mStencilStartAccess , access);
747722
723+ // Update the invalidate state for optimizing this render pass's stencilStoreOp
724+ return onDepthStencilAccess (access, &mStencilCmdSizeInvalidated , &mStencilCmdSizeDisabled );
725+ }
726+
727+ bool CommandBufferHelper::onDepthStencilAccess (ResourceAccess access,
728+ uint32_t *cmdCountInvalidated,
729+ uint32_t *cmdCountDisabled)
730+ {
731+ if (*cmdCountInvalidated == kInfiniteCmdSize )
732+ {
733+ // If never invalidated or no longer invalidated, return early.
734+ return false ;
735+ }
748736 if (access == vk::ResourceAccess::Write)
749737 {
750- // This handles various scenarios that an app/test can do with valid GLES usage. For
751- // example, consider an app that invalidates, doesn't disable the functionality, and draws
752- // again. In that case, the drawing that occurs after the invalidate means that there is
753- // once again valid content in the attachment (i.e. that should not be discarded). Since
754- // we don't track draws, we must be conservative and assume that a draw may have occured
755- // since invalidation unless the functionality has also been disabled and the re-enabled.
756- invalidatedState = (!mStencilEnabled ) ? NoLongerInvalidated : Invalidated;
757- // Keep track of whether stencil functionality is enabled
758- mStencilEnabled = true ;
738+ // Drawing to this attachment is being enabled. Assume that drawing will immediately occur
739+ // after this attachment is enabled, and that means that the attachment will no longer be
740+ // invalidated.
741+ *cmdCountInvalidated = kInfiniteCmdSize ;
742+ *cmdCountDisabled = kInfiniteCmdSize ;
743+ // Return true to indicate that the store op should remain STORE and that mContentDefined
744+ // should be set to true;
745+ return true ;
759746 }
760747 else
761748 {
762- invalidatedState = Invalidated;
763- // Keep track of whether stencil functionality is enabled
764- mStencilEnabled = false ;
749+ // Drawing to this attachment is being disabled.
750+ if (isNoLongerInvalidated (*cmdCountInvalidated, *cmdCountDisabled))
751+ {
752+ // The attachment was previously drawn while enabled, and so is no longer invalidated.
753+ *cmdCountInvalidated = kInfiniteCmdSize ;
754+ *cmdCountDisabled = kInfiniteCmdSize ;
755+ // Return true to indicate that the store op should remain STORE and that
756+ // mContentDefined should be set to true;
757+ return true ;
758+ }
759+ else
760+ {
761+ // Get the latest CmdSize at the start of being disabled. At the end of the render
762+ // pass, cmdCountDisabled is <= the actual command buffer size, and so it's compared
763+ // with cmdCountInvalidated. If the same, the attachment is still invalidated.
764+ *cmdCountDisabled = mCommandBuffer .getCommandBufferSize ();
765+ return false ;
766+ }
765767 }
766-
767- // Update the access for optimizing this render pass's loadOp
768- UpdateAccess (&mStencilStartAccess , access);
769- // Update the invalidate state for optimizing this render pass's stencilStoreOp
770- UpdateInvalidatedState (&mStencilInvalidatedState , invalidatedState);
771768}
772769
773770void CommandBufferHelper::executeBarriers (ContextVk *contextVk, PrimaryCommandBuffer *primary)
@@ -863,19 +860,20 @@ void CommandBufferHelper::endRenderPass(ContextVk *contextVk)
863860
864861 PackedAttachmentOpsDesc &dsOps = mAttachmentOps [mDepthStencilAttachmentIndex ];
865862
866- // Address invalidated depth/stencil attachments
867- if (mDepthInvalidatedState == Invalidated)
863+ // Depth/Stencil buffer optimizations:
864+ //
865+ // First, if the attachment is invalidated, skip the store op.
866+ if (isInvalidated (mDepthCmdSizeInvalidated , mDepthCmdSizeDisabled ))
868867 {
869868 dsOps.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
870869 }
871- if (mStencilInvalidatedState == Invalidated )
870+ if (isInvalidated ( mStencilCmdSizeInvalidated , mStencilCmdSizeDisabled ) )
872871 {
873872 dsOps.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
874873 }
875874
876- // Depth/Stencil buffer optimization: if we are loading or clearing the buffer, but the
877- // buffer has not been used, and the data has also not been stored back into buffer, then
878- // just skip the load/clear op.
875+ // Second, if we are loading or clearing the attachment, but the attachment has not been used,
876+ // and the data has also not been stored back into attachment, then just skip the load/clear op.
879877 if (mDepthStartAccess == ResourceAccess::Unused &&
880878 dsOps.storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE)
881879 {
@@ -1099,10 +1097,10 @@ void CommandBufferHelper::reset()
10991097 mRebindTransformFeedbackBuffers = false ;
11001098 mDepthStartAccess = ResourceAccess::Unused;
11011099 mStencilStartAccess = ResourceAccess::Unused;
1102- mDepthInvalidatedState = NeverInvalidated ;
1103- mDepthEnabled = false ;
1104- mStencilInvalidatedState = NeverInvalidated ;
1105- mStencilEnabled = false ;
1100+ mDepthCmdSizeInvalidated = kInfiniteCmdSize ;
1101+ mDepthCmdSizeDisabled = kInfiniteCmdSize ;
1102+ mStencilCmdSizeInvalidated = kInfiniteCmdSize ;
1103+ mStencilCmdSizeDisabled = kInfiniteCmdSize ;
11061104 mDepthStencilAttachmentIndex = kInvalidAttachmentIndex ;
11071105 mRenderPassUsedImages .clear ();
11081106 }
0 commit comments