Skip to content

feat(oot): The Legend of Zelda: Ocarina of Time (Switch 2) on the TotK runtime (experimental) - #1836

Closed
Kolkka wants to merge 12 commits into
ly05010419:mainfrom
Kolkka:feat/oot
Closed

Kolkka wants to merge 12 commits into
ly05010419:mainfrom
Kolkka:feat/oot

Conversation

@Kolkka

@Kolkka Kolkka commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What

The Legend of Zelda: Ocarina of Time (0400486024DEC000, SDK 22.2.8, NVN2 231.40) as a build of games/totk (GAME_OOT + GAME_NS2), like Donkey Kong Bananza and Pokémon Pokopia. build_app.py makes a Mac app from your own dump. No game content is included.

python3 build_app.py <dump folder> --work <work folder> -o "Ocarina of Time.app"

Status on a 16 GB Apple silicon Mac

  • From the packaged app: the title with menu text, and New Game into the opening movie with subtitles, about 60 fps once warmed up.
  • From a development build, same code: a loaded save through Link's house into Kokiri Forest, one session of about 3 minutes with no crash.
  • Frame rate, single runs: 60 fps at the spawn point and the forest view, about 53 fps facing the house's door, about 55 fps on the deck outside (frame p50 17.4 to 17.8 ms). 45 to 60 fps in the 3 minute session.
  • The rest of the world and sessions over 3 minutes are not tested.

Known limits

  • Memory: wired memory peaked at 11.7 GB in that session, against the 12.3 GB limit where the game stops itself (exit 87). Longer sessions may reach it.
  • Picture: a pale haze, cause not confirmed, with no console reference yet. agl's upscaler is bypassed by a plain copy (TOTK_NDSR_BYPASS=0 runs it), so the picture is softer than the console's. CONTRIBUTING.md asks for a correct picture before a fast one: this is a known gap.
  • Banding: visible single-level steps in the fade from black at startup (measured (0,1,0) over 30% of the screen). Whether the console shows them is not known.
  • Game speed: by the host's count only, 0.97 to 1.00 of real time. Link's speed has not been compared with a console. TOTK_GAME_SPEED scales it.
  • Fractional time steps: only played for those minutes; cutscenes and combat are not checked.
  • Draws skipped: shaders that read an image or buffer texture handle from memory.
  • Shaders: 7 of 42,309 do not translate, and 3 of those prepared do not compile on this Mac.
  • Save thumbnail: the autosave's picture in the Load menu is black (seen earlier, not rechecked).
  • First start: the warm-up screen appears for about 30 s. In the test build Metal kept only 24 of 64 sampled shaders from the packaging step.

Main changes

Packaging

  • build_app.py: this game's entry in the Switch 2 table, a dump with no update, optional system fonts (no run has asked for them; a request stops the runtime). ns2_shader_corpus.py reads the game's Zstandard dictionaries (Pack/ZsDic.pack.zs) and Layout2Shader/.
  • games/oot/prebuilt/macos-arm64/totk_xlate (8 MB, from publish_native.sh): this game's own translator. games/totk/prebuilt is unchanged, so other games keep theirs.

Game time

  • The game's step was 60 / the frame-rate controller's fps at main+0x6e6cc4, so below 60 fps it ran slow. It is now the measured frame time, averaged over 5 frames as on Tears of the Kingdom. The same 3 s walk ends in about the same place at 51 fps and at a 30 fps cap (compared by eye). The host caps at 60 fps by its own clock.

Translator (tools/totk_xlate)

  • patches/0009: guarded Ampere deferred writes. Glyph quads had lost their y coordinate, so all menu text was missing.
  • patches/0010: Ampere front end synced from seedds/nxnative (MIT) 339d9f23. Part of this touches shared lowering, not only Ampere.
  • patches/0011: a raw memory access remembers the pool table entry it chose last (after nxnative 0f510fd5).
  • Pools.cs: per-type texture tables, a seen bitmap of what shaders read, [[early_fragment_tests]] where safe. Hmma.cs, MeshStage.cs, patches/0008: HMMA lowering, task and mesh stages.

