From 901548fcbb569ef0fa466f9baff5c643ba692927 Mon Sep 17 00:00:00 2001 From: ParantezTech <12572227+par274@users.noreply.github.com> Date: Fri, 2 Oct 2026 18:51:29 +0300 Subject: [PATCH] [Gpu] Collect an image only once it is old enough in frames Since images age by frame, clamping the age to the current frame made every image of the first frame collectable during the first 16 frames, and a submission that ended no frame could delete a texture the frame still used. Without memory pressure nothing is collected until the full age has passed; under pressure the clamp still lets collection relieve memory early. --- .../Gpu/Images/GuestImageCache.Collection.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/SharpEmu.Libs/Gpu/Images/GuestImageCache.Collection.cs b/src/SharpEmu.Libs/Gpu/Images/GuestImageCache.Collection.cs index 91eb205..cc71b78 100644 --- a/src/SharpEmu.Libs/Gpu/Images/GuestImageCache.Collection.cs +++ b/src/SharpEmu.Libs/Gpu/Images/GuestImageCache.Collection.cs @@ -34,7 +34,13 @@ public sealed partial class GuestImageCache { var pressured = _totalUsedMemory >= _memoryPressureBytes; var aggressive = allowAggressive && _totalUsedMemory >= _criticalMemoryBytes; - var age = Math.Min(aggressive ? 160UL : pressured ? 80UL : 16UL, tick); + var age = aggressive ? 160UL : pressured ? 80UL : 16UL; + if (tick < age && !pressured && !aggressive) + { + return; + } + + age = Math.Min(age, tick); var deletions = aggressive ? 40 : pressured ? 20 : 10; var candidates = new List(deletions); // Deleting a depth image also deletes its stencil association, so the recency walk ends first.