diff --git a/AUDIT.md b/AUDIT.md index c474a278..bfa900a8 100644 --- a/AUDIT.md +++ b/AUDIT.md @@ -1150,7 +1150,7 @@ back. | 115 | Pipeline layouts, set layouts, update templates | `P.lock` | None found | Shutdown | | 116 | Stage libraries `libs[1024]` chained; failed builds cached as null | `P.lock` | None found | Shutdown (`libs_destroy`) | | 117 | Library and pipeline job queues | `P.lock` | None found | When built; dropped at shutdown | -| 118 | `VkPipelineCache` in memory and `pipeline-cache.bin` | `cache_rw`, `save_lock` | File > `NX2NAVI_PIPELINE_CACHE_MAX_MB` (512) starts empty; in memory: the driver's, none found | Saved by "pipe autosave" at most every 20 s and at exit (waits ≤ 5 s) | +| 118 | `VkPipelineCache` in memory and `pipeline-cache.bin` | `cache_rw`, `save_lock` | File > `NX2NAVI_PIPELINE_CACHE_MAX_MB` (1024) starts empty; in memory: the driver's, none found | Saved by "pipe autosave" at most every 20 s and at exit (waits ≤ 5 s) | | 119 | Pipeline binaries `pipeline-binaries.bin` | `PB.lock` | `NX2NAVI_PIPE_BINARIES_MAX_MB` 1024; `NX2NAVI_PIPE_BINARIES` default 0 | — | | 120 | `pipeline-keys.bin` and its `seen` set | `K.io` | None found (append-only) | Never | | 121 | `compute-used.bin` | `cu_io` | `NX2NAVI_COMPUTE_KEEP` 512 | — | diff --git a/nx2navi.ini.example b/nx2navi.ini.example index 076febae..2f107f78 100644 --- a/nx2navi.ini.example +++ b/nx2navi.ini.example @@ -188,8 +188,10 @@ # build_reserve_mb = 64 # 1: the log says how many pipelines came from pipeline-cache.bin; 2 also logs every compute pipeline built. 0: off. # pipe_feedback = 1 -# pipeline-cache.bin larger than this (MB) starts empty and is rewritten (0: no limit). -# pipeline_cache_max_mb = 512 +# pipeline-cache.bin larger than this (MB) starts empty and is rewritten (0: no limit). With the pipeline list of +# 0.9.1 and later a full cache is about 550 MB on an NVIDIA card, so the limit has to stay well above that: under +# it the cache is thrown away at every start and the pipelines are built again each time. Default: 1024. +# pipeline_cache_max_mb = 1024 # 1: the pipelines a run compiles go into pipeline-cache-play.bin, a small file of its own, so pipeline-cache.bin # (hundreds of MB) is not written again while you play; the small file is folded into the large one at a start once # it has grown. 0: one file, written whole whenever a run made a new pipeline. @@ -211,6 +213,13 @@ # Count the shared pipeline list that comes with the release (seed-pipeline-keys.bin) as known pipelines, so a new # install builds them at the start instead of at their first draw. 0: only the pipelines this install drew. # pipe_seed = 1 +# Whether the start builds the pipelines of that list which this install has never drawn. They take 2 to 4 GB of +# memory (commit) on an NVIDIA card and about 1.5 GB on an AMD one for the whole run, drawn or not. +# auto (default): built at the start, except on a PC that starts with less memory free than the game takes in play +# (the start's "this machine has ... MB of memory left for the game" warning): there each is made at its first +# draw, from the pipeline cache, and built at the start from then on. +# 1: always built at the start. 0: never; a first visit to an area can then hold a frame for a moment. +# pipe_seed_boot = auto # 1: the start waits until every known pipeline is built. Default 0: with the graphics pipeline library the start # builds them for at most 20 seconds and the rest in the background while you play. # prewarm_full = 0 diff --git a/runtime/cfg.c b/runtime/cfg.c index 0d843815..c50354f3 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -59,7 +59,7 @@ static const char *const known[] = { "MOTION_GUARD_DEGREES", "MOTION_POLICY_TRACE", "SELECTIVE_MOTION", "SELECTIVE_MOTION_RAW", // motion_owner.c, vk_fg_pose.inc "MVOBJ_ALL", "MVOBJ_BANKS", "MVOBJ_EQUAL", "MVOBJ_EXACT", "MVOBJ_EXEC", "MVOBJ_NOC4", "MVOBJ_ONLY", "MVOBJ_TIMES", "MVPREV_CHECK", "MVPREV_GROW", "MVPREV_SKIP", "MVPREV_TRUST", "MV_CHECK", "MV_SURVEY", - "ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PACE_HZ", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_RES_FIXED", "PATCH_SCENE", "PATCH_WIDE_ASPECT", "PATCH_WIDE_HUD", "PATCH_WIDE_MOVIE", "PATCH_WIDE_OUT", "PATCH_FREECAM", "PATCH_WIDE_SCENE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPELINE_CACHE_MAX_MB", "PIPELINE_CACHE_PLAY", "PIPELINE_CACHE_PLAY_MB", "PIPE_BINARIES", "PIPE_BINARIES_MAX_MB", "PIPE_FEEDBACK", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SEED", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "POWER_FULL", "TEX_SAME", "TEX_SAME_BIG", "TEX_FLAT3D", "TEX_KEEP_TAKEN", "TEX_STALE_KEPT", "PRESENT_HELD", "HELD_SYNC", + "ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PACE_HZ", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_RES_FIXED", "PATCH_SCENE", "PATCH_WIDE_ASPECT", "PATCH_WIDE_HUD", "PATCH_WIDE_MOVIE", "PATCH_WIDE_OUT", "PATCH_FREECAM", "PATCH_WIDE_SCENE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPELINE_CACHE_MAX_MB", "PIPELINE_CACHE_PLAY", "PIPELINE_CACHE_PLAY_MB", "PIPE_BINARIES", "PIPE_BINARIES_MAX_MB", "PIPE_FEEDBACK", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SEED", "PIPE_SEED_BOOT", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "POWER_FULL", "TEX_SAME", "TEX_SAME_BIG", "TEX_FLAT3D", "TEX_KEEP_TAKEN", "TEX_STALE_KEPT", "PRESENT_HELD", "HELD_SYNC", "PREPARE_PIPELINES", "PREWARM_FULL", "PREWARM_WAIT_MS", "PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES", "PROFILE_REPLAY", "PROFILE_SLOW", "POOL_FAST", "POOL_GROUP", "POOL_GROUP_CHECK", "POOL_PRESNAP", "POOL_PRESNAP_RUNS", "SUBMIT_FINISH_GPU", "SVC_WAITS", "SNAP_WIDEN", "SUBMIT_FINISH_RESULTS", "SUBMIT_FINISH_KINDS", "FOLIAGE", "MIRROR_STAGE", "FLUSH_SKIP_CLEAN", "MIRROR_HOT", "MESH_EMULATION", "MESH_EMU_MB", "MESH_EMU_TASKS", "MESH_EMU_BATCH", "GUEST_OPT", "LOG_TEX_NEW", "DUMP_KEY", "VEC_INDEX_FIX", "PASS_TIMES", @@ -141,7 +141,7 @@ static const struct { const char *key, *section; } sections[] = { {"TIMER_1MS", "performance"}, {"PIPE_WAIT", "performance"}, {"PIPE_SKIP", "performance"}, {"ONESHOT_BUDGET", "performance"}, {"PIPE_FRAME_WAIT_MS", "performance"}, {"PIPE_SKIP_STEADY", "performance"}, {"CACHE_DIE", "performance"}, {"ONE_PER_CORE", "performance"}, - {"LIB_PREBUILD", "performance"}, {"LIB_PREBUILD_THREADS", "performance"}, {"LIB_WARM", "performance"}, {"PIPE_LINK_MS", "performance"}, {"PIPE_LINK_DRAW_MS", "performance"}, {"PIPE_AHEAD", "performance"}, {"LINE_WIDTH", "performance"}, {"POOL_SHOWN_FIRST", "performance"}, {"TEX_REUSE_NAMED", "performance"}, {"TEX_OVERWRITTEN_USED", "performance"}, {"PIPE_FAST_WORKERS", "performance"}, {"GPL_FEEDBACK", "performance"}, {"FRAME_HOLD_MS", "performance"}, {"PACE_SMOOTH", "performance"}, {"OQ_BATCH", "performance"}, {"GATE_WAIT_MS", "performance"}, {"PIPE_PREBUILD", "performance"}, {"PIPE_SEED", "performance"}, + {"LIB_PREBUILD", "performance"}, {"LIB_PREBUILD_THREADS", "performance"}, {"LIB_WARM", "performance"}, {"PIPE_LINK_MS", "performance"}, {"PIPE_LINK_DRAW_MS", "performance"}, {"PIPE_AHEAD", "performance"}, {"LINE_WIDTH", "performance"}, {"POOL_SHOWN_FIRST", "performance"}, {"TEX_REUSE_NAMED", "performance"}, {"TEX_OVERWRITTEN_USED", "performance"}, {"PIPE_FAST_WORKERS", "performance"}, {"GPL_FEEDBACK", "performance"}, {"FRAME_HOLD_MS", "performance"}, {"PACE_SMOOTH", "performance"}, {"OQ_BATCH", "performance"}, {"GATE_WAIT_MS", "performance"}, {"PIPE_PREBUILD", "performance"}, {"PIPE_SEED", "performance"}, {"PIPE_SEED_BOOT", "performance"}, {"COMPUTE_KEEP", "performance"}, {"PREWARM_XLATE", "performance"}, {"GPL", "performance"}, {"ASTC", "performance"}, {"MEMORY", "performance"}, {"TEX_ALIAS", "performance"}, {"DEPTH_INIT_INLINE", "performance"}, {"DEPTH_ALIAS_LOG", "diagnostics"}, {"TEX_DISUSE", "performance"}, {"TEX_DISUSE_EVICT", "performance"}, {"TEX_GEN_UNDO", "performance"}, {"TEX_REUSE", "performance"}, {"TEX_SPLIT_FILL", "performance"}, {"TEX_VRAM_PRESSURE", "performance"}, {"TEX_PROC_COMMIT_MB", "performance"}, {"ASTC_BC", "performance"}, {"LOD_GUARD", "performance"}, {"FIX_C0", "performance"}, {"FIX_ZERO", "performance"}, {"WATER_PROJECTIVE", "performance"}, @@ -298,10 +298,10 @@ static const CfgMeta metas[] = { {"GATE_WAIT_MS", "10", "0..100", RESTART}, // vk_exec.c vk_exec_gate_wait {"LIB_PREBUILD", "1", "0|1", RESTART}, {"LIB_PREBUILD_THREADS", "", "1..64", RESTART}, {"LIB_WARM", "1", "0|1|force", RESTART}, // vk_pipeline.c lw_start: the driver's cache of stage libraries, warmed when cold - {"PIPE_PREBUILD", "1", "0|1", RESTART}, {"PIPE_SEED", "1", "0|1", RESTART}, // vk_pipeline.c keys_open_seed + {"PIPE_PREBUILD", "1", "0|1", RESTART}, {"PIPE_SEED", "1", "0|1", RESTART}, {"PIPE_SEED_BOOT", "auto", "0|1|auto", RESTART}, // vk_pipeline.c keys_open_seed {"PREWARM_XLATE", "", "1..64", RESTART}, {"GPL", "", "0|1", RESTART}, // vk_caps.c vk_caps_gpl: by the driver, off with AMD's for RDNA 2 and older {"LIB_PREBUILD_BIG_BG", "1", "0|1", RESTART}, {"PIPE_FEEDBACK", "1", "0|1|2", RESTART}, - {"PIPELINE_CACHE_MAX_MB", "512", "0..65536", RESTART}, + {"PIPELINE_CACHE_MAX_MB", "1024", "0..65536", RESTART}, {"FFX_PIPE_CACHE", "1", "0|1", RESTART}, // vk_ffx.cpp vk_ffx_proc_addr: FSR 3.1's pipelines through the pipeline caches {"PIPELINE_CACHE_PLAY", "1", "0|1", RESTART}, {"PIPELINE_CACHE_PLAY_MB", "64", "1..65536", RESTART}, // vk_pipeline.c "the play cache": what a run compiles goes into a file of its own {"PIPE_BINARIES", "0", "0|1", RESTART}, {"ONESHOT_WAIT_MS", "30000", "0..60000", RESTART}, {"ONESHOT_BUDGET", "1", "0|1", RESTART}, {"PIPE_BINARIES_MAX_MB", "1024", "0..65536", RESTART}, {"BIG_BUILD_FREE_MB", "8192", "0..262144", RESTART}, diff --git a/runtime/vk_pipeline.c b/runtime/vk_pipeline.c index 37f59814..36040e6e 100644 --- a/runtime/vk_pipeline.c +++ b/runtime/vk_pipeline.c @@ -46,6 +46,7 @@ #include "mesh_emu_spirv.h" #include "gfx.h" #include "host.h" +#include "mem_need.h" #include "nvn_hmap.h" #include "platform/platform.h" #include "prp_file.h" @@ -746,8 +747,12 @@ static VkResult pipe_create(int kind, void *ci, VkPipeline *pipe) { // The data of the pipeline cache file at path for vkCreatePipelineCache (malloc'd, its size in *size), NULL when the // run starts without it, which the log says with the file's size. Cache data whose header names another device or // driver is dropped before Vulkan sees it. -// NX2NAVI_PIPELINE_CACHE_MAX_MB (default 512; 0 no limit): a larger file starts the run empty, and the run's -// saves replace it. The file only grows: entries of earlier translators and builds stay, and on NVIDIA +// NX2NAVI_PIPELINE_CACHE_MAX_MB (default 1024; 0 no limit): a larger file starts the run empty, and the run's +// saves replace it. The limit has to stay above what one run builds, or nothing ever replaces the file: at 512, with +// the pipeline list of 0.9.1 (8,849 records), an RTX 2080 Ti's file held 551 MB and the play file the run then wrote +// 541 MB, so both were dropped at every start, 7,247 of 8,531 pipelines were built again in each (17 s of the +// boot) and 541 MB were written again in each session (cache_load says so when both files are over). The file only +// grows: entries of earlier translators and builds stay, and on NVIDIA // (621.01) an entry another executable wrote is neither used nor written again, so a renamed or updated exe // compiles while the file keeps its size (2026-11-09: 650 MB, 15-18 % of the pipelines read from it). The // whole file sits in process memory twice at the boot (this read and the driver's copy) and is copied out @@ -830,6 +835,10 @@ static void cache_load(VkCtx *c) { int want = cfg_bool("NX2NAVI_PIPELINE_CACHE_PLAY") && !prep_mode, on = want && P.cache_control; size_t psize = 0, pkept = 0; void *pdata = cache_data_read(c, P.play_path, &psize); + if (base_over && cache_over_cap) // what one run builds is over the limit: nothing will ever replace either file + rt_log("vk_pipeline: both pipeline cache files are over NX2NAVI_PIPELINE_CACHE_MAX_MB, so what one run builds does " + "not fit it: this start builds every pipeline again, and so will each one after it until the limit is " + "raised above the play file's size (pipeline_cache_max_mb in nx2navi.ini; 0 = no limit)"); VkPipelineCache play = psize || on ? cache_make(c, pdata, psize, &pkept) : VK_NULL_HANDLE; free(pdata); uint64_t fold_at = (uint64_t)strtoull(cfg_value("NX2NAVI_PIPELINE_CACHE_PLAY_MB"), NULL, 10) << 20; @@ -4173,6 +4182,7 @@ static struct { uint32_t pend_n, pend_cap; uint8_t *file; // the file as read at boot, until the prewarm is done with it size_t file_n; // records in it + size_t own_n; // of them, the first ones: this install's own (keys_open); the shared list's follow PlatMutex io; // one writer // prebuild progress (under P.lock) int loading; // the prewarm still queues records @@ -4276,6 +4286,7 @@ static void keys_open_seed(void); static void keys_open_own(void); static void keys_open(void) { keys_open_own(); + K.own_n = K.file_n; if (K.path[0]) keys_open_seed(); } @@ -5287,6 +5298,30 @@ void vk_pipeline_prewarm(void) { __atomic_store_n(&pw_phase, 3, __ATOMIC_RELEASE); } +// NX2NAVI_PIPE_SEED_BOOT (auto, the default; 1; 0): whether the boot builds the pipelines of the shared list that this +// install has never drawn (keys_open_seed), 1, or leaves them to their first draw, 0. Built at boot they are there +// when a draw first needs them, which is what the list is for, and every one is a pipeline the driver holds for the +// whole run: with the list of 0.9.1 the boot's pipeline stage went from about 1.6 GB of commit (0.8.0, 3,256 +// pipelines on an RTX 5080) to 3.9-4.4 GB (8,531 on an RTX 2080 Ti, 6,977 on an RTX 5070 Ti) and 0.3-0.6 GiB of +// video memory, 1.5-1.8 GB of commit on AMD's driver, of which the list's share is half to nearly all. On a machine +// that has that to spare it buys the first visit of every area without a wait. On one that starts short of the +// commit the game takes in play (mem_need.h, the start's own warning) it is memory taken from the game for +// pipelines that may never be drawn, and running out of commit ends the game (a failed allocation or a lost device). +// auto leaves them out there and only there. A pipeline left out is made at its first draw as any new one is, from +// pipeline-cache.bin when the preparation built it (0.5-0.8 ms on a worker), and is the install's own from then on: +// the next start builds it at boot. Mesh pipelines are built at boot either way: they have no fast link, and a draw +// waits for the whole build. The list's pairs still count in the vertex output unions, so the modules stay the ones +// the preparation built. +static int seed_boot(void) { + static int on = -1; + if (on >= 0) return on; + const char *e = cfg_get("NX2NAVI_PIPE_SEED_BOOT"); + if (e && (!strcmp(e, "0") || !strcmp(e, "1"))) return on = e[0] == '1'; + double proc, used, limit, need = strtod(cfg_value("NX2NAVI_MEM_NEED_MB"), NULL); + plat_commit_info(&proc, &used, &limit); + return on = !mem_need_short(proc, used, limit, need); +} + static void prewarm_run(void) { const char *gpu = rt_config()->gpu; uint32_t pr_hist[16] = {0}, fs_hist[4] = {0}; // library state of the recorded pipelines (lb_start) @@ -5354,7 +5389,8 @@ static void prewarm_run(void) { return; } pm_set(); - uint32_t queued = 0, dropped = 0, known = 0; + uint32_t queued = 0, dropped = 0, known = 0, listed = 0; + int at_boot = seed_boot(); plat_mutex_lock(&P.lock); K.t0 = t1; K.loading = 1; @@ -5385,6 +5421,10 @@ static void prewarm_run(void) { pr_hist[(k.clamp & 1) | (k.poly_mode & 3) << 1 | (k.minus_w & 1) << 3]++; fs_hist[k.samples >= 8 ? 3 : k.samples >= 4 ? 2 : k.samples >= 2 ? 1 : 0]++; } + if (!at_boot && i >= K.own_n && !is_mesh(&s)) { // of the shared list alone: made at its first draw (seed_boot) + listed++; + continue; + } uint64_t h = key_hash(&k, sizeof k); int q = 0; if (pipe_find(&k, sizeof k, h)) known++; @@ -5392,6 +5432,13 @@ static void prewarm_run(void) { } K.loading = 0; plat_mutex_unlock(&P.lock); + if (listed) { + const char *e = cfg_get("NX2NAVI_PIPE_SEED_BOOT"); + rt_log("vk_pipeline: prewarm: %u records of the shared pipeline list that this install has not drawn are left to " + "their first draw, when pipeline-cache.bin gives them (NX2NAVI_PIPE_SEED_BOOT=%s%s)", listed, + e && !strcmp(e, "0") ? "0" : "auto", + e && !strcmp(e, "0") ? "" : ": this machine started with less commit free than the game takes in play"); + } free(ids), free(sh); __atomic_store_n(&pw_pipe_done, 0, __ATOMIC_RELAXED);