mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-18 09:09:56 -04:00
Keep released textures for one minute and up to a thirty-second of the video memory budget.
The textures the game lets go of were kept for three minutes and could hold a quarter of the card's budget, up to 8 GiB with room. A run through Hyrule Field shows what that bought and what it cost (RTX 5090, 5120x2160 with DLSS Performance, about three minutes of running; the game keeps 4.8 GiB of textures live and loads about 190 a second): the released textures held 5.3 GiB on average and the video memory in use went from 11.1 to 17.9 GiB, while the game took back 1,494 MiB of them within 10 s of the release, 171 MiB within a minute and 10 MiB later, beside 33,000 textures it loaded anew. A shorter hold alone gives nothing back: with 20 s the released textures fell to 0.5 GiB and the free space inside the allocator's blocks rose to 4.9 GiB, since a block returns to the driver only when it is empty. What the released textures hold at their fullest is what the session costs, so the bound is the lever. The bound is now a thirty-second of the budget, 384 MiB to 1 GiB (vk_tex_release.h trl_cap_mb), still doubled while the card and the commit have room, and the hold 60 s, 120 for content only the GPU made. The same run with the new defaults: 13.2 GiB in use on average against 16.7, 13.8 at most against 17.9, 532 MiB of textures made again over the run, 77 fps against 75. An 8 GiB card keeps 384 MiB where it kept up to 1.9 GiB. tests/tex_release_check checks the bound by the budget and the sessions it simulates against the rule before. Compaction (tex_compact) and 16 MiB blocks were tried on the same run and gave back 0.7 and 1.2 GiB; neither is changed here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
// The simulation follows vk_texture.c sweep_pressure: once a second (the cache checks every 8 submissions) take-backs
|
||||
// that fall due find their entry or make it again, drop_aged takes the entries past their hold, and drop_stale takes
|
||||
// the oldest entries released 2 s ago or earlier while the released bytes are above trl_keep. The streams are shaped
|
||||
// by the figures of two sessions' logs on an RTX 5090 (vk_tex_release.h).
|
||||
// by the figures of three sessions' logs on an RTX 5090 (vk_tex_release.h).
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -62,7 +62,7 @@ static void clock_checks(void) {
|
||||
|
||||
// ---- the rules
|
||||
static void rule_checks(void) {
|
||||
CHECK(trl_hold(TRL_HOLD_S, TRL_STORAGE) == 180 && trl_hold(TRL_HOLD_S, TRL_GPU) == 360, "holds 180 and 360 s");
|
||||
CHECK(trl_hold(TRL_HOLD_S, TRL_STORAGE) == 60 && trl_hold(TRL_HOLD_S, TRL_GPU) == 120, "holds 60 and 120 s");
|
||||
CHECK(!trl_aged(0, TRL_STORAGE, 100000), "no hold: nothing ages out");
|
||||
CHECK(!trl_aged(180, TRL_STORAGE, 179) && trl_aged(180, TRL_STORAGE, 180), "the hold's edge");
|
||||
CHECK(!trl_aged(180, TRL_GPU, 359) && trl_aged(180, TRL_GPU, 360), "GPU content waits twice the hold");
|
||||
@@ -80,6 +80,23 @@ static void rule_checks(void) {
|
||||
CHECK(trl_keep(180, MB(4008), 1) == MB(8016) && trl_keep(180, MB(4008), 0) == MB(4008), "keep: twice with room");
|
||||
CHECK(trl_keep(0, MB(4008), 1) == MB(4008), "keep: the bound without the hold, as before");
|
||||
CHECK(trl_keep(180, UINT64_MAX, 1) == UINT64_MAX, "keep: no bound stays none");
|
||||
// the default bound by the card's budget (MiB): a thirty-second of it, 384 MiB to 1 GiB
|
||||
CHECK(trl_cap_mb(0) == TRL_CAP_UNKNOWN_MB, "no budget known: %u", trl_cap_mb(0));
|
||||
CHECK(trl_cap_mb(31419) == 981, "RTX 5090 (budget 31419 MiB): %u", trl_cap_mb(31419));
|
||||
CHECK(trl_cap_mb(15450) == 482, "a 16 GiB card (budget 15450 MiB): %u", trl_cap_mb(15450));
|
||||
CHECK(trl_cap_mb(7680) == TRL_CAP_MIN_MB && trl_cap_mb(3900) == TRL_CAP_MIN_MB, "8 and 4 GiB cards: the least");
|
||||
CHECK(trl_cap_mb(48000) == TRL_CAP_MAX_MB && trl_cap_mb(UINT64_MAX) == TRL_CAP_MAX_MB, "a larger card: the most");
|
||||
uint32_t last = 0;
|
||||
for (uint64_t b = 1; b <= 65536; b += 97) {
|
||||
uint32_t c = trl_cap_mb(b);
|
||||
CHECK(c >= last && c >= TRL_CAP_MIN_MB && c <= TRL_CAP_MAX_MB, "budget %llu MiB: bound %u after %u",
|
||||
(unsigned long long)b, c, last);
|
||||
last = c;
|
||||
}
|
||||
// what the released textures may hold at their fullest: under 2 GiB on a 32 GiB card with room (8 GiB by the
|
||||
// rule before, a quarter of the budget and twice that), 384 MiB on an 8 GiB card in play (1.9 GiB before)
|
||||
CHECK(trl_keep(TRL_HOLD_S, MB(trl_cap_mb(31419)), 1) < MB(2048), "the most on a 32 GiB card");
|
||||
CHECK(trl_keep(TRL_HOLD_S, MB(trl_cap_mb(7680)), 0) == MB(384), "the most on an 8 GiB card in play");
|
||||
}
|
||||
|
||||
// ---- the take-backs of the logs against the hold
|
||||
@@ -91,6 +108,11 @@ static const struct { const char *session; uint64_t n[5]; } TAKEN[] = {
|
||||
{"balanced, frame 7200", {120779, 91, 1, 0, 0}},
|
||||
};
|
||||
static const uint32_t EDGE[5] = {2, 10, 60, 300, UINT32_MAX};
|
||||
// The run through Hyrule Field that set the bound (2026-11-14, the rule before: 180 s, 4008 MiB and twice that with
|
||||
// room): MiB and textures taken back by the time released, 2-10 s, 10-60 s, later; and the textures loaded anew
|
||||
// meanwhile.
|
||||
static const uint64_t FIELD_BACK_MB[3] = {1494, 171, 10};
|
||||
static const uint64_t FIELD_BACK_N[3] = {941, 331, 28}, FIELD_UPLOADS = 33118;
|
||||
|
||||
static void taken_back_checks(void) {
|
||||
uint32_t longest = 0;
|
||||
@@ -98,10 +120,18 @@ static void taken_back_checks(void) {
|
||||
for (int b = 0; b < 5; b++)
|
||||
if (TAKEN[i].n[b] && EDGE[b] > longest) longest = EDGE[b];
|
||||
CHECK(longest == 60, "the longest take-back of the logs lies under %u s", longest);
|
||||
// nothing the logs took back would have gone past the hold: every take-back came before 60 s, the hold is 180 s
|
||||
// nothing those logs took back would have gone past the hold: every take-back came before 60 s
|
||||
for (int cls = TRL_STORAGE; cls <= TRL_GPU; cls++)
|
||||
CHECK(!trl_aged(TRL_HOLD_S, cls, longest) && trl_hold(TRL_HOLD_S, cls) >= 3 * longest,
|
||||
"class %d: hold %u s against take-backs up to %u s", cls, trl_hold(TRL_HOLD_S, cls), longest);
|
||||
CHECK(!trl_aged(TRL_HOLD_S, cls, longest - 1) && trl_hold(TRL_HOLD_S, cls) >= longest,
|
||||
"class %d: hold %u s against take-backs under %u s", cls, trl_hold(TRL_HOLD_S, cls), longest);
|
||||
// the field run: what came back later than the hold is under a hundredth of what came back at all, and everything
|
||||
// the cache gave back in three minutes is a twenty-fifth of what the game loaded anew in that time
|
||||
uint64_t all_mb = FIELD_BACK_MB[0] + FIELD_BACK_MB[1] + FIELD_BACK_MB[2];
|
||||
uint64_t all_n = FIELD_BACK_N[0] + FIELD_BACK_N[1] + FIELD_BACK_N[2];
|
||||
CHECK(FIELD_BACK_MB[2] * 100 < all_mb, "field run: %llu of %llu MiB came back past a minute",
|
||||
(unsigned long long)FIELD_BACK_MB[2], (unsigned long long)all_mb);
|
||||
CHECK(all_n * 20 < FIELD_UPLOADS, "field run: %llu taken back beside %llu loaded", (unsigned long long)all_n,
|
||||
(unsigned long long)FIELD_UPLOADS);
|
||||
}
|
||||
|
||||
// ---- simulated sessions
|
||||
@@ -119,7 +149,7 @@ typedef struct {
|
||||
} Policy;
|
||||
|
||||
typedef struct {
|
||||
uint64_t remade, remade_bytes, dropped_age, dropped_bound, peak, end, at_burst_end;
|
||||
uint64_t remade, remade_bytes, remade_quick, dropped_age, dropped_bound, peak, end, at_burst_end;
|
||||
} Result;
|
||||
|
||||
#define MAXE 400000
|
||||
@@ -168,7 +198,7 @@ static Result run(const Policy *p, int room, uint32_t burst_s, uint32_t end_s) {
|
||||
while (next < nents && ents[next].rel <= s) held += ents[next++].bytes;
|
||||
for (; nb < nbacks && ents[backs[nb]].back <= s; nb++) { // the take-backs due now
|
||||
Ent *e = &ents[backs[nb]];
|
||||
if (e->gone) r.remade++, r.remade_bytes += e->bytes;
|
||||
if (e->gone) r.remade++, r.remade_bytes += e->bytes, r.remade_quick += e->back - e->rel < 10;
|
||||
else held -= e->bytes;
|
||||
e->taken = 1;
|
||||
}
|
||||
@@ -201,59 +231,72 @@ static void print_result(const char *scenario, const Policy *p, int room, const
|
||||
}
|
||||
|
||||
static void session_checks(void) {
|
||||
// RTX 5090, 31 GiB budget: the size bound a quarter of it (4008 MiB, the logs' figure)
|
||||
const Policy old_low = {"old low", MB(1024), 0}, balanced = {"old balanced", MB(4008), 0},
|
||||
low = {"new low", MB(4008), TRL_HOLD_S};
|
||||
// an 8 GiB card: bound 1.9 GiB, no room in play
|
||||
const Policy b8 = {"old balanced", MB(1920), 0}, l8 = {"new low", MB(1920), TRL_HOLD_S},
|
||||
o8 = {"old low", MB(1024), 0};
|
||||
// RTX 5090, 31 GiB budget: until 0.10.2 a quarter of it (4008 MiB, the logs' figure) and 180 s; now trl_cap_mb
|
||||
const Policy was = {"until 0.10.2", MB(4008), 180}, now = {"0.10.2", MB(trl_cap_mb(31419)), TRL_HOLD_S};
|
||||
// an 8 GiB card: no room in play
|
||||
const Policy was8 = {"until 0.10.2", MB(1920), 180}, now8 = {"0.10.2", MB(trl_cap_mb(7680)), TRL_HOLD_S};
|
||||
struct { const char *name; uint32_t burst_s; double burst_mbs; uint32_t end_s; double calm_mbs; } sc[] = {
|
||||
// the Balanced session's second line: 3.2 GiB released and kept within 35 s; then 10 minutes in one area
|
||||
{"area changes 70 s, calm 10 min", 70, 93.0, 670, 1.0},
|
||||
// a long session: an area change every few minutes, shown as a slower stream throughout
|
||||
{"steady 20 MiB/s for 20 min", 1200, 20.0, 1500, 0.5},
|
||||
// a teleport tour: 4 minutes at the burst rate, past twice the bound
|
||||
// a teleport tour: 4 minutes at the burst rate
|
||||
{"teleports 4 min, calm 10 min", 240, 93.0, 840, 1.0},
|
||||
// the run through Hyrule Field: the game lets go of about 130 MiB a second for three minutes
|
||||
{"field run 3 min, calm 2 min", 170, 130.0, 290, 1.0},
|
||||
};
|
||||
printf("simulated sessions (made again: taken back after its drop; MiB: own memory of released textures)\n");
|
||||
for (size_t i = 0; i < sizeof sc / sizeof *sc; i++) {
|
||||
rng_state = 0x9e3779b97f4a7c15ull + i;
|
||||
make_stream(sc[i].burst_s, sc[i].burst_mbs, sc[i].end_s, sc[i].calm_mbs, 20, 0);
|
||||
Result rl = run(&low, 1, sc[i].burst_s, sc[i].end_s), rb = run(&balanced, 1, sc[i].burst_s, sc[i].end_s);
|
||||
Result ro = run(&old_low, 1, sc[i].burst_s, sc[i].end_s);
|
||||
Result rl8 = run(&l8, 0, sc[i].burst_s, sc[i].end_s), rb8 = run(&b8, 0, sc[i].burst_s, sc[i].end_s);
|
||||
Result ro8 = run(&o8, 0, sc[i].burst_s, sc[i].end_s);
|
||||
print_result(sc[i].name, &old_low, 1, &ro), print_result("", &balanced, 1, &rb), print_result("", &low, 1, &rl);
|
||||
print_result(" same on an 8 GiB card", &o8, 0, &ro8), print_result("", &b8, 0, &rb8);
|
||||
print_result("", &l8, 0, &rl8);
|
||||
// with room the new default makes nothing again, unless a burst passes twice the bound within the hold
|
||||
uint64_t total = 0;
|
||||
for (uint32_t k = 0; k < nents && ents[k].rel <= sc[i].burst_s; k++) total += ents[k].bytes;
|
||||
if (total < 2 * low.cap - MB(256))
|
||||
CHECK(rl.remade == 0, "%s: new low made %llu again", sc[i].name, (unsigned long long)rl.remade);
|
||||
// never more made again than the old Balanced, on either card
|
||||
CHECK(rl.remade <= rb.remade && rl8.remade <= rb8.remade, "%s: new low %llu/%llu against balanced %llu/%llu",
|
||||
sc[i].name, (unsigned long long)rl.remade, (unsigned long long)rl8.remade, (unsigned long long)rb.remade,
|
||||
(unsigned long long)rb8.remade);
|
||||
// what it holds at the end: what the last hold released, far under the old Balanced's
|
||||
CHECK(rl.end <= rb.end / 2 || rb.end < MB(256), "%s: new low holds %.0f MiB at the end, balanced %.0f",
|
||||
sc[i].name, rl.end / 1048576.0, rb.end / 1048576.0);
|
||||
// the old low's 1 GiB made textures again in every burst, as the log showed
|
||||
CHECK(ro.remade > 0, "%s: old low made nothing again", sc[i].name);
|
||||
CHECK(!rl.dropped_bound || total >= 2 * low.cap - MB(256), "%s: new low dropped %llu by the bound with room",
|
||||
sc[i].name, (unsigned long long)rl.dropped_bound);
|
||||
Result rn = run(&now, 1, sc[i].burst_s, sc[i].end_s), rw = run(&was, 1, sc[i].burst_s, sc[i].end_s);
|
||||
Result rn8 = run(&now8, 0, sc[i].burst_s, sc[i].end_s), rw8 = run(&was8, 0, sc[i].burst_s, sc[i].end_s);
|
||||
print_result(sc[i].name, &was, 1, &rw), print_result("", &now, 1, &rn);
|
||||
print_result(" same on an 8 GiB card", &was8, 0, &rw8), print_result("", &now8, 0, &rn8);
|
||||
uint64_t total = 0, came_back = 0;
|
||||
for (uint32_t k = 0; k < nents; k++) total += ents[k].bytes, came_back += ents[k].back ? ents[k].bytes : 0;
|
||||
// What the cache holds at its fullest is what the session costs in video memory: never more than what it may
|
||||
// keep and what two seconds release (drop_stale leaves the entries of the last two seconds), on either card
|
||||
uint64_t slack = MB((uint64_t)(2 * sc[i].burst_mbs) + 4);
|
||||
CHECK(rn.peak <= trl_keep(now.hold, now.cap, 1) + slack, "%s: holds %.0f MiB at its fullest", sc[i].name,
|
||||
rn.peak / 1048576.0);
|
||||
CHECK(rn8.peak <= trl_keep(now8.hold, now8.cap, 0) + slack, "%s, 8 GiB card: holds %.0f MiB at its fullest",
|
||||
sc[i].name, rn8.peak / 1048576.0);
|
||||
// and never more than the rule before held; where that one filled up, less than half of it
|
||||
CHECK(rn.peak <= rw.peak && rn8.peak <= rw8.peak, "%s: peak %.0f/%.0f MiB against %.0f/%.0f before", sc[i].name,
|
||||
rn.peak / 1048576.0, rn8.peak / 1048576.0, rw.peak / 1048576.0, rw8.peak / 1048576.0);
|
||||
if (rw.peak > MB(4096))
|
||||
CHECK(rn.peak * 2 < rw.peak, "%s: peak %.0f MiB, %.0f before", sc[i].name, rn.peak / 1048576.0,
|
||||
rw.peak / 1048576.0);
|
||||
// what it holds once play is calm is what the last hold released
|
||||
CHECK(rn.end <= rw.end && rn.end <= MB((uint64_t)(sc[i].calm_mbs * 2 * TRL_HOLD_S) + 64),
|
||||
"%s: holds %.0f MiB at the end, %.0f before", sc[i].name, rn.end / 1048576.0, rw.end / 1048576.0);
|
||||
// A take-back within ten seconds of the release (turning round) finds its texture wherever ten seconds of
|
||||
// releases fit in what the cache may keep; on the 32 GiB card that is every scenario here
|
||||
if ((uint64_t)(sc[i].burst_mbs * 12) < (trl_keep(now.hold, now.cap, 1) >> 20))
|
||||
CHECK(rn.remade_quick == 0, "%s: %llu quick take-backs made again", sc[i].name,
|
||||
(unsigned long long)rn.remade_quick);
|
||||
if ((uint64_t)(sc[i].burst_mbs * 12) < (trl_keep(now8.hold, now8.cap, 0) >> 20))
|
||||
CHECK(rn8.remade_quick == 0, "%s, 8 GiB card: %llu quick take-backs made again", sc[i].name,
|
||||
(unsigned long long)rn8.remade_quick);
|
||||
// and what it makes again is never more than what the game takes back at all (a fiftieth of the stream here)
|
||||
CHECK(rn.remade_bytes <= came_back && rn8.remade_bytes <= came_back && came_back * 40 < total,
|
||||
"%s: made again %.0f/%.0f MiB of %.0f MiB that came back", sc[i].name, rn.remade_bytes / 1048576.0,
|
||||
rn8.remade_bytes / 1048576.0, came_back / 1048576.0);
|
||||
}
|
||||
// a game that takes textures back late: at 150 s nothing goes before (hold 180), at 200 s the hold costs
|
||||
// a game that takes textures back late, in calm play where the bound is far: at 50 s nothing goes before (the
|
||||
// hold is 60 s), at 90 s the hold has dropped them
|
||||
rng_state = 7;
|
||||
make_stream(70, 93.0, 670, 1.0, 20, 150);
|
||||
Result r150 = run(&low, 1, 70, 670);
|
||||
CHECK(r150.remade == 0, "take-backs at 150 s: new low made %llu again", (unsigned long long)r150.remade);
|
||||
make_stream(0, 0.0, 400, 5.0, 20, 50);
|
||||
Result r50 = run(&now, 1, 0, 400);
|
||||
CHECK(r50.remade == 0 && r50.dropped_bound == 0, "take-backs at 50 s: made %llu again, %llu dropped by the bound",
|
||||
(unsigned long long)r50.remade, (unsigned long long)r50.dropped_bound);
|
||||
rng_state = 7;
|
||||
make_stream(70, 93.0, 670, 1.0, 20, 200);
|
||||
Result r200 = run(&low, 1, 70, 670);
|
||||
CHECK(r200.remade > 0, "take-backs at 200 s: the hold should have dropped some first");
|
||||
printf(" late take-backs: at 150 s made again %llu, at 200 s %llu (the hold is %u s)\n",
|
||||
(unsigned long long)r150.remade, (unsigned long long)r200.remade, TRL_HOLD_S);
|
||||
make_stream(0, 0.0, 400, 5.0, 20, 90);
|
||||
Result r90 = run(&now, 1, 0, 400);
|
||||
CHECK(r90.remade > 0, "take-backs at 90 s: the hold should have dropped some first");
|
||||
printf(" late take-backs in calm play: at 50 s made again %llu, at 90 s %llu (the hold is %u s)\n",
|
||||
(unsigned long long)r50.remade, (unsigned long long)r90.remade, TRL_HOLD_S);
|
||||
}
|
||||
|
||||
// ---- past the hard count (trl_hard_class, trl_hard_pick)
|
||||
|
||||
Reference in New Issue
Block a user