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
4 changes: 3 additions & 1 deletion dm/games/0400486024DEC000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Measured on an M6 Mac with 16 GB, headless, on one walk with camera turns (`walk
- Current on an M5 Pro MacBook Pro (16-inch, 20-core GPU, 24 GB, macOS 27.2, 2026-11-09), `kokiri-deck` from a deck autosave with the full library of chain `dedc9391c30b`, at full resolution (Dynamic resolution off), two runs a variant: in a window a locked 60 fps (59.8–60.0, frame p99 16.8–19.4 ms, GPU p50 10.2 ms). In fullscreen on its ProMotion screen it held 40 fps (39.6–40.1) at the same GPU time, with every present a 120 Hz refresh late and every other link tick skipped: [The 60 Hz link at 40 fps in fullscreen on a ProMotion screen](../../../docs/reference/frame-rate.md#the-60-hz-link-at-40-fps-in-fullscreen-on-a-promotion-screen). With the 120 Hz link there, 58.8–59.6 fps, frame p99 25.3 ms; with the screen held at its fixed 60 Hz mode, 60.0 fps, frame p99 16.9 ms, which fullscreen now switches to. MetalFX present upscaling to the 3456-wide fullscreen cost no measurable GPU time (59.4–59.7 fps). Resident about 10 GB, GPU allocated 11.2–11.4 GB; the prepare step took 7.3 s on a first start.
- Current: the title and menu, a movie behind them, are a locked 60 fps (p50 16.67 ms, GPU span 15.6 ms).
- Game speed: the game steps its time by a frame ratio, its base rate (60, or 30) / its int frame rate, whatever the frame took (`main+0x6e6cc4` on v131072), so frames longer than a vsync played in slow motion (seen by the user on a slower Mac; [issue 1375](https://github.com/seedds/nxnative/issues/1375)'s M1 Max ran the title at about 28 fps). With `fps_target 60` the ratio is the host's frame step × base / 60 ([A fixed frame step plays in slow motion on a slow Mac](../../../docs/reference/frame-rate.md#a-fixed-frame-step-plays-in-slow-motion-on-a-slow-mac)), a stub placed by its function's fingerprint ([`patches.py`](patches.py)). Mac runs on the M6 (2026-11-08, a test host on the libraries of chain `3ee493b2c3a4`): the user's play sessions held 60 fps with 2- and 3-vsync holds while areas loaded, game time 1.000 of real time by the host's count. That count is the stub's own; no run on a Mac slow enough to show the slow motion before and after.
- Current: movies keep their time down to 30 fps. They are AV1 at 60 pictures a second with no sound track (`Event/Movie/*.webm`; the opening's `Dm_Kokiri_0000` is 9,254 pictures, 154.2 s), and the game's player took one picture a calc at most, so below 60 fps a movie fell behind the sound the game plays beside it: [A player that takes one picture a calc at most falls behind its sound below 60 fps](../../../docs/reference/movies.md#a-player-that-takes-one-picture-a-calc-at-most-falls-behind-its-sound-below-60-fps). On an iPhone Duo the opening took 262 s (35.3 pictures a second at 26-31 ms a frame, one a frame over 9,283 frames), its scenes later and later against the narration; at a 2-vsync hold a movie played at half speed ([issue 1922](https://github.com/seedds/nxnative/issues/1922), and the half-speed cutscenes of [PR #1996](https://github.com/seedds/nxnative/pull/1996)). A cut in [`patches.py`](patches.py) makes the player's limit 2 a calc, its own value for a larger creation argument. Open: the cut is checked under Unicorn (`test_oot_movie.py`) and has not been timed on a device yet.
- Current: walking the village at the game's top internal resolution, 1536x864: a locked 60 fps, mean 16.67 ms over each settled window. Per 2,700 frames: 0-8 frames over 25 ms and 0-2 over 33 ms. Frame p95 17.8-18.9 ms with no window, as the game's own loop moves around its fence wait; in a window p95 17.8 ms, 3 over 25 ms and 5-16 over 18 ms per 600. GPU span p50 16.5 ms, summed GPU 15.8 ms, CPU 6 ms, about 101 passes a frame. The heavy stretch where the village opens (about 1,560 draws) holds 16.65-16.8 ms by lowering its resolution, then returns to full. The main pass used to sit at 763x429 at the same GPU time: [marked shaders tested depth late](../../../docs/reference/frame-rate.md#a-hosts-own-store-in-a-fragment-shader-moves-its-depth-test).
- Before [pool shaders stopped counting as depth readers](../../../docs/reference/rendering.md#pool-shaders-taken-as-depth-readers): passes 118, 104, 219, 224 in a four-frame cycle, frame times 15, 15, 18, 18.5 ms, mean 16.9 ms. Half the frames rendered the reflection probe's faces with one draw a pass.
- The host's GPU figure adds up command buffers, which overlap, so it reads above the real span: 17.5 ms was never a frame's real time. The real span is `@gpu_end_ms − @gpu_beg_ms` in `DM_NVN_TSV`, or the `first start to last end` of `DM_NVN_GPUPROF`.
Expand All @@ -50,7 +51,7 @@ Measured on an M6 Mac with 16 GB, headless, on one walk with camera turns (`walk
- The first long run on a new chain is slower (p50 60–114 ms), while `MTLCompilerService` compiles pipelines; the next run is not.
- [`pso_manifest.tsv`](pso_manifest.tsv) seeds the [prepare step](../../../docs/development.md#the-prepare-step) of a first start: 9,625 rows (8,376 shaders, 1,112 render and 137 compute pipelines) recorded on an M3 Pro Mac (macOS 27.2) with no lists present, over boot, the title and its movie, a new game and the opening, Link's house, Kokiri Forest and a save load ([PR 1493](https://github.com/seedds/nxnative/pull/1493)), and five compute pipelines Saria's greeting builds (Deku Scrub, Business Scrub, Deku Baba), found in [PR 1488](https://github.com/seedds/nxnative/pull/1488). With the list empty, a first start with a cold Metal shader cache showed a black picture with the title music for minutes: one title frame built 11 pipelines and loaded 12 shader libraries in 252.6 s on that Mac ([issue 1477](https://github.com/seedds/nxnative/issues/1477)). Before compute pipelines were in the offline archive, a true first start with the list prepared for 134.7 s on an M4 MacBook Air and then had no frame over 0.25 s to a save load. Open: the first start has not been measured with the archive's compute pipelines, nor on iOS, where this game has no bundled archive (no `pso_mtl4`) and the list is all a first start has; the render bases the `R` rows need are not in the offline archive. A longer list from hours of iPad play (PR 1488, 9,789 rows) prepared 16 s longer on that MacBook and avoided only 7 render builds that made no frame over 100 ms.
- 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.
- The opening cannot be skipped: about 8 minutes on a new file. Its story movie is 154 s of 60 pictures a second (an earlier note here gave it a pace of 24 fps: that was the game's frame rate under the movie network, which the player then showed one picture a frame at).

## Dynamic resolution

Expand Down Expand Up @@ -116,6 +117,7 @@ From an empty save: at about 45 s `A` (title), `A` (New Game), then the movie. F
- [One Pro Controller read as two players](../../../docs/reference/services.md#one-pro-controller-read-as-two-players): resolved, no music in Kokiri Forest gameplay and its cutscenes; the controller applet opened over and over and the game kept its music suspended while it had focus.
- [Compute bindings prepare texture copies before the dispatch encoder](../../../docs/reference/rendering.md#compute-bindings-prepare-texture-copies-before-the-dispatch-encoder): resolved, `DM_NVN_DISPATCH_OWN=1` crashed in the Metal driver (`AGX::ComputeContext::prepareForEnqueue`) during the Kokiri Forest load ([issue #1743](https://github.com/seedds/nxnative/issues/1743)); on an M2 Pro 5 of 5 runs crashed before the fix and 3 of 3 loaded the forest after it.
- [A fixed frame step plays in slow motion on a slow Mac](../../../docs/reference/frame-rate.md#a-fixed-frame-step-plays-in-slow-motion-on-a-slow-mac): the frame-ratio division.
- [A player that takes one picture a calc at most falls behind its sound below 60 fps](../../../docs/reference/movies.md#a-player-that-takes-one-picture-a-calc-at-most-falls-behind-its-sound-below-60-fps): the opening movie's 154 s took 262 s on an iPhone Duo, its sound in time.
- [Frame-step stubs placed by their function](../../../docs/reference/rewriter.md#frame-step-stubs-placed-by-their-function)
- [Repository patches missing under bracketed paths](../../../docs/reference/rewriter.md#repository-patches-missing-under-bracketed-paths): resolved, a build in a folder named with brackets lost this game's frame-step stubs and cuts without an error.
- [Retired pool buffers pile up while a game submits nothing](../../../docs/reference/memory.md#retired-pool-buffers-pile-up-while-a-game-submits-nothing): out of focus GPU allocated went from 11 to 20 GB in 12 s with swap following (PR #1392); the likely cause of a session that stayed frozen after a window switch. Not reproduced on the village-deck route (2026-11-09, M6): 40 s out of focus, during the load or standing on the deck, made no pool deletions at all, so the scene that remakes a virtual pool's runs out of focus is still to be found.
Expand Down
20 changes: 19 additions & 1 deletion dm/games/0400486024DEC000/patches.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 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
# MATCH_FRAME_STEP and MATCH_CUTS as described there ("Registered patches"). Patches of Nintendo SDK module builds are in dm/tools/sdk_patches.py
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 @@ -77,7 +77,25 @@ def dynamic_resolution(ctx):
'dynamic resolution update': {'size': 0xb24, 'fingerprints': ['5a423697838976baf286cffa5e2ceef0d4e037abbcd9d371e90e9e702d61b3d4']}}}, # main+0x805aa0
]}

# Movie pictures. The movies are AV1 at 60 pictures a second (Event/Movie/*.webm, no sound track: the opening's Dm_Kokiri_0000 is 9,254 pictures, 154.2 s). The player's update
# (main+0x3b5ca60, v131072) adds the time object's step (+0x18 × 60, the frame ratio) to a remainder and advances that many picture times, at most the player's limit (+0x20):
# main+0x3b5cb20. Its queue (main+0x3b61ea0) pops that many decoded pictures and shows the last, so the player can skip. The limit is 1 + (the creation argument >= 2)
# (main+0x3b5d068 / +0x3b5d084), and the game passes 1 (main+0x3b5c55c): one picture a calc at most, right at 60 calcs a second and nowhere else. Below 60 fps the movie fell
# behind its sound, which the game's audio plays on its own: on an iPhone at 26-31 ms a frame the opening's 9,254 pictures took 262 s (35 a second), and at a 2-vsync hold a
# movie plays at half speed (issue #1922; the "half-speed cutscenes" of PR #1996, which a frame ratio cannot mend: the ratio was already 2 a frame there). The cut makes the
# limit 2, the player's own value for an argument of 2 or more (its buffers follow it, +0x50), so a movie keeps its time down to 30 fps.
# main+0x3b5cec0, 828 bytes: cinc w8,w28,ge → add w8,w28,#1 at +0x1c4 (w28 = 1; the flags of cmp w27,#2 are not read again)
movie = 'movie pictures: up to 2 a calc'
MATCH_CUTS = {'main': [
{'name': movie, 'size': 828, 'fingerprints': ['f61ad468b6b4e1d574fe8678f5a12dfc60e1aab71be7375142a4b48b0d73ce19'],
'cuts': [(452, '88b79c1a', '88070011', movie + ' (as v131072 main+0x3b5d084)')]},
]}

BINDING = [
{'what': movie, 'now': 'game', 'goal': 'game', 'purpose': 'frame rate',
'why': "the game's own movie player takes one picture a calc at most; function-matched (MATCH_CUTS) on any build that keeps the player's constructor",
'checked': 'v131072 main: one function with this fingerprint; the limit, its two readers, the update that clamps to it and the queue that skips read by disassembly (2026-11-09); '
'the opening movie timed on an iPhone before the cut (9,254 pictures in 262 s for 154 s)'},
{'what': 'frame ratio from the host\'s step', 'now': 'game', 'goal': 'game', 'purpose': 'frame rate',
'why': "the game's own frame-ratio division, found by its function's fingerprint on any build that keeps the function",
'checked': 'v131072 main: one function with this fingerprint, the site and its free registers read by disassembly (2026-11-08)'},
Expand Down
75 changes: 75 additions & 0 deletions dm/tools/tests/test_oot_movie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""Ocarina of Time's movie cut (patches.py MATCH_CUTS): the player's limit of pictures a calc becomes 2.

The player's constructor sets the limit to 1 + (its creation argument >= 2) with cmp w27,#2 … cinc w8,w28,ge (w28 = 1), and the
game passes 1: one picture a calc, so a 60-picture movie fell behind its sound whenever a frame took longer than a vsync. The cut
replaces the cinc with add w8,w28,#1, the limit the player itself takes for a larger argument.
"""
import importlib
import importlib.util
from pathlib import Path
import struct
import sys
import unittest

REPO = Path(__file__).resolve().parents[3]
sys.path.insert(0, str(REPO / 'dm/tools'))

spec = importlib.util.spec_from_file_location('oot_patches', REPO / 'dm/games/0400486024DEC000/patches.py')
assert spec is not None and spec.loader is not None
profile = importlib.util.module_from_spec(spec)
spec.loader.exec_module(profile)


def optional(name):
try:
return importlib.import_module(name)
except ImportError:
return None


capstone, unicorn, arm = optional('capstone'), optional('unicorn'), optional('unicorn.arm64_const')


def rule():
rules = [r for r in profile.MATCH_CUTS['main'] if r['name'] == profile.movie]
assert len(rules) == 1, rules
return rules[0]


def limit(word, argument):
"""The limit the constructor's sequence gives: mov w28,#1; cmp w27,#2; the instruction under test"""
assert unicorn is not None and arm is not None
base = 0x10000
m = unicorn.Uc(unicorn.UC_ARCH_ARM64, unicorn.UC_MODE_ARM)
m.mem_map(base, 0x1000)
m.mem_write(base, struct.pack('<3I', 0x5280003c, 0x71000b7f, word)) # mov w28,#1; cmp w27,#2
m.reg_write(arm.UC_ARM64_REG_X27, argument)
m.emu_start(base, base + 12)
return m.reg_read(arm.UC_ARM64_REG_X8) & 0xffffffff


class MovieCut(unittest.TestCase):
def test_one_instruction_inside_the_function(self):
r = rule()
(offset, old, new, _), = r['cuts']
self.assertEqual((len(bytes.fromhex(old)), len(bytes.fromhex(new))), (4, 4))
self.assertTrue(offset % 4 == 0 and 0 <= offset < r['size'])

@unittest.skipIf(capstone is None, 'optional disassembler: capstone')
def test_the_conditional_increment_becomes_an_add(self):
assert capstone is not None
md = capstone.Cs(capstone.CS_ARCH_ARM64, capstone.CS_MODE_ARM)
(_, old, new, _), = rule()['cuts']
text = [[(i.mnemonic, i.op_str) for i in md.disasm(bytes.fromhex(h), 0)] for h in (old, new)]
self.assertEqual(text, [[('cinc', 'w8, w28, ge')], [('add', 'w8, w28, #1')]])

@unittest.skipIf(unicorn is None or arm is None, 'optional ARM64 execution dependency: unicorn')
def test_the_limit_is_two_whatever_the_argument(self):
(_, old, new, _), = rule()['cuts']
old, new = (struct.unpack('<I', bytes.fromhex(h))[0] for h in (old, new))
self.assertEqual([limit(old, a) for a in (1, 2, 3)], [1, 2, 2]) # the game passes 1
self.assertEqual([limit(new, a) for a in (1, 2, 3)], [2, 2, 2])


if __name__ == '__main__':
unittest.main()
4 changes: 3 additions & 1 deletion docs/agents/game-patches.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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 | 1 | 0 | `game` ×3 |
| [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` |

Expand Down Expand Up @@ -536,9 +536,11 @@ Every patch bound tighter than it could be: the open gaps, then the blocked, kep

[The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md), `0400486024DEC000`, [patches.py](../../dm/games/0400486024DEC000/patches.py).

- **`game`**, frame rate, at goal, checked: v131072 main: one function with this fingerprint; the limit, its two readers, the update that clamps to it and the queue that skips read by disassembly (2026-11-09); the opening movie timed on an iPhone before the cut (9,254 pictures in 262 s for 154 s): movie pictures: up to 2 a calc. The game's own movie player takes one picture a calc at most; function-matched (MATCH_CUTS) on any build that keeps the player's constructor
- **`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)

- **function-matched** (`main` of builds without CUTS): movie pictures: up to 2 a calc: 1 function, 1 cut
- **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

### The Legend of Zelda: Tears of the Kingdom
Expand Down
1 change: 1 addition & 0 deletions docs/agents/symptoms.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ One line per symptom in the [subsystem references](../reference/): what you see
- a movie stays black with the game waiting behind it, the decoder made and no `first picture` line (`Submit…InputBuffer` never called). Or `[RED] nn::codec VP9: Corrupt frame detected`, then `Keyframe / intra-only frame required`, each time about 6 s into a movie or after skipping in one. → [The submission-ready event counted as packets](../reference/movies.md#the-submission-ready-event-counted-as-packets)
- a crash in `nn::codec::video::InitializeAv1DecoderByTransferMemory` when a movie starts. → [AV1 movies through SDK 22's decoder](../reference/movies.md#av1-movies-through-sdk-22s-decoder)
- an abort in `nn::codec` (the SDK's own decoder client, which opens a service the host does not have) when a movie starts in a game built with SDK 19 for the Switch 2. → [SDK 19's decoder forms](../reference/movies.md#sdk-19s-decoder-forms)
- a movie plays in slow motion while its sound keeps time: each scene comes later against the narration, and the sound ends long before the picture. At a 30 fps cap or a 2-vsync hold the movie plays at exactly half speed (issue 1922 on an iPhone; "50s awkward silences between narrator phrases", PR #1996, which took it for the frame ratio). The frame counter shows 30-40 fps and the game's own scenes keep their speed. → [A player that takes one picture a calc at most falls behind its sound below 60 fps](../reference/movies.md#a-player-that-takes-one-picture-a-calc-at-most-falls-behind-its-sound-below-60-fps)

## Audio

Expand Down
Loading
Loading