Skip to content

Compute dispatches can be ordered by the game's own barriers (profile key dispatch_barriers game): Kirby Air Riders' particle systems go from 6.6-9.8 ms to 0.4-1.2 ms a frame - #2250

Closed
FifteenPen wants to merge 1 commit into
seedds:mainfrom
FifteenPen:pr/dispatch-barriers

Conversation

@FifteenPen

@FifteenPen FifteenPen commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What and why

This makes Kirby Air Riders hold 60 FPS under the heaviest scenes.

Symptom. Kirby Air Riders (040077201BE50000, 1.3.3) drops under 60 fps in races wherever its particle systems are busy. DM_NVN_GPUPROF shows one compute / copy encoder at the start of each frame with 170–290 dispatches taking 6.6–9.8 ms, about 30 µs a dispatch, more than all of the frame's rendering (about 6 ms).

Cause. dispatch_enc orders every dispatch after everything before it in its encoder (a barrier before each, as for a texture copy), so the GPU runs them one at a time. NVN does not ask for that: a dispatch's writes are visible to later work when the game issues nvnCommandBufferBarrier, which the host already follows for draw passes (draw_barriers game).

Two things I tried first and dropped, because they show why the game's barriers are the right source of order:

  • No barriers at all (DM_NVN_BLIT_ORDER=0): the same encoder takes 0.13–0.18 ms, but the game's real dependencies race and the GPU faults.
  • Barriers only where memory ranges meet: no gain. The particle systems share the buffers they write, and 91 % of the dispatches met a range an earlier one wrote.

Change. A profile key, dispatch_barriers game (default full, unchanged), set for Kirby Air Riders. With it a dispatch gets a barrier:

  • when the game issued nvnCommandBufferBarrier since the operation before it;
  • when a copy's range meets its own (a dispatch after a copy that wrote what it reads, a copy after a dispatch that wrote or read what it touches), so the host's uniform updates and uploads keep their order;
  • always, on both sides, when one of its bindings has no memory range (an image, a buffer texture, a handle in a uniform slot, global memory traced to no storage buffer).

DM_NVN_DISPATCH_BARRIER=game / full overrides the key, and ab alternates the two with the DM_AB phases.

With the key at its default nothing changes: the dispatch sets stay empty and dispatches take dispatch_enc as before.

Reference entry: Compute dispatches that wait for each other.

Measurements

M4 Pro (48 GB), macOS 27.2, Air Ride races, window at 2560x1440.

Both orders in one race (DM_AB=600 DM_NVN_DISPATCH_BARRIER=ab, 450 measured frames a phase; the race phases):

full (5 phases) game (4 phases)
GPU p50, per phase 8.2, 11.5, 8.8, 8.4, 8.3 ms 5.7, 6.2, 5.2, 4.1 ms
GPU p50, mean 9.0 ms 5.3 ms
GPU p90, per phase 12.4, 13.7, 9.8, 10.0, 11.4 ms 9.6, 9.9, 8.7, 5.1 ms
Heaviest phase: frame p50 / p90 / mean 17.27 / 19.36 / 17.68 ms 16.66 / 16.75 / 16.66 ms

The particle encoder (DM_NVN_GPUPROF=every:300, separate races):

full game
Encoder time 6.6–9.8 ms 0.4–1.2 ms (one frame 2.6 ms)
Per dispatch about 30 µs 2–6 µs
Frame time p95 over a race 18–22 ms in the heavy windows 16.8 ms in every window

Where the barriers went (600,000 dispatches): 7 % a barrier of the game's, 2 % a copy's range, 6 % a binding with no range, 85 % none.

