From 61d2459e94ec80f7c0f8050f8ce622981e4a4128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 10 Dec 2024 16:07:54 +0100 Subject: [PATCH 1/2] Minor code cleanup --- GPU/Common/TextureReplacer.cpp | 3 +++ GPU/Common/TextureReplacer.h | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/GPU/Common/TextureReplacer.cpp b/GPU/Common/TextureReplacer.cpp index 6842e2490d40..8c3043b8fb2a 100644 --- a/GPU/Common/TextureReplacer.cpp +++ b/GPU/Common/TextureReplacer.cpp @@ -506,10 +506,13 @@ u32 TextureReplacer::ComputeHash(u32 addr, int bufw, int w, int h, bool swizzled } const u8 *checkp = Memory::GetPointerUnchecked(addr); + + float reduceHashSize = 1.0f; if (reduceHash_) { reduceHashSize = LookupReduceHashRange(w, h); // default to reduceHashGlobalValue which default is 0.5 } + if (bufw <= w) { // We can assume the data is contiguous. These are the total used pixels. const u32 totalPixels = bufw * h + (w - bufw); diff --git a/GPU/Common/TextureReplacer.h b/GPU/Common/TextureReplacer.h index d71c36b09c7c..9762bcd8295d 100644 --- a/GPU/Common/TextureReplacer.h +++ b/GPU/Common/TextureReplacer.h @@ -150,7 +150,6 @@ class TextureReplacer { bool reduceHash_ = false; bool ignoreMipmap_ = false; - float reduceHashSize = 1.0f; // default value with reduceHash to false float reduceHashGlobalValue = 0.5f; // Global value for textures dump pngs of all sizes, 0.5 by default but can be set in textures.ini double lastTextureCacheSizeGB_ = 0.0; From ec19c47b89e358659a2aee2cf1ce031585e93579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 10 Dec 2024 16:21:45 +0100 Subject: [PATCH 2/2] Add special texture hashing mode solving the Tag Force problem. Don't want to build some complicated rule-based thing until we have more use cases, so this is quite specialized. See #19714 --- GPU/Common/TextureReplacer.cpp | 9 ++++++++- GPU/Common/TextureReplacer.h | 1 + GPU/Vulkan/TextureCacheVulkan.cpp | 2 -- UI/GameSettingsScreen.cpp | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/GPU/Common/TextureReplacer.cpp b/GPU/Common/TextureReplacer.cpp index 8c3043b8fb2a..aa2ecc022ad0 100644 --- a/GPU/Common/TextureReplacer.cpp +++ b/GPU/Common/TextureReplacer.cpp @@ -301,6 +301,7 @@ bool TextureReplacer::LoadIniValues(IniFile &ini, VFSBackend *dir, bool isOverri // Multiplies sizeInRAM/bytesPerLine in XXHASH by 0.5. options->Get("reduceHash", &reduceHash_, reduceHash_); options->Get("ignoreMipmap", &ignoreMipmap_, ignoreMipmap_); + options->Get("skipLastDXT1Blocks128x64", &skipLastDXT1Blocks128x64_, skipLastDXT1Blocks128x64_); if (reduceHash_ && hash_ == ReplacedTextureHash::QUICK) { reduceHash_ = false; ERROR_LOG(Log::TexReplacement, "Texture Replacement: reduceHash option requires safer hash, use xxh32 or xxh64 instead."); @@ -516,7 +517,7 @@ u32 TextureReplacer::ComputeHash(u32 addr, int bufw, int w, int h, bool swizzled if (bufw <= w) { // We can assume the data is contiguous. These are the total used pixels. const u32 totalPixels = bufw * h + (w - bufw); - const u32 sizeInRAM = (textureBitsPerPixel[fmt] * totalPixels) / 8 * reduceHashSize; + u32 sizeInRAM = (textureBitsPerPixel[fmt] * totalPixels) / 8 * reduceHashSize; // Sanity check: Ignore textures that are at the end of RAM. if (Memory::MaxSizeAtAddress(addr) < sizeInRAM) { @@ -524,6 +525,12 @@ u32 TextureReplacer::ComputeHash(u32 addr, int bufw, int w, int h, bool swizzled return 0; } + // Hack for Yu Gi Oh texture hashing problem. See issue #19714 + if (skipLastDXT1Blocks128x64_ && fmt == GE_TFMT_DXT1 && w == 128 && h == 64) { + // Skip the last few blocks as specified. + sizeInRAM -= 8 * skipLastDXT1Blocks128x64_; + } + switch (hash_) { case ReplacedTextureHash::QUICK: return StableQuickTexHash(checkp, sizeInRAM); diff --git a/GPU/Common/TextureReplacer.h b/GPU/Common/TextureReplacer.h index 9762bcd8295d..ea70bc09ea0b 100644 --- a/GPU/Common/TextureReplacer.h +++ b/GPU/Common/TextureReplacer.h @@ -149,6 +149,7 @@ class TextureReplacer { bool ignoreAddress_ = false; bool reduceHash_ = false; bool ignoreMipmap_ = false; + int skipLastDXT1Blocks128x64_ = 0; float reduceHashGlobalValue = 0.5f; // Global value for textures dump pngs of all sizes, 0.5 by default but can be set in textures.ini diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 9449ed5190af..1520358cadaf 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -652,8 +652,6 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { } // Format might be wrong in lowMemoryMode_, so don't save. if (plan.saveTexture && !lowMemoryMode_) { - INFO_LOG(Log::G3D, "Calling NotifyTextureDecoded %08x", entry->addr); - // When hardware texture scaling is enabled, this saves the original. int w = dataScaled ? mipWidth : mipUnscaledWidth; int h = dataScaled ? mipHeight : mipUnscaledHeight; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 428301a83d0a..68772aeb3807 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -2089,6 +2089,7 @@ UI::EventReturn DeveloperToolsScreen::OnLoggingChanged(UI::EventParams &e) { } UI::EventReturn DeveloperToolsScreen::OnRunCPUTests(UI::EventParams &e) { + // TODO: If game is loaded, don't do anything. #if !PPSSPP_PLATFORM(UWP) RunTests(); #endif