From 5aa3bc411918443326ba9a08151b8ab3d782c36f Mon Sep 17 00:00:00 2001 From: chrg6 Date: Sun, 8 Nov 2026 02:25:15 -0500 Subject: [PATCH] Render widescreen pictures at the DLSS mode's real share, and size frame generation for the scene it is given. The game sizes its scene from the scale at the patch page against its own 1440-line picture, so on a 2160-line picture native DLAA rendered a 1440-line scene and Quality 44 %. The page now gets the share times the picture's height over 1440, and DLAA is native at any picture size. Switching dlaa off in the menu also gives the scene back the game's own scale instead of leaving it small with nothing to enlarge it. FSR 3.1 frame generation was created with the window as its largest render size, but it is given the scene's depth and motion vectors, up to the picture's size. A 3414x1440 or 5120x2160 scene in a 1920x1080 window wrote past its resources: a crash in amd_fidelityfx_vk.dll, device faults, striped frames. The context is now made for the picture's size once. Co-Authored-By: Claude Opus 5.5 --- runtime/host.h | 1 + runtime/vk_fg.cpp | 31 ++++++++++++++++++++++++------- runtime/widescreen.c | 24 +++++++++++++++++++++--- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/runtime/host.h b/runtime/host.h index 869a93c9..d30f7a8f 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -270,6 +270,7 @@ void res_heapdef_served(void); // romfs.c serves the void wide_init(void); void wide_present(void); // each present: DLSS's render scale (res_fixed) // after rt_patches_init: widescreen.c, NX2NAVI_GAME_ASPECT int wide_available(void); // the generated C has the widescreen sets +void wide_picture(unsigned *w, unsigned *h); // the picture the game draws (its scene is never larger) uint64_t wide_heap_extra_kib(void); // the texture heap's growth for the widescreen picture void res_init(void); // after rt_patches_init: the patch page and the sets float res_dlss_lod_bias(void); // NX2NAVI_DLSS upscaling: texture LOD bias (<= 0) diff --git a/runtime/vk_fg.cpp b/runtime/vk_fg.cpp index 849c4d37..f9fd71ca 100644 --- a/runtime/vk_fg.cpp +++ b/runtime/vk_fg.cpp @@ -38,6 +38,7 @@ struct { ffxContext sc = nullptr; // the swapchain context ffxContext fg = nullptr; // the frame generation context VkExtent2D fg_ext = {0, 0}; + VkExtent2D fg_max = {0, 0}; // the context's largest render size VkFormat fg_fmt = VK_FORMAT_UNDEFINED; ffxQueryDescSwapchainReplacementFunctionsVK fn = {}; uint64_t frame = 0; @@ -165,6 +166,18 @@ extern "C" void vk_fg_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt, if (!vk_fg_active()) return; vk_dlaa_hudless_wanted = 1; // the upscaling pass keeps a copy of the picture before the HUD (vk_dlaa.c hudless) const VkCtx *c = vk_ctx(); + VkFfxImage depth, mv; + float jx = 0, jy = 0; + int reset = 0; + int have = vk_dlaa_fg_inputs(&depth, &mv, &jx, &jy, &reset); + // The context's largest render size covers the depth and motion vectors it is given. They have the scene's size, + // which DLAA and the widescreen pictures make larger than the window, and a context made for the window's size alone + // wrote past its own resources: a crash in amd_fidelityfx_vk.dll, device faults, striped frames. The scene is never + // larger than the picture (widescreen.c wide_picture), so the context is made for that once; remaking it while the + // swapchain still generated from the old one hung the present. A frame with a larger depth anyway is not generated. + unsigned pw, ph; + wide_picture(&pw, &ph); + VkExtent2D max_render = {ext.width > pw ? ext.width : pw, ext.height > ph ? ext.height : ph}; if (F.fg && (F.fg_ext.width != ext.width || F.fg_ext.height != ext.height || F.fg_fmt != fmt)) { vk_queue_lock(), vkDeviceWaitIdle(c->device), vk_queue_unlock(); // a new window size: the context is made for its display size vk_ffx_destroy(&F.fg); @@ -186,17 +199,21 @@ extern "C" void vk_fg_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt, d.header.pNext = &hl.header; d.flags = FFX_FRAMEGENERATION_ENABLE_DEPTH_INFINITE | (hdr_format(fmt) ? FFX_FRAMEGENERATION_ENABLE_HIGH_DYNAMIC_RANGE : 0); d.displaySize = {ext.width, ext.height}; - d.maxRenderSize = {ext.width, ext.height}; + d.maxRenderSize = {max_render.width, max_render.height}; d.backBufferFormat = ffxApiGetSurfaceFormatVK(fmt); ffxReturnCode_t r = vk_ffx_create(&F.fg, &d.header); if (r != FFX_API_RETURN_OK) return F.fg = nullptr, fail("the frame generation context", r); - F.fg_ext = ext, F.fg_fmt = fmt; - rt_log("fg: frame generation context for %ux%u%s", ext.width, ext.height, hdr_format(fmt) ? " (HDR)" : ""); + F.fg_ext = ext, F.fg_fmt = fmt, F.fg_max = max_render; + rt_log("fg: frame generation context for %ux%u%s, render size up to %ux%u", ext.width, ext.height, + hdr_format(fmt) ? " (HDR)" : "", max_render.width, max_render.height); + } + if (have && (depth.width > F.fg_max.width || depth.height > F.fg_max.height)) { + static int told; + if (!told++) + rt_log("fg: a %ux%u scene is larger than the context's %ux%u: those frames are not generated", depth.width, + depth.height, F.fg_max.width, F.fg_max.height); + have = 0; } - VkFfxImage depth, mv; - float jx = 0, jy = 0; - int reset = 0; - int have = vk_dlaa_fg_inputs(&depth, &mv, &jx, &jy, &reset); int on = have && !menu_is_open(); __atomic_store_n(&F.on, on, __ATOMIC_RELAXED); if (!have) F.no_inputs++; diff --git a/runtime/widescreen.c b/runtime/widescreen.c index be6ea162..01c3d4d1 100644 --- a/runtime/widescreen.c +++ b/runtime/widescreen.c @@ -80,13 +80,19 @@ static unsigned picture_height(void) { // (vk_dlaa_wanted is read once) and DLSS only where NGX came up (vk_dlaa_available), so a mode picked in the menu, or one // this PC cannot run, no longer shrinks the scene with nothing to scale it back up. A mode change while one runs still // applies at once. +// dlaa switched off in the menu stops DLSS at once (vk_dlaa.c vk_dlaa_frame reads it each frame), so the share follows +// the setting too: the scene goes back to the game's own scale instead of staying small with nothing to enlarge it. static double dlss_share(void) { - if (!vk_dlaa_wanted() || (!vk_dlaa_fsr3() && !vk_dlaa_available())) return 0; + if (!vk_dlaa_wanted() || !cfg_bool("NX2NAVI_DLAA") || (!vk_dlaa_fsr3() && !vk_dlaa_available())) return 0; const char *m = cfg_value("NX2NAVI_DLSS"); return !strcmp(m, "quality") ? 2.0 / 3 : !strcmp(m, "balanced") ? 0.58 : !strcmp(m, "performance") ? 0.5 : !strcmp(m, "ultra_performance") ? 1.0 / 3 : 1.0; } +// The game turns the scale at +240 into a scene size against its own 1440-line picture (a 2160-line picture at 1.0 +// gave a 1440-line scene), so the share goes there times the picture's height over 1440: wide_init sets it. +static double scale_k = 1.0; + void wide_present(void) { static int set = -2; static uint64_t presents; @@ -96,8 +102,8 @@ void wide_present(void) { unsigned v = cfg_version(); if (v != seen) { seen = v; - float s = (float)dlss_share(); - if (s > 0) memcpy((uint8_t *)rt_patch_page() + 240, &s, 4); + float s = (float)dlss_share(), page_s = (float)(s * scale_k); + if (s > 0) memcpy((uint8_t *)rt_patch_page() + 240, &page_s, 4); if (s <= 0 && rt_patch_enabled(set)) { rt_patch_switch(set, 0); rt_log("widescreen: DLSS off: the game's own render scale again"); @@ -110,6 +116,7 @@ void wide_present(void) { rt_log("widescreen: DLSS render scale %.0f%% of the picture (the game's dynamic resolution off)", dlss_share() * 100); } else if (presents > RES_FIXED_AFTER && dlss_share() > 0 && !rt_patch_enabled(set)) { rt_patch_switch(set, 1); // DLSS switched on later in the run + rt_log("widescreen: DLSS on again: render scale %.0f%% of the picture", dlss_share() * 100); } } @@ -184,10 +191,21 @@ void wide_init(void) { rt_patch_switch(sa, 1); rt_patch_switch(sh, 1); rt_patch_switch(sm, 1); + scale_k = (double)oh / GAME_H; rt_log("widescreen: picture %ux%u, scene %ux%u (%.0f%% of it), camera aspect ratio %.4f (16:9 is %.4f), UI and movies " "in the middle %.1f%%", ow, oh, sw, sch, f * 100, ratio, game, squeeze * 100); } +// The picture the game draws: the widescreen one wide_init set up, else the game's own 2560x1440. DLSS's largest mode +// (dlaa) renders the scene at this size. +void wide_picture(unsigned *w, unsigned *h) { + static unsigned pw, ph; + if (!pw) { + if (!wide_available() || !picture_size(&pw, &ph, 1)) pw = GAME_W, ph = GAME_H; + } + *w = pw, *h = ph; +} + // The generated C has the widescreen patch sets (the menu shows the row only then). int wide_available(void) { static const char *const names[] = {"wide_out", "wide_scene", "wide_aspect", "wide_hud", "wide_movie"};