From 1e057a76b58699bb57da0806671879da113bfca3 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 19 Aug 2014 22:28:26 -0700 Subject: [PATCH] Convert all CLUT entries ever loaded. Some games reuse previously loaded bytes, like World Neverland. We displayed bad colors in these cases when we don't convert all the entries. Technically, this means we're hashing less than used in these cases, but if we hash more we will get lots of false cache misses. Fixes #6752. --- GPU/GLES/TextureCache.cpp | 6 ++++-- GPU/GLES/TextureCache.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 9d97e0d46c..7ca203456c 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -63,7 +63,7 @@ extern int g_iNumVideos; -TextureCache::TextureCache() : clearCacheNextFrame_(false), lowMemoryMode_(false), clutBuf_(NULL), texelsScaledThisFrame_(0) { +TextureCache::TextureCache() : clearCacheNextFrame_(false), lowMemoryMode_(false), clutBuf_(NULL), clutMaxBytes_(0), texelsScaledThisFrame_(0) { timesInvalidatedAllThisFrame_ = 0; lastBoundTexture = -1; decimationCounter_ = TEXCACHE_DECIMATION_INTERVAL; @@ -909,6 +909,7 @@ void TextureCache::LoadClut() { } // Reload the clut next time. clutLastFormat_ = 0xFFFFFFFF; + clutMaxBytes_ = std::max(clutMaxBytes_, clutTotalBytes_); } void TextureCache::UpdateCurrentClut() { @@ -923,7 +924,8 @@ void TextureCache::UpdateCurrentClut() { // Avoid a copy when we don't need to convert colors. if (UseBGRA8888() || clutFormat != GE_CMODE_32BIT_ABGR8888) { - ConvertColors(clutBufConverted_, clutBufRaw_, getClutDestFormat(clutFormat), clutExtendedBytes / sizeof(u16)); + const int numColors = (clutMaxBytes_ + clutBaseBytes) / (clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16)); + ConvertColors(clutBufConverted_, clutBufRaw_, getClutDestFormat(clutFormat), numColors); clutBuf_ = clutBufConverted_; } else { clutBuf_ = clutBufRaw_; diff --git a/GPU/GLES/TextureCache.h b/GPU/GLES/TextureCache.h index 90aa8f3c4f..f92dcc7f13 100644 --- a/GPU/GLES/TextureCache.h +++ b/GPU/GLES/TextureCache.h @@ -226,6 +226,7 @@ private: u32 *clutBuf_; u32 clutHash_; u32 clutTotalBytes_; + u32 clutMaxBytes_; // True if the clut is just alpha values in the same order (RGBA4444-bit only.) bool clutAlphaLinear_; u16 clutAlphaLinearColor_;