From 0ae1b762620ca39ef694eb5a4775d980bd517de6 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Tue, 3 Feb 2026 01:27:58 +0800 Subject: [PATCH] [Feat] (MG_State/VertexArrayState): Replace dirty mark with resource version for VA. --- .../VertexArrayState/VertexArrayObject.cpp | 49 ++++++++++--------- .../VertexArrayState/VertexArrayObject.h | 16 ++++-- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp index a5b91cb3..507955bb 100644 --- a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp +++ b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp @@ -22,20 +22,20 @@ namespace MobileGL { attr.Offset = 0; attr.Buffer = nullptr; - MarkAttributeDirty(index); + BumpAttributeFormatVersion(index); } } void VertexArrayObject::EnableAttribute(Uint index) { if (index >= MAX_VERTEX_ATTRIBS) return; m_attributes[index].Enabled = true; - MarkAttributeDirty(index); + BumpAttributeFormatVersion(index); } void VertexArrayObject::DisableAttribute(Uint index) { if (index >= MAX_VERTEX_ATTRIBS) return; m_attributes[index].Enabled = false; - MarkAttributeDirty(index); + BumpAttributeFormatVersion(index); } Bool VertexArrayObject::IsAttributeEnabled(Uint index) const { @@ -59,13 +59,13 @@ namespace MobileGL { attr.Offset = offset; attr.IsInteger = isInteger; - MarkAttributeDirty(index); + BumpAttributeFormatVersion(index); } void VertexArrayObject::BindAttributeBuffer(Uint index, const SharedPtr& buffer) { if (index >= MAX_VERTEX_ATTRIBS) return; m_attributes[index].Buffer = buffer; - MarkAttributeDirty(index); + BumpAttributeBufferVersion(index); } BindingSlot& VertexArrayObject::GetIndexBufferBindingSlot() { @@ -83,22 +83,6 @@ namespace MobileGL { return m_attributes; } - void VertexArrayObject::MarkAttributeDirty(Uint index) { - if (index >= MAX_VERTEX_ATTRIBS) return; - if (std::find(m_dirtyAttributes.begin(), m_dirtyAttributes.end(), index) != m_dirtyAttributes.end()) { - return; - } - m_dirtyAttributes.push_back(index); - } - - const Vector& VertexArrayObject::GetDirtyAttributeIndices() const { - return m_dirtyAttributes; - } - - void VertexArrayObject::ClearDirtyAttributes() { - m_dirtyAttributes.clear(); - } - Uint VertexArrayObject::GetExternalIndex() const { return m_externalIndex; } @@ -107,13 +91,34 @@ namespace MobileGL { if (index >= MAX_VERTEX_ATTRIBS) return; if (m_attributes[index].Divisor == divisor) return; m_attributes[index].Divisor = divisor; - MarkAttributeDirty(index); + BumpAttributeFormatVersion(index); } Uint VertexArrayObject::GetAttributeDivisor(Uint index) const { if (index >= MAX_VERTEX_ATTRIBS) return 0; return m_attributes[index].Divisor; } + + void VertexArrayObject::BumpAttributeFormatVersion(Uint index) { + if (index >= MAX_VERTEX_ATTRIBS) return; + ++m_attributeVersions[index].FormatVersion; + } + + void VertexArrayObject::BumpAttributeBufferVersion(Uint index) { + if (index >= MAX_VERTEX_ATTRIBS) return; + ++m_attributeVersions[index].BufferVersion; + } + + const VertexAttributeVersion& VertexArrayObject::GetAttributeVersion(Uint index) const { + static VertexAttributeVersion emptyVersion; + if (index >= MAX_VERTEX_ATTRIBS) return emptyVersion; + return m_attributeVersions[index]; + } + + const Array& VertexArrayObject:: + GetAllAttributeVersions() const { + return m_attributeVersions; + } } // namespace GLState } // namespace MG_State } // namespace MobileGL diff --git a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h index 854122c9..ccb8b5c1 100644 --- a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h +++ b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h @@ -9,6 +9,7 @@ #pragma once #include #include "../BufferState/BufferObject.h" +#include "MG_Util/Types.h" namespace MobileGL { namespace MG_State { @@ -25,6 +26,11 @@ namespace MobileGL { SharedPtr Buffer; }; + struct VertexAttributeVersion { + Uint16 FormatVersion = 0; + Uint16 BufferVersion = 0; + }; + class VertexArrayObject { public: static constexpr int MAX_VERTEX_ATTRIBS = 16; @@ -45,19 +51,21 @@ namespace MobileGL { const VertexAttribute& GetAttribute(Uint index) const; const Array& GetAllAttributes() const; - const Vector& GetDirtyAttributeIndices() const; - void ClearDirtyAttributes(); Uint GetExternalIndex() const; void SetAttributeDivisor(Uint index, Uint divisor); Uint GetAttributeDivisor(Uint index) const; + const VertexAttributeVersion& GetAttributeVersion(Uint index) const; + const Array& GetAllAttributeVersions() const; + private: - void MarkAttributeDirty(Uint index); + void BumpAttributeFormatVersion(Uint index); + void BumpAttributeBufferVersion(Uint index); const Uint m_externalIndex = 0; Array m_attributes; - Vector m_dirtyAttributes; + Array m_attributeVersions; // format version, buffer version BindingSlot m_indexBufferBindingSlot; }; } // namespace GLState