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 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-10 15:14:25 -05:00
parent e8f5f8e01e
commit caf50ecf1c
20 changed files with 504 additions and 18 deletions

View File

@@ -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);