Skip to content

nvn/segments: commit inside a long draw pass when the GPU runs dry (OoT −0.15 to −0.3 ms a frame on an M1, slow spot at 30 fps) - #2560

Closed
AdyaGMD wants to merge 1 commit into
seedds:mainfrom
AdyaGMD:cut-when-gpu-runs-dry
Closed

AdyaGMD wants to merge 1 commit into
seedds:mainfrom
AdyaGMD:cut-when-gpu-runs-dry

Conversation

@AdyaGMD

@AdyaGMD AdyaGMD commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

What

sub_cut commits a segment only between passes, at a render-target change. When the GPU ran out of committed work in the middle of a long draw pass, it sat idle until the host had encoded to the pass's end.

With DM_NVN_CUT_DRY (on by default; =0 off, ab for the DM_AB phases), before each draw the host checks two things:

  • nothing is in flight (g_seg_inflight == 0);
  • at least DM_NVN_CUT_DRY_N (default 24) draws were encoded since the last commit.

When both hold, the pass ends and the segment commits there, whatever DM_NVN_CUT's draw count. The draw then reopens the pass, loading its attachments.

It isn't tried while a pass is deferred, merged or hoisted, while the readable-tile check runs, or for geometry-emulation draws: the same states sub_cut already avoids.

Why

A probe at each moment the GPU ran out of committed work (Ocarina of Time, Kokiri Forest, M1) found:

  • about 0.7 ms a frame of idle;
  • never because the game was late: the job had been handed over about 20 ms earlier;
  • 1.5 times a frame, the replay thread was already about 1.1 ms into a job with no commit point yet. OoT's scene passes have 500–800 draws, and the GPU waited about 0.33 ms each time.

A Metal System Trace showed the same thing: one 0.5–1.7 ms gap a frame between fragment and vertex work.

Splitting a full-resolution pass costs about 65 µs on the M1. That was measured by forcing extra splits: +33 passes a frame gave +2.1 ms.

Performance

Ocarina of Time (0400486024DEC000), Kokiri Forest, MacBook M1 (8-core GPU), fullscreen. Measured in a tree with other local changes, including #2526's first-segment cut. Frame p50 per phase:

Run On Off Difference
DM_NVN_CUT_DRY=ab, 300-frame phases 33.33 / 33.31 / 33.45 / 33.36 ms 33.57 / 33.88 / 33.65 / 33.57 ms −0.3 ms
=ab:0/2 (polarity swapped), 450-frame phases 33.35 / 33.32 / 33.31 ms 33.45 / 33.52 / 33.47 ms −0.15 ms

The game paces to 30 fps, so 33.3 ms is its floor; the on-phases sit there. About 2 more passes a frame. With it on, the slow spot holds 30 fps: on-screen frame time p99 is 33.33 ms, against 50 ms before. Screenshots look right.

Switches (in docs/env_switches.tsv)

  • DM_NVN_CUT_DRY=0|1|ab: on by default.
  • DM_NVN_CUT_DRY_N=<draws>: default 24.

Checked

  • The host compiles on this branch. On main, sub_cut has no first-segment or idle rule, so the dry cut forces its commit there (g_cut_dry).

Not run

  • This branch's host in game (it was measured in another tree).
  • Any test suite.
  • iPhone.
  • M3 and later.
  • Other games.

🤖 Generated with Claude Code

…nd commit: Ocarina of Time -0.15 to -0.3 ms a frame on an M1

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) docs Documentation labels Nov 13, 2026
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

Thank you for this, and for the Ocarina of Time probe data. It's closed as a duplicate of #1468, which landed on main as 1831312. Both end a long pass and commit when the GPU runs dry. #1468 caps the splits at 2 per NVN pass. Without a cap, a 24-draw threshold can split a host-bound pass many times: the GPU finishes each short segment and runs dry again. #1468 also keeps DM_NVN_CUT=0 meaning no draw-count commits. Your measurements are cited in docs/reference/frame-rate.md ("A long render pass split while the GPU has nothing") and in Ocarina's note. If you can, an A/B on main with DM_NVN_PASS_SPLIT=0 against the default in Kokiri Forest on your M1 would show whether the 256-draw threshold catches OoT's 500–800-draw passes as well as 24 did.

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.

2 participants