[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.
This commit is contained in:
Eurya0x13 committed 2026-11-26 18:14:25 +08:00
1 parent 6ad3d3f519
commit 86471dfb80
2 files changed
+4 -6

No files matched your search

+4 -3
View File
@@ -487,9 +487,9 @@ namespace MobileGL::MG_Pipe {
VaoMemo& MemoFor(const VertexArrayObject& vao) { VaoMemo& MemoFor(const VertexArrayObject& vao) {
const Uint64 lifetimeId = vao.GetLifetimeId(); const Uint64 lifetimeId = vao.GetLifetimeId();
const Uint64 epoch = MGPipeSlots().ResetEpoch(); const Uint64 epoch = MGPipeSlots().ResetEpoch();
// A per-array hint survives switching arrays. Growth and erasure can move entries, // Keep recent slots in the emitter across array switches. Collisions, growth and
// so the slot is only a candidate until both identity and the allocator epoch match. // erasure can stale a hint, so check the lifetime and epoch before using it.
SizeT& hint = vao.PipeVertexInputMemoHint(); SizeT& hint = m_vaoMemoHints[lifetimeId & (m_vaoMemoHints.size() - 1)];
if (hint < m_vaoMemo.size() && m_vaoMemo[hint].LifetimeId == lifetimeId && if (hint < m_vaoMemo.size() && m_vaoMemo[hint].LifetimeId == lifetimeId &&
m_vaoMemo[hint].SlotEpoch == epoch) m_vaoMemo[hint].SlotEpoch == epoch)
return m_vaoMemo[hint]; return m_vaoMemo[hint];
@@ -528,6 +528,7 @@ namespace MobileGL::MG_Pipe {
} }
Vector<VaoMemo> m_vaoMemo; Vector<VaoMemo> m_vaoMemo;
SizeT m_vaoMemoUsed = 0; SizeT m_vaoMemoUsed = 0;
Array<SizeT, 256> m_vaoMemoHints{};
public: public:
// The VAO died (MGPipeEmitVertexElementsDestroyAndFree): its entry goes, by backward-shift // The VAO died (MGPipeEmitVertexElementsDestroyAndFree): its entry goes, by backward-shift
@@ -69,8 +69,6 @@ namespace MobileGL {
// DirectVulkan's VulkanRenderer). // DirectVulkan's VulkanRenderer).
Uint64 GetLifetimeId() const { return m_lifetimeId; } Uint64 GetLifetimeId() const { return m_lifetimeId; }
SizeT& PipeVertexInputMemoHint() const { return m_pipeVertexInputMemoHint; }
void SetAttributeDivisor(Uint index, Uint divisor); void SetAttributeDivisor(Uint index, Uint divisor);
Uint GetAttributeDivisor(Uint index) const; Uint GetAttributeDivisor(Uint index) const;
@@ -136,7 +134,6 @@ namespace MobileGL {
const Uint m_externalIndex = 0; const Uint m_externalIndex = 0;
const Uint64 m_lifetimeId = AllocateLifetimeId(); const Uint64 m_lifetimeId = AllocateLifetimeId();
mutable SizeT m_pipeVertexInputMemoHint = ~SizeT{0};
Array<VertexAttribute, MAX_VERTEX_ATTRIBS> m_attributes; Array<VertexAttribute, MAX_VERTEX_ATTRIBS> m_attributes;
Array<VertexAttributeVersion, MAX_VERTEX_ATTRIBS> m_attributeVersions; Array<VertexAttributeVersion, MAX_VERTEX_ATTRIBS> m_attributeVersions;
BindingSlot<BufferObject> m_indexBufferBindingSlot; BindingSlot<BufferObject> m_indexBufferBindingSlot;