From 86471dfb807b11094f54b09353d521cd145fb1b4 Mon Sep 17 00:00:00 2001 From: Eurya0x13 Date: Thu, 26 Nov 2026 18:14:25 +0800 Subject: [PATCH] [Refactor] (MG_Impl/Pipe, MG_State/GLState): keep vertex-input memo hints in the emitter - Use a bounded slot hint table keyed by array lifetime. - Validate the lifetime and allocator epoch before reusing an entry. --- MobileGL/MG_Impl/Pipe/VertexInputEmit.h | 7 ++++--- .../MG_State/GLState/VertexArrayState/VertexArrayObject.h | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/MobileGL/MG_Impl/Pipe/VertexInputEmit.h b/MobileGL/MG_Impl/Pipe/VertexInputEmit.h index 388178f5..4960ad5f 100644 --- a/MobileGL/MG_Impl/Pipe/VertexInputEmit.h +++ b/MobileGL/MG_Impl/Pipe/VertexInputEmit.h @@ -487,9 +487,9 @@ namespace MobileGL::MG_Pipe { VaoMemo& MemoFor(const VertexArrayObject& vao) { const Uint64 lifetimeId = vao.GetLifetimeId(); const Uint64 epoch = MGPipeSlots().ResetEpoch(); - // A per-array hint survives switching arrays. Growth and erasure can move entries, - // so the slot is only a candidate until both identity and the allocator epoch match. - SizeT& hint = vao.PipeVertexInputMemoHint(); + // Keep recent slots in the emitter across array switches. Collisions, growth and + // erasure can stale a hint, so check the lifetime and epoch before using it. + SizeT& hint = m_vaoMemoHints[lifetimeId & (m_vaoMemoHints.size() - 1)]; if (hint < m_vaoMemo.size() && m_vaoMemo[hint].LifetimeId == lifetimeId && m_vaoMemo[hint].SlotEpoch == epoch) return m_vaoMemo[hint]; @@ -528,6 +528,7 @@ namespace MobileGL::MG_Pipe { } Vector m_vaoMemo; SizeT m_vaoMemoUsed = 0; + Array m_vaoMemoHints{}; public: // The VAO died (MGPipeEmitVertexElementsDestroyAndFree): its entry goes, by backward-shift diff --git a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h index a6143268..97b176cb 100644 --- a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h +++ b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h @@ -69,8 +69,6 @@ namespace MobileGL { // DirectVulkan's VulkanRenderer). Uint64 GetLifetimeId() const { return m_lifetimeId; } - SizeT& PipeVertexInputMemoHint() const { return m_pipeVertexInputMemoHint; } - void SetAttributeDivisor(Uint index, Uint divisor); Uint GetAttributeDivisor(Uint index) const; @@ -136,7 +134,6 @@ namespace MobileGL { const Uint m_externalIndex = 0; const Uint64 m_lifetimeId = AllocateLifetimeId(); - mutable SizeT m_pipeVertexInputMemoHint = ~SizeT{0}; Array m_attributes; Array m_attributeVersions; BindingSlot m_indexBufferBindingSlot;