Host: memory

  • Only pools the driver gave an address in go in the raw pool table; a pool is no longer wired to check it holds a texture (pool_holds). The application pool is 9 GB.
  • Views are made only for textures shaders really read. Same 170 s forest run: Metal peak 12.5 to 10.7 GB. A type view leak of 88 a frame is fixed.

Host: frame rate

  • Passes ordered by the game's barriers (barrier_game), compute dispatches with no barrier between them overlap (after cheemu21/kid-with-sword-remake, MIT), task and mesh draws stay in the open pass (147 to 98 passes a frame).
  • Indirect dispatches and mesh draws run on the GPU without a readback. Pool liveness and type view lookups are cached; the type view sweep runs in slices.
  • Door view, single runs: frame p50 31.5 to 18.3-18.9 ms.

Host: bring-up

  • ZBIC modules, SDK 22 codecs and AV1 through dav1d, audio output, eventfds, RomFS listing and aliases, NVN 231.40, wired_guard_check from games/mkw on for this game only.

docs/ns2-port.md and games/oot/README.md have the details.

For reviewers

  • Layout: CONTRIBUTING.md gives each game its own folder. This follows Bananza and Pokopia in games/totk, as docs/ns2-port.md intends, so it changes shared files.
  • Other games not re-tested: Tears of the Kingdom, Breath of the Wild, Bananza and Pokopia were not run. The type view sweep and leak fix are shared code. Most other host changes are behind GAME_OOT or reached only by Ampere shaders. Bananza and Pokopia now link -ldav1d.
  • GPLv2 build dependency: this game's modules are ZBIC, read with the separate zbic package (Kinnay, GPLv2). build_app.py installs it with pip for this game's build only. It is not in the repository or the app, but please confirm this is acceptable.
  • Version label: 1.0.0 is assumed, as the dump has no update. The game files were not checked for it.
  • Licenses: code taken from seedds/nxnative and cheemu21/kid-with-sword-remake is MIT. No code was copied from GPL projects.

How it was tested

  • build_app.py from a dump folder to a working app: 44 minutes for the last full pass, on a 16 GB Mac. The self-check passed.
  • The app launched from its binary, reaching the title and the opening movie, played through the first part of the game.
  • python -m unittest discover -s tests from a clean checkout of this commit: 1,537 tests, OK (6 skipped). The other CI steps were not run locally.
  • All frame times are one Mac and mostly one run each.

…pp (experimental)

Ocarina of Time (0400486024DEC000, SDK 22.2.8, NVN2 231.40) on the TotK runtime
(GAME_OOT + GAME_NS2). build_app.py makes a Mac app from your own dump; no game
content is included. See games/oot/README.md and docs/ns2-port.md.

- Translator (games/oot/prebuilt, for this game only): Ampere front end from
  seedds/nxnative (MIT), guarded deferred writes, per-type texture tables,
  task and mesh stages, one raw pool lookup per invocation.
- Memory: pools stay unwired, textures made only for IDs shaders really read.
- Frame rate: game barriers, overlapping dispatches, mesh draws in the pass,
  incremental type view sweep, view lookup cache.
- Game time follows the measured frame time at main+0x6e6cc4, 60 fps cap.
- build_app.py: this game's table entry, base-only dumps, optional fonts;
  ns2_shader_corpus.py reads the game's Zstandard dictionaries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017tiHubFpduDtd8tQGw7wEA
@Kolkka
Kolkka marked this pull request as ready for review November 7, 2026 15:02
oxyp1e and others added 2 commits November 7, 2026 21:31
Ocarina of Time's output size (layer render targets and the NVN crop) is
DisplayConfig's base size, written only by setBaseSize at main+0x1087f40.
Two verified veneers redirect it to a host-chosen size: one at
setBaseSize's entry, one in the per-frame cfg update at main+0x6502f8 that
calls setBaseSize when the request changes, so the engine's own resize
path (the one dock/undock uses) re-creates the targets and the 3D scene
follows the output every frame. Both original words are checked, as is
the padding after the frame-step stub and the loader's parameter page.

