Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dm/games/0400486024DEC000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A Switch 2 game: update v131072, SDK 22.2.8 (`Ounce`). Nintendo EPD's engine (se
| `mem_map_limit on` | [`game.tsv`](game.tsv) | a map past the application pool fails with ResultLimitReached, as on Horizon. The SDK's allocator keeps freed pages mapped until a map fails, then gives them back ([PR 1444](https://github.com/seedds/nxnative/pull/1444) reports a black screen leaving the Deku Tree without it; not reached here) |
| `sys_resource 0x3000000` | `game.tsv` | 48 MB, as the NPDM declares |
| Dynamic-resolution stub | [`patches.py`](patches.py) (frame step rule, `others`) | full resolution unless the launcher's Dynamic resolution is on ([Dynamic resolution](#dynamic-resolution)) |
| Wide-screen stubs | [`patches.py`](patches.py) (frame step rule, `others`) | on a Mac screen wider than 16:9 the picture takes the screen's shape unless the launcher's Wide screen is 16:9 ([Wide screen](#wide-screen)) |
| `draw_barriers game` | `game.tsv` | about 180 full barriers a frame NVN does not ask for: GPU 25 → 18 ms at full resolution. From 7f50222 until the fix in [Draw passes that wait for each other again while images share memory](../../../docs/reference/frame-rate.md#draw-passes-that-wait-for-each-other-again-while-images-share-memory) it had no effect, since the dynamic resolution's family heaps turned it off; with the fix, M1 Max gameplay GPU 22.2 → 20.3 ms; no change on an M2 Air or an M4 Pro |
| `tex_flush_upload on`, `tex_dirty_upload on` | `game.tsv` | as Tears of the Kingdom: the CPU writes the terrain tiles' height (R32F), blend and hole (RGBA8) maps into textures after creating them. Without the keys those textures stay zero: flat blue holes in the ground around the path with grass floating in them, and grey stone where the console shows dirt |
| `shader_groups`, `shader_note` | `game.tsv` | shaders grouped as `/Shader/`, `/Effect/`, `/Lib/`, `/UI/` |
Expand Down Expand Up @@ -73,6 +74,14 @@ Measured on an M6 Mac with 16 GB, headless, on one walk with camera turns (`walk
- Where the full-resolution GPU frame goes (M4 Pro, Metal System Trace, 2026-11-08): vertex/mesh 4.9, fragment 5.2, compute 4.3 ms per 1/60 s, and they do not overlap (their union is 14.4 ms, their sum 14.4). The heaviest passes: the main mesh pass (task `a5288d0a6c4971fd`, mesh `3439aaa071d868ae`, fragment `a1a56cf6d62ae798`), two foliage passes (task `47f9b38490dcf9a2`), and the upscaler's compute (`fa3033d05c0a41d6`, 177 HMMA calls, already on `simdgroup` matrices). Ruled out: the stage serialization is mostly the game's own barriers (about 70 a frame, 39 of them `ORDER_PRIMITIVES | INVALIDATE_TEXTURE`). The relaxed draw-pass barriers of `draw_barriers game` were then off whenever an image family heap existed (this game's dynamic-resolution depth buffer makes one). Keeping them on with the alias flush moved to a start barrier skipped 22% of the full barriers, but the real GPU span on this M4 Pro did not change (14.7 ms p50 either way, two runs each). That change is on main now, with fragment-only barriers no longer forcing the full one, for its gain on the M1 Max ([Draw passes that wait for each other again while images share memory](../../../docs/reference/frame-rate.md#draw-passes-that-wait-for-each-other-again-while-images-share-memory)). Also ruled out: mesh shaders writing only the vertices their primitives use (the highest index + 1, instead of all `max_v`), as an overlay of the 31 play mesh shaders against the same shaders recompiled: span 14.7 / 15.5 ms against 16.0 / 15.6, so the game's meshlets are full. A shader timeline needs the trace attached before the pipelines are made, and a recording from 3 s to the play window (9 GB, or 45 s with the shader profiler) never finished saving.
- Measured on the M4 Pro (20-core GPU, 2026-11-08, `kokiri-deck`, one run each): at full resolution (the main passes 1536x864 in pass dumps at 75, 100 and 125 s) 48.1 fps, frame p50 16.74 / p95 33.41 ms, GPU p50 15.0 / p95 16.9 ms: the GPU needs about one vsync a frame, so the frame step holds 2 vsyncs much of the time. With the game's own dynamic resolution and the host fixes above: 60 fps, GPU p50 12.6 ms, at a lower resolution. A second dynamic-resolution run wandered off the route into Saria's dialogue and is not counted.

## Wide screen

- Current: with `DM_SCREEN_WIDE=3440x1440` (launcher setting *Wide screen*, **Match screen** by default on the Mac; offered because the rewrite declares the `SCREEN_WIDE` capability) the game renders a 3440x1440 picture instead of 2560x1440: the swap chain and the composite 3440x1440, the 3D targets 2580x1080 instead of 1920x1080, the scene at 16:9's vertical angle with more at the sides, the HUD at the screen's edges (hearts and item slots in the corners, the minimap bottom right), the menus' panels centred, their text and the items they render in 3D at their 16:9 shape (the menus' 2D pictures are stretched: Open, below). The engine does the layout by itself once its frame buffer is wider; the stubs in [`patches.py`](patches.py) (`screen_wide`, five functions found by fingerprint, all or none) change only what holds 16:9: nnMain's create arg (the swap chain's 2560x1440), the framework constructor's docked and handheld frame buffer sizes, and three camera updates that copy a 16/9 aspect of their own into the view's `sead::PerspectiveProjection` (aspect at +0xb0). With the sizes alone the 16:9 view was stretched over the wide picture. The host side is `loader.c` (state +0xa0 the ratio in 16.16, +0xa4 as a float; `auto`, the default for a build whose fixups table has `SCREEN_WIDE`, asks the front end for the main screen's size), `mtl_present_screen` for the picture's shape, and `front_mac.m` (the screen's size; a window of the picture's shape).
- Checked on an M5 Pro MacBook Pro (48 GB, macOS 27.2, 2026-11-12, headless, a Goron City save): the title, the load menu, the save's first frames and a walk: 3440x1440 screenshots whose centre matches the 16:9 run's pixel for pixel in proportions (Link, the Goron and the pot the same size), the same red lines as at 16:9 (`stage 5 cb3 has no uniform buffer bound`, which 16:9 prints too), GPU about 11-12 ms a frame in Goron City. In a window (`auto`): `the main screen is 3440x1440`, a 1720x720 window, the present's picture shape 3440x1440. With `DM_SCREEN_WIDE` unset or `0` the rewrite runs the original instructions: 2560x1440, as before.
- Open: the UI's 2D pictures are stretched over the wider picture, 1.34 times at 3440x1440: the pause menu's art and slots, the load menu's panels and save pictures, the minimap. Text, glyphs and the items a menu renders in 3D keep their shape. The UI is drawn straight to the swap chain with an orthographic projection of 2/1280 by 2/720 (its uniform block at heap+0x226BD178 on this build, heap offsets being the same from run to run; written through a pool alias, so `DM_PROBE_POLL` sees the writes and `DM_PROBE_WATCH` does not), so its 1280 units span the whole width. The game has no nn::ui2d layouts (no `lyt1` or `pan1` tags), so it is another UI system and Breath of the Wild's layout rules do not apply. Ruled out as the source of the 1280, each set to 1720 with no visible change: the framework's +0xb78 (`main+0x108b698`), the 13-slot create arg (`main+0xf26e48`), the display defaults (`main+0x369a444`), the TV display's virtual size (`main+0x6549d0`, which does change the layers' virtual canvas and five other orthographic matrices to 2/1720), six 1280x720 constants in `main+0x1537d48..0x1539ae0`, and the size-getter classes at `main+0x20ec4a0`.
- Against [PR 1460](https://github.com/seedds/nxnative/pull/1460), which widens the same three sizes at build time (an environment switch of the NSP script's run) together with the output width as a float (`main+0xecbc80`) and the output resolution table (`main+0x3f58540`, its 2560x1440 entry), and no camera: with those two also at 3440 on top of the stubs the pause menu's stretch and the play HUD did not change, so they are not among the stubs; with them and the three camera sites back at the original load, play in Goron City showed the 16:9 view stretched over the wide picture (Link, his shield and the Goron visibly wider), so the cameras are needed there (2026-11-12, words replaced in the rewritten main, one run each).
- Stays 16:9 inside the wide picture: three targets made over and over in play, 2560x1440 (format 0x38), 1920x1080 (0x1) and 960x540 (0xd), created from `main+0x3b6345c`; not identified (the picture shows no 16:9 part). Open: handheld mode (`DM_OPMODE=0`) does not follow: the game crops its picture to 1920x1080 in the wide swap chain while the cameras take the wide ratio (a squeezed 16:9 picture in a corner), since its handheld size comes from somewhere the stubs do not reach (not the framework constructor's 1920x1080 at +0xb70, which the stub widens to no effect), so the loader keeps 16:9 in handheld mode. Not checked: cutscenes and movies (a movie is a 16:9 picture), the Deku Tree, a 32:9 screen, the frame rate against 16:9 on a bench route.

## Memory

- Current: on the walk, run from an external drive with a 3.5 GB pipeline archive: resident 10.9-11.4 GB, wired about 9.4 GB, on a 16 GB Mac. `vmmap` and `footprint`: 6.4 GB of guest memory and 3.8 GB of Metal textures and targets, 1 GB of IOAccelerator memory. [Reading the archive into memory](../../../docs/reference/memory.md#a-pipeline-archive-on-an-external-drive-is-read-into-memory) used to add 3.5 GB (footprint 15.0, peak 16.7). `mem_map_limit on`: a map past the application pool fails as on Horizon, and the SDK's allocator then gives back the pages it keeps. Other apps' memory adds to the swap: other games running beside it can push the Mac over.
Expand Down
71 changes: 70 additions & 1 deletion dm/games/0400486024DEC000/patches.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# The Legend of Zelda: Ocarina of Time (0400486024DEC000): the rewriter's patches of this game's own code. dm/tools/patch_nso.py loads every profile's patches.py;
# MATCH_FRAME_STEP as described there ("Registered patches"). Patches of Nintendo SDK module builds are in dm/tools/sdk_patches.py
import struct
from nso_asm import ADRP, B

# The game's frame ratio. Once a frame the function at main+0x6e6be0 (v131072) divides its base rate (60.0, or 30.0 while bit 0 of [x21+0x24f] is set) by the int frame rate at
Expand Down Expand Up @@ -32,6 +33,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)
screen_wide(ctx)

# 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
Expand Down Expand Up @@ -71,10 +73,74 @@ 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')

# A screen wider than 16:9 (DM_SCREEN_WIDE, loader.c: an ultrawide monitor's 3440x1440). The engine lays its picture out from the size of its frame buffer: given a wider one it
# makes its swap chain, its 3D targets (1920x1080 → 2580x1080) and its composite that wide, and its layouts keep their size and stay at the screen's edges and centre (hearts and
# items at the corners, menus in the middle), all with no further change. Two things hold 16:9 by themselves:
# the sizes. nnMain's create arg (main+0x1202ee0 on v131072: mov x8,#2560; movk x8,#1440,lsl #32; stur x8,[x21,#0x14]) sizes the swap chain, and the framework's constructor
# (main+0x31f39f4: 2560x1440 at +0xb68, the docked frame buffer; main+0x31f3a00: 1920x1080 at +0xb70, the handheld one) the frame buffer the views and layouts follow.
# With only the second widened the game composes 3440 wide and presents the left 2560 of it
# the scene cameras' aspect. Three camera updates copy their own aspect field (+0x140, 16/9 from their parameters) into the view's sead::PerspectiveProjection (near +0x98,
# far +0x9c, fovy +0xa0 and the half angle's sin / cos / tan, aspect +0xb0, offset +0xb4; each store sets the dirty flag at +8): main+0x4c5334, main+0x2e1bb64 and
# main+0x2e1c7c8, all ldr s0,[x19,#0x140]. With the sizes alone the 16:9 view was stretched over the wide picture (Link's hat 1.34 times as wide as at 16:9). The other
# writers of +0xb0 take the viewport's ratio (main+0x28e72a4, main+0x3b50988, main+0x3b50b50 under mIsCalcAspectFromViewport) or another projection's (main+0x653bd4,
# main+0x6545f4) and follow by themselves; main+0x2dd7164 is a fixed 1280x720 or 144x144 view of its own and stays
# The size stubs give the width of the screen's ratio at the site's own height, (height x ratio + 0x8000) >> 16 with the ratio in 16.16 fixed point (state +0xa0; 1440 → 3440,
# 1080 → 2580 for 3440x1440), and the site's original mov when it is 0 (16:9). The camera stubs run the original load and replace an aspect within 0x100 ulps of 16/9 with
# the screen's ratio (state +0xa4, a float; 0 = off), so a camera with a shape of its own keeps it; they use no flags. x16 / x17 are free at every site (none of the five
# functions uses them but main+0x4c48c0, as a temporary at +0xdc..+0xe4, far before its site). The picture keeps the vertical angle and shows more at the sides.
# All five functions are needed (found by fingerprint, as the frame ratio's): with one missing nothing is patched, since sizes without the cameras stretch the picture
_wide_sizes = ( # (function, offset in it, original word, the height the site sets, what)
('wide: nnMain create arg', 0x200, 0xd2814008, 1440, 'swap chain size 2560x1440: the width of the screen\'s ratio'),
('wide: framework constructor', 0x164, 0xd2814008, 1440, 'docked frame buffer 2560x1440: the width of the screen\'s ratio'),
('wide: framework constructor', 0x170, 0xd280f008, 1080, 'handheld frame buffer 1920x1080: the width of the screen\'s ratio'))
_wide_cameras = (('wide: camera update A', 0xa74), ('wide: camera update B', 0x204), ('wide: camera update C', 0x428)) # ldr s0,[x19,#0x140] before the projection's aspect store
def screen_wide(ctx):
here, emit, fs_site, fs_put, FS_STATE_OFF = ctx.here, ctx.emit, ctx.site, ctx.put, ctx.state
fns = {label: ctx.others.get(label) for label in [l for l, *_ in _wide_sizes] + [l for l, _ in _wide_cameras]}
if any(v is None for v in fns.values()): return # not all found in this build (a red line from the locator): the game's own 16:9
for label, off, orig, height, what in _wide_sizes:
site = fns[label] + off
fs_site(site, struct.pack('<I', orig).hex())
start = here(); emit(ADRP(16, here(), FS_STATE_OFF))
for w in (0xb940a210, # ldr w16,[x16,#0xa0] the ratio, 16.16 (0 = 16:9)
0x340000d0, # cbz w16,orig (+6)
0x52800011 | height << 5, # mov w17,#height
0x9bb17e10, # umull x16,w16,w17
0x91402210, # add x16,x16,#0x8000
0xd350fe08): # lsr x8,x16,#16 the width
emit(w)
emit(B(here(), site + 4))
emit(orig); emit(B(here(), site + 4)) # orig: mov x8,#width; back
fs_put(site, [B(site, start)], what + ' (state +0xa0, DM_SCREEN_WIDE; 0 = the game\'s)')
for label, off in _wide_cameras:
site = fns[label] + off
fs_site(site, '604241bd') # ldr s0,[x19,#0x140]
start = here(); emit(0xbd414260) # the original load
emit(ADRP(16, here(), FS_STATE_OFF))
for w in (0xb940a611, # ldr w17,[x16,#0xa4] the ratio as a float (0 = off)
0x34000131, # cbz w17,back (+9)
0x1e260010, # fmov w16,s0
0x5291a731, # mov w17,#0x8d39
0x72a7fc71, # movk w17,#0x3fe3,lsl #16 16/9 (0x3fe38e39) - 0x100
0x4b110210, # sub w16,w16,w17
0x53097e10, # lsr w16,w16,#9
0x35000070): # cbnz w16,back (+3) not within 0x100 of 16/9: the camera's own aspect
emit(w)
emit(ADRP(16, here(), FS_STATE_OFF))
emit(0xbd40a600) # ldr s0,[x16,#0xa4]
emit(B(here(), site + 4))
fs_put(site, [B(site, start)], 'scene camera: a 16:9 aspect becomes the screen\'s ratio in its projection (state +0xa4, DM_SCREEN_WIDE; 0 = the game\'s)')
ctx.capabilities.add('SCREEN_WIDE')

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
'dynamic resolution update': {'size': 0xb24, 'fingerprints': ['5a423697838976baf286cffa5e2ceef0d4e037abbcd9d371e90e9e702d61b3d4']}}}, # main+0x805aa0
'dynamic resolution update': {'size': 0xb24, 'fingerprints': ['5a423697838976baf286cffa5e2ceef0d4e037abbcd9d371e90e9e702d61b3d4']}, # main+0x805aa0
'wide: nnMain create arg': {'size': 0x570, 'fingerprints': ['f2c5558922a471ab585d374cc9293013d48da1562d43169367efdc8ea90a3fe8']}, # main+0x1202ce0
'wide: framework constructor': {'size': 0x273c, 'fingerprints': ['2227b93a9fa9dd0fd9aeb64359649df6e2ade519a8e47fa560f840efcdb5d7e7']}, # main+0x31f3890
'wide: camera update A': {'size': 0x1700, 'fingerprints': ['efc2b7111d6387f88960348730d936b4bec9e6d08a19f67bd33e75d752f61df8']}, # main+0x4c48c0
'wide: camera update B': {'size': 0xa40, 'fingerprints': ['876b8ff1dc66ff0cb867028d9043fc71adbfac31acc093d040644550e37ac770']}, # main+0x2e1b960
'wide: camera update C': {'size': 0x638, 'fingerprints': ['755b131403f6a7d8bb991716f403bb482bbcee61ec0dbf2f04421cc74a749166']}}}, # main+0x2e1c3a0
]}

BINDING = [
Expand All @@ -84,4 +150,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': 'wide screen: the swap chain and frame buffer sizes and the scene cameras\' aspect (DM_SCREEN_WIDE)', 'now': 'game', 'goal': 'game', 'purpose': 'rendering',
'why': "the game's own size constants and camera updates, each found by its function's fingerprint on any build that keeps all five; switchable (DM_SCREEN_WIDE)",
'checked': 'v131072 main: one function with each fingerprint, the sites and x16 / x17 read by disassembly; on an M5 Pro at 3440x1440 the title, the load menu and Goron City rendered 3440x1440 with 2580x1080 3D targets, the HUD at the screen\'s edges and the scene at 16:9\'s proportions with more at the sides (2026-11-12)'},
]
Loading
Loading