Turn the lazy write-back on by default on Windows and take its row out of the settings menu.

The user asked for this once the flicker fix was measured. The single-frame flicker that kept it off in 0.7.0 came from frames drawn before the game's signal that their data was written, which the previous commit fixes; the lazy write-back only made the frames come faster, so the signal fell into the replay more often. wb_lazy = 0 in nx2navi.ini still turns it off, and an ini that already holds the key keeps its value. Elsewhere than Windows the default stays 0, as its fetch inside the access-fault handler has never run there.

Measured on the build of the previous commit, 1,800 presented frames a run, standing in Hyrule Field by day with DLSS Performance, frame generation 4x and HDR. With the lazy write-back on and eight busy threads beside the game: 38 and 0 single-frame spikes with the fix switched off (408 and 44 frames whose signal came during the replay), 0 and 0 with it on (667 and 724 such frames). With it off and the same load: 0 spikes in four runs, two with the fix and two without, 86 to 140 such frames each. Without load, one run each: 88.5 frames a second with the fix against 93.3 without it with the lazy write-back on (GPU 7.2 against 6.8 ms a frame, 6.53 against 6.48 submissions a frame), 71.0 against 65.6 with it off, so the fix's cost is inside the run-to-run spread; every run ended cleanly without a fatal error. This build was started once with no setting anywhere: the lazy write-back was on, and the Screen tab shows no row for it.

