Turn the lazy write-back off by default and offer it in the settings menu as Experimental FPS boost.

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 in every run, and with it on 43 to 181
while four other threads keep the CPU busy (10 to 97 in earlier runs, 0 on an idle machine); the cause is not found.
Two candidate fixes (arming only against a sync whose copies were handed over, and snapshots waiting for GPU writes in
flight) did not change the count, and fetching at every release made it far worse.

So wb_lazy is 0 unless set, on every platform (mem_init loses its special case), and the Screen tab has the row
Experimental FPS boost for it on Windows, with its text in the four menu languages; like every setting read at the
start it notes "after restart". The 0.7.0 notes describe it as experimental and off, say about 1.6 GiB for the video
memory a full shader cache no longer holds (2,484 to 846 MiB at the title screen in the measured run), and list the
two fixes before this one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-10 07:12:23 -05:00
parent 71eb5fbe26
commit 9dbfed207f
8 changed files with 52 additions and 22 deletions

View File

@@ -245,7 +245,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", "1", "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", "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_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,7 +108,10 @@ static void unprobe_locked(uint64_t r) {
plat_dec32(&nprb);
}
// Lazy write-back (NX2NAVI_WB_LAZY, vk_memory.c "lazy write-back"). What a shader wrote into a mirrored pool used to be
// 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
// 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
@@ -634,11 +637,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);
#ifdef _WIN32
} else if (cfg_bool("NX2NAVI_WB_LAZY")) { // armed only once the back end can fetch (mem_lazy_enable)
#else // the fetch runs inside the access-fault handler, which has not run on this platform yet: only when set
} else if (cfg_bool("NX2NAVI_WB_LAZY") && cfg_is_set("NX2NAVI_WB_LAZY")) {
#endif
} else if (cfg_bool("NX2NAVI_WB_LAZY")) { // off unless set; armed only once the back end can fetch (mem_lazy_enable)
plat_mem_access_hook(access_fault);
lz_want = 1;
}

View File

@@ -975,6 +975,11 @@ 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

@@ -84,6 +84,11 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_ANISO] = "Texture filtering",
[UI_MENU_ANISO_DESC] = "Anisotropic filtering of surface textures: ground, roads and walls seen at a shallow angle stay sharp into the distance instead of blurring. Game: the level the game asks for, as on the Switch.",
[UI_MENU_ANISO_GAME] = "Game",
[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",
@@ -628,6 +633,11 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_ANISO] = "Фильтрация текстур",
[UI_MENU_ANISO_DESC] = "Анизотропная фильтрация текстур поверхностей: земля, дороги и стены под острым углом остаются чёткими вдали, а не размываются. Игра: уровень, который запрашивает игра, как на Switch.",
[UI_MENU_ANISO_GAME] = "Игра",
[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",
@@ -1432,6 +1442,11 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
"ângulo raso continuam nítidos ao longe em vez de borrar. Jogo: o nível que o jogo pede, "
"como no Switch.",
[UI_MENU_ANISO_GAME] = "Jogo",
[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 "
@@ -2111,6 +2126,9 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_ANISO] = "纹理过滤",
[UI_MENU_ANISO_DESC] = "表面纹理的各向异性过滤:以小角度看到的地面、道路和墙壁在远处依然清晰,而不会模糊。游戏:使用游戏请求的级别,与 Switch 上相同。",
[UI_MENU_ANISO_GAME] = "游戏",
[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

@@ -41,6 +41,7 @@ typedef enum {
UI_MENU_FOV, UI_MENU_FOV_DESC,
UI_MENU_SHADOW_RES, UI_MENU_SHADOW_RES_DESC, UI_MENU_SHADOW_RES_GAME,
UI_MENU_ANISO, UI_MENU_ANISO_DESC, UI_MENU_ANISO_GAME,
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

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