From 29ea3ffe0c85a7d2bde037a304e0e4a836b240da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 20 Aug 2022 09:46:15 +0200 Subject: [PATCH] Restore the clearing optimization, avoiding unnecessary depth copies --- GPU/Common/FramebufferManagerCommon.cpp | 9 ++++++--- GPU/Common/FramebufferManagerCommon.h | 2 +- GPU/GPUCommon.cpp | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index 7c2159146c..308f1b7fd5 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -497,13 +497,16 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame } // Called on the first use of depth in a render pass. -void FramebufferManagerCommon::SetDepthFrameBuffer() { +void FramebufferManagerCommon::SetDepthFrameBuffer(bool isClearingDepth) { if (!currentRenderVfb_) { return; } - // "Resolve" the depth buffer, by copying from any overlapping buffers with fresher content. - CopyToDepthFromOverlappingFramebuffers(currentRenderVfb_); + // If this first draw call is anything other than a clear, "resolve" the depth buffer, + // by copying from any overlapping buffers with fresher content. + if (!isClearingDepth) { + CopyToDepthFromOverlappingFramebuffers(currentRenderVfb_); + } currentRenderVfb_->usageFlags |= FB_USAGE_RENDER_DEPTH; currentRenderVfb_->depthBindSeq = GetBindSeqCount(); diff --git a/GPU/Common/FramebufferManagerCommon.h b/GPU/Common/FramebufferManagerCommon.h index 3acff211dd..447554f376 100644 --- a/GPU/Common/FramebufferManagerCommon.h +++ b/GPU/Common/FramebufferManagerCommon.h @@ -267,7 +267,7 @@ public: return vfb; } } - void SetDepthFrameBuffer(); + void SetDepthFrameBuffer(bool isClearingDepth); void RebindFramebuffer(const char *tag); std::vector GetFramebufferList() const; diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 14c4cf1f5e..7db2fd4b42 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -1635,7 +1635,7 @@ void GPUCommon::CheckDepthUsage(VirtualFramebuffer *vfb) { if (isClearingDepth || gstate.isDepthWriteEnabled()) { vfb->last_frame_depth_updated = gpuStats.numFlips; } - framebufferManager_->SetDepthFrameBuffer(); + framebufferManager_->SetDepthFrameBuffer(isClearingDepth); } } }