[Feat|Perf] (MG_Backend/DirectGLES): Skip whole sampler object when not dirty.

This commit is contained in:
BZLZHH
2026-02-03 00:08:25 +08:00
parent 3f0744a8ce
commit 653ca9ea74
2 changed files with 20 additions and 28 deletions
+18 -28
View File
@@ -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());
@@ -101,6 +101,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
FloatVec4 m_cacheBorderColor = {0.0f, 0.0f, 0.0f, 0.0f};
Vec4<TextureSwizzleParam> m_cacheSwizzleParams = {TextureSwizzleParam::Red, TextureSwizzleParam::Green,
TextureSwizzleParam::Blue, TextureSwizzleParam::Alpha};
Uint16 m_syncedSamplerVersion = 0;
};
extern UnorderedMap<SharedPtr<MG_State::GLState::ITextureObject>, SharedPtr<BackendTextureObject>>
@@ -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<MG_State::GLState::SamplerObject>, SharedPtr<BackendSamplerObject>>