Count the texture cache's short waits in seconds below 60 presents a second too.

The cache counts its short waits in presents (PRESENTS(n): n presents at 60 a second) and scales them by the presents
a second. Above 60 it always did. Below 60 the rate stopped at 60, so the 120 presents a released texture stays out
of the VRAM pressure's reach (STALE_FRAMES) were 4 s at 30 presents a second and 5.7 s at 21. The game lets go of
textures by the second, as the player moves, so what that window holds grows with its length.

A tester's log (RTX 4070 SUPER, 2560x1440, DLSS Quality with frame generation, texture detail Full, 0.10.2-rc4): the
card went to 11,198 MiB against a budget of 10,600 while the frame rate fell from 63 to 21 fps. The released textures
held 2,644 MiB against their bound of 384, and 2,105 MiB of that was released too lately to go (442 MiB when the
pressure began).

On an RTX 5090 with the budget taken as 10,600 MiB and the tester's output settings, a walk through Hyrule Field at a
30 fps limit: the released-too-lately textures were all in their first 120 presents (the new census line below) and
held 383 and 429 MiB on average at the memory reports of two runs, against 292 MiB at 60 fps. With this change they
are in their first 60 presents and hold 209 MiB. Textures made again after a drop: 295 and 523 before, 511 after.
Not shown: the tester's 21 fps and a card that is really over its budget, which this card does not reach; the memory
in use as the driver counts it stayed at 9.8 GiB in the capped runs.

The rate now follows the presents down to 15 a second (vk_tex_release.h trl_rate_sample, trl_rate, trl_presents),
once eight seconds in a row were under 60, and never in a run's first eight seconds; one slow second among fast ones
still shortens nothing. Every wait PRESENTS counts follows it. NX2NAVI_TEX_RATE_LOW=0 stops the rate at 60 as before,
and one line says when the rate crosses 60. Values at 60 presents a second and above are the ones before.

The census of the released textures over their bound gets a second line: what the ones released too lately wait for
(their first presents after the release, content only the GPU made, the gap before a take-back with or without a
lookup still reaching them). It is what showed which wait held the memory.

tests/tex_release_check has the rate's checks and a table of the wait by presents a second; they fail against the
rule before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-14 11:33:02 -05:00
parent 712568d4fb
commit 2dd363b86e
6 changed files with 141 additions and 10 deletions

View File

@@ -139,3 +139,36 @@ static inline uint32_t trl_clock_age(const TrlClock *c, uint64_t frame, uint32_t
uint32_t s = c->sec[lo % TRL_CLOCK_N];
return now_sec > s ? now_sec - s : 0;
}
// The rate the short waits go by. vk_texture.c counts them in presents (PRESENTS(n): n presents at 60 a second: how
// long after its release a texture may go, how long without a sample makes one idle) and scales them by the presents
// a second, kept as a multiple of 60 in 1/256. Above 60 they always were scaled. Below 60 they were not: the rate
// stopped at 60, so "120 presents" was 4 s at 30 presents a second and 5.7 s at 21, and every texture the game let go
// of stayed out of the VRAM pressure's reach that much longer. The game lets go by the second, as the player moves, so
// what the window holds grows with its length: in a tester's log (RTX 4070 SUPER at 2560x1440, 2026-11-14) it held
// 442 MiB at 60 presents a second and 2,105 MiB at 21, on a card then 600 MiB over its budget. The rate follows the
// presents down to TRL_RATE_MIN now (low 1; 0: stops at 60, as before).
#define TRL_RATE_60 256u
#define TRL_RATE_MIN 64u // 15 presents a second: fewer count as 15
#define TRL_RATE_MAX 2048u // 480 presents a second
static inline uint32_t trl_rate_sample(uint64_t presents, uint64_t ns, int low) {
if (!ns) return TRL_RATE_60;
uint64_t r = presents * 256ull * 1000000000ull / (ns * 60);
uint32_t least = low ? TRL_RATE_MIN : TRL_RATE_60;
return r < least ? least : r > TRL_RATE_MAX ? TRL_RATE_MAX : (uint32_t)r;
}
// The rate of the last n samples (one a second): the highest of them, so that a slow second or a few (an area load, a
// movie's start) shorten nothing, and only n slow seconds in a row do. A sample not taken yet (0) counts as 60 a
// second: the first n seconds of a run never go below it.
static inline uint32_t trl_rate(const uint32_t *ring, int n) {
uint32_t m = TRL_RATE_MIN;
for (int i = 0; i < n; i++) {
uint32_t v = ring[i] ? ring[i] : TRL_RATE_60;
if (v > m) m = v;
}
return m;
}
// n presents at 60 a second, in presents at the rate: the same wall time.
static inline uint64_t trl_presents(uint64_t n, uint32_t rate) { return n * rate >> 8; }