From d6d052cd7b0e09bc07883b69ebae60b5fdeace87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 23 Jan 2024 00:04:30 +0100 Subject: [PATCH] Separate out the checks for save vs replace textures more, fixing some issues --- GPU/Common/TextureCacheCommon.cpp | 6 ++--- GPU/Common/TextureReplacer.cpp | 40 +++++++++++++++---------------- GPU/Common/TextureReplacer.h | 8 +++++-- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 4359802e9400..2b57e6a5a899 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1553,7 +1553,7 @@ ReplacedTexture *TextureCacheCommon::FindReplacement(TexCacheEntry *entry, int * // Short circuit the non-enabled case. // Otherwise, due to bReplaceTexturesAllowLate, we'll still spawn tasks looking for replacements // that then won't be used. - if (!replacer_.Enabled()) { + if (!replacer_.ReplaceEnabled()) { return nullptr; } @@ -1562,7 +1562,7 @@ ReplacedTexture *TextureCacheCommon::FindReplacement(TexCacheEntry *entry, int * } double replaceStart = time_now_d(); - u64 cachekey = replacer_.Enabled() ? entry->CacheKey() : 0; + u64 cachekey = entry->CacheKey(); ReplacedTexture *replaced = replacer_.FindReplacement(cachekey, entry->fullhash, *w, *h); replacementTimeThisFrame_ += time_now_d() - replaceStart; if (!replaced) { @@ -2915,7 +2915,7 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt // But, we still need to create the texture at a larger size. plan.replaced->GetSize(0, &plan.createW, &plan.createH); } else { - if (replacer_.Enabled() && !plan.doReplace && plan.depth == 1 && canReplace) { + if (replacer_.SaveEnabled() && !plan.doReplace && plan.depth == 1 && canReplace) { ReplacedTextureDecodeInfo replacedInfo; // TODO: Do we handle the race where a replacement becomes valid AFTER this but before we save? replacedInfo.cachekey = entry->CacheKey(); diff --git a/GPU/Common/TextureReplacer.cpp b/GPU/Common/TextureReplacer.cpp index d85e8372213b..d388aaa80c33 100644 --- a/GPU/Common/TextureReplacer.cpp +++ b/GPU/Common/TextureReplacer.cpp @@ -78,35 +78,36 @@ TextureReplacer::~TextureReplacer() { void TextureReplacer::NotifyConfigChanged() { gameID_ = g_paramSFO.GetDiscID(); - bool wasEnabled = enabled_; - enabled_ = g_Config.bReplaceTextures || g_Config.bSaveNewTextures; - if (enabled_) { + bool wasReplaceEnabled = replaceEnabled_; + replaceEnabled_ = g_Config.bReplaceTextures; + saveEnabled_ = g_Config.bSaveNewTextures; + if (replaceEnabled_ || saveEnabled_) { basePath_ = GetSysDirectory(DIRECTORY_TEXTURES) / gameID_; - + replaceEnabled_ = replaceEnabled_ && File::IsDirectory(basePath_); newTextureDir_ = basePath_ / NEW_TEXTURE_DIR; // If we're saving, auto-create the directory. - if (g_Config.bSaveNewTextures && !File::Exists(newTextureDir_)) { + if (saveEnabled_ && !File::Exists(newTextureDir_)) { File::CreateFullPath(newTextureDir_); File::CreateEmptyFile(newTextureDir_ / ".nomedia"); } + } - enabled_ = File::IsDirectory(basePath_); + if (saveEnabled_) { + // Somewhat crude message, re-using translation strings. + auto d = GetI18NCategory(I18NCat::DEVELOPER); + auto di = GetI18NCategory(I18NCat::DIALOG); + g_OSD.Show(OSDType::MESSAGE_INFO, std::string(d->T("Save new textures")) + ": " + di->T("Enabled"), 2.0f); + } - if (g_Config.bSaveNewTextures) { - // Somewhat crude message, re-using translation strings. - auto d = GetI18NCategory(I18NCat::DEVELOPER); - auto di = GetI18NCategory(I18NCat::DIALOG); - g_OSD.Show(OSDType::MESSAGE_INFO, std::string(d->T("Save new textures")) + ": " + di->T("Enabled"), 2.0f); - } - } else if (wasEnabled) { + if (!replaceEnabled_ && wasReplaceEnabled) { delete vfs_; vfs_ = nullptr; Decimate(ReplacerDecimateMode::ALL); } - if (enabled_) { - enabled_ = LoadIni(); + if (replaceEnabled_) { + replaceEnabled_ = LoadIni(); } } @@ -313,7 +314,7 @@ bool TextureReplacer::LoadIniValues(IniFile &ini, VFSBackend *dir, bool isOverri if (ini.HasSection("hashes")) { auto hashes = ini.GetOrCreateSection("hashes")->ToMap(); // Format: hashname = filename.png - bool checkFilenames = g_Config.bSaveNewTextures && !g_Config.bIgnoreTextureFilenames && !vfsIsZip_; + bool checkFilenames = saveEnabled_ && !g_Config.bIgnoreTextureFilenames && !vfsIsZip_; for (const auto &item : hashes) { ReplacementCacheKey key(0, 0); @@ -477,7 +478,7 @@ void TextureReplacer::ParseReduceHashRange(const std::string& key, const std::st } u32 TextureReplacer::ComputeHash(u32 addr, int bufw, int w, int h, bool swizzled, GETextureFormat fmt, u16 maxSeenV) { - _dbg_assert_msg_(enabled_, "Replacement not enabled"); + _dbg_assert_msg_(replaceEnabled_ || saveEnabled_, "Replacement not enabled"); // TODO: Take swizzled into account, like in QuickTexHash(). // Note: Currently, only the MLB games are known to need this. @@ -721,8 +722,7 @@ class SaveTextureTask : public Task { }; bool TextureReplacer::WillSave(const ReplacedTextureDecodeInfo &replacedInfo) { - _assert_msg_(enabled_, "Replacement not enabled"); - if (!g_Config.bSaveNewTextures) + if (!saveEnabled_) return false; // Don't save the PPGe texture. if (replacedInfo.addr > 0x05000000 && replacedInfo.addr < PSP_GetKernelMemoryEnd()) @@ -734,7 +734,7 @@ bool TextureReplacer::WillSave(const ReplacedTextureDecodeInfo &replacedInfo) { } void TextureReplacer::NotifyTextureDecoded(ReplacedTexture *texture, const ReplacedTextureDecodeInfo &replacedInfo, const void *data, int pitch, int level, int origW, int origH, int scaledW, int scaledH) { - _assert_msg_(enabled_, "Replacement not enabled"); + _assert_msg_(saveEnabled_, "Texture saving not enabled"); _assert_(pitch >= 0); if (!WillSave(replacedInfo)) { diff --git a/GPU/Common/TextureReplacer.h b/GPU/Common/TextureReplacer.h index 7cc192319fcb..53b92dfcfbae 100644 --- a/GPU/Common/TextureReplacer.h +++ b/GPU/Common/TextureReplacer.h @@ -100,7 +100,10 @@ class TextureReplacer { void NotifyConfigChanged(); - bool Enabled() const { return enabled_; } + bool Enabled() const { return replaceEnabled_ || saveEnabled_; } // used to check hashing method etc. + bool ReplaceEnabled() const { return replaceEnabled_; } + bool SaveEnabled() const { return saveEnabled_; } + bool AllowVideo() const { return allowVideo_; } u32 ComputeHash(u32 addr, int bufw, int w, int h, bool swizzled, GETextureFormat fmt, u16 maxSeenV); @@ -140,7 +143,8 @@ class TextureReplacer { void ScanForHashNamedFiles(VFSBackend *dir, std::map> &filenameMap); void ComputeAliasMap(const std::map> &filenameMap); - bool enabled_ = false; + bool replaceEnabled_ = false; + bool saveEnabled_ = false; bool allowVideo_ = false; bool ignoreAddress_ = false; bool reduceHash_ = false;