[Optimization] (MG_Backend/DirectGLES): optimize BackendTextureBindingProtector usage

This commit is contained in:
2025-12-11 20:38:09 +08:00
parent 91b04f6995
commit 6a9738a7c5
3 changed files with 17 additions and 1 deletions
+1
View File
@@ -33,6 +33,7 @@
#include <string_view>
#include <unordered_map>
#include <mutex>
#include <bitset>
// Include FastSTL
#include <FastSTL/UnorderedMap.h>
@@ -191,6 +191,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
// 1. textures bound to texture units (TODO: only sync ones that are used in current program)
// 2. textures used in current FBO
// 3. textures bound to image units (TODO)
constexpr SizeT TextureTargetCount = static_cast<SizeT>(TextureTarget::TextureTargetCount);
std::bitset<TextureTargetCount> dirtyTextureTargetBits;
Vector<SharedPtr<MG_State::GLState::ITextureObject>> texturesToSync;
@@ -202,6 +204,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
const auto& end = texturesToSync.end();
if (std::find(texturesToSync.begin(), end, textureObject) == end) {
texturesToSync.push_back(textureObject);
dirtyTextureTargetBits.set(static_cast<SizeT>(textureObject->GetTarget()));
}
}
}
@@ -217,11 +220,23 @@ namespace MobileGL::MG_Backend::DirectGLES {
const auto& end = texturesToSync.end();
if (std::find(texturesToSync.begin(), end, textureObject) == end) {
texturesToSync.push_back(textureObject);
dirtyTextureTargetBits.set(static_cast<SizeT>(textureObject->GetTarget()));
}
}
}
}
BufferImpl::BackendBufferBindingProtector pixelUnpackProtector =
BufferImpl::BackendBufferBindingProtector(GL_PIXEL_UNPACK_BUFFER);
Vector<BackendTextureBindingProtector> textureBindingProtectors;
for (SizeT target = 0; target < TextureTargetCount; ++target) {
if (dirtyTextureTargetBits[target]) {
textureBindingProtectors.emplace_back(
MG_Util::ConvertTextureTargetToGLEnum(static_cast<TextureTarget>(target)));
}
}
// Do real sync
for (auto& textureObject : texturesToSync) {
SyncTextureObjectToBackend(textureObject);
+1 -1
View File
@@ -328,7 +328,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
return;
}
BackendTextureBindingProtector backendTextureBindingProtector(target);
// BackendTextureBindingProtector backendTextureBindingProtector(target);
Bind(target);
errorLopper.Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
MGLOG_D("%s(%s:%d) ES error: %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());