Skip to content

nvn/pass: a long render pass starts on the GPU while it is translated - #1468

Closed
Xipzer wants to merge 1 commit into
seedds:mainfrom
Xipzer:pass-split
Closed

Xipzer wants to merge 1 commit into
seedds:mainfrom
Xipzer:pass-split

Conversation

@Xipzer

@Xipzer Xipzer commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

A long render pass is now handed to the GPU in parts while it is translated, instead of after it is fully translated.

Why. Breath of the Wild draws 2,700 of its 4,100 draws a frame into one G-buffer pass, and its main thread waits on each frame's fence before it starts the next. A render pass could only be cut at its end (sub_cut runs at OP_SET_RT). So the GPU finished the shadow passes before the G-buffer pass and then waited about 2.5 ms for the whole pass to be translated. A Metal System Trace at 120 fps on the Mac shows the GPU busy for 6.3 ms of each 9 ms frame, in one block, with the idle time between frames.

What. At a draw, pass_split_try ends the open pass and commits the segment when:

  • no segment is on the GPU (g_seg_inflight),
  • DM_NVN_PASS_SPLIT draws (default 256, 0 off) were encoded since the last cut,
  • the pass is not merged, ranged, slice-merged, hoisted, deferred or probing (the same exclusions as sub_cut, plus the merge states).

The pass end is rp_end, the path every other mid-pass end (feedback splits, game barriers) takes. Its store lookahead has no index past this point, so it stores every attachment (why=6), and the next draw opens the pass again with loads. In a pass dump the loads show as load cannot be skipped, and no clear is replayed.

Each split costs a store and a load of the attachments, so DM_NVN_PASS_SPLIT_MAX (default 2, 0 no limit) caps the splits per NVN pass, counted by render target changes (g_setrt_n). A pass reopened by a split skips the dispatch-hoist scan (g_split_resume): the pass's first draw already scanned that stretch, and rescanning it from each split cost the submit thread more than the split saved.

Measured on an M4 Max, Breath of the Wild 1.9.0 at 190% (3040x1976) with MetalFX, one spot, frames presented directly (DM_PRESENT_LINK=0), 170 s runs, before this branch's merge with the newer DM_NVN_CUT_BUSY:

DM_NVN_PASS_SPLIT_MAX frame p50 / p90 GPU done after the present (p50)
splits off 8.75 / 9.33 ms 5.09 ms
1 8.36 / 8.74 ms 4.37 ms
2 (default) 8.34 / 8.68 ms 4.03 ms
4 8.34 / 8.64 ms 3.80 ms

8.34 ms is the 120 fps cap. Attachment traffic was within noise across the variants: 4.1-4.4 GB of loads and stores a frame in every one. With DM_NVN_CUT_BUSY on main, sub_cut holds a commit while a segment is in flight. A split only happens with none in flight, so the two do not fight.

Graphics tests pass, except t_nvn, which aborts with the BotW profile on main too and passes with DM_PRESENT_SNAP=0. test_env_switches passes.

@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) docs Documentation labels Nov 6, 2026
@Xipzer

Xipzer commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Note: I couldn't run scripts/regress.py check for this one. This Mac has Xcode 27.1 (Metal 32023.921), and the chain lock on main names 27.2's 32023.922, so the local games' shaders don't build against main's chain here. The measurements come from my integration branch, which carries the same change on a lock for 27.1. If you can run the check on your side, I'd appreciate it.

john62036203-ops added a commit to john62036203-ops/NXNativeWindows that referenced this pull request Nov 6, 2026
…s translated)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013SzykpcKm2eZPvPjGPKx1C
gnosticgeek pushed a commit to gnosticgeek/nxforge that referenced this pull request Nov 6, 2026
# Conflicts:
#	dm/gfx/nvn/nvn_mtl.m
@Xipzer

Xipzer commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (04811a6); no changes besides conflict resolution (the forward declarations next to gmem_commit_patch).

With no segment on the GPU and DM_NVN_PASS_SPLIT draws (256) encoded since the last cut, the open pass is ended
(attachments stored by rp_end as at every other mid-pass end), the segment committed, and the next draw opens the
pass again with loads; at most DM_NVN_PASS_SPLIT_MAX (2) splits a pass. A pass reopened by a split does not run
the dispatch-hoist scan again.
@Xipzer Xipzer changed the title A long render pass starts on the GPU while it is translated (DM_NVN_PASS_SPLIT) nvn/pass: a long render pass starts on the GPU while it is translated Nov 13, 2026
@Xipzer

Xipzer commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (2e6edda), retitled to the area/component form. The only conflict was the forward declarations before mtl_sub_begin.

