From bd54e701a82e51566900dd6d6e3263afb87aa22d Mon Sep 17 00:00:00 2001 From: SchulzCode <116190857+SchulzCode@users.noreply.github.com> Date: Sat, 31 Oct 2026 16:31:09 +0100 Subject: [PATCH] Choose the DLSS model and pass DLSS the real frame time dlss_preset (default, k or j; F1 > Screen > "DLSS model", live) sets the render preset hints when a DLSS feature is created. default leaves the choice to NGX (preset K for DLAA, Quality and Balanced in the 310 releases); j is the transformer model NVIDIA describes as slightly less ghosting at the cost of more flicker. A change recreates the features at the next DLAA run. FrameTimeDeltaInMsec now carries the time since the previous evaluation instead of a fixed 16.67 ms. The menu and totk.ini.example name the DLSS model file of the platform in use. --- runtime/cfg.c | 7 ++++--- runtime/ui/menu.cpp | 2 ++ runtime/ui_text.c | 33 ++++++++++++++++++++++++------ runtime/ui_text.h | 3 ++- runtime/vk_dlaa.c | 50 +++++++++++++++++++++++++++++++++++++++++---- totk.ini.example | 12 ++++++++--- 6 files changed, 90 insertions(+), 17 deletions(-) diff --git a/runtime/cfg.c b/runtime/cfg.c index 53f2bb98..cfac4b81 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -37,7 +37,7 @@ static const char *const known[] = { "BIND_SKIP", "BIND_STATS", "BIND_UP", "BIND_X", "BIND_Y", "BIND_ZL", "BIND_ZR", "BLOCK_VIEWS_3D", "CLOTH_REALTIME", "COLOR_BRIGHTNESS", "COLOR_CONTRAST", "COLOR_GAMMA", "COLOR_PRESET", "COLOR_SATURATION", "CONTACT_DEBUG", "CONTACT_SHADOWS", "CORE_DIAG", "CRIT", "CRIT_OUT", - "DESC_TEMPLATE", "DEVICE_PROFILE", "DLAA", "DLAA_JITTER", "DLAA_MV", "DLSS", "DUMP", "DUMP_BUF", "DUMP_DIR", + "DESC_TEMPLATE", "DEVICE_PROFILE", "DLAA", "DLAA_JITTER", "DLAA_MV", "DLSS", "DLSS_PRESET", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FREEZE_IDLE", "FREE_CORES", "FULLSCREEN", "FXAA", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "HDR", "HDR_GAME_NITS", @@ -70,7 +70,7 @@ static const struct { const char *key, *section; } sections[] = { {"COLOR_BRIGHTNESS", "display"}, {"COLOR_CONTRAST", "display"}, {"COLOR_SATURATION", "display"}, {"COLOR_GAMMA", "display"}, {"HDR", "display"}, {"HDR_PEAK_NITS", "display"}, {"HDR_GAME_NITS", "display"}, {"HDR_UI_NITS", "display"}, {"SHADOW_RES", "display"}, - {"DLAA", "display"}, {"DLSS", "display"}, {"FXAA", "display"}, + {"DLAA", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"FXAA", "display"}, {"DEVICE_PROFILE", "display"}, {"ASSUME_FOCUS", "display"}, {"SHADOW_SCALE", "display"}, {"SHADOW_RANGE", "display"}, {"CONTACT_SHADOWS", "display"}, {"PCSS", "display"}, @@ -111,7 +111,8 @@ static const CfgMeta metas[] = { {"PERF_OVERLAY", "off", "off|fps|full", LIVE}, {"OUTPUT_RES", "1920x1080", NULL, RESTART}, {"RENDER_SCALE", "game", "game|50|67|75|100|125|150|200", RESTART}, {"UPSCALER", "fsr", "fsr|bilinear", LIVE}, {"SHARPNESS", "80", "0..100", LIVE}, - {"DLAA", "0", "0|1", RESTART}, {"DLSS", "dlaa", "dlaa|quality|balanced|performance", RESTART}, {"FXAA", "1", "0|1", LIVE}, + {"DLAA", "0", "0|1", RESTART}, {"DLSS", "dlaa", "dlaa|quality|balanced|performance", RESTART}, + {"DLSS_PRESET", "default", "default|k|j", LIVE}, {"FXAA", "1", "0|1", LIVE}, {"ASPECT", "fit", "fit|stretch", LIVE}, {"FOV", "100", "70..140", LIVE}, {"ANISO", "game", "game|2|4|8|16", RESTART}, // vk_texture.c sampler_features // colour adjustment (vk_color.c); the preset is the menu's, the four values are what the present uses diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index a4a6e33d..e4407a9e 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -674,6 +674,8 @@ static void tab_screen(float scale) { static const UiTextId dlss[] = {UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY, UI_MENU_DLSS_BALANCED, UI_MENU_DLSS_PERFORMANCE}; opt_choice("TOTK_DLSS", UI_MENU_DLSS, dlss, 4, UI_MENU_DLSS_DESC); + static const UiTextId preset[] = {UI_MENU_DLSS_PRESET_DEFAULT, UI_MENU_DLSS_PRESET_K, UI_MENU_DLSS_PRESET_J}; + opt_choice("TOTK_DLSS_PRESET", UI_MENU_DLSS_PRESET, preset, 3, UI_MENU_DLSS_PRESET_DESC); opt_toggle("TOTK_FXAA", UI_MENU_FXAA, UI_MENU_FXAA_DESC); rows_color(); opt_group(UI_MENU_HDR_GROUP); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 03ca1186..b7069d08 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -25,6 +25,15 @@ typedef struct { const char *lang; const char *const *text; } Row; [UI_SWKBD_TITLE] = title, [UI_SWKBD_PROMPT] = prompt, [UI_SWKBD_DEFAULT_NAME] = name, [UI_SWKBD_OK] = ok, \ [UI_SWKBD_CANCEL] = cancel, [UI_SWKBD_PAD_HINT] = hint, LANG_NAMES +// The DLSS model file and the executable, as the player sees them on this platform. +#ifdef _WIN32 +#define DLSS_FILE "nvngx_dlss.dll" +#define EXE_FILE "totk.exe" +#else +#define DLSS_FILE "libnvidia-ngx-dlss.so" +#define EXE_FILE "totk" +#endif + static const char *const text_en[UI_TEXT_COUNT] = { SWKBD("Text entry", "Enter a name", "Horse", "OK", "Cancel", "Controller: A = OK, B = Cancel"), @@ -123,9 +132,14 @@ static const char *const text_en[UI_TEXT_COUNT] = { "away. Spreads the shadow map over more ground: raise Shadow resolution with it. " "Takes effect at the next start.", [UI_MENU_DLAA] = "NVIDIA DLSS / DLAA", - [UI_MENU_DLAA_DESC] = "NVIDIA DLSS for the 3D scene (NVIDIA RTX GPUs; nvngx_dlss.dll next to totk.exe): smoother edges " - "and less shimmer. The HUD is not touched. The mode below sets the resolution it works from. Takes effect " - "after a restart.", + [UI_MENU_DLAA_DESC] = "NVIDIA DLSS for the 3D scene (NVIDIA RTX GPUs; " DLSS_FILE " next to " EXE_FILE "): smoother " + "edges and less shimmer. The HUD is not touched. The mode below sets the resolution it works from. Takes effect after a restart.", + [UI_MENU_DLSS_PRESET] = "DLSS model", + [UI_MENU_DLSS_PRESET_DESC] = "Which DLSS model runs. Automatic lets the driver choose (the transformer model K for DLAA, " + "Quality and Balanced). J: slightly less ghosting behind moving characters, a little more " + "flicker. K: always the sharpest model, also in Performance. Applies at once.", + [UI_MENU_DLSS_PRESET_DEFAULT] = "Automatic", [UI_MENU_DLSS_PRESET_K] = "K (sharpest)", + [UI_MENU_DLSS_PRESET_J] = "J (less ghosting)", [UI_MENU_DLSS] = "DLSS mode", [UI_MENU_DLSS_DESC] = "DLAA draws the 3D scene at full resolution. Quality, Balanced and Performance draw it at 67, 58 " "and 50 % and let DLSS scale it up, for more frames per second; they replace the 3D render " @@ -552,9 +566,16 @@ static const char *const text_ru[UI_TEXT_COUNT] = { "Карта теней растягивается на большую площадь, поэтому вместе с этим поднимайте " "разрешение теней. Действует после перезапуска.", [UI_MENU_DLAA] = "NVIDIA DLSS / DLAA", - [UI_MENU_DLAA_DESC] = "NVIDIA DLSS для 3D-сцены (видеокарты NVIDIA RTX; nvngx_dlss.dll рядом с totk.exe): ровнее края и " - "меньше мерцания. Интерфейс не затрагивается. Режим ниже задаёт разрешение, с которым он работает. " - "Действует после перезапуска.", + [UI_MENU_DLAA_DESC] = "NVIDIA DLSS для 3D-сцены (видеокарты NVIDIA RTX; " DLSS_FILE " рядом с " EXE_FILE "): ровнее " + "края и меньше мерцания. Интерфейс не затрагивается. Режим ниже задаёт разрешение, с которым он " + "работает. Действует после перезапуска.", + [UI_MENU_DLSS_PRESET] = "Модель DLSS", + [UI_MENU_DLSS_PRESET_DESC] = "Какая модель DLSS работает. «Автоматически» оставляет выбор драйверу (трансформерная модель " + "K для DLAA, «Качества» и «Баланса»). J: чуть меньше шлейфов за движущимися персонажами, " + "немного больше мерцания. K: всегда самая чёткая модель, и в «Производительности». " + "Действует сразу.", + [UI_MENU_DLSS_PRESET_DEFAULT] = "Автоматически", [UI_MENU_DLSS_PRESET_K] = "K (самая чёткая)", + [UI_MENU_DLSS_PRESET_J] = "J (меньше шлейфов)", [UI_MENU_DLSS] = "Режим DLSS", [UI_MENU_DLSS_DESC] = "DLAA рисует 3D-сцену в полном разрешении. «Качество», «Баланс» и «Производительность» рисуют её " "в 67, 58 и 50 % и масштабируют через DLSS ради большего числа кадров; они заменяют масштаб " diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 702cdc4e..15e05c41 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -54,7 +54,8 @@ typedef enum { UI_MENU_CONTACT_SHADOWS, UI_MENU_CONTACT_SHADOWS_DESC, UI_MENU_PCSS, UI_MENU_PCSS_DESC, UI_MENU_DLAA, UI_MENU_DLAA_DESC, UI_MENU_DLSS, UI_MENU_DLSS_DESC, UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY, - UI_MENU_DLSS_BALANCED, UI_MENU_DLSS_PERFORMANCE, UI_MENU_FXAA, UI_MENU_FXAA_DESC, + UI_MENU_DLSS_BALANCED, UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_PRESET, UI_MENU_DLSS_PRESET_DESC, + UI_MENU_DLSS_PRESET_DEFAULT, UI_MENU_DLSS_PRESET_K, UI_MENU_DLSS_PRESET_J, UI_MENU_FXAA, UI_MENU_FXAA_DESC, // Game UI_MENU_FPS_LIMIT, UI_MENU_FPS_LIMIT_DESC, UI_MENU_FPS_30, UI_MENU_FPS_40, UI_MENU_FPS_45, UI_MENU_FPS_60, UI_MENU_FPS_90, diff --git a/runtime/vk_dlaa.c b/runtime/vk_dlaa.c index fb7d0b3f..0c1bfc92 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -319,7 +319,10 @@ static struct { 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}; + int preset, preset_dirty; // the DLSS model features are created with (preset_value); a change pending + unsigned cfg_seen; // cfg_version when preset was read + uint64_t last_eval_ns; // plat_now_ns of the previous evaluation (FrameTimeDeltaInMsec) +} D = {.mv_ok = -1, .cfg_seen = ~0u}; static int dl_active(void) { return N.available && !D.failed && D.on; } @@ -540,6 +543,17 @@ static void next_jitter(void) { D.jit_ok = !D.hold && !nj; } +// The DLSS model (TOTK_DLSS_PRESET, live): default leaves the choice to NGX, which in the 310 releases is the +// transformer preset K for DLAA, Quality and Balanced and M for Performance. j is the other transformer model: NVIDIA +// describes it as slightly less ghosting at the cost of extra flicker. k pins K, also in Performance. The value is an +// NVSDK_NGX_DLSS_Hint_Render_Preset, read when a feature is created; a change recreates the features (preset_check). +static int preset_value(void) { + const char *v = cfg_get("TOTK_DLSS_PRESET"); + if (v && (v[0] == 'k' || v[0] == 'K') && !v[1]) return 11; + if (v && (v[0] == 'j' || v[0] == 'J') && !v[1]) return 10; + return 0; +} + // The quality setting DLSS is created with, from the scene's share of the output width. static int perf_quality(uint32_t w, uint32_t ow) { if (w >= ow) return NGX_PERFQ_DLAA; @@ -554,6 +568,11 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) { uint32_t w = t->width, h = t->height, ow = dst->width, oh = dst->height; VkCommandBuffer cb = ex->cb; vk_exec_barrier(ex); // what drew the scene is done (no pass is open here) + if (D.preset_dirty) { // another model: features are created with it, so every size gets a new one + for (int i = 0; i < 3; i++) + if (D.sizes[i].out) free_size(&D.sizes[i]); + D.last = NULL, D.preset_dirty = 0; + } struct Size *e = size_for(cb, w, h, ow, oh); if (!e) return dl_fail("work image creation", 0); if (e != D.last) D.reset = 1, D.why[0]++; // another size's history is from another moment @@ -583,11 +602,17 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) { // IsHDR | MVLowRes | AutoExposure: linear scene light, motion vectors at the render size, no exposure texture p_seti(p, "DLSS.Feature.Create.Flags", (1 << 0) | (1 << 1) | (1 << 6)); p_seti(p, "DLSS.Enable.Output.Subrects", 0); + static const char *const hint[] = {"DLSS.Hint.Render.Preset.DLAA", "DLSS.Hint.Render.Preset.Quality", + "DLSS.Hint.Render.Preset.Balanced", "DLSS.Hint.Render.Preset.Performance", + "DLSS.Hint.Render.Preset.UltraPerformance", + "DLSS.Hint.Render.Preset.UltraQuality"}; + for (size_t i = 0; i < sizeof hint / sizeof *hint; i++) p_setu(p, hint[i], (unsigned)D.preset); NgxResult r = N.create(cb, NGX_FEATURE_SUPERSAMPLING, p, &e->feat); if (!NGX_OK(r) || !e->feat) return dl_fail("DLSS feature creation", r); D.reset = 1; - rt_log("dlaa: DLSS feature created at %ux%u -> %ux%u, quality value %d (scene format %d, depth format %d)", w, - h, ow, oh, perf_quality(w, ow), (int)t->format, (int)z->format); + rt_log("dlaa: DLSS feature created at %ux%u -> %ux%u, quality value %d, preset %s (scene format %d, depth " + "format %d)", w, h, ow, oh, perf_quality(w, ow), D.preset == 11 ? "K" : D.preset == 10 ? "J" : "default", + (int)t->format, (int)z->format); } if (D.last_color != t->image) D.reset = 1, D.why[2]++, D.last_color = t->image; VkImageView cv = vk_exec_target_view(t->img, t->format, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, t->level, @@ -610,7 +635,12 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) { p_setu(p, "DLSS.Render.Subrect.Dimensions.Height", h); p_setf(p, "DLSS.Pre.Exposure", 1.0f); p_setf(p, "DLSS.Exposure.Scale", 1.0f); - p_setf(p, "FrameTimeDeltaInMsec", 16.67f); + // The time since the previous evaluation, which DLSS weighs its history by; 60 fps before the first and after a + // gap (a pause, a load), where no history carries over anyway. + uint64_t now = plat_now_ns(); + double dt = D.last_eval_ns ? (now - D.last_eval_ns) / 1e6 : 0; + D.last_eval_ns = now; + p_setf(p, "FrameTimeDeltaInMsec", dt > 0 && dt < 100 ? (float)dt : 16.67f); NgxResult r = N.evaluate(cb, e->feat, p, NULL); if (!NGX_OK(r)) return dl_fail("DLSS evaluation", r); D.reset = 0; @@ -674,7 +704,19 @@ void vk_dlaa_pass(VkExec *ex) { } } +// The preset, read again when a setting changed (the menu); a different one recreates the features at the next DLAA run. +static void preset_check(void) { + unsigned v = cfg_version(); + if (v == D.cfg_seen) return; + D.cfg_seen = v; + int p = preset_value(); + if (p == D.preset) return; + if (D.evals) rt_log("dlaa: DLSS preset %s; the features are created again", p == 11 ? "K" : p == 10 ? "J" : "default"); + D.preset = p, D.preset_dirty = 1, D.reset = 1; +} + void vk_dlaa_frame(void) { + preset_check(); int on = N.available && cfg_bool("TOTK_DLAA"); if (on != D.on) { rt_log("dlaa: %s", on ? "on" : "off"); diff --git a/totk.ini.example b/totk.ini.example index e22dbbee..ed1899ca 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -191,14 +191,20 @@ # patch 0010), so the shader cache is rebuilt once after an update. Read at start. # pcss = 0 -# NVIDIA DLSS / DLAA for the 3D scene, on NVIDIA RTX GPUs with nvngx_dlss.dll (from NVIDIA's DLSS SDK) next to -# totk.exe; elsewhere the setting does nothing. The HUD is drawn after it and is not touched. Read at start. +# NVIDIA DLSS / DLAA for the 3D scene, on NVIDIA RTX GPUs with the DLSS model from NVIDIA's DLSS SDK next to the +# executable (Windows: nvngx_dlss.dll next to totk.exe; Linux: libnvidia-ngx-dlss.so. next to totk, with the +# NVIDIA driver's libnvidia-ngx.so.1 installed); 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). They apply -# only with dlaa = 1 and nvngx_dlss.dll next to totk.exe, on Windows; otherwise the scene follows render_scale. Read at +# only with dlaa = 1 and the DLSS model next to the executable; otherwise the scene follows render_scale. Read at # start. # dlss = dlaa +# The DLSS model: default (NGX chooses: the transformer model K for dlaa, quality and balanced, M for performance), k +# (K in every mode) or j (the other transformer model: slightly less ghosting behind moving characters, a little more +# flicker). Changes while the game runs take effect at once (DLSS starts a new history). +# dlss_preset = default # 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. # fxaa = 1