mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Feat|Perf|Fix] (MG_Backend/DirectGLES): Skip redundant sync for VA when not dirty.
This commit is contained in:
@@ -156,7 +156,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
} // namespace BufferImpl
|
} // namespace BufferImpl
|
||||||
|
|
||||||
namespace VertexArrayImpl {
|
namespace VertexArrayImpl {
|
||||||
void SyncCurrentVAO(Bool needDivisor) {
|
void SyncCurrentVAO() {
|
||||||
#ifdef TRACY_ENABLE
|
#ifdef TRACY_ENABLE
|
||||||
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
||||||
#endif
|
#endif
|
||||||
@@ -174,7 +174,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
} else {
|
} else {
|
||||||
backendVAOObject = backendVAOIt->second;
|
backendVAOObject = backendVAOIt->second;
|
||||||
}
|
}
|
||||||
backendVAOObject->SyncToBackend(currentVAOObject, needDivisor);
|
backendVAOObject->SyncToBackend(currentVAOObject);
|
||||||
}
|
}
|
||||||
} // namespace VertexArrayImpl
|
} // namespace VertexArrayImpl
|
||||||
|
|
||||||
@@ -388,7 +388,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
||||||
#endif
|
#endif
|
||||||
BufferImpl::SyncNeccessaryBuffers(syncBit & DrawSyncBit::IndexBuffer, syncBit & DrawSyncBit::IndirectBuffer);
|
BufferImpl::SyncNeccessaryBuffers(syncBit & DrawSyncBit::IndexBuffer, syncBit & DrawSyncBit::IndirectBuffer);
|
||||||
VertexArrayImpl::SyncCurrentVAO(syncBit & DrawSyncBit::Instancing);
|
VertexArrayImpl::SyncCurrentVAO();
|
||||||
TextureImpl::SyncNeccessaryTextures();
|
TextureImpl::SyncNeccessaryTextures();
|
||||||
FramebufferImpl::SyncCurrentFBO();
|
FramebufferImpl::SyncCurrentFBO();
|
||||||
PrgramImpl::SyncCurrentProgram();
|
PrgramImpl::SyncCurrentProgram();
|
||||||
@@ -856,8 +856,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
|
|
||||||
if (MG_External::GLES::glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (MG_External::GLES::glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
MGLOG_E("ES glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE");
|
MGLOG_E("ES glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE");
|
||||||
|
|
||||||
// Protector will automatically revert to previous fbo states
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -867,7 +865,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
|
errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
|
||||||
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
});
|
});
|
||||||
// Protector will automatically revert to previous fbo states
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -927,8 +924,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
});
|
});
|
||||||
if (MG_External::GLES::glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (MG_External::GLES::glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
MGLOG_E("ES glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE");
|
MGLOG_E("ES glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE");
|
||||||
|
|
||||||
// Protector will automatically revert to previous fbo states
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -938,7 +933,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
|
errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
|
||||||
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
});
|
});
|
||||||
// Protector will automatically revert to previous fbo states
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,8 +212,38 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
MG_External::GLES::glBindVertexArray(m_backendVAOId);
|
MG_External::GLES::glBindVertexArray(m_backendVAOId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackendVertexArrayObject::SyncToBackend(SharedPtr<MG_State::GLState::VertexArrayObject>& stateVAOObject,
|
void BackendVertexArrayObject::SyncAttributeBuffer(Uint index,
|
||||||
Bool needDivisor) {
|
const MG_State::GLState::VertexAttribute& attrib) {
|
||||||
|
const auto& bufferObject = attrib.Buffer;
|
||||||
|
if (!bufferObject) {
|
||||||
|
MGLOG_W("Attribute has no bound buffer, skipping.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& backendBufferIt = BufferImpl::g_backendBufferObjects.find(bufferObject);
|
||||||
|
if (backendBufferIt == BufferImpl::g_backendBufferObjects.end()) {
|
||||||
|
MGLOG_E("No backend buffer found for attribute's buffer, cannot bind attribute.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto& backendBufferObject = backendBufferIt->second;
|
||||||
|
|
||||||
|
backendBufferObject->Bind(GL_ARRAY_BUFFER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BackendVertexArrayObject::SyncAttributeFormat(Uint index,
|
||||||
|
const MG_State::GLState::VertexAttribute& attrib) {
|
||||||
|
if (attrib.Enabled) {
|
||||||
|
MGLOG_D("Binding attribute index %u for VAO ID: %u", index, m_backendVAOId);
|
||||||
|
MG_External::GLES::glEnableVertexAttribArray(index);
|
||||||
|
} else {
|
||||||
|
MGLOG_D("Disabling attribute index %u for VAO ID: %u", index, m_backendVAOId);
|
||||||
|
MG_External::GLES::glDisableVertexAttribArray(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
MG_External::GLES::glVertexAttribDivisor(index, attrib.Divisor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BackendVertexArrayObject::SyncToBackend(SharedPtr<MG_State::GLState::VertexArrayObject>& stateVAOObject) {
|
||||||
#ifdef TRACY_ENABLE
|
#ifdef TRACY_ENABLE
|
||||||
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
||||||
#endif
|
#endif
|
||||||
@@ -227,31 +257,24 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
|
|
||||||
Bind();
|
Bind();
|
||||||
|
|
||||||
for (const auto& attribIndex : stateVAOObject->GetDirtyAttributeIndices()) {
|
const auto& allAttributeVersions = stateVAOObject->GetAllAttributeVersions();
|
||||||
const auto& attrib = stateVAOObject->GetAttribute(attribIndex);
|
const auto& allAttributes = stateVAOObject->GetAllAttributes();
|
||||||
if (attrib.Enabled) {
|
for (Uint attribIndex = 0; attribIndex < allAttributes.size(); ++attribIndex) {
|
||||||
MGLOG_D("Binding attribute index %u for VAO ID: %u", attribIndex, m_backendVAOId);
|
Bool needsSyncFormat = allAttributeVersions[attribIndex].FormatVersion !=
|
||||||
MG_External::GLES::glEnableVertexAttribArray(attribIndex);
|
m_syncedAttributeVersions[attribIndex].FormatVersion;
|
||||||
} else {
|
Bool needsSyncBuffer = allAttributeVersions[attribIndex].BufferVersion !=
|
||||||
MGLOG_D("Disabling attribute index %u for VAO ID: %u", attribIndex, m_backendVAOId);
|
m_syncedAttributeVersions[attribIndex].BufferVersion;
|
||||||
MG_External::GLES::glDisableVertexAttribArray(attribIndex);
|
if (!needsSyncFormat && !needsSyncBuffer) continue;
|
||||||
continue;
|
|
||||||
|
const auto& attrib = allAttributes[attribIndex];
|
||||||
|
if (needsSyncBuffer) {
|
||||||
|
SyncAttributeBuffer(attribIndex, attrib);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& bufferObject = attrib.Buffer;
|
if (needsSyncFormat) {
|
||||||
if (!bufferObject) {
|
SyncAttributeFormat(attribIndex, attrib);
|
||||||
MGLOG_W("Attribute has no bound buffer, skipping.");
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& backendBufferIt = BufferImpl::g_backendBufferObjects.find(bufferObject);
|
|
||||||
if (backendBufferIt == BufferImpl::g_backendBufferObjects.end()) {
|
|
||||||
MGLOG_E("No backend buffer found for attribute's buffer, cannot bind attribute.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const auto& backendBufferObject = backendBufferIt->second;
|
|
||||||
|
|
||||||
backendBufferObject->Bind(GL_ARRAY_BUFFER);
|
|
||||||
if (!attrib.IsInteger) {
|
if (!attrib.IsInteger) {
|
||||||
MG_External::GLES::glVertexAttribPointer(
|
MG_External::GLES::glVertexAttribPointer(
|
||||||
attribIndex, attrib.Size, MG_Util::ConvertDataTypeToGLEnum(attrib.Type),
|
attribIndex, attrib.Size, MG_Util::ConvertDataTypeToGLEnum(attrib.Type),
|
||||||
@@ -261,10 +284,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
MG_Util::ConvertDataTypeToGLEnum(attrib.Type),
|
MG_Util::ConvertDataTypeToGLEnum(attrib.Type),
|
||||||
attrib.Stride, (const void*)attrib.Offset);
|
attrib.Stride, (const void*)attrib.Offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needDivisor) {
|
|
||||||
MG_External::GLES::glVertexAttribDivisor(attribIndex, attrib.Divisor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& indexBufferBinding = stateVAOObject->GetIndexBufferBindingSlot().GetBoundObject();
|
const auto& indexBufferBinding = stateVAOObject->GetIndexBufferBindingSlot().GetBoundObject();
|
||||||
@@ -278,7 +297,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stateVAOObject->ClearDirtyAttributes();
|
m_syncedAttributeVersions = allAttributeVersions;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnorderedMap<SharedPtr<MG_State::GLState::VertexArrayObject>, SharedPtr<BackendVertexArrayObject>>
|
UnorderedMap<SharedPtr<MG_State::GLState::VertexArrayObject>, SharedPtr<BackendVertexArrayObject>>
|
||||||
|
|||||||
@@ -44,13 +44,18 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
class BackendVertexArrayObject {
|
class BackendVertexArrayObject {
|
||||||
public:
|
public:
|
||||||
BackendVertexArrayObject();
|
BackendVertexArrayObject();
|
||||||
void SyncToBackend(SharedPtr<MG_State::GLState::VertexArrayObject>& stateVAOObject, Bool needDivisor);
|
void SyncToBackend(SharedPtr<MG_State::GLState::VertexArrayObject>& stateVAOObject);
|
||||||
Uint GetBackendVertexArrayId() { return m_backendVAOId; }
|
Uint GetBackendVertexArrayId() { return m_backendVAOId; }
|
||||||
void Bind();
|
void Bind();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void SyncAttributeFormat(Uint index, const MG_State::GLState::VertexAttribute& attrib);
|
||||||
|
void SyncAttributeBuffer(Uint index, const MG_State::GLState::VertexAttribute& attrib);
|
||||||
|
|
||||||
Uint m_backendVAOId = 0;
|
Uint m_backendVAOId = 0;
|
||||||
Bool m_isInitialized = false;
|
Bool m_isInitialized = false;
|
||||||
|
Array<MG_State::GLState::VertexAttributeVersion, MG_State::GLState::VertexArrayObject::MAX_VERTEX_ATTRIBS>
|
||||||
|
m_syncedAttributeVersions;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern UnorderedMap<SharedPtr<MG_State::GLState::VertexArrayObject>, SharedPtr<BackendVertexArrayObject>>
|
extern UnorderedMap<SharedPtr<MG_State::GLState::VertexArrayObject>, SharedPtr<BackendVertexArrayObject>>
|
||||||
|
|||||||
Reference in New Issue
Block a user