The Resolution row in the settings panel, the "resolution WxH" input
command and TOTK_OUTPUT_RES now work for Ocarina of Time: 16:9, both
sides multiples of 8, from 640x360 up to the game's own 2560x1440
swapchain. The default stays the shipped 2048x1152 and TOTK_OUTPUT_RES=0
skips the patch. Aspect stays 16:9. TOTK_OOT_DISPLAY_LOG=1 logs request
vs. what setBaseSize was given (off by default).

runtime_output_size_valid is shared by the panel's choices and Custom
input; Bananza's and Pokopia's acceptance rule is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… process

Ocarina of Time opens nn::hid when the ocarina first runs (main+0x329541c ->
sdk+0x10be854). The runtime had no handler for it, so sm answered "service hid
not implemented" and stopped the process.

Input, rumble and motion already reach the game through the SDK hooks in
hid_feedback.c, so the service only answers: every command returns success with
a zeroed reply, which nn::hid::Initialize and its style-set / handle queries
accept. The first 12 commands are logged, so a call that really needs data can
be recognised.

Tested on bd3e70e from a Hateno save, including the ocarina, on an M3 Max
(48 GB): the process no longer stops, and the rest of the session was stable.
@MD5Visual

Copy link
Copy Markdown
Contributor

Follow-up with a fix for a crash found while testing this branch: playing the ocarina stops the process. OoT opens nn::hid when the ocarina first runs (main+0x329541c → sdk+0x10be854), and the runtime has no handler for that service, so sm answers "service hid not implemented" and stops the process.

Opened Kolkka#2: a hid service in games/totk/runtime/hid_feedback.c that answers every command with success and a zeroed reply; input, rumble and motion are unchanged (they still go through the existing SDK hooks). First 12 commands are logged so a call that really needs data can be spotted.

Tested on bd3e70e + that patch on an M3 Max (48 GB): loaded a Hateno save and played the ocarina — no crash. Apart from that, the session was pretty stable (title/menu, opening movie, Hateno gameplay, no other crash). Without the patch the process stops the first time the ocarina opens.

@MD5Visual

