Skip to content

Indirect-count multi-draws are copied when their pass opens: Mario Kart World's scene passes are no longer split for them - #1179

Closed
aksmith-git wants to merge 1 commit into
seedds:mainfrom
aksmith-git:pr/mdx-prescan
Closed

aksmith-git wants to merge 1 commit into
seedds:mainfrom
aksmith-git:pr/mdx-prescan

Conversation

@aksmith-git

@aksmith-git aksmith-git commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

mdx_run copied a multi-draw's records at its first draw. When the render pass had already opened for an earlier draw, that split the pass, and the colour and depth attachments (2048x1152, 20 MB) were loaded again.

mdx_prescan runs the same forward scan when a draw that is not such a multi-draw opens a pass, once per epoch and submission, so no copy is made inside the pass. Ranges (draw_multi) are not scanned ahead and behave as before.

Mario Kart World, Grand Prix route:

  • Pass dump at a race frame: masking splits 2 → 0. Mergeable splits 5 → 2 (tbdr_pass_merge.py: 118 → 47 MB a frame).
  • iPad Pro (M5), 10 minutes: 72,000 splits → 0.
  • M4 Pro GPU time (first-flyover shot runs): p50 13.0 ms, against 13.65–14.1 ms in five runs without it.
  • iPad GPU time: unchanged within noise (race p50 about 14.3 ms). Its bandwidth makes the reloads cheap there.
  • Pictures: as before, apart from run-to-run differences.

Rebased on main 0f510fd

  • The one conflict was mdx_run's first take, where main added indirect task / mesh draws (DM_PRIM_MESH_TASKS, keyed by the record alone). Both are kept: a mesh draw takes its record as on main, an ordinary draw as before, and a call with neither (mdx_prescan) takes only the draws after it. The forward scan already takes mesh draws, so a pass an ordinary draw opens copies the indirect mesh draws after it too.
  • make -C dm/host GAME=0400486024DEC000 dmhost builds; check_t_large_mdi and check_t_geometry_mesh pass; docs_symptoms.py, test_docs.py.
  • Docs: an entry in docs/reference/rendering.md (Indirect-count multi-draws split the pass an earlier draw opened), its line in the symptom index, and a line in Mario Kart World's note.
  • The measurements above are from before the rebase; not measured again on main.

@github-actions github-actions Bot added the nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) label Nov 4, 2026
@github-actions github-actions Bot added docs Documentation game: 0400C3F00006E000 A game profile labels Nov 6, 2026
lossefanya pushed a commit to lossefanya/nxnative that referenced this pull request Nov 6, 2026
…mit on): in free roam the game frees its own blocks, and its footprint stays near 4 GB with DM_GUEST_FILE

Free roam streams the world, and the memory kept growing: on a 16 GB M1 Pro, handheld, a
scripted drive into new areas took the footprint from 7.8 to 9.4 GB in 12 minutes (the game's
charged memory 3.9 to 5.3 GB, 4.5 GB compressed, swap growing). Most of it was the game's own
memory, which the host cannot give back without knowing what the game still needs.

With mem_map_limit on, MapPhysicalMemory past the 9 GB pool fails as on Horizon, and the
game's streaming frees its own blocks: its alias region peaked at 1.5 GB mapped where it had
3.0 GB, as issue seedds#1536 found on an 8 GB Mac. With DM_GUEST_FILE=1 as well, the footprint
stayed at 3.8 to 4.4 GB over 13 to 17 minutes, compressed memory under 0.6 GB, swap flat,
wired unchanged. The cost is more long frames: a 20-minute played windowed run (Grand Prix and
free roam) had 1.35 long frames a second (21 over 100 ms) against 0.65-0.73 without the files. Measured on
a branch that also had pull requests seedds#1179, seedds#1229, seedds#1230, seedds#1251 and seedds#1350.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rt World's scene passes are no longer split for them

mdx_run copied a multi-draw's records at its first draw. When the pass had already opened for an earlier draw, that split
it, and the colour and depth (2048x1152, 20 MB) were loaded again. mdx_prescan runs the same scan, once per epoch and
submission, when a draw that is not such a multi-draw opens a pass. Ranges (draw_multi) are not scanned ahead and behave
as before.

Mario Kart World, the Grand Prix route:
- Pass dump at a race frame: masking splits 2 → 0, mergeable splits 5 → 2 (tbdr_pass_merge.py: 118 → 47 MB a frame).
- 10 minutes on an iPad Pro (M5): 72,000 splits → 0.
- GPU time on an M4 Pro (first-flyover shot runs): p50 13.0 ms against 13.65–14.1 in five runs without it.
- GPU time on the iPad: unchanged within noise (race p50 about 14.3 ms), its bandwidth makes the reloads cheap there.
- Pictures as before (only run-to-run differences).

The reference entry is in docs/reference/rendering.md, with its line in the
symptom index and Mario Kart World's note.
@aksmith-git

