mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Optimization] (MG_Backend/DirectGLES): optimize BackendTextureBindingProtector usage
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <bitset>
|
||||||
|
|
||||||
// Include FastSTL
|
// Include FastSTL
|
||||||
#include <FastSTL/UnorderedMap.h>
|
#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)
|
// 1. textures bound to texture units (TODO: only sync ones that are used in current program)
|
||||||
// 2. textures used in current FBO
|
// 2. textures used in current FBO
|
||||||
// 3. textures bound to image units (TODO)
|
// 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;
|
Vector<SharedPtr<MG_State::GLState::ITextureObject>> texturesToSync;
|
||||||
|
|
||||||
@@ -202,6 +204,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
const auto& end = texturesToSync.end();
|
const auto& end = texturesToSync.end();
|
||||||
if (std::find(texturesToSync.begin(), end, textureObject) == end) {
|
if (std::find(texturesToSync.begin(), end, textureObject) == end) {
|
||||||
texturesToSync.push_back(textureObject);
|
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();
|
const auto& end = texturesToSync.end();
|
||||||
if (std::find(texturesToSync.begin(), end, textureObject) == end) {
|
if (std::find(texturesToSync.begin(), end, textureObject) == end) {
|
||||||
texturesToSync.push_back(textureObject);
|
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
|
// Do real sync
|
||||||
for (auto& textureObject : texturesToSync) {
|
for (auto& textureObject : texturesToSync) {
|
||||||
SyncTextureObjectToBackend(textureObject);
|
SyncTextureObjectToBackend(textureObject);
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BackendTextureBindingProtector backendTextureBindingProtector(target);
|
// BackendTextureBindingProtector backendTextureBindingProtector(target);
|
||||||
Bind(target);
|
Bind(target);
|
||||||
errorLopper.Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
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());
|
MGLOG_D("%s(%s:%d) ES error: %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
|
|||||||
Reference in New Issue
Block a user