From efc09a7b47d0261f33d1d6f83e8b69307fbb60a9 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 23 Jun 2022 22:18:55 +1000 Subject: [PATCH] GS/TextureCache: Unswizzle shared texture formats when hashing Fixes formats such as PSMT4HL giving different hashes depending on what the overlapping/shared pixels in local memory contain. Enable this unconditionally, rather than only when dumping, because unswizzling and hashing is around 25% faster on AVX2 builds than hashing the backing local memory for larger textures (e.g. Star Ocean 3 menus). Also has the added bonus of hitting the cache more often in such cases too. --- pcsx2/GS/Renderers/HW/GSTextureCache.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp index dfbad2ba3d..683deb02d9 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp @@ -2936,7 +2936,12 @@ static void HashTextureLevel(const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, Blo // For textures which are smaller than the block size, we expand and then hash. // This is because otherwise we get the padding bytes, which can be random junk. - if (tw < bs.x || th < bs.y) + // We also expand formats where the bits contributing to the texture do not cover + // all the 32 bits, as otherwise we'll get differing hash values if game overlap + // the texture data with other textures/framebuffers/etc (which is common). + // Even though you might think this would be slower than just hashing for the hash + // cache, it actually ends up faster (unswizzling is faster than hashing). + if (tw < bs.x || th < bs.y || psm.fmsk != 0xFFFFFFFFu) { // Expand texture indices. Align to 32 bytes for AVX2. const u32 pitch = Common::AlignUpPow2(static_cast(block_rect.w), 32);