diff --git a/runtime/cfg.c b/runtime/cfg.c index 09c15436..a688e68d 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -42,7 +42,7 @@ static const char *const known[] = { "DESC_TEMPLATE", "DEVICE_PROFILE", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG", "LOG_CS_BINDS", "LOG_TEX_FLAGS", "LOG_MESH", "MESH", "POOL", "NATIVE_TENSOR", "LOG_RCOND", "LOG_RT_SIZES", "DUMP_WHITE", "DUMP_AFTER", "SUBMIT_FINISH", "ACQUIRE_WAIT", "CS_FALLBACK", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FREEZE_IDLE", "FREE_CORES", - "FULLSCREEN", "FXAA", "GAME_ASPECT", "GPA", "GPA_EMPTY", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "HDR", "HDR_GAME_NITS", "HDR_HUE", + "FULLSCREEN", "FXAA", "GAME_ASPECT", "GAME_RES", "GPA", "GPA_EMPTY", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "HDR", "HDR_GAME_NITS", "HDR_HUE", "HDR_PEAK_NITS", "HDR_UI_NITS", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "LANG", "LIB_PREBUILD", "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MEMORY", "MENU_LANG", "MENU_SOUND_VOLUME", "MENU_TEST", "MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MOTION", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_HOST", "MOVIE_PACE", @@ -68,7 +68,7 @@ static const struct { const char *key, *section; } sections[] = { {"FPS_LIMIT", "frame rate"}, {"FPS60", "frame rate"}, {"REALTIME", "frame rate"}, {"CLOTH_REALTIME", "frame rate"}, {"HIGHFPS_FIX", "frame rate"}, {"FULLSCREEN", "display"}, {"WINDOW_SIZE", "display"}, {"PERF_OVERLAY", "display"}, {"VK_PRESENT", "display"}, - {"GPU_INDEX", "display"}, {"OUTPUT_RES", "display"}, {"GAME_ASPECT", "display"}, {"RENDER_SCALE", "display"}, {"UPSCALER", "display"}, + {"GPU_INDEX", "display"}, {"OUTPUT_RES", "display"}, {"GAME_ASPECT", "display"}, {"GAME_RES", "display"}, {"RENDER_SCALE", "display"}, {"UPSCALER", "display"}, {"SHARPNESS", "display"}, {"ASPECT", "display"}, {"FOV", "display"}, {"ANISO", "display"}, {"COLOR_PRESET", "display"}, {"COLOR_BRIGHTNESS", "display"}, {"COLOR_CONTRAST", "display"}, {"COLOR_SATURATION", "display"}, @@ -121,6 +121,7 @@ static const CfgMeta metas[] = { {"DLSS_PRESET", "default", "default|k|j", LIVE}, {"DLSS_CHAR_MASK", "65", "0|35|65|100", LIVE}, {"FXAA", "1", "0|1", LIVE}, {"GAME_ASPECT", "16:9", "16:9|window|21:9|32:9", RESTART}, // widescreen.c + {"GAME_RES", "1440", "1440|1800|2160|2880|window", RESTART}, // widescreen.c: the picture's height {"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 312612c7..5ba076d7 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -724,6 +724,28 @@ static const char *present_note(void) { // ---- the tabs +// One upscaling choice over two settings: NX2NAVI_UPSCALER (how the picture is fitted to the window) and NX2NAVI_DLAA +// (DLSS on). DLSS runs at the game's own render scale (widescreen.c: the scene stays 3/4 of the picture, so DLSS's +// quality modes would all render the same) and fits the picture with bilinear; its model is NVIDIA's own for the +// scale (vk_dlaa.c evaluate, dlss_preset at its default). +static void row_upscaling(void) { + const char *names[3] = {menu_text(UI_MENU_UPSCALER_BILINEAR), menu_text(UI_MENU_UPSCALER_FSR), "NVIDIA DLSS"}; + int cur = cfg_bool("NX2NAVI_DLAA") ? 2 : strcmp(cfg_value("NX2NAVI_UPSCALER"), "fsr") ? 0 : 1; + int nv = opt_choice_index("NX2NAVI_UPSCALER", UI_MENU_UPSCALING, names, 3, cur, 1, UI_MENU_UPSCALING_DESC, + cur == 2 ? menu_text(UI_MENU_UPSCALING_DLSS_NOTE) : nullptr); + if (nv < 0) return; + opt_apply("NX2NAVI_UPSCALER", nv == 1 ? "fsr" : "bilinear"); + opt_apply("NX2NAVI_DLAA", nv == 2 ? "1" : "0"); + if (nv == 2) opt_apply("NX2NAVI_DLSS", "dlaa"); +} + +// The picture's height (widescreen.c picture_height): the game's 1440 or more. +static void row_game_res(void) { + static const char *const values[] = {"1440", "1800", "2160", "2880", "window"}; + const char *names[] = {"1440p", "1800p", "2160p (4K)", "2880p (5K)", menu_text(UI_MENU_GAME_RES_NATIVE)}; + opt_choice_list("NX2NAVI_GAME_RES", UI_MENU_GAME_RES, values, names, 5, UI_MENU_GAME_RES_DESC); +} + static void tab_screen(float scale) { opt_begin("##screen", scale); opt_toggle("NX2NAVI_FULLSCREEN", UI_MENU_FULLSCREEN, UI_MENU_FULLSCREEN_DESC); @@ -741,19 +763,13 @@ static void tab_screen(float scale) { static const UiTextId wide[] = {UI_MENU_GAME_ASPECT_16_9, UI_MENU_GAME_ASPECT_WINDOW, UI_MENU_GAME_ASPECT_21_9, UI_MENU_GAME_ASPECT_32_9}; if (wide_available()) opt_choice("NX2NAVI_GAME_ASPECT", UI_MENU_GAME_ASPECT, wide, 4, UI_MENU_GAME_ASPECT_DESC); - static const UiTextId up[] = {UI_MENU_UPSCALER_FSR, UI_MENU_UPSCALER_BILINEAR}; - opt_choice("NX2NAVI_UPSCALER", UI_MENU_UPSCALER, up, 2, UI_MENU_UPSCALER_DESC); - // RCAS runs only under FSR (vk_fsr.c vk_fsr_record): with bilinear the slider would do nothing - if (strcmp(cfg_value("NX2NAVI_UPSCALER"), "fsr")) opt_disable_next(UI_MENU_SHARPNESS_NEEDS_FSR); + if (wide_available()) row_game_res(); + row_upscaling(); + // RCAS runs only under FSR (vk_fsr.c vk_fsr_record): with bilinear or DLSS the slider would do nothing + if (strcmp(cfg_value("NX2NAVI_UPSCALER"), "fsr") || cfg_bool("NX2NAVI_DLAA")) opt_disable_next(UI_MENU_SHARPNESS_NEEDS_FSR); opt_slider("NX2NAVI_SHARPNESS", UI_MENU_SHARPNESS, 0, 100, UI_MENU_SHARPNESS_DESC, 5, "%.0f %%"); static const UiTextId aspect[] = {UI_MENU_ASPECT_FIT, UI_MENU_ASPECT_STRETCH}; opt_choice("NX2NAVI_ASPECT", UI_MENU_ASPECT, aspect, 2, UI_MENU_ASPECT_DESC); - // DLSS at the game's own resolution (vk_dlaa.c). This build cannot change the scene size (no scene patch set), so - // the quality modes would all render the same: there is no mode row, only the switch and the model. - opt_toggle("NX2NAVI_DLAA", UI_MENU_DLAA, UI_MENU_DLAA_GAME_DESC); - static const UiTextId preset[] = {UI_MENU_DLSS_PRESET_DEFAULT, UI_MENU_DLSS_PRESET_K, UI_MENU_DLSS_PRESET_J}; - if (!cfg_bool("NX2NAVI_DLAA")) opt_disable_next(UI_MENU_DLSS_PRESET_NEEDS_DLAA); - opt_choice("NX2NAVI_DLSS_PRESET", UI_MENU_DLSS_PRESET, preset, 3, UI_MENU_DLSS_PRESET_DESC); opt_end(); } diff --git a/runtime/ui/option_rows.cpp b/runtime/ui/option_rows.cpp index c5fac488..7aaf9384 100644 --- a/runtime/ui/option_rows.cpp +++ b/runtime/ui/option_rows.cpp @@ -342,6 +342,27 @@ bool opt_choice_list(const char *key, UiTextId label, const char *const *values, return true; } +int opt_choice_index(const char *key, UiTextId label, const char *const *names, int n, int cur, int def, UiTextId desc, + const char *note) { + RowView v = {cur >= 0 && cur < n ? names[cur] : "", cur == def, true, note}; + int step = row(key, label, desc, v); + if (!step || n <= 0) return -1; + int nv = cur < 0 ? 0 : step == 2 ? (cur + 1) % n : cur + step < 0 ? 0 : cur + step >= n ? n - 1 : cur + step; + if (nv == cur) return -1; + menu_sound_play(MENU_SOUND_CURSOR); + return nv; +} + +void opt_apply(const char *key, const char *value) { // as apply, without its sound: a row writing several keys + if (*value) { + cfg_set(key, value); + } else { + const char *k = key; + cfg_reset(&k, 1); + } + opt_save_soon(); +} + bool opt_choice(const char *key, UiTextId label, const UiTextId *names, int n, UiTextId desc, const char *note) { enum { MAX = 32 }; const CfgMeta *m = cfg_meta(key); diff --git a/runtime/ui/option_rows.h b/runtime/ui/option_rows.h index 9ca25968..9842f4c2 100644 --- a/runtime/ui/option_rows.h +++ b/runtime/ui/option_rows.h @@ -45,6 +45,12 @@ bool opt_choice(const char *key, UiTextId label, const UiTextId *names, int n, U // unset. cur: the index in effect, -1 to find cfg_value(key) in values (no match: the value shown as it is). bool opt_choice_list(const char *key, UiTextId label, const char *const *values, const char *const *names, int n, UiTextId desc, int cur = -1, const char *note = nullptr); +// A choice whose value is spread over several settings: the caller gives the index in effect and the default's and +// writes the settings itself (opt_apply) when this returns the new index; -1 while unchanged. key: the setting the row +// stands for (its restart mark and the environment check). +int opt_choice_index(const char *key, UiTextId label, const char *const *names, int n, int cur, int def, UiTextId desc, + const char *note = nullptr); +void opt_apply(const char *key, const char *value); // what a row writes: "" unsets the key; saved a moment later // A row that runs an action: true on A or a click. id: unique on the page and not a setting ("##copy_info"); value: // shown on the right ("" none). bool opt_button(const char *id, UiTextId label, UiTextId desc, const char *value = ""); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index d1c10bf9..a12a9174 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -502,11 +502,20 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_CHEAT_UNSUPPORTED_DESC] = "This cheat cannot be used with this version of the game:", [UI_BOOT_TITLE] = "Preparing shaders", [UI_BOOT_HINT] = "This happens once after an update or a graphics driver change.", [UI_BOOT_STARTING] = "Starting", [UI_BOOT_SHADERS] = "Shaders: %lld of %lld", [UI_BOOT_PIPELINES] = "Pipelines: %lld of %lld", - [UI_MENU_DLAA_GAME_DESC] = "NVIDIA DLSS anti-aliasing for the 3D scene at the game's own resolution (NVIDIA RTX GPUs; " - DLSS_FILE " next to the game's .exe). The HUD is not touched. Early version: it works on " - "each frame on its own for now, without the motion history that makes DLSS sharpest. " - "Takes effect after a restart.", - [UI_MENU_DLSS_PRESET_NEEDS_DLAA] = "only with DLSS on", + [UI_MENU_UPSCALING] = "Upscaling", + [UI_MENU_UPSCALING_DESC] = "How the picture is made smooth and fitted to the window. Bilinear: plain scaling. AMD FSR 1: " + "sharper edges and detail when the window is larger than the picture (strength below). " + "NVIDIA DLSS (RTX GPUs; " DLSS_FILE " next to the game's .exe): anti-aliasing of the 3D " + "scene at the game's own render scale, with NVIDIA's newest model for it; the HUD is not " + "touched. DLSS still works on each frame on its own for now, without motion history. " + "Turning DLSS on or off takes effect after a restart.", + [UI_MENU_UPSCALING_DLSS_NOTE] = "DLSS: after restart", + [UI_MENU_GAME_RES] = "Resolution", + [UI_MENU_GAME_RES_DESC] = "The height of the game's picture: 1440p is the game's own; higher draws a sharper picture " + "and its scene in proportion, at a matching cost on the graphics card. Native: the " + "window's height (the monitor's in fullscreen), from 1440 up to 4320. The width follows " + "the widescreen shape. Takes effect after a restart.", + [UI_MENU_GAME_RES_NATIVE] = "Native", [UI_MENU_CHEATS_REBUILD] = "Rebuild the game now", [UI_MENU_CHEATS_REBUILD_DESC] = "Some cheats change the game's code and are not built into it: they are new or " "edited, or their last rebuild failed or was cancelled. Closes the game; the setup " diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 53150189..5a8eb16f 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -241,8 +241,10 @@ typedef enum { // the boot screen while the boot prewarm prepares shaders and pipelines (boot.c, ui/menu.cpp menu_boot_frame) UI_BOOT_TITLE, UI_BOOT_HINT, UI_BOOT_STARTING, UI_BOOT_SHADERS, UI_BOOT_PIPELINES, // printf: "%lld" done, "%lld" total - // the settings menu's DLSS row for this game (ui/menu.cpp tab_screen): DLSS at the game's own resolution - UI_MENU_DLAA_GAME_DESC, UI_MENU_DLSS_PRESET_NEEDS_DLAA, + // the settings menu's Picture rows for this game (ui/menu.cpp tab_screen): one upscaling choice (bilinear, FSR 1 + // or a DLSS mode) and the picture's resolution + UI_MENU_UPSCALING, UI_MENU_UPSCALING_DESC, UI_MENU_UPSCALING_DLSS_NOTE, + UI_MENU_GAME_RES, UI_MENU_GAME_RES_DESC, UI_MENU_GAME_RES_NATIVE, UI_TEXT_COUNT } UiTextId; diff --git a/runtime/widescreen.c b/runtime/widescreen.c index a4ef836b..e8e15df2 100644 --- a/runtime/widescreen.c +++ b/runtime/widescreen.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "cfg.h" @@ -30,42 +31,68 @@ #define GAME_H 1440 #define SCENE_H 1080 +// The window's size, or the monitor's in fullscreen; 0 when unknown. +static int screen_size(int *w, int *h) { + *w = *h = 0; + if (gfx_cfg_fullscreen()) return gfx_window_monitor_size(w, h) && *h > 0; + gfx_cfg_window_size(w, h); + return *h > 0; +} + // The shape the setting asks for as width / height; 0 for the game's own. static double wanted_ratio(void) { const char *s = cfg_value("NX2NAVI_GAME_ASPECT"); if (!strcmp(s, "21:9")) return 64.0 / 27.0; if (!strcmp(s, "32:9")) return 32.0 / 9.0; if (strcmp(s, "window")) return 0; - int w = 0, h = 0; - if (gfx_cfg_fullscreen()) { - if (!gfx_window_monitor_size(&w, &h)) { - rt_log("widescreen: the monitor's size is unknown; the game's own 16:9"); - return 0; - } - } else { - gfx_cfg_window_size(&w, &h); + int w, h; + if (!screen_size(&w, &h)) { + rt_log("widescreen: the screen's size is unknown; the game's own 16:9"); + return 0; } - return h > 0 ? (double)w / h : 0; + return (double)w / h; } +// NX2NAVI_GAME_RES: the picture's height, from the game's 1440 up to 4320 ("window": the window's height, or the +// monitor's in fullscreen). +static unsigned picture_height(void) { + const char *s = cfg_value("NX2NAVI_GAME_RES"); + int w = 0, h = GAME_H; + if (!strcmp(s, "window")) { + if (!screen_size(&w, &h)) h = GAME_H; + } else { + h = atoi(s); + } + return h < GAME_H ? GAME_H : h > 4320 ? 4320 : (unsigned)h; +} + + + void wide_init(void) { int so = rt_patch_set("wide_out"), ss = rt_patch_set("wide_scene"), sa = rt_patch_set("wide_aspect"), sh = rt_patch_set("wide_hud"), sm = rt_patch_set("wide_movie"); - double r = wanted_ratio(), game = (double)GAME_W / GAME_H; + // The scene keeps the game's 3/4 of the picture. Its renderer takes the scene's size from the picture's by that + // share itself: writing another size into wide_scene's constant (main+0x31f3a00) left the light target at 3/4, + // so DLSS's quality modes, which need a smaller scene, have no lever here yet. + double r = wanted_ratio(), game = (double)GAME_W / GAME_H, f = 0.75; + unsigned oh = picture_height(); if (r <= 0 || r < game * 1.01) { - if (r > 0) rt_log("widescreen: a %.4f picture is not wider than 16:9; the game's own 2560x1440", r); - return; + if (r > 0) rt_log("widescreen: a %.4f picture is not wider than 16:9; the game's 16:9", r); + r = game; } + if (r == game && oh == GAME_H && f == 0.75) return; // the game's own sizes: every set stays off if (so < 0 || ss < 0 || sa < 0 || sh < 0 || sm < 0) { rt_log("widescreen: the generated C has no widescreen patch sets (gen.py --patches recomp/patches-v111.txt); " - "the game's own 16:9"); + "the game's own 2560x1440 picture"); return; } if (r > 32.0 / 9.0) r = 32.0 / 9.0; - // Widths in whole multiples of 8 pixels (the scene keeps the game's 3:4 of the picture), heights the game's. - unsigned ow = (unsigned)lround(GAME_H * r / 8) * 8, sw = (unsigned)lround(ow * 3.0 / 4 / 8) * 8; - uint64_t out = (uint64_t)GAME_H << 32 | ow, scene = (uint64_t)SCENE_H << 32 | sw; - float match = 16.0f / 9.0f, ratio = (float)ow / GAME_H, tolerance = 0.01f, squeeze = match / ratio; + // Widths in whole multiples of 8 pixels, the scene's height even: the picture oh high and as wide as its shape, the + // scene 3/4 of both. + unsigned ow = (unsigned)lround(oh * r / 8) * 8, sw = (unsigned)lround(ow * f / 8) * 8; + unsigned sch = (unsigned)lround(oh * f / 2) * 2; + uint64_t out = (uint64_t)oh << 32 | ow, scene = (uint64_t)sch << 32 | sw; + float match = 16.0f / 9.0f, ratio = (float)ow / oh, tolerance = 0.01f, squeeze = match / ratio; float ui[2] = {2.0f / 3840.0f, 2.0f / 2160.0f}, squeeze4[4] = {squeeze, squeeze, squeeze, squeeze}; float margin = (1.0f - squeeze) / 2; // the screens whose UI keeps the whole picture (recomp/patches-v111.txt, set wide_hud): the item-wheel, pause and @@ -88,8 +115,8 @@ void wide_init(void) { rt_patch_switch(sa, 1); rt_patch_switch(sh, 1); rt_patch_switch(sm, 1); - rt_log("widescreen: picture %ux%u, scene %ux%u, camera aspect ratio %.4f (16:9 is %.4f), UI and movies in the " - "middle %.1f%%", ow, GAME_H, sw, SCENE_H, ratio, game, squeeze * 100); + 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 generated C has the widescreen patch sets (the menu shows the row only then).