Copy link
Copy Markdown
Contributor Author

Rebased on main eed7c42 (the conflict was the game note's entry list). Builds with the Mario Kart World profile; check_t_large_mdi passes; docs_symptoms --check current; test_docs OK.

seedds added a commit that referenced this pull request Nov 13, 2026
…(PR #1179)

mdx_run copied a multi-draw's records at its first draw. When an ordinary draw had already opened the render pass, the copy's compute pass split it and the attachments were loaded again. mdx_prescan runs the same forward scan when a draw that is not such a multi-draw opens a pass, once per g_mdx_epoch and submission, so the multi-draws after it are copied before the pass. Ranges replayed through draw_multi are not scanned ahead. The rebase onto the mesh-grid changes keeps DMSH_MESH_GRID as an indirect mesh draw's limit in mdx_run's first take.

Added here:
- The scan runs only once the game has drawn such a multi-draw or an indirect mesh draw (g_mdx_runs), so other games do not walk their submissions for it.
- A barrier with ORDER_INDIRECT_DATA after a draw with shader writes since the copies were made (g_mdx_wr against g_vbuf_write_epoch) bumps g_mdx_epoch, and the multi-draws after it copy again: a draw can write a record, and NVN orders that write for indirect fetch only by such a barrier. The copies made ahead now come before the pass-opening draw; the scan from a multi-draw's own first draw already had this gap for the draws between multi-draws. No game is known to write records from a draw.
- DM_NVN_MDX_PRESCAN=0 turns the scan off, =ab alternates it with DM_AB.
- t_mdx_prescan: split counts and pictures for the first multi-draw (split), a pass opened by an ordinary draw (none), count 0, an indirect barrier with and without a shader write before it, and a shader write with no barrier. It fails without the prescan and without the barrier rule.

Mario Kart World 1.8.0 on an M4 Pro, the regression route: masking splits in pass dumps every 600 frames 12 and 10 in two runs without it, 0 and 0 with it. In one run alternating DM_NVN_MDX_PRESCAN=ab every 300 frames, the first ten race phases load 69 MB and store 47 MB less per frame with 2.2 fewer passes (8 of 8 comparisons); the last fifteen show no difference, as main hardly splits there. GPU time unchanged within noise (p50 about 9.6 ms). The author's pre-rebase M4 Pro gain (p50 13.65-14.1 to 13.0 ms at the first flyover) was not reproduced here.

Checked: regress.py check on Mario Kart World, 2+2 runs PASS (59.3 fps both, p99 20.7/20.6 to 20.6/20.4 ms, no new red line, no shader change) and the A/B run; make -C dm/gfx/tests run (the whole suite, t_large_mdi, t_geometry_mesh and t_mesh_first_use among it); lint_c.py tidy on nvn_mtl.m and the test at the baseline; test_docs, test_env_switches. Not run: Ocarina of Time (indirect mesh draws reach the prescan; covered by the mesh tests), Monster Hunter Rise (not on this Mac), iOS and the iPad.

Co-authored-by: aksmith-git <242086076+aksmith-git@users.noreply.github.com>
@seedds

seedds commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Landed on main as a4705fe, with you as co-author. Thank you for the diagnosis and the measurements.

Changes on top of the PR:

  • Rebase: main's mesh-grid change (09dcb62) came after your base. The rebase keeps DMSH_MESH_GRID as an indirect mesh draw's limit in mdx_run's first take; the PR's version of that line still had 0, which would have made mdx.metal divide by zero.
  • Gate: the prescan runs only once the game has drawn an indirect-count multi-draw or an indirect mesh draw (g_mdx_runs), so other games don't walk their submissions for it.
  • Draw-written records: a copy made ahead now comes before the draw that opens the pass. A draw's shader can write a record, which NVN orders for indirect fetch only by a barrier with ORDER_INDIRECT_DATA, so such a barrier after a shader write since the copies were made now ends them, and the multi-draws after it copy again.
  • Switch: DM_NVN_MDX_PRESCAN=0 turns the prescan off, and =ab alternates it with DM_AB.
  • Test: t_mdx_prescan covers split counts and pictures for each case.

Measured on main (1.8.0, M4 Pro, the regression route):

  • Splits: in pass dumps, 12 and 10 masking splits without it, 0 and 0 with it.
  • Traffic: with the prescan alternating in one run, the first ten race phases load 69 MB and store 47 MB less per frame, with 2.2 fewer passes. Later in the race there is no difference.
  • GPU time: unchanged within noise (p50 about 9.6 ms). Your 13.65–14.1 → 13.0 ms at the first flyover was not reproduced here. If you can, an A/B on your machine with DM_AB=300 DM_NVN_MDX_PRESCAN=ab (the [ab] lines in the log) would show whether it holds there.

@seedds seedds closed this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation game: 0400C3F00006E000 A game profile 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