diff --git a/dm/games/0400486024DEC000/README.md b/dm/games/0400486024DEC000/README.md index 98e00ecae0..48dd063952 100644 --- a/dm/games/0400486024DEC000/README.md +++ b/dm/games/0400486024DEC000/README.md @@ -52,6 +52,12 @@ Measured on an M6 Mac with 16 GB, headless, on one walk with camera turns (`walk - With a window, the first start on a new chain runs the pipeline prebuild first: 33,190 shader pairs, 691 s on this Mac. A run with no window skips it. - The opening movie runs at the movie's own 24 fps pace during the story section and cannot be skipped: about 8 minutes on a new file. +## Native output + +- The launcher's **Output** (`DM_OUTPUT`, v131072): the game draws its picture into 80 % of the output (`nvnWindowSetCrop`, 2048x1152 of the docked 2560x1440) and the system scales it up, the console's own frame. The 80 % is two multiplies in the game's code (`main+0x6505c4`, `+0x6505d4`; not in `ModelSceneExtensionParam`), and with **Native** stubs there skip them: the crop, the 3D and its depth are the full output size and nothing is scaled. Framing and field of view stay the same. +- Measured (M5 Max, macOS 26.6.2, 2026-11-09, Castle Town market, Link standing, headless, the 300 frames after the scene settled, n=1 each; at 3024x1702 with the 3D's levels at x1.0, both from our own build): the 80 % frame, 3D 2419x1361: frame p50 / p95 16.67 / 17.64 ms, GPU p50 / p95 13.36 / 14.20 ms; native, 3D 3024x1702: 19.47 / 21.29 ms, GPU 17.34 / 18.37 ms, and the market no longer held 60 at that size. A second pair, with the stubs: 16.64 / 17.92 ms, GPU 13.09 / 13.90 ms against 16.54 / 18.53 ms, GPU 14.37 / 15.41 ms. So 1.56 times the pixels cost 1.1 to 1.3 times the GPU; macOS sets the GPU clock per run. The pause menu, speech bubbles and button prompts draw at the full size. +- Not checked: the game's own 2560x1440 output (native makes the crop 2560x1440 instead of 2048x1152), other areas in play, handheld, other builds. + ## Dynamic resolution - The controller (v131072; found by fingerprint, so the addresses are only for reading): the parameters are `game__gfx__DynamicResolutionParam` (`LoadThreshold`, `ReduceCounterMax`, `IncreaseCounterMax`, and a list of levels, each a `ResolutionReduceScale` and a `Priority`). Once a frame the update (`main+0x805aa0`) reads the frame's GPU time, subtracts what its cost model predicts at the current size and keeps the trend of that residual. The level function (`main+0x8065e0`) adds the residual to the model's cost at each level and returns the best level under the threshold: 0, the full 1536x864, when the current size fits. The update moves down after `ReduceCounterMax` frames that ask for it and back up after `IncreaseCounterMax`. Scripted `GPULoad` hints from event data (`main+0x31c3de0`) and `OneshotSetDynamicResolutionLoadThreshold` adjust it in cutscenes. diff --git a/dm/games/0400486024DEC000/patches.py b/dm/games/0400486024DEC000/patches.py index cade577a2e..f57bd17f70 100644 --- a/dm/games/0400486024DEC000/patches.py +++ b/dm/games/0400486024DEC000/patches.py @@ -32,6 +32,7 @@ def frame_step(ctx): emit(0x1e201828); emit(B(here(), site + 4)) # orig: fdiv s8,s1,s0; back fs_put(site, [B(site, start)], 'frame ratio: the host\'s step × base rate / 60 instead of base rate / the game\'s frame rate (state page target fps; 0 = the game\'s ratio)') dynamic_resolution(ctx) + if base == 0x6e6be0: native_output(ctx) # v131072's main (the only build the crop sites are known for) # The game's dynamic resolution (game__gfx__DynamicResolutionParam: LoadThreshold, ReduceCounterMax, IncreaseCounterMax and a list of levels, each a ResolutionReduceScale and a # Priority; on v131072 levels 0..9 at 0.75..0.333 of 2048x1152, 1536x864 to 683x384). Its update (main+0x805aa0) reads the frame's GPU load (about 0.2 ms a unit) into +0x8, subtracts @@ -71,6 +72,25 @@ def dynamic_resolution(ctx): fs_put(site, [B(site, start)], 'dynamic resolution level: 0 (full resolution), or with state +0x40 (DM_DYNAMIC_RESOLUTION) a climb on the load measured at each level') ctx.capabilities.add('DYNAMIC_RESOLUTION') +# Native output (DM_OUTPUT=native, the launcher's Output; v131072 only, guarded by the matched frame-step function's place): the game draws its picture into 80 % of the output +# and the system scales that up, the console's own frame. The crop is set in main+0x650380's function: crop = the base size ([entry+0x64], ints) times a float pair per mode and +# level, 0.8 here, read from [obj+0xf0 + mode * 0x208 + level * 0x60 + (signed byte [obj+0x54a]) * 8 + 0x1e4 / +0x1e8]; each side is clamped to the size from main+0x112c5e0 +# and stored through main+0x1087f40, which main+0x650538 later reads for nvnWindowSetCrop (called from main+0x11e7b74). The 0.8 is in code, not in +# ModelSceneExtensionParam. Found by watching the crop object's size field: one store, 3024x1702 -> 2419x1361, pc main+0x1087f64, lr main+0x650604. +# The stubs skip the two multiplies when state +0x44 is 1, so the crop is the full base size and the picture, the 3D and its depth are the full output size. x16 is free at +# both sites: a call (bl main+0x112c5e0) follows within three instructions and nothing between reads x16 +def native_output(ctx): + here, emit, fs_site, fs_put, ST = ctx.here, ctx.emit, ctx.site, ctx.put, ctx.state + for site, orig in ((0x6505c4, 0x1e200840), (0x6505d4, 0x1e200820)): # fmul s0,s2,s0 (width) / fmul s0,s1,s0 (height) + fs_site(site, orig.to_bytes(4, 'little').hex()) + start = here(); emit(ADRP(16, here(), ST)) + emit(0xb9404610) # ldr w16,[x16,#0x44] 1 = native output + emit(0x35000050) # cbnz w16,+8 skip the multiply + emit(orig) # the original multiply: the game's 80 % + emit(B(here(), site + 4)) + fs_put(site, [B(site, start)], 'native output: the crop multiply skipped when state +0x44 is set (DM_OUTPUT=native), so the picture is the full output size') + ctx.capabilities.add('NATIVE_OUTPUT') + MATCH_FRAME_STEP = {'main': [ {'name': 'frame ratio from the host\'s step', 'size': 0x9b4, 'fingerprints': ['6ae2aff5344d14568e4dbaf93455e2d8278384bf892ed6c6eca87fef98fbcd1d'], 'stub': frame_step, # v131072 main+0x6e6be0 'others': {'dynamic resolution': {'size': 0x294, 'fingerprints': ['7af6ceb0aedf8e0c17dc08ce17fcd6a7cba6d394a0d09e3b504c6d668dc418e7']}, # v131072 main+0x8065e0 @@ -84,4 +104,7 @@ def dynamic_resolution(ctx): {'what': 'dynamic resolution: full size, or a climb on the load measured at each level', 'now': 'game', 'goal': 'game', 'purpose': 'rendering', 'why': "the game's own dynamic-resolution level function and update, found by their functions' fingerprints on any build that keeps both; switchable (DM_DYNAMIC_RESOLUTION)", 'checked': 'v131072 main: one function with each fingerprint (the level function a leaf, x2..x11 / x16 / x17 / s0..s2 free), its callers, the update and the controller fields read by disassembly, the fields read in play (2026-11-08); the climb run natively against a model of the update and in play to full size (2026-11-09)'}, + {'what': 'native output: the window crop\'s two 80 % multiplies skipped (DM_OUTPUT=native)', 'now': 'build', 'goal': 'game', 'purpose': 'rendering', + 'why': "two multiplies in v131072's crop function, placed by address and only when the frame-step function sits at v131072's place; a function-matched rule could carry them to other builds", + 'checked': 'v131072 main: the sites and x16 read by disassembly; the same skip (both multiplies as no-ops) run headless in Castle Town at 3024x1702 and checked for speech bubbles and button prompts (M5 Max, macOS 26.6.2, 2026-11-09)'}, ] diff --git a/dm/games/settings.tsv b/dm/games/settings.tsv index 15f4824107..5a85c20c31 100644 --- a/dm/games/settings.tsv +++ b/dm/games/settings.tsv @@ -17,6 +17,7 @@ DM_FPS_TARGET choice 30=30 fps,60=60 fps,120=120 fps?DM_GAME_FPS_MAX==120&platform:mac DM_GAME_FPS_TARGET DM_GAME_FPS_TARGET!=0 Game Frame rate level=basic DM_DYNAMIC_RESOLUTION toggle - 0 fixups:DYNAMIC_RESOLUTION Game Dynamic resolution Lets the game lower its resolution under load. Turn off to keep full resolution for the selected console mode. DM_RENDER_SCALE range 0.5:1.0:0.05 1.0 fixups:RENDER_SCALE Game Render scale level=basic +DM_OUTPUT choice 0=Game (80 % frame scaled up),native=Native (full size) 0 fixups:NATIVE_OUTPUT Game Output What the game draws into the picture: its own frame, 80 % of the size scaled up as on the console, or the full size, sharper and with more GPU time level=basic DM_OPMODE choice 1=Docked,0=Handheld DM_GAME_OPMODE always Game Console mode level=basic DM_PRESENT_UPSCALE choice off=Standard,metalfx=MetalFX off always Game Upscaling Uses more GPU time and can increase heat. DM_UPSCALER choice game=Game's own,metalfx=MetalFX game DM_GAME_UPSCALER_N!=0 Game Game's upscaler diff --git a/dm/host/loader.c b/dm/host/loader.c index da3a970c9e..d4186d4cdd 100644 --- a/dm/host/loader.c +++ b/dm/host/loader.c @@ -326,6 +326,12 @@ void dm_fps_state_apply(void) { const char *dr = getenv("DM_DYNAMIC_RESOLUTION"); uint32_t dyn = dr && !strcmp(dr, "1"); if (dr && strcmp(dr, "0") && strcmp(dr, "1")) LOG("[RED] DM_DYNAMIC_RESOLUTION=%s: must be 0 or 1; keeping full resolution", dr); memcpy(dm_fps_state + 0x40, &dyn, sizeof dyn); + // Native output, for builds whose stubs read it (the NATIVE_OUTPUT capability: Ocarina of Time v131072's window crop): DM_OUTPUT=native draws the full output size instead + // of the game's 80 % frame scaled up; 0 or unset keeps the game's frame. Builds without such a stub ignore the field + const char *no = getenv("DM_OUTPUT"); uint32_t native = no && !strcmp(no, "native"); + if (no && strcmp(no, "0") && !native) LOG("[RED] DM_OUTPUT=%s: must be 0 or native; keeping the game's frame", no); + else if (native) LOG("%s: output native (DM_OUTPUT): the picture is the full output size", g_fps_mod); + memcpy(dm_fps_state + 0x44, &native, sizeof native); // Screen shape: DM_SCREEN_ASPECT, the screen's width / height between 1.3 and 1.77, makes the builds with screen-shape stubs // (Breath of the Wild 1.9.0's patches.py) render that shape: the output keeps its width (1920) and takes the height that gives the ratio, a multiple of 48 so the // 2/3-size layout space (1280 wide) stays whole: 1.43 → 1920x1344 and 1280x896. State +0x48 u32 output height, +0x4c u32 layout height, +0x50 its float; 0 = 16:9 diff --git a/dm/tools/patch_nso.py b/dm/tools/patch_nso.py index c0594bb86a..b593683ee7 100644 --- a/dm/tools/patch_nso.py +++ b/dm/tools/patch_nso.py @@ -1554,7 +1554,8 @@ def stdalloc_gates(): # runs the original instructions), +4 30 fps movie/cinematic flag, +8 double lead (TOTK), +0x10 float render scale (TOTK, BotW), +0x18 double game seconds (TOTK), # +0x20 u32 step in vsyncs (host; 0 = not decided yet), +0x24 u32 a step the game fixes itself (BotW's VFR override; 0 = none), +0x28 u32 AoC's vsyncs per update, marked by # its first stub (0 = off), +0x30 u64 vsyncs stepped (the stubs; logged by the host to check the game's speed), +0x40 u32 1 = the game's own dynamic resolution runs, 0 = its -# stub holds full resolution (DM_DYNAMIC_RESOLUTION, written by the loader; the stub declares the DYNAMIC_RESOLUTION capability). Stub bodies assembled with clang +# stub holds full resolution (DM_DYNAMIC_RESOLUTION, written by the loader; the stub declares the DYNAMIC_RESOLUTION capability), +0x44 u32 1 = native output, the game's +# frame crop skipped (Ocarina of Time v131072; DM_OUTPUT=native, written by the loader; the stub declares the NATIVE_OUTPUT capability). Stub bodies assembled with clang # A build's stubs are FRAME_STEP[build ID](ctx) in its patches.py: ctx.here() / ctx.emit(word) assemble into the patch area, ctx.site(offset, original bytes) asserts a site and that it is # no rewrite site, ctx.put(offset, words, reason) writes it (listed with the cuts), ctx.state is the state page's offset, ctx.render_scale = 1 marks a render-scale stub, # ctx.others the other functions a MATCH_FRAME_STEP rule names, ctx.address(offset) the data address an adrp there and the add / load / store after it make (in the original diff --git a/docs/agents/game-patches.md b/docs/agents/game-patches.md index 308d350a66..1a1eee40e9 100644 --- a/docs/agents/game-patches.md +++ b/docs/agents/game-patches.md @@ -31,6 +31,7 @@ Every patch bound tighter than it could be: the open gaps, then the blocked, kep | `build` → `game` | interval controller: the lower bound and the GPU-time path | frame rate | gap | judgement | 1 | [The Legend of Zelda: Breath of the Wild](../../dm/games/01007EF00011E000/README.md) | sead::GameFrameworkNx's interval controller in this build; Tears of the Kingdom shares sead but not this code | | `build` → `game` | job pool wake-up | race | gap | judgement | 1 | [FINAL FANTASY TACTICS - The Ivalice Chronicles](../../dm/games/010038B015560000/README.md) | a lost wake-up in the game's own job pool, not a host or SDK difference | | `build` → `game` | malloc region 60 GB → 4 GB and its first arena | address space | gap | judgement | 1 | [Xenoblade Chronicles 3](../../dm/games/010074F013262000/README.md) | Monolith's own allocator; its constants span two functions (a multi-function rule). The cause, an iPhone's address space, is a platform limit | +| `build` → `game` | native output: the window crop's two 80 % multiplies skipped (DM_OUTPUT=native) | rendering | gap | checked: v131072 main: the sites and x16 read by disassembly; the same skip (both multiplies as no-ops) run headless in Castle Town at 3024x1702 and checked for speech bubbles and button prompts (M5 Max, macOS 26.6.2, 2026-11-09) | 1 | [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md) | two multiplies in v131072's crop function, placed by address and only when the frame-step function sits at v131072's place; a function-matched rule could carry them to other builds | | `build` → `game` | PhysX completion task release | race | gap | judgement | 1 | [The Legend of Zelda: Link's Awakening](../../dm/games/01006BB00C6F0000/README.md) | a lifetime race in the game's own completion task (its release slot serves this one vtable) | | `build` → `game` | render intervals, the forced-interval flag and the render-wait timeout | frame rate | gap | judgement | 1 | [Fire Emblem: Three Houses](../../dm/games/010055D009F78000/README.md) | the game's own tables, flag and timeout | | `build` → `game` | task ring push and pop barriers | race | gap | judgement | 1 | [Batman: Arkham Knight](../../dm/games/0100ACD0163D0000/README.md) | a data race in the game's own task ring | @@ -76,7 +77,7 @@ Every patch bound tighter than it could be: the open gaps, then the blocked, kep | [Taiko Risshiden V DX](#taiko-risshiden-v-dx) | 1 | 0 | 0 | 2 | 0 | `game` | | [The Legend of Zelda: Breath of the Wild](#the-legend-of-zelda-breath-of-the-wild) | 7 | 0 | 43 | 0 | 0 | `build` → `game` ×2 | | [The Legend of Zelda: Link's Awakening](#the-legend-of-zelda-links-awakening) | 1 | 0 | 0 | 0 | 0 | `build` → `game` | -| [The Legend of Zelda: Ocarina of Time](#the-legend-of-zelda-ocarina-of-time) | 0 | 0 | 2 | 0 | 0 | `game` ×2 | +| [The Legend of Zelda: Ocarina of Time](#the-legend-of-zelda-ocarina-of-time) | 0 | 0 | 2 | 0 | 0 | `game` ×2, `build` → `game` | | [The Legend of Zelda: Tears of the Kingdom](#the-legend-of-zelda-tears-of-the-kingdom) | 0 | 0 | 9 | 0 | 0 | `game` | | [Xenoblade Chronicles 3](#xenoblade-chronicles-3) | 6 | 0 | 0 | 0 | 0 | `build` → `game` | @@ -538,6 +539,7 @@ Every patch bound tighter than it could be: the open gaps, then the blocked, kep - **`game`**, frame rate, at goal, checked: v131072 main: one function with this fingerprint, the site and its free registers read by disassembly (2026-11-08): frame ratio from the host's step. The game's own frame-ratio division, found by its function's fingerprint on any build that keeps the function - **`game`**, rendering, at goal, checked: v131072 main: one function with each fingerprint (the level function a leaf, x2..x11 / x16 / x17 / s0..s2 free), its callers, the update and the controller fields read by disassembly, the fields read in play (2026-11-08); the climb run natively against a model of the update and in play to full size (2026-11-09): dynamic resolution: full size, or a climb on the load measured at each level. The game's own dynamic-resolution level function and update, found by their functions' fingerprints on any build that keeps both; switchable (DM_DYNAMIC_RESOLUTION) +- **`build` → `game`**, rendering, gap, checked: v131072 main: the sites and x16 read by disassembly; the same skip (both multiplies as no-ops) run headless in Castle Town at 3024x1702 and checked for speech bubbles and button prompts (M5 Max, macOS 26.6.2, 2026-11-09): native output: the window crop's two 80 % multiplies skipped (DM_OUTPUT=native). Two multiplies in v131072's crop function, placed by address and only when the frame-step function sits at v131072's place; a function-matched rule could carry them to other builds - **function-matched frame step** (`main` of builds without FRAME_STEP): frame ratio from the host's step: a function of 0x9b4 bytes, `+0xe4` in it; dynamic resolution, a function of 0x294 bytes, `+0x0` in it; dynamic resolution update, a function of 0xb24 bytes, in it; launcher capabilities: DYNAMIC_RESOLUTION diff --git a/docs/env_switches.tsv b/docs/env_switches.tsv index 6e4fe5a52a..5dc04d9ef3 100644 --- a/docs/env_switches.tsv +++ b/docs/env_switches.tsv @@ -238,6 +238,7 @@ DM_OODLE_JOB path `=`: the host runs the game's own Oodle decoder on e DM_OODLE_MODULES path The rewritten modules the Mac host's Oodle tool mode loads when `shader_split.py` decodes Trinity packs; set by the NSP script DM_OODLE_SERVE switch `=1`: the host answers decode requests on stdin / stdout with the game's own Oodle (or LZ5) decoder from the guest main thread before the SDK starts, until stdin ends DM_OPMODE player The operation mode the game sees: `0` handheld, `1` console (default: the profile's `op_mode`, console unless set); read once at startup +DM_OUTPUT player `native` draws the full output size instead of the game's 80 % frame scaled up, for builds with a native-output stub (the NATIVE_OUTPUT capability: Ocarina of Time v131072); `0` or unset keeps the game's frame DM_PAD_IDENTICAL switch `0` stops reading identical pads here when GameController lists fewer of their model than IOKit has, such as two Pro Controllers over USB (each a player of its own: a Pro Controller from its report 0x30, another model from its HID elements; `pad_hid_mac.h`, `pad_pro.h`); `DM_HID_PADS=0` stops it too; Mac only DM_PAD_MERGE switch `=1` merges every controller into player 1, as before, instead of giving each controller a player of its own (Mac and iOS) DM_PAD_PRESS_TO_JOIN player `1`: a controller is no player until one of its buttons is pressed, then it is the lowest player free, whatever its port, link or model, identical pads included (`front_mac.m`, `DmGamepad.m`, `pad_slots.h`); not with `DM_PAD_MERGE`. Launcher setting diff --git a/docs/settings.md b/docs/settings.md index a826eeeacf..e7b989405e 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -3,7 +3,7 @@ The screen before the game starts shows the settings the game supports. A setting that only matters while another is on appears under it and disappears when that one is turned off. Tap **Play** to start; the app remembers your choices for the next start. All settings are on one scrollable screen, under **Game**, **Controls** and **Performance**. Tap a menu or move a slider there; no settings page needs opening. **Upscaling** is in **Game**, beside **Console mode**. A Mac app shows the same settings in a [window of its own](#the-mac-settings-window). - [Tested defaults](#tested-defaults) -- [Game](#game): [Frame rate](#frame-rate), [Render scale](#render-scale), [Console mode](#console-mode), [Upscaling](#upscaling), [Game's upscaler](#games-upscaler), [Game language](#game-language), [Picture](#picture), [Frame-rate counter](#frame-rate-counter) +- [Game](#game): [Frame rate](#frame-rate), [Render scale](#render-scale), [Output](#output), [Console mode](#console-mode), [Upscaling](#upscaling), [Game's upscaler](#games-upscaler), [Game language](#game-language), [Picture](#picture), [Frame-rate counter](#frame-rate-counter) - [Controls](#controls): [Touch feedback](#touch-feedback), [Game rumble](#game-rumble), [Rumble strength](#rumble-strength), [Rumble cutoff](#rumble-cutoff), [Press a button to join](#press-a-button-to-join) - [Performance](#performance): [Frame buffering](#frame-buffering), [Metal 4 pipelines](#metal-4-pipelines), [Pipeline prebuild](#pipeline-prebuild), [Encode thread](#encode-thread), [Hold frames when late](#hold-frames-when-late), [Performance HUD](#performance-hud), [Reset to tested defaults](#reset-to-tested-defaults) - [The Mac settings window](#the-mac-settings-window): [Display mode](#display-mode) @@ -35,6 +35,10 @@ Off, the default, keeps the 3D picture at full size. On lets the game lower its The size of the 3D picture, from 50 to 100 %. Below 100 % the size is fixed there and the game's own dynamic resolution is off; 100 % keeps the game's own. Lower can be lighter on the GPU but is blurrier; the HUD and text keep their sharpness. Only games the app can scale offer it. +### Output + +What the game draws into the picture, for games the app can change it in (Ocarina of Time v131072): **Game**, the default, its own frame, 80 % of the size scaled up as on the console; **Native**, the full size, sharper and with more GPU time. + ### Console mode **Docked** renders at the Switch's TV resolution, **Handheld** at its lower handheld resolution, which is lighter on the phone and can give a higher frame rate.