From d61fd5f6a6cab1901a48a57a50a49e2956f66b96 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 18 Feb 2018 12:26:00 -0800 Subject: [PATCH 1/2] TexCache: Decimate CLUT variants more often. When creating a new texture, we determine if it has CLUT variants and decimate more often. --- GPU/Common/TextureCacheCommon.cpp | 22 +++++++++++++++++++++- GPU/Common/TextureCacheCommon.h | 3 +-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 75f9a5d14c..062cbf9224 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -46,6 +46,8 @@ #define TEXTURE_KILL_AGE_LOWMEM 60 // Not used in lowmem mode. #define TEXTURE_SECOND_KILL_AGE 100 +// Used when there are multiple CLUT variants of a texture. +#define TEXTURE_KILL_AGE_CLUT 12 // Try to be prime to other decimation intervals. #define TEXCACHE_DECIMATION_INTERVAL 13 @@ -454,6 +456,22 @@ void TextureCacheCommon::SetTexture(bool force) { entry->status = TexCacheEntry::STATUS_UNRELIABLE; } + if (hasClut && clutRenderAddress_ == 0xFFFFFFFF) { + const u64 cachekeyMin = (u64)(texaddr & 0x3FFFFFFF) << 32; + const u64 cachekeyMax = cachekeyMin + (1ULL << 32); + bool found = false; + for (auto it = cache_.lower_bound(cachekeyMin), end = cache_.upper_bound(cachekeyMax); it != end; ++it) { + if (it->second->cluthash != entry->cluthash) { + it->second->status |= TexCacheEntry::STATUS_CLUT_VARIANTS; + found = true; + } + } + + if (found) { + entry->status |= TexCacheEntry::STATUS_CLUT_VARIANTS; + } + } + nextNeedsChange_ = false; } @@ -505,8 +523,10 @@ void TextureCacheCommon::Decimate() { const u32 had = cacheSizeEstimate_; ForgetLastTexture(); - int killAge = lowMemoryMode_ ? TEXTURE_KILL_AGE_LOWMEM : TEXTURE_KILL_AGE; + int killAgeBase = lowMemoryMode_ ? TEXTURE_KILL_AGE_LOWMEM : TEXTURE_KILL_AGE; for (TexCache::iterator iter = cache_.begin(); iter != cache_.end(); ) { + bool hasClut = (iter->second->status & TexCacheEntry::STATUS_CLUT_VARIANTS) != 0; + int killAge = hasClut ? TEXTURE_KILL_AGE_CLUT : killAgeBase; if (iter->second->lastFrame + killAge < gpuStats.numFlips) { DeleteTexture(iter++); } else { diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 1bc16a2541..0c3e626545 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -108,8 +108,7 @@ struct TexCacheEntry { STATUS_ALPHA_FULL = 0x00, // Has no alpha channel, or always full alpha. STATUS_ALPHA_MASK = 0x04, - // 0x08 free. - + STATUS_CLUT_VARIANTS = 0x08, // Has multiple CLUT variants. STATUS_CHANGE_FREQUENT = 0x10, // Changes often (less than 6 frames in between.) STATUS_CLUT_RECHECK = 0x20, // Another texture with same addr had a hashfail. STATUS_DEPALETTIZE = 0x40, // Needs to go through a depalettize pass. From e97046da4e9c057af46849e7c9c34113aabaf944 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 18 Feb 2018 12:29:14 -0800 Subject: [PATCH 2/2] TexCache: Decimate aggressively with many variants. It should be safe to decimate after fewer frames with a threshold like this. --- GPU/Common/TextureCacheCommon.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 062cbf9224..51703e3ecd 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -47,7 +47,9 @@ // Not used in lowmem mode. #define TEXTURE_SECOND_KILL_AGE 100 // Used when there are multiple CLUT variants of a texture. -#define TEXTURE_KILL_AGE_CLUT 12 +#define TEXTURE_KILL_AGE_CLUT 6 + +#define TEXTURE_CLUT_VARIANTS_MIN 6 // Try to be prime to other decimation intervals. #define TEXCACHE_DECIMATION_INTERVAL 13 @@ -459,15 +461,17 @@ void TextureCacheCommon::SetTexture(bool force) { if (hasClut && clutRenderAddress_ == 0xFFFFFFFF) { const u64 cachekeyMin = (u64)(texaddr & 0x3FFFFFFF) << 32; const u64 cachekeyMax = cachekeyMin + (1ULL << 32); - bool found = false; + + int found = 0; for (auto it = cache_.lower_bound(cachekeyMin), end = cache_.upper_bound(cachekeyMax); it != end; ++it) { - if (it->second->cluthash != entry->cluthash) { - it->second->status |= TexCacheEntry::STATUS_CLUT_VARIANTS; - found = true; - } + found++; } - if (found) { + if (found >= TEXTURE_CLUT_VARIANTS_MIN) { + for (auto it = cache_.lower_bound(cachekeyMin), end = cache_.upper_bound(cachekeyMax); it != end; ++it) { + it->second->status |= TexCacheEntry::STATUS_CLUT_VARIANTS; + } + entry->status |= TexCacheEntry::STATUS_CLUT_VARIANTS; } }