From 9306bbd4e401f51d73a898fa24bb279c29427ca6 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 17 Oct 2021 21:51:45 -0700 Subject: [PATCH] GPU: Refactor framebuffer depth blit for reuse. Shouldn't change anything yet, just moving logic around. --- GPU/Common/FramebufferManagerCommon.cpp | 34 ++++++++++++++----------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index 91b712086b..4da29c10a3 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -469,6 +469,22 @@ void FramebufferManagerCommon::DestroyFramebuf(VirtualFramebuffer *v) { } void FramebufferManagerCommon::BlitFramebufferDepth(VirtualFramebuffer *src, VirtualFramebuffer *dst) { + _dbg_assert_(src && dst); + + // Check that the depth address is even the same before actually blitting. + bool matchingDepthBuffer = src->z_address == dst->z_address && src->z_stride != 0 && dst->z_stride != 0; + bool matchingSize = src->width == dst->width && src->height == dst->height; + if (!matchingDepthBuffer || !matchingSize) + return; + + // Copy depth value from the previously bound framebuffer to the current one. + bool hasNewerDepth = src->last_frame_depth_render != 0 && src->last_frame_depth_render >= dst->last_frame_depth_updated; + if (!src->fbo || !dst->fbo || !useBufferedRendering_ || !hasNewerDepth) { + // If depth wasn't updated, then we're at least "two degrees" away from the data. + // This is an optimization: it probably doesn't need to be copied in this case. + return; + } + int w = std::min(src->renderWidth, dst->renderWidth); int h = std::min(src->renderHeight, dst->renderHeight); @@ -687,21 +703,9 @@ void FramebufferManagerCommon::NotifyRenderFramebufferSwitched(VirtualFramebuffe textureCache_->ForgetLastTexture(); shaderManager_->DirtyLastShader(); - if (prevVfb) { - // Copy depth value from the previously bound framebuffer to the current one. - // We check that the address is the same within BlitFramebufferDepth before actually blitting. - - bool hasNewerDepth = prevVfb->last_frame_depth_render != 0 && prevVfb->last_frame_depth_render >= vfb->last_frame_depth_updated; - if (!prevVfb->fbo || !vfb->fbo || !useBufferedRendering_ || !hasNewerDepth || isClearingDepth) { - // If depth wasn't updated, then we're at least "two degrees" away from the data. - // This is an optimization: it probably doesn't need to be copied in this case. - } else { - bool matchingDepthBuffer = prevVfb->z_address == vfb->z_address && prevVfb->z_stride != 0 && vfb->z_stride != 0; - bool matchingSize = prevVfb->width == vfb->width && prevVfb->height == vfb->height; - if (matchingDepthBuffer && matchingSize) { - BlitFramebufferDepth(prevVfb, vfb); - } - } + // Copy depth between the framebuffers, if the z_address is the same (checked inside.) + if (prevVfb && !isClearingDepth) { + BlitFramebufferDepth(prevVfb, vfb); } if (vfb->drawnFormat != vfb->format) {