Checked on this commit (M4 Max): host build, make -C dm/gfx/tests run (every target passes), the settings / docs / switch-table tool tests. The host tests pass except audio-device checks (t_audio's device stall here, t_audio_device on clean main in the same session).

@Xipzer

Xipzer commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Now that this Mac has the chain lock's compiler (Xcode 27.2), scripts/regress.py check on Breath of the Wild 1.9.0, main (2e6edda) against this branch, replacing my earlier note that I could not run it:

regress.py check (full): PASS

Baseline 2e6edda4d334feaf48326407c1718cb96c43e2de 2e6edda, candidate 667c37d3cbab902d3f85693e53d4efd5af24568e 667c37d; Apple M4 Max, macOS 27.2.1, Xcode 27.2; 324.3 s

game status shaders (base → cand) newly failing newly building changed MSL interface (new / known) boot fps p50 frame p99 ms peak MB prepare s new RED
BOTW 01007EF00011E000 PASS 19592/19592 → 19592/19592 0 0 0 0 / 0 ok 59.7 → 59.8 18.13 → 17.15 3236 → 3199 0.21 → 0.05 0

BOTW 01007EF00011E000: PASS

  • screenshots (s: dHash bits / RGB diff / baseline noise): 60: 12/3.88/0, 80: 9/3.63/0
  • baseline: exit None, first frame 2.4 s, max frame 5928, reached True, prepare 0.21 s, prebuild 203.7 s (15767 built, 0 failed), fps 59.7, p50/p99 16.67/18.13 ms, peak 3236 MB
  • candidate: exit None, first frame 2.1 s, max frame 6230, reached True, prepare 0.05 s, prebuild 168.7 s (15767 built, 0 failed), fps 59.8, p50/p99 16.67/17.15 ms, peak 3199 MB
  • time: chain 44.5 s, smoke 279.6 s

The route's save is my own outdoors save, not the one smoke.tsv was written with. The split is on by default (256 draws), so the route runs it.

seedds added a commit that referenced this pull request Nov 14, 2026
A segment could be committed only between passes, so a long pass reached the GPU at its end: Breath of the Wild draws 2,700 of its 4,100 draws a frame into one G-buffer pass, and the GPU, done with the shadow passes, waited about 2.5 ms of a 9 ms frame for it. At a draw, with nothing committed still on the GPU, DM_NVN_PASS_SPLIT draws (default 256, 0 off) since the last cut and a cut that will commit, the pass is ended, the segment committed, and the next draw opens the pass again with loads; at most DM_NVN_PASS_SPLIT_MAX (default 2) splits per NVN pass. The author measured BotW on an M4 Max at 120 fps: frame p50 / p90 8.75 / 9.33 -> 8.34 / 8.68 ms.

Beside the pull request: the split ends a pass only when sub_cut will commit after it (sub_cut_ready, shared with sub_cut; before, DM_NVN_CUT=0 or a cut above 256 draws stored and loaded the attachments for nothing); the split's pass end always stores its attachments (the store lookahead skips the rest of the pass and could leave unstored one the reopened pass loads, with DM_NVN_TBDR=1); the resume flag that skips the dispatch-hoist scan is cleared at each target change; the readable-tile check redraw is not split.

Checked on an M4 Pro: regress.py check on BotW and OCTOPATH TRAVELER II, shaders unchanged, no new RED lines, screenshots match. BotW's run-to-run noise (GPU 6-12 ms a frame on identical code, including a split-off control) is larger than the change; a second split-on run matched main (GPU 8.4 vs 8.8 ms). Graphics tests pass except t_present_rescue's 2 present-link checks, which fail on main too. Not run: iPhone, Ocarina of Time (the case of PR #2560, which this supersedes).

Co-authored-by: Xipzer <60103178+Xipzer@users.noreply.github.com>
@seedds

seedds commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Landed on main as 1831312, with you as co-author. Thank you.

Changes beside yours:

  • The split ends a pass only when sub_cut will commit after it (sub_cut_ready, now shared with sub_cut). Before, DM_NVN_CUT=0 or a cut above 256 draws stored and loaded the attachments without committing anything.
  • The split's pass end always stores its attachments. With DM_NVN_TBDR=1, the store lookahead skips the rest of the pass (its draws set no target), so it could find a later clear and leave unstored an attachment the reopened pass loads.
  • g_split_resume is cleared at each target change, so a draw that returns early cannot skip another pass's dispatch-hoist scan.
  • The readable-tile check redraw (g_fz_checking) is not split.
  • A reference entry: docs/reference/frame-rate.md, "A long render pass split while the GPU has nothing".

Checked on an M4 Pro with regress.py check on BotW and OCTOPATH TRAVELER II: shaders unchanged, no new RED lines, screenshots match. BotW's run-to-run noise at 60 fps (GPU 6–12 ms a frame on identical code, including a split-off control) is larger than the change, so your M4 Max numbers remain the measurement. Not run on an iPhone.

@lunks

lunks commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Checked 1831312 (DM_NVN_PASS_SPLIT, default 256) on Ocarina of Time (Switch 2), M5 Pro 24 GB, Hyrule Field, same host, 4 boots per setting, alternated: neutral. Frame p99 19.86 ms with the split vs 19.89 without, GPU p50 10.70 vs 10.61 ms. It rarely fires there: the GPU is seldom idle when a pass reaches 256 draws. No objection to the default. Thanks for taking it.

Kayyluhh pushed a commit to Kayyluhh/nxnative that referenced this pull request Nov 15, 2026
… its parts not on main): a larger store-witness set, cached uniform-conflict and vertex-stream checks, cached mesh lookups, doubling queue buffers and the GPU clock keeper

(cherry picked from commit ac10683) Main has the rest in its own form: the pool lookup's last hit, uniform-only argument patches (args_cbuf_only) and long-pass splits (seedds#1468, pass_split_try); those hunks keep main's code and seedds#1847's split is left out.
Kayyluhh added a commit to Kayyluhh/nxnative that referenced this pull request Nov 15, 2026
…release, a GPU clock keeper on the Mac, and translation caches for heavy NVN frames

From regress/pr1847-host: seedds#1847's cbce3d5, its ac10683 without what main has in its own form (the pool lookup's last hit, uniform-only argument patches, long-pass splits from seedds#1468), 03d2598 and ca08664. Its docs come with it: the DM_GPU_KEEP, DM_GPU_KEEP_MS and DM_NVN_ACQ_FENCE rows and five frame-rate.md entries (the uniform-conflict one rewritten for main's patching), linked from Donkey Kong Bananza's note. Played on the Mac on two games by the batch owner; regress.py not run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants