Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture replacer: Make the internal cache model texture-centric instead of miplevel-centric #17078

Merged
merged 6 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't reuse the ReplacedTexture struct in "saved cache".
  • Loading branch information
hrydgard committed Mar 8, 2023
commit 4752e20ad42dff8afd2015a7a74fca42da680943
18 changes: 8 additions & 10 deletions Core/TextureReplacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,6 @@ void TextureReplacer::NotifyTextureDecoded(const ReplacedTextureDecodeInfo &repl
cachekey = cachekey & 0xFFFFFFFFULL;
}

/*
bool found = false;
std::string hashfile = LookupHashFile(cachekey, replacedInfo.hash, &found);
const Path filename = basePath_ / hashfile;
Expand All @@ -753,9 +752,10 @@ void TextureReplacer::NotifyTextureDecoded(const ReplacedTextureDecodeInfo &repl
double now = time_now_d();
if (it != savedCache_.end()) {
// We've already saved this texture. Let's only save if it's bigger (e.g. scaled now.)
if (it->second.first.w >= w && it->second.first.h >= h) {
// TODO: Isn't this check backwards?
if (it->second.levelW[level] >= w && it->second.levelH[level] >= h) {
// If it's been more than 5 seconds, we'll check again. Maybe they deleted.
double age = now - it->second.second;
double age = now - it->second.lastTimeSaved;
if (age < 5.0)
return;

Expand Down Expand Up @@ -794,13 +794,11 @@ void TextureReplacer::NotifyTextureDecoded(const ReplacedTextureDecodeInfo &repl

// Remember that we've saved this for next time.
// Should be OK that the actual disk write may not be finished yet.
ReplacedTextureLevel saved;
saved.fmt = Draw::DataFormat::R8G8B8A8_UNORM;
saved.file = filename;
saved.w = w;
saved.h = h;
savedCache_[replacementKey] = std::make_pair(saved, now);
*/
SavedTextureCacheData &saveData = savedCache_[replacementKey];
saveData.levelW[level] = w;
saveData.levelH[level] = h;
saveData.levelSaved[level] = true;
saveData.lastTimeSaved = now;
}

void TextureReplacer::Decimate(ReplacerDecimateMode mode) {
Expand Down
9 changes: 8 additions & 1 deletion Core/TextureReplacer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ struct ReplacedTextureLevel {
VFSFileReference *fileRef = nullptr;
};

struct SavedTextureCacheData {
int levelW[8]{};
int levelH[8]{};
bool levelSaved[8]{};
double lastTimeSaved;
};

struct ReplacedLevelsCache {
std::mutex lock;
std::vector<std::vector<uint8_t>> data;
Expand Down Expand Up @@ -252,7 +259,7 @@ class TextureReplacer {
std::unordered_map<ReplacementCacheKey, TextureFiltering> filtering_;

std::unordered_map<ReplacementCacheKey, ReplacedTexture *> cache_;
std::unordered_map<ReplacementCacheKey, std::pair<ReplacedTextureLevel, double>> savedCache_;
std::unordered_map<ReplacementCacheKey, SavedTextureCacheData> savedCache_;

// the key is from aliases_. It's a |-separated sequence of texture filenames of the levels of a texture.
std::unordered_map<std::string, ReplacedLevelsCache> levelCache_;
Expand Down