Skip to content

Commit

Permalink
Merge pull request #12913 from unknownbrackets/gles-invalidate
Browse files Browse the repository at this point in the history
Add glInvalidateFramebuffer on clobber
  • Loading branch information
hrydgard committed Jul 13, 2020
2 parents 6009bf7 + dbbcaa9 commit 09238ed
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ext/native/thin3d/GLQueueRunner.cpp
Expand Up @@ -609,6 +609,44 @@ void GLQueueRunner::RunSteps(const std::vector<GLRStep *> &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++) {
Expand Down

0 comments on commit 09238ed

Please sign in to comment.