Checked

  • Tests: new t_dispatch_barrier, run in both modes and with the encode thread on and off (21 checks full, 25 game): a chain of 64 dispatches behind the game's barriers gives the sequential result; dispatches the game did not order get no barrier in game and one each in full; a fill before a dispatch and a copy after one stay ordered; a rangeless dispatch keeps the full order. With the line that records the game's barrier removed, it fails (0 of 63 barriers, the chain's result wrong). t_dispatch_own, t_copy_alias, t_tg_spill pass. test_docs.py, test_env_switches.py, docs_symptoms.py.
  • Games run: Kirby Air Riders 1.3.3 on the Mac, several Air Ride races with the key on, played by hand: no [RED] line, no GPU error, and no visible change in the particle effects (not compared frame by frame).
  • Not checked: other games with the key on (it is off for all of them); iOS. regress.py check was not run: this Mac has no builds of the manifest games. regress.py impact lists every NVN game, as the change is in the copy encoder's path; with the key off that path is the same as before.
  • Kirby Air Riders does not run long on main by itself: its particle shaders hang the GPU without the barrier-exit fix and loop guard that were in Orbitals (040004F027560000) plays on the Mac: Unreal Engine 5.6 Switch 2 shaders and Ampere forms, threadgroup store fences, whole-built integer-bit pipelines, GPU hang defences #1275. The measurements are from a tree with that fix; this change does not depend on it.

Docs

  • The finding is in its game note and its docs/reference/frame-rate.md entry, and python3 dm/tools/docs_symptoms.py was run
  • No chain tool changed
  • No game files, keys or data extracted from a game in the change or the attachments

… key dispatch_barriers game): Kirby Air Riders' particle systems, about 230 dispatches a frame that the GPU ran one at a time, go from 6.6-9.8 ms to 0.4-1.2 ms a frame
@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: 040077201BE50000 Kirby Air Riders labels Nov 10, 2026
seedds added a commit that referenced this pull request Nov 12, 2026
Compute dispatches are ordered by the game's own barriers, for every game (PR #2250): dispatch_enc put a barrier before every dispatch in the shared copy encoder, so the GPU ran them one at a time, while NVN makes a dispatch's writes visible to later work only when the game issues nvnCommandBufferBarrier. Now a dispatch (dispatch_enc_cs) gets a barrier when the game issued one since the dispatch before it, or when one of the host's copies meets its ranges in either direction (uniform updates and uploads keep their order; copies are checked against what dispatches wrote and read, g_dw / g_dr); a dispatch with a binding whose reach is no memory range (an image, a buffer texture, a handle in a uniform slot, untraced global memory) and the host's own dispatches keep the full order on both sides. Kirby Air Riders' particle systems, about 230 dispatches a frame that share the buffers they write (91 % meet an earlier one's range, so ranges alone gain nothing): the encoder 6.6-9.8 → 0.4-1.2 ms, GPU p50 over alternating race phases 9.0 → 5.3 ms, the heaviest phase's frame p90 19.36 → 16.75 ms (PR author, M4 Pro, with PR #2254's loop guard). The PR made it a profile key for Kirby; it is the host default here, as the rule is NVN's: DM_NVN_DISPATCH_BARRIER=full brings back the barrier before every dispatch (diagnostic), ab alternates with the DM_AB phases. It replaces PR #1901's dispatch_overlap for Ocarina of Time. Also fixed on top of the PR: a new copy encoder empties the dispatch range sets (ranges from a closed encoder put needless barriers before its copies; t_dispatch_barrier's new case 6 fails without it), and bufsnap's copy is recorded as writing everything, so a later dispatch cannot overwrite what it still reads. The periodic [nvn] line counts dispatches after a game barrier, after a copy's range, in the full order and with none. Reference entry Compute dispatches that wait for each other (frame-rate.md), rendering.md's two dispatch entries point to it, Kirby's note lists it, env switch row, symptom index regenerated. Checked: t_dispatch_barrier in both orders with the encode thread on and off (27 / 31 checks), t_dispatch_own, t_copy_alias, t_tg_spill, t_cpu_tex, test_docs, test_env_switches, test_game_profile, lint_c.py tidy (at the baseline); regress.py check against 8a5c5e7 (M4 Pro): Mario Kart World PASS, 69,367 of about 1.02 M dispatches with no barrier, 59.8 / 60.0 fps, no new red line; OCTOPATH TRAVELER II PASS, but all its dispatches have a rangeless binding and keep the full order. Not run: Kirby Air Riders and Ocarina of Time in this form (no files / no route here), the iPhone

Co-authored-by: FifteenPen <354289956+FifteenPen@users.noreply.github.com>
@seedds

seedds commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Landed as 547c5db, with you as co-author. Thank you: the rule, the test and the Kirby diagnosis are yours.

What changed from the PR:

  • On for every game, not a profile key: the rule is NVN's own ordering, so its binding is host. DM_NVN_DISPATCH_BARRIER=full brings back a barrier before every dispatch (a diagnostic), and ab alternates the two with the DM_AB phases.
  • A new copy encoder empties the dispatch range sets (blit_open). Ranges from a closed encoder put needless barriers before the next encoder's copies. t_dispatch_barrier's new case 6 fails without the fix.
  • bufsnap's copy is recorded as writing everything, so a dispatch the game's barriers leave unordered cannot overwrite what the snapshot still reads.
  • The periodic [nvn] compute dispatches line counts dispatches after a game barrier, after a copy's range, in the full order, and with no barrier. It replaces the line every 200,000 dispatches.

Checked: t_dispatch_barrier in both orders with the encode thread on and off, t_dispatch_own, t_copy_alias, t_tg_spill, t_cpu_tex, and the docs tests. regress.py check against main on an M4 Pro:

  • Mario Kart World: PASS. 69,367 of about 1.02 M dispatches ran with no barrier, 59.8 → 60.0 fps, no new red line.
  • OCTOPATH TRAVELER II: PASS, but every one of its dispatches has a binding with no range, so all kept the full order.

Not run here: Kirby Air Riders and Ocarina of Time in this form, and the iPhone. A Kirby race with DM_AB=600 DM_NVN_DISPATCH_BARRIER=ab on current main would be welcome, ideally counting how often #2254's loop guard fires in each phase.

@seedds seedds closed this Nov 12, 2026
Kayyluhh added a commit to Kayyluhh/nxnative that referenced this pull request Nov 14, 2026
…losed, superseded by seedds#2250, on main as 547c5db (compute dispatches ordered by the game's barriers for every game)

Ocarina of Time's profile drops dispatch_overlap; the barrier op records the game's bits without g_cs_gbar; dispatch_enc is main's as it was before seedds#2250. seedds#2226's ind_split and seedds#2341's replay_ahead stay.
Kayyluhh added a commit to Kayyluhh/nxnative that referenced this pull request Nov 14, 2026
…ered by the game's barriers (547c5db, seedds#2250) in place of seedds#1901

Kirby's note, hle_nvn.c's periodic lines (seedds#2261's GPU share and main's dispatch counts) and the tests Makefile keep both sides. Checked: t_dispatch_barrier (full and game, encode thread off and on), t_dispatch_own, t_copy_alias, t_tg_spill, t_replay_ahead, t_cpu_tex 107, t_view_cache 44, t_serial_owner 167, all dm/gfx/tests programs build, test_docs, test_env_switches, test_game_profile, test_nsp_chain, the Mac host for 0400486024DEC000.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation game: 040077201BE50000 Kirby Air Riders 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.

2 participants