diff --git a/Core/Config.cpp b/Core/Config.cpp index 2afcf76cf5..8143123e88 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -887,6 +887,7 @@ static ConfigSetting graphicsSettings[] = { ReportedConfigSetting("ReplaceTextures", &g_Config.bReplaceTextures, true, true, true), ReportedConfigSetting("SaveNewTextures", &g_Config.bSaveNewTextures, false, true, true), ConfigSetting("IgnoreTextureFilenames", &g_Config.bIgnoreTextureFilenames, false, true, true), + ConfigSetting("ReplaceTexturesAllowLate", &g_Config.bReplaceTexturesAllowLate, true, true, true), ReportedConfigSetting("TexScalingLevel", &g_Config.iTexScalingLevel, 1, true, true), ReportedConfigSetting("TexScalingType", &g_Config.iTexScalingType, 0, true, true), diff --git a/Core/Config.h b/Core/Config.h index b6bf7f062e..7ded5c9aa0 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -197,6 +197,7 @@ public: bool bReplaceTextures; bool bSaveNewTextures; bool bIgnoreTextureFilenames; + bool bReplaceTexturesAllowLate; int iTexScalingLevel; // 0 = auto, 1 = off, 2 = 2x, ..., 5 = 5x int iTexScalingType; // 0 = xBRZ, 1 = Hybrid bool bTexDeposterize; diff --git a/Core/TextureReplacer.cpp b/Core/TextureReplacer.cpp index 251f97841e..ab5c7697e4 100644 --- a/Core/TextureReplacer.cpp +++ b/Core/TextureReplacer.cpp @@ -783,12 +783,7 @@ public: } void Run() override { - tex_.levelData_.resize(tex_.MaxLevel() + 1); - for (int i = 0; i <= tex_.MaxLevel(); ++i) { - if (tex_.cancelPrepare_) - break; - tex_.PrepareData(i); - } + tex_.Prepare(); waitable_->Notify(); } @@ -814,22 +809,36 @@ bool ReplacedTexture::IsReady(double budget) { if (budget <= 0.0) return false; - threadWaitable_ = new LimitedWaitable(); - g_threadManager.EnqueueTask(new ReplacedTextureTask(*this, threadWaitable_), TaskType::IO_BLOCKING); + if (g_Config.bReplaceTexturesAllowLate) { + threadWaitable_ = new LimitedWaitable(); + g_threadManager.EnqueueTask(new ReplacedTextureTask(*this, threadWaitable_), TaskType::IO_BLOCKING); - uint32_t budget_us = (uint32_t)(budget * 1000000.0); - if (threadWaitable_->WaitFor(budget_us)) { - threadWaitable_->WaitAndRelease(); - threadWaitable_ = nullptr; + uint32_t budget_us = (uint32_t)(budget * 1000000.0); + if (threadWaitable_->WaitFor(budget_us)) { + threadWaitable_->WaitAndRelease(); + threadWaitable_ = nullptr; - // If we finished all the levels, we're done. - return !levelData_.empty(); + // If we finished all the levels, we're done. + return !levelData_.empty(); + } + } else { + Prepare(); + return true; } // Still pending on thread. return false; } +void ReplacedTexture::Prepare() { + levelData_.resize(MaxLevel() + 1); + for (int i = 0; i <= MaxLevel(); ++i) { + if (cancelPrepare_) + break; + PrepareData(i); + } +} + void ReplacedTexture::PrepareData(int level) { _assert_msg_((size_t)level < levels_.size(), "Invalid miplevel"); diff --git a/Core/TextureReplacer.h b/Core/TextureReplacer.h index 9b9551396c..6deefe8daf 100644 --- a/Core/TextureReplacer.h +++ b/Core/TextureReplacer.h @@ -162,6 +162,7 @@ struct ReplacedTexture { bool Load(int level, void *out, int rowPitch); protected: + void Prepare(); void PrepareData(int level); void PurgeIfOlder(double t);