From 9dbfed207f538e5c8a0f9230399783ab2a11c849 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Tue, 10 Nov 2026 07:12:23 -0500 Subject: [PATCH] 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 --- docs/releases/v0.7.0.md | 25 +++++++++++++++---------- nx2navi.ini.example | 10 ++++++---- runtime/cfg.c | 2 +- runtime/memory.c | 11 +++++------ runtime/ui/menu.cpp | 5 +++++ runtime/ui_text.c | 18 ++++++++++++++++++ runtime/ui_text.h | 1 + runtime/vk_memory.c | 2 +- 8 files changed, 52 insertions(+), 22 deletions(-) diff --git a/docs/releases/v0.7.0.md b/docs/releases/v0.7.0.md index deac0e42..3b5c000e 100644 --- a/docs/releases/v0.7.0.md +++ b/docs/releases/v0.7.0.md @@ -1,5 +1,5 @@ A performance and feature release for *The Legend of Zelda: Ocarina of Time* for Nintendo Switch 2 (game version -1.1.1): a much higher frame rate in open areas and towns, less memory, DLSS Multi Frame Generation, save sharing, a +1.1.1): a higher frame rate in towns and less stutter, less memory, DLSS Multi Frame Generation, save sharing, a launcher you can restyle, and many fixes. **No game files are included**: the setup builds the game on your PC from your own dump. @@ -21,11 +21,6 @@ cards). ## Faster -- **Open areas.** What the game's shaders write into its memory was copied back from the video card after every GPU - submission, in case the game's CPU code reads it: 66 MiB a frame in Hyrule Field, more than half of the frame's GPU - time. It is now copied once and after that only when the CPU touches it. Standing in Hyrule Field on our test PC - (RTX 5090, 3416x1440, DLAA) that is 76 fps instead of 57. `wb_lazy = 0` in `nx2navi.ini` brings the old behaviour - back; on Linux it is off unless you set `wb_lazy = 1`. - **Towns.** Large towns release and take back thousands of textures a second, and every one made the game's texture table look up about 10,000 entries again. A texture that comes back unchanged now leaves the table alone. - **Every frame.** The wait after a frame's first GPU submission no longer includes the copy back to memory (3 to 4 ms @@ -33,7 +28,13 @@ cards). - **Less stutter.** Textures are created over several frames instead of all at once, shaders are read from the disk off the render thread, a controller that connects or disconnects no longer stalls the game for 100 ms and more, and DLSS Frame Generation no longer makes 100 to 150 ms frames after menus and cutscenes. -- **Less memory.** With a full shader cache the game holds about 1.7 GiB less video memory from the title screen on +- **Experimental FPS boost** (Screen tab of the settings menu, off by default, takes effect after a restart; `wb_lazy` + in `nx2navi.ini`). What the game's shaders write into its memory is copied back from the video card after every GPU + submission, in case the game's CPU code reads it: 66 MiB a frame in Hyrule Field, more than half of the frame's GPU + time. With the boost on it is copied once and after that only when the CPU touches it: standing in Hyrule Field on + our test PC (RTX 5090, 3416x1440, DLAA) that is 76 fps instead of 57. It is experimental because single frames of the + scene can flicker with it on, more when other programs keep the processor busy; tell us what you see if you try it. +- **Less memory.** With a full shader cache the game holds about 1.6 GiB less video memory from the title screen on (twenty very large shaders the game never runs were created at every start), video memory blocks are smaller, DLSS models that are not in use are freed, textures no shader has sampled for two minutes give way when memory runs low, and textures give way before the game's buffers lose their place in video memory. @@ -72,6 +73,12 @@ cards). pass among them once its 50 ms were spent, and the frame was shown without it. Such a frame is no longer shown: the previous picture stays for the frame or two it takes, while the game runs on (`frame_hold_ms`, 120 by default; 0 shows every frame as before). +- A dark or black flash when a DLSS or FSR 3.1 mode was picked in the settings menu. The game makes its scene images + again at the new size and the first frames drawn into them came out dark or black; the previous picture now stays + on screen for those few frames, with frame generation on as well. +- The ground, walls and buildings drawn black for the first second or seconds after a load screen (longer on a busy or + slower processor). An area's textures were made a few dozen a frame like textures that stream in during play; after a + load they are now made at once, before the area fades in. - The performance overlay's VRAM line counted every program on the graphics card as if it were the game. It now shows the game's own share beside it (*game 6.8 GB* of 10.4 GB in use, in one measurement). - Textures that turned dark or blank for a moment: textures out of view were dropped after 11 seconds at 165 fps (30 @@ -114,9 +121,7 @@ cards). - Integrated AMD GPUs can fail at the title screen (their host memory heap is too small for the game's memory). - Opening the game's settings menu can crash on some AMD Radeon GPUs. - A rare crash in the game's particle code. -- The new copy-on-touch of shader-written memory is the largest change in this release. If something behaves wrong - that did not before (physics, effects, a picture), set `wb_lazy = 0` in `nx2navi.ini`, and tell us whether that - cures it. +- With *Experimental FPS boost* on (off by default) single frames of the scene can flicker. ## For builders diff --git a/nx2navi.ini.example b/nx2navi.ini.example index e742928e..3314b8d9 100644 --- a/nx2navi.ini.example +++ b/nx2navi.ini.example @@ -646,10 +646,12 @@ # 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 -# 1: 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). 0: copied back at the end of -# every GPU submission, as before. On Linux it is off unless set here. -# wb_lazy = 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). +# wb_lazy = 0 # 1: the game's flushes of mirrored memory are copied into the mirrors even where the write watch already sees every # page the game wrote; 0 (default) copies only the written pages there, which saved 47-57 MiB of copies a frame in # Kokiri Forest. diff --git a/runtime/cfg.c b/runtime/cfg.c index b2b0dd95..52af67b1 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -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 diff --git a/runtime/memory.c b/runtime/memory.c index 2906b1b5..2b3853ba 100644 --- a/runtime/memory.c +++ b/runtime/memory.c @@ -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; } diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index e44685cc..e7bedbe2 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -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 diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 8d83cb7b..3103ce42 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -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。", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 657bd2f2..4a02137f 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -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, diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index 091cae66..61afe5c4 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -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