Files
seeddsandEric Schaal 685d2aecf0 gfx/nvn: Metal 4 mesh pipeline bases, mesh_pairs.tsv prebuild, and prefetch
Compile and archive format-unspecialized Metal 4 mesh pipeline bases (task + mesh + pixel), specialize them across attachment/blend/depth states at draw time, proactively prefetch them on NVN program creation, and prebuild static (task, mesh, pixel) triples offline and on device via mesh_pairs.tsv.

- Reflection & chain: mark mesh shaders that emit per-primitive outputs with mesh_stage.prim in dmsh_meshstage.py / dmsh_build.py and bump DMSH_CHAIN to 3fe2e3787fdf.
- Host Metal 4 mesh bases (nvn_geometry.inc, nvn_mtl.m): build, deduplicate, archive, compact, and specialize Metal 4 mesh bases (preserving mtk_spill payload clamping and tagging dm_mesh_nop); fall back to whole pipelines for mesh_stage.prim and reads_prim_id as a workaround for an Apple Metal 4 compiler/driver bug (verified on Apple M6, macOS 27.2.1 / Metal 32023.922) that non-deterministically zeroes per-primitive outputs and [[primitive_id]] on specialized mesh bases; skip recording M manifest rows when a base hits archive; prefetch mesh bases from mtl_prog_prefetch() on a bounded background queue (DM_NVN_MESH_PREFETCH=0 disables).
- Static mesh triples & prebuild (shader_split.py, pso_offline.py, pack_app.py, build_ipa_from_nsp.py, build_ipa.sh, regress.py, nvn_mtl.m): emit mesh_pairs.tsv (M\t<task or ->\t<mesh>\t<pixel or ->), compile eligible mesh bases into MTL4Archive via metal-tt, route depth-only / non-default-constant triples to rest_pairs.tsv, and load mesh_pairs.tsv / DM_MESH_PAIRS in pso_prebuild().
- Tests & docs: extend t_pso_archive, t_pso_bundle, test_pso_offline, test_dmsh_meshstage, test_dmsh_pairs, and test_nsp_incremental; update env_switches.tsv, docs/reference/shaders.md, and Ocarina of Time's note.

Checked: Mac host build, Metal 4 GPU tests (t_pso_archive 441/441 + 15/15 restarts, t_pso_bundle 118/118, t_mesh_first_use, t_pso_stall 124/124), Python suites (test_pso_offline, test_nsp_incremental, test_nsp_mac_app, test_docs, test_env_switches, test_nsp_chain, test_game_profile, test_dmsh_pairs, test_dmsh_meshstage prim checks), regress.py on Fast Fusion (PASS), and regress.py + 3-way cold-start A/B/C on Ocarina of Time (mesh stall 15,847.5 ms -> 6,056.4 ms with prefetch -> 2.6 ms with offline mesh bundle).

Front-ends: break: shader libraries must be rebuilt for chain 3fe2e3787fdf.
Co-authored-by: Eric Schaal <[email protected]>
2026-11-24 02:17:20 +08:00
..
A pull of the cloud's save is recoverable from wherever it stopped, an unsafe save is not mounted, and automated runs share one cloud-save policy. Pull (dm/host/save_sync.c): a journal, <save>.pull, is written and synced before the first of this device's folders moves and removed once the cloud's save is wholly in place (the commit point); it names the backup folder and, for each folder, what this device had there (nothing, an empty folder, or a save with the folder's device and inode: a rename or a swap keeps a folder's inode, so recovery finds it wherever the pull stopped). One recovery puts this device's save back from any point and removes only the cloud's folders: a failed step calls it (replacing the in-call undo list), and so does the first save mount of every start, before the staging folder is cleared and before a sender can run, whatever DM_SAVE_SYNC says. An app killed between the two folders' swaps left a half-replaced save before, which the next start played on and could send (reproduced against the old pull: killed after its first swap, the next start played the cloud's save folder with this device's save_device). A journal that cannot be read or a recovery that fails leaves everything in place and refuses the mount: save_sync_mount returns -1 (a second mount gets the first's answer) and hle_fs.c's three save mounts stop the game with the reason (die), the next start trying again; the Mac launcher's send after the host sends nothing while a journal is pending; the older local backups are pruned only once a pull completes (backup_dir prunes at creation only for the cloud's side). An app kill is covered, a power loss not claimed (the folder renames are not synced to the disk). Automated runs: dm/tools/run_saves.py cloud_off is the one policy regress.py's run_env, bench.py's run_one and the NSP script's tool_env and prebuild apply last (DM_SAVE_SYNC=0, DM_SAVE_SYNC_CHOICE removed, which none of them did; a caller's own option turning sync on refused, CloudSync), replacing three copies. The step 15 audit of the review's F1 and F2 fixes named both as their from-scratch designs. New reference entry (A pull cut short left a half-replaced save), the F1 and F2 entries updated, symptom index regenerated. Checked: t_save_sync_metadata (204: a kill after each rename and swap of a pull, this device's device folder holding a save, empty or absent, the cloud's save with and without one, then the next start's mount: back as it was, nothing of the cloud's left, the journal gone; a kill in the middle of that recovery; a putting back that fails keeps the journal and the next start recovers it; a failing recovery refuses the mount and the start after it recovers; an unreadable journal refuses it; a second mount's answer; pruning only after a completed pull; no send after the host with a journal pending; four deliberate breaks each fail it), t_save_sync (104: a journal the start cannot put back stops the game's own MountSaveData, the save and the journal left as they were, and with it gone the mount goes on), make -C dm/host/tests run, asan, tsan memory-tsan tsan-threads, lint_c.py tidy on the changed C files (at the baseline), the iOS compile check (263 files); test_run_saves, test_regress, test_bench, test_nsp_env_checks (the inherited choice removed in each), test_pr_areas, test_docs, lint_python.py (nothing new); regress.py check against be412f82 (headless, M6): Bastion 59.5 / 59.6 fps, frame 5,236 reached, no save-sync line (sync off), no new red line, flagged on its 70 s shot only outside the game's 1600x900 crop (the baseline's purple strip this time; inside the crop RGB 10.4 / 7.8, animation). Not run: a real iCloud pull, the iPhone, a power loss, a front end's report of a pending journal (save_sync_report does not say)
2026-11-12 16:02:16 +08:00