Replacement: Purge old cached decoded textures.

Not actually decoding into the cache, just setup.
This commit is contained in:
Unknown W. Brackets committed 2021-10-21 17:05:38 -07:00
1 parent 2356280a9c
commit 36fc2c2628
3 files changed
+45 -1

No files matched your search

+37 -1
View File
@@ -31,6 +31,7 @@
#include "Common/File/FileUtil.h"
#include "Common/StringUtils.h"
#include "Common/Thread/ParallelLoop.h"
#include "Common/TimeUtil.h"
#include "Core/Config.h"
#include "Core/Host.h"
#include "Core/System.h"
@@ -621,6 +622,15 @@ void TextureReplacer::NotifyTextureDecoded(const ReplacedTextureDecodeInfo &repl
savedCache_[replacementKey] = saved;
}
void TextureReplacer::Decimate(bool forcePressure) {
// Allow replacements to be cached for a long time, although they're large.
const double age = forcePressure ? 90.0 : 1800.0;
const double threshold = time_now_d() - age;
for (auto &item : cache_) {
item.second.PurgeIfOlder(threshold);
}
}
template <typename Key, typename Value>
static typename std::unordered_map<Key, Value>::const_iterator LookupWildcard(const std::unordered_map<Key, Value> &map, Key &key, u64 cachekey, u32 hash, bool ignoreAddress) {
auto alias = map.find(key);
@@ -734,7 +744,33 @@ float TextureReplacer::LookupReduceHashRange(int& w, int& h) {
}
bool ReplacedTexture::IsReady(double budget) {
return true;
lastUsed_ = time_now_d();
if (levelData_.size() == levels_.size())
return true;
if (budget <= 0.0)
return false;
double deadline = lastUsed_ + budget;
for (int i = (int)levelData_.size(); i <= MaxLevel(); ++i) {
levelData_.resize(i + 1);
PrepareData(i);
if (time_now_d() >= deadline) {
break;
}
}
// If we finished all the levels, we're done.
return levelData_.size() == levels_.size();
}
void ReplacedTexture::PrepareData(int level) {
// TODO
}
void ReplacedTexture::PurgeIfOlder(double t) {
if (lastUsed_ < t) {
levelData_.clear();
}
}
bool ReplacedTexture::Load(int level, void *out, int rowPitch) {
+7
View File
@@ -158,8 +158,13 @@ struct ReplacedTexture {
bool Load(int level, void *out, int rowPitch);
protected:
void PrepareData(int level);
void PurgeIfOlder(double t);
std::vector<ReplacedTextureLevel> levels_;
std::vector<std::vector<uint8_t>> levelData_;
ReplacedTextureAlpha alphaStatus_;
double lastUsed_ = 0.0;
friend TextureReplacer;
};
@@ -193,6 +198,8 @@ public:
void NotifyTextureDecoded(const ReplacedTextureDecodeInfo &replacedInfo, const void *data, int pitch, int level, int w, int h);
void Decimate(bool forcePressure);
static bool GenerateIni(const std::string &gameID, Path &generatedFilename);
protected:
+1
View File
@@ -724,6 +724,7 @@ void TextureCacheCommon::Decimate(bool forcePressure) {
}
DecimateVideos();
replacer_.Decimate(forcePressure);
}
void TextureCacheCommon::DecimateVideos() {