From 99d32439a803f1121e4a0ba267774a348bbd748c Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Tue, 3 Feb 2026 00:39:55 +0800 Subject: [PATCH] [Perf] (MG_Backend/DirectGLES): Remove binding state protectors. --- MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp | 20 ----- MobileGL/MG_Backend/DirectGLES/Managers.cpp | 7 -- MobileGL/MG_Backend/DirectGLES/Utils.cpp | 86 +------------------ MobileGL/MG_Backend/DirectGLES/Utils.h | 52 +---------- 4 files changed, 5 insertions(+), 160 deletions(-) diff --git a/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp b/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp index fb55df5f..820f04e9 100644 --- a/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp +++ b/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp @@ -844,16 +844,6 @@ namespace MobileGL::MG_Backend::DirectGLES { errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) { MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str()); }); - FramebufferImpl::BackendFramebufferBindingProtector drawFboProtector(GL_DRAW_FRAMEBUFFER); - FramebufferImpl::BackendFramebufferBindingProtector readFboProtector(GL_READ_FRAMEBUFFER); - errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) { - MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str()); - }); - - FramebufferImpl::BackendFramebufferBindingProtector::BindTempFBO(FramebufferTarget::Draw); - errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) { - MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str()); - }); GLint currentTex; MG_External::GLES::glGetIntegerv(Utils::GetBindingQuery(target, false), ¤tTex); @@ -925,15 +915,6 @@ namespace MobileGL::MG_Backend::DirectGLES { }); } else { MGLOG_D("%s: Backend depth", __func__); - FramebufferImpl::BackendFramebufferBindingProtector drawFboProtector(GL_DRAW_FRAMEBUFFER); - FramebufferImpl::BackendFramebufferBindingProtector readFboProtector(GL_READ_FRAMEBUFFER); - errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) { - MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str()); - }); - FramebufferImpl::BackendFramebufferBindingProtector::BindTempFBO(FramebufferTarget::Draw); - errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) { - MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str()); - }); GLint currentTex; MG_External::GLES::glGetIntegerv(Utils::GetBindingQuery(target, false), ¤tTex); errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) { @@ -971,7 +952,6 @@ namespace MobileGL::MG_Backend::DirectGLES { auto texture = slot.GetBoundObject(); auto backendTexture = TextureImpl::SyncTextureObjectToBackend(texture); - TextureImpl::BackendTextureBindingProtector protector(target); backendTexture->Bind(target); MG_External::GLES::glGenerateMipmap(target); } diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.cpp b/MobileGL/MG_Backend/DirectGLES/Managers.cpp index e33b7026..04af6811 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Managers.cpp @@ -105,7 +105,6 @@ namespace MobileGL::MG_Backend::DirectGLES { #ifdef TRACY_ENABLE ZoneScopedC(TRACY_ZONECOLOR_BACKEND); #endif - BackendBufferBindingProtector backendBufferBindingProtector(TempBufferTarget); MGLOG_D("Syncing buffer data (glBufferData) for object with ID : %u", m_backendBufferId); @@ -122,7 +121,6 @@ namespace MobileGL::MG_Backend::DirectGLES { #ifdef TRACY_ENABLE ZoneScopedC(TRACY_ZONECOLOR_BACKEND); #endif - BackendBufferBindingProtector backendBufferBindingProtector(TempBufferTarget); MGLOG_D("Syncing buffer sub-data (glBufferSubData) for object with ID : %u", m_backendBufferId); @@ -146,7 +144,6 @@ namespace MobileGL::MG_Backend::DirectGLES { #ifdef TRACY_ENABLE ZoneScopedC(TRACY_ZONECOLOR_BACKEND); #endif - BackendBufferBindingProtector backendBufferBindingProtector(TempBufferTarget); MGLOG_D("Syncing buffer map (glMapBuffer) for object with ID : %u", m_backendBufferId); MGLOG_D("Mapping buffer with ID: %u", m_backendBufferId); @@ -228,9 +225,6 @@ namespace MobileGL::MG_Backend::DirectGLES { MGLOG_D("Syncing VAO with backend ID %u to backend for state ID %u", m_backendVAOId, stateVAOObject->GetExternalIndex()); - BufferImpl::BackendBufferBindingProtector backendBufferBindingProtector(BufferImpl::TempBufferTarget); - BackendVertexArrayBindingProtector backendVAOBindingProtector; - Bind(); for (const auto& attribIndex : stateVAOObject->GetDirtyAttributeIndices()) { @@ -759,7 +753,6 @@ namespace MobileGL::MG_Backend::DirectGLES { MGLOG_D("Syncing FBO with backend ID %u to backend for state ID %u, as %s FBO", m_backendFBOId, stateFBOObject->GetExternalIndex(), (asTarget == FramebufferTarget::Draw ? "DRAW" : "READ")); GLenum glFBOTarget = MG_Util::ConvertFramebufferTargetToGLEnum(asTarget); - BackendFramebufferBindingProtector backendFBOBindingProtector(glFBOTarget); Bind(asTarget); // Handle all attachments diff --git a/MobileGL/MG_Backend/DirectGLES/Utils.cpp b/MobileGL/MG_Backend/DirectGLES/Utils.cpp index 65435cb8..8c528ee7 100644 --- a/MobileGL/MG_Backend/DirectGLES/Utils.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Utils.cpp @@ -19,55 +19,11 @@ #include namespace MobileGL::MG_Backend::DirectGLES { - namespace BufferImpl { - BackendBufferBindingProtector::BackendBufferBindingProtector(GLenum target) { -#ifdef TRACY_ENABLE - ZoneScopedC(TRACY_ZONECOLOR_BACKEND); -#endif - m_target = target; - MG_External::GLES::glGetIntegerv(Utils::GetBindingQuery(target, false), &m_previousBinding); - } + namespace BufferImpl {} // namespace BufferImpl - BackendBufferBindingProtector::~BackendBufferBindingProtector() { -#ifdef TRACY_ENABLE - ZoneScopedC(TRACY_ZONECOLOR_BACKEND); -#endif - MG_External::GLES::glBindBuffer(m_target, m_previousBinding); - } - } // namespace BufferImpl - - namespace VertexArrayImpl { - BackendVertexArrayBindingProtector::BackendVertexArrayBindingProtector() { -#ifdef TRACY_ENABLE - ZoneScopedC(TRACY_ZONECOLOR_BACKEND); -#endif - MG_External::GLES::glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &m_previousBinding); - } - - BackendVertexArrayBindingProtector::~BackendVertexArrayBindingProtector() { -#ifdef TRACY_ENABLE - ZoneScopedC(TRACY_ZONECOLOR_BACKEND); -#endif - MG_External::GLES::glBindVertexArray(m_previousBinding); - } - } // namespace VertexArrayImpl + namespace VertexArrayImpl {} // namespace VertexArrayImpl namespace TextureImpl { - BackendTextureBindingProtector::BackendTextureBindingProtector(GLenum target) { -#ifdef TRACY_ENABLE - ZoneScopedC(TRACY_ZONECOLOR_BACKEND); -#endif - m_target = target; - MG_External::GLES::glGetIntegerv(Utils::GetBindingQuery(target, true), &m_previousBinding); - } - - BackendTextureBindingProtector::~BackendTextureBindingProtector() { -#ifdef TRACY_ENABLE - ZoneScopedC(TRACY_ZONECOLOR_BACKEND); -#endif - MG_External::GLES::glBindTexture(m_target, m_previousBinding); - } - void GenerateTextureFormatInfo(TextureInternalFormat internalFormat, GLenum* outInternalFormat, GLenum* outFormat, GLenum* outType) { #ifdef TRACY_ENABLE @@ -81,43 +37,7 @@ namespace MobileGL::MG_Backend::DirectGLES { } } // namespace TextureImpl - namespace FramebufferImpl { - BackendFramebufferBindingProtector::BackendFramebufferBindingProtector(GLenum target) { -#ifdef TRACY_ENABLE - ZoneScopedC(TRACY_ZONECOLOR_BACKEND); -#endif - m_target = target; - MG_External::GLES::glGetIntegerv(Utils::GetBindingQuery(target, false), &m_previousBinding); - } - - BackendFramebufferBindingProtector::~BackendFramebufferBindingProtector() { -#ifdef TRACY_ENABLE - ZoneScopedC(TRACY_ZONECOLOR_BACKEND); -#endif - MG_External::GLES::glBindFramebuffer(m_target, m_previousBinding); - } - - GLuint BackendFramebufferBindingProtector::GetTempFBO(FramebufferTarget target) { -#ifdef TRACY_ENABLE - ZoneScopedC(TRACY_ZONECOLOR_BACKEND); -#endif - GLenum glTarget = MG_Util::ConvertFramebufferTargetToGLEnum(target); - GLuint& fbo = (glTarget == GL_DRAW_FRAMEBUFFER) ? s_tempDrawFBO : s_tempReadFBO; - if (fbo == 0) { - MG_External::GLES::glGenFramebuffers(1, &fbo); - } - return fbo; - } - - void BackendFramebufferBindingProtector::BindTempFBO(MobileGL::FramebufferTarget target) { -#ifdef TRACY_ENABLE - ZoneScopedC(TRACY_ZONECOLOR_BACKEND); -#endif - GLuint fbo = GetTempFBO(target); - GLenum glTarget = MG_Util::ConvertFramebufferTargetToGLEnum(target); - MG_External::GLES::glBindFramebuffer(glTarget, fbo); - } - } // namespace FramebufferImpl + namespace FramebufferImpl {} // namespace FramebufferImpl namespace PrgramImpl { String ProcessOutColorLocations(const String& glslCode) { diff --git a/MobileGL/MG_Backend/DirectGLES/Utils.h b/MobileGL/MG_Backend/DirectGLES/Utils.h index 2f239dd7..21777e33 100644 --- a/MobileGL/MG_Backend/DirectGLES/Utils.h +++ b/MobileGL/MG_Backend/DirectGLES/Utils.h @@ -27,66 +27,18 @@ namespace MobileGL::MG_Backend::DirectGLES { }; } // namespace DebugImpl - namespace BufferImpl { - class BackendBufferBindingProtector { - public: - BackendBufferBindingProtector(GLenum target); - - ~BackendBufferBindingProtector(); - - private: - GLenum m_target; - GLint m_previousBinding = 0; - }; - } // namespace BufferImpl + namespace BufferImpl {} // namespace BufferImpl namespace VertexArrayImpl { GLenum GetBindingQuery(GLenum target, bool isTexture); - - class BackendVertexArrayBindingProtector { - public: - BackendVertexArrayBindingProtector(); - - ~BackendVertexArrayBindingProtector(); - - private: - GLint m_previousBinding = 0; - }; } // namespace VertexArrayImpl namespace TextureImpl { - class BackendTextureBindingProtector { - public: - BackendTextureBindingProtector(GLenum target); - - ~BackendTextureBindingProtector(); - - private: - GLenum m_target; - GLint m_previousBinding = 0; - }; - void GenerateTextureFormatInfo(TextureInternalFormat internalFormat, GLenum* outInternalFormat, GLenum* outFormat, GLenum* outType); } // namespace TextureImpl - namespace FramebufferImpl { - class BackendFramebufferBindingProtector { - public: - BackendFramebufferBindingProtector(GLenum target); - - ~BackendFramebufferBindingProtector(); - - static GLuint GetTempFBO(FramebufferTarget target); - static void BindTempFBO(FramebufferTarget target); - - private: - GLenum m_target; - GLint m_previousBinding = 0; - inline static GLuint s_tempReadFBO = 0; - inline static GLuint s_tempDrawFBO = 0; - }; - } // namespace FramebufferImpl + namespace FramebufferImpl {} // namespace FramebufferImpl namespace PrgramImpl { String ProcessOutColorLocations(const String& glslCode);