From dbbcaa9eca16920508cdf87380f12626a6244996 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 May 2020 16:56:31 -0700 Subject: [PATCH] GLES: Invalidate framebuffers bound DONT_CARE. Let's try to invalidate when it's possible. We move the invalidate to the end of the render when detected. --- ext/native/thin3d/GLQueueRunner.cpp | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/ext/native/thin3d/GLQueueRunner.cpp b/ext/native/thin3d/GLQueueRunner.cpp index cb5d63d847..682212be0e 100644 --- a/ext/native/thin3d/GLQueueRunner.cpp +++ b/ext/native/thin3d/GLQueueRunner.cpp @@ -609,6 +609,44 @@ void GLQueueRunner::RunSteps(const std::vector &steps, bool skipGLCal } } + auto ignoresContents = [](GLRRenderPassAction act) { + return act == GLRRenderPassAction::CLEAR || act == GLRRenderPassAction::DONT_CARE; + }; + int invalidateAllMask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; + + for (int j = 0; j < (int)steps.size() - 1; ++j) { + GLRStep &primaryStep = *steps[j]; + if (primaryStep.stepType == GLRStepType::RENDER) { + const GLRFramebuffer *fb = primaryStep.render.framebuffer; + + // Let's see if we can invalidate it... + int invalidateMask = 0; + for (int i = j + 1; i < (int)steps.size(); ++i) { + const GLRStep &secondaryStep = *steps[i]; + if (secondaryStep.stepType == GLRStepType::RENDER && secondaryStep.render.framebuffer == fb) { + if (ignoresContents(secondaryStep.render.color)) + invalidateMask |= GL_COLOR_BUFFER_BIT; + if (ignoresContents(secondaryStep.render.depth)) + invalidateMask |= GL_DEPTH_BUFFER_BIT; + if (ignoresContents(secondaryStep.render.stencil)) + invalidateMask |= GL_STENCIL_BUFFER_BIT; + + if (invalidateMask == invalidateAllMask) + break; + } else if (secondaryStep.dependencies.contains(fb)) { + // Can't do it, this step may depend on fb's data. + break; + } + } + + if (invalidateMask) { + GLRRenderData data{ GLRRenderCommand::INVALIDATE }; + data.clear.clearMask = invalidateMask; + primaryStep.commands.push_back(data); + } + } + } + CHECK_GL_ERROR_IF_DEBUG(); size_t renderCount = 0; for (size_t i = 0; i < steps.size(); i++) {