[Optimization] (MG_Backend/DirectGLES): add more tracy zones

This commit is contained in:
2025-12-12 10:25:39 +08:00
parent f08859d1c5
commit 0519cdeb9c
@@ -409,6 +409,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
BindCurrentFBO(FramebufferTarget::Draw); BindCurrentFBO(FramebufferTarget::Draw);
{
#ifdef TRACY_ENABLE
ZoneScopedNC("BindCurrentVAO", TRACY_ZONECOLOR_BACKEND);
#endif
const auto& currentVAO = MG_State::pGLContext->GetBoundVertexArray(); const auto& currentVAO = MG_State::pGLContext->GetBoundVertexArray();
if (currentVAO) { if (currentVAO) {
const auto& backendVAOIt = VertexArrayImpl::g_backendVertexArrayObjects.find(currentVAO); const auto& backendVAOIt = VertexArrayImpl::g_backendVertexArrayObjects.find(currentVAO);
@@ -418,7 +422,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
} else { } else {
MG_External::GLES::glBindVertexArray(0); MG_External::GLES::glBindVertexArray(0);
} }
}
{
#ifdef TRACY_ENABLE
ZoneScopedNC("BindCurrentTextures", TRACY_ZONECOLOR_BACKEND);
#endif
Int maxTextureUnits = MG_State::GLState::TextureState::MAX_TEXTURE_IMAGE_UNITS; Int maxTextureUnits = MG_State::GLState::TextureState::MAX_TEXTURE_IMAGE_UNITS;
for (Int unit = 0; unit < maxTextureUnits; ++unit) { for (Int unit = 0; unit < maxTextureUnits; ++unit) {
auto& textureUnit = MG_State::pGLContext->GetTextureUnitObject(unit); auto& textureUnit = MG_State::pGLContext->GetTextureUnitObject(unit);
@@ -457,15 +466,22 @@ namespace MobileGL::MG_Backend::DirectGLES {
MG_External::GLES::glBindSampler(unit, 0); MG_External::GLES::glBindSampler(unit, 0);
} }
} }
}
const auto& currentProgram = MG_State::pGLContext->GetCurrentProgram(); const auto& currentProgram = MG_State::pGLContext->GetCurrentProgram();
if (currentProgram && currentProgram->GetLinkStatus()) { if (currentProgram && currentProgram->GetLinkStatus()) {
#ifdef TRACY_ENABLE
ZoneScopedNC("BindCurrentProgram", TRACY_ZONECOLOR_BACKEND);
#endif
const auto& backendProgramIt = PrgramImpl::g_backendProgramObjects.find(currentProgram); const auto& backendProgramIt = PrgramImpl::g_backendProgramObjects.find(currentProgram);
if (backendProgramIt != PrgramImpl::g_backendProgramObjects.end()) { if (backendProgramIt != PrgramImpl::g_backendProgramObjects.end()) {
backendProgramIt->second->Use(); backendProgramIt->second->Use();
auto backendProgramId = backendProgramIt->second->GetBackendProgramId(); auto backendProgramId = backendProgramIt->second->GetBackendProgramId();
// Global UBO // Global UBO
if (currentProgram->GetUBOSize() > 0) { if (currentProgram->GetUBOSize() > 0) {
#ifdef TRACY_ENABLE
ZoneScopedNC("UpdateGlobalUBO", TRACY_ZONECOLOR_BACKEND);
#endif
MG_External::GLES::glBindBuffer(GL_UNIFORM_BUFFER, MG_External::GLES::glBindBuffer(GL_UNIFORM_BUFFER,
backendProgramIt->second->GetBackendGlobalUBOId()); backendProgramIt->second->GetBackendGlobalUBOId());
MG_External::GLES::glBufferSubData(GL_UNIFORM_BUFFER, 0, currentProgram->GetUBOSize(), MG_External::GLES::glBufferSubData(GL_UNIFORM_BUFFER, 0, currentProgram->GetUBOSize(),
@@ -480,6 +496,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
MG_External::GLES::glBindBufferBase(GL_UNIFORM_BUFFER, 0, MG_External::GLES::glBindBufferBase(GL_UNIFORM_BUFFER, 0,
backendProgramIt->second->GetBackendGlobalUBOId()); backendProgramIt->second->GetBackendGlobalUBOId());
} }
{
#ifdef TRACY_ENABLE
ZoneScopedNC("UpdateUBO", TRACY_ZONECOLOR_BACKEND);
#endif
// Normal UBO // Normal UBO
auto uboCount = currentProgram->GetActiveUniformBlocksCount(); auto uboCount = currentProgram->GetActiveUniformBlocksCount();
Uint lastUBOBinding = 0; // to prevent overlapping bindings between global UBO and normal UBOs Uint lastUBOBinding = 0; // to prevent overlapping bindings between global UBO and normal UBOs
@@ -516,7 +537,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
} }
} }
} }
}
{
#ifdef TRACY_ENABLE
ZoneScopedNC("BindSamplerUnit", TRACY_ZONECOLOR_BACKEND);
#endif
// Sampler unit binding // Sampler unit binding
auto maxUniformLoc = currentProgram->GetMaxUniformLocation(); auto maxUniformLoc = currentProgram->GetMaxUniformLocation();
for (int loc = 0; loc < maxUniformLoc; ++loc) { for (int loc = 0; loc < maxUniformLoc; ++loc) {
@@ -543,6 +569,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
MG_External::GLES::glBindSampler(unit, 0); MG_External::GLES::glBindSampler(unit, 0);
} }
} }
}
} else { } else {
MG_External::GLES::glUseProgram(0); MG_External::GLES::glUseProgram(0);
MGLOG_E("No backend program found (maybe not synced) for current program, cannot use program."); MGLOG_E("No backend program found (maybe not synced) for current program, cannot use program.");