[Optimize] (MG_Backend/DirectGLES): get rid of dedup logic in buffer sync

This commit is contained in:
2026-02-02 11:17:16 +08:00
parent 3d420f6d12
commit 33a4afba5e
+4 -13
View File
@@ -94,7 +94,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
// 1.VBO 2.IBO (if needed) 3.UBO 4.IndirectBuffer (if needed) 5.SSBO (TODO) // 1.VBO 2.IBO (if needed) 3.UBO 4.IndirectBuffer (if needed) 5.SSBO (TODO)
// PBO is not needed since it should be handled in frontend // PBO is not needed since it should be handled in frontend
Vector<SharedPtr<MG_State::GLState::BufferObject>> buffersToSync; static Vector<SharedPtr<MG_State::GLState::BufferObject>> buffersToSync;
buffersToSync.clear();
const auto& currentVAOObject = MG_State::pGLContext->GetBoundVertexArray(); const auto& currentVAOObject = MG_State::pGLContext->GetBoundVertexArray();
if (!currentVAOObject) { if (!currentVAOObject) {
MGLOG_E("No VAO is currently bound, cannot sync necessary buffers."); MGLOG_E("No VAO is currently bound, cannot sync necessary buffers.");
@@ -106,35 +109,26 @@ namespace MobileGL::MG_Backend::DirectGLES {
if (!attrib.Enabled) continue; if (!attrib.Enabled) continue;
const auto& bufferObject = attrib.Buffer; const auto& bufferObject = attrib.Buffer;
if (bufferObject) { if (bufferObject) {
const auto& end = buffersToSync.end();
if (std::find(buffersToSync.begin(), end, bufferObject) == end) {
buffersToSync.push_back(bufferObject); buffersToSync.push_back(bufferObject);
} }
} }
}
// IBO // IBO
if (includeIBO) { if (includeIBO) {
const auto& possibleIBO = currentVAOObject->GetIndexBufferBindingSlot().GetBoundObject(); const auto& possibleIBO = currentVAOObject->GetIndexBufferBindingSlot().GetBoundObject();
if (possibleIBO) { if (possibleIBO) {
const auto& end = buffersToSync.end();
if (std::find(buffersToSync.begin(), end, possibleIBO) == end) {
buffersToSync.push_back(possibleIBO); buffersToSync.push_back(possibleIBO);
} }
} }
}
// Indirect Buffer Object // Indirect Buffer Object
if (includeIndirectBuffer) { if (includeIndirectBuffer) {
const auto& possibleIndirectBuffer = const auto& possibleIndirectBuffer =
MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::DrawIndirect).GetBoundObject(); MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::DrawIndirect).GetBoundObject();
if (possibleIndirectBuffer) { if (possibleIndirectBuffer) {
const auto& end = buffersToSync.end();
if (std::find(buffersToSync.begin(), end, possibleIndirectBuffer) == end) {
buffersToSync.push_back(possibleIndirectBuffer); buffersToSync.push_back(possibleIndirectBuffer);
} }
} }
}
// UBO // UBO
auto uboBindingPointCnt = MG_State::pGLContext->GetBufferBindingPointCount(BufferTarget::Uniform); auto uboBindingPointCnt = MG_State::pGLContext->GetBufferBindingPointCount(BufferTarget::Uniform);
@@ -142,12 +136,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
auto& point = MG_State::pGLContext->GetBufferBindingPoint(BufferTarget::Uniform, i); auto& point = MG_State::pGLContext->GetBufferBindingPoint(BufferTarget::Uniform, i);
auto obj = point.GetBoundObject(); auto obj = point.GetBoundObject();
if (obj) { if (obj) {
const auto& end = buffersToSync.end();
if (std::find(buffersToSync.begin(), end, obj) == end) {
buffersToSync.push_back(obj); buffersToSync.push_back(obj);
} }
} }
}
// Do real sync // Do real sync
for (auto& bufferObject : buffersToSync) { for (auto& bufferObject : buffersToSync) {