Skip to content

A vertex library with layer entry points of its own gets bases for its main0 pairs: Ocarina of Time's 230 ms camera-turn hitch in Hyrule Field goes to 39 ms - #2065

Closed
Raymon82777 wants to merge 1 commit into
seedds:mainfrom
Raymon82777:oot-layer-entry-bases

Conversation

@Raymon82777

Copy link
Copy Markdown
Contributor

What

A vertex library with layer entry points of its own (entry_layer in its reflection, main0_l) writes render_target_array_index only in those entries; its main0 writes none. The shader loader already takes the layer from the entry it uses (shader_load, layer_out). The offline archive (pso_offline.py, writes_layer) and the device prebuild (pre_desc) instead looked for the layer anywhere in the library, so every pair of such a shader was left out of both.

Ocarina of Time's effect vertex shaders are such libraries and have no stage inputs, so no stand-in pipeline either: each pair was compiled at its first draw while the frame waited (34-74 ms per pipeline). Both places now follow the loader's rule. A library without layer entry points whose code writes the layer is still left out.

No shader or chain change; the pipeline archive is rebuilt. A host with this fix and an archive built before it finds bases the archive lacks, distrusts it, and builds the prebuild on the device in the background, as for any incomplete archive.

Measured

Ocarina of Time v131072, Apple M6 (applegpu_g18g), macOS 27.2, bench.py route field-run (added here: a Hyrule Field save, camera turn at about 105 s), two runs each, DM_PSO_WAITLOG=1:

archive bases worst frame pipeline waits > 20 ms
before (host and archive without the fix) 30,690 230.3 / 234.1 ms 4 / 4
after 33,365 (+2,675) 38.8 / 39.6 ms 0 / 0

The stall at the camera turn (210-214 ms at 105.5 s, and a 50 ms frame after it) is gone. A 39 ms frame at about 117 s remains (one pipeline of 15-20 ms, under the wait log's threshold), recorded as open in the reference entry. Measured on a branch with an earlier main; the change applied here unmodified.

Checks

  • dm/tools/tests/test_pso_offline.py: a library with entry_layer gets its main0 base (with test_docs.py: 51 tests, OK).
  • t_pso_bundle: the prebuild gives such a library's main0 a base, and a library whose main0 writes the layer gets none (71 checks, 0 failed).
  • scripts/regress.py check --games 0400486024DEC000,01006A800016E000 against 04811a63: PASS on both (Ocarina 42,848/42,848 shaders, Smash 35,012/35,012; 0 newly failing, 0 changed MSL, interface 0 new / 0 known). Neither game has a smoke.tsv here, so this run is the static part only; the runtime evidence is the bench above.
  • Games: the change reaches only vertex libraries with layer entry points. Counted in the local builds: Ocarina 4,539, Smash 463, Mario Kart 8 Deluxe 2, Breath of the Wild 2, Rhythm Heaven Groove 0. Checked the two it reaches; the disk on this Mac could not hold full chain builds of the others.

Docs

docs/reference/shaders.md "Vertex shaders with layer entry points left out of the prebuild", the Ocarina note's "Found on this game", the symptom index, and the field-run / field-still bench routes.

🤖 Generated with Claude Code

…s main0 pairs: pso_offline.py and the host prebuild looked for render_target_array_index anywhere in the library, not in the entry the pair uses, as the shader loader does, so Ocarina of Time's effect vertex shaders (no stage inputs, no stand-in) were compiled at their first draw: a 230 ms frame at a camera turn in Hyrule Field, 39 ms after (M6, 2,675 more bases)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) tools Tools and scripts (dm/tools, scripts) docs Documentation game: 0400486024DEC000 A game labels Nov 9, 2026
FeReuss pushed a commit to FeReuss/nxnative-oot that referenced this pull request Nov 10, 2026
…ayer entry points of its own gets bases for its main0 pairs: Ocarina of Time's 230 ms camera-turn hitch in Hyrule Field goes to

kept both sides of dm/games/0400486024DEC000/README.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@akratch

akratch commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

I reviewed this against an independent local audit that found the same library-wide layer detection gap. The host/offline planner change also passes our complete graphics suite on a local OOT integration, with unchanged shader outputs; that integration result is supporting evidence, not an exact-branch gameplay measurement of this PR.

I prepared a small test-only follow-up on your exact 425ad34f6672 head:
akratch@899cdea1

It makes the negative control actually write render_target_array_index from main0 (the current vw is another copy of the mixed-entry library), checks main0 and main0_z, actually compiles both accepted bases, and fails if the new fixture libraries fail to compile rather than silently skipping those checks.

On Apple M4 Max / macOS 27.2 / Xcode 27.2:

  • t_pso_bundle: 77 checks, 0 failed on the exact PR head plus that test-only commit.
  • Restoring only the old host condition (if (!vl || t_lib_layer)) gives 6 failures out of 77; restoring your fix passes again.
  • Focused LLVM 23.1.5 clang-tidy ratchet: zero new findings.

Feel free to cherry-pick the test commit. No game files, extracted shaders, saves or private diagnostic captures are included. No other-game or iOS execution is claimed.

seedds added a commit that referenced this pull request Nov 10, 2026
…out), and the host and pso_offline.py read nothing else for it: a library with layer entry points of its own gets bases for its main0 pairs, and Ocarina of Time's 230 ms camera-turn hitch in Hyrule Field goes to 39 ms (PR #2065); chain d403eb0683df

