Skip to content

Compile offline pipeline archives in optional sequential batches - #1119

Closed
itsrenoria wants to merge 1 commit into
seedds:mainfrom
itsrenoria:fix/offline-archive-batches
Closed

itsrenoria wants to merge 1 commit into
seedds:mainfrom
itsrenoria:fix/offline-archive-batches

Conversation

@itsrenoria

Copy link
Copy Markdown
Contributor

What and why

Super Mario Odyssey 1.4.1 finishes shader translation on an 8 GB M2 but its 32,864-base offline archive exhausts paging space inside Apple's GPU compiler. The kernel killed air-nt, reporting 33,856 MB. This happened with the Python memory fix from db8acc5 already applied.

Add an optional pso_offline.py --batch-size N path: compile sequential groups containing at most N bases, with each script referencing only the libraries it needs, then combine every group with metal-pack -nthreads 1. The result is the existing single <arch>.mtl4a archive. The default, --batch-size 0, keeps the single compiler invocation.

Each group has a content-based cache key covering its descriptors, library bytes, GPU, platform, OS minimum and compiler. Completed groups survive a failed run; changing one group rebuilds that group. A compile or merge failure stays fatal and cannot publish a new complete archive key or coverage stamp. The full archive retains its existing input key, so the normal Mac app packer can reuse it. The shader translation chain, host and profile inputs are unchanged.

This bounds the number of compiler inputs, not memory: one expensive pipeline or the final merge can still exceed available resources. Related to #1022, which requests archive partitioning for another workload; this PR does not claim to resolve that report.

Usage: run the standalone archive builder with its usual game/library/output/work/GPU/platform options and --batch-size 1000, then run the normal app packer with the same work directory. See the development guide and the reference entry.

Checked

  • python -m unittest dm.tools.tests.test_pso_offline dm.tools.tests.test_docs: 45 tests passed, including batch resume, a partial last group, changed-group invalidation, strict compile/merge failure handling, and reuse through the ordinary archive key.
  • make -C dm/gfx/tests GAME=0100000000010000 check_t_pso_bundle: 58 checks passed on current main plus this change. The fixture builds both ordinary and one-base-per-group archives, opens the merged archive through Metal 4, retrieves a base from each group, rejects an absent depth entry and compares coverage stamps.
  • Pinned Python lint ratchet: 391 baseline findings, 0 new, 0 stale baseline entries.
  • LLVM 23.1.4 lint_c.py compdb --game 0100000000010000 and lint_c.py tidy --against origin/main dm/gfx/tests/t_pso_bundle.m: 0 file/check pairs above the baseline, 0 below. The existing baseline was unchanged.
  • Complete workload: Super Mario Odyssey, title ID 0100000000010000, update 1.4.1 / v393216. All 33 groups compiled and merged; direct MTL4Archive lookups found 32,864 of 32,864 bases, with no compiler fallback. The 1,018,501,792-byte bundled archive matched the verified output, and the Mac app passed resource and signature checks.
  • Device/toolchain: Apple M2, 8 GB RAM, applegpu_g14g, macOS 26.6.1, Xcode 27.2 (27B52), Metal Toolchain 27B47, Metal/AIR-TT 32023.922.
  • Measurement provenance: the complete workload used b64a5ff + db8acc5 + this batching implementation, shader chain b2197aa0df0c. The PR is based on current main; focused unit, lint and synthetic Metal checks were repeated there. pso_offline.py is outside the shader translation chain.
Archive build Result / resource evidence
One invocation, 32,864 bases Compiler killed after the kernel reported no paging space; 33,856 MB as reported by macOS
Sequential groups, at most 1,000 bases Complete archive; largest recorded compiler lifetime physical footprint 2.065 GiB

The kernel kill figure and the sampled footprint are different measurements; no percentage reduction or hard memory cap is inferred. Physical/lifetime peak footprint came from proc_pid_rusage, sampled once per second; short-lived processes can be missed. The pilot took 20.5 s; the complete batched pass reusing that first group took 507.2 s; full archive lookups took 18.2 s.

scripts/regress.py impact origin/main..HEAD maps the change to present:pipeline_prebuild. Four recorded profiles have no matching usage and 130 profiles have no manifest, so this report supplies no cross-game verification.

Regression scope: the change is confined to an opt-in offline archive construction path. The focused tool suite, synthetic Metal bundle test and complete archive coverage checks exercise it directly; the shader/runtime regression harness does not exercise batch compilation. Other games, GPU architectures, OS/compiler versions and batch sizes remain unverified.

Docs

  • The generic mechanism is in docs/reference/shaders.md, usage is in docs/development.md, and the measured workload is in Odyssey's game note.
  • python3 dm/tools/docs_symptoms.py regenerated the symptom index.
  • No shader-chain tool changed; the chain header is unchanged.
  • No game files, keys or data extracted from a game are included in the change or attachments. Tests generate their own synthetic fixtures.

…mplete archive

A 32,864-base Odyssey archive exhausted paging space inside Apple GPU compilation on an 8 GB M2 even after the Python memory fix. --batch-size limits each sequential compiler invocation, then metal-pack combines every successful group into the existing archive format.

Keep the default and full-input archive key compatible. Cache each group independently and keep compiler or merge failures fatal. Add resume/failure tests and a synthetic Metal 4 merge check; document the complete archive validation and physical-footprint measurements.
@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: 0100000000010000 Super Mario Odyssey labels Nov 3, 2026
seedds added a commit that referenced this pull request Nov 3, 2026
…n sequential groups of at most N bases and merges them with metal-pack: Super Mario Odyssey's 32,864 bases no longer exhaust an 8 GB Mac's paging space in air-nt (#1119)

The default (0) keeps the single compiler invocation. Each group has a
content key, so a failed run keeps the groups it finished.

Co-authored-by: itsrenoria <1799282+itsrenoria@users.noreply.github.com>
@seedds

seedds commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Landed on main as 6ddeda9, with you credited as co-author. test_pso_offline (34 tests) and t_pso_bundle (58 checks, with the batched path through metal-pack on this Mac) pass. Thanks!

@seedds seedds closed this Nov 3, 2026
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…n sequential groups of at most N bases and merges them with metal-pack: Super Mario Odyssey's 32,864 bases no longer exhaust an 8 GB Mac's paging space in air-nt (seedds#1119)

The default (0) keeps the single compiler invocation. Each group has a
content key, so a failed run keeps the groups it finished.

Co-authored-by: itsrenoria <1799282+itsrenoria@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation game: 0100000000010000 Super Mario Odyssey 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