From 653ca9ea74390e003adb15ce6c6e137f14f15cbb Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Tue, 3 Feb 2026 00:08:25 +0800 Subject: [PATCH] [Feat|Perf] (MG_Backend/DirectGLES): Skip whole sampler object when not dirty. --- MobileGL/MG_Backend/DirectGLES/Managers.cpp | 46 ++++++++------------- MobileGL/MG_Backend/DirectGLES/Managers.h | 2 + 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.cpp b/MobileGL/MG_Backend/DirectGLES/Managers.cpp index 31558319..7c8ffb62 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Managers.cpp @@ -554,6 +554,14 @@ namespace MobileGL::MG_Backend::DirectGLES { return; } + Uint currentSamplerVersion = stateTextureObject->GetSamplerObject()->GetVersion(); + if (m_syncedSamplerVersion == currentSamplerVersion) { + MGLOG_D("Sampler parameters have not changed for texture ID: %u, skipping sync.", m_backendTextureId); + return; + } + + m_syncedSamplerVersion = currentSamplerVersion; + MGLOG_D("Syncing texture built-in sampler with backend ID %u to backend for state ID %u", m_backendTextureId, stateTextureObject->GetExternalIndex()); @@ -987,16 +995,7 @@ namespace MobileGL::MG_Backend::DirectGLES { source = ProcessOutColorLocations(source); source = ForceSupporterOutput(source); - // TODO: probably a patch system? - // String findStr = "if (distance_weight_sum == 0.0)"; - // String replaceStr = "if (distance_weight_sum <= 0.0001)"; - // auto pos = source.find(findStr); - // while (pos != String::npos) { - // MGLOG_D("Applying patch #1 to Photon..."); - // source.replace(pos, findStr.length(), replaceStr); - // pos = source.find(findStr, pos); - // } - + // Patch for Photon compiler precision issue String findStr = "1000000.0"; String replaceStr = "65500.0"; auto pos = source.find(findStr); @@ -1006,24 +1005,6 @@ namespace MobileGL::MG_Backend::DirectGLES { pos = source.find(findStr, pos); } - // findStr = "if (gtao.w == 0.0)"; - // replaceStr = "if (abs(gtao.w) <= 0.00001)"; - // pos = source.find(findStr); - // while (pos != String::npos) { - // MGLOG_D("Applying patch #3 to Photon..."); - // source.replace(pos, findStr.length(), replaceStr); - // pos = source.find(findStr, pos); - // } - - // findStr = "== 0.0"; - // replaceStr = "<= 0.00001"; - // pos = source.find(findStr); - // while (pos != String::npos) { - // MGLOG_D("Applying patch #4 to Photon..."); - // source.replace(pos, findStr.length(), replaceStr); - // pos = source.find(findStr, pos); - // } - const char* sourceCStr = source.c_str(); MGLOG_D("Setting shader source for backend shader ID: %u\nsrc:\n%s", backendShaderId, sourceCStr); MG_External::GLES::glShaderSource(backendShaderId, 1, &sourceCStr, nullptr); @@ -1110,6 +1091,15 @@ namespace MobileGL::MG_Backend::DirectGLES { return; } + Uint currentSamplerVersion = stateSamplerObject->GetVersion(); + if (m_isInitialized && m_syncedSamplerVersion == currentSamplerVersion) { + MGLOG_D("Sampler parameters have not changed for sampler ID: %u, skipping sync.", + stateSamplerObject->GetExternalIndex()); + return; + } + + m_syncedSamplerVersion = currentSamplerVersion; + MGLOG_D("Syncing sampler with backend ID %u to backend for state ID %u", m_backendSamplerId, stateSamplerObject->GetExternalIndex()); diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.h b/MobileGL/MG_Backend/DirectGLES/Managers.h index bb9ceb69..7ca7da85 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.h +++ b/MobileGL/MG_Backend/DirectGLES/Managers.h @@ -101,6 +101,7 @@ namespace MobileGL::MG_Backend::DirectGLES { FloatVec4 m_cacheBorderColor = {0.0f, 0.0f, 0.0f, 0.0f}; Vec4 m_cacheSwizzleParams = {TextureSwizzleParam::Red, TextureSwizzleParam::Green, TextureSwizzleParam::Blue, TextureSwizzleParam::Alpha}; + Uint16 m_syncedSamplerVersion = 0; }; extern UnorderedMap, SharedPtr> @@ -181,6 +182,7 @@ namespace MobileGL::MG_Backend::DirectGLES { Uint m_backendSamplerId = 0; Bool m_isInitialized = false; SamplerParameters m_cacheSamplerParameters; + Uint16 m_syncedSamplerVersion = 0; }; extern UnorderedMap, SharedPtr>