Three places guessed the layer from the library's bytes (render_target_array_index anywhere
in the file), each in its own way. shader_load excepted a library with layer entry points
(entry_layer, main0_l: they alone write the layer, main0 writes none); pre_desc and
pso_offline.py did not, and left every pair of such a shader out of the device prebuild and
the bundled archive. Ocarina of Time's effect vertex shaders have no stage inputs and so no
stand-in: each pair was compiled at its first draw (34-74 ms per pipeline).

dmsh_build.py layer_out: main0's output writes render_target_array_index. The vertex
reflection and the geometry output reader's (<key>_bgv) carry "layer_out": true then;
layer entry points do not count. shader_load, pre_desc and pso_offline.py plan read it;
t_lib_layer, its two byte scans and pso_offline's LAYER scan go. So do the two retries
that rebuilt a pipeline after Metal refused it naming render_target_array_index (the draw
and the background prewarm, Pokémon Legends: Z-A's layered full-screen passes): they stood
in for the fact the reflection did not hold.

Measured by the PR on its form of the rule (same bases): Ocarina v131072, M6, field-run,
two runs each: archive bases 30,690 -> 33,365, worst frame 230.3 / 234.1 ms -> 38.8 /
39.6 ms, pipeline waits over 20 ms 4 / 4 -> 0 / 0. Not re-measured on this form.

Checks: test_dmsh_layer_out.py (new), test_pso_offline.py, test_docs.py and the other
tool tests (106 OK); t_pso_bundle 71, t_pso_warm 123, t_pso_archive 230, t_geometry 1,929
checks, 0 failed; lint_c tidy: nothing above the baseline.
Regression: not run on this form (skipped by choice). The PR's regress check of its form
passed on Ocarina and Smash (all shaders built, 0 changed MSL, interface clean). Octopath
Traveler II (198 shaders with layer entry points, 29 geometry readers) and Z-A (the retries'
case) are the games to check on this chain.

Co-authored-by: Ray McDonald <54215218+Raymon82777@users.noreply.github.com>
@seedds

seedds commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks: the diagnosis and the measurements were right, and they landed in 5e1c1ae (with you as co-author), in a different form.

Instead of a third copy of the loader's rule, whether a vertex shader writes the layer is now in its reflection: dmsh_build.py sets "layer_out": true when main0's output writes render_target_array_index (also on the geometry output reader <key>_bgv); layer entry points do not count. shader_load, pre_desc and pso_offline.py read that and nothing else, so they cannot drift apart again:

  • t_lib_layer and the byte scans in lib_from_file_ and pso_offline.py (LAYER, writes_layer) are gone.
  • So are the two retries that rebuilt a pipeline after Metal refused it naming render_target_array_index (the draw and the background prewarm), which stood in for the missing fact.
  • It is a chain change: d403eb0683df.

Your bench routes, the reference entry (rewritten for the new fix), the Ocarina note line and the test cases are kept; test_dmsh_layer_out.py is new. Tool tests, t_pso_bundle (71), t_pso_warm (123), t_pso_archive (230) and t_geometry (1,929) pass.

Not re-measured on this form: the bases should be the same as with your rule, but if you rebuild Ocarina on the new chain, a field-run on it would confirm the 39 ms. No regress was run on this form; Octopath Traveler II (198 shaders with layer entry points) and Pokémon Legends: Z-A (the retries' case) are the games worth a check.

@seedds seedds closed this Nov 10, 2026
FeReuss pushed a commit to FeReuss/nxnative-oot that referenced this pull request Nov 10, 2026
…ed commit, which the next merge brings

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
FeReuss pushed a commit to FeReuss/nxnative-oot that referenced this pull request Nov 10, 2026
Conflicts resolved by hand:
- seedds#2085, seedds#2078 and seedds#2065 came back from upstream as reworked commits (6f50de0, 12a44e0, 5e1c1ae): our three merges were reverted first, so the merge brings upstream's version instead of two copies.
- GPU copies into a texture (copy_b2t, mirror_rb_land, nvn_obj.h): upstream's seedds#1310 rework (mspan_t, pkg_copy_absorb, for the readback case) and our seedds#2077 (mirror_rb_own, gsb_mark, for a texture the GPU owns) cover different cases and both stay: own = !rb is taken before the synchronous mirror, so the two paths exclude each other. mirror_rb_own passes no span.
- loader.c: upstream's render-scale parse with the stub's largest scale (Hades II) and our graphics-scale tier block. t_readback.m: upstream's additive tests added to ours. pso_offline.py: its header comment. Docs and tables keep both sides; DM_RENDER_SCALE rows, render_base and the settings table take upstream's Hades II range plus our text.
- dmsh_chain.h regenerated; .github/workflows/tests.yml follows upstream (a test list).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Fasen24-AI added a commit to Fasen24-AI/swordboiMacNative that referenced this pull request Nov 10, 2026
seedds#1901 seedds#1459 seedds#1928 seedds#1942 seedds#1940 seedds#1952 seedds#1611 seedds#2065 seedds#2083 seedds#2008 seedds#2079 seedds#2022 seedds#2075 seedds#2077 seedds#2020 seedds#2021 onto main 04811a6

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014eD437mxrMnW2UwLZhpwc7

Upstream pull requests applied in this commit (their authors' work, brought onto this tree with a three-way merge; the description is in each PR):
- seedds#1459 by PromethOps (open): DM_UPSCALER=metalfx takes agl's agl_ndsr_vr.pck networks too, and a variant with no curve and no power is drawn as one colour space: Ocarina of Time's upscaler is MetalFX's
- seedds#1611 by Esteban-V (open): An argument block whose only change is a uniform buffer is patched instead of encoded again
- seedds#1774 by uncraftablexd (closed): Compute threads that exit before a barrier keep arriving at it, and every shader loop has a cap (GPU hang defences), chain change
- seedds#1824 by cocoman93 (open): Clamp texel fetches past a sampled 2D texture's edge: no hard edge in Ocarina of Time's mist
- seedds#1901 by FifteenPen (open): The game's compute dispatches with no game barrier between them run side by side (profile key dispatch_overlap, on for Ocarina of Time): Kokiri Forest GPU p50 15.63 → 14.76 ms
- seedds#1928 by FeReuss (open): Ocarina of Time: enc_thread on, the replay encodes on a thread of its own
- seedds#1929 by FeReuss (open): Unused border corrections are compiled out of pipelines that bind no sampler with a twin (function constant DMSH_BORDER_FC)
- seedds#1930 by FeReuss (open): A float add to storage memory with no result read is one native atomic add instead of a compare-and-swap loop
- seedds#1940 by uncraftablexd (open): A prewarm list's lines after its #@after_first_frame line are built after the first frame, in the background, instead of in the prepare step (issue seedds#1747)
- seedds#1942 by uncraftablexd (open): Frame step: late frames with the GPU idle do not step up, and a longer hold the GPU does not explain is probed
- seedds#1952 by AdyaGMD (open): Compute moves ahead of scene passes past occlusion queries and conditional rendering; clears wait across dispatches
- seedds#2008 by bquilty25 (open): nvn: reactive memory watchdog, 16-way view cache, and texture upload batching
- seedds#2020 by padsiwono (open): Ocarina of Time v131072: Output Native draws the full output size instead of the game's 80 % frame (`DM_OUTPUT`)
- seedds#2021 by padsiwono (open): Ocarina of Time v131072 renders at the launcher's Resolution (`DM_RENDER_SIZE`), docked
- seedds#2022 by sleepyeyedjoe (closed): Ocarina of Time: large models no longer go black for one frame twice, 4–5 frames apart, when the game streams new textures into them (a texture ID a shader has read keeps its read mark when it gets another texture)
- seedds#2030 by humanperzeus (open): A NaN colour at alpha 0 is returned as 0, as NVIDIA's blender takes a zero factor: Ocarina of Time's white clouds over the ferns are gone
- seedds#2035 by Know-It-All-Brother (open): The shader build runs as worker processes, and no shader waits for a batch (Ocarina of Time's cold Mac map: 3,002 s to 1,298 s)
- seedds#2065 by Raymon82777 (closed): A vertex library with layer entry points of its own gets bases for its main0 pairs: Ocarina of Time's 230 ms camera-turn hitch in Hyrule Field goes to 39 ms
- seedds#2075 by sleepyeyedjoe (closed): Ocarina of Time: a patch of scenery no longer draws dark for one frame when the game gives it a sharper texture (a pool texture the walk does not make holds a stand-in of its own colours until its first read)
- seedds#2077 by roandegraaf (closed): Ocarina of Time: fix the "plaid" terrain / missing texture tiles (GPU-drawn textures now reach the storage the game copies)
- seedds#2079 by uncraftablexd (open): Render pipelines that share a vertex function are taken from the archive or compiled one at a time: the AGX driver crashes in createVertexProgramVariant's completion block
- seedds#2083 by FifteenPen (closed): Ocarina of Time's prewarm list gets 41 more task / mesh pipelines from later play
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation game: 0400486024DEC000 A game nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants