mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-11 05:26:24 +02:00
Small cleanup of purging code
This commit is contained in:
1 parent
35f46ec161
commit
725d4195df
3 files changed
+32
-16
No files matched your search
@@ -95,9 +95,6 @@ private:
|
||||
|
||||
ReplacedTexture::ReplacedTexture(VFSBackend *vfs, const ReplacementDesc &desc) : vfs_(vfs), desc_(desc) {
|
||||
logId_ = desc.logId;
|
||||
SetState(ReplacementState::POPULATED);
|
||||
|
||||
// TODO: What used to be here is now done on the thread task.
|
||||
}
|
||||
|
||||
ReplacedTexture::~ReplacedTexture() {
|
||||
@@ -115,19 +112,38 @@ ReplacedTexture::~ReplacedTexture() {
|
||||
}
|
||||
}
|
||||
|
||||
void ReplacedTexture::PurgeIfOlder(double t) {
|
||||
if (threadWaitable_ && !threadWaitable_->WaitFor(0.0))
|
||||
void ReplacedTexture::PurgeIfNotUsedSinceTime(double t) {
|
||||
if (State() != ReplacementState::ACTIVE) {
|
||||
return;
|
||||
if (lastUsed_ >= t)
|
||||
}
|
||||
|
||||
// If there's some leftover threadWaitable, get rid of it.
|
||||
if (threadWaitable_) {
|
||||
if (threadWaitable_->WaitFor(0.0)) {
|
||||
delete threadWaitable_;
|
||||
threadWaitable_ = nullptr;
|
||||
// Continue with purging.
|
||||
} else {
|
||||
// Try next time.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// "atomic-enough" to not lock?
|
||||
if (lastUsed_ >= t) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
if (data_.size() && lastUsed < t) {
|
||||
// We have to lock since multiple textures might reference this same data.
|
||||
data_.clear();
|
||||
// This means we have to reload. If we never purge any, there's no need.
|
||||
SetState(ReplacementState::POPULATED);
|
||||
}
|
||||
|
||||
// We have to lock since multiple textures might reference this same data.
|
||||
data_.clear();
|
||||
levels_.clear();
|
||||
fmt = Draw::DataFormat::UNDEFINED;
|
||||
alphaStatus_ = ReplacedTextureAlpha::UNKNOWN;
|
||||
|
||||
// This means we have to reload. If we never purge any, there's no need.
|
||||
SetState(ReplacementState::POPULATED);
|
||||
}
|
||||
|
||||
// This can only return true if ACTIVE or NOT_FOUND.
|
||||
|
||||
@@ -170,19 +170,19 @@ private:
|
||||
|
||||
void Prepare(VFSBackend *vfs);
|
||||
LoadLevelResult LoadLevelData(VFSFileReference *fileRef, const std::string &filename, int level, Draw::DataFormat *pixelFormat);
|
||||
void PurgeIfOlder(double t);
|
||||
void PurgeIfNotUsedSinceTime(double t);
|
||||
|
||||
std::vector<std::vector<uint8_t>> data_;
|
||||
std::vector<ReplacedTextureLevel> levels_;
|
||||
|
||||
ReplacedTextureAlpha alphaStatus_ = ReplacedTextureAlpha::UNKNOWN;
|
||||
double lastUsed_ = 0.0;
|
||||
LimitedWaitable *threadWaitable_ = nullptr;
|
||||
std::mutex lock_;
|
||||
Draw::DataFormat fmt = Draw::DataFormat::UNDEFINED; // NOTE: Right now, the only supported format is Draw::DataFormat::R8G8B8A8_UNORM.
|
||||
ReplacedTextureAlpha alphaStatus_ = ReplacedTextureAlpha::UNKNOWN;
|
||||
double lastUsed = 0.0;
|
||||
|
||||
std::atomic<ReplacementState> state_ = ReplacementState::UNINITIALIZED;
|
||||
std::atomic<ReplacementState> state_ = ReplacementState::POPULATED;
|
||||
|
||||
VFSBackend *vfs_ = nullptr;
|
||||
ReplacementDesc desc_;
|
||||
|
||||
@@ -746,7 +746,7 @@ void TextureReplacer::Decimate(ReplacerDecimateMode mode) {
|
||||
size_t totalSize = 0;
|
||||
for (auto &item : levelCache_) {
|
||||
std::lock_guard<std::mutex> guard(item.second->lock_);
|
||||
item.second->PurgeIfOlder(threshold);
|
||||
item.second->PurgeIfNotUsedSinceTime(threshold);
|
||||
totalSize += item.second->GetTotalDataSize(); // TODO: Make something better.
|
||||
// don't actually delete the items here, just clean out the data.
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user