From bef078a3bd8bb6611ddd9c605c24b94b3945ee50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 24 May 2020 19:18:04 +0200 Subject: [PATCH] GLRenderManager: Removes some redundant dirtying. Preserves blend state (color mask) across clears. --- ext/native/thin3d/GLQueueRunner.cpp | 5 ++++- ext/native/thin3d/GLRenderManager.cpp | 16 ---------------- ext/native/thin3d/GLRenderManager.h | 2 +- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/ext/native/thin3d/GLQueueRunner.cpp b/ext/native/thin3d/GLQueueRunner.cpp index 5a297aa974..7be3fd09c2 100644 --- a/ext/native/thin3d/GLQueueRunner.cpp +++ b/ext/native/thin3d/GLQueueRunner.cpp @@ -796,7 +796,6 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { } if (c.clear.colorMask != colorMask) { glColorMask(c.clear.colorMask & 1, (c.clear.colorMask >> 1) & 1, (c.clear.colorMask >> 2) & 1, (c.clear.colorMask >> 3) & 1); - colorMask = c.clear.colorMask; } if (c.clear.clearMask & GL_COLOR_BUFFER_BIT) { float color[4]; @@ -818,6 +817,10 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { glClearStencil(c.clear.clearStencil); } glClear(c.clear.clearMask); + // Restore the color mask if it was different. + if (c.clear.colorMask != colorMask) { + glColorMask(colorMask & 1, (colorMask >> 1) & 1, (colorMask >> 2) & 1, (colorMask >> 3) & 1); + } if (c.clear.scissorW == 0) { glEnable(GL_SCISSOR_TEST); } diff --git a/ext/native/thin3d/GLRenderManager.cpp b/ext/native/thin3d/GLRenderManager.cpp index b2fe949cf2..f04d8f9390 100644 --- a/ext/native/thin3d/GLRenderManager.cpp +++ b/ext/native/thin3d/GLRenderManager.cpp @@ -5,7 +5,6 @@ #include "thin3d/thin3d.h" #include "thread/threadutil.h" #include "base/logging.h" -#include "GPU/GPUState.h" #include "Common/MemoryUtil.h" #if 0 // def _DEBUG @@ -318,9 +317,6 @@ void GLRenderManager::BindFramebufferAsRenderTarget(GLRFramebuffer *fb, GLRRende step->dependencies.insert(fb); } } - - // Every step clears this state. - gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE); } void GLRenderManager::BindFramebufferAsTexture(GLRFramebuffer *fb, int binding, int aspectBit, int attachment) { @@ -346,9 +342,6 @@ void GLRenderManager::CopyFramebuffer(GLRFramebuffer *src, GLRect2D srcRect, GLR if (dstPos.x != 0 || dstPos.y != 0 || !fillsDst) step->dependencies.insert(dst); steps_.push_back(step); - - // Every step clears this state. - gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE); } void GLRenderManager::BlitFramebuffer(GLRFramebuffer *src, GLRect2D srcRect, GLRFramebuffer *dst, GLRect2D dstRect, int aspectMask, bool filter, const char *tag) { @@ -365,9 +358,6 @@ void GLRenderManager::BlitFramebuffer(GLRFramebuffer *src, GLRect2D srcRect, GLR if (!fillsDst) step->dependencies.insert(dst); steps_.push_back(step); - - // Every step clears this state. - gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE); } bool GLRenderManager::CopyFramebufferToMemorySync(GLRFramebuffer *src, int aspectBits, int x, int y, int w, int h, Draw::DataFormat destFormat, uint8_t *pixels, int pixelStride, const char *tag) { @@ -382,9 +372,6 @@ bool GLRenderManager::CopyFramebufferToMemorySync(GLRFramebuffer *src, int aspec step->tag = tag; steps_.push_back(step); - // Every step clears this state. - gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE); - curRenderStep_ = nullptr; FlushSync(); @@ -414,9 +401,6 @@ void GLRenderManager::CopyImageToMemorySync(GLRTexture *texture, int mipLevel, i step->tag = tag; steps_.push_back(step); - // Every step clears this state. - gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE); - curRenderStep_ = nullptr; FlushSync(); diff --git a/ext/native/thin3d/GLRenderManager.h b/ext/native/thin3d/GLRenderManager.h index 47338a85eb..bffa535895 100644 --- a/ext/native/thin3d/GLRenderManager.h +++ b/ext/native/thin3d/GLRenderManager.h @@ -812,7 +812,7 @@ public: curRenderStep_->commands.push_back(data); } - // If scissorW == 0, no scissor is applied. + // If scissorW == 0, no scissor is applied (the whole render target is cleared). void Clear(uint32_t clearColor, float clearZ, int clearStencil, int clearMask, int colorMask, int scissorX, int scissorY, int scissorW, int scissorH) { _dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); if (!clearMask)