mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Optimization] (MG_Backend/DirectGLES): add more tracy zones
This commit is contained in:
@@ -409,63 +409,79 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
|
|
||||||
BindCurrentFBO(FramebufferTarget::Draw);
|
BindCurrentFBO(FramebufferTarget::Draw);
|
||||||
|
|
||||||
const auto& currentVAO = MG_State::pGLContext->GetBoundVertexArray();
|
{
|
||||||
if (currentVAO) {
|
#ifdef TRACY_ENABLE
|
||||||
const auto& backendVAOIt = VertexArrayImpl::g_backendVertexArrayObjects.find(currentVAO);
|
ZoneScopedNC("BindCurrentVAO", TRACY_ZONECOLOR_BACKEND);
|
||||||
if (backendVAOIt != VertexArrayImpl::g_backendVertexArrayObjects.end()) {
|
#endif
|
||||||
backendVAOIt->second->Bind();
|
const auto& currentVAO = MG_State::pGLContext->GetBoundVertexArray();
|
||||||
}
|
if (currentVAO) {
|
||||||
} else {
|
const auto& backendVAOIt = VertexArrayImpl::g_backendVertexArrayObjects.find(currentVAO);
|
||||||
MG_External::GLES::glBindVertexArray(0);
|
if (backendVAOIt != VertexArrayImpl::g_backendVertexArrayObjects.end()) {
|
||||||
}
|
backendVAOIt->second->Bind();
|
||||||
|
|
||||||
Int maxTextureUnits = MG_State::GLState::TextureState::MAX_TEXTURE_IMAGE_UNITS;
|
|
||||||
for (Int unit = 0; unit < maxTextureUnits; ++unit) {
|
|
||||||
auto& textureUnit = MG_State::pGLContext->GetTextureUnitObject(unit);
|
|
||||||
|
|
||||||
MG_External::GLES::glActiveTexture(GL_TEXTURE0 + unit);
|
|
||||||
|
|
||||||
for (const auto& bindingSlot : textureUnit.GetAllBindingSlots()) {
|
|
||||||
const auto& textureObject = bindingSlot.GetBoundObject();
|
|
||||||
if (!textureObject) continue;
|
|
||||||
|
|
||||||
// Bind texture object
|
|
||||||
auto target = textureObject->GetTarget();
|
|
||||||
if (target == TextureTarget::Texture1D ||
|
|
||||||
target == TextureTarget::TextureRectangle || target == TextureTarget::Texture2DMultisampleArray ||
|
|
||||||
target == TextureTarget::Texture1DArray || target == TextureTarget::Texture3D ||
|
|
||||||
target == TextureTarget::Texture2DMultisample || target == TextureTarget::Texture2DArray) {
|
|
||||||
MGLOG_D(" Texture target %s is not supported, skipping.",
|
|
||||||
MG_Util::ConvertTextureTargetToString(target).c_str());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const auto& backendTextureIt = TextureImpl::g_backendTextureObjects.find(textureObject);
|
|
||||||
if (backendTextureIt == TextureImpl::g_backendTextureObjects.end()) continue;
|
|
||||||
|
|
||||||
GLenum targetGL = MG_Util::ConvertTextureTargetToGLEnum(target);
|
|
||||||
backendTextureIt->second->Bind(targetGL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bind sampler object
|
|
||||||
const auto& samplerObject = textureUnit.GetSamplerObject();
|
|
||||||
if (samplerObject) {
|
|
||||||
const auto& backendSamplerIt = SamplerImpl::g_backendSamplerObjects.find(samplerObject);
|
|
||||||
if (backendSamplerIt != SamplerImpl::g_backendSamplerObjects.end()) {
|
|
||||||
backendSamplerIt->second->Bind(unit);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MG_External::GLES::glBindSampler(unit, 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;
|
||||||
|
for (Int unit = 0; unit < maxTextureUnits; ++unit) {
|
||||||
|
auto& textureUnit = MG_State::pGLContext->GetTextureUnitObject(unit);
|
||||||
|
|
||||||
|
MG_External::GLES::glActiveTexture(GL_TEXTURE0 + unit);
|
||||||
|
|
||||||
|
for (const auto& bindingSlot : textureUnit.GetAllBindingSlots()) {
|
||||||
|
const auto& textureObject = bindingSlot.GetBoundObject();
|
||||||
|
if (!textureObject) continue;
|
||||||
|
|
||||||
|
// Bind texture object
|
||||||
|
auto target = textureObject->GetTarget();
|
||||||
|
if (target == TextureTarget::Texture1D ||
|
||||||
|
target == TextureTarget::TextureRectangle || target == TextureTarget::Texture2DMultisampleArray ||
|
||||||
|
target == TextureTarget::Texture1DArray || target == TextureTarget::Texture3D ||
|
||||||
|
target == TextureTarget::Texture2DMultisample || target == TextureTarget::Texture2DArray) {
|
||||||
|
MGLOG_D(" Texture target %s is not supported, skipping.",
|
||||||
|
MG_Util::ConvertTextureTargetToString(target).c_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto& backendTextureIt = TextureImpl::g_backendTextureObjects.find(textureObject);
|
||||||
|
if (backendTextureIt == TextureImpl::g_backendTextureObjects.end()) continue;
|
||||||
|
|
||||||
|
GLenum targetGL = MG_Util::ConvertTextureTargetToGLEnum(target);
|
||||||
|
backendTextureIt->second->Bind(targetGL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind sampler object
|
||||||
|
const auto& samplerObject = textureUnit.GetSamplerObject();
|
||||||
|
if (samplerObject) {
|
||||||
|
const auto& backendSamplerIt = SamplerImpl::g_backendSamplerObjects.find(samplerObject);
|
||||||
|
if (backendSamplerIt != SamplerImpl::g_backendSamplerObjects.end()) {
|
||||||
|
backendSamplerIt->second->Bind(unit);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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,67 +496,78 @@ 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());
|
||||||
}
|
}
|
||||||
// Normal UBO
|
|
||||||
auto uboCount = currentProgram->GetActiveUniformBlocksCount();
|
|
||||||
Uint lastUBOBinding = 0; // to prevent overlapping bindings between global UBO and normal UBOs
|
|
||||||
for (Int i = 0; i < uboCount; ++i) {
|
|
||||||
++lastUBOBinding;
|
|
||||||
// program state binding index == backend binding index
|
|
||||||
|
|
||||||
// Connect program ubo index to backend binding point
|
{
|
||||||
auto binding = currentProgram->GetUniformBlockBinding(i);
|
#ifdef TRACY_ENABLE
|
||||||
auto& name = currentProgram->GetUniformBlockName(i);
|
ZoneScopedNC("UpdateUBO", TRACY_ZONECOLOR_BACKEND);
|
||||||
GLuint backendBlkIdx = MG_External::GLES::glGetUniformBlockIndex(backendProgramId, name.c_str());
|
#endif
|
||||||
MG_External::GLES::glUniformBlockBinding(backendProgramId, backendBlkIdx, lastUBOBinding);
|
// Normal UBO
|
||||||
|
auto uboCount = currentProgram->GetActiveUniformBlocksCount();
|
||||||
|
Uint lastUBOBinding = 0; // to prevent overlapping bindings between global UBO and normal UBOs
|
||||||
|
for (Int i = 0; i < uboCount; ++i) {
|
||||||
|
++lastUBOBinding;
|
||||||
|
// program state binding index == backend binding index
|
||||||
|
|
||||||
// Connect buffer to backend binding point
|
// Connect program ubo index to backend binding point
|
||||||
auto& point = MG_State::pGLContext->GetBufferBindingPoint(BufferTarget::Uniform, binding);
|
auto binding = currentProgram->GetUniformBlockBinding(i);
|
||||||
auto bufferObj = point.GetBoundObject();
|
auto& name = currentProgram->GetUniformBlockName(i);
|
||||||
auto range = point.GetRange();
|
GLuint backendBlkIdx = MG_External::GLES::glGetUniformBlockIndex(backendProgramId, name.c_str());
|
||||||
|
MG_External::GLES::glUniformBlockBinding(backendProgramId, backendBlkIdx, lastUBOBinding);
|
||||||
|
|
||||||
if (bufferObj) {
|
// Connect buffer to backend binding point
|
||||||
const auto& backendBufferIt = BufferImpl::g_backendBufferObjects.find(bufferObj);
|
auto& point = MG_State::pGLContext->GetBufferBindingPoint(BufferTarget::Uniform, binding);
|
||||||
if (backendBufferIt != BufferImpl::g_backendBufferObjects.end()) {
|
auto bufferObj = point.GetBoundObject();
|
||||||
const auto& backendBufferObject = backendBufferIt->second;
|
auto range = point.GetRange();
|
||||||
backendBufferObject->Bind(GL_UNIFORM_BUFFER);
|
|
||||||
if (range.end == 0) {
|
if (bufferObj) {
|
||||||
MG_External::GLES::glBindBufferBase(GL_UNIFORM_BUFFER, lastUBOBinding,
|
const auto& backendBufferIt = BufferImpl::g_backendBufferObjects.find(bufferObj);
|
||||||
backendBufferObject->GetBackendBufferId());
|
if (backendBufferIt != BufferImpl::g_backendBufferObjects.end()) {
|
||||||
|
const auto& backendBufferObject = backendBufferIt->second;
|
||||||
|
backendBufferObject->Bind(GL_UNIFORM_BUFFER);
|
||||||
|
if (range.end == 0) {
|
||||||
|
MG_External::GLES::glBindBufferBase(GL_UNIFORM_BUFFER, lastUBOBinding,
|
||||||
|
backendBufferObject->GetBackendBufferId());
|
||||||
|
} else {
|
||||||
|
MG_External::GLES::glBindBufferRange(GL_UNIFORM_BUFFER, lastUBOBinding,
|
||||||
|
backendBufferObject->GetBackendBufferId(),
|
||||||
|
range.start, range.end - range.start);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
MG_External::GLES::glBindBufferRange(GL_UNIFORM_BUFFER, lastUBOBinding,
|
MGLOG_E("No backend buffer found for UBO binding, cannot bind UBO.");
|
||||||
backendBufferObject->GetBackendBufferId(),
|
|
||||||
range.start, range.end - range.start);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
MGLOG_E("No backend buffer found for UBO binding, cannot bind UBO.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sampler unit binding
|
{
|
||||||
auto maxUniformLoc = currentProgram->GetMaxUniformLocation();
|
#ifdef TRACY_ENABLE
|
||||||
for (int loc = 0; loc < maxUniformLoc; ++loc) {
|
ZoneScopedNC("BindSamplerUnit", TRACY_ZONECOLOR_BACKEND);
|
||||||
auto unit = currentProgram->GetUniformSamplerOrImageUnitIndex(loc);
|
#endif
|
||||||
if (unit == -1) continue;
|
// Sampler unit binding
|
||||||
auto& name = currentProgram->GetUniformName(loc);
|
auto maxUniformLoc = currentProgram->GetMaxUniformLocation();
|
||||||
auto locAtBackend = MG_External::GLES::glGetUniformLocation(
|
for (int loc = 0; loc < maxUniformLoc; ++loc) {
|
||||||
backendProgramIt->second->GetBackendProgramId(), name.c_str());
|
auto unit = currentProgram->GetUniformSamplerOrImageUnitIndex(loc);
|
||||||
MG_External::GLES::glUniform1i(locAtBackend, unit);
|
if (unit == -1) continue;
|
||||||
|
auto& name = currentProgram->GetUniformName(loc);
|
||||||
|
auto locAtBackend = MG_External::GLES::glGetUniformLocation(
|
||||||
|
backendProgramIt->second->GetBackendProgramId(), name.c_str());
|
||||||
|
MG_External::GLES::glUniform1i(locAtBackend, unit);
|
||||||
|
|
||||||
auto samplerObject = MG_State::pGLContext->GetTextureUnitObject(unit).GetSamplerObject();
|
auto samplerObject = MG_State::pGLContext->GetTextureUnitObject(unit).GetSamplerObject();
|
||||||
|
|
||||||
if (samplerObject) {
|
if (samplerObject) {
|
||||||
const auto& backendSamplerIt = SamplerImpl::g_backendSamplerObjects.find(samplerObject);
|
const auto& backendSamplerIt = SamplerImpl::g_backendSamplerObjects.find(samplerObject);
|
||||||
SharedPtr<SamplerImpl::BackendSamplerObject> backendSamplerObject;
|
SharedPtr<SamplerImpl::BackendSamplerObject> backendSamplerObject;
|
||||||
if (backendSamplerIt == SamplerImpl::g_backendSamplerObjects.end()) {
|
if (backendSamplerIt == SamplerImpl::g_backendSamplerObjects.end()) {
|
||||||
backendSamplerObject = MakeShared<SamplerImpl::BackendSamplerObject>();
|
backendSamplerObject = MakeShared<SamplerImpl::BackendSamplerObject>();
|
||||||
SamplerImpl::g_backendSamplerObjects[samplerObject] = backendSamplerObject;
|
SamplerImpl::g_backendSamplerObjects[samplerObject] = backendSamplerObject;
|
||||||
|
} else {
|
||||||
|
backendSamplerObject = backendSamplerIt->second;
|
||||||
|
}
|
||||||
|
backendSamplerObject->SyncToBackend(samplerObject);
|
||||||
} else {
|
} else {
|
||||||
backendSamplerObject = backendSamplerIt->second;
|
MG_External::GLES::glBindSampler(unit, 0);
|
||||||
}
|
}
|
||||||
backendSamplerObject->SyncToBackend(samplerObject);
|
|
||||||
} else {
|
|
||||||
MG_External::GLES::glBindSampler(unit, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user