Not measured: play by hand with the lazy write-back on and the fix (the user's sessions so far ran with it off), other areas than Hyrule Field, and more than one run for the frame rates.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-10 10:51:04 -05:00
parent c1951d2b37
commit 381264165a
7 changed files with 23 additions and 37 deletions

View File

@@ -684,12 +684,11 @@
# 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
# 0: what the game's shaders write into its memory is copied back from the video card at the end of every GPU
# submission. 1 (experimental): copied back 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. With 1, single
# frames of the scene can flicker; tell us what you see if you try it. In the settings menu: Experimental FPS boost
# (Screen tab). With shadow storage (Linux, Wine) it stays off.
# wb_lazy = 0
# 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.
# wb_lazy = 1
# Linux, shadow storage: 1 clears the write watch's protection of a range in one call before the GPU's bytes are copied
# back into the game's memory, instead of taking a fault at the first store into each page.
# shadow_bulk_write = 0

View File

@@ -134,6 +134,14 @@ static const struct { const char *key, *section; } sections[] = {
// value (it depends on the machine); its consumer reads cfg_get and keeps an "unset" branch.
#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).
#ifdef _WIN32
#define WB_LAZY_DEFAULT "1"
#else
#define WB_LAZY_DEFAULT "0"
#endif
static const CfgMeta metas[] = {
// Screen
{"FULLSCREEN", "0", "0|1", LIVE}, {"WINDOW_SIZE", "1920x1080", NULL, LIVE},
@@ -251,7 +259,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", RESTART}, {"WB_LAZY", "0", "0|1", RESTART}, {"WB_LAZY_TOUCH", "0", "0..16", 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", RESTART}, {"WB_LAZY", WB_LAZY_DEFAULT, "0|1", RESTART}, {"WB_LAZY_TOUCH", "0", "0..16", 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

View File

@@ -108,10 +108,13 @@ static void unprobe_locked(uint64_t r) {
plat_dec32(&nprb);
}
// Lazy write-back (NX2NAVI_WB_LAZY, default 0, vk_memory.c "lazy write-back"). Off by default: with it on, single
// frames come out with the whole scene lit differently (brighter, shadows off). The flight recorder's thumbnails of
// 1,800 presents standing in Hyrule Field show none with it off and 10 to 180 with it on, most when other programs keep
// the CPU busy; the cause is not found (2026-11-10). What a shader wrote into a mirrored pool is
// Lazy write-back (NX2NAVI_WB_LAZY, default 1 on Windows and 0 elsewhere, 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
// (vk_exec_xfer.c "events the CPU signals"), and with the write-backs gone the frames came faster and the signal fell
// into the replay more often. With that fixed, two such runs under eight busy threads showed none.
// What a shader wrote into a mirrored pool is
// copied back into guest memory at the end of every submission, in case the CPU reads it. Ocarina's CPU does not read
// most of it: standing in Hyrule Field, 66 MiB a frame went back over PCIe, 7 to 9 ms of each frame's 13 to 15 ms of
// GPU time, and the write-back probe found no access to it in 40 s. So a range that went back once is armed here: its
@@ -637,7 +640,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")) { // off unless set; armed only once the back end can fetch (mem_lazy_enable)
} else if (cfg_bool("NX2NAVI_WB_LAZY")) { // armed only once the back end can fetch (mem_lazy_enable)
plat_mem_access_hook(access_fault);
lz_want = 1;
}

View File

@@ -1062,11 +1062,6 @@ static void tab_screen(float scale) {
row_gpu();
static const UiTextId perf[] = {UI_MENU_PERF_OFF, UI_MENU_PERF_FPS, UI_MENU_PERF_FULL};
opt_choice("NX2NAVI_PERF_OVERLAY", UI_MENU_PERF_OVERLAY, perf, 3, UI_MENU_PERF_OVERLAY_DESC);
#ifdef _WIN32
// The lazy write-back (memory.c "Lazy write-back"), off by default and read at the start: the row notes the restart.
// Not offered where its fetch inside the access-fault handler has never run.
opt_toggle("NX2NAVI_WB_LAZY", UI_MENU_FPS_BOOST, UI_MENU_FPS_BOOST_DESC);
#endif
opt_group(UI_MENU_GRAPHICS);
// The game resolution needs the output and scene patch sets (resolution.c res_adjustable): Ocarina's build has
// none and always draws its own size, so the row would change nothing

View File

@@ -88,11 +88,6 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_TEX_DETAIL_DESC] = "Sharpness of large surface textures. Reduced and Low leave out their largest versions, so that an area fits the video memory of 6 and 8 GB cards; only surfaces seen up close look softer. Automatic picks by the card's video memory.",
[UI_MENU_TEX_DETAIL_AUTO] = "Automatic: %s",
[UI_MENU_TEX_DETAIL_FULL] = "Full", [UI_MENU_TEX_DETAIL_REDUCED] = "Reduced", [UI_MENU_TEX_DETAIL_LOW] = "Low",
[UI_MENU_FPS_BOOST] = "Experimental FPS boost",
[UI_MENU_FPS_BOOST_DESC] = "What the game's shaders write into its memory is copied back from the video card only "
"when the game's own code needs it, instead of after every step of a frame. About a "
"third more frames per second in large open areas. Experimental: single frames can "
"flicker with it on. Off by default.",
[UI_MENU_SHARPNESS] = "FSR sharpness",
[UI_MENU_SHARPNESS_DESC] = "How sharp FSR makes the picture. 0 turns it off.",
[UI_MENU_SHARPNESS_NEEDS_FSR] = "only with AMD FSR 1 or FSR 3.1",
@@ -657,11 +652,6 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_TEX_DETAIL_DESC] = "Чёткость больших текстур поверхностей. «Сниженная» и «Низкая» не загружают их самые крупные версии, чтобы область помещалась в видеопамять карт на 6 и 8 ГБ; мягче выглядят только поверхности вблизи. «Авто» выбирает по объёму видеопамяти.",
[UI_MENU_TEX_DETAIL_AUTO] = "Авто: %s",
[UI_MENU_TEX_DETAIL_FULL] = "Полная", [UI_MENU_TEX_DETAIL_REDUCED] = "Сниженная", [UI_MENU_TEX_DETAIL_LOW] = "Низкая",
[UI_MENU_FPS_BOOST] = "Экспериментальное ускорение FPS",
[UI_MENU_FPS_BOOST_DESC] = "То, что шейдеры игры записывают в её память, копируется с видеокарты обратно только "
"тогда, когда это нужно коду самой игры, а не после каждого этапа кадра. Примерно на "
"треть больше кадров в секунду на больших открытых пространствах. Экспериментально: "
"отдельные кадры могут мерцать. По умолчанию выключено.",
[UI_MENU_SHARPNESS] = "Резкость FSR",
[UI_MENU_SHARPNESS_DESC] = "Насколько FSR повышает резкость. 0 отключает.",
[UI_MENU_SHARPNESS_NEEDS_FSR] = "только с AMD FSR 1",
@@ -1475,11 +1465,6 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
"da placa.",
[UI_MENU_TEX_DETAIL_AUTO] = "Automático: %s",
[UI_MENU_TEX_DETAIL_FULL] = "Completo", [UI_MENU_TEX_DETAIL_REDUCED] = "Reduzido", [UI_MENU_TEX_DETAIL_LOW] = "Baixo",
[UI_MENU_FPS_BOOST] = "Aumento de FPS experimental",
[UI_MENU_FPS_BOOST_DESC] = "O que os shaders do jogo escrevem na memória dele só é copiado de volta da placa de "
"vídeo quando o próprio código do jogo precisa, em vez de após cada etapa do quadro. "
"Cerca de um terço a mais de quadros por segundo em grandes áreas abertas. "
"Experimental: quadros isolados podem piscar com isto ligado. Desligado por padrão.",
[UI_MENU_COLOR] = "Cor",
[UI_MENU_COLOR_PRESET] = "Perfil de cor",
[UI_MENU_COLOR_PRESET_DESC] = "Define os quatro valores abaixo. Vívido: mais contraste e saturação, sombras um "
@@ -2164,9 +2149,6 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_TEX_DETAIL_DESC] = "大型表面纹理的清晰度。“降低”和“低”不加载它们最大的版本,使一个区域能放进 6 GB 和 8 GB 显卡的显存;只有近处的表面看起来略微柔和。“自动”根据显卡的显存选择。",
[UI_MENU_TEX_DETAIL_AUTO] = "自动:%s",
[UI_MENU_TEX_DETAIL_FULL] = "完整", [UI_MENU_TEX_DETAIL_REDUCED] = "降低", [UI_MENU_TEX_DETAIL_LOW] = "低",
[UI_MENU_FPS_BOOST] = "实验性帧率提升",
[UI_MENU_FPS_BOOST_DESC] = "游戏着色器写入其内存的数据,只有在游戏自身的代码需要时才从显卡复制回来,而不是在每帧的每个阶段之后都"
"复制。在大型开放区域中帧率提高约三分之一。实验性功能:开启后个别帧可能闪烁。默认关闭。",
[UI_MENU_HDR_GROUP] = "HDR",
[UI_MENU_HDR] = "HDR 输出",
[UI_MENU_HDR_DESC] = "在 HDR 显示器上呈现更亮的高光。请先在 Windows 中开启 HDR。",

