Files
NX2navi/runtime/wb_lazy_choice.h
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

64 lines
4.2 KiB
C

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