Permalink
Browse files

Merge pull request #10442 from unknownbrackets/depth-clear

GPU: Reduce depth blits when not updated
  • Loading branch information...
hrydgard committed Dec 24, 2017
2 parents 46c468f + 0956fa3 commit 138cd9e851469e6ad92242aad7bc97d7e0696f19
@@ -440,7 +440,6 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame
vfb->drawnFormat = params.fmt;
vfb->usageFlags = FB_USAGE_RENDERTARGET;
SetColorUpdated(vfb, skipDrawReason);
vfb->depthUpdated = false;
u32 byteSize = FramebufferByteSize(vfb);
u32 fb_address_mem = (params.fb_address & 0x3FFFFFFF) | 0x04000000;
@@ -588,7 +587,8 @@ void FramebufferManagerCommon::NotifyRenderFramebufferSwitched(VirtualFramebuffe
// Copy depth pixel value from the read framebuffer to the draw framebuffer
if (prevVfb && !g_Config.bDisableSlowFramebufEffects) {
if (!prevVfb->fbo || !vfb->fbo || !useBufferedRendering_ || !prevVfb->depthUpdated || isClearingDepth) {
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 {
@@ -79,9 +79,10 @@ struct VirtualFramebuffer {
int last_frame_displayed;
int last_frame_clut;
int last_frame_failed;
int last_frame_depth_updated;
int last_frame_depth_render;
u32 clutUpdatedBytes;
bool memoryUpdated;
bool depthUpdated;
bool firstFrameSaved;
u32 fb_address;
@@ -283,7 +284,8 @@ class FramebufferManagerCommon {
void SetDepthUpdated() {
if (currentRenderVfb_) {
currentRenderVfb_->depthUpdated = true;
currentRenderVfb_->last_frame_depth_render = gpuStats.numFlips;
currentRenderVfb_->last_frame_depth_updated = gpuStats.numFlips;
}
}
void SetColorUpdated(int skipDrawReason) {
@@ -539,6 +539,7 @@ void FramebufferManagerD3D11::BlitFramebufferDepth(VirtualFramebuffer *src, Virt
// TODO: Currently, this copies depth AND stencil, which is a problem. See #9740.
draw_->CopyFramebufferImage(src->fbo, 0, 0, 0, 0, dst->fbo, 0, 0, 0, 0, src->renderWidth, src->renderHeight, 1, Draw::FB_DEPTH_BIT);
RebindFramebuffer();
dst->last_frame_depth_updated = gpuStats.numFlips;
}
}
@@ -529,7 +529,7 @@ void FramebufferManagerGLES::BlitFramebufferDepth(VirtualFramebuffer *src, Virtu
// Let's only do this if not clearing depth.
glstate.scissorTest.force(false);
draw_->BlitFramebuffer(src->fbo, 0, 0, w, h, dst->fbo, 0, 0, w, h, Draw::FB_DEPTH_BIT, Draw::FB_BLIT_NEAREST);
// WARNING: If we set dst->depthUpdated here, our optimization above would be pointless.
dst->last_frame_depth_updated = gpuStats.numFlips;
glstate.scissorTest.restore();
}
}
@@ -412,6 +412,7 @@ void FramebufferManagerVulkan::BlitFramebufferDepth(VirtualFramebuffer *src, Vir
if (matchingDepthBuffer && matchingRenderSize && matchingSize) {
// TODO: Currently, this copies depth AND stencil, which is a problem. See #9740.
draw_->CopyFramebufferImage(src->fbo, 0, 0, 0, 0, dst->fbo, 0, 0, 0, 0, src->renderWidth, src->renderHeight, 1, Draw::FB_DEPTH_BIT);
dst->last_frame_depth_updated = gpuStats.numFlips;
} else if (matchingDepthBuffer && matchingSize) {
/*
int w = std::min(src->renderWidth, dst->renderWidth);

0 comments on commit 138cd9e

Please sign in to comment.