Files
NX2navi/tests/wb_lazy_check.c
chrg6 caf50ecf1c 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>
2026-11-10 15:14:25 -05:00

91 lines
5.2 KiB
C

// 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 <stdio.h>
#include <string.h>
#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;
}