From f3ab1b0e765b23df3000fca2e3df62610d5c3f6a Mon Sep 17 00:00:00 2001 From: Wellington Dias Date: Thu, 29 Oct 2026 22:20:59 -0300 Subject: [PATCH] Give the camera and interface the output's shape on 1.2.1, so 16:10 and 21:9 are not stretched. The aspect patch set (recomp/patches-v121.txt) makes the world camera's DefaultAspect parameter default, the two camera-viewport updates that divide a 16:9 rectangle, and the five loads of the 2D canvas size read the patch page. resolution.c writes the output's aspect and the canvas factors there (wider than 16:9 the canvas grows in x, narrower in y) and switches the set on when the game resolution is not 16:9. The sites are those of Fruithapje21's TOTK-Ultrawide 1.2.1 patch (GPL-3.0, read for behaviour); a heap scan of the live projections confirmed the four world cameras take the new aspect. The interface keeps its 16:9 layout in the middle of the canvas: the per-layout edits that move it to the screen's edges are not done. A version without the set (1.4.3 for now) draws the largest 16:9 size inside the wanted one, letterboxed. The Steam Deck profile now draws the screen's own 1280x800, and the menu offers 16:10 and 21:9 game resolutions. --- docs/tester-guide.md | 9 +++++---- recomp/patches-v121.txt | 25 +++++++++++++++++++++++++ runtime/cfg.c | 7 ++++--- runtime/resolution.c | 29 ++++++++++++++++++++++++++++- runtime/ui/menu.cpp | 5 +++-- runtime/ui_text.c | 9 +++++---- totk.ini.example | 7 ++++--- 7 files changed, 74 insertions(+), 17 deletions(-) diff --git a/docs/tester-guide.md b/docs/tester-guide.md index 5d86f628..45e6e9bd 100644 --- a/docs/tester-guide.md +++ b/docs/tester-guide.md @@ -69,16 +69,17 @@ Build or install on Linux ([installer.md](installer.md), "Linux release"), in De mode; for Game Mode, add `totk` from the install folder to Steam as a non-Steam game. The game recognises the Deck (LCD and OLED) and uses its device profile for every setting `totk.ini` does not set: -fullscreen, game resolution 1280x720 letterboxed in the 1280x800 screen, the game's own 3D scale, vsync and a 40 fps -limit. These are starting points, not measurements. What helps most: +fullscreen, the screen's own 1280x800 (16:10: on 1.2.1 the camera and interface take that shape; 1.4.3 draws 1280x720 +with black bars until its aspect patch exists), the game's own 3D scale, vsync and a 40 fps limit. These are starting points, not measurements. What helps most: 1. The performance overlay (F10, or both stick clicks L3 + R3) in full mode: the frame rate, mean and longest frame time over a minute in Lookout Landing, in the Depths and in the Sky, with the settings named. 2. The same with `fps_limit` 30, 45 and 60 and `render_scale` 50, 67 and game, so the defaults can be picked from measurements. Steam's own performance overlay (the ... button) adds power draw and temperatures. 3. LCD or OLED, SteamOS version (`uname -r` in Desktop Mode's terminal), and the game update. -4. Anything that looks stretched or cut off: the game draws 16:9 only, so the profile keeps black bars above and - below; `picture_fit = stretch` fills the screen instead. +4. Anything that looks stretched, squeezed or cut off, with a screenshot: at 16:10 the interface keeps its 16:9 layout + in the middle of the taller screen, and full-screen backgrounds of some menus may not reach the top and bottom + edges yet. `device_profile = desktop` in `totk.ini` turns the profile off; `deck` turns it on elsewhere, to try the Deck's settings on a PC. diff --git a/recomp/patches-v121.txt b/recomp/patches-v121.txt index 64793027..1fddf02e 100644 --- a/recomp/patches-v121.txt +++ b/recomp/patches-v121.txt @@ -9,6 +9,7 @@ set cloth TOTK_CLOTH_REALTIME 1 set bounce TOTK_HIGHFPS_FIX 1 set output TOTK_PATCH_OUTPUT 0 set scene TOTK_PATCH_SCENE 0 +set aspect TOTK_PATCH_ASPECT 0 # 60 fps: the adaptive present-interval controller (main+0x8f26c8, 1.0.0 0x8f6bec) gets the minimum interval 1. site fps60 main 8f273c 6b08015f 7100055f # clamp: cmp w10, #1 (was cmp w10, w8 = minimum) @@ -930,3 +931,27 @@ spin sdk 23a590 23a5d8 # 19 instructions; loads spin sdk 23a658 23a6a0 # 19 instructions; loads spin sdk 23a7fc 23a918 # 19 instructions; loads spin sdk 3d3250 3d3270 # 9 instructions; loads + +# Aspect ratio (runtime/resolution.c aspect_init switches the set on when the game resolution is not 16:9; the sites are those of +# Fruithapje21's TOTK-Ultrawide 1.2.1 patch, GPL-3.0, read for behaviour, the code here our own). The page holds +64 the +# aspect (output width / height), +68 and +72 the factors the 2D canvas size is multiplied by in x and y: wider than +# 16:9, x by aspect / (16/9); narrower (the Steam Deck's 16:10), y by (16/9) / aspect; the other is 1. +# - The world camera reads its aspect from the camera parameter DefaultAspect (main+0x1164a7c reads DefaultFovy, +# DefaultAspect, DefaultOffsetX...), whose default is the float at main+0x3816ab4: the reader takes the page's instead. +site aspect main 1164aa8 d0013588 @page:x8 # adrp x8, 0x3816000 -> adrp x8, page +site aspect main 1164aac 912ad108 91010108 # add x8, x8, #0xab4 -> add x8, x8, #64 +# - Two copies of a camera-viewport update compute aspect = (right - left) / (bottom - top) of a 16:9 rectangle; +# x9 is set to 1 again after the load, so it holds the page meanwhile. +site aspect main 19b36e0 1e223800 @page:x9 # fsub s0, s0, s2 -> adrp x9, page +site aspect main 19b36e8 52800029 bd404120 # mov w9, #1 -> ldr s0, [x9, #64] +site aspect main 19b36f0 1e211800 52800029 # fdiv s0, s0, s1 -> mov w9, #1 +site aspect main 1ecdf58 1e223800 @page:x9 +site aspect main 1ecdf60 52800029 bd404120 +site aspect main 1ecdf68 1e211800 52800029 +# - The size of the 2D canvas the layouts are drawn in, loaded as {width, height} at five places: each load is kept +# and followed by the multiplication, with x9 and s2 saved on the stack around it. +site aspect main 1add300 2d4307a0 2d4307a0 f81f0fe9 bd000be2 @page:x9 bd404522 1e220800 bd404922 1e220821 bd400be2 f84107e9 # ldp s0, s1, [x29, #0x18] +site aspect main 1ae1ae4 2d440680 2d440680 f81f0fe9 bd000be2 @page:x9 bd404522 1e220800 bd404922 1e220821 bd400be2 f84107e9 # ldp s0, s1, [x20, #0x20] +site aspect main 1adc6f8 2d4103e1 2d4103e1 f81f0fe9 bd000be2 @page:x9 bd404522 1e220821 bd404922 1e220800 bd400be2 f84107e9 # ldp s1, s0, [sp, #8] (width in s1) +site aspect main 12c7bd4 2d400500 2d400500 f81f0fe9 bd000be2 @page:x9 bd404522 1e220800 bd404922 1e220821 bd400be2 f84107e9 # ldp s0, s1, [x8] +site aspect main 12c7fbc 2d400500 2d400500 f81f0fe9 bd000be2 @page:x9 bd404522 1e220800 bd404922 1e220821 bd400be2 f84107e9 # ldp s0, s1, [x8] diff --git a/runtime/cfg.c b/runtime/cfg.c index 001e4d33..19b35ecf 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -204,11 +204,12 @@ int cfg_load(const char *path) { // (default: the Steam Deck when the firmware says so), desktop (none) or deck. // // The Steam Deck (LCD Jupiter, OLED Galileo; 1280x800, 16:10, 4 Zen 2 cores, RDNA 2 with 8 CUs sharing 16 GB): the game -// at 1280x720 with its own 5/6 scene, letterboxed in the 16:10 screen (TOTK_PICTURE_FIT) until the game draws 16:10 -// itself; fullscreen and vsync, as gamescope composes Game Mode; 40 fps, which divides 40 Hz (and 120 Hz on the OLED). +// at the screen's 1280x800 with its own 5/6 scene (a version without the aspect patch draws 1280x720, letterboxed, +// resolution.c); fullscreen and vsync, as gamescope composes Game Mode; 40 fps, which divides 40 Hz (and 120 Hz on the +// OLED). // Starting points to replace with measured ones (docs/tester-guide.md, Steam Deck). static const struct { const char *key, *value; } DECK[] = { - {"FULLSCREEN", "1"}, {"WINDOW_SIZE", "1280x800"}, {"OUTPUT_RES", "1280x720"}, {"RENDER_SCALE", "game"}, + {"FULLSCREEN", "1"}, {"WINDOW_SIZE", "1280x800"}, {"OUTPUT_RES", "1280x800"}, {"RENDER_SCALE", "game"}, {"VK_PRESENT", "fifo"}, {"FPS_LIMIT", "40"}, }; static int profile = -1; // 0 none, 1 Steam Deck diff --git a/runtime/resolution.c b/runtime/resolution.c index 2e4b1d7c..0ad73d63 100644 --- a/runtime/resolution.c +++ b/runtime/resolution.c @@ -5,7 +5,8 @@ // MacNativeGames contributors) make the game read both sizes from the patch page, and the texture heap that holds the // output- and scene-sized render targets grows with them. // -// Settings, read at start: TOTK_OUTPUT_RES = x (default 1920x1080, the game's own), TOTK_RENDER_SCALE = the +// Settings, read at start: TOTK_OUTPUT_RES = x (default 1920x1080, the game's own; another shape than 16:9 gets +// a camera and interface canvas of that shape, aspect_init), TOTK_RENDER_SCALE = the // scene's size relative to the output: "game" (default, 5/6, the game's 1600x900 at 1080p) or a percentage; above 100 // the game supersamples its scene, which smooths edges (anti-aliasing) at the cost of GPU time. The game's own final // pass (FSR 1 EASU) scales the scene to the output; the present scales the output to the window (vk_fsr.c). @@ -41,6 +42,7 @@ #define SCENE_H 900 #define DTA_KIB 113664u // DynamicTextureAllocatorMem, shipped #define SCENE_MAX 4096 // per side, as MacNativeGames' TOTK_RENDER_RES +#define ASPECT_EPS 0.002 // an output this close to 16:9 is 16:9 (1366x768 is 1.7786) static struct { int decided; @@ -64,6 +66,16 @@ static void decide(void) { } else { rt_log("resolution: TOTK_OUTPUT_RES=%s is not x in 1280x720..7680x4320; 1920x1080", o); } + // A game version without the aspect set draws 16:9 only: the largest 16:9 size inside the wanted one, which the + // present letterboxes in a window of the wanted shape (TOTK_PICTURE_FIT) + double a = (double)R.ow / R.oh, base = (double)BASE_W / BASE_H; + if (fabs(a - base) >= ASPECT_EPS && rt_patch_set("aspect") < 0) { + unsigned w = R.ow, h = R.oh; + if (a > base) R.ow = (unsigned)(R.oh * base + 0.5) & ~1u; + else R.oh = (unsigned)(R.ow / base + 0.5) & ~1u; + rt_log("resolution: this game version has no aspect patch set: %ux%u draws %ux%u (16:9), letterboxed", w, h, R.ow, + R.oh); + } const char *s = cfg_value("TOTK_RENDER_SCALE"); double k = 5.0 / 6.0; if (strcmp(s, "game")) { @@ -188,6 +200,20 @@ int res_heapdef_build(const void *in, size_t n, void **out, size_t *out_n) { void res_heapdef_served(void) { R.heapdef_ok = 1; } +// ---- aspect ratio: an output of another shape than 16:9 gets a camera and a 2D canvas of its shape (the aspect set, +// recomp/patches-v121.txt). Page +64 the aspect, +68 and +72 the factors of the canvas width and height: wider than 16:9 +// the canvas grows in x, narrower in y, so the 16:9 layouts keep their proportions and sit in the middle of it. +static void aspect_init(uint8_t *page) { + int set = rt_patch_set("aspect"); // decide() kept a version without it at 16:9 + double a = (double)R.ow / R.oh, base = (double)BASE_W / BASE_H; + if (fabs(a - base) < ASPECT_EPS || set < 0) return; + float v[3] = {(float)a, (float)(a > base ? a / base : 1.0), (float)(a < base ? base / a : 1.0)}; + memcpy(page + 64, v, sizeof v); + rt_patch_switch(set, 1); + rt_log("resolution: aspect %.4f (%ux%u): camera and interface canvas follow it (x %.4f, y %.4f)", a, R.ow, R.oh, v[1], + v[2]); +} + // ---- start: the patch page and the sets static uint64_t pack(unsigned w, unsigned h) { return (uint64_t)h << 32 | w; } @@ -218,6 +244,7 @@ void res_init(void) { rt_patch_switch(output, R.ow != BASE_W || R.oh != BASE_H); rt_patch_switch(scene, scene_on); R.on = 1; + aspect_init(page); rt_log("resolution: output %ux%u, scene %ux%u%s; texture heap +%llu KiB", R.ow, R.oh, R.sw, R.sh, scene_on ? "" : " (the game's own 5/6 of the output)", (unsigned long long)res_heap_extra_kib()); } diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 7e86ce74..41280e17 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -412,8 +412,9 @@ static void row_window_size(void) { // The game resolution (resolution.c): 16:9 sizes from the game's own 1920x1080 up, and the current value when it is // another size. static void row_output_res(void) { - // 1280x720: the Steam Deck's (letterboxed in its 1280x800 screen, TOTK_PICTURE_FIT) - static const char *const vals[] = {"1280x720", "1600x900", "1920x1080", "2560x1440", "3200x1800", "3840x2160"}; + // 16:9, 16:10 (the Steam Deck's 1280x800) and 21:9 sizes: the aspect patch gives the game the output's shape + static const char *const vals[] = {"1280x720", "1280x800", "1600x900", "1920x1080", "1920x1200", + "2560x1080", "2560x1440", "3440x1440", "3200x1800", "3840x2160"}; enum { N = sizeof vals / sizeof *vals }; char shown[N][32]; const char *names[N]; diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 4cd7444a..c087aeda 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -51,8 +51,9 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_PERF_LINE_FPS] = "%.0f fps", [UI_MENU_GRAPHICS] = "Picture", [UI_MENU_OUTPUT_RES] = "Game resolution", - [UI_MENU_OUTPUT_RES_DESC] = "The size the game draws its picture and interface in. Above 1920 x 1080 the game needs " - "more video memory and GPU time.", + [UI_MENU_OUTPUT_RES_DESC] = "The size the game draws its picture and interface in. A 16:10 or 21:9 size gives the " + "camera and the interface that shape. Above 1920 x 1080 the game needs more video memory " + "and GPU time.", [UI_MENU_RENDER_SCALE] = "3D render scale", [UI_MENU_RENDER_SCALE_DESC] = "Size of the 3D scene relative to the game resolution; the game's FSR scales it to " "that size. Above 100 % smooths jagged edges (supersampling) at a high GPU cost.", @@ -275,8 +276,8 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_PERF_LINE_FPS] = "%.0f к/с", [UI_MENU_GRAPHICS] = "Изображение", [UI_MENU_OUTPUT_RES] = "Разрешение игры", - [UI_MENU_OUTPUT_RES_DESC] = "Размер, в котором игра рисует картинку и интерфейс. Выше 1920 × 1080 игре нужно больше " - "видеопамяти и времени GPU.", + [UI_MENU_OUTPUT_RES_DESC] = "Размер, в котором игра рисует картинку и интерфейс. Размер 16:10 или 21:9 даёт камере и " + "интерфейсу эту форму. Выше 1920 × 1080 игре нужно больше видеопамяти и времени GPU.", [UI_MENU_RENDER_SCALE] = "Масштаб 3D-отрисовки", [UI_MENU_RENDER_SCALE_DESC] = "Размер 3D-сцены относительно разрешения игры; FSR игры доводит её до этого размера. " "Выше 100 % сглаживает лесенки на краях (суперсэмплинг) ценой большой нагрузки на GPU.", diff --git a/totk.ini.example b/totk.ini.example index f9461e06..cf2fba27 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -95,7 +95,7 @@ [display] # Device profile: auto (the Steam Deck when this is one), desktop or deck. On a Steam Deck the keys this file does not -# set default to fullscreen = 1, window_size = 1280x800, output_res = 1280x720, render_scale = game, vk_present = fifo +# set default to fullscreen = 1, window_size = 1280x800, output_res = 1280x800, render_scale = game, vk_present = fifo # and fps_limit = 40 (starting points, not measured yet). Read at start. # device_profile = auto # Presentation mode: mailbox (default when the driver offers it, vsync otherwise), fifo (vsync) or immediate. @@ -110,8 +110,9 @@ # Which GPU to use: its index in the log, or part of its name. Default: the first discrete GPU with Vulkan 1.3. # gpu_index = 0 # gpu_name = NVIDIA -# Game resolution: the size the game draws its picture and interface in (1280x720 to 7680x4320). Above 1920x1080 the -# game's texture heap and memory pool grow with it. Read at start. +# Game resolution: the size the game draws its picture and interface in (1280x720 to 7680x4320). Another shape than +# 16:9 (1280x800, 2560x1080) gives the camera and the interface that shape (1.2.1; 1.4.3 draws the largest 16:9 size +# inside it, with black bars). Above 1920x1080 the game's texture heap and memory pool grow with it. Read at start. # output_res = 1920x1080 # 3D render scale: the scene's size relative to the game resolution, game (5/6, the game's own 1600x900 at 1080p) or # a percentage (25 to 400, at most 4096 pixels a side); above 100 supersamples the scene (anti-aliasing). Read at start.