View File

@@ -44,7 +44,6 @@ typedef enum {
UI_MENU_TEX_DETAIL, UI_MENU_TEX_DETAIL_DESC,
UI_MENU_TEX_DETAIL_AUTO, // "Automatic: %s", %s the level it picks on this card
UI_MENU_TEX_DETAIL_FULL, UI_MENU_TEX_DETAIL_REDUCED, UI_MENU_TEX_DETAIL_LOW,
UI_MENU_FPS_BOOST, UI_MENU_FPS_BOOST_DESC,
UI_MENU_SHARPNESS, UI_MENU_SHARPNESS_DESC, UI_MENU_SHARPNESS_NEEDS_FSR,
UI_MENU_COLOR, // group heading over the colour rows
UI_MENU_COLOR_PRESET, UI_MENU_COLOR_PRESET_DESC, UI_MENU_COLOR_DEFAULT, UI_MENU_COLOR_VIVID, UI_MENU_COLOR_CLARITY,

View File

@@ -2499,7 +2499,7 @@ static void snap_free(void *arg) { // completion thread: the submission is don
free(f);
}
// ---- lazy write-back (NX2NAVI_WB_LAZY, default 0; memory.c "Lazy write-back")
// ---- lazy write-back (NX2NAVI_WB_LAZY, default 1 on Windows; 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