From aed3e83cc248b22b793a7c97934c72c86c2726bf Mon Sep 17 00:00:00 2001 From: ExpertKT Date: Mon, 2 Nov 2026 19:41:07 +0800 Subject: [PATCH 01/10] Say in totk.ini.example that the frame limit should divide the monitor's refresh rate --- totk.ini.example | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/totk.ini.example b/totk.ini.example index 227a923f..bb0892f8 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -7,6 +7,12 @@ # Frame rate limit: 30, 40, 45, 60, 90, 120, 144, any whole rate from 30 to 240, or display (the refresh rate of the # window's monitor, at most 240). A higher rate gives 240: above it the game's physics runs out of memory. Above 60 # is experimental and needs realtime = 1. Changes while the game runs take effect at once. +# With mailbox or fifo presentation (vk_present, the default) a frame reaches the screen at a vertical blank, so a limit +# that does not divide the monitor's refresh rate keeps each frame on screen for a different number of refreshes. On a +# 320 Hz monitor 80, 64, 40 and 32 divide it and 90 does not: 90 fps alternates 3 and 4 refreshes per frame, which reads +# as judder while the frame counter still shows 90. Likewise on 240 Hz 60, 48 and 40 divide it and on 144 Hz 72, 48 and +# 36 do, while 60 does not. vk_present = immediate shows a frame as soon as it is presented, without this quantisation, +# at the cost of tearing. # fps_limit = 60 # Older key, read only while fps_limit is unset: fps60 = 0 means a limit of 30. # fps60 = 1 From 6f3d553a2323be26fe93b4880fa9f800ad7780fd Mon Sep 17 00:00:00 2001 From: ExpertKT Date: Mon, 2 Nov 2026 19:43:17 +0800 Subject: [PATCH 02/10] Warn in totk.ini.example that memory = import is much slower on a discrete GPU --- totk.ini.example | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/totk.ini.example b/totk.ini.example index 227a923f..d21e7399 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -57,7 +57,10 @@ # astc = auto # Game memory shared with the GPU: auto (mirror on a discrete GPU, import on an integrated one), import (host memory # imported into Vulkan), mirror (pools used as buffers get a copy in video memory) or verify (mirror plus a check of -# every copy; slow). +# every copy; slow). On a discrete GPU import can be far slower than mirror, not slightly slower: the GPU reads the +# game's pools over PCIe. A 5070 Ti Laptop went from 6 ms to 135-230 ms of GPU time per frame with import (5 fps on the +# title screen, bound: gpu, every line of the perf window waiting on a fence). The log names the mode in use: "mem: +# mode import" or "mem: mode mirror". # memory = auto # A new texture created over a live texture's memory starts with that content instead of empty. # tex_alias = 1 From 4933725112731f4fffde635ede3ee6908d401f35 Mon Sep 17 00:00:00 2001 From: Takeya Saito Date: Mon, 2 Nov 2026 12:46:20 +0000 Subject: [PATCH 03/10] Keep world markers over their target at game resolutions of another shape than 16:9 The wide and tall UI overlays scale each layout's root pane on the stretched axis. The lock-on arrow, the name label of the item or character in front of Link, enemy life bars and notices, and speech balloons are moved in code to the target's projected position on a pane under that root, so the position was scaled as well: on 32:9 these markers sat at half their distance from the middle of the screen, short of what they point at. Those four layouts keep their root at scale 1 and give the scale to the panes under it that the code does not move and no animation scales, so the markers land on their target and keep their 16:9 proportions. Co-Authored-By: Claude Opus 5.5 --- tools/ultrawide_layout.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tools/ultrawide_layout.py b/tools/ultrawide_layout.py index 6c2fff1a..c67d212c 100644 --- a/tools/ultrawide_layout.py +++ b/tools/ultrawide_layout.py @@ -22,6 +22,19 @@ FIELD = {'x': 44, 'y': 48, 'scale_x': 68, 'scale_y': 72} KEEP_ROOT = {'AppMenuBG_00', 'PauseMenuBG_00', 'ShopMenuParasailBG_00', 'ShortCutBG_00', 'TitleMenuBG_00', 'EventFade_00', 'EventFadeWipe_00', 'CameraShutter_00', 'PaAppPictureBookDetail_00', 'AppMenuOverlay_00'} +# Layouts whose markers the game places over a point in the world (the lock-on arrow, the name of the item or character +# in front of Link, enemy life bars and notices, speech balloons): the code moves a pane under the root to the target's +# projected position in the 1920x1080 grid, which spans the whole canvas. Under a scaled root that position would be +# scaled too, so the marker lands short of its target, toward the middle of the screen (at half the distance on 32:9). +# Their root keeps scale 1 and the scale goes one level down instead, to the panes listed here: ones the code does not +# move and no animation scales, so the markers keep their 16:9 proportions. +MARKER_ROOT = { + 'AttentionBalloon_00': ('C_Capture_00', 'N_InOut_00'), # N_PosRoot_00 moves; N_InOut_00 animates y and alpha + 'AttentionLockOn_00': ('N_Offset_00',), # N_PosRoot_00 moves; N_Offset_00 animates y + 'EnemyInfo_00': ('Pa_EnemyLife_00', 'Pa_EnemyNotice_00'), # the parts move; N_EnemyLifeArea_* stay screen-sized + 'BalloonMessage_00': ('Pa_BalloonMessage_00',), +} + def edits(k, hud_corner): """(layout, pane, field, value) for the aspect: k = 16/9 over the aspect (the root's scale), w = how far a 1920-wide layout's edge moves out in its own units (960 * (1 / k - 1)). OFF moves a pane out of sight.""" @@ -222,8 +235,8 @@ def apply(blarc, members, width, height, hud_corner=True): assert k < 1, 'only for canvases of another shape than 16:9' root_scale = 'scale_x' if wide else 'scale_y' changed, layouts = set(), {} - unknown = sorted(n for n in KEEP_ROOT if f'blyt/{n}.bflyt' not in members) - if unknown: raise SystemExit(f'KEEP_ROOT names no layout: {unknown}') + unknown = sorted(n for n in KEEP_ROOT | MARKER_ROOT.keys() if f'blyt/{n}.bflyt' not in members) + if unknown: raise SystemExit(f'KEEP_ROOT or MARKER_ROOT names no layout: {unknown}') def pane_offset(layout, pane): member = f'blyt/{layout}.bflyt' if member not in members: raise SystemExit(f'{layout}: no layout {member} in the archive') @@ -232,6 +245,14 @@ def apply(blarc, members, width, height, hud_corner=True): return find_pane(layouts[member], layout, pane) for member in sorted(m for m in members if m.startswith('blyt/') and m.endswith('.bflyt')): if member[5:-6] in KEEP_ROOT: continue + if member[5:-6] in MARKER_ROOT: # the root stays at 1, its listed panes take the scale + layout = member[5:-6] + for pane in ('RootPane',) + MARKER_ROOT[layout]: + at = pane_offset(layout, pane) + FIELD[root_scale] + have = struct.unpack_from(' 1e-3: raise SystemExit(f'{layout} {pane} {root_scale}: {have}, expected 1.0') + if pane != 'RootPane': struct.pack_into(' 1e-3: raise SystemExit(f'{member[5:-6]} RootPane {root_scale}: {have}, expected 1.0') From ea72b01524a825bf3c40e42d57f433cceaf3b519 Mon Sep 17 00:00:00 2001 From: lowlevel-larry Date: Mon, 2 Nov 2026 09:47:35 -0300 Subject: [PATCH 04/10] Pace audio frames apart and raise the Linux prefill default Device-paced frames rendered back to back after each period pull (1024 samples on PipeWire, 4-5 frames), before the game's audio thread could clear the render event or fill the AUX return ring. Frames now stay at least 4/5 of a frame apart, as the DSP renders one frame every 5 ms on hardware. This fixes AUX clicks at frame seams (#426) and the progressive sound loss of #131 (overlapping render notifications 52.7% -> 0.1%). Linux prefill default raised to 60 ms: at 20 ms PipeWire underran thousands of times within minutes in busy scenes. The reverb ring (#421) and advance_voice stepping parts of this change landed in dev separately (d22a19c, b44caca). Fixes #131 Co-Authored-By: Claude Opus 5.5 --- runtime/audio_mixer.c | 15 +++++++++++---- runtime/audren.c | 13 ++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/runtime/audio_mixer.c b/runtime/audio_mixer.c index 4c212e9c..c82c7b79 100644 --- a/runtime/audio_mixer.c +++ b/runtime/audio_mixer.c @@ -8,7 +8,7 @@ // into its destination mix, folds the submixes, runs the mix effects and writes the device sink's stereo mix into a // single-producer single-consumer ring. The SDL audio thread drains that ring without taking any lock: an empty ring // plays silence and never blocks the render thread or the guest. TOTK_AUDIO=none (or TOTK_AUDIO_OFF) mixes without a -// device; TOTK_AUDIO_PREFILL_MS (0..500, default 20) is the queued audio the output waits for after start or underrun. +// device; TOTK_AUDIO_PREFILL_MS (0..500, default 20, 60 on Linux) is the queued audio the output waits for after start or underrun. // The device's clock paces the render thread, as the audio hardware paces the Switch's DSP (audio_mixer_pace_ns): a // frame is rendered when the ring holds less than the output target, max(prefill, two device periods), so the queue and // the delay from the game to the speakers stay there and the host and device clocks cannot drift apart. LASRecomp and @@ -90,8 +90,15 @@ static void report_once(Mixer *m, unsigned bit, const char *msg, int value) { // ---- output: SDL3 audio stream fed from the ring // How much audio the output waits for before it starts, and again after an underrun: TOTK_AUDIO_PREFILL_MS rounded up // to whole 5 ms render blocks. Returns -1 for a value outside 0..500 ms. +// The Linux default is higher: at 20 ms PipeWire's queue (max(prefill, two 1024-sample periods)) underran +// thousands of times within minutes in busy scenes, and 60 ms removed the underruns. +#ifdef __linux__ +#define PREFILL_DEFAULT_MS 60 +#else +#define PREFILL_DEFAULT_MS 20 +#endif static int prefill_blocks_for(const char *e) { - if (!e || !*e) return 4; + if (!e || !*e) return PREFILL_DEFAULT_MS / 5; char *end; double ms = strtod(e, &end); if (end == e || *end || !(ms >= 0) || ms > 500) return -1; @@ -318,8 +325,8 @@ void audio_mixer_open(AudioRenderer *r) { const char *pe = cfg_get("TOTK_AUDIO_PREFILL_MS"); m->prefill = prefill_blocks_for(pe); if (m->prefill < 0) { - rt_log("audio: TOTK_AUDIO_PREFILL_MS=%s is not 0..500 ms: using 20", pe); - m->prefill = 4; + rt_log("audio: TOTK_AUDIO_PREFILL_MS=%s is not 0..500 ms: using %d", pe, PREFILL_DEFAULT_MS); + m->prefill = PREFILL_DEFAULT_MS / 5; } r->mixer = m; atomic_store(&m->playing, r->state == 0); diff --git a/runtime/audren.c b/runtime/audren.c index 2b3ca42e..4d127161 100644 --- a/runtime/audren.c +++ b/runtime/audren.c @@ -352,7 +352,13 @@ static void render_thread(void *p) { plat_thread_priority(PLAT_PRIO_HIGHEST); const uint64_t frame_ns = (uint64_t)r->param.sample_count * 1000000000ull / (uint64_t)r->param.sample_rate; const double frame = (double)r->param.sample_count / r->param.sample_rate; - uint64_t next = kern_now_ns(); + // When the device pulls a period (1024 samples on PipeWire, 4-5 frames) the ring drops below its target + // and the frames would otherwise render back to back. On hardware the DSP renders one frame every 5 ms and + // the game's audio thread works in between; AUX effects need that time to fill the return ring, or mix_aux + // reads stale samples and the frame clicks at its seams. Device-paced frames stay at least 4/5 of a frame + // apart, which still refills a period well before the device drains it. + const uint64_t gap_ns = frame_ns * 4 / 5; + uint64_t next = kern_now_ns(), last = 0; while (plat_cas32(&r->running, 0, 0)) { uint64_t now = kern_now_ns(); int64_t pace = audio_mixer_pace_ns(r, now); @@ -360,6 +366,10 @@ static void render_thread(void *p) { plat_wait_ns((uint64_t)pace); continue; } + if (pace == 0 && last && now - last < gap_ns) { + plat_wait_ns(gap_ns - (now - last)); + continue; + } if (pace == 0) { next = now + frame_ns; // where the timer goes on if the device stops pacing } else { @@ -367,6 +377,7 @@ static void render_thread(void *p) { else if (now - next > 100000000ull) next = now; // fell far behind (debugger, sleep): resynchronise next += frame_ns; } + last = kern_now_ns(); plat_mutex_lock(&r->lock); if (r->state == 0) { voices_prepare(r); From 36752867474aa4850dbf31f8f3d79866901d12e7 Mon Sep 17 00:00:00 2001 From: lowlevel-larry <350257211+lowlevel-larry@users.noreply.github.com> Date: Mon, 2 Nov 2026 10:40:51 -0300 Subject: [PATCH 05/10] Keep a texture's pool flags instead of reading its pool object later tex_mirrored (vk_texture.c) read t->pool->flags whenever the back end created the host entry of a texture, which can happen long after nvnTextureInitialize. A game may finalize a memory pool and free the memory the NVNmemoryPool object lived in while textures from it are still looked up (on a level change, for instance); reading the freed object then faults. The NVN driver keeps no pointer to the pool either. tex_t now records the pool's flags at Initialize, in the padding after layout[8], so NVNtexture's size is unchanged. Co-Authored-By: Claude Opus 5.5 --- runtime/nvn_api_obj.c | 1 + runtime/nvn_obj.h | 3 +++ runtime/vk_exec_probe.c | 2 +- runtime/vk_texture.c | 3 +-- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/runtime/nvn_api_obj.c b/runtime/nvn_api_obj.c index 6d3c3fcf..ffe0648a 100644 --- a/runtime/nvn_api_obj.c +++ b/runtime/nvn_api_obj.c @@ -197,6 +197,7 @@ NVN_API(nvnTextureInitialize) { o->magic = NVN_TEX_MAGIC; o->d = s->d; o->pool = s->pool; + o->pool_flags = s->pool ? (uint16_t)s->pool->flags : 0; o->off = s->off; o->has_layout = s->has_layout; memcpy(o->layout, s->layout, 8); diff --git a/runtime/nvn_obj.h b/runtime/nvn_obj.h index 662ba149..7b81c6ec 100644 --- a/runtime/nvn_obj.h +++ b/runtime/nvn_obj.h @@ -48,6 +48,9 @@ typedef struct { } tex_builder_t; FITS(tex_builder_t, NVNtextureBuilder); typedef struct { uint32_t magic; nvn_texdesc d; uint8_t has_layout, layout[8]; + uint16_t pool_flags; // the pool's flags at Initialize (in the padding): a game may finalize and free + // the pool object while the back end still looks the texture up, and the + // driver keeps no pointer to it either nvn_texlayout L; uint8_t *mem; pool_t *pool; int64_t off; uint64_t serial; // Initialization serial: the back end uses it to find its texture in the host table (the game may copy the object by value, so object pointers cannot be stored) } tex_t; FITS(tex_t, NVNtexture); diff --git a/runtime/vk_exec_probe.c b/runtime/vk_exec_probe.c index 3663e556..f3011c43 100644 --- a/runtime/vk_exec_probe.c +++ b/runtime/vk_exec_probe.c @@ -175,7 +175,7 @@ static void init_tex(tex_t *t, pool_t *pool, int64_t off, int format) { t->d.target = NVN_TEXTURE_TARGET_2D, t->d.format = format, t->d.width = TEX_W, t->d.height = TEX_H; t->d.depth = 1, t->d.levels = 1; nvn_tex_layout(&t->d, &t->L); - t->pool = pool, t->off = off, t->mem = pool->mem + off, t->serial = 100 + (uint64_t)off; + t->pool = pool, t->pool_flags = (uint16_t)pool->flags, t->off = off, t->mem = pool->mem + off, t->serial = 100 + (uint64_t)off; } // Pixel of the RGBA8 target after the stream: the scissored second clear inside the rectangle, the first elsewhere. diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index 2a57ca68..995c613d 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -166,8 +166,7 @@ static int same_but_swizzle(const TexKey *a, const TexKey *b) { static int tex_mirrored(const tex_t *t) { if (!t->mem || nvn_gpu_only((uintptr_t)t->mem)) return 0; if (t->has_layout) return 1; - const pool_t *p = t->pool; - if (!p || !(p->flags & (NVN_MEMORY_POOL_FLAGS_CPU_UNCACHED | NVN_MEMORY_POOL_FLAGS_CPU_CACHED))) return 0; + if (!(t->pool_flags & (NVN_MEMORY_POOL_FLAGS_CPU_UNCACHED | NVN_MEMORY_POOL_FLAGS_CPU_CACHED))) return 0; if (t->d.flags & (NVN_TEXTURE_FLAGS_DISPLAY | NVN_TEXTURE_FLAGS_COMPRESSIBLE | NVN_TEXTURE_FLAGS_ADAPTIVE_ZCULL | NVN_TEXTURE_FLAGS_DEPTH16_PREFER_FAST_CLEAR | NVN_TEXTURE_FLAGS_ZCULL_SUPPORT_STENCIL)) return 0; From 5bd11f5d5c766670861d5c4feeba3e40ba498d15 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Mon, 2 Nov 2026 17:03:55 +0300 Subject: [PATCH 06/10] Keep the 4/5-frame gap between device-paced audio frames to Linux Co-Authored-By: Claude Opus 5.5 --- runtime/audren.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/audren.c b/runtime/audren.c index 4d127161..5ede6072 100644 --- a/runtime/audren.c +++ b/runtime/audren.c @@ -356,8 +356,14 @@ static void render_thread(void *p) { // and the frames would otherwise render back to back. On hardware the DSP renders one frame every 5 ms and // the game's audio thread works in between; AUX effects need that time to fill the return ring, or mix_aux // reads stale samples and the frame clicks at its seams. Device-paced frames stay at least 4/5 of a frame - // apart, which still refills a period well before the device drains it. + // apart, which still refills a period well before the device drains it. Linux only: on Windows SDL pulls + // 480-sample periods, and a sink dump (TOTK_AUDIO_DUMP) of the bursts there showed no more seam spikes than + // chance, so a wait on this thread buys nothing. +#ifdef __linux__ const uint64_t gap_ns = frame_ns * 4 / 5; +#else + const uint64_t gap_ns = 0; +#endif uint64_t next = kern_now_ns(), last = 0; while (plat_cas32(&r->running, 0, 0)) { uint64_t now = kern_now_ns(); From 55ba4d312d43a00c6dedb970e2cedf4040d566e2 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Mon, 2 Nov 2026 17:03:56 +0300 Subject: [PATCH 07/10] Say in totk.ini.example that variable refresh removes the frame limit's judder Co-Authored-By: Claude Opus 5.5 --- totk.ini.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/totk.ini.example b/totk.ini.example index 6193c9e0..387169b2 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -12,7 +12,8 @@ # 320 Hz monitor 80, 64, 40 and 32 divide it and 90 does not: 90 fps alternates 3 and 4 refreshes per frame, which reads # as judder while the frame counter still shows 90. Likewise on 240 Hz 60, 48 and 40 divide it and on 144 Hz 72, 48 and # 36 do, while 60 does not. vk_present = immediate shows a frame as soon as it is presented, without this quantisation, -# at the cost of tearing. +# at the cost of tearing. A monitor running with variable refresh (FreeSync, G-Sync) follows the frames instead, so +# there any limit inside its range is even. # fps_limit = 60 # Older key, read only while fps_limit is unset: fps60 = 0 means a limit of 30. # fps60 = 1 From 438aa417474b5a4bb270d9ba228ebe4794f90f7a Mon Sep 17 00:00:00 2001 From: itaskaev2 <165683571+itaskaev2@users.noreply.github.com> Date: Mon, 2 Nov 2026 13:10:05 +0100 Subject: [PATCH 08/10] Keep the scene at render_scale when DLSS cannot run A DLSS mode (quality, balanced, performance) shrank the scene to 67, 58 or 50 % of the output and sharpened the material textures' mip bias to match, even when nvngx_dlss.dll was missing and NGX reported DLSS as not available. The game's plain scaling then stretched the smaller scene, and the negative bias made textures shimmer in motion. With dlaa = 1 the scene size now waits on nvngx_dlss.dll next to totk.exe (checked before the device exists, as the size is decided then) and follows render_scale without it. The mip bias applies only when NGX came up with DLSS. dlaa = 0 keeps the documented size with the game's scaling, without the bias. Co-Authored-By: Claude Opus 5.5 --- runtime/resolution.c | 22 ++++++++++++++++++++++ runtime/vk_dlaa.c | 3 +++ runtime/vk_dlaa.h | 2 ++ runtime/vk_texture.c | 6 ++++-- totk.ini.example | 3 ++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/runtime/resolution.c b/runtime/resolution.c index d1941300..894ee0b6 100644 --- a/runtime/resolution.c +++ b/runtime/resolution.c @@ -36,6 +36,7 @@ #include "cfg.h" #include "host.h" +#include "platform/platform.h" #define BASE_W 1920 #define BASE_H 1080 @@ -55,6 +56,23 @@ static struct { double dlss_k; // TOTK_DLSS quality/balanced/performance: the scene's share of the output, else 0 } R; +// The scene size is decided before the device exists, so NGX cannot be asked yet. With dlaa on, NGX loads DLSS from +// nvngx_dlss.dll next to totk.exe (vk_dlaa.c vk_dlaa_init): without that file DLSS never runs, and a DLSS mode would +// leave the game's plain scaling at 50..67 % of the output. dlaa = 0 keeps the documented size with the game's scaling. +static int dlss_dll(void) { +#ifdef _WIN32 + if (!cfg_bool("TOTK_DLAA")) return 1; + char exe[1024], path[1024 + 32]; + if (!plat_exe_path(exe, sizeof exe)) return 1; + char *last = plat_last_sep(exe); + if (!last) return 1; + snprintf(path, sizeof path, "%.*s/nvngx_dlss.dll", (int)(last - exe), exe); + return plat_file_exists(path); +#else + return 1; +#endif +} + static void decide(void) { if (R.decided) return; R.decided = 1; @@ -78,6 +96,10 @@ static void decide(void) { {"quality", 2.0 / 3.0}, {"balanced", 0.58}, {"performance", 0.5}}; for (int i = 0; cfg_bool("TOTK_DLAA") && i < 3; i++) if (!strcmp(m, dlss[i].name)) R.dlss_k = dlss[i].k; + if (R.dlss_k && !dlss_dll()) { + rt_log("resolution: DLSS %s needs nvngx_dlss.dll next to totk.exe, which is missing: the scene follows render_scale", m); + R.dlss_k = 0; + } if (R.dlss_k) { k = R.dlss_k; R.scene_set = 1; diff --git a/runtime/vk_dlaa.c b/runtime/vk_dlaa.c index af926221..7acdd130 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -202,6 +202,8 @@ void vk_dlaa_init(void) { driver ? "; the driver needs an update" : ""); } +int vk_dlaa_available(void) { return vk_dlaa_wanted() && N.available; } + // ---------------------------------------------------------------- where DLAA runs in TotK's frame // Measured (TOTK_DUMP, frame 2100 at Lookout Landing, 2560x1440 scene): the G-buffer passes draw into five targets with // the scene depth (d32f at the scene size), one of them the R11G11B10F light target; lighting and the transparents @@ -680,6 +682,7 @@ void vk_dlaa_device_exts(const VkExtensionProperties *have, uint32_t nhave, cons (void)have, (void)nhave, (void)ext, (void)n, (void)max; } void vk_dlaa_init(void) {} +int vk_dlaa_available(void) { return 0; } void vk_dlaa_pass(VkExec *ex) { (void)ex; } void vk_dlaa_frame(void) {} void vk_dlaa_draw(VkExec *ex) { (void)ex; } diff --git a/runtime/vk_dlaa.h b/runtime/vk_dlaa.h index dc291b10..685a2524 100644 --- a/runtime/vk_dlaa.h +++ b/runtime/vk_dlaa.h @@ -8,6 +8,8 @@ int vk_dlaa_wanted(void); // the setting is on (the device may still lack DLSS void vk_dlaa_instance_exts(const char **ext, uint32_t *n, uint32_t max); void vk_dlaa_device_exts(const VkExtensionProperties *have, uint32_t nhave, const char **ext, uint32_t *n, uint32_t max); void vk_dlaa_init(void); +// 1 when dlaa is on and NGX came up with DLSS (after vk_dlaa_init): a DLSS mode's smaller scene is scaled up by DLSS. +int vk_dlaa_available(void); // vk_exec.c vk_exec_pass_begin, once the pass's targets are resolved and before its barrier: arms the frame on the // scene's light target or, at the first quarter-width pass after it, runs DLAA on that target. Each present ends the // frame (vk_dlaa_frame). diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index 995c613d..46abe06f 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -26,6 +26,7 @@ #include "nvn_tex.h" #include "tex.h" #include "vk.h" +#include "vk_dlaa.h" #include "vk_exec.h" #include "platform/platform.h" @@ -1680,8 +1681,9 @@ static VkSampler make_sampler(VkCtx *c, const samp_par *d) { if (si.maxLod < si.minLod) si.maxLod = si.minLod; float lim = c->props.limits.maxSamplerLodBias, bias = d->lod_bias; // DLSS upscaling (resolution.c): the scene's material textures, the filtered mipmapped ones that repeat, are - // sampled for the output's resolution; clamped ones (post effects, LUTs, the UI) keep the game's bias. - if (!d->cmp_mode && mf == NVN_MIN_FILTER_LINEAR_MIPMAP_LINEAR && + // sampled for the output's resolution; clamped ones (post effects, LUTs, the UI) keep the game's bias. Without DLSS + // running (dlaa = 0, or NGX without DLSS) nothing accumulates the extra detail, and the sharper mips only shimmer. + if (vk_dlaa_available() && !d->cmp_mode && mf == NVN_MIN_FILTER_LINEAR_MIPMAP_LINEAR && (si.addressModeU == VK_SAMPLER_ADDRESS_MODE_REPEAT || si.addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT || si.addressModeV == VK_SAMPLER_ADDRESS_MODE_REPEAT || si.addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT)) bias += res_dlss_lod_bias(); diff --git a/totk.ini.example b/totk.ini.example index 387169b2..8edc4535 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -196,7 +196,8 @@ # dlaa = 0 # What DLSS works from: dlaa (the 3D scene at full size), quality, balanced or performance (the scene at 67, 58 or # 50 % of the output, scaled up by DLSS; these replace render_scale and sharpen texture filtering to match). With dlaa -# = 0 the game's own scaling is used at that size. Read at start. +# = 0 the game's own scaling is used at that size, without the sharper filtering. With dlaa = 1 but no nvngx_dlss.dll +# next to totk.exe the scene follows render_scale. Read at start. # dlss = dlaa # The game's own FXAA after the post effects; with DLAA on it is not needed. Changes while the game runs take effect at # once. From 92639896251a2a6b31810f81da50e09af4b166c3 Mon Sep 17 00:00:00 2001 From: itaskaev2 <165683571+itaskaev2@users.noreply.github.com> Date: Mon, 2 Nov 2026 13:40:32 +0100 Subject: [PATCH 09/10] Skip the game's scaling draw over DLSS's picture again With a DLSS mode (a scene smaller than the output) DLSS writes the scaled picture into the scaling pass's target and vk_dlaa_skip_draw skips the game's own scaling draw, known by its fragment shader's SPIR-V hash. Translator patch 0011 (the shadow filter spread) changed that hash, so the draw ran again and covered DLSS's picture with the scaled jittered scene: the whole picture shook by a fraction of a pixel each frame, most visible on lit flat surfaces in shrines. The FXAA switch (fxaa = 0) stopped working for the same reason. Add the hash of the current translator, and log once when DLSS scaled a frame whose scaling draw was not found, so the next translator change that moves the hash shows in the log. Measured on 1.4.3, Ukouh Shrine, output 3200x1800, dlss = quality, mean absolute change between consecutive frames with a still camera: 1.40 before, 0.07 after (0.054 with dlaa = 0). Outdoors on stone: 4.29 before, 1.08 after. Co-Authored-By: Claude Opus 5.5 --- runtime/vk_dlaa.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/runtime/vk_dlaa.c b/runtime/vk_dlaa.c index 7acdd130..886d2a23 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -256,6 +256,8 @@ static struct { uint64_t mv_frames, mv_none; uint64_t why[3]; // history resets: scene size changed, no camera, scene target changed int on; // the dlaa setting, read at each present (the menu switches it live) + int scaler_skipped; // this frame: the game's scaling draw over DLSS's picture was skipped + uint64_t scaler_missed; // frames DLSS scaled whose scaling draw was not found (vk_dlaa_skip_draw) } D = {.mv_ok = -1}; static int dl_active(void) { return N.available && !D.failed && D.on; } @@ -626,7 +628,10 @@ void vk_dlaa_frame(void) { if (D.jit_used && !D.done) D.hold = 60, D.holds++; // jittered but not resolved: that frame shook else if (D.hold) D.hold--; if (!D.done) D.jit_ok = 0; - D.armed = D.done = D.jit_used = D.gbuf = D.ended = D.up = 0; + if (D.up && !D.scaler_skipped && ++D.scaler_missed == 1) + rt_log("dlaa: the game's scaling draw over DLSS's picture was not found (its fragment shader is not in FXAA_FS): " + "the jittered scene reaches the screen and shakes"); + D.armed = D.done = D.jit_used = D.gbuf = D.ended = D.up = D.scaler_skipped = 0; D.cam_addr = 0; } @@ -640,8 +645,10 @@ void vk_dlaa_frame(void) { // scaled picture into the output-sized target, in a pass without the depth attachment the in-place FXAA has: there it // is always drawn, whatever fxaa says (skipping it would leave the 3D picture out), unless DLSS already wrote that // target this frame. -// The stock translator's hash, and the one with tools/xlate patch 0010 (PCSS, PR #89) applied. -static const uint64_t FXAA_FS[] = {0xf450003ebeb3dc52ull, 0x0a12f4bc2a9a4fbeull}; +// The stock translator's hash, the one with tools/xlate patch 0010 (PCSS, PR #89) applied, and the one with patches +// 0010 and 0011 (the shadow filter spread) applied. A translator change that gives the shader another hash is reported +// by vk_dlaa_frame: the game's scaling draw then covers DLSS's picture with the jittered scene, which shakes. +static const uint64_t FXAA_FS[] = {0xf450003ebeb3dc52ull, 0x0a12f4bc2a9a4fbeull, 0x5c43ae18948d52cbull}; static uint64_t spirv_hash(const GfxShader *s) { static struct { const GfxShader *s; uint64_t h; } tab[8192]; @@ -667,8 +674,10 @@ int vk_dlaa_skip_draw(VkExec *ex, const GfxShader *fs) { if (fxaa && !D.up) return 0; // nothing to skip: no shader lookup per draw at the defaults if (!fs) return 0; uint64_t h = spirv_hash(fs); - if (h != FXAA_FS[0] && h != FXAA_FS[1]) return 0; - if (!ex->depth.image) return D.up; // the scaling pass + int known = 0; + for (size_t i = 0; i < sizeof FXAA_FS / sizeof FXAA_FS[0]; i++) known |= h == FXAA_FS[i]; + if (!known) return 0; + if (!ex->depth.image) return D.scaler_skipped = D.up; // the scaling pass return !fxaa; } From 3ee347b2489f6b80abbd4648a54c688437c4ba0b Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Mon, 2 Nov 2026 17:11:14 +0300 Subject: [PATCH 10/10] Size the scene by a DLSS mode only where DLSS can run, and log whether fxaa = 0 found the game's FXAA The DLSS modes already apply only with dlaa on (3de0839), so the DLL check no longer looks at dlaa, and off Windows, where vk_dlaa.c is no-op stubs, a DLSS mode no longer shrinks the scene. fxaa = 0 names the FXAA shader it skipped, or reports a minute of frames without it, so a translator change that moves FXAA_FS shows on any GPU. Co-Authored-By: Claude Opus 5.5 --- runtime/resolution.c | 13 ++++++++----- runtime/vk_dlaa.c | 17 ++++++++++++++++- totk.ini.example | 6 +++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/runtime/resolution.c b/runtime/resolution.c index 894ee0b6..cd93a74c 100644 --- a/runtime/resolution.c +++ b/runtime/resolution.c @@ -56,12 +56,11 @@ static struct { double dlss_k; // TOTK_DLSS quality/balanced/performance: the scene's share of the output, else 0 } R; -// The scene size is decided before the device exists, so NGX cannot be asked yet. With dlaa on, NGX loads DLSS from -// nvngx_dlss.dll next to totk.exe (vk_dlaa.c vk_dlaa_init): without that file DLSS never runs, and a DLSS mode would -// leave the game's plain scaling at 50..67 % of the output. dlaa = 0 keeps the documented size with the game's scaling. +// The scene size is decided before the device exists, so NGX cannot be asked yet. NGX loads DLSS from nvngx_dlss.dll +// next to totk.exe (vk_dlaa.c vk_dlaa_init): without that file DLSS never runs, and a DLSS mode would leave the game's +// plain scaling at 50..67 % of the output. Off Windows vk_dlaa.c is built as no-op stubs, so there is no DLSS at all. static int dlss_dll(void) { #ifdef _WIN32 - if (!cfg_bool("TOTK_DLAA")) return 1; char exe[1024], path[1024 + 32]; if (!plat_exe_path(exe, sizeof exe)) return 1; char *last = plat_last_sep(exe); @@ -69,7 +68,7 @@ static int dlss_dll(void) { snprintf(path, sizeof path, "%.*s/nvngx_dlss.dll", (int)(last - exe), exe); return plat_file_exists(path); #else - return 1; + return 0; #endif } @@ -97,7 +96,11 @@ static void decide(void) { for (int i = 0; cfg_bool("TOTK_DLAA") && i < 3; i++) if (!strcmp(m, dlss[i].name)) R.dlss_k = dlss[i].k; if (R.dlss_k && !dlss_dll()) { +#ifdef _WIN32 rt_log("resolution: DLSS %s needs nvngx_dlss.dll next to totk.exe, which is missing: the scene follows render_scale", m); +#else + rt_log("resolution: DLSS %s runs on Windows only: the scene follows render_scale", m); +#endif R.dlss_k = 0; } if (R.dlss_k) { diff --git a/runtime/vk_dlaa.c b/runtime/vk_dlaa.c index 886d2a23..4872dd32 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -669,8 +669,19 @@ static uint64_t spirv_hash(const GfxShader *s) { int vk_dlaa_skip_draw(VkExec *ex, const GfxShader *fs) { static uint64_t frame_read = ~0ull; static int fxaa = 1; + // fxaa = 0 reports once whether it found the game's FXAA draw: the first skip, or a minute of frames (3600) with + // none, which is what a translator change that moves FXAA_FS looks like on every GPU, with or without DLSS + static uint64_t fx_off_frames; + static int fx_found, fx_reported; uint64_t f = __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED); - if (f != frame_read) frame_read = f, fxaa = cfg_bool("TOTK_FXAA"); // once a frame: the menu switches it live + if (f != frame_read) { // once a frame: the menu switches it live + frame_read = f, fxaa = cfg_bool("TOTK_FXAA"); + if (!fxaa && !fx_found && !fx_reported && ++fx_off_frames == 3600) { + fx_reported = 1; + rt_log("dlaa: fxaa = 0 found no draw of the game's FXAA in %llu frames (its fragment shader is not in " + "FXAA_FS): the FXAA stays on", (unsigned long long)fx_off_frames); + } + } if (fxaa && !D.up) return 0; // nothing to skip: no shader lookup per draw at the defaults if (!fs) return 0; uint64_t h = spirv_hash(fs); @@ -678,6 +689,10 @@ int vk_dlaa_skip_draw(VkExec *ex, const GfxShader *fs) { for (size_t i = 0; i < sizeof FXAA_FS / sizeof FXAA_FS[0]; i++) known |= h == FXAA_FS[i]; if (!known) return 0; if (!ex->depth.image) return D.scaler_skipped = D.up; // the scaling pass + if (!fxaa && !fx_found) { + fx_found = 1; + rt_log("dlaa: fxaa = 0 skips the game's FXAA (fragment shader %016llx)", (unsigned long long)h); + } return !fxaa; } diff --git a/totk.ini.example b/totk.ini.example index 8edc4535..e22dbbee 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -195,9 +195,9 @@ # totk.exe; elsewhere the setting does nothing. The HUD is drawn after it and is not touched. Read at start. # dlaa = 0 # What DLSS works from: dlaa (the 3D scene at full size), quality, balanced or performance (the scene at 67, 58 or -# 50 % of the output, scaled up by DLSS; these replace render_scale and sharpen texture filtering to match). With dlaa -# = 0 the game's own scaling is used at that size, without the sharper filtering. With dlaa = 1 but no nvngx_dlss.dll -# next to totk.exe the scene follows render_scale. Read at start. +# 50 % of the output, scaled up by DLSS; these replace render_scale and sharpen texture filtering to match). They apply +# only with dlaa = 1 and nvngx_dlss.dll next to totk.exe, on Windows; otherwise the scene follows render_scale. Read at +# start. # dlss = dlaa # The game's own FXAA after the post effects; with DLAA on it is not needed. Changes while the game runs take effect at # once.