From 6e87c921a1c96186ce6e61382a27e8d600fb5909 Mon Sep 17 00:00:00 2001 From: bct8925 <31393107+bct8925@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:22:50 -0500 Subject: [PATCH] Start a new DLSS history on a camera cut, and give frame generation the same new start. vk_dlaa_fg_inputs handed frame generation a reset of 0 every frame, so it was never told of a new history: across an area load, another scene size or another target it generated frames between two unrelated pictures. It now gets the reset DLSS ran with on the same frame. DLSS itself started a new history only for a lost camera, another scene size or another target, not when the camera jumped. cam_cut takes a move over 5 m, or a turn over 10 degrees together with a move over 0.5 m, per 60 Hz frame (scaled by the time since the last camera) for a cut, from camera traces of play in the Fire Temple: a median of 0.05 m and 0.08 degrees a frame, area loads of 5 to 180 m in one frame. NX2NAVI_DLAA_CUT=0 turns it off, and each cut is logged, up to 24. Co-Authored-By: Claude Opus 5.5 --- runtime/cfg.c | 2 +- runtime/vk_dlaa.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/runtime/cfg.c b/runtime/cfg.c index ca39163a..8559993b 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -44,7 +44,7 @@ static const char *const known[] = { "BIND_SKIP", "BIND_STATS", "BIND_UP", "BIND_X", "BIND_Y", "BIND_ZL", "BIND_ZR", "BLOCK_VIEWS_3D", "CACHE_DIE", "CLOTH_REALTIME", "COLOR_BRIGHTNESS", "COMPUTE_KEEP", "COLOR_CONTRAST", "COLOR_GAMMA", "COLOR_PRESET", "COLOR_SATURATION", "CONTACT_DEBUG", "CONTACT_SHADOWS", "CORE_DIAG", "CRIT", "CRIT_OUT", - "DESC_TEMPLATE", "DEVICE_PROFILE", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_CAM_KEEP", "DLSS_IDLE_FREE", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TARGET_KEEP", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR", + "DESC_TEMPLATE", "DEVICE_PROFILE", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_CAM_KEEP", "DLAA_CUT", "DLSS_IDLE_FREE", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TARGET_KEEP", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG", "DUMP_RAW", "DUMP_SHADERS", "DUMP_FILE", "DS3", "LOG_CS_BINDS", "LOG_TEX_FLAGS", "LOG_MESH", "MESH", "POOL", "NATIVE_TENSOR", "LOG_RCOND", "LOG_RT_SIZES", "DUMP_WHITE", "DUMP_AFTER", "DUMP_MOVIE", "SUBMIT_FINISH", "ACQUIRE_WAIT", "CRASH_FILTER_GUARD", "CS_FALLBACK", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", "GPU_TIMELINE", "FFX_PIPE_CACHE", "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLIGHT_EVERY", "FLUSH_SPAN", "FLUSH_UPLOAD", "FOG_CULL", "FOLIAGE_SHADOW_CULL", "FOLIAGE_SHADOW_VRS", "FOV", "FOV_PATCH", "FG_HUDLESS_SHOW", "FG_MULT", "FPS60", "FPS_LIMIT", "FRAMEGEN", "FRAMEGEN_MULTIPLIER", "FREEZE_IDLE", "FREEZE_ASYNC", "FREEZE_BUDGET_US", "FREE_CORES", "FULLSCREEN", "FXAA", "GAME_ASPECT", "GAME_RES", "GPA", "GPA_EMPTY", "GPA_TWIN", "GPA_TWIN_MAX_KB", "MIRROR_CAPTURE_KB", "WB_SKIP_MB", "GPL", "GPL_DRAW_BUILD", "GPL_FEEDBACK", "PIPE_AHEAD", "PIPE_FAST_WORKERS", "PIPE_FRAME_WAIT_MS", "PIPE_LINK_DRAW_MS", "PIPE_SKIP_STEADY", "PROG_LEAD", "GPU", "GPU_INDEX", "GPU_PASSES", "GPU_NAME", "HDR", diff --git a/runtime/vk_dlaa.c b/runtime/vk_dlaa.c index 489ece3d..28b2d279 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -528,6 +528,9 @@ static struct { uint64_t cam_none_draw, cam_none_snap; // no scene-context draw this frame / one, not in the evaluating submission's copy uint64_t cam_at_draw; // camera taken from the bytes the draw read, where the evaluating submission lacks them uint64_t cam_kept, cam_kept_max; // no camera, history kept with zero motion / runs cut short at KEEP_MAX + float cut_pos[3], cut_fwd[3]; // last frame's camera position and direction (cam_cut) + uint64_t cut_ns, cuts; // when it was read; camera cuts that started a new history + int cut_ok, cut_logged; int keep_run; // frames in a row kept without a camera uint64_t gap_logged, miss_logged, target_logged, second_logged; uint64_t seq_present; // vk_exec_submit_seq at the last present (vk_dlaa_frame) @@ -616,7 +619,10 @@ int vk_dlaa_fg_inputs(VkFfxImage *depth, VkFfxImage *mv, float *jx, float *jy, i if (!D.fg_fresh || D.failed) return 0; D.fg_fresh = 0; if (!fg_current(D.fg_at)) return 0; - *depth = D.fg_depth, *mv = D.fg_mv, *jx = D.fg_jx, *jy = D.fg_jy, *reset = 0; + // reset: DLSS started a new history on this frame (evaluate). Handed out as 0 before, so frame generation was never + // told of a camera cut, another scene size or another target, and interpolated across them: an area load + // generated frames between two unrelated pictures. + *depth = D.fg_depth, *mv = D.fg_mv, *jx = D.fg_jx, *jy = D.fg_jy, *reset = D.fg_reset; return 1; } @@ -1059,6 +1065,45 @@ static void cam_note(int view, int kept) { : "new history"); } +// Camera cuts (NX2NAVI_DLAA_CUT, default 1; 0: off). Only a lost camera (mv_pass), another scene size or another +// target started a new history, so DLSS and frame generation (vk_dlaa_fg_inputs) carried their history across a camera +// that jumped: an area load or a spawn moves it 5 to 180 m in one frame. Such a frame now starts a new history, as +// NVIDIA's DLSS guide asks for a camera cut: a move over 5 m, or a turn over 10 degrees together with a move over 0.5 m, +// both per 60 Hz frame and scaled by the time since the last camera. Camera traces of play in the Fire Temple +// (NX2NAVI_MOUSE_TRACE) had a median of 0.05 m and 0.08 degrees a frame; the second test took only the area loads and a +// swing of the camera through a doorway at 12 to 18 degrees and 0.7 to 1.4 m a frame. A turn alone (the mouse camera, +// which orbits about 3 m from Link) does not count. Each cut is logged, up to 24. +// v: the Ocarina scene context's rows 0-2, the view (fg_camera). +static void cam_cut(const float *v) { + static int on = -1; + if (on < 0) on = rt_knob("DLAA_CUT", "1"); + float pos[3], fwd[3]; + for (int i = 0; i < 3; i++) { + fwd[i] = -v[8 + i]; + pos[i] = -(v[i] * v[3] + v[4 + i] * v[7] + v[8 + i] * v[11]); + } + uint64_t now = plat_now_ns(); + if (on && D.cut_ok) { + double dot = fwd[0] * D.cut_fwd[0] + fwd[1] * D.cut_fwd[1] + fwd[2] * D.cut_fwd[2]; + double turn = acos(dot > 1 ? 1 : dot < -1 ? -1 : dot) * (180.0 / 3.14159265358979); + double dx = pos[0] - D.cut_pos[0], dy = pos[1] - D.cut_pos[1], dz = pos[2] - D.cut_pos[2]; + double move = sqrt(dx * dx + dy * dy + dz * dz); + double k = (now - D.cut_ns) / 1e6 / (1000.0 / 60); // 60 Hz frames since the last camera + if (k < 0.25) k = 0.25; + if (k > 4) k = 4; + if (move > 5.0 * k || (turn > 10.0 * k && move > 0.5 * k)) { + D.reset = 1, D.cuts++; + if (D.cut_logged < 24) + D.cut_logged++, rt_log("dlaa: frame %llu: camera cut (moved %.2f m, turned %.1f degrees in %.1f ms): new " + "history (%llu so far)", + (unsigned long long)__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED) + 1, + move, turn, (now - D.cut_ns) / 1e6, (unsigned long long)D.cuts); + } + } + memcpy(D.cut_pos, pos, sizeof pos), memcpy(D.cut_fwd, fwd, sizeof fwd); + D.cut_ns = now, D.cut_ok = 1; +} + // The pass, recorded through the recorder like the replay's own commands. 0: no camera this frame (the vectors stay // zero and DLSS starts a new history); 2: no camera, but the history is kept (the vectors stay zero, dlaa_cam_keep). // bias > 0 with this frame's G-buffer classes (D.ids) also writes e->mask, the bias mask (dlaa_mv.comp); *masked says @@ -1126,6 +1171,7 @@ static int mv_pass(VkExec *ex, struct Size *e, VkImageView zv, float jx, float j } D.fg_cam_ok = 0; if (cr && have_m && D.cam_size == OCAM_BLOCK) fg_camera(cr, m); + if (cr && D.cam_size == OCAM_BLOCK) cam_cut(cr); int s = D.cam_slot, had_prev = D.cam_prev_ok; if (D.cam_size == CAM_BLOCK) { // the whole block, for the per-object motion pass (the deferred engine's only) VkBufferCopy bc = {cam.offset, (VkDeviceSize)s * CAM_SLOT, CAM_BLOCK}; @@ -1909,6 +1955,9 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) { if (!NGX_OK(r)) return dl_fail("DLSS evaluation", r); evaluated: if (timed) times_mark(cb, T_DL1); // through the recorder, after NGX's own commands + // Frame generation gets the same new start with this frame's inputs (vk_dlaa_fg_inputs): a frame DLSS starts a + // new history on (a camera cut, another scene size or target) has no motion from the frame before that holds. + D.fg_reset = D.reset; D.reset = 0; D.last = e, e->used = D.evals + 1; if (D.evals % 600 == 0) query_vram();