Skip to content

nvn/submit: commit a submission's first segment after 8 draws even while earlier work runs (OoT −0.85 ms a frame on an M1) - #2526

Open
AdyaGMD wants to merge 1 commit into
seedds:mainfrom
AdyaGMD:early-first-segment
Open

AdyaGMD wants to merge 1 commit into
seedds:mainfrom
AdyaGMD:early-first-segment

Conversation

@AdyaGMD

@AdyaGMD AdyaGMD commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

What

A submission's first segment is cut after DM_NVN_CUT_FIRST_N draws (8) and committed at once, even while earlier segments are still running (DM_NVN_CUT_FIRST, on by default; =0 off, ab for the DM_AB phases).

Why

Ocarina of Time holds one frame in flight: its main thread waits on the fence of the frame it just submitted (wait ledger: SyncWait on the newest fence 0.72 times a frame, 17.4 ms). At each frame boundary the GPU has nothing queued until the next frame's first segment is committed.

sub_cut's busy rule commits a segment only once no earlier one is in flight. That held the first segment back until the previous frame's last ran out, and then until the next cut point. A counter-free Metal System Trace on an M1 showed 0.4–3 ms of GPU idle at every frame boundary. Committed early, the first segment runs while the previous frame's last work finishes.

Performance

Ocarina of Time (0400486024DEC000), Kokiri Forest, MacBook M1 (8-core GPU), fullscreen, in a tree with other local changes. Those include the image-heap alias flush once a submission (companion PR), which lets command buffers overlap at all.

With (frame p50) Without
ab:2,3/4, 300-frame phases 36.33 / 36.41 / 36.37 ms 37.19 / 37.33 / 37.41 ms
Phases swapped, ab:0/2, 450-frame phases 36.48 / 36.53 / 36.51 ms 37.57 / 37.38 / 37.35 ms

About −0.85 ms a frame, lower in every phase both ways.

An earlier test of committing every segment at once gained nothing while the alias flush on every barrier serialized the GPU. So this gain probably depends on the companion change.

Switches (in docs/env_switches.tsv)

  • DM_NVN_CUT_FIRST=0|1|ab: on by default.
  • DM_NVN_CUT_FIRST_N=<draws>: the first segment's size (default 8).

Not run

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

🤖 Generated with Claude Code

…ven while earlier work runs: Ocarina of Time -0.85 ms a frame on an M1

Ocarina of Time holds one frame in flight: its main thread waits on the fence of the frame it just submitted (the wait ledger: SyncWait on the newest fence 0.72 times a frame,
17.4 ms), so at each frame boundary the GPU has nothing queued until the next frame's first segment is committed. sub_cut's busy rule commits a segment only once no earlier one
is in flight, which held that first segment back until the previous frame's last ran out, and then until the next cut point: a counter-free Metal System Trace on an M1 showed
0.4-3 ms of GPU idle there every frame. Now a submission's first segment is cut after DM_NVN_CUT_FIRST_N draws (8) and committed at once (DM_NVN_CUT_FIRST, on by default;
=0 off, ab for the DM_AB phases), so it runs while the previous frame's last work finishes.

Measured (0400486024DEC000, Kokiri Forest, MacBook M1 8-core GPU, fullscreen, in a tree with other local changes, among them the image-heap alias flush once a submission of the
companion PR, which lets command buffers overlap at all): DM_NVN_CUT_FIRST=ab:2,3/4 in 300-frame phases, frame p50 36.33 / 36.41 / 36.37 ms with it against 37.19 / 37.33 /
37.41 without; with the phases swapped (ab:0/2, 450-frame phases) 36.48 / 36.53 / 36.51 against 37.57 / 37.38 / 37.35: -0.85 ms, lower in every phase both ways. Without
the overlap the alias flush on every barrier forbids, an earlier test of committing every segment at once gained nothing, so the gain here likely needs that change.

Not run: this branch's host in game, any test suite, the iPhone, other games.

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 12, 2026
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.

1 participant