From 47f6aef2f60bf3aaf84e63818750463990ebd2f1 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Tue, 10 Nov 2026 23:56:29 -0500 Subject: [PATCH] Turn the piece release of the lazy write-back off by default: with it on the graphics device was lost after some save loads. Loading a save in Hyrule Field at night lost the device about 2 s after the load in 7 of about 22 loads on an RTX 5090 (a GPU read fault at the start of a large buffer, in or right after one of the game's compute dispatches). With the lazy write-back off it loaded 10 times of 10, and with only the piece release off 15 times of 15. How the piece release leads to the fault is not known; until it is, a CPU touch releases its whole range again, as before the town performance pass. wb_lazy_chunk = 1 turns it back on. Co-Authored-By: Claude Fable 5.2 --- nx2navi.ini.example | 6 ++++-- runtime/cfg.c | 2 +- runtime/memory.c | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/nx2navi.ini.example b/nx2navi.ini.example index 686b88ac..ee298122 100644 --- a/nx2navi.ini.example +++ b/nx2navi.ini.example @@ -754,11 +754,13 @@ # "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 -# With wb_lazy: 1: when the game's CPU code touches such memory, only the 64 KiB around the place it touched are copied +# With wb_lazy, off by default: with it on the graphics device was lost shortly after some save loads (about one load +# in three of a save in Hyrule Field at night on one card), and not once in 15 loads with it off; the cause is open. +# 1: when the game's CPU code touches such memory, only the 64 KiB around the place it touched are copied # back and kept up to date from then on; the rest of that buffer stays on the video card. The game reads a few words # at the start of buffers of several MiB about twice a second. 0: the whole buffer comes back and everything near it # is copied back every frame for up to 32 seconds, as before (a tenth fewer frames a second in a village). -# wb_lazy_chunk = 1 +# wb_lazy_chunk = 0 # 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. # 0: a full barrier before every pass and every dispatch. Default: 1 on NVIDIA graphics cards, 0 on all others, where it diff --git a/runtime/cfg.c b/runtime/cfg.c index 8cf00fa0..9880d1cc 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -281,7 +281,7 @@ static const CfgMeta metas[] = { {"VK_NOOPT", "0", "0|1", RESTART}, // vk_pipeline.c noopt_flag // diagnostics {"TRACE", "", NULL, RESTART}, {"FLIGHT", "0", "0|1", RESTART}, {"FLIGHT_SPIKE_MS", "100", "0..60000", RESTART}, - {"WB_FENCE_LIMIT", "65536", "0..1073741824", RESTART}, {"WB_MERGE", "1", "0|1", RESTART}, {"WB_EXACT", "1", "0|1", RESTART}, {"MEM_CENSUS", "0", "0|1", RESTART}, {"WB_NO_REUP", "1", "0|1", RESTART}, {"WB_PROBE", "0", "0|1", RESTART}, {"WB_SPLIT", "1", "0|1|2", RESTART}, {"WB_LAZY", WB_LAZY_DEFAULT, "0|1", RESTART}, {"HEAP_LAZY", "0", "0|1", RESTART}, {"WB_LAZY_TOUCH", "0", "0..16", RESTART}, {"WB_LAZY_CHUNK", "1", "0|1", RESTART}, {"FLUSH_UPLOAD", "0", "0|1", RESTART}, {"GPA_TWIN_MAX_KB", "0", "0..1048576", RESTART}, + {"WB_FENCE_LIMIT", "65536", "0..1073741824", RESTART}, {"WB_MERGE", "1", "0|1", RESTART}, {"WB_EXACT", "1", "0|1", RESTART}, {"MEM_CENSUS", "0", "0|1", RESTART}, {"WB_NO_REUP", "1", "0|1", RESTART}, {"WB_PROBE", "0", "0|1", RESTART}, {"WB_SPLIT", "1", "0|1|2", RESTART}, {"WB_LAZY", WB_LAZY_DEFAULT, "0|1", RESTART}, {"HEAP_LAZY", "0", "0|1", RESTART}, {"WB_LAZY_TOUCH", "0", "0..16", RESTART}, {"WB_LAZY_CHUNK", "0", "0|1", RESTART}, {"FLUSH_UPLOAD", "0", "0|1", RESTART}, {"GPA_TWIN_MAX_KB", "0", "0..1048576", RESTART}, {"WB_MERGE_MAX", "32", "1..256", RESTART}, {"TEXUP_LOG_MS", "0", "0..60000", RESTART}, // vk_texture.c vk_texstat_frame {"VMA_BLOCK_MB", "64", "16..256", RESTART}, // vk_headroom.c vk_vma_block_size {"ASTC_BC_PROBE", "0", "0|1", RESTART}, // vk_texture.c astc_probe_alpha diff --git a/runtime/memory.c b/runtime/memory.c index ff404b82..b500e353 100644 --- a/runtime/memory.c +++ b/runtime/memory.c @@ -155,7 +155,9 @@ static uint64_t lz_unclean; // frz_lock: arms refused since the last // in the partial pages at a range's ends. They are written back at every submission that writes them. enum { LZ_NO_FROZEN, LZ_NO_HOT, LZ_NO_THAW, LZ_NO_PAGES, LZ_NO_EDGE, LZ_NO_N }; static uint64_t lz_no[LZ_NO_N], lz_no_small, lz_arm_calls; // ranges without a whole page; ranges written back -// NX2NAVI_WB_LAZY_CHUNK (default 1; 0 = a touch releases its whole range and holds its regions, as before): the +// NX2NAVI_WB_LAZY_CHUNK (default 0 = a touch releases its whole range and holds its regions; off because with it on +// the graphics device was lost about 2 s after a save load in Hyrule Field at night, in 7 of about 22 loads on an +// RTX 5090, a GPU read fault at the start of a large buffer, and in 0 of 15 with it off; why is not known yet): the // first touch of an armed range gives back only the LZ_CHUNK bytes around the address, fetched alone, and only that // piece is held (lz_hots, 1 s doubling to 32 s like a region's hold); the rest of the range stays armed. More than // LZ_HEAVY_N touches in one region within LZ_HEAVY_MS are a reader going through the range: its range goes whole