MD5Visual commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Another OoT fix from testing, separate from the hid service (Kolkka#2):

The [mesh] [RED] … Fragment input(s) 'user(locn5)' mismatching … flood is a depth-only mesh pass, not the object's colour draw. Those passes have cfmt=0×8, dfmt=0xfc; the program's fragment is still the colour fragment, which reads user(locn5), but the position-only shadow/prepass mesh does not write it, so Metal rejects the whole mesh pipeline every frame. The object's colour pass is a different pair, so the object renders throughout — the failed prepass is the thing that flickers when async shaders skip the draw intermittently.

Fix: use an empty fragment void for mesh pipelines whose pass has no colour attachment (colour passes keep the program's fragment). Runtime-only, no shader retranslation.

PR: Kolkka#3

Tested on M3 Max 48 GB with the Hyrule Castle save: before, 1,878 user(locn5) lines per pair and intermittent shadow flicker; after, zero lines, stable, shadows correct.

Kolkka and others added 4 commits November 8, 2026 08:16
feat(oot): live output resolution up to the game's 2560x1440 swapchain
fix(oot): serve the nn::hid service, so the ocarina does not stop the process
OoT: use a null fragment for depth-only mesh pipelines
From nxnative (seedds/nxnative, MIT), up to 028a2631.

Mesh stage (MeshStage.cs):
- all vertex blocks come before the primitive blocks, with the point size
  ahead of the position and the topology from the control section (3ccb7da0)
- index bytes are reserved for whole primitive blocks, so lanes of a
  max_p 126 mesh no longer write past the stage memory (d365496d)
- position is invariant; mesh libraries compile with preserveInvariance
  (e5f1adee)

Translator (patch 0012, SharedStore.cs):
- LDSM is fenced by subgroup barriers (16776913)
- a pixel shader's depth follows four registers per enabled target (473c9026)
- 64 and 128-bit raw global loads are one vector load (04419bc2)
- shared memory byte and half-word stores are one Metal store (ffebfd59)
- MUFU.SIN/COS, ATOMS.INC/DEC/CAS, ALU carries and modifiers, half pairs and
  directed I2F/F2F rounding as Ampere computes them (b5948342, 1a410e6e,
  b97f0dc6, 9dc81953, 645d3029)

The prebuilt translator is rebuilt and the development shader cache
namespace is bumped. Every shader changes, so the first load after this
freezes while Metal compiles them.

Kokiri Forest from a loaded save, one run each, shaders already built:
48-50 fps with this change, 37-38 fps with the mesh changes alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017tiHucPmA6R8Fqbf1Y85ny
@MD5Visual

Copy link
Copy Markdown
Contributor

Voice acting was missing for a RomFS-path reason, not audio decoding. OoT requests voice lines as content://Voice/Resource//Stream/...; the double slash after Resource left an empty interior component, which romfs_path_valid_relative rejected. Every voice stream open returned not-found, while music and effects (single slash) played normally. Voice/VoiceSettingInfo.Product.111.byml.zs still loaded, which is why the setting looked present.

Fix proposed against feat/oot in Kolkka#4: Kolkka#4

It collapses repeated separators before the RomFS index lookup and adds a Sound/Resource//Stream/... case to probe-fs. Verified in the Goron cutscene: the JPja voice stream now opens and decodes.

@MD5Visual

Copy link
Copy Markdown
Contributor

The other two mesh-replay fixes are now proposed against feat/oot in Kolkka#5: Kolkka#5

  • indirect mesh record mapped as 16 bytes and the first workgroup copied from the record;
  • task/mesh c0 storage-buffer tables at 0x670..0x770 / 0x770..0x870.

One correction from testing: OoT reads the first index from word 1, not NVN2's word 3. Word 3 removed the grass and made distant vertices tear, so the PR defaults to word 1 and keeps the NVN2 {count,0,0,first} layout behind TOTK_MESH_FIRST_NEW=1. Grass and vertex tearing are fixed; the distance-only chunk crosshatch remains separate.

Kolkka and others added 3 commits November 9, 2026 17:48
Conflicts kept from both sides: the Makefile's dav1d flags and input_prompts.m, the type-view drop and image_view release in the texture registry, the pool binding kinds in the reflection, and a new development shader cache name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017tiHucPmA6R8Fqbf1Y85ny
OoT requests voice lines as content://Voice/Resource//Stream/... . The RomFS validator rejected the empty interior component, so every voice stream open returned not-found while music and effects (single slash) worked. Collapse repeated separators before index lookup and cover the Resource//Stream form in probe-fs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017tiHucPmA6R8Fqbf1Y85ny
driver_bank_fill already writes these tables at 0x670 and 0x770. drv_fillable did not know them, so drv_scan logged reads of them as unfilled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017tiHucPmA6R8Fqbf1Y85ny
…ink input prompts

The voice-path fix accepted empty components in romfs_path_valid_relative itself. That broke tests/test_romfs_paths.c (rom:/dir//file is expected to fail) and the add-on content lookup, which did not collapse. The validator is strict again. romfs_path_relative_collapsed collapses repeated separators and then validates, and both RomFS and add-on content requests use it. New test cases cover voice paths, "." and ".." after a double slash, and overflow. docs/audio-troubleshooting.md is updated to match.

The OoT link line needs runtime/input_prompts.m, which origin/main added to the other games' lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017tiHucPmA6R8Fqbf1Y85ny
@Kolkka

Kolkka commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Closing as 33a36ea is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants