mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 13:39:58 -04:00
Keep the driver's cache of stage libraries warm, link a missing pipeline instead of skipping its draw, and count the texture cache's waits in time.
The preparation builds every stage library once so the driver's disk cache holds it and a library a draw needs later takes under a millisecond. Turning dynamic vertex input off for AMD's RDNA 3 and newer driver changed the dynamic states every library lists, which gave each one another entry in the driver's cache, and nothing built them again: an update carried the prepared shaders over without the driver step. On an RX 7900 XT (26.10.1) all 42,142 prepared libraries were cold, 93 ms a vertex and 242 ms a fragment library on average. With no pipeline recorded, a walk through a village skipped 11,180 draws while their pipelines built and made 94 draws wait 5.5 s in all, four of them 1.0 to 2.0 s; a player's session log shows up to 114,834 draws skipped in 600 frames and 181 waits of 251 ms on average. Skipped ground and walls appear and disappear, and a skipped lighting pass is a black frame with the interface intact. - The game checks the driver's cache at every start (vk_pipeline.c lw_start): a sample of the prepared fragment libraries is built, and when their median time says the cache is cold the whole prepared list is built into it again on idle-priority threads while the game runs. shader-warm.txt records a warm in progress, so the next start goes on with one a run ended, and stops the tries on a driver that does not keep the libraries. This also covers a driver update and a cache the driver emptied. - An update that carries the prepared shaders over runs the game's --warm-shaders (tools/make_game.py warm_driver_cache): 11 s with the libraries there, about 8 minutes with all of them cold on that card. - A draw whose pipeline is missing waits for its fast link from a budget of 6 ms a presented frame, 3 ms at most each (NX2NAVI_PIPE_LINK_MS), before it is skipped: with warm libraries the link is done within that. - Full-screen draws wait from their 50 ms budget again instead of being skipped (NX2NAVI_PIPE_SKIP = any is the default; fullscreen stays selectable). With warm libraries the wait is a millisecond. The same walk afterwards: libraries 0.3 and 0.7 ms on average, 1,605 draws skipped, 1,473 of them in the scene's first 600 frames and 8 to 80 in each 600 after, and 19 waits of 60 ms in all. First visits to four other saves (a mountain pass, the Lost Woods, Kokiri Forest, a river) waited 12 to 84 ms in all except the Lost Woods, where mesh shader pipelines, which have no stage libraries, and vertex libraries that need added outputs still compiled once: 23 waits, 2.1 s in all, the longest 776 ms. The texture cache counted its waits in presents chosen at 60 a second: at 165 presents a second the 1800 that stood for thirty seconds were 11 s, so a released render target went sooner than meant and a texture out of view for 11 s was retired and showed its stand-in for some frames when it came back. The counts are now taken times the present rate over 60 (presents_for), and a texture is retired after two minutes without a sample instead of thirty seconds. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -3249,23 +3249,53 @@ static void foliage_shadow_cull(const VkExec *ex, VkPipeState *s) {
|
||||
// buffer or g-buffer with a colour target the frame before did not use: half-resolution effect buffers in fights).
|
||||
// Passes with none (volumes, LUTs, shadow layers seen for the first time) still wait, and so do passes whose only
|
||||
// recent target is the depth buffer while a colour target is rendered for the first time (item icon captures).
|
||||
// fullscreen (2, default): as any, and full-screen draws into such passes are skipped instead of waiting from their
|
||||
// Full-screen draws into such passes wait from their budget of 50 ms a presented frame. The default: a skipped
|
||||
// full-screen draw is a lighting, fog or tone mapping pass that leaves its target as it was, which shows as a black
|
||||
// or unlit frame with the interface intact, and with the stage libraries in the driver's cache the wait is a
|
||||
// millisecond (vk_pipeline.c lw_start keeps them there).
|
||||
// fullscreen (2): as any, and full-screen draws into such passes are skipped instead of waiting from their
|
||||
// budget. A full-screen pass whose stage libraries are cold in the driver cache took 86 ms on average (up to 194 ms)
|
||||
// in a fight on an RX 9070: three frames in a row each spent the 50 ms budget, and some of the draws were skipped
|
||||
// after all. Skipping costs the pass for the frames until the pipeline is ready.
|
||||
// after all. Skipping costs the pass for the frames until the pipeline is ready. It was the default until the
|
||||
// libraries were kept warm.
|
||||
// Any other draw whose pipeline is missing waits for its fast link from a small budget per presented frame
|
||||
// (link_budget) before it is skipped.
|
||||
static int pipe_skip_mode(void) {
|
||||
static int mode = -1;
|
||||
if (mode < 0) {
|
||||
const char *e = cfg_value("NX2NAVI_PIPE_SKIP");
|
||||
mode = !strcmp(e, "strict") || !strcmp(e, "0") ? 0 : !strcmp(e, "fullscreen") || !strcmp(e, "2") ? 2 : 1;
|
||||
static const char *const what[3] = {"only draws into per-frame passes (NX2NAVI_PIPE_SKIP=strict)",
|
||||
"draws into passes with a target the previous frame rendered",
|
||||
"draws into passes with a target the previous frame rendered; full-screen "
|
||||
"draws wait (NX2NAVI_PIPE_SKIP=any)",
|
||||
"those and full-screen draws (NX2NAVI_PIPE_SKIP=fullscreen)"};
|
||||
rt_log("vk_exec: draws skipped while their pipeline builds: %s", what[mode]);
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
// NX2NAVI_PIPE_LINK_MS (default 6; 0 = off): how long the draws of one presented frame may wait, in all, for the fast
|
||||
// link of a pipeline that is missing, LINK_DRAW_MS at most each. A draw into a per-frame pass used to be skipped at
|
||||
// once and for as long as its pipeline built, also when its stage libraries were in the driver's cache and the link
|
||||
// took under a millisecond: geometry seen for the first time (ground, a wall, a character) was missing for a frame or
|
||||
// more and then appeared. With the libraries warm the wait ends within the budget and nothing is skipped; with them
|
||||
// cold it runs out after a few draws and the rest are skipped as before, so a burst of cold pipelines costs a frame
|
||||
// this much and no more. Measured on an RX 7900 XT, first walk through a village with no pipeline recorded: 2,349
|
||||
// draws skipped without the budget, with the libraries warm in both runs.
|
||||
#define LINK_DRAW_MS 3u
|
||||
static uint64_t *link_budget(void) {
|
||||
static uint64_t frame = ~0ull, left, per_frame = ~0ull;
|
||||
if (per_frame == ~0ull) {
|
||||
long long ms = cfg_int("NX2NAVI_PIPE_LINK_MS");
|
||||
per_frame = (uint64_t)(ms < 0 ? 0 : ms > 100 ? 100 : ms) * 1000000ull;
|
||||
rt_log("vk_exec: draws wait up to %llu ms a frame in all for the fast link of a missing pipeline "
|
||||
"(NX2NAVI_PIPE_LINK_MS)", (unsigned long long)(per_frame / 1000000));
|
||||
}
|
||||
uint64_t f = __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED);
|
||||
if (f != frame) frame = f, left = per_frame;
|
||||
return &left;
|
||||
}
|
||||
|
||||
// The previous draw's shaders, kept while its program, bound pipeline state, the vertex and fragment stages' first 32
|
||||
// texture and image handles and every slot's resolution (vk_texture_slots_gen, read unlocked: a registration racing
|
||||
// with it is ordered after this draw, as answers_for's own check would order it) stay the same: answers_for reads
|
||||
@@ -3461,6 +3491,7 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int
|
||||
uint32_t wait_ms = 0;
|
||||
uint64_t t0 = 0;
|
||||
uint64_t *budget = NULL; // the per-frame budget a timed wait is charged to
|
||||
int linking = 0; // the wait is the short one for a fast link (link_budget)
|
||||
int large = (uint64_t)ex->pass_w * ex->pass_h >= ONESHOT_LARGE_PX;
|
||||
if (oneshot > 0 && oneshot_budget_on()) {
|
||||
budget = oneshot_budget(large);
|
||||
@@ -3474,6 +3505,12 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int
|
||||
wait_ms = (uint32_t)(wait_left_ns / 1000000);
|
||||
if (wait_ms) t0 = kern_now_ns();
|
||||
budget = &wait_left_ns;
|
||||
} else {
|
||||
budget = link_budget();
|
||||
wait_ms = (uint32_t)(*budget / 1000000);
|
||||
if (wait_ms > LINK_DRAW_MS) wait_ms = LINK_DRAW_MS;
|
||||
linking = wait_ms != 0;
|
||||
if (!wait_ms) budget = NULL;
|
||||
}
|
||||
// The previous draw's pipeline while its state repeats (PM, NX2NAVI_PIPE_MEMO=0 turns it off): the cache key is made
|
||||
// from the state alone, and a pipeline once found only changes from its fast link to its optimised build, read
|
||||
@@ -3485,13 +3522,21 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int
|
||||
info = PM.info, pending = 0;
|
||||
p = __atomic_load_n(&info->pipeline, __ATOMIC_ACQUIRE);
|
||||
} else {
|
||||
w0 = t0 ? t0 : wait_ms ? kern_now_ns() : 0; // the clock is read only for draws that may wait
|
||||
p = vk_pipeline_graphics_async(&s, &info, &pending, wait_ms);
|
||||
if (linking) { // nearly every draw finds its pipeline: the clock is read only for one that did not
|
||||
p = vk_pipeline_graphics_async(&s, &info, &pending, 0);
|
||||
if (pending) {
|
||||
t0 = kern_now_ns();
|
||||
p = vk_pipeline_graphics_async(&s, &info, &pending, wait_ms);
|
||||
}
|
||||
} else {
|
||||
w0 = t0 ? t0 : wait_ms ? kern_now_ns() : 0; // the clock is read only for draws that may wait
|
||||
p = vk_pipeline_graphics_async(&s, &info, &pending, wait_ms);
|
||||
}
|
||||
if (t0 && budget) {
|
||||
uint64_t spent = kern_now_ns() - t0;
|
||||
*budget = spent < *budget ? *budget - spent : 0;
|
||||
}
|
||||
why = oneshot > 0 ? "one-shot, shader" : wait_ms ? "full-screen" : NULL;
|
||||
why = oneshot > 0 ? "one-shot, shader" : linking ? NULL : wait_ms ? "full-screen" : NULL;
|
||||
if (pending && oneshot < 0 && !vk_exec_targets_recent(ex, skip >= 1)) {
|
||||
perf_count(PERF_CNT_ONESHOT_WAIT);
|
||||
why = "one-shot";
|
||||
|
||||
Reference in New Issue
Block a user