mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Replace "none_" with nullptr.
This commit is contained in:
parent
81351056f4
commit
226197f30f
@ -87,12 +87,13 @@ static ReplacedImageType Identify(VFSBackend *vfs, VFSOpenFile *openFile, std::s
|
||||
return IdentifyMagic(magic);
|
||||
}
|
||||
|
||||
TextureReplacer::TextureReplacer() {
|
||||
none_.initDone_ = true;
|
||||
none_.prepareDone_ = true;
|
||||
}
|
||||
TextureReplacer::TextureReplacer() {}
|
||||
|
||||
TextureReplacer::~TextureReplacer() {
|
||||
for (auto &iter : cache_) {
|
||||
delete iter.second;
|
||||
}
|
||||
|
||||
delete vfs_;
|
||||
}
|
||||
|
||||
@ -206,7 +207,6 @@ bool TextureReplacer::LoadIniValues(IniFile &ini, bool isOverride) {
|
||||
auto options = ini.GetOrCreateSection("options");
|
||||
std::string hash;
|
||||
options->Get("hash", &hash, "");
|
||||
// TODO: crc32c.
|
||||
if (strcasecmp(hash.c_str(), "quick") == 0) {
|
||||
hash_ = ReplacedTextureHash::QUICK;
|
||||
} else if (strcasecmp(hash.c_str(), "xxh32") == 0) {
|
||||
@ -448,27 +448,29 @@ u32 TextureReplacer::ComputeHash(u32 addr, int bufw, int w, int h, GETextureForm
|
||||
}
|
||||
}
|
||||
|
||||
ReplacedTexture &TextureReplacer::FindReplacement(u64 cachekey, u32 hash, int w, int h, double budget) {
|
||||
ReplacedTexture *TextureReplacer::FindReplacement(u64 cachekey, u32 hash, int w, int h, double budget) {
|
||||
// Only actually replace if we're replacing. We might just be saving.
|
||||
if (!Enabled() || !g_Config.bReplaceTextures) {
|
||||
return none_;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ReplacementCacheKey replacementKey(cachekey, hash);
|
||||
auto it = cache_.find(replacementKey);
|
||||
if (it != cache_.end()) {
|
||||
if (!it->second.prepareDone_ && budget > 0.0) {
|
||||
if (!it->second->prepareDone_ && budget > 0.0) {
|
||||
// We don't do this on a thread, but we only do it while within budget.
|
||||
PopulateReplacement(&it->second, cachekey, hash, w, h);
|
||||
PopulateReplacement(it->second, cachekey, hash, w, h);
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
// Okay, let's construct the result.
|
||||
ReplacedTexture &result = cache_[replacementKey];
|
||||
result.vfs_ = this->vfs_;
|
||||
|
||||
ReplacedTexture *result = new ReplacedTexture();
|
||||
cache_[replacementKey] = result;
|
||||
result->vfs_ = this->vfs_;
|
||||
if (!g_Config.bReplaceTexturesAllowLate || budget > 0.0) {
|
||||
PopulateReplacement(&result, cachekey, hash, w, h);
|
||||
PopulateReplacement(result, cachekey, hash, w, h);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -531,7 +533,7 @@ void TextureReplacer::PopulateReplacement(ReplacedTexture *result, u64 cachekey,
|
||||
for (size_t i = 0; i < result->levels_.size(); ++i) {
|
||||
result->levelData_[i] = &levelCache_[result->levels_[i]];
|
||||
}
|
||||
|
||||
|
||||
result->prepareDone_ = true;
|
||||
}
|
||||
|
||||
@ -776,7 +778,8 @@ void TextureReplacer::Decimate(ReplacerDecimateMode mode) {
|
||||
|
||||
const double threshold = time_now_d() - age;
|
||||
for (auto &item : cache_) {
|
||||
item.second.PurgeIfOlder(threshold);
|
||||
item.second->PurgeIfOlder(threshold);
|
||||
// don't actually delete the items here, just clean out the data.
|
||||
}
|
||||
|
||||
size_t totalSize = 0;
|
||||
|
@ -54,13 +54,14 @@ enum class ReplacedTextureHash {
|
||||
};
|
||||
|
||||
struct ReplacedTextureLevel {
|
||||
int w;
|
||||
int h;
|
||||
Draw::DataFormat fmt; // NOTE: Right now, the only supported format is Draw::DataFormat::R8G8B8A8_UNORM.
|
||||
ReplacedTextureLevel() {}
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
Draw::DataFormat fmt = Draw::DataFormat::UNDEFINED; // NOTE: Right now, the only supported format is Draw::DataFormat::R8G8B8A8_UNORM.
|
||||
Path file;
|
||||
// Can be ignored for hashing/equal, since file has all uniqueness.
|
||||
// To be able to reload, we need to be able to reopen, unfortunate we can't use zip_file_t.
|
||||
VFSFileReference *fileRef;
|
||||
VFSFileReference *fileRef = nullptr;
|
||||
bool operator ==(const ReplacedTextureLevel &other) const {
|
||||
if (w != other.w || h != other.h || fmt != other.fmt)
|
||||
return false;
|
||||
@ -249,11 +250,9 @@ public:
|
||||
|
||||
u32 ComputeHash(u32 addr, int bufw, int w, int h, GETextureFormat fmt, u16 maxSeenV);
|
||||
|
||||
ReplacedTexture &FindReplacement(u64 cachekey, u32 hash, int w, int h, double budget);
|
||||
// Returns nullptr if not found.
|
||||
ReplacedTexture *FindReplacement(u64 cachekey, u32 hash, int w, int h, double budget);
|
||||
bool FindFiltering(u64 cachekey, u32 hash, TextureFiltering *forceFiltering);
|
||||
ReplacedTexture &FindNone() {
|
||||
return none_;
|
||||
}
|
||||
|
||||
// Check if a NotifyTextureDecoded for this texture is desired (used to avoid reads from write-combined memory.)
|
||||
bool WillSave(const ReplacedTextureDecodeInfo &replacedInfo);
|
||||
@ -301,8 +300,7 @@ protected:
|
||||
std::unordered_map<ReplacementAliasKey, std::string> aliases_;
|
||||
std::unordered_map<ReplacementCacheKey, TextureFiltering> filtering_;
|
||||
|
||||
ReplacedTexture none_;
|
||||
std::unordered_map<ReplacementCacheKey, ReplacedTexture> cache_;
|
||||
std::unordered_map<ReplacementCacheKey, ReplacedTexture *> cache_;
|
||||
std::unordered_map<ReplacementCacheKey, std::pair<ReplacedTextureLevel, double>> savedCache_;
|
||||
std::unordered_map<ReplacedTextureLevel, ReplacedLevelCache> levelCache_;
|
||||
};
|
||||
|
@ -528,8 +528,8 @@ TexCacheEntry *TextureCacheCommon::SetTexture() {
|
||||
int w0 = gstate.getTextureWidth(0);
|
||||
int h0 = gstate.getTextureHeight(0);
|
||||
int d0 = 1;
|
||||
ReplacedTexture &replaced = FindReplacement(entry, w0, h0, d0);
|
||||
if (replaced.IsInvalid()) {
|
||||
ReplacedTexture *replaced = FindReplacement(entry, w0, h0, d0);
|
||||
if (replaced && replaced->IsInvalid()) {
|
||||
entry->status &= ~TexCacheEntry::STATUS_TO_REPLACE;
|
||||
if (g_Config.bSaveNewTextures) {
|
||||
// Load once more to actually save.
|
||||
@ -1482,17 +1482,17 @@ u32 TextureCacheCommon::EstimateTexMemoryUsage(const TexCacheEntry *entry) {
|
||||
return pixelSize << (dimW + dimH);
|
||||
}
|
||||
|
||||
ReplacedTexture &TextureCacheCommon::FindReplacement(TexCacheEntry *entry, int &w, int &h, int &d) {
|
||||
ReplacedTexture *TextureCacheCommon::FindReplacement(TexCacheEntry *entry, int &w, int &h, int &d) {
|
||||
if (d != 1) {
|
||||
// We don't yet support replacing 3D textures.
|
||||
return replacer_.FindNone();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// 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()) {
|
||||
return replacer_.FindNone();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Allow some delay to reduce pop-in.
|
||||
@ -1501,16 +1501,21 @@ ReplacedTexture &TextureCacheCommon::FindReplacement(TexCacheEntry *entry, int &
|
||||
double replaceStart = time_now_d();
|
||||
double budget = std::min(MAX_BUDGET_PER_TEX, replacementFrameBudget_ - replacementTimeThisFrame_);
|
||||
u64 cachekey = replacer_.Enabled() ? entry->CacheKey() : 0;
|
||||
ReplacedTexture &replaced = replacer_.FindReplacement(cachekey, entry->fullhash, w, h, budget);
|
||||
if (replaced.IsReady(budget)) {
|
||||
if (replaced.GetSize(0, w, h)) {
|
||||
ReplacedTexture *replaced = replacer_.FindReplacement(cachekey, entry->fullhash, w, h, budget);
|
||||
if (!replaced) {
|
||||
replacementTimeThisFrame_ += time_now_d() - replaceStart;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (replaced->IsReady(budget)) {
|
||||
if (replaced->GetSize(0, w, h)) {
|
||||
// Consider it already "scaled."
|
||||
entry->status |= TexCacheEntry::STATUS_IS_SCALED;
|
||||
}
|
||||
|
||||
// Remove the flag, even if it was invalid.
|
||||
entry->status &= ~TexCacheEntry::STATUS_TO_REPLACE;
|
||||
} else if (!replaced.IsInvalid()) {
|
||||
} else if (!replaced->IsInvalid()) {
|
||||
entry->status |= TexCacheEntry::STATUS_TO_REPLACE;
|
||||
}
|
||||
replacementTimeThisFrame_ += time_now_d() - replaceStart;
|
||||
@ -2778,10 +2783,10 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt
|
||||
}
|
||||
|
||||
if (canReplace) {
|
||||
plan.replaced = &FindReplacement(entry, plan.w, plan.h, plan.depth);
|
||||
plan.replaced = FindReplacement(entry, plan.w, plan.h, plan.depth);
|
||||
plan.replaceValid = plan.replaced->Valid();
|
||||
} else {
|
||||
plan.replaced = &replacer_.FindNone();
|
||||
plan.replaced = nullptr;
|
||||
plan.replaceValid = false;
|
||||
}
|
||||
|
||||
|
@ -378,7 +378,7 @@ protected:
|
||||
CheckAlphaResult DecodeTextureLevel(u8 *out, int outPitch, GETextureFormat format, GEPaletteFormat clutformat, uint32_t texaddr, int level, int bufw, TexDecodeFlags flags);
|
||||
void UnswizzleFromMem(u32 *dest, u32 destPitch, const u8 *texptr, u32 bufw, u32 height, u32 bytesPerPixel);
|
||||
CheckAlphaResult ReadIndexedTex(u8 *out, int outPitch, int level, const u8 *texptr, int bytesPerIndex, int bufw, bool reverseColors, bool expandTo32Bit);
|
||||
ReplacedTexture &FindReplacement(TexCacheEntry *entry, int &w, int &h, int &d);
|
||||
ReplacedTexture *FindReplacement(TexCacheEntry *entry, int &w, int &h, int &d);
|
||||
|
||||
// Return value is mapData normally, but could be another buffer allocated with AllocateAlignedMemory.
|
||||
void LoadTextureLevel(TexCacheEntry &entry, uint8_t *mapData, int mapRowPitch, BuildTexturePlan &plan, int srcLevel, Draw::DataFormat dstFmt, TexDecodeFlags texDecFlags);
|
||||
|
@ -501,7 +501,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
|
||||
}
|
||||
|
||||
// Turn off texture replacement for this texture.
|
||||
plan.replaced = &replacer_.FindNone();
|
||||
plan.replaced = nullptr;
|
||||
|
||||
plan.createW /= plan.scaleFactor;
|
||||
plan.createH /= plan.scaleFactor;
|
||||
|
Loading…
Reference in New Issue
Block a user