diff --git a/runtime/cfg.c b/runtime/cfg.c index 566acbcc..76714066 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -44,7 +44,7 @@ static const char *const known[] = { "DESC_TEMPLATE", "DESWIZZLE", "DEVICE_PROFILE", "DIALOGUE_CLICK", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_CAM_JITTER", "DLAA_EFFECTS_AFTER", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_FIXED_EXPOSURE", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG", "DYNAMIC_RES", "DYN_DELTA", "EXEFS", "FEEDBACK", "FG_DEBUG", "FG_SHOT", "FG_SHOT_DIR", "FG_TEST", "FG_TIMES", "FIXED_RES_PATCH", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FRAME_GEN", "FRAME_QUEUE", "FREECAM_KEY", "FREECAM_PAD", "FREECAM_PATCH", - "FREEZE_IDLE", "FREE_CORES", "FSR3_DEBUG", "FSR3_VIEW", + "FREEZE_IDLE", "FREE_CORES", "FSR3_DEBUG", "FSR3_VIEW", "FSR_SHARPNESS", "FULLSCREEN", "FXAA", "GAMEPLAY_DISTANCE_SENSITIVITY", "GAMEPLAY_ITEM_AD", "GAMEPLAY_ITEM_SENSITIVITY", "GAMEPLAY_ITEM_WHEEL", "GAMEPLAY_MAP_ZOOM", "GAMEPLAY_MAP_ZOOM_SENSITIVITY", "GAMEPLAY_ROTATION_SENSITIVITY", "GAMEPLAY_TWEAKS_ENABLED", @@ -85,7 +85,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"}, {"HDR_HUE", "display"}, {"SHADOW_RES", "display"}, - {"SCENE_UPSCALER", "display"}, {"DLAA", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_CHAR_MASK", "display"}, {"DLSS_FIXED_EXPOSURE", "display"}, {"DLAA_EFFECTS_AFTER", "display"}, {"REFLEX", "display"}, {"FXAA", "display"}, + {"SCENE_UPSCALER", "display"}, {"DLAA", "display"}, {"DLSS", "display"}, {"FSR_SHARPNESS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_CHAR_MASK", "display"}, {"DLSS_FIXED_EXPOSURE", "display"}, {"DLAA_EFFECTS_AFTER", "display"}, {"REFLEX", "display"}, {"FXAA", "display"}, {"DEVICE_PROFILE", "display"}, {"ASSUME_FOCUS", "display"}, {"DISCORD_RPC", "discord"}, {"DISCORD_APP_ID", "discord"}, {"DISCORD_IMAGE", "discord"}, {"SHADOW_SCALE", "display"}, {"SHADOW_RANGE", "display"}, {"GRASS_RANGE", "display"}, {"CONTACT_SHADOWS", "display"}, @@ -143,6 +143,7 @@ static const CfgMeta metas[] = { {"UPSCALER", "fsr", "fsr|bilinear", LIVE}, {"SHARPNESS", "80", "0..100", LIVE}, {"SCENE_UPSCALER", "off", "off|dlss|fsr3", RESTART}, {"DLAA", "0", "0|1", RESTART}, {"DLSS", "dlaa", "dlaa|quality|balanced|performance|ultra_performance", LIVE}, + {"FSR_SHARPNESS", "80", "0..100", LIVE}, // vk_dlaa.c fsr_evaluate {"DLSS_PRESET", "default", "default|k|j", LIVE}, {"DLSS_FIXED_EXPOSURE", "0", "0|1", LIVE}, {"DLAA_EFFECTS_AFTER", "0", "0|1", LIVE}, {"DLSS_CHAR_MASK", "65", "0|35|65|100", LIVE}, {"REFLEX", "off", "off|on|boost", RESTART}, {"FXAA", "1", "0|1", LIVE}, {"LOD_STEADY", "0", "0|1", RESTART}, // sets steady diff --git a/runtime/resolution.c b/runtime/resolution.c index 57de14f9..420f0dc5 100644 --- a/runtime/resolution.c +++ b/runtime/resolution.c @@ -674,19 +674,29 @@ void res_fov_live(void) { // 2867-wide scene stays at 100 %, one wider than about 2970 does not, and a 4267-wide one (5120x1440 at render_scale // 83) fits no tier and falls back to 80 % every frame, whatever the GPU's load. 1 (the default) leaves the game's own // stepping and the set off. Runs on a settings change (gfx_present.c window_settings_live), like res_fov_live. +// FSR 3.1 as the scene upscaler holds it at 100 % whatever dynamic_res says, as codexx-dev's pull request #1245 does +// for its FSR: each tier is a scene of another size, so every step starts FSR's history again, and below 100 % the +// game ends its frame another way (a frame log on 1.4.3: its copy shader scales the scene straight into the +// output-sized target instead of the scaling FXAA draw), which #1245 measured as a picture that went soft and sharp in +// turns at a 2560x1440 scene. A 1280x720 scene (1080p, quality) stayed at 100 % through a 70 s town run, so it gains +// nothing there; the hold matters for the wide scenes the cost model steps down. void res_dynres_live(void) { static int set = -2, shown = -1; if (set == -2) set = rt_patch_set("fixres"); - int dyn = cfg_bool("TOTK_DYNAMIC_RES"); - if (dyn == shown) return; - shown = dyn; + int fsr = vk_upscaler_on() && vk_upscaler_engine() == UPSCALER_FSR3; + int dyn = cfg_bool("TOTK_DYNAMIC_RES") && !fsr; + int state = dyn | fsr << 1; + if (state == shown) return; + shown = state; if (set < 0) { if (!dyn) rt_log("resolution: this game version has no fixed-resolution patch; the game keeps its dynamic resolution"); return; } rt_patch_switch(set, !dyn); rt_log("resolution: dynamic resolution %s", - dyn ? "on: the game's own 100, 90 or 80 %" : "off: the scene stays at 100 %"); + dyn ? "on: the game's own 100, 90 or 80 %" + : fsr ? "off while FSR 3.1 upscales the scene: the scene stays at 100 %" + : "off: the scene stays at 100 %"); } void res_wanted(unsigned out[2]) { diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 0513c7ba..60684572 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -827,6 +827,8 @@ static void tab_screen(float scale) { UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_ULTRA}; opt_choice("TOTK_DLSS", UI_MENU_DLSS, dlss, 5, UI_MENU_DLSS_DESC); } + if (!strcmp(engine, "fsr3")) // FSR 3.1's own sharpening (vk_dlaa.c fsr_evaluate) + opt_slider("TOTK_FSR_SHARPNESS", UI_MENU_FSR3_SHARPNESS, 0, 100, UI_MENU_FSR3_SHARPNESS_DESC, 5, "%.0f %%"); if (!strcmp(engine, "dlss")) { // DLSS's model, its characters' mask and its other switches (FSR 3.1 has none) 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); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 8c96fa3a..5d2a1a8f 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -189,6 +189,8 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1", [UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU] = "DLSS: needs an NVIDIA RTX GPU", [UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS: " DLSS_FILE " is missing", + [UI_MENU_FSR3_SHARPNESS] = "FSR 3.1 sharpness", + [UI_MENU_FSR3_SHARPNESS_DESC] = "Sharpening of the 3D scene after FSR 3.1; 0 turns it off.", [UI_MENU_FPS_LIMIT] = "Frame rate limit", [UI_MENU_FPS_LIMIT_DESC] = "The most frames per second the game draws. Above 60 is experimental and needs Game speed " @@ -833,6 +835,8 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1", [UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU] = "DLSS: нужна видеокарта NVIDIA RTX", [UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS: нет " DLSS_FILE, + [UI_MENU_FSR3_SHARPNESS] = "Резкость FSR 3.1", + [UI_MENU_FSR3_SHARPNESS_DESC] = "Повышение резкости 3D-сцены после FSR 3.1; 0 выключает его.", [UI_MENU_FPS_LIMIT] = "Ограничение частоты кадров", [UI_MENU_FPS_LIMIT_DESC] = "Наибольшее число кадров в секунду. Выше 60 — экспериментальный режим, нужна «Скорость " @@ -1944,6 +1948,8 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1", [UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU] = "DLSS: precisa de uma GPU NVIDIA RTX", [UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS: falta o " DLSS_FILE, + [UI_MENU_FSR3_SHARPNESS] = "Nitidez do FSR 3.1", + [UI_MENU_FSR3_SHARPNESS_DESC] = "Aumento de nitidez da cena 3D após o FSR 3.1; 0 desliga.", [UI_MENU_TAB_CHEATS] = "Cheats", [UI_MENU_CHEATS_NONE] = "Nenhum cheat para esta versão do jogo. Os cheats de um mod são um arquivo de cheats do " "Atmosphere na pasta cheats dele, com o nome da build do jogo: mods\\\\cheats\\%s. " @@ -2697,6 +2703,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1", [UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU] = "DLSS:需要 NVIDIA RTX 显卡", [UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS:缺少 " DLSS_FILE, + [UI_MENU_FSR3_SHARPNESS] = "FSR 3.1 锐度", + [UI_MENU_FSR3_SHARPNESS_DESC] = "FSR 3.1 之后 3D 场景的锐化强度;0 为关闭。", [UI_MENU_TAB_CHEATS] = "金手指", [UI_MENU_CHEATS_NONE] = "此游戏版本没有金手指。模组的金手指是它的 cheats 文件夹中以游戏构建命名的 Atmosphere " "金手指文件:mods\\<模组>\\cheats\\%s。重启游戏后才会读取。对于修改游戏代码的金手指," diff --git a/runtime/ui_text.h b/runtime/ui_text.h index da69fe77..3cdb2ff4 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -65,7 +65,8 @@ typedef enum { UI_MENU_DLSS_CHARS_OFF, UI_MENU_DLSS_CHARS_LIGHT, UI_MENU_DLSS_CHARS_MEDIUM, UI_MENU_DLSS_CHARS_FULL, UI_MENU_FXAA, UI_MENU_FXAA_DESC, UI_MENU_REFLEX, UI_MENU_REFLEX_DESC, UI_MENU_REFLEX_OFF, UI_MENU_REFLEX_ON, UI_MENU_REFLEX_BOOST, UI_MENU_SCENE_UPSCALER, UI_MENU_SCENE_UPSCALER_DESC, UI_MENU_SCENE_UPSCALER_OFF, UI_MENU_SCENE_UPSCALER_DLSS, - UI_MENU_SCENE_UPSCALER_FSR3, UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU, UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL, + UI_MENU_SCENE_UPSCALER_FSR3, UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU, UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL, UI_MENU_FSR3_SHARPNESS, + UI_MENU_FSR3_SHARPNESS_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 de982d73..30ec999e 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -1291,10 +1291,15 @@ static int fsr_evaluate(VkExec *ex, struct Size *e, const VkExecTarget *t, const uint64_t now = plat_now_ns(); double dt = D.last_eval_ns ? (now - D.last_eval_ns) / 1e6 : 0; D.last_eval_ns = now; + // FSR's own sharpening (fsr_sharpness, live): the game's sharpening is part of its FXAA, which FSR's frames go + // without (vk_dlaa_skip_draw), so without it FSR's picture is softer than the game's own + int sharp = cfg_int("TOTK_FSR_SHARPNESS"); + sharp = sharp < 0 ? 0 : sharp > 100 ? 100 : sharp; Fsr3Frame fr = {.color = t->image, .color_format = t->format, .depth = z->image, .mv = e->mv, .out = e->out, .w = t->width, .h = t->height, .ow = ow, .oh = oh, .jx = jx, .jy = jy, .near_m = cam.near_m, .far_m = cam.infinite || cam.far_m <= cam.near_m ? 1e5f : cam.far_m, .fov_y = cam.fov_y, - .dt_ms = dt > 0 && dt < 100 ? (float)dt : 16.67f, .reset = D.reset, .fence = ex->fence}; + .dt_ms = dt > 0 && dt < 100 ? (float)dt : 16.67f, .reset = D.reset, .sharpness = sharp / 100.0f, + .fence = ex->fence}; uint64_t c0 = timed ? kern_now_ns() : 0; int ok = fsr3_dispatch(ex->cb, &fr); if (timed) T.cpu_ngx += kern_now_ns() - c0; @@ -1885,6 +1890,10 @@ void vk_dlaa_frame(void) { // stretched over the whole screen. static const uint64_t FXAA_FS[] = {0xf450003ebeb3dc52ull, 0x0a12f4bc2a9a4fbeull, 0x5c43ae18948d52cbull, 0xaad42238801d31d8ull, 0xde20aef90fea4ce6ull, 0x755964e8dce7f34dull}; +// The fragment shader of the FXAA's first pass, the copy of the scene target into the scratch target (this build's +// translator, seen in 1.4.3 frame logs; another hash leaves the draw alone). See vk_dlaa_skip_draw for why FSR 3.1's +// frames skip it where it copies the scene target onto itself. +static const uint64_t FXAA_COPY_FS[] = {0xa0fd34391f2af811ull}; // Chunks of one submission look shaders up side by side: an entry's hash is stored before its shader, and entries are // added under the lock. @@ -1929,7 +1938,16 @@ int vk_dlaa_skip_draw(VkExec *ex, const GfxShader *fs) { "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 + // FSR 3.1 in place (the scene as large as the output, so no scaling draw follows) goes without the game's FXAA + // and its copy of the scene target onto itself on every frame, as codexx-dev found for FSR (pull request #1245, + // vk_dlaa.c vk_dlaa_skip_draw there). Measured there on 1.4.3 at a 2560x1440 scene and output: with the upscaler on + // the game ran its FXAA, which also sharpens, on 17 frames in every 96 and on the others drew its copy shader from + // the scene target onto itself, so the picture went soft and sharp in turns. Here the dynamic resolution stays at + // 100 % while FSR 3.1 runs (resolution.c res_dynres_live) and FSR sharpens its own output (fsr_sharpness, + // fsr_evaluate) in place of the FXAA's sharpening. Scaled frames (D.up) need nothing more: there FSR's picture + // already replaces the scaling FXAA draw below. + int fsr_in_place = D.done && !D.up && D.fsr; + if (fxaa && !D.up && !fsr_in_place) return 0; // nothing to skip: no shader lookup per draw at the defaults if (!fs) return 0; // 1.2.1 scales the light target to the output with an upscaler of its own (12 texelFetch taps around the source // pixel, fragment shader e6f7ae35b8479ef3 with this build's translator), not with the FXAA one, in a pass without @@ -1949,6 +1967,24 @@ int vk_dlaa_skip_draw(VkExec *ex, const GfxShader *fs) { uint64_t h = spirv_hash(fs); int known = 0; for (size_t i = 0; i < sizeof FXAA_FS / sizeof FXAA_FS[0]; i++) known |= h == FXAA_FS[i]; + if (fsr_in_place) { + static int logged_fxaa, logged_copy; + if (known && ex->depth.image) { + if (!logged_fxaa) + logged_fxaa = 1, rt_log("dlaa: FSR 3.1 skips the game's FXAA (fragment shader %016llx) and sharpens its " + "own picture (fsr_sharpness)", (unsigned long long)h); + return 1; + } + int copy = 0; + for (size_t i = 0; i < sizeof FXAA_COPY_FS / sizeof FXAA_COPY_FS[0]; i++) copy |= h == FXAA_COPY_FS[i]; + if (copy && ex->color[0].image == D.color.image && vk_exec_draw_samples(ex, fs, D.color.img)) { + if (!logged_copy) + logged_copy = 1, rt_log("dlaa: FSR 3.1 skips the game's copy of the scene target onto itself (fragment " + "shader %016llx)", (unsigned long long)h); + return 1; + } + if (fxaa) return 0; + } if (!known) return 0; if (!ex->depth.image) return D.up; // the scaling pass, which DLSS replaced if (!fxaa && !fx_found) { diff --git a/runtime/vk_fsr3.cpp b/runtime/vk_fsr3.cpp index 2a088a7a..56e50721 100644 --- a/runtime/vk_fsr3.cpp +++ b/runtime/vk_fsr3.cpp @@ -233,8 +233,10 @@ extern "C" int fsr3_dispatch(VkCommandBuffer cb, const Fsr3Frame *f) { dd.motionVectorScale = {1.0f, 1.0f}; // render pixels already dd.renderSize = {f->w, f->h}; dd.upscaleSize = {f->ow, f->oh}; - dd.enableSharpening = false; // the present's RCAS (upscaler = fsr, sharpness) is the one sharpening pass - dd.sharpness = 0.0f; + // FSR's RCAS pass on its output (fsr_sharpness): the game's own sharpening is part of the scaling FXAA draw that + // FSR replaces, and the present's RCAS (upscaler = fsr, sharpness) only runs where it scales to the window + dd.enableSharpening = f->sharpness > 0.0f; + dd.sharpness = f->sharpness > 1.0f ? 1.0f : f->sharpness; dd.frameTimeDelta = f->dt_ms; dd.preExposure = 1.0f; dd.reset = f->reset != 0; diff --git a/runtime/vk_fsr3.h b/runtime/vk_fsr3.h index c367c25b..6cc7b8b0 100644 --- a/runtime/vk_fsr3.h +++ b/runtime/vk_fsr3.h @@ -22,6 +22,7 @@ typedef struct { float near_m, far_m, fov_y; // the camera's planes (m) and vertical field of view (radians) float dt_ms; // time since the last upscaled frame int reset; // no usable history (a cut, a new size, the first frame) + float sharpness; // FSR 3.1's own sharpening (RCAS) on its output, 0..1; 0 leaves the pass out uint64_t fence; // the submission's timeline value (VkExec.fence) } Fsr3Frame; diff --git a/totk.ini.example b/totk.ini.example index 5fdc945c..a1581d3b 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -228,7 +228,7 @@ # Dynamic resolution: 1 lets the game lower the scene to 90 or 80 % of that size, 0 keeps it at 100 %. The game decides # by a cost estimate made for the Switch, which grows with the scene's width and ignores how fast your GPU is: a # scene wider than about 3000 pixels can drop to 80 % on any GPU. 1 is the default. 1.1.0, 1.2.1 and 1.4.3. Changes in -# the menu take effect at once. +# the menu take effect at once. While FSR 3.1 upscales the scene (scene_upscaler = fsr3) it stays at 100 %. # dynamic_res = 1 # Scaling to the window when it is larger than the game resolution: fsr (AMD FSR 1) or bilinear, and FSR's sharpening # from 0 (off) to 100. Changes while the game runs take effect at once. @@ -308,6 +308,10 @@ # upscaler runs; otherwise the scene follows render_scale. Changes while the game runs take effect at once (1.4.3; 1.2.1 # at the next start). # dlss = dlaa +# FSR 3.1's own sharpening of the 3D scene, from 0 (off) to 100. The game's sharpening is part of its FXAA, which FSR +# 3.1 replaces, so at 0 FSR's picture is softer than the game's own. Only with scene_upscaler = fsr3. Changes while the +# game runs take effect at once. +# fsr_sharpness = 80 # The DLSS model: default (NVIDIA's advice per mode: K for dlaa, quality and balanced, M for performance, L for # ultra_performance), k (K in every mode) or j (the other transformer model: slightly less ghosting behind moving # characters, a little more flicker). Any other model by its letter, a to m: on slower RTX cards the older model e is