From e78eee972e47ede41c7e4f507f24fa7715a191b9 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Mon, 13 Jul 2026 06:53:37 -0400 Subject: [PATCH] [Perf] (MG_Backend/DirectVulkan): store the resolved TextureResource pointer in the per-draw sync memo so repeat SyncTextureAndGetDescriptor calls skip the resource-map lookup --- .../DirectVulkan/Renderer/VkTextureManager.cpp | 15 +++++++-------- .../DirectVulkan/Renderer/VkTextureManager.h | 10 +++++++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp index ae32c964..764a14cc 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp @@ -705,11 +705,10 @@ namespace MobileGL::MG_Backend::DirectVulkan { // transition path, so the short-circuited resource still reflects the truth. const Bool memoActive = m_drawSyncScopeActive; if (memoActive) { - for (const TextureIdentity& synced : m_drawSyncedThisDraw) { - if (synced == identity) { - auto cachedIt = m_textureResources.find(identity); - if (cachedIt != m_textureResources.end() && cachedIt->second.image != VK_NULL_HANDLE) { - return &(cachedIt->second); + for (const DrawSyncedTexture& synced : m_drawSyncedThisDraw) { + if (synced.identity == identity) { + if (synced.resource != nullptr && synced.resource->image != VK_NULL_HANDLE) { + return synced.resource; } break; // resource unexpectedly gone -> fall through to a full sync } @@ -748,14 +747,14 @@ namespace MobileGL::MG_Backend::DirectVulkan { if (memoActive) { Bool recorded = false; - for (const TextureIdentity& synced : m_drawSyncedThisDraw) { - if (synced == identity) { + for (const DrawSyncedTexture& synced : m_drawSyncedThisDraw) { + if (synced.identity == identity) { recorded = true; break; } } if (!recorded) { - m_drawSyncedThisDraw.push_back(identity); + m_drawSyncedThisDraw.push_back({identity, &(it->second)}); } } diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.h b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.h index 7cb8fa0c..e2683936 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.h +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.h @@ -287,7 +287,15 @@ private: // Active only between BeginDrawSyncScope/EndDrawSyncScope; identities of // textures already fully synced in the current draw (small N -> flat scan). Bool m_drawSyncScopeActive = false; - Vector m_drawSyncedThisDraw; + // Per-draw sync memo: the identity plus the resolved resource pointer. The pointer is stable + // across rehash in the node-based m_textureResources and stays valid for the draw (a texture + // synced this draw is alive and is not erased mid-draw), so a repeat sync of the same texture + // returns the resource without re-hashing the identity into m_textureResources. + struct DrawSyncedTexture { + TextureIdentity identity; + TextureResource* resource = nullptr; + }; + Vector m_drawSyncedThisDraw; std::unordered_map, TextureIdentityHash> m_aliveObjects; std::unordered_map m_textureResources; Vector> m_deferredReleases;