From caf50ecf1c6639974cb452fa66102730b6a9c7ff Mon Sep 17 00:00:00 2001 From: chrg6 Date: Tue, 10 Nov 2026 15:14:25 -0500 Subject: [PATCH 1/5] Turn the lazy write-back off by default on AMD's driver for RX 5000 and 6000 cards, and say in the log which settings a run had. A player on an AMD card reported crashes in fights and that a line added to nx2navi.ini cured them. That line, async_compute = 1, is no setting of the game, and neither are two more in the same file; the one line of the file that changes how memory reaches the GPU is wb_lazy = 0. A second report, an RX 6600 on 0.7.1, lost its device 3.5 minutes into play with the lazy write-back on. Neither proves it the cause: the player changed several lines at once and sent no log, the RX 6600's last pass mark is inside a draw pass and not a fetch, cards with 8 GB lost their device the same way on NVIDIA before the lazy write-back existed, and reading the fault handler, the fetch, the arming and the buffers' lifetimes found no failure path. What depends on the driver and cannot be checked without the card: pages of guest memory are inaccessible while a host-pointer import of them is bound and written by the GPU, and Vulkan calls run inside the access-fault handler. The default is now decided once the driver is known (wb_lazy_choice.h, vk_memory.c vk_mem_lazy_decide): on under Windows as before, except on AMD's driver branch for RDNA 1 and 2, which none of us has run it on; AMD's driver for RDNA 3 and newer keeps it on, since builds with that default were measured on an RX 7900 XT. What the player sets wins everywhere, and one line at start says the choice and its reason. On those cards open areas run at the 0.7.0 frame rate again (on an RTX 5090 that was 65 fps against 90 in Hyrule Field; not measured on AMD). tests/wb_lazy_check.c checks the choice by platform, driver and setting without a GPU. For reports of this kind the log now holds what was missing. At start: every setting nx2navi.ini sets, and in one line the keys that are no settings of this version and do nothing; the settings menu shows those in its bottom row. At a fatal error or a crash: one line with the card, its driver, the memory mode, the lazy write-back with its reason, armed ranges, fetches so far and a fetch in progress, and the texture detail (dispatch.c rt_fatal_note_add, vk_device.c fatal_note), since a report is often the end of a log alone. --probe-cfg loads the player's file: the three lines are named, and the menu's save keeps them and every other line it does not change byte for byte. Nothing here ran on an AMD card, and no fatal error was provoked to read the new line. Co-Authored-By: Claude Fable 5.2 --- nx2navi.ini.example | 15 +++++-- runtime/cfg.c | 74 ++++++++++++++++++++++++++++++++- runtime/cfg.h | 4 ++ runtime/cfg_probe.c | 79 +++++++++++++++++++++++++++++++++++ runtime/dispatch.c | 17 ++++++++ runtime/dispatch.h | 5 +++ runtime/host.h | 1 + runtime/main.c | 1 + runtime/memory.c | 34 ++++++++++++++- runtime/ui/menu.cpp | 21 +++++++++- runtime/ui_text.c | 4 ++ runtime/ui_text.h | 1 + runtime/vk.h | 9 +++- runtime/vk_caps.c | 7 ++++ runtime/vk_device.c | 11 +++++ runtime/vk_memory.c | 42 ++++++++++++++++--- runtime/vk_texture.c | 13 +++++- runtime/wb_lazy_choice.h | 63 ++++++++++++++++++++++++++++ tests/wb_lazy_check.c | 90 ++++++++++++++++++++++++++++++++++++++++ tests/wb_lazy_check.py | 31 ++++++++++++++ 20 files changed, 504 insertions(+), 18 deletions(-) create mode 100644 runtime/wb_lazy_choice.h create mode 100644 tests/wb_lazy_check.c create mode 100644 tests/wb_lazy_check.py diff --git a/nx2navi.ini.example b/nx2navi.ini.example index 891b1845..de5459e9 100644 --- a/nx2navi.ini.example +++ b/nx2navi.ini.example @@ -2,6 +2,10 @@ # Each line shows the default; on a Steam Deck the device profile ([display]) changes a few of them. A NX2NAVI_* # environment variable of the same name (NX2NAVI_FPS_LIMIT for fps_limit) overrides the file. Keys are case-insensitive; # '#' and ';' start a comment; [sections] only group lines. +# Only the keys in this file are settings. A line with any other key does nothing: the game's log names it at the +# start ("no setting of this version") and the settings menu (F1) shows it in its bottom row. +# Updates and rebuilds of the game never rewrite nx2navi.ini; the settings menu changes only the lines of the settings +# it changes and keeps every other line as it is. [frame rate] # Frame rate limit: 30, 40, 45, 60, 90, 120, 144, any whole rate from 30 to 240, display (the refresh rate of the @@ -729,10 +733,13 @@ # first submission ends when that submission's passes are through, without waiting for the copy back (3 to 4 ms of # every frame). 0: the copy back is part of the submission, and the wait covers it. # wb_split = 1 -# 1 (the default on Windows): what the game's shaders write into its memory is copied back from the video card once, -# and after that only when the game's CPU code touches it (most of it never is: 66 MiB a frame in Hyrule Field), for -# about a third more frames a second in open areas. 0: copied back at the end of every GPU submission, as in 0.7.0. -# With shadow storage (Linux, Wine) it stays off. +# 1: what the game's shaders write into its memory is copied back from the video card once, and after that only when +# the game's CPU code touches it (most of it never is: 66 MiB a frame in Hyrule Field), for about a third more frames +# a second in open areas. 0: copied back at the end of every GPU submission, as in 0.7.0. +# Default: 1 on Windows, except 0 with AMD's driver for RX 5000 and RX 6000 cards, where it has not been tried by us +# and one report lost its device with it on: set 1 there to try it, and back to 0 if the game ends in play (the log's +# "mem: lazy write-back" line says which is in effect and why). 0 elsewhere. With shadow storage (Linux, Wine) it +# stays off whatever is set. # wb_lazy = 1 # Barriers between the game's draw passes and compute dispatches. 1: only where the game itself asks for one, or where # the work changes between drawing and compute; this takes about a tenth off the graphics card's time for a frame. diff --git a/runtime/cfg.c b/runtime/cfg.c index c2a1d3c7..3815ae6a 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -138,7 +138,10 @@ static const struct { const char *key, *section; } sections[] = { #define LIVE 1 #define RESTART 0 // The lazy write-back (memory.c "Lazy write-back") is on where it has run: its fetch inside the access-fault handler -// has only ever run on Windows. With shadow storage it stays off whatever is set (vk_memory.c wb_lazy). +// has only ever run on Windows. This is the platform's part of the default, which memory.c mem_init goes by to take +// the access faults; the back end then turns it off for a driver it is not trusted on while the key is unset +// (wb_lazy_choice.h: AMD's for RX 5000 and 6000 cards), and with shadow storage whatever is set (vk_memory.c +// vk_mem_lazy_decide). #ifdef _WIN32 #define WB_LAZY_DEFAULT "1" #else @@ -286,9 +289,45 @@ static int is_known(const char *key) { return !strncmp(key, "CHEAT_", 6); // cheats.c and the cheat patch sets (tools/cheats.py) } +// The keys of the file's lines that are not settings of this version (add), lower-case, ", " between them, each once; +// what did not fit is counted and left out. Written by cfg_load, before any other thread reads settings. +static char unknown_keys[384]; +static int n_unknown, unknown_cut; // how many; whether the list left some out + +static void note_unknown(const char *key) { + char low[64]; + size_t n = 0; + for (; key[n] && n < sizeof low - 1; n++) { + // a key of other characters (a line of text with an '=' in it) is counted, not listed: the menu cuts the list + // by bytes to fit its row + if (!isalnum((unsigned char)key[n]) && key[n] != '_') break; + low[n] = (char)tolower((unsigned char)key[n]); + } + if (key[n]) { + n_unknown++, unknown_cut = 1; + return; + } + low[n] = 0; + size_t have = strlen(unknown_keys); + for (const char *p = unknown_keys; (p = strstr(p, low)) != NULL; p += n) // a repeated line counts once + if ((p == unknown_keys || p[-1] == ' ') && (p[n] == ',' || !p[n])) return; + n_unknown++; + if (have + n + 3 > sizeof unknown_keys) { + unknown_cut = 1; + return; + } + snprintf(unknown_keys + have, sizeof unknown_keys - have, "%s%s", have ? ", " : "", low); +} + +const char *cfg_unknown_keys(int *count) { + if (count) *count = n_unknown; + return unknown_keys; +} + static void clear(void) { for (int i = 0; i < n_entries; i++) free(entries[i].key), free(entries[i].value); n_entries = 0; + unknown_keys[0] = 0, n_unknown = unknown_cut = 0; } static char *trim(char *s) { @@ -309,7 +348,10 @@ static void add(char *key, char *value, int line) { size_t vl = strlen(value); if (vl >= 2 && value[0] == '"' && value[vl - 1] == '"') value[vl - 1] = 0, value++; if (!*key) return; - if (!is_known(key)) rt_log("cfg: nx2navi.ini line %d: unknown key '%s'", line, key); + if (!is_known(key)) { + rt_log("cfg: nx2navi.ini line %d: unknown key '%s'", line, key); + note_unknown(key); + } if (!*value) return; // "key =" leaves the setting at its default for (int i = 0; i < n_entries; i++) if (!strcmp(entries[i].key, key)) { // a repeated key: the later line wins @@ -919,6 +961,33 @@ int cfg_save(void) { return 0; } +// What the file sets, in the log once at start: the settings of this version with their values, in lines of up to +// about 900 characters, and then the keys that are no settings of this version, which do nothing. A report's log then +// shows which settings its run had and which of the file's lines had no effect; before, it held only the count of +// keys, and a player who had added a line this version does not read could take it for the cause of what changed. +static void log_file_settings(void) { + char line[1024]; + size_t k = 0; + for (int i = 0; i < n_entries; i++) { + if (!entries[i].value || !is_known(entries[i].key)) continue; + char key[64]; + snprintf(key, sizeof key, "%s", entries[i].key); + for (char *p = key; *p; p++) *p = (char)tolower((unsigned char)*p); + size_t vl = strlen(entries[i].value); + if (vl > 200) vl = 200; // a long value (a list of mods) is cut: the line shows that the key is set + if (k && k + strlen(key) + vl + 5 > 900) { + rt_log("cfg: nx2navi.ini sets: %s", line); + k = 0; + } + k += (size_t)snprintf(line + k, sizeof line - k, "%s%s = %.*s", k ? ", " : "", key, (int)vl, entries[i].value); + } + if (k) rt_log("cfg: nx2navi.ini sets: %s", line); + if (n_unknown) + rt_log("cfg: nx2navi.ini has %d key%s that %s no setting of this version and %s nothing: %s%s", n_unknown, + n_unknown == 1 ? "" : "s", n_unknown == 1 ? "is" : "are", n_unknown == 1 ? "does" : "do", unknown_keys, + unknown_cut ? ", ..." : ""); +} + static void load_ini(void) { if (!find_ini()) return; if (!cfg_load(ini_path)) { @@ -926,6 +995,7 @@ static void load_ini(void) { return; } rt_log("cfg: read %s: %d keys", ini_path, n_entries); + log_file_settings(); for (int i = 0; i < n_entries; i++) { char var[128]; snprintf(var, sizeof var, PREFIX "%s", entries[i].key); diff --git a/runtime/cfg.h b/runtime/cfg.h index 62dc21ed..29753a53 100644 --- a/runtime/cfg.h +++ b/runtime/cfg.h @@ -25,6 +25,10 @@ int cfg_setenv(const char *name, const char *value); int cfg_from_env(const char *name); // 1 when the player set name (the environment or nx2navi.ini), 0 when cfg_get gives a device profile's default or NULL. int cfg_is_set(const char *name); +// The keys of the file's lines that are no settings of this version, lower-case with ", " between them ("" when there +// are none; a list too long to keep ends early), and how many there are. Such a line does nothing: the log says so at +// start and the settings menu shows it (ui/menu.cpp), so that nobody takes one for the cause of what they see. +const char *cfg_unknown_keys(int *count); // The device profile in use, "deck" or "desktop" (NX2NAVI_DEVICE_PROFILE, else what the machine is). const char *cfg_device_profile(void); // Writes the keys cfg_set changed since the last save into nx2navi.ini next to nx2navi.exe (cfg_save_to: the file at path). diff --git a/runtime/cfg_probe.c b/runtime/cfg_probe.c index a10cd1d5..efe5e75e 100644 --- a/runtime/cfg_probe.c +++ b/runtime/cfg_probe.c @@ -71,6 +71,11 @@ int probe_cfg(void) { CHECK(cfg_get("NX2NAVI_CLOTH_REALTIME") == NULL, "absent key is NULL"); CHECK(cfg_get("NX2NAVI_comment") == NULL, "comment is not a key"); CHECK(EQ(cfg_get("NX2NAVI_NO_SUCH_SETTING"), "1"), "unknown key is still readable"); + { + int n = -1; + const char *u = cfg_unknown_keys(&n); + CHECK(n == 2 && EQ(u, "no_such_setting, last"), "the keys that are no settings: listed lower-case, in the file's order"); + } cfg_setenv("NX2NAVI_FPS60", "1"); CHECK(EQ(cfg_get("NX2NAVI_FPS60"), "1"), "environment overrides the file"); cfg_setenv("NX2NAVI_FPS60", NULL); @@ -78,6 +83,80 @@ int probe_cfg(void) { plat_file_delete(path); CHECK(cfg_load(path) == 0, "missing file is not an error"); CHECK(cfg_get("NX2NAVI_FPS60") == NULL, "missing file leaves no keys"); + { + int n = -1; + CHECK(EQ(cfg_unknown_keys(&n), "") && n == 0, "a missing file leaves no unknown keys either"); + } + + // A player's file as a report showed it: settings the menu wrote, and three lines added by hand that are no + // settings of this version (the player took the first for the fix of a crash). The three are named as such, a + // repeated one once, a key of other characters is counted without being listed, and the menu's save keeps every + // line it does not change byte for byte, the three included: only the changed, the reset and the new key move. +#define PLAYER_HEAD \ + "[display]\n" \ + "async_compute = 1\n" \ + "fullscreen = 1\n" \ + "window_size = 1920x1080\n" \ + "gpu_index = 0\n" \ + "perf_overlay = fps\n" \ + "vk_present = mailbox\n" \ + "upscaler = bilinear\n" \ + "dlaa = 1\n" \ + "framegen = off\n" \ + "taa = fsr3\n" \ + "hdr = 0\n" \ + "aspect = fit\n" \ + "game_res = 1800\n" +#define PLAYER_MID \ + "aniso = 2\n" \ + "assume_focus = 1\n" \ + "texture_detail = auto\n" \ + "\n" \ + "[input]\n" \ + "bind_a = key:default, pad:south\n" \ + "bind_b = key:default, pad:east\n" \ + "\n" \ + "[language]\n" \ + "operation_mode = docked\n" \ + "\n" \ + "[performance]\n" \ + "wb_lazy = 0\n" \ + "vram_safe_mode = 1\n" \ + "exception_handler = 1\n" \ + "ASYNC_COMPUTE = 1\n" \ + "f\xC3\xBCr sp\xC3\xA4ter = 1\n" \ + "\n" \ + "[frame rate]\n" + static const char player[] = PLAYER_HEAD "sharpness = 80\n" PLAYER_MID "fps_limit = 120\n"; + static const char player_saved[] = PLAYER_HEAD PLAYER_MID "fps_limit = 60\n\n[audio]\nvolume = 55\n"; +#undef PLAYER_HEAD +#undef PLAYER_MID + cfg_setenv("NX2NAVI_FPS_LIMIT", NULL); + cfg_setenv("NX2NAVI_VOLUME", NULL); + cfg_setenv("NX2NAVI_SHARPNESS", NULL); + cfg_setenv("NX2NAVI_WB_LAZY", NULL); + CHECK(plat_file_write(path, player, sizeof player - 1), "write the player's ini"); + CHECK(cfg_load(path) == 1, "load the player's ini"); + { + int n = -1; + const char *u = cfg_unknown_keys(&n); + CHECK(n == 4 && EQ(u, "async_compute, vram_safe_mode, exception_handler"), + "the player's three lines are named as no settings; a repeat counts once, a key of other characters is only counted"); + CHECK(EQ(cfg_get("NX2NAVI_WB_LAZY"), "0") && cfg_is_set("NX2NAVI_WB_LAZY"), "wb_lazy = 0 is a setting, and set"); + CHECK(!cfg_is_set("NX2NAVI_VK_NAN_PRESERVE"), "a key the file lacks is not set"); + static const char *const reset[] = {"SHARPNESS"}; + cfg_set("NX2NAVI_FPS_LIMIT", "60"); + cfg_set("NX2NAVI_VOLUME", "55"); + CHECK(cfg_reset(reset, 1) == 1 && cfg_save_to(path) == 1, "the menu changes, adds and resets a key and saves"); + uint64_t pn = 0; + uint8_t *p = plat_file_read(path, &pn); + CHECK(p && pn == sizeof player_saved - 1 && !memcmp(p, player_saved, pn), + "the save keeps every other line byte for byte, the lines that are no settings included"); + if (p && (pn != sizeof player_saved - 1 || memcmp(p, player_saved, pn))) fprintf(stderr, "---- saved:\n%s\n----\n", p); + free(p); + } + plat_file_delete(path); + CHECK(cfg_load(path) == 0, "the player's ini is gone again"); // cfg_set / cfg_save: only changed lines move, comments stay, a missing key goes under its section static const char before[] = diff --git a/runtime/dispatch.c b/runtime/dispatch.c index 75d28e01..76afb92b 100644 --- a/runtime/dispatch.c +++ b/runtime/dispatch.c @@ -41,6 +41,22 @@ static uint64_t g_table_bytes, g_functions; static struct { uint64_t addr; GuestFn fn; } g_host[HOST_CAP]; static uint64_t g_nhost; +static void (*fatal_notes[4])(void); +static int n_fatal_notes; + +void rt_fatal_note_add(void (*fn)(void)) { + for (int i = 0; i < n_fatal_notes; i++) + if (fatal_notes[i] == fn) return; + if (n_fatal_notes < (int)(sizeof fatal_notes / sizeof *fatal_notes)) fatal_notes[n_fatal_notes++] = fn; +} + +// Once per process: a second fatal error, on another thread or inside a note, adds none. +void rt_fatal_notes(void) { + static volatile int32_t done; + if (plat_xchg32(&done, 1)) return; + for (int i = 0; i < n_fatal_notes; i++) fatal_notes[i](); +} + void rt_fatal(const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -54,6 +70,7 @@ void rt_fatal(const char *fmt, ...) { double proc, used, limit; plat_commit_info(&proc, &used, &limit); rt_log("fatal: memory commit: this process %.0f MB, the system %.0f of %.0f MB", proc, used, limit); + rt_fatal_notes(); kern_free_cores_note(); prof_sampler_write(); // NX2NAVI_PROFILE: what was sampled until now, else a crash loses the whole profile // RivaTuner Statistics Server's profile as it was: left with the game's limit in it, the next run would take that diff --git a/runtime/dispatch.h b/runtime/dispatch.h index a46e66e3..519d6ea8 100644 --- a/runtime/dispatch.h +++ b/runtime/dispatch.h @@ -51,3 +51,8 @@ RtDispatchStats rt_dispatch_stats(void); // Runtime fatal error: message to stderr, then exit. Used by the dispatcher and the stubs. void rt_fatal(const char *fmt, ...) __attribute__((noreturn, format(printf, 1, 2))); +// Lines of context for a fatal error's report, which rt_fatal and the crash report (main.c crash_handler) write after +// their own: fn logs one with rt_log. It runs on the failing thread, which may hold any lock, so it reads only what +// needs none. At most four; adding one twice keeps one. rt_fatal_notes runs them, once per process. +void rt_fatal_note_add(void (*fn)(void)); +void rt_fatal_notes(void); diff --git a/runtime/host.h b/runtime/host.h index e8af6dde..f2f4fb65 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -196,6 +196,7 @@ int mem_lazy_armed(uint64_t a, uint64_t n); void mem_lazy_window(int open); void mem_lazy_release(uint64_t a, uint64_t n); void mem_lazy_report(uint64_t frame, uint64_t skipped); +void mem_lazy_note(char *out, size_t n); // its state as a phrase, without a lock (a fatal error's line) int mem_lazy_pick(uint64_t *addr, int max); // test: addresses of armed pages int mem_probe(uint64_t a, uint64_t n); // the 2 MiB regions inside [a, a+n) fault on their next access int mem_probing(void); // the probe is on diff --git a/runtime/main.c b/runtime/main.c index 0462cedd..3a599f67 100644 --- a/runtime/main.c +++ b/runtime/main.c @@ -311,6 +311,7 @@ static void crash_handler(const PlatCrash *x) { } else { rt_logf(" not on a guest thread\n"); } + rt_fatal_notes(); // the card, its driver and the memory settings in effect (vk_device.c fatal_note) kern_free_cores_note(); rtss_limit_restore(); // after the report: RivaTuner Statistics Server's profile as it was fflush(stderr); diff --git a/runtime/memory.c b/runtime/memory.c index c8bff935..2fd19de2 100644 --- a/runtime/memory.c +++ b/runtime/memory.c @@ -108,7 +108,8 @@ static void unprobe_locked(uint64_t r) { plat_dec32(&nprb); } -// Lazy write-back (NX2NAVI_WB_LAZY, default 1 on Windows and 0 elsewhere, vk_memory.c "lazy write-back"). It was off +// Lazy write-back (NX2NAVI_WB_LAZY; unset: on under Windows except on AMD's driver for RX 5000 and 6000 cards, off +// elsewhere, as wb_lazy_choice.h decides and gives the reasons for; vk_memory.c "lazy write-back"). It was off // by default in 0.7.0: with it on, single frames came out with the whole scene's shadowing missing, 10 to 180 of 1,800 // presents standing in Hyrule Field with other programs keeping the CPU busy and none found with it off. That was // not this code's doing: frames were drawn from copies taken before the game's signal that their data was written @@ -148,6 +149,12 @@ static uint64_t lz_unclean; // frz_lock: arms refused since the last // frz_lock: since the last report: faults by a read, by a write, other releases, fetches, their bytes and time static uint64_t lz_faults[2], lz_other, lz_fetches, lz_fetch_bytes, lz_fetch_ns, lz_gaps; static volatile uint32_t lz_win_tid; // the replay thread's id while its part is between check and hand-over; 0 else +// For a fatal error's summary line (mem_lazy_note): written under frz_lock and read without it, since the thread that +// fails may be the one inside a fetch. +static volatile uint64_t lz_fetch_total; // fetches since the start +static volatile uint32_t lz_fetch_ms; // plat_now_ms() | 1 at the end of the last one; 0: none yet +static volatile uint32_t lz_fetch_tid; // the thread inside a fetch now; 0: none +static volatile uint64_t lz_fetch_now; // that fetch's bytes static void lazy_flags_locked(uint64_t lo, uint64_t hi) { for (uint64_t r = lo >> FRZ_SHIFT; r <= (hi - 1) >> FRZ_SHIFT; r++) { @@ -165,7 +172,12 @@ static void lazy_drop_locked(int i, int why) { LzSeg s = lzs[i]; if (s.stale && lz_fetch) { uint64_t t0 = plat_now_ns(); + __atomic_store_n(&lz_fetch_now, s.hi - s.lo, __ATOMIC_RELAXED); + __atomic_store_n(&lz_fetch_tid, plat_thread_id(), __ATOMIC_RELEASE); lz_fetch(s.h0, s.h1, (uint64_t)((int64_t)s.lo + s.delta), s.hi - s.lo); + __atomic_store_n(&lz_fetch_ms, (uint32_t)plat_now_ms() | 1, __ATOMIC_RELAXED); + __atomic_store_n(&lz_fetch_total, lz_fetch_total + 1, __ATOMIC_RELAXED); + __atomic_store_n(&lz_fetch_tid, 0, __ATOMIC_RELEASE); lz_fetches++, lz_fetch_bytes += s.hi - s.lo, lz_fetch_ns += plat_now_ns() - t0; } for (uint64_t a = s.lo, b; a < s.hi; a = b) @@ -368,6 +380,24 @@ int mem_lazy_pick(uint64_t *addr, int max) { return k; } +// The lazy write-back's state as a phrase for a fatal error's summary line, "" while nothing is armed by it. No lock: +// the count of armed ranges may be a moment old, and a fetch in progress is named with its thread, which tells a game +// that ended inside a fetch (the device lost under it, or its wait run out) from one that ended elsewhere. +void mem_lazy_note(char *out, size_t n) { + *out = 0; + if (!__atomic_load_n(&lz_on, __ATOMIC_RELAXED)) return; + uint32_t tid = __atomic_load_n(&lz_fetch_tid, __ATOMIC_ACQUIRE), last = __atomic_load_n(&lz_fetch_ms, __ATOMIC_RELAXED); + int k = snprintf(out, n, "%d ranges armed, %llu fetches so far", lz_n, + (unsigned long long)__atomic_load_n(&lz_fetch_total, __ATOMIC_RELAXED)); + if (k < 0 || (size_t)k >= n) return; + if (tid) + snprintf(out + k, n - (size_t)k, ", one of %llu bytes in progress on thread %u%s", + (unsigned long long)__atomic_load_n(&lz_fetch_now, __ATOMIC_RELAXED), tid, + tid == plat_thread_id() ? " (this one)" : ""); + else if (last) + snprintf(out + k, n - (size_t)k, ", the last ended %u ms ago", (uint32_t)plat_now_ms() - last); +} + // One log line since the last one; skipped: the bytes the back end left in the mirror since then. void mem_lazy_report(uint64_t frame, uint64_t skipped) { if (!__atomic_load_n(&lz_on, __ATOMIC_RELAXED)) return; @@ -640,7 +670,7 @@ void mem_init(void) { if (cfg_bool("NX2NAVI_WB_PROBE")) { // a diagnosis: off, no access fault reaches probe_fault and nothing is probed plat_mem_access_hook(access_fault); __atomic_store_n(&prb_on, 1, __ATOMIC_RELEASE); - } else if (cfg_bool("NX2NAVI_WB_LAZY")) { // armed only once the back end can fetch (mem_lazy_enable) + } else if (cfg_bool("NX2NAVI_WB_LAZY")) { // armed once the back end wants it and can fetch (mem_lazy_enable) plat_mem_access_hook(access_fault); lz_want = 1; } diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 957d9f3c..9e7fd90b 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -1531,7 +1531,26 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) { // the save menu's brown buttons, with the game's cursor on the selected one (ui/menu_skin.cpp) float gap = st.ItemSpacing.x + skin_cursor_reach(scale); // right-aligned; in a window too narrow for all three, from the left edge - ImGui::SetCursorPos(ImVec2(fmaxf(st.WindowPadding.x, ImGui::GetWindowWidth() - st.WindowPadding.x - bw * 3 - gap * 2), y)); + const float buttons_x = fmaxf(st.WindowPadding.x, ImGui::GetWindowWidth() - st.WindowPadding.x - bw * 3 - gap * 2); + // Lines of nx2navi.ini that are no settings of this version do nothing (cfg.c cfg_unknown_keys). Said here, in the + // save status's place while saving works, so that a line added by hand is not taken for the cause of what the game + // does: a player took such a line for the fix of a crash. The list is cut to the room left of the buttons. + const char *unknown = cfg_unknown_keys(NULL); + if (cfg_last_save_ok() && *unknown) { + char note[512]; + snprintf(note, sizeof note, menu_text(UI_MENU_INI_UNKNOWN), unknown); + size_t keep = strlen(note), head = keep > strlen(unknown) ? keep - strlen(unknown) : keep; + const float room = buttons_x - st.WindowPadding.x - gap; + while (keep > head && ImGui::CalcTextSize(note).x > room) { + keep--; + snprintf(note + keep, sizeof note - keep, "..."); + } + if (keep > head) { + ImGui::SetCursorPos(ImVec2(st.WindowPadding.x, y + st.FramePadding.y)); + ImGui::TextColored(ImVec4(0.90f, 0.80f, 0.50f, 1), "%s", note); + } + } + ImGui::SetCursorPos(ImVec2(buttons_x, y)); if (skin_widget_button(cont, ImVec2(bw, 0), scale)) set_open(0); ImGui::SameLine(0, gap); if (skin_widget_button(restart, ImVec2(bw, 0), scale)) g_confirm_quit = false, ImGui::OpenPopup("##confirm"); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index faaa02d3..61905516 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -46,6 +46,7 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_ON] = "On", [UI_MENU_OFF] = "Off", [UI_MENU_AUTO] = "Automatic", [UI_MENU_DEFAULT_MARK] = "default", [UI_MENU_AFTER_RESTART] = "after restart", [UI_MENU_SET_BY_ENV] = "set by environment variable", [UI_MENU_SAVE_FAILED] = "could not save settings", + [UI_MENU_INI_UNKNOWN] = "nx2navi.ini: not settings of this version, ignored: %s", [UI_MENU_VERSION] = "NX2navi %s, game %s", [UI_MENU_FULLSCREEN] = "Fullscreen", [UI_MENU_FULLSCREEN_DESC] = "Play in fullscreen. F11 switches it.", @@ -609,6 +610,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_DEFAULT_MARK] = "по умолчанию", [UI_MENU_AFTER_RESTART] = "после перезапуска", [UI_MENU_SET_BY_ENV] = "задано переменной окружения", [UI_MENU_SAVE_FAILED] = "не удалось сохранить настройки", + [UI_MENU_INI_UNKNOWN] = "nx2navi.ini: не настройки этой версии, пропущены: %s", [UI_MENU_VERSION] = "NX2navi %s, игра %s", [UI_MENU_FULLSCREEN] = "Полный экран", [UI_MENU_FULLSCREEN_DESC] = "Игра на весь экран. F11 переключает.", @@ -1166,6 +1168,7 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_DEFAULT_MARK] = "padrão", [UI_MENU_AFTER_RESTART] = "após reiniciar", [UI_MENU_SET_BY_ENV] = "definido por variável de ambiente", [UI_MENU_SAVE_FAILED] = "não foi possível salvar as configurações", + [UI_MENU_INI_UNKNOWN] = "nx2navi.ini: não são configurações desta versão, ignoradas: %s", [UI_MENU_VERSION] = "NX2navi %s, jogo %s", [UI_MENU_FULLSCREEN] = "Tela cheia", [UI_MENU_FULLSCREEN_DESC] = "Jogar em tela cheia. F11 alterna.", @@ -1720,6 +1723,7 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_AFTER_RESTART] = "重启后生效", [UI_MENU_SET_BY_ENV] = "由环境变量设定", [UI_MENU_SAVE_FAILED] = "无法保存设置", + [UI_MENU_INI_UNKNOWN] = "nx2navi.ini:以下不是此版本的设置,已忽略:%s", [UI_MENU_VERSION] = "NX2navi %s,游戏 %s", [UI_MENU_FULLSCREEN] = "全屏", [UI_MENU_FULLSCREEN_DESC] = "全屏运行。按 F11 切换。", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index d22313b1..7d3262b0 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -22,6 +22,7 @@ typedef enum { UI_MENU_AFTER_RESTART, // note on a setting that is read at start UI_MENU_SET_BY_ENV, // note on a setting an environment variable fixes UI_MENU_SAVE_FAILED, + UI_MENU_INI_UNKNOWN, // "...: %s": the keys of nx2navi.ini that are no settings of this version (cfg_unknown_keys) UI_MENU_VERSION, // "NX2navi %s, game %s": the port version and the game update, beside the title // Screen diff --git a/runtime/vk.h b/runtime/vk.h index 5e05bbf9..a6bc9b92 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -63,9 +63,13 @@ typedef struct { int amd_sc; // AMD's Windows driver branch for RDNA 1 and 2 ("AMD proprietary shader compiler") int amd_llpc; // AMD's own driver for RDNA 3 and newer (its driverInfo names LLPC) int mesa; // a Mesa driver the game runs on: RADV, ANV or NVK + uint32_t driver_id; // the device's VkDriverId + char driver_info[256]; // and its driverInfo (VK_MAX_DRIVER_INFO_SIZE) } VkCaps; extern VkCaps vk_caps; -void vk_caps_driver(VkPhysicalDevice p); // first, before vkCreateDevice: vk_caps.amd, amd_sc, amd_llpc, mesa +void vk_caps_driver(VkPhysicalDevice p); // first, before vkCreateDevice: vk_caps.amd, amd_sc, amd_llpc, mesa, driver_id +// The card and its driver in one phrase, for a fatal error's summary line ("" before vk_caps_init). Any thread. +const char *vk_caps_summary(void); void vk_caps_features(VkPhysicalDeviceFeatures *f); // before vkCreateDevice (NX2NAVI_VK_NO_FLOAT64 clears shaderFloat64) // Before vkCreateDevice, with the driver's graphics pipeline library feature and properties: sets vk_caps.gpl, // 1 = enable the extensions (VK_KHR_pipeline_library, VK_EXT_graphics_pipeline_library) and the feature. @@ -337,6 +341,8 @@ int vk_mem_mirror_pending(void); void vk_mem_mirror_prologue(VkCommandBuffer cb); void vk_mem_lazy_part_end(void); // lazy write-back: a part ends (before its prologue), and it is handed over void vk_mem_lazy_handed(void); +void vk_mem_lazy_decide(void); // once the driver is known (after vk_caps_driver): on or off, with one log line +void vk_mem_fatal_note(char *out, size_t n); // the memory mode and the lazy write-back's state, for a fatal error's line // Shadow storage (vk_memory.c): vk_sync.c calls vk_mem_shadow_sync right before each submit; the replay notes every GPU // write into CPU-visible memory at record time (vk_mem_gpu_pending) and reports it at the fence with vk_gpu_written, // which copies the bytes back into guest memory before telling the texture cache (vk_guest_written). @@ -514,6 +520,7 @@ VkSampler vk_sampler_compare_by_id_locked(int id); // Texture detail (vk_texture.c): what texture_detail = auto picks on this device, 0 full, 1 reduced, 2 low (the budget is // read at the first call). For the menu's row. int vk_texture_detail_auto(void); +const char *vk_texture_detail_name(void); // the detail in effect: full, reduced or low; a fatal error's line // The slot's sampler for a texture made without its top `skip` mip levels (VkTexImage.skip): its LOD clamp counts the // game's levels, so it moves down by skip. The slot's own sampler when its clamp is open or skip is 0. VkSampler vk_sampler_detail_by_id_locked(int id, uint32_t skip); diff --git a/runtime/vk_caps.c b/runtime/vk_caps.c index c91041c3..7d9b62de 100644 --- a/runtime/vk_caps.c +++ b/runtime/vk_caps.c @@ -24,6 +24,9 @@ VkCaps vk_caps = {.float64 = 1, .sg_size = 32}; static int f64_supported; static VkBool32 gpl_lib, gpl_fast; // the driver's graphicsPipelineLibrary (feature), ...FastLinking (property) +static char summary[832]; // vk_caps_summary: written once, in vk_caps_init, before any other thread reads it + +const char *vk_caps_summary(void) { return summary; } static uint32_t env_u32(const char *name, uint32_t def) { const char *e = cfg_get(name); @@ -41,6 +44,8 @@ void vk_caps_driver(VkPhysicalDevice p) { VkPhysicalDeviceProperties2 p2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, .pNext = &drv}; vkGetPhysicalDeviceProperties2(p, &p2); vk_caps.amd = p2.properties.vendorID == 0x1002; + vk_caps.driver_id = (uint32_t)drv.driverID; + snprintf(vk_caps.driver_info, sizeof vk_caps.driver_info, "%s", drv.driverInfo); // AMD split RDNA 1 and 2 off into a driver branch of their own; its driverInfo reads // "26.10.1 (AMD proprietary shader compiler)" where the RDNA 3 and 4 driver names LLPC. vk_caps.amd_sc = drv.driverID == VK_DRIVER_ID_AMD_PROPRIETARY && strstr(drv.driverInfo, "shader compiler"); @@ -132,6 +137,8 @@ void vk_caps_init(VkCtx *c) { char dv[32]; driver_version(dv, sizeof dv, c->props.vendorID, c->props.driverVersion); + snprintf(summary, sizeof summary, "%s, driver %s \"%s\" version %s", c->props.deviceName, drv.driverName, + drv.driverInfo, dv); uint32_t v = c->props.apiVersion; VkPhysicalDevice p = c->phys; rt_log("vk caps: %s, vendor %#06x device %#06x, driver %s \"%s\" (id %d, version %s, raw %#x), api %u.%u.%u", diff --git a/runtime/vk_device.c b/runtime/vk_device.c index 485fcaef..980f8670 100644 --- a/runtime/vk_device.c +++ b/runtime/vk_device.c @@ -304,6 +304,15 @@ typedef struct { VkPhysicalDeviceAddressBindingReportFeaturesEXT abr; } FeatureChain; +// One line for a fatal error's report (dispatch.h rt_fatal_note_add): the card, its driver, and the settings in effect +// that change how the game's memory behaves. A report often arrives as the end of a log alone, or as a picture of it, +// and the lines that say these things are at its start. No lock is taken: the failing thread may hold any. +static void fatal_note(void) { + char mem[512]; + vk_mem_fatal_note(mem, sizeof mem); + rt_log("fatal: gpu %s; %s; texture detail %s", vk_caps_summary(), mem, vk_texture_detail_name()); +} + static int create_device(void) { uint32_t ne = 0; vkEnumerateDeviceExtensionProperties(g_vk.phys, NULL, &ne, NULL); @@ -510,6 +519,8 @@ static int create_device(void) { vkGetPhysicalDeviceProperties2(g_vk.phys, &p2); g_vk.min_imported_host_alignment = (uint32_t)emh.minImportedHostPointerAlignment; vk_caps_init(&g_vk); + vk_mem_lazy_decide(); // the driver is known: the lazy write-back's default depends on it + rt_fatal_note_add(fatal_note); VmaAllocatorCreateInfo ai = {.physicalDevice = g_vk.phys, .device = g_vk.device, .instance = g_vk.instance, .vulkanApiVersion = VK_API_VERSION_1_3, diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index e730abea..d6964751 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -21,6 +21,7 @@ #include "vk_dlaa.h" #include "vk_exec.h" #include "vk_gpa.h" +#include "wb_lazy_choice.h" #include "wb_merge_spv.h" #include "platform/platform.h" @@ -2536,7 +2537,7 @@ static void snap_free(void *arg) { // completion thread: the submission is don free(f); } -// ---- lazy write-back (NX2NAVI_WB_LAZY, default 1 on Windows; memory.c "Lazy write-back") +// ---- lazy write-back (NX2NAVI_WB_LAZY; the default by platform and driver, wb_lazy_choice.h; memory.c "Lazy write-back") // A range a shader wrote goes back to guest memory once and is then armed (vk_gpu_written_back, mem_lazy_arm). While it // stays armed, gpu_wrote leaves the later writes of its pages in the mirror: no snapshot, no merge, no copy. When the // CPU touches a page, memory.c calls lazy_fetch with the mirror and the imported buffer of the range: a copy of its @@ -2605,15 +2606,33 @@ static int lazy_clean(uint64_t lo, uint64_t hi, void *ctx) { return mem_written_peek(lo, hi - lo, p, 1) == 0; // UINT64_MAX (not watched) counts as written } +// Whether the lazy write-back is wanted on this device, decided and logged once, when the driver is known +// (vk_device.c create_device, after vk_caps_init): the player's setting, else the default of the platform and driver +// (wb_lazy_choice.h). Never in import mode, where no pool has a mirror; with shadow storage, where a fetch would copy +// the mirror into the pool's buffer, which is guest memory only when the pool is imported (a shadow's bytes reach +// guest memory in the submission's shadow_wb_cb); or with the write-back probe, which watches the same pages. +_Static_assert(WBL_DRIVER_AMD == VK_DRIVER_ID_AMD_PROPRIETARY, "wb_lazy_choice.h names AMD's own driver"); +static int lz_wanted = -1; // -1 not decided, 0 off, 1 on +static const char *lz_why = ""; // the reason the log gave + +void vk_mem_lazy_decide(void) { + const char *set = cfg_is_set("NX2NAVI_WB_LAZY") ? cfg_get("NX2NAVI_WB_LAZY") : NULL; + WblChoice ch = wb_lazy_choice(set, WBL_ON_WINDOWS, vk_caps.driver_id, vk_caps.driver_info); + if (!vk_mirror_on) ch = (WblChoice){0, "no pool has a mirror in import mode"}; + else if (shadow_on) ch = (WblChoice){0, "shadow storage keeps it off"}; + else if (ch.on && cfg_bool("NX2NAVI_WB_PROBE")) ch = (WblChoice){0, "the write-back probe watches the same pages"}; + lz_why = ch.why; + __atomic_store_n(&lz_wanted, ch.on, __ATOMIC_RELEASE); + rt_log("mem: lazy write-back %s: %s", ch.on ? "on" : "off", ch.why); +} + static int wb_lazy(void) { int s = __atomic_load_n(&lz_state, __ATOMIC_ACQUIRE); if (s) return s == 1; plat_mutex_lock(&lz_init_lock); if (!lz_state) { VkCtx *c = vk_ctx(); - // Not with shadow storage: a fetch copies the mirror into the pool's buffer, which is guest memory only when - // the pool is imported; a shadow's bytes reach guest memory in the submission's shadow_wb_cb. - int on = vk_mirror_on && !shadow_on && c && cfg_bool("NX2NAVI_WB_LAZY"); + int on = c && __atomic_load_n(&lz_wanted, __ATOMIC_ACQUIRE) == 1; if (on) { VkCommandPoolCreateInfo pi = {.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, .queueFamilyIndex = c->gfx_family}; @@ -2625,10 +2644,10 @@ static int wb_lazy(void) { vkCreateFence(c->device, &fi, NULL, &lz_fence) == VK_SUCCESS; on = on && mem_lazy_enable(lazy_fetch, lazy_clean); } - rt_log("mem: what shaders write into mirrored pools %s (NX2NAVI_WB_LAZY%s)", + rt_log("mem: what shaders write into mirrored pools %s (lazy write-back: %s)", on ? "goes back to guest memory once and then only when the CPU touches it" : "goes back to guest memory at the end of every submission", - shadow_on ? "; shadow storage keeps it off" : ""); + on || lz_wanted != 1 ? lz_why : "its command buffer and fence could not be made"); __atomic_store_n(&lz_state, on ? 1 : 2, __ATOMIC_RELEASE); } plat_mutex_unlock(&lz_init_lock); @@ -3296,6 +3315,17 @@ void vk_mem_lost_report(void) { exact ? "the driver's figures, every program counted in the budget" : "this game's own allocations only"); } +// The settings that change how the game's memory reaches the GPU, as they are in effect, for a fatal error's summary +// line (vk_device.c fatal_note): the memory mode and the lazy write-back with its reason and state. No lock, any thread. +void vk_mem_fatal_note(char *out, size_t n) { + char lazy[160]; + mem_lazy_note(lazy, sizeof lazy); + int st = __atomic_load_n(&lz_state, __ATOMIC_ACQUIRE), want = __atomic_load_n(&lz_wanted, __ATOMIC_ACQUIRE); + snprintf(out, n, "memory mode %s%s, lazy write-back %s (%s%s%s)", mirror_verify ? "verify" : vk_mirror_on ? "mirror" : "import", + shadow_on ? " with shadow storage" : "", want < 0 ? "not decided" : st == 2 && want ? "failed to start" : want ? "on" : "off", + lz_why, *lazy ? "; " : "", lazy); +} + float vk_mem_device_used_mb(void) { VkCtx *c = vk_ctx(); if (!c || !c->has_memory_budget) return -1; diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index 75d577c0..c72b452e 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -872,8 +872,16 @@ int vk_texture_detail_auto(void) { return most; } +static const char *const detail_names[3] = {"full", "reduced", "low"}; +static int detail_chosen = -1; // detail_most's answer once it is made + +// The texture detail in effect, for a fatal error's summary line. No lock, any thread. +const char *vk_texture_detail_name(void) { + int most = __atomic_load_n(&detail_chosen, __ATOMIC_RELAXED); + return most < 0 ? "not chosen yet (no texture made)" : detail_names[most]; +} + static int detail_most(void) { // the most levels a texture is made without: 0 full, 1 reduced, 2 low - static const char *const names[3] = {"full", "reduced", "low"}; static int most = -1; if (most >= 0) return most; const char *v = cfg_value("NX2NAVI_TEXTURE_DETAIL"); @@ -886,10 +894,11 @@ static int detail_most(void) { // the most levels a texture is made without: 0 rt_log("vk: texture detail: full (texture_detail = %s; the device reports no video memory budget)", v); else rt_log("vk: texture detail: %s, chosen for a video memory budget of %lld MiB (texture_detail = %s; full from " - "%d MiB, low under %d MiB%s)", names[most], (long long)detail_budget_mb, v, DETAIL_FULL_MB, DETAIL_LOW_MB, + "%d MiB, low under %d MiB%s)", detail_names[most],(long long)detail_budget_mb, v, DETAIL_FULL_MB, DETAIL_LOW_MB, vk_astc_mode() != VK_ASTC_NATIVE && !vk_astc_bc() && detail_budget_mb < DETAIL_RGBA8_MB ? "; one step lower because ASTC textures stay uncompressed here" : ""); } + __atomic_store_n(&detail_chosen, most, __ATOMIC_RELAXED); return most; } diff --git a/runtime/wb_lazy_choice.h b/runtime/wb_lazy_choice.h new file mode 100644 index 00000000..cf2e5fd9 --- /dev/null +++ b/runtime/wb_lazy_choice.h @@ -0,0 +1,63 @@ +// Whether the lazy write-back runs (memory.c "Lazy write-back", vk_memory.c vk_mem_lazy_decide), from the player's +// setting, the platform and the GPU driver, with the reason the log gives. Own header so tests/wb_lazy_check.c checks +// it without Vulkan. +// +// The lazy write-back makes pages of guest memory inaccessible while a host-pointer import of them is bound to a buffer +// the GPU writes, and copies their bytes down from inside the access-fault handler of whichever thread touched them. A +// driver is free to handle both differently, so the default is on only where it has run: +// - Windows, NVIDIA's driver: on. Measured and played there. +// - Windows, AMD's driver for RDNA 3 and newer: on. Builds with this default were measured on an RX 7900 XT (driver +// 26.10.1) standing in Hyrule Field and walking through a village (vk_exec_xfer.c oq_take and vk_exec_draw.c +// have numbers from that card). Whether fights were played on it is not recorded. +// - Windows, AMD's driver branch for RDNA 1 and 2 (RX 5000 and 6000; its driverInfo reads "AMD proprietary shader +// compiler", as vk_caps.c amd_sc tells it): off. Nobody has run it there under our eyes, and the one log of it +// there is an RX 6600 that lost its device 3.5 minutes into play (146 fetches in the 1,200 frames before; the +// GPU's last mark was inside a draw pass, not a fetch). That log does not prove the lazy write-back the cause: +// no failure path was found in the code, and cards with 8 GB lost their device the same way on NVIDIA before it +// existed. A second report, of a game that ended in fights on an AMD card of unknown model and ran for hours with +// a settings file that turns it off, changed several settings at once. Until one of these cards has run it with +// a log to compare, what shaders write goes back at the end of every submission there, as before 0.7.1, at that +// cost (about 90 fps against 65 standing in Hyrule Field on an RTX 5090; not measured on these cards). +// - Windows, any other driver: on, as 0.7.1 shipped it. No report from one. +// - elsewhere: off, as before. The fetch inside the fault handler has only run on Windows. +// A value the player sets wins everywhere: wb_lazy = 1 turns it on for an RX 6000 card, wb_lazy = 0 off for any. +#pragma once + +#include +#include + +#define WBL_DRIVER_AMD 1 // VkDriverId of AMD's own driver, VK_DRIVER_ID_AMD_PROPRIETARY (vk_memory.c asserts the value) +#ifdef _WIN32 +#define WBL_ON_WINDOWS 1 +#else +#define WBL_ON_WINDOWS 0 +#endif + +typedef struct { + int on; + const char *why; // the end of the log line "mem: lazy write-back on|off: " +} WblChoice; + +// AMD's driver branch for RDNA 1 and 2: its own driver whose driverInfo names the older shader compiler. +static inline int wbl_amd_rdna12(uint32_t driver_id, const char *driver_info) { + return driver_id == WBL_DRIVER_AMD && driver_info && strstr(driver_info, "shader compiler") != NULL; +} + +// set: the value the player gave NX2NAVI_WB_LAZY (the environment or nx2navi.ini), NULL or "" when they gave none. +// windows: the game runs on Windows (WBL_ON_WINDOWS). driver_id, driver_info: the device's VkDriverId and the +// driverInfo of its VkPhysicalDeviceDriverProperties. +static inline WblChoice wb_lazy_choice(const char *set, int windows, uint32_t driver_id, const char *driver_info) { + if (set && *set) { + if (!strcmp(set, "0")) return (WblChoice){0, "wb_lazy = 0 is set"}; + return (WblChoice){1, "wb_lazy is set to on"}; + } + if (!windows) + return (WblChoice){0, "the default outside Windows, where its fetch inside the access-fault handler has not run " + "(wb_lazy = 1 turns it on)"}; + if (wbl_amd_rdna12(driver_id, driver_info)) + return (WblChoice){0, "the default on AMD's driver for RX 5000 and 6000 cards, where it has not been tried by " + "us and a report had the game lose its device with it on; what shaders write goes back " + "at the end of every submission, which costs frame rate in open areas (wb_lazy = 1 turns " + "it on)"}; + return (WblChoice){1, "the default on Windows (wb_lazy = 0 turns it off)"}; +} diff --git a/tests/wb_lazy_check.c b/tests/wb_lazy_check.c new file mode 100644 index 00000000..d36f3a15 --- /dev/null +++ b/tests/wb_lazy_check.c @@ -0,0 +1,90 @@ +// runtime/wb_lazy_choice.h: whether the lazy write-back runs, by the player's setting, the platform and the GPU driver +// (runtime/vk_memory.c vk_mem_lazy_decide). Built and run by tests/wb_lazy_check.py; prints each failed check and +// exits 1 on any. +#include +#include + +#include "wb_lazy_choice.h" + +static int fails; +#define CHECK(c, ...) do { if (!(c)) { fails++; printf("FAIL line %d: ", __LINE__); printf(__VA_ARGS__); printf("\n"); } } while (0) + +// VkDriverId values (vulkan_core.h) +enum { AMD_PROPRIETARY = 1, AMD_OPEN_SOURCE = 2, MESA_RADV = 3, NVIDIA_PROPRIETARY = 4, INTEL_WINDOWS = 5, MESA_NVK = 24 }; +enum { LINUX = 0, WINDOWS = 1 }; + +// driverInfo as the drivers report it: AMD's branch for RDNA 1 and 2 (an RX 6600's log), its driver for RDNA 3 and +// newer, NVIDIA's, Mesa's. +static const char RDNA12[] = "26.10.2 (AMD proprietary shader compiler)"; +static const char RDNA34[] = "26.10.1 (LLPC)"; +static const char NVIDIA[] = "617.42"; +static const char MESA[] = "Mesa 26.0.1"; + +typedef struct { unsigned id; const char *info; const char *name; } Driver; +static const Driver drivers[] = { + {AMD_PROPRIETARY, RDNA12, "AMD RDNA 1/2"}, {AMD_PROPRIETARY, RDNA34, "AMD RDNA 3+"}, {AMD_OPEN_SOURCE, "", "AMD open"}, + {MESA_RADV, MESA, "RADV"}, {NVIDIA_PROPRIETARY, NVIDIA, "NVIDIA"}, {INTEL_WINDOWS, "", "Intel"}, {MESA_NVK, MESA, "NVK"}, + {0, NULL, "unknown"}, +}; +enum { ND = sizeof drivers / sizeof *drivers }; + +static int has(const char *s, const char *part) { return s && strstr(s, part) != NULL; } + +int main(void) { + // Nothing set, Windows: on, except on AMD's driver branch for RDNA 1 and 2. + WblChoice nv = wb_lazy_choice(NULL, WINDOWS, NVIDIA_PROPRIETARY, NVIDIA); + CHECK(nv.on == 1, "Windows, NVIDIA's driver, nothing set: on"); + CHECK(has(nv.why, "default") && has(nv.why, "wb_lazy = 0"), "it says it is the default and how to turn it off: %s", nv.why); + CHECK(wb_lazy_choice(NULL, WINDOWS, AMD_PROPRIETARY, RDNA34).on == 1, "Windows, AMD's driver for RDNA 3 and newer: on"); + CHECK(wb_lazy_choice(NULL, WINDOWS, INTEL_WINDOWS, "").on == 1, "Windows, Intel's driver, nothing set: on"); + CHECK(wb_lazy_choice(NULL, WINDOWS, 0, NULL).on == 1, "Windows, a driver that reports nothing: on, as 0.7.1 had it"); + WblChoice amd = wb_lazy_choice(NULL, WINDOWS, AMD_PROPRIETARY, RDNA12); + CHECK(amd.on == 0, "Windows, AMD's driver for RDNA 1 and 2, nothing set: off"); + CHECK(has(amd.why, "AMD") && has(amd.why, "RX 5000 and 6000") && has(amd.why, "wb_lazy = 1"), + "it names the driver's cards and how to turn it on: %s", amd.why); + CHECK(has(amd.why, "frame rate"), "it says what off costs: %s", amd.why); + CHECK(has(amd.why, "default"), "it says it is a default: %s", amd.why); + + // The branch is told by the driver and its driverInfo together, as vk_caps.c tells it: another driver whose + // driverInfo happened to hold the words is not AMD's. + CHECK(wbl_amd_rdna12(AMD_PROPRIETARY, RDNA12) && !wbl_amd_rdna12(AMD_PROPRIETARY, RDNA34), "the branch by driverInfo"); + CHECK(!wbl_amd_rdna12(AMD_PROPRIETARY, NULL) && !wbl_amd_rdna12(AMD_PROPRIETARY, ""), "no driverInfo: not the branch"); + CHECK(!wbl_amd_rdna12(NVIDIA_PROPRIETARY, RDNA12) && wb_lazy_choice(NULL, WINDOWS, MESA_RADV, RDNA12).on == 1, + "the words alone, under another driver: not the branch"); + + // An empty value is no value (cfg.c add: "key =" leaves the setting at its default). + CHECK(wb_lazy_choice("", WINDOWS, AMD_PROPRIETARY, RDNA12).on == 0, "an empty value on the RDNA 1/2 branch: the default, off"); + CHECK(wb_lazy_choice("", WINDOWS, NVIDIA_PROPRIETARY, NVIDIA).on == 1, "an empty value on NVIDIA: the default, on"); + + // Nothing set, elsewhere: off on every driver. + for (int i = 0; i < ND; i++) { + WblChoice c = wb_lazy_choice(NULL, LINUX, drivers[i].id, drivers[i].info); + CHECK(c.on == 0 && has(c.why, "wb_lazy = 1"), "Linux, %s, nothing set: off, and how to turn it on: %s", + drivers[i].name, c.why); + } + + // What the player sets wins on every platform and driver, and the reason says it was set. + for (int os = LINUX; os <= WINDOWS; os++) + for (int i = 0; i < ND; i++) { + WblChoice on = wb_lazy_choice("1", os, drivers[i].id, drivers[i].info); + WblChoice off = wb_lazy_choice("0", os, drivers[i].id, drivers[i].info); + CHECK(on.on == 1 && has(on.why, "set"), "os %d, %s, wb_lazy = 1: on (%s)", os, drivers[i].name, on.why); + CHECK(off.on == 0 && has(off.why, "set"), "os %d, %s, wb_lazy = 0: off (%s)", os, drivers[i].name, off.why); + CHECK(!has(on.why, "default") && !has(off.why, "default"), "os %d, %s: a set value is not a default", os, + drivers[i].name); + } + // Any value but 0 counts as on, as cfg_bool reads it for memory.c mem_init. + CHECK(wb_lazy_choice("on", WINDOWS, AMD_PROPRIETARY, RDNA12).on == 1, "wb_lazy = on: on"); + + CHECK(WBL_DRIVER_AMD == AMD_PROPRIETARY, "WBL_DRIVER_AMD is VK_DRIVER_ID_AMD_PROPRIETARY"); + + // The game passes the platform it was built for. +#ifdef _WIN32 + CHECK(WBL_ON_WINDOWS == 1, "a Windows build says so"); +#else + CHECK(WBL_ON_WINDOWS == 0, "a build elsewhere says so"); +#endif + + if (!fails) printf("wb lazy choice: all checks passed\n"); + return fails != 0; +} diff --git a/tests/wb_lazy_check.py b/tests/wb_lazy_check.py new file mode 100644 index 00000000..b066d7ae --- /dev/null +++ b/tests/wb_lazy_check.py @@ -0,0 +1,31 @@ +"""Build and run tests/wb_lazy_check.c: runtime/wb_lazy_choice.h, whether the lazy write-back runs, by the player's +setting, the platform and the GPU driver. + +Usage: wb_lazy_check.py +""" +import os +import subprocess +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / 'tests' / 'diff')) +from common import MSYS_BIN, compiler # noqa: E402 + + +def main(): + work = ROOT / 'build' / 'test' / 'wb_lazy' + work.mkdir(parents=True, exist_ok=True) + exe = work / ('wb_lazy_check.exe' if os.name == 'nt' else 'wb_lazy_check') + env = dict(os.environ) + if os.name == 'nt' and MSYS_BIN.exists(): + env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '') + # every platform's and driver's choice is checked through wb_lazy_choice's arguments; WBL_ON_WINDOWS on the one + # built for + subprocess.check_call([compiler(), '-O1', '-Wall', '-Werror', '-I', str(ROOT / 'runtime'), + str(ROOT / 'tests' / 'wb_lazy_check.c'), '-o', str(exe)], env=env) + return subprocess.run([str(exe)], env=env).returncode + + +if __name__ == '__main__': + sys.exit(main()) From 11050fb0d399675041ff6172cde341124cdfc3b2 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Tue, 10 Nov 2026 15:14:42 -0500 Subject: [PATCH 2/5] Test that an update leaves a player's nx2navi.ini alone, and keep its bytes when the older installer sets the language. A player wrote that the settings file is overwritten on updates and that a line has to be added again each time. Nothing an update of the launcher's install does writes the file: the updater works in the launcher's own folders, and the build only reads it (the bind_ lines for the button prompts, shader_carry for the shaders step). The tests now hold that with the player's file as reported: settings the menu wrote, three lines that are no settings of the game, a comment, CRLF line ends and no line end after the last line. It comes through the launcher's part of an update (staging, the switch, the cleanup; BackgroundUpdateTest), through the rebuild under a newer kit, a rebuild with nothing to do and a build from the game files again (MakeGameTest, with the check, the ExeFS, RomFS, shaders and prompts steps real and the lift and compile as stand-ins), and through the launcher's own settings switch, which adds its one line (PlayerIniTest). One writer did write the whole file again: installer/ini.py, the older installer's last step at every install and update. It kept every line, but turned CRLF into LF, added a line end after the last line and dropped a byte order mark, and a file saved as UTF-16 stopped the step with an error. It now changes the lang line only and keeps every other byte; a UTF-16 file is read as that and written as UTF-8, as the game's menu writes it. Co-Authored-By: Claude Fable 5.2 --- installer/ini.py | 70 ++++++++++++----- tests/launcher_test.py | 174 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+), 19 deletions(-) diff --git a/installer/ini.py b/installer/ini.py index 86be3341..f6024412 100644 --- a/installer/ini.py +++ b/installer/ini.py @@ -3,7 +3,8 @@ A new file starts from nx2navi.ini.example, whose lines are all commented defaults. The language goes into `lang` (a Switch language code, runtime/ov_system.c): an active `lang = ...` line is rewritten in place, else the commented `# lang = ...` line of the example is activated, else the line is added to [language] (created at the end if -missing). Other lines, comments and line order stay as they are. +missing). Other lines, comments and line order stay as they are, byte for byte: the file's byte order mark, its line +ends and a last line without one are kept, so a player's own lines come through an install or an update unchanged. """ import os import re @@ -21,6 +22,7 @@ NEED_SHARED_FONTS = ('ko', 'zh-Hans', 'zh-Hant') ACTIVE = re.compile(r'^(\s*)(?:nx2navi_)?lang(\s*=\s*)(.*?)(\s*)$', re.IGNORECASE) COMMENTED = re.compile(r'^\s*[#;]\s*(?:nx2navi_)?lang\s*=.*$', re.IGNORECASE) SECTION = re.compile(r'^\s*\[(.*)\]\s*$') +BOM = '' def canonical_language(lang): @@ -29,27 +31,43 @@ def canonical_language(lang): def set_language(text, lang): - """text with `lang = ` (an alias written as its canonical code); see the module docstring.""" + """text with `lang = ` (an alias written as its canonical code); see the module docstring. Only that line + changes: a byte order mark, each line's own ending (LF or CRLF) and a last line without one stay as they are, and + a line that is added ends as the file's first line does.""" lang = canonical_language(lang) - lines = text.splitlines() + bom = BOM if text.startswith(BOM) else '' + lines = text[len(bom):].splitlines(keepends=True) + nl = '\r\n' if lines and lines[0].endswith('\r\n') else '\n' + + def split(line): + body = line.rstrip('\r\n') + return body, line[len(body):] + for i, line in enumerate(lines): - m = ACTIVE.match(line) + body, end = split(line) + m = ACTIVE.match(body) if m: - lines[i] = f'{m.group(1)}lang{m.group(2)}{lang}' - return '\n'.join(lines) + '\n' + lines[i] = f'{m.group(1)}lang{m.group(2)}{lang}{end}' + return bom + ''.join(lines) for i, line in enumerate(lines): - if COMMENTED.match(line): - lines[i] = f'lang = {lang}' - return '\n'.join(lines) + '\n' + body, end = split(line) + if COMMENTED.match(body): + lines[i] = f'lang = {lang}{end}' + return bom + ''.join(lines) for i, line in enumerate(lines): - m = SECTION.match(line) + body, end = split(line) + m = SECTION.match(body) if m and m.group(1).strip().lower() == 'language': - lines.insert(i + 1, f'lang = {lang}') - return '\n'.join(lines) + '\n' + if not end: # the header is the file's last line, without an ending + lines[i] = body + nl + lines.insert(i + 1, f'lang = {lang}{nl}') + return bom + ''.join(lines) + if lines and not split(lines[-1])[1]: + lines[-1] += nl if lines and lines[-1].strip(): - lines.append('') - lines += ['[language]', f'lang = {lang}'] - return '\n'.join(lines) + '\n' + lines.append(nl) + lines += [f'[language]{nl}', f'lang = {lang}{nl}'] + return bom + ''.join(lines) def get_language(text): @@ -60,19 +78,33 @@ def get_language(text): return None +def read(path): + """The file's text with its byte order mark and its own line ends. Bytes that are not UTF-8 come back as they are + (surrogate escapes), so a line in another encoding survives a rewrite. A file saved as UTF-16 (an editor's + "Unicode", which the game reads too: runtime/cfg.c utf16_text) is decoded as that and written back as UTF-8, as + the game's own menu writes it.""" + raw = Path(path).read_bytes() + if raw[:2] in (b'\xff\xfe', b'\xfe\xff'): + return raw.decode('utf-16', errors='replace') + return raw.decode('utf-8', errors='surrogateescape') + + def write(dest, lang, example=None): - """Write dest/nx2navi.ini with lang; an existing file keeps its other lines. Returns the path.""" + """Write dest/nx2navi.ini with lang; an existing file keeps every other line byte for byte (set_language). + Returns the path.""" path = Path(dest) / 'nx2navi.ini' + old = None if path.is_file(): - text = path.read_text(encoding='utf-8-sig') + text = old = read(path) elif example and Path(example).is_file(): text = Path(example).read_text(encoding='utf-8') else: text = '' new = set_language(text, lang) - if path.is_file() and new == text: + if new == old: return path tmp = path.with_name('nx2navi.ini.tmp') - tmp.write_text(new, encoding='utf-8', newline='\n') + with open(tmp, 'w', encoding='utf-8', errors='surrogateescape', newline='') as f: + f.write(new) os.replace(tmp, path) return path diff --git a/tests/launcher_test.py b/tests/launcher_test.py index 597a3fe0..bcf39d12 100644 --- a/tests/launcher_test.py +++ b/tests/launcher_test.py @@ -262,6 +262,50 @@ class VersionTest(unittest.TestCase): versions.parse('banana') +# A player's settings file as a report showed it (an AMD card, 0.7.1): what the game's menu wrote, three lines added by +# hand that are no settings of the game (async_compute, vram_safe_mode, exception_handler: the player took the first for +# the fix of a crash and asked for it as a default, because "the configuration file gets overwritten on updates"), and a +# comment. Saved as an editor on Windows saves it: CRLF line ends, no line end after the last line. Nothing in an +# update may change a byte of it (PlayerIniTest, BackgroundUpdateTest and MakeGameTest each run their part of one). +PLAYER_INI = ( + b'# my settings\r\n' + b'[display]\r\n' + b'async_compute = 1\r\n' + b'fullscreen = 1\r\n' + b'window_size = 1920x1080\r\n' + b'gpu_index = 0\r\n' + b'perf_overlay = fps\r\n' + b'vk_present = mailbox\r\n' + b'upscaler = bilinear\r\n' + b'dlaa = 1\r\n' + b'framegen = off\r\n' + b'taa = fsr3\r\n' + b'hdr = 0\r\n' + b'aspect = fit\r\n' + b'game_res = 1800\r\n' + b'sharpness = 80\r\n' + b'aniso = 2\r\n' + b'assume_focus = 1\r\n' + b'texture_detail = auto\r\n' + b'\r\n' + b'[input]\r\n' + b'bind_a = key:default, pad:south\r\n' + b'bind_b = key:default, pad:east\r\n' + b'bind_x = key:default, pad:north\r\n' + b'bind_y = key:default, pad:west\r\n' + b'\r\n' + b'[language]\r\n' + b'operation_mode = docked\r\n' + b'\r\n' + b'[performance]\r\n' + b'wb_lazy = 0\r\n' + b'vram_safe_mode = 1\r\n' + b'exception_handler = 1\r\n' + b'\r\n' + b'[frame rate]\r\n' + b'fps_limit = 120') + + class GameIniTest(Tmp): """The game settings the launcher switches (launcher/gameini.py), read as runtime/cfg.c reads nx2navi.ini.""" @@ -305,6 +349,45 @@ class GameIniTest(Tmp): gameini.put(self.tmp, 'discord', 'discord_rpc', '1') self.assertTrue((self.tmp / 'nx2navi.ini').is_dir()) +class PlayerIniTest(Tmp): + """The settings file of a player (PLAYER_INI) under the two writers outside the game: the launcher's Settings + (launcher/gameini.py) and the older installer's last step (installer/ini.py). Each changes the one line it is + for; the lines that are no settings of the game, the comment and every other byte stay.""" + + def test_the_launchers_setting_adds_one_line(self): + ini = self.tmp / 'nx2navi.ini' + ini.write_bytes(PLAYER_INI) + self.assertEqual(gameini.get(self.tmp, 'wb_lazy'), '0') + self.assertEqual(gameini.get(self.tmp, 'async_compute'), '1') # read like any line; the game ignores it + gameini.put(self.tmp, 'discord', 'discord_rpc', '0') + self.assertEqual(ini.read_bytes(), PLAYER_INI + b'\r\n\r\n[discord]\r\ndiscord_rpc = 0\r\n') + gameini.put(self.tmp, 'discord', 'discord_rpc', '1') + self.assertEqual(ini.read_bytes(), PLAYER_INI + b'\r\n\r\n[discord]\r\ndiscord_rpc = 1\r\n') + + def test_the_older_installer_changes_the_language_line_only(self): + """installer/ini.py sets the language, in the older installer's last step at every install and update: the + one line goes under [language] with the file's own line ends, and every other byte stays (it used to write + the whole file again with LF line ends, a line end after the last line and no byte order mark). A second run + leaves the file alone; a changed language changes that line; a byte order mark and a line that is not UTF-8 + stay too.""" + from installer import ini as inst_ini + path = self.tmp / 'nx2navi.ini' + path.write_bytes(PLAYER_INI) + inst_ini.write(self.tmp, 'en-US') + want = PLAYER_INI.replace(b'[language]\r\n', b'[language]\r\nlang = en-US\r\n') + self.assertEqual(path.read_bytes(), want) + self.assertEqual(want.count(b'lang = en-US'), 1) + stamp = path.stat().st_mtime_ns + inst_ini.write(self.tmp, 'en-US') + self.assertEqual((path.read_bytes(), path.stat().st_mtime_ns), (want, stamp)) + inst_ini.write(self.tmp, 'de') + self.assertEqual(path.read_bytes(), want.replace(b'lang = en-US', b'lang = de')) + marked = b'\xef\xbb\xbf# caf\xe9\r\nlang = ja\r\nasync_compute = 1' + path.write_bytes(marked) + inst_ini.write(self.tmp, 'fr') + self.assertEqual(path.read_bytes(), marked.replace(b'lang = ja', b'lang = fr')) + self.assertFalse((self.tmp / 'nx2navi.ini.tmp').exists()) + class RebuildArgsTest(Tmp): """Rebuild the Game compiles the game's code for this processor's level (--retune); an update keeps the level its @@ -898,6 +981,28 @@ class BackgroundUpdateTest(Tmp): self.assertEqual(bg.install(self.game, rel), '') self.assertEqual(len(self.restarts), 1) + def test_an_update_leaves_the_games_settings_file(self): + """The launcher's part of an update (the release staged beside the running version, the switch to it, the + cleanup after the rebuild) changes nothing in the game folder, also in its default place inside the + launcher's folder: the player's nx2navi.ini is the same bytes afterwards, and an uninstall that keeps the game + does not name it.""" + game = self.layout.root / 'game' + (game / 'profile').mkdir(parents=True) + ini = game / 'nx2navi.ini' + ini.write_bytes(PLAYER_INI) + before = sorted(p.relative_to(game).as_posix() for p in game.rglob('*')) + bg = self.background(self.context()) + rel = self.publish('0.5.0', runtime='py-2') + self.assertEqual(self.stage(bg, rel), 'staged') + self.assertEqual(ini.read_bytes(), PLAYER_INI) + self.assertEqual(bg.install(str(game), rel, why='the launcher started'), '0.5.0') + self.assertEqual(self.state(), ('0.5.0', '0.4.0', [['--continue-update', '0.4.0']])) + updater.prune(self.layout) # what ContinueUpdateJob ends with + self.assertEqual(ini.read_bytes(), PLAYER_INI) + self.assertEqual(sorted(p.relative_to(game).as_posix() for p in game.rglob('*')), before) + gone, _ = winsys.uninstall_plan(self.layout) + self.assertFalse([p for p in gone if p == game or p in ini.parents]) + def test_no_install_while_the_game_runs(self): """A copy of the game started elsewhere, the copy the launcher started, and a download under way each hold the install back, also one the player asked for.""" @@ -1635,6 +1740,75 @@ class MakeGameTest(Tmp): self.assertEqual(build(), ([], [{'ev': 'step', 'step': 'prompts', 'state': 'skip'}], 4)) self.assertTrue((self.out / 'romfs-patches-xbox' / 'manifest.tsv').is_file()) + def test_an_update_keeps_the_settings_file(self): + """The rebuild an update ends with (make_game.py --rebuild under a newer kit: the lift, the compile, the + shaders step and the button prompts all run again) leaves the game folder's nx2navi.ini as the player has it, + byte for byte. The build reads the file (the bind_ lines for the prompts, shader_carry for the shaders step) + and never writes it; so does a second rebuild that finds nothing to do, and one from the game files again. + The lift and the compile are stand-ins here (the real ones need the game and clang); the check, the ExeFS and + RomFS steps, the shaders step and the prompts step are the real ones.""" + from unittest import mock + kit = self.tmp / 'kit' + for d in ('tools', 'bin', 'recomp'): + (kit / d).mkdir(parents=True) + (kit / 'VERSION').write_text('0.7.0\n') + (kit / 'recomp' / 'gen.py').write_text('# the lifter of 0.7.0\n') + (kit / 'bin' / self.mg.XLATE_NAME).write_bytes(b'translator') + (kit / 'bin' / 'nx2navi_xlate.id').write_text('xlate 1\n') + (kit / 'tools' / 'prepare_shaders.py').write_text('print("prepare-shaders: progress build 1 1", flush=True)\n') + for name in ('prompt_art.py', 'button_icons.py'): + shutil.copy2(ROOT / 'tools' / name, kit / 'tools' / name) + (kit / 'tools' / 'pad_prompts.py').write_text(FAKE_PAD_PROMPTS) + art = kit / 'prompt-art' / 'XGamepad' / 'Default' + art.mkdir(parents=True) + (art / 'T_X_A_White.png').write_bytes(b'picture one') + ran = [] + + def fake(name): + def step(*args, **kw): + ran.append(name) + return step + + def build(*source): + """One run of make_game.py; the steps that ran, in order.""" + buf = io.StringIO() + argv = ['make_game.py', *source, '--out', str(self.out), '--msys', str(self.msys), '--events'] + with mock.patch.object(sys, 'argv', argv), contextlib.redirect_stdout(buf), \ + contextlib.redirect_stderr(io.StringIO()): + self.mg.main() + events = [json.loads(ln[2:]) for ln in buf.getvalue().splitlines() if ln.startswith('@@')] + return [e['step'] for e in events if e['ev'] == 'step' and e['state'] == 'start'] + + sys.path.insert(0, str(self.layout.pydeps)) # the fake zbic + self.addCleanup(sys.path.remove, str(self.layout.pydeps)) + ini = self.out / 'nx2navi.ini' + with mock.patch.multiple(self.mg, KIT=kit, PROMPT_PACKAGES={}, EVENTS=False, step_lift=fake('lift'), + step_compile=fake('compile'), step_scan=fake('scan')): + self.assertEqual(build('--nup', str(self.nup)), + ['check', 'exefs', 'romfs', 'lift', 'compile', 'shaders', 'prompts', 'scan']) + self.assertFalse(ini.exists()) # the build makes no settings file: the game's menu does + ini.write_bytes(PLAYER_INI) + names = sorted(p.name for p in self.out.iterdir()) + # the update: a kit with another lifter and another version + (kit / 'VERSION').write_text('0.7.1\n') + (kit / 'recomp' / 'gen.py').write_text('# the lifter of 0.7.1\n') + ran.clear() + steps = build('--rebuild') + self.assertEqual(steps, ['check', 'lift', 'compile', 'shaders', 'prompts']) # the bind_ lines are new to it + self.assertEqual(ran, ['lift', 'compile']) + self.assertEqual(ini.read_bytes(), PLAYER_INI) + self.assertEqual(sorted(p.name for p in self.out.iterdir()), names) # no copy, no backup, no temporary file + self.assertEqual(json.loads((self.out / 'build-cache' / 'state.json').read_text())['kit'], '0.7.1') + self.assertEqual(build('--rebuild'), ['check']) # nothing to do + self.assertEqual(ini.read_bytes(), PLAYER_INI) + # from the game files again into the same folder (Rebuild the Game without a build to start from) + st = json.loads((self.out / 'build-cache' / 'state.json').read_text()) + st['steps'] = {} + (self.out / 'build-cache' / 'state.json').write_text(json.dumps(st)) + self.assertEqual(build('--nup', str(self.nup)), + ['check', 'exefs', 'romfs', 'lift', 'compile', 'shaders', 'prompts', 'scan']) + self.assertEqual(ini.read_bytes(), PLAYER_INI) + @unittest.skipIf(os.name == 'nt', 'uses a POSIX script as the compiler') def test_largest_source_compiles_first(self): src, obj = self.tmp / 'src', self.tmp / 'obj' From d83f01acb3285c15502f1cf993602cd1a43248ab Mon Sep 17 00:00:00 2001 From: chrg6 Date: Tue, 10 Nov 2026 15:14:43 -0500 Subject: [PATCH 3/5] Note the lazy write-back's default on AMD RX 5000 and 6000 cards, the settings-file lines and the fatal summary in the draft release notes, and the new checks in the build guide. Co-Authored-By: Claude Fable 5.2 --- docs/building.md | 10 ++++++++++ docs/releases/v0.7.2.md | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/docs/building.md b/docs/building.md index de709c79..85f5f877 100644 --- a/docs/building.md +++ b/docs/building.md @@ -336,6 +336,16 @@ A change to what the library warm logs when the driver's cache of stage librarie `runtime/vk_pipeline.c` `lw_main`) passes `python tests\warm_hint_check.py`, which builds the header alone and checks the added text by GPU vendor and by why the cache was cold. No game files. +A change to where the lazy write-back is on by default (`runtime/wb_lazy_choice.h`, `runtime/vk_memory.c` +`vk_mem_lazy_decide`) passes `python tests\wb_lazy_check.py`, which builds the header alone and checks the choice and +its reason by platform, by GPU driver and by what the player set. No game files, no GPU. + +A change to what writes `nx2navi.ini` outside the game (`launcher/gameini.py`, `installer/ini.py`, `tools/make_game.py`, +`launcher/updater.py`) passes the settings-file tests of `tests\launcher_test.py` (`PlayerIniTest`, and the tests named +`..._settings_file` of `BackgroundUpdateTest` and `MakeGameTest`): a player's file with lines that are no settings of +the game comes through an update and a rebuild byte for byte. The game's own writer, the settings menu, is checked by +`--probe-cfg` with the same lines. + A change to the mouse camera's stick deflection (`runtime/input_map.c` `input_mouse_stick`) passes `python tests\mouse_stick_check.py`, which builds that file with the rest of the runtime stubbed and checks the deflection at each camera speed: a slow movement is divided by the factor, a fast flick reaches full tilt. No game diff --git a/docs/releases/v0.7.2.md b/docs/releases/v0.7.2.md index 23311b26..03fe2766 100644 --- a/docs/releases/v0.7.2.md +++ b/docs/releases/v0.7.2.md @@ -33,3 +33,23 @@ Draft notes for the release after 0.7.1. The version number is not decided yet. shader compiler"); with it each NaN test is now made on the bits of the number instead, which no compiler can drop. It is on by default only with that driver (`vk_nan_bits`); the first start after the update compiles the pipelines again. Untested on those cards before this release: please report whether the blocks are gone. +- The older installer's last step no longer writes `nx2navi.ini` again as a whole to set the language: it changes the + `lang` line and keeps every other byte (it turned Windows line ends into Unix ones and dropped a byte order mark). + +## Changed + +- **AMD RX 5000 and RX 6000 cards: the faster copy-back of 0.7.1 is off by default again.** 0.7.1 turned it on for + every card on Windows (what the game's shaders write is copied back from the video card once, and then only when + the game's CPU code touches it). None of us has one of these cards, their Windows driver is a branch of its own, + and one report from an RX 6600 lost its video device a few minutes into play with it on. We found no fault in the + code and cannot say it was the cause, so until someone has run it there the old copy-back at the end of every GPU + submission is the default with that driver; open areas run slower for it, as they did in 0.7.0. `wb_lazy = 1` in + `nx2navi.ini` turns it on: if you try it, tell us whether the game stays up, with the log. NVIDIA cards and AMD's + RX 7000 and RX 9000 cards keep it on. The log says which is in effect and why ("mem: lazy write-back ..."). +- **A line in `nx2navi.ini` that is no setting of this version is pointed out.** Such a line does nothing; the game + only wrote "unknown key" into its log. The log now lists them in one line at the start, beside a line with every + setting the file does set, and the settings menu shows them in its bottom row. An update or a rebuild never rewrites + `nx2navi.ini`, and the menu keeps such lines when it saves, so nothing has to be added again after an update. +- When the game ends with a fatal error or a crash, the end of the log names the video card, its driver, the memory + mode, whether the lazy write-back was on (with its armed ranges, its fetches so far and one in progress) and the + texture detail, so a report that holds only the last lines of a log still says them. From 755e56065a12d8c98466c4308c98ef7a9801448f Mon Sep 17 00:00:00 2001 From: chrg6 Date: Tue, 10 Nov 2026 15:15:34 -0500 Subject: [PATCH 4/5] Let the lazy write-back choice check find its compiler by itself. tests/wb_lazy_check.py took the compiler from tests/diff/common.py, which imports Unicorn and Capstone before anything else: on a PC without them the check stopped at the import, though it needs only a C compiler. It now picks the compiler as tests/gpa_check.py does. Co-Authored-By: Claude Fable 5.2 --- tests/wb_lazy_check.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/wb_lazy_check.py b/tests/wb_lazy_check.py index b066d7ae..5017842b 100644 --- a/tests/wb_lazy_check.py +++ b/tests/wb_lazy_check.py @@ -1,16 +1,27 @@ """Build and run tests/wb_lazy_check.c: runtime/wb_lazy_choice.h, whether the lazy write-back runs, by the player's setting, the platform and the GPU driver. +Needs a C compiler only: no Vulkan headers, no GPU and no game files. + Usage: wb_lazy_check.py """ import os +import shutil import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(ROOT / 'tests' / 'diff')) -from common import MSYS_BIN, compiler # noqa: E402 +MSYS_BIN = Path(r'C:\msys64\ucrt64\bin') + + +def compiler(): + """$CC, else MSYS2 UCRT64's clang, else clang on PATH (as tests/diff/common.py picks it, without its Unicorn).""" + if os.environ.get('CC'): + return os.environ['CC'] + if os.name == 'nt' and (MSYS_BIN / 'clang.exe').exists(): + return str(MSYS_BIN / 'clang.exe') + return shutil.which('clang') or 'clang' def main(): @@ -22,7 +33,7 @@ def main(): env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '') # every platform's and driver's choice is checked through wb_lazy_choice's arguments; WBL_ON_WINDOWS on the one # built for - subprocess.check_call([compiler(), '-O1', '-Wall', '-Werror', '-I', str(ROOT / 'runtime'), + subprocess.check_call([compiler(), '-std=gnu11', '-O1', '-Wall', '-Werror', '-I', str(ROOT / 'runtime'), str(ROOT / 'tests' / 'wb_lazy_check.c'), '-o', str(exe)], env=env) return subprocess.run([str(exe)], env=env).returncode From 62e8578aa2ce0e42d5a5ddf503639b192b1538e2 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Tue, 10 Nov 2026 15:20:47 -0500 Subject: [PATCH 5/5] Turn the lazy write-back off by default on every card of AMD's own Windows driver, and let the device probe print the fatal summary line. The default was off only on AMD's driver branch for RDNA 1 and 2, on the grounds that builds with the default on had been measured on an RX 7900 XT. Those measurements were standing in Hyrule Field and walking through a village; the report this is about is of a game that ended in fights, on an AMD card the player did not name, and fights are where the lazy path is busiest. Nobody has played one on an AMD card under our eyes on either branch, so the exception is now AMD's own driver as a whole (wb_lazy_choice.h, by VkDriverId), until a card of each branch has played fights with wb_lazy = 1 and a log to show. The cost is the open-area frame rate of 0.7.0 on every AMD card under Windows; the RX 7900 XT figures in the draft notes come from builds that had it on by default, which the notes now say. wb_lazy = 1 still turns it on. --probe-vkdevice prints the line a fatal error or a crash adds to the log, so its wording can be read without a failing run. On an RTX 5090: "fatal: gpu NVIDIA GeForce RTX 5090, driver NVIDIA "621.01" version 621.1.0.0; memory mode mirror, lazy write-back on (the default on Windows (wb_lazy = 0 turns it off)); texture detail not chosen yet (no texture made)", and with the reporting player's nx2navi.ini beside the exe "lazy write-back off (wb_lazy = 0 is set)", after a start whose log names async_compute, vram_safe_mode and exception_handler as no settings of this version. Co-Authored-By: Claude Fable 5.2 --- docs/releases/v0.7.2.md | 18 ++++++----- nx2navi.ini.example | 4 +-- runtime/cfg.c | 3 +- runtime/memory.c | 4 +-- runtime/vk.h | 1 - runtime/vk_caps.c | 1 - runtime/vk_device.c | 1 + runtime/vk_memory.c | 2 +- runtime/wb_lazy_choice.h | 51 +++++++++++++----------------- tests/wb_lazy_check.c | 68 +++++++++++++++------------------------- 10 files changed, 64 insertions(+), 89 deletions(-) diff --git a/docs/releases/v0.7.2.md b/docs/releases/v0.7.2.md index 03fe2766..744e8ae3 100644 --- a/docs/releases/v0.7.2.md +++ b/docs/releases/v0.7.2.md @@ -38,14 +38,16 @@ Draft notes for the release after 0.7.1. The version number is not decided yet. ## Changed -- **AMD RX 5000 and RX 6000 cards: the faster copy-back of 0.7.1 is off by default again.** 0.7.1 turned it on for - every card on Windows (what the game's shaders write is copied back from the video card once, and then only when - the game's CPU code touches it). None of us has one of these cards, their Windows driver is a branch of its own, - and one report from an RX 6600 lost its video device a few minutes into play with it on. We found no fault in the - code and cannot say it was the cause, so until someone has run it there the old copy-back at the end of every GPU - submission is the default with that driver; open areas run slower for it, as they did in 0.7.0. `wb_lazy = 1` in - `nx2navi.ini` turns it on: if you try it, tell us whether the game stays up, with the log. NVIDIA cards and AMD's - RX 7000 and RX 9000 cards keep it on. The log says which is in effect and why ("mem: lazy write-back ..."). +- **AMD cards: the faster copy-back of 0.7.1 is off by default again.** 0.7.1 turned it on for every card on Windows + (what the game's shaders write is copied back from the video card once, and then only when the game's CPU code + touches it). Since then two reports from AMD cards had the game end in play: an RX 6600 lost its video device a + few minutes in with it on, and a player whose game ended in fights played for hours with it off. We found no fault + in the code and cannot say it was the cause, and none of us has played a fight on an AMD card with it on. Until + someone has, the old copy-back at the end of every GPU submission is the default with AMD's Windows driver; open + areas run slower for it, as they did in 0.7.0. The RX 7900 XT figures under *Faster* come from builds that had it + on by default. `wb_lazy = 1` in `nx2navi.ini` turns it on: if you try it, play a few fights and tell us whether the + game stays up, with the log. NVIDIA cards keep it on. The log says which is in effect and why ("mem: lazy + write-back ..."). - **A line in `nx2navi.ini` that is no setting of this version is pointed out.** Such a line does nothing; the game only wrote "unknown key" into its log. The log now lists them in one line at the start, beside a line with every setting the file does set, and the settings menu shows them in its bottom row. An update or a rebuild never rewrites diff --git a/nx2navi.ini.example b/nx2navi.ini.example index de5459e9..d64ac63e 100644 --- a/nx2navi.ini.example +++ b/nx2navi.ini.example @@ -736,8 +736,8 @@ # 1: what the game's shaders write into its memory is copied back from the video card once, and after that only when # the game's CPU code touches it (most of it never is: 66 MiB a frame in Hyrule Field), for about a third more frames # a second in open areas. 0: copied back at the end of every GPU submission, as in 0.7.0. -# Default: 1 on Windows, except 0 with AMD's driver for RX 5000 and RX 6000 cards, where it has not been tried by us -# and one report lost its device with it on: set 1 there to try it, and back to 0 if the game ends in play (the log's +# Default: 1 on Windows, except 0 on AMD graphics cards (AMD's own driver), where two reports had the game end in play +# with it on and the cause is not found: set 1 there to try it, and back to 0 if the game ends in a fight (the log's # "mem: lazy write-back" line says which is in effect and why). 0 elsewhere. With shadow storage (Linux, Wine) it # stays off whatever is set. # wb_lazy = 1 diff --git a/runtime/cfg.c b/runtime/cfg.c index 3815ae6a..9941862e 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -140,8 +140,7 @@ static const struct { const char *key, *section; } sections[] = { // The lazy write-back (memory.c "Lazy write-back") is on where it has run: its fetch inside the access-fault handler // has only ever run on Windows. This is the platform's part of the default, which memory.c mem_init goes by to take // the access faults; the back end then turns it off for a driver it is not trusted on while the key is unset -// (wb_lazy_choice.h: AMD's for RX 5000 and 6000 cards), and with shadow storage whatever is set (vk_memory.c -// vk_mem_lazy_decide). +// (wb_lazy_choice.h: AMD's own), and with shadow storage whatever is set (vk_memory.c vk_mem_lazy_decide). #ifdef _WIN32 #define WB_LAZY_DEFAULT "1" #else diff --git a/runtime/memory.c b/runtime/memory.c index 2fd19de2..425df439 100644 --- a/runtime/memory.c +++ b/runtime/memory.c @@ -108,8 +108,8 @@ static void unprobe_locked(uint64_t r) { plat_dec32(&nprb); } -// Lazy write-back (NX2NAVI_WB_LAZY; unset: on under Windows except on AMD's driver for RX 5000 and 6000 cards, off -// elsewhere, as wb_lazy_choice.h decides and gives the reasons for; vk_memory.c "lazy write-back"). It was off +// Lazy write-back (NX2NAVI_WB_LAZY; unset: on under Windows except on AMD's own driver, off elsewhere, as +// wb_lazy_choice.h decides and gives the reasons for; vk_memory.c "lazy write-back"). It was off // by default in 0.7.0: with it on, single frames came out with the whole scene's shadowing missing, 10 to 180 of 1,800 // presents standing in Hyrule Field with other programs keeping the CPU busy and none found with it off. That was // not this code's doing: frames were drawn from copies taken before the game's signal that their data was written diff --git a/runtime/vk.h b/runtime/vk.h index a6bc9b92..d31c27c8 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -64,7 +64,6 @@ typedef struct { int amd_llpc; // AMD's own driver for RDNA 3 and newer (its driverInfo names LLPC) int mesa; // a Mesa driver the game runs on: RADV, ANV or NVK uint32_t driver_id; // the device's VkDriverId - char driver_info[256]; // and its driverInfo (VK_MAX_DRIVER_INFO_SIZE) } VkCaps; extern VkCaps vk_caps; void vk_caps_driver(VkPhysicalDevice p); // first, before vkCreateDevice: vk_caps.amd, amd_sc, amd_llpc, mesa, driver_id diff --git a/runtime/vk_caps.c b/runtime/vk_caps.c index 7d9b62de..03ce9f2f 100644 --- a/runtime/vk_caps.c +++ b/runtime/vk_caps.c @@ -45,7 +45,6 @@ void vk_caps_driver(VkPhysicalDevice p) { vkGetPhysicalDeviceProperties2(p, &p2); vk_caps.amd = p2.properties.vendorID == 0x1002; vk_caps.driver_id = (uint32_t)drv.driverID; - snprintf(vk_caps.driver_info, sizeof vk_caps.driver_info, "%s", drv.driverInfo); // AMD split RDNA 1 and 2 off into a driver branch of their own; its driverInfo reads // "26.10.1 (AMD proprietary shader compiler)" where the RDNA 3 and 4 driver names LLPC. vk_caps.amd_sc = drv.driverID == VK_DRIVER_ID_AMD_PROPRIETARY && strstr(drv.driverInfo, "shader compiler"); diff --git a/runtime/vk_device.c b/runtime/vk_device.c index 980f8670..ec421e51 100644 --- a/runtime/vk_device.c +++ b/runtime/vk_device.c @@ -690,6 +690,7 @@ int probe_vkdevice(void) { c->has_conditional_rendering, c->has_transform_feedback, c->has_provoking_vertex, c->has_robustness2, c->has_device_fault, c->has_memory_budget, c->has_buffer_device_address, c->has_fragment_shader_interlock, c->has_buffer_marker, c->has_nv_checkpoints, c->validation); + fatal_note(); // the line a fatal error or a crash would add to the log, to read it without one vk_shutdown(); printf("probe-vkdevice: %s (validation errors %ld)\n", g_errors_total ? "FAILED" : "passed", g_errors_total); return g_errors_total ? 1 : 0; diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index d6964751..1c17fd59 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -2617,7 +2617,7 @@ static const char *lz_why = ""; // the reason the log gave void vk_mem_lazy_decide(void) { const char *set = cfg_is_set("NX2NAVI_WB_LAZY") ? cfg_get("NX2NAVI_WB_LAZY") : NULL; - WblChoice ch = wb_lazy_choice(set, WBL_ON_WINDOWS, vk_caps.driver_id, vk_caps.driver_info); + WblChoice ch = wb_lazy_choice(set, WBL_ON_WINDOWS, vk_caps.driver_id); if (!vk_mirror_on) ch = (WblChoice){0, "no pool has a mirror in import mode"}; else if (shadow_on) ch = (WblChoice){0, "shadow storage keeps it off"}; else if (ch.on && cfg_bool("NX2NAVI_WB_PROBE")) ch = (WblChoice){0, "the write-back probe watches the same pages"}; diff --git a/runtime/wb_lazy_choice.h b/runtime/wb_lazy_choice.h index cf2e5fd9..ef9d31eb 100644 --- a/runtime/wb_lazy_choice.h +++ b/runtime/wb_lazy_choice.h @@ -4,23 +4,23 @@ // // The lazy write-back makes pages of guest memory inaccessible while a host-pointer import of them is bound to a buffer // the GPU writes, and copies their bytes down from inside the access-fault handler of whichever thread touched them. A -// driver is free to handle both differently, so the default is on only where it has run: -// - Windows, NVIDIA's driver: on. Measured and played there. -// - Windows, AMD's driver for RDNA 3 and newer: on. Builds with this default were measured on an RX 7900 XT (driver -// 26.10.1) standing in Hyrule Field and walking through a village (vk_exec_xfer.c oq_take and vk_exec_draw.c -// have numbers from that card). Whether fights were played on it is not recorded. -// - Windows, AMD's driver branch for RDNA 1 and 2 (RX 5000 and 6000; its driverInfo reads "AMD proprietary shader -// compiler", as vk_caps.c amd_sc tells it): off. Nobody has run it there under our eyes, and the one log of it -// there is an RX 6600 that lost its device 3.5 minutes into play (146 fetches in the 1,200 frames before; the -// GPU's last mark was inside a draw pass, not a fetch). That log does not prove the lazy write-back the cause: -// no failure path was found in the code, and cards with 8 GB lost their device the same way on NVIDIA before it -// existed. A second report, of a game that ended in fights on an AMD card of unknown model and ran for hours with -// a settings file that turns it off, changed several settings at once. Until one of these cards has run it with -// a log to compare, what shaders write goes back at the end of every submission there, as before 0.7.1, at that -// cost (about 90 fps against 65 standing in Hyrule Field on an RTX 5090; not measured on these cards). -// - Windows, any other driver: on, as 0.7.1 shipped it. No report from one. +// driver is free to handle both differently, so the default is on only where it has been played: +// - Windows, AMD's own driver: off. In the days after 0.7.1 turned it on for every card on Windows, two reports +// from AMD cards had the game end in play. An RX 6600 lost its device 3.5 minutes in with it on (146 fetches in +// the 1,200 frames before; the GPU's last mark was inside a draw pass, not a fetch). A player whose game ended in +// fights, on a card they did not name, then played for hours with a settings file that turns it off. Neither +// proves it the cause: the player changed several settings at once, cards with 8 GB lost their device the same +// way on NVIDIA before it existed, and no failure path was found in the code. But fights are where it is busiest +// (shaders write, the CPU reads back, every read faults and fetches), and nobody has played one on an AMD card +// under our eyes: builds with the default on were measured on an RX 7900 XT (driver 26.10.1) standing in Hyrule +// Field and walking through a village (vk_exec_xfer.c oq_take, vk_exec_draw.c), which says nothing about a fight, +// and none of us has a card of the driver branch for RDNA 1 and 2. Since the second report's card is unknown, the +// default is off on both of AMD's branches until a card of each has played fights with it on and a log to show. +// The cost is the frame rate in open areas, back to what it was before 0.7.1 (about 65 fps against 90 standing in +// Hyrule Field on an RTX 5090; not measured on AMD). +// - Windows, any other driver: on, as 0.7.1 shipped it. Measured and played on NVIDIA's; no report from Intel's. // - elsewhere: off, as before. The fetch inside the fault handler has only run on Windows. -// A value the player sets wins everywhere: wb_lazy = 1 turns it on for an RX 6000 card, wb_lazy = 0 off for any. +// A value the player sets wins everywhere: wb_lazy = 1 turns it on for an AMD card, wb_lazy = 0 off for any. #pragma once #include @@ -38,15 +38,9 @@ typedef struct { const char *why; // the end of the log line "mem: lazy write-back on|off: " } WblChoice; -// AMD's driver branch for RDNA 1 and 2: its own driver whose driverInfo names the older shader compiler. -static inline int wbl_amd_rdna12(uint32_t driver_id, const char *driver_info) { - return driver_id == WBL_DRIVER_AMD && driver_info && strstr(driver_info, "shader compiler") != NULL; -} - // set: the value the player gave NX2NAVI_WB_LAZY (the environment or nx2navi.ini), NULL or "" when they gave none. -// windows: the game runs on Windows (WBL_ON_WINDOWS). driver_id, driver_info: the device's VkDriverId and the -// driverInfo of its VkPhysicalDeviceDriverProperties. -static inline WblChoice wb_lazy_choice(const char *set, int windows, uint32_t driver_id, const char *driver_info) { +// windows: the game runs on Windows (WBL_ON_WINDOWS). driver_id: the device's VkDriverId. +static inline WblChoice wb_lazy_choice(const char *set, int windows, uint32_t driver_id) { if (set && *set) { if (!strcmp(set, "0")) return (WblChoice){0, "wb_lazy = 0 is set"}; return (WblChoice){1, "wb_lazy is set to on"}; @@ -54,10 +48,9 @@ static inline WblChoice wb_lazy_choice(const char *set, int windows, uint32_t dr if (!windows) return (WblChoice){0, "the default outside Windows, where its fetch inside the access-fault handler has not run " "(wb_lazy = 1 turns it on)"}; - if (wbl_amd_rdna12(driver_id, driver_info)) - return (WblChoice){0, "the default on AMD's driver for RX 5000 and 6000 cards, where it has not been tried by " - "us and a report had the game lose its device with it on; what shaders write goes back " - "at the end of every submission, which costs frame rate in open areas (wb_lazy = 1 turns " - "it on)"}; + if (driver_id == WBL_DRIVER_AMD) + return (WblChoice){0, "the default on AMD's driver, where reports had the game end in play with it on and the " + "cause is not found; what shaders write goes back at the end of every submission, which " + "costs frame rate in open areas (wb_lazy = 1 turns it on)"}; return (WblChoice){1, "the default on Windows (wb_lazy = 0 turns it off)"}; } diff --git a/tests/wb_lazy_check.c b/tests/wb_lazy_check.c index d36f3a15..f5e1deaf 100644 --- a/tests/wb_lazy_check.c +++ b/tests/wb_lazy_check.c @@ -13,69 +13,51 @@ static int fails; enum { AMD_PROPRIETARY = 1, AMD_OPEN_SOURCE = 2, MESA_RADV = 3, NVIDIA_PROPRIETARY = 4, INTEL_WINDOWS = 5, MESA_NVK = 24 }; enum { LINUX = 0, WINDOWS = 1 }; -// driverInfo as the drivers report it: AMD's branch for RDNA 1 and 2 (an RX 6600's log), its driver for RDNA 3 and -// newer, NVIDIA's, Mesa's. -static const char RDNA12[] = "26.10.2 (AMD proprietary shader compiler)"; -static const char RDNA34[] = "26.10.1 (LLPC)"; -static const char NVIDIA[] = "617.42"; -static const char MESA[] = "Mesa 26.0.1"; - -typedef struct { unsigned id; const char *info; const char *name; } Driver; -static const Driver drivers[] = { - {AMD_PROPRIETARY, RDNA12, "AMD RDNA 1/2"}, {AMD_PROPRIETARY, RDNA34, "AMD RDNA 3+"}, {AMD_OPEN_SOURCE, "", "AMD open"}, - {MESA_RADV, MESA, "RADV"}, {NVIDIA_PROPRIETARY, NVIDIA, "NVIDIA"}, {INTEL_WINDOWS, "", "Intel"}, {MESA_NVK, MESA, "NVK"}, - {0, NULL, "unknown"}, -}; -enum { ND = sizeof drivers / sizeof *drivers }; - static int has(const char *s, const char *part) { return s && strstr(s, part) != NULL; } int main(void) { - // Nothing set, Windows: on, except on AMD's driver branch for RDNA 1 and 2. - WblChoice nv = wb_lazy_choice(NULL, WINDOWS, NVIDIA_PROPRIETARY, NVIDIA); + static const unsigned drivers[] = {AMD_PROPRIETARY, AMD_OPEN_SOURCE, MESA_RADV, NVIDIA_PROPRIETARY, INTEL_WINDOWS, + MESA_NVK, 0}; + enum { ND = sizeof drivers / sizeof *drivers }; + + // Nothing set, Windows: on, except on AMD's own driver (both of its branches report this id). + WblChoice nv = wb_lazy_choice(NULL, WINDOWS, NVIDIA_PROPRIETARY); CHECK(nv.on == 1, "Windows, NVIDIA's driver, nothing set: on"); CHECK(has(nv.why, "default") && has(nv.why, "wb_lazy = 0"), "it says it is the default and how to turn it off: %s", nv.why); - CHECK(wb_lazy_choice(NULL, WINDOWS, AMD_PROPRIETARY, RDNA34).on == 1, "Windows, AMD's driver for RDNA 3 and newer: on"); - CHECK(wb_lazy_choice(NULL, WINDOWS, INTEL_WINDOWS, "").on == 1, "Windows, Intel's driver, nothing set: on"); - CHECK(wb_lazy_choice(NULL, WINDOWS, 0, NULL).on == 1, "Windows, a driver that reports nothing: on, as 0.7.1 had it"); - WblChoice amd = wb_lazy_choice(NULL, WINDOWS, AMD_PROPRIETARY, RDNA12); - CHECK(amd.on == 0, "Windows, AMD's driver for RDNA 1 and 2, nothing set: off"); - CHECK(has(amd.why, "AMD") && has(amd.why, "RX 5000 and 6000") && has(amd.why, "wb_lazy = 1"), - "it names the driver's cards and how to turn it on: %s", amd.why); + CHECK(wb_lazy_choice(NULL, WINDOWS, INTEL_WINDOWS).on == 1, "Windows, Intel's driver, nothing set: on"); + CHECK(wb_lazy_choice(NULL, WINDOWS, 0).on == 1, "Windows, a driver that reports no id: on, as 0.7.1 had it"); + WblChoice amd = wb_lazy_choice(NULL, WINDOWS, AMD_PROPRIETARY); + CHECK(amd.on == 0, "Windows, AMD's driver, nothing set: off"); + CHECK(has(amd.why, "AMD") && has(amd.why, "wb_lazy = 1"), "it names the driver and how to turn it on: %s", amd.why); CHECK(has(amd.why, "frame rate"), "it says what off costs: %s", amd.why); CHECK(has(amd.why, "default"), "it says it is a default: %s", amd.why); - // The branch is told by the driver and its driverInfo together, as vk_caps.c tells it: another driver whose - // driverInfo happened to hold the words is not AMD's. - CHECK(wbl_amd_rdna12(AMD_PROPRIETARY, RDNA12) && !wbl_amd_rdna12(AMD_PROPRIETARY, RDNA34), "the branch by driverInfo"); - CHECK(!wbl_amd_rdna12(AMD_PROPRIETARY, NULL) && !wbl_amd_rdna12(AMD_PROPRIETARY, ""), "no driverInfo: not the branch"); - CHECK(!wbl_amd_rdna12(NVIDIA_PROPRIETARY, RDNA12) && wb_lazy_choice(NULL, WINDOWS, MESA_RADV, RDNA12).on == 1, - "the words alone, under another driver: not the branch"); - // An empty value is no value (cfg.c add: "key =" leaves the setting at its default). - CHECK(wb_lazy_choice("", WINDOWS, AMD_PROPRIETARY, RDNA12).on == 0, "an empty value on the RDNA 1/2 branch: the default, off"); - CHECK(wb_lazy_choice("", WINDOWS, NVIDIA_PROPRIETARY, NVIDIA).on == 1, "an empty value on NVIDIA: the default, on"); + CHECK(wb_lazy_choice("", WINDOWS, AMD_PROPRIETARY).on == 0, "an empty value on AMD: the default, off"); + CHECK(wb_lazy_choice("", WINDOWS, NVIDIA_PROPRIETARY).on == 1, "an empty value on NVIDIA: the default, on"); // Nothing set, elsewhere: off on every driver. for (int i = 0; i < ND; i++) { - WblChoice c = wb_lazy_choice(NULL, LINUX, drivers[i].id, drivers[i].info); - CHECK(c.on == 0 && has(c.why, "wb_lazy = 1"), "Linux, %s, nothing set: off, and how to turn it on: %s", - drivers[i].name, c.why); + WblChoice c = wb_lazy_choice(NULL, LINUX, drivers[i]); + CHECK(c.on == 0 && has(c.why, "wb_lazy = 1"), "Linux, driver %u, nothing set: off, and how to turn it on: %s", + drivers[i], c.why); } // What the player sets wins on every platform and driver, and the reason says it was set. for (int os = LINUX; os <= WINDOWS; os++) for (int i = 0; i < ND; i++) { - WblChoice on = wb_lazy_choice("1", os, drivers[i].id, drivers[i].info); - WblChoice off = wb_lazy_choice("0", os, drivers[i].id, drivers[i].info); - CHECK(on.on == 1 && has(on.why, "set"), "os %d, %s, wb_lazy = 1: on (%s)", os, drivers[i].name, on.why); - CHECK(off.on == 0 && has(off.why, "set"), "os %d, %s, wb_lazy = 0: off (%s)", os, drivers[i].name, off.why); - CHECK(!has(on.why, "default") && !has(off.why, "default"), "os %d, %s: a set value is not a default", os, - drivers[i].name); + WblChoice on = wb_lazy_choice("1", os, drivers[i]), off = wb_lazy_choice("0", os, drivers[i]); + CHECK(on.on == 1 && has(on.why, "set"), "os %d driver %u, wb_lazy = 1: on (%s)", os, drivers[i], on.why); + CHECK(off.on == 0 && has(off.why, "set"), "os %d driver %u, wb_lazy = 0: off (%s)", os, drivers[i], off.why); + CHECK(!has(on.why, "default") && !has(off.why, "default"), "os %d driver %u: a set value is not a default", os, + drivers[i]); } // Any value but 0 counts as on, as cfg_bool reads it for memory.c mem_init. - CHECK(wb_lazy_choice("on", WINDOWS, AMD_PROPRIETARY, RDNA12).on == 1, "wb_lazy = on: on"); + CHECK(wb_lazy_choice("on", WINDOWS, AMD_PROPRIETARY).on == 1, "wb_lazy = on: on"); + // The exception is the driver, not the vendor: another driver for AMD cards follows its platform's default. + CHECK(wb_lazy_choice(NULL, WINDOWS, AMD_OPEN_SOURCE).on == 1 && wb_lazy_choice(NULL, WINDOWS, MESA_RADV).on == 1, + "the exception is AMD's own driver"); CHECK(WBL_DRIVER_AMD == AMD_PROPRIETARY, "WBL_DRIVER_AMD is VK_DRIVER_ID_AMD_PROPRIETARY"); // The game passes the platform it was built for.