From 2d64481e71af7c9b3b891df45c24e70e7523891b Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sun, 7 Jun 2026 23:41:44 -0600 Subject: [PATCH] Evict dynamic palette textures in evict_copy_texture --- lib/gx/gx.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/gx/gx.cpp b/lib/gx/gx.cpp index 4cd9b4d..9ca9036 100644 --- a/lib/gx/gx.cpp +++ b/lib/gx/gx.cpp @@ -401,14 +401,38 @@ void clear_copy_texture_cache() noexcept { void clear_static_texture_cache() noexcept { s_staticTextureCacheClearPending.store(true, std::memory_order_release); } void evict_copy_texture(const void* dest) noexcept { - g_gxState.copyTextures.erase(dest); + absl::flat_hash_set sourceIdentities; + if (const auto it = g_gxState.copyTextures.find(dest); it != g_gxState.copyTextures.end()) { + if (it->second.handle) { + sourceIdentities.insert(it->second.handle.get()); + } + g_gxState.copyTextures.erase(it); + } + for (auto it = g_gxState.copyTextureCache.begin(); it != g_gxState.copyTextureCache.end();) { if (it->first.dest == dest) { + if (it->second.handle) { + sourceIdentities.insert(it->second.handle.get()); + } g_gxState.copyTextureCache.erase(it++); } else { ++it; } } + + if (sourceIdentities.empty()) { + return; + } + + for (auto& [_, cache] : s_tlutObjectCaches) { + for (auto it = cache.dynamicPaletteTextures.begin(); it != cache.dynamicPaletteTextures.end();) { + if (sourceIdentities.contains(it->first.sourceIdentity)) { + cache.dynamicPaletteTextures.erase(it++); + } else { + ++it; + } + } + } } void resolve_sampled_textures(const ShaderInfo& info) noexcept {