mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-10 03:18:55 +02:00
[texture_cache] Reduce garbage collection logic by simplifying conditions and thresholds
This commit is contained in:
parent
18ad42f996
commit
e343ee9524
1 changed files with 39 additions and 52 deletions
|
|
@ -118,17 +118,10 @@ TextureCache<P>::TextureCache(Runtime& runtime_, Tegra::MaxwellDeviceMemoryManag
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
void TextureCache<P>::RunGarbageCollector() {
|
void TextureCache<P>::RunGarbageCollector() {
|
||||||
bool high_priority_mode = false;
|
bool high_priority_mode = total_used_memory >= expected_memory;
|
||||||
bool aggressive_mode = false;
|
bool aggressive_mode = false;
|
||||||
u64 ticks_to_destroy = 0;
|
u64 ticks_to_destroy = high_priority_mode ? 25ULL : 50ULL;
|
||||||
size_t num_iterations = 0;
|
size_t num_iterations = high_priority_mode ? 20 : 10;
|
||||||
|
|
||||||
const auto Configure = [&](bool allow_aggressive) {
|
|
||||||
high_priority_mode = total_used_memory >= expected_memory;
|
|
||||||
aggressive_mode = allow_aggressive && total_used_memory >= critical_memory;
|
|
||||||
ticks_to_destroy = aggressive_mode ? 10ULL : high_priority_mode ? 25ULL : 50ULL;
|
|
||||||
num_iterations = aggressive_mode ? 40 : (high_priority_mode ? 20 : 10);
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto Cleanup = [this, &num_iterations, &high_priority_mode,
|
const auto Cleanup = [this, &num_iterations, &high_priority_mode,
|
||||||
&aggressive_mode](ImageId image_id) {
|
&aggressive_mode](ImageId image_id) {
|
||||||
|
|
@ -145,12 +138,9 @@ void TextureCache<P>::RunGarbageCollector() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (True(image.flags & ImageFlagBits::IsDecoding)) {
|
if (True(image.flags & ImageFlagBits::IsDecoding)) {
|
||||||
// This image is still being decoded, deleting it will invalidate the slot
|
|
||||||
// used by the async decoder thread.
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prioritize large sparse textures for cleanup
|
|
||||||
const bool is_large_sparse = lowmemorydevice &&
|
const bool is_large_sparse = lowmemorydevice &&
|
||||||
image.info.is_sparse &&
|
image.info.is_sparse &&
|
||||||
image.guest_size_bytes >= 256_MiB;
|
image.guest_size_bytes >= 256_MiB;
|
||||||
|
|
@ -183,7 +173,6 @@ void TextureCache<P>::RunGarbageCollector() {
|
||||||
|
|
||||||
if (total_used_memory < critical_memory) {
|
if (total_used_memory < critical_memory) {
|
||||||
if (aggressive_mode) {
|
if (aggressive_mode) {
|
||||||
// Sink the aggresiveness.
|
|
||||||
num_iterations >>= 2;
|
num_iterations >>= 2;
|
||||||
aggressive_mode = false;
|
aggressive_mode = false;
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -196,55 +185,53 @@ void TextureCache<P>::RunGarbageCollector() {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto CollectBelow = [this](u64 threshold) {
|
// Single pass: collect all candidates, classified by tier
|
||||||
boost::container::small_vector<ImageId, 64> expired;
|
const u64 normal_threshold = frame_tick > ticks_to_destroy ? frame_tick - ticks_to_destroy : 0;
|
||||||
for (auto [id, image] : slot_images) {
|
const u64 aggressive_threshold = frame_tick > 10 ? frame_tick - 10 : 0;
|
||||||
if (True(image->flags & ImageFlagBits::Registered) &&
|
boost::container::small_vector<ImageId, 64> sparse_candidates;
|
||||||
image->last_use_tick < threshold) {
|
boost::container::small_vector<ImageId, 64> expired;
|
||||||
expired.push_back(id);
|
boost::container::small_vector<ImageId, 64> aggressive_expired;
|
||||||
}
|
|
||||||
}
|
|
||||||
return expired;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Aggressively clear massive sparse textures
|
for (auto [id, image] : slot_images) {
|
||||||
if (total_used_memory >= expected_memory) {
|
if (False(image->flags & ImageFlagBits::Registered)) {
|
||||||
auto candidates = CollectBelow(frame_tick);
|
continue;
|
||||||
for (const auto image_id : candidates) {
|
}
|
||||||
auto& image = slot_images[image_id];
|
const u64 tick = image->last_use_tick;
|
||||||
if (lowmemorydevice &&
|
if (tick < normal_threshold) {
|
||||||
image.info.is_sparse &&
|
expired.push_back(id);
|
||||||
image.guest_size_bytes >= 256_MiB &&
|
} else if (tick < aggressive_threshold) {
|
||||||
image.allocation_tick < frame_tick - 3) {
|
aggressive_expired.push_back(id);
|
||||||
LOG_DEBUG(HW_GPU, "GC targeting old sparse texture at 0x{:X} ({} MiB, age: {} frames)",
|
} else if (high_priority_mode && tick < frame_tick &&
|
||||||
image.gpu_addr, image.guest_size_bytes / (1024 * 1024),
|
lowmemorydevice && image->info.is_sparse &&
|
||||||
frame_tick - image.allocation_tick);
|
image->guest_size_bytes >= 256_MiB) {
|
||||||
if (Cleanup(image_id)) {
|
sparse_candidates.push_back(id);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Configure(false);
|
// Tier 1: large sparse textures under memory pressure
|
||||||
if (frame_tick > ticks_to_destroy) {
|
for (const auto image_id : sparse_candidates) {
|
||||||
auto expired = CollectBelow(frame_tick - ticks_to_destroy);
|
auto& image = slot_images[image_id];
|
||||||
for (const auto image_id : expired) {
|
if (image.allocation_tick < frame_tick - 3) {
|
||||||
if (Cleanup(image_id)) {
|
if (Cleanup(image_id)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If pressure is still too high, prune aggressively.
|
// Tier 2: normal expiration
|
||||||
|
for (const auto image_id : expired) {
|
||||||
|
if (Cleanup(image_id)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tier 3: if still critical, use aggressive threshold with more iterations
|
||||||
if (total_used_memory >= critical_memory) {
|
if (total_used_memory >= critical_memory) {
|
||||||
Configure(true);
|
aggressive_mode = true;
|
||||||
if (frame_tick > ticks_to_destroy) {
|
num_iterations = 40;
|
||||||
auto expired = CollectBelow(frame_tick - ticks_to_destroy);
|
for (const auto image_id : aggressive_expired) {
|
||||||
for (const auto image_id : expired) {
|
if (Cleanup(image_id)) {
|
||||||
if (Cleanup(image_id)) {
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue