From b5151948d2c1a1d12ae6b2ce05b1e8f66b4242ea Mon Sep 17 00:00:00 2001 From: CamilleLaVey Date: Fri, 3 Apr 2026 23:53:49 -0400 Subject: [PATCH] [texture_cache] Adjusted GC logic for the iterations with older or obsolete textures --- src/video_core/texture_cache/texture_cache.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index eae1c11ce7..3d5a4a153b 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -128,7 +129,7 @@ void TextureCache

::RunGarbageCollector() { if (num_iterations == 0) { return true; } - --num_iterations; + auto& image = slot_images[image_id]; // Never delete recently allocated sparse textures (within 3 frames) @@ -156,6 +157,8 @@ void TextureCache

::RunGarbageCollector() { return false; } + --num_iterations; + if (must_download && !is_large_sparse) { auto map = runtime.DownloadStagingBuffer(image.unswizzled_size_bytes); const auto copies = FixSmallVectorADL(FullDownloadCopies(image.info)); @@ -185,6 +188,12 @@ void TextureCache

::RunGarbageCollector() { return false; }; + const auto SortByAge = [this](auto& vec) { + std::sort(vec.begin(), vec.end(), [this](ImageId a, ImageId b) { + return slot_images[a].last_use_tick < slot_images[b].last_use_tick; + }); + }; + // Single pass: collect all candidates, classified by tier const u64 normal_threshold = frame_tick > ticks_to_destroy ? frame_tick - ticks_to_destroy : 0; const u64 aggressive_threshold = frame_tick > 10 ? frame_tick - 10 : 0; @@ -208,6 +217,9 @@ void TextureCache

::RunGarbageCollector() { } } + SortByAge(expired); + SortByAge(aggressive_expired); + // Tier 1: large sparse textures under memory pressure for (const auto image_id : sparse_candidates) { auto& image = slot_images[image_id];