Skip to content

Commit

Permalink
Fix main-thread stalls due to decimate during replacement texture loa…
Browse files Browse the repository at this point in the history
…ding
  • Loading branch information
hrydgard committed Oct 3, 2023
1 parent 20c13f3 commit d07c3c5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions GPU/Common/TextureReplacer.cpp
Expand Up @@ -809,9 +809,13 @@ void TextureReplacer::Decimate(ReplacerDecimateMode mode) {
const double threshold = time_now_d() - age;
size_t totalSize = 0;
for (auto &item : levelCache_) {
std::lock_guard<std::mutex> guard(item.second->lock_);
item.second->PurgeIfNotUsedSinceTime(threshold);
totalSize += item.second->GetTotalDataSize(); // TODO: Make something better.
// During decimation, it's fine to try-lock here to avoid blocking the main thread while
// the level is being loaded - in that case we don't want to decimate anyway.
if (item.second->lock_.try_lock()) {
item.second->PurgeIfNotUsedSinceTime(threshold);
totalSize += item.second->GetTotalDataSize(); // TODO: Make something better.
item.second->lock_.unlock();
}
// don't actually delete the items here, just clean out the data.
}

Expand Down

0 comments on commit d07c3c5

Please sign in to comment.