mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-08 12:18:30 +09:00
[Optimization] (MG_Backend/DirectGLES): optimize BackendTextureBindingProtector usage
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user