# MetalWatch-VI — Apple Silicon Porting Playbook & Bottlenecks

> Cross-project Metal 3 / Metal 4, Apple7–Apple11 (M1–M6), Darwin Mach VM & UMA engineering dossier for Xbox Series X|S (1.0.2.1) and PS5 (PPSA38500) compatibility runtimes on macOS.

- **Live HTML Page:** https://metalwatch-vi.github.io/playbook/
- **Raw Agent Endpoint:** https://metalwatch-vi.github.io/playbook.md
- **Updated (UTC):** `2026-12-04T14:30:00Z` (v1.0)
- **Cadence:** Updated organically on verified PR breakthroughs + weekly Deep Research delta across Apple Metal docs, KosmicKrisp, nxnative, Mullion, and tracked Mac repos.
- **Policy:** Independent technical tracker. Zero game files, binaries, shaders, screenshots, videos, or download links. Public open-source metadata and user-reported hardware observations only.

## Agent Quick-Start Protocol (Claude Code / Antigravity / Codex)

1. Check Block 1 (Quick-Win Transfers) against your repo before inventing a custom optimization — verified 10–40% wins (guarded bvh_lanes, MACBOX_NMT_PAGES=1, MACBOX_LINK_MESH_OVER=32768, depth-plane blit, Apple7/8/9 flags, off-lock PSO compile) already have working code and tests in sibling ports.
2. Audit Block 3 (Darwin Memory Traps & Apple Compiler Errata) before debugging mystery hangs, slow modes, or leaks — queue-attached MTLResidencySet kernel re-wiring, missing @autoreleasepool on .contents/readback, Darwin madvise(MADV_FREE) on PROT_NONE, vertex-only MTLBinaryArchive poisoning, and KosmicKrisp KK_WORKAROUND_* explain most macOS-only failures.
3. Respect Block 5 (Dead Ends / Verified Negative Results) so you do not burn sessions repeating proven regressions (clean-table block reuse = 0 hits, UPLOAD_BUDGET_MB=24 corruption, HIGH_PRIORITY=2 exceeding P-cores, unguarded SERIAL_COMPUTE=0 on M5/M2, naive mip-drop on mutable textures).
4. Benchmark strictly with warm A/B/B/A discipline: freeze commit, macOS build, shader-cache state, internal and output pixel dimensions, RT mode, and foreground visibility; report p50/p95/p99 native frame times (never Frame Gen), GPU ms, CPU prep ms, and memory peaks.
5. Respect epistemic tags: [Verified] = measured in PR, driver, or Apple documentation; [Conditional] = verified gain with chip/pass caveats; [Hypothesis] = grounded in primary Metal 4/driver proof, ready for A/B validation on target ports.

---

## 1. Top Cross-Repo Quick-Win Transfers (Low–Med Effort -> High Verified Gain)

### 1. Guarded bvh_lanes RT traversal (+40% RT FPS) [Verified · Effort: Low]
- **Donor:** MacBox GDK #53 (bvh.rs L223–256) (https://github.com/0xjohnnydev/macbox-gdk/pull/53)
- **Target Repos:** MacBox GDK, ForjaVI, BareMetalVI, VIvid, VIa, MetalVI
- **Measured / Expected Impact:** -16 to -18 ms GPU (+40% indoor RT FPS: 16.2–17.4 -> 22.9–24.1 FPS on M4 Max)
- **Mechanism:** Stop loading node_dwords and evaluating both bvh_box and bvh_triangle unconditionally before select. Guard node_dwords behind ty < 6 and branch is_box vs is_tri (371/371 shader tests pass).
- **Caveat:** Applies to software/inline BVH traversal paths; pair with #53 nonzero acceleration-structure SRV root binding (0 -> 34,906 ray hits).

### 2. Move MTLResidencySet from Queue to per-CB useResidencySet: [Hypothesis · Effort: Low–Med]
- **Donor:** seedds/nxnative #2715/#2751 (also MoltenVK#2890, uzu#988) (https://github.com/BareMetalVI/BareMetalVI/issues/812)
- **Target Repos:** BareMetalVI (#811/#812), StrongMetal, BetterXen (#879), VIvid
- **Measured / Expected Impact:** Eliminated 2–3x kernel re-wiring slow mode in 20/20 M4, 4/4 M2 (13.6->29.8 FPS), 6/6 M5 (~0.03 ms/frame cost)
- **Mechanism:** Remove addResidencySet: from MTLCommandQueue and call useResidencySet: on each command buffer before endCommandBuffer (including drawable sets). Respect Apple's hard limit of <=32 residency sets per CB.
- **Caveat:** Verified across 30/30 runs in nxnative; top priority A/B test for BareMetalVI #811/#812.

### 3. Raise mesh-pixel link threshold to Metal's real 32 KiB cap [Verified · Effort: Very Low]
- **Donor:** MacBox GDK #41 (MACBOX_LINK_MESH_OVER=32768) (https://github.com/0xjohnnydev/macbox-gdk/issues/41)
- **Target Repos:** MacBox GDK (M4 Pro/Max), ForjaVI, VIne, MetalVI
- **Measured / Expected Impact:** Drops Apple 9 mesh XPC register-allocator refusals from 2 -> 0 on M4 Max with zero compute rewrite
- **Mechanism:** Raise mesh-pixel linking threshold from 24576 to 32768 so 24–32 KiB mesh+pixel pairs compile separately instead of tripping Apple's XPC regalloc crash.
- **Caveat:** Re-verify directly on M4 Pro 20-core (#41); keep attribute compaction (MetalVI 24/24) for pipelines truly exceeding 32,768 bytes.

### 4. Cache-local BCPack BC7 tables + optional 2nd worker (2.45x) [Verified · Effort: Low–Med]
- **Donor:** MacBox GDK #55 (2444d73) + #57 zero-staging bypass (https://github.com/0xjohnnydev/macbox-gdk/pull/55)
- **Target Repos:** ForjaVI, BareMetalVI (#953), VIne, MetalVI, VIvid
- **Measured / Expected Impact:** BC7 decode 48.5 -> 77.8 -> 119.0 MB/s on M5 Max (2.45x); #57 unblocks zero-staging reads (22/22 storage tests)
- **Mechanism:** Improve decode-table cache locality first, then test parallel reconstruction; allow zero-staging reads to bypass scratch-blocked DirectStorage requests while preserving completion order.
- **Caveat:** Flat-layout variant gained 1.09x; test single-thread table layout first on 4–6 P-core Macs so nested workers never starve submission.

### 5. MACBOX_NMT_PAGES=1 + watch.rs alias leak fix & pool partitioning [Verified · Effort: Low–Med]
- **Donor:** MacBox GDK #19/#26/#58 + seedds/nxnative #2507 (https://github.com/0xjohnnydev/macbox-gdk/issues/58)
- **Target Repos:** MacBox GDK, ForjaVI, VIne, MetalVI
- **Measured / Expected Impact:** Eliminates 1–3 FPS driving freezes (20–30 FPS M4 Max) and targets 5 -> 309 ms lock growth & 96% false-dirty texture churn
- **Mechanism:** Fix Tracked::drop* and title_memory_remapped leaking ~50k orphan alias pages in g.protected; partition guard tables per memory pool, attach per-range write-sequence counters, and coalesce dirty snapshots per submit.
- **Caveat:** Also verify MacBox #43's 3 unmap/descriptor/PageWindow races plus MTL4VisibilityOptionResourceAlias so ~4% watch-clean textures never stay stale.

### 6. Ad-hoc Wine loader signing + decoupled Retina / MetalFX cap [Verified · Effort: Very Low]
- **Donor:** MacBox GDK #29/#44/#47 + WWDC26-356 (Cyberpunk 2077) (https://github.com/0xjohnnydev/macbox-gdk/pull/29)
- **Target Repos:** ForjaVI, VIne, MetalVI, BetterXen, 3r1-MetalBridge, MacBox GDK
- **Measured / Expected Impact:** Fixes MetalFX temporal GPU timeouts; saves 3–6 GB RAM & eliminates 24–36 GB Retina OOM/black screens
- **Mechanism:** Ad-hoc sign Wine loaders (codesign --force --sign -) for MetalFX Temporal; decouple internal 3D render size (720p–1080p) from CAMetalLayer 2x Retina backing scale and default Retina off below 48 GB RAM.
- **Caveat:** Use 120 Hz presentation link in fullscreen on ProMotion displays to avoid the 40 FPS cadence lock.

### 7. Chip-gated MSC & exposure flags (Apple9 0x100 + Apple7/8 M1/M2) [Verified · Effort: Very Low]
- **Donor:** MacBox GDK #16 + ForjaVI (docs/BENCHMARKS-M2PRO.md) (https://github.com/0xjohnnydev/macbox-gdk/pull/16)
- **Target Repos:** ForjaVI, VIne, MetalVI, MacBox GDK, VIvid, BetterXen
- **Measured / Expected Impact:** Fixes black/flat-colour 3D worlds across both M1/M2 (Apple7/8) and M3/M4 (Apple9) GPUs
- **Mechanism:** Clear MSC compat flag 0x100 on Apple9 (M3/M4); set VICTORY_METAL_MSC_APPLE10_FLAGS=1 and VICTORY_EXPOSURE_REALTIME=0 on Apple7/8 (M1/M2).
- **Caveat:** Keep flags strictly gated by detected MTLGPUFamily so Apple10/11 (M5/M6) paths stay unaffected.

### 8. Depth-plane buffer blit + MACBOX_TEXTURE_BACK=1 (water buoyancy) [Verified · Effort: Low]
- **Donor:** MacBox GDK #42 (c32e95a) + #46 (https://github.com/0xjohnnydev/macbox-gdk/pull/42)
- **Target Repos:** ForjaVI, VIne, MetalVI, native MetalFX backends
- **Measured / Expected Impact:** Eliminates 7,566 -> 0 dropped temporal depth copies at ~0 FPS penalty (27.7->27.8 FPS); restores floating boats (1–1.4 ms CPU)
- **Mechanism:** Blit Depth32Float_Stencil8 <-> Depth32Float via a temporary GPU buffer; copy GPU-written water height textures back to title memory when sampled by CPU buoyancy.
- **Caveat:** Wrap readback threads touching MTLBuffer.contents in an explicit @autoreleasepool to prevent 600+ MiB/min Objective-C temporary leaks.

### 9. 60s unused texture eviction + off-lock PSO compile + HOLD_RELEASE=1 [Verified · Effort: Low–Med]
- **Donor:** MetalVI #27 (06d7678) + BareMetalVI / StrongMetal + ForjaVI (https://github.com/Aoody743/MetalVI/pull/27)
- **Target Repos:** shitisix (~2 GB/min leak), BareMetalVI (#991), MacBox GDK (#47), VIvid
- **Measured / Expected Impact:** Caps wired growth (~25–27 GB steady vs 44 GB OOM); cold compute lock holds drop 2.9 s -> 23 ms; 2h15m leak-free
- **Mechanism:** Evict unreferenced placed textures after 60s once GPU observers finish; compile cold PSOs outside the TITLE lock via a per-key future; defer object release on a serial queue with @autoreleasepool.
- **Caveat:** Never skip compute PSOs with short frame budgets (#47 breaks DoF/foliage); only insert pipelines containing a fragment stage into MTLBinaryArchive (#44).

### 10. Selective compute-switch barrier removal (implicit-pass guarded) [Conditional · Effort: Low–Med]
- **Donor:** MacBox GDK #39 (MACBOX_METAL_SERIAL_COMPUTE=0) (https://github.com/0xjohnnydev/macbox-gdk/pull/39)
- **Target Repos:** Direct Metal backends (only after per-pass barrier classification)
- **Measured / Expected Impact:** M4 Pro 48 GB GPU dropped 49.0 -> 42.3–42.7 ms (+2.7–3.0 FPS: 20.1 -> 22.8–23.1 FPS)
- **Mechanism:** Count compute barriers by reason; remove only redundant pipeline-switch drains while preserving UAV, alias, internal-translator, and implicit auto-exposure/luminance dependencies.
- **Caveat:** DO NOT blanket-disable: unguarded SERIAL_COMPUTE=0 produced an all-white picture on M5 (ritr1t) and regressed M2 Pro in ForjaVI (8.8 -> 7.1 FPS, 26% <5 FPS).

---

## 2. Three-Track Engineering Bottleneck Matrix

### A. Shared Apple Silicon GPU / Metal / UMA

| Bottleneck | Affected Chips / Repos | Status | Grade | Proven Fix or Attack Path | Impact | Effort | Refs |
| :--- | :--- | :---: | :---: | :--- | :--- | :---: | :--- |
| **Queue-attached MTLResidencySet slow mode & 16 GB IOGPUGroupMemory panics** | All M1–M6 (esp. 16–32 GB); BareMetalVI #811/#812, StrongMetal, BetterXen #879, VIvid #5 | Partial | Verified | Use per-CB useResidencySet: (<=32 sets/CB; nxnative #2715/#2751 eliminated slow mode in 30/30 M2/M4/M5 runs); cap resident memory <=95% recommendedMaxWorkingSetSize on macOS 26 (KosmicKrisp WA20); exclude texture-only & shader-code pools from raw-pointer sets; commit outside xmem/remap locks (mlock file-backed buffers outside locks). | 2–4x FPS recovery; eliminates 16 GB panics & 8m deadlocks; -2–5 GB wired | Low–Med | nxnative #2715/#2751, KosmicKrisp WA20, BetterXen #879/#880, StrongMetal |
| **Cross-VA aliased UMA buffer coherency & watch-clean stale textures** | M1–M6 (macOS 26–27); MacBox GDK #43 (~4% stale), BetterXen, BareMetalVI, MetalVI | Partial | Verified | Add MTL4VisibilityOptionResourceAlias to barriers over mach_vm_remap / NoCopy aliases (MacNativeGames proved MTL4VisibilityOptionDevice alone fails 100% of aliased M4 reads); defer unmap/forget_uses until GPU completion; guard DirectStorage PageWindow writes before detiling. | Eliminates ~4% stale textures and silent aliased-memory corruption | Low–Med | Metal 4 VisibilityOptions, MacNativeGames, MacBox GDK #43 |
| **TBDR bandwidth waste: disabled lossless compression, global barriers & IMR passes** | Apple5–9 (M1–M4) & Apple10 (M5); all Direct Metal ports | Open | Verified | Strip unused shaderWrite / pixelFormatView / shaderAtomic from RTs (restores M1–M4 lossless compression); use MTLStorageModeMemoryless for single-pass depth/MSAA; add [[early_fragment_tests]] to non-discarding UAV G-buffer shaders; rewrite self-pixel decals to [[color(n)]] programmable blending; use select() over ternary (-10–31% M2) and gate unused occlusion queries (-11.7 ms M2). | -10 to -25 ms GPU (~20–35% GPU speedup); -0.5–1.5 GB RAM | Medium | Apple Tech Talk 111431, Apple Texture Docs, MacNativeGames, nxnative #1860/#2574 |
| **Retina 2x backing-scale OOM & ProMotion 120 Hz 40 FPS cadence trap** | 16–36 GB Retina & ProMotion Macs; MacBox GDK #44/#47, all windowed/fullscreen ports | Partial | Verified | Track 4 sizes separately (window points, drawable pixels, internal scene, upscaler output); keep internal 3D at 720p–1080p with MTLFXTemporalScaler (M5 Pro/Max Neural Accelerators) and cap output <48 GB (Cyberpunk caps even M5 Max to 2336x1460); drive ProMotion fullscreen with a 120 Hz display link. | -3 to -6 GB RAM (4x fewer pixels on scaled RTs); removes 24/36 GB OOM & 40 FPS cap | Low | MacBox #44/#47, WWDC26-356 (Cyberpunk 2077), nxnative |
| **>16 sampler-heap refusals & missing Query Texture LOD (image_get_lod)** | M1–M6; BareMetalVI #914 (179 shaders), BetterXen #877/#878 (65/87 shaders) | Partial | Verified | Move all dynamic & static/inline samplers into a deduplicated Tier 2 Sampler Argument Buffer (inline constexpr MSL samplers consume the 16 direct slots; keep <=996 on M1/M2, up to 500K on M3–M6); expose native calculate_clamped_lod / calculate_unclamped_lod (Apple8+ native, Apple7 prop check) to unlock 65/87 refused SM 6.6 heap pixel shaders. | Unlocks 179–636 refused shaders & removes sampler fallback bugs | Medium | Apple Feature Tables (Oct 2026), KosmicKrisp, BetterXen #877/#878, BareMetalVI #914 |
| **>32 KiB mesh outputs, M4 Pro XPC regalloc crashes & M1/M2 1,024-group mesh cap** | M1–M6 (esp. M4 Pro & M1/M2); MacBox #41, MetalVI, 3r1, BareMetalVI | Partial | Verified | Set MACBOX_LINK_MESH_OVER=32768 (drops 24–32 KiB M4 Max crashes 2 -> 0); use dynamic output counts (3r1 #38: 664/677 shaders) and attribute compaction (MetalVI: 24/24 fit); split mesh grids >1,024 threadgroups on M1/M2 (Apple7/8 hard limit); reserve Mesa libpoly compute lowering only for truly >32 KiB survivors. | Eliminates M4 Pro compiler crashes & missing interior geometry | Low–Med | MacBox #41, 3r1 #38, MetalVI, Apple Feature Tables p. 9, Mesa libpoly |
| **HWRT BVH traversal cost, builder faults & Apple7/8 64-bit atomics** | M1–M6; MacBox #53, BareMetalVI #54/#920, shitisix (BVH off), ForjaVI | Partial | Verified | Guard bvh_lanes (ty < 6 + is_box/is_tri -> +40% RT FPS on M4 Max); pair BareMetalVI #920 fences with VIctory-xmem #429 batched BVH invalidation inside Metal 4's unified MTL4ComputeCommandEncoder; use native HW 64-bit ulong min/max on M2 (Apple8) and >=2^20-word lock tables or 2-pass 32-bit atomics on M1 (Apple7). | -16 to -18 ms GPU in RT scenes; crash-free RTGI & M1/M2 culling | Low–Med | MacBox #53, BareMetalVI #920/#405, xmem #429, mach9 #91, Apple Tables p. 6 |

### B. Native Metal / Pure ARM64 (Zero Wine)

| Bottleneck | Affected Chips / Repos | Status | Grade | Proven Fix or Attack Path | Impact | Effort | Refs |
| :--- | :--- | :---: | :---: | :--- | :--- | :---: | :--- |
| **Single TITLE lock serializing ~110 ms/frame (32 ms descriptors + 27 ms tex + 12 ms encode)** | All ARM64 Macs; BareMetalVI (~17 FPS GPU floor), StrongMetal, VIvid | Open | Hypothesis | Build versioned submission packets under the title lock and encode in parallel using per-thread MTL4CommandAllocator (dttdrv/mullion 17f8ffd) + reusable MTL4ArgumentTable (-22.7% submit CPU in nxnative #3554); replace blanket descriptor copies with dirty-span/indexed lookup (VIne WrapTable) + GPU compute detiling; validate synchronous replay before enabling worker (#997 hung at 34s). | -50 to -85 ms CPU (2–3x FPS lift toward ~17+ FPS GPU floor) | Med–High | BareMetalVI #46/#997, Mullion 17f8ffd, nxnative #3554, VKD3D-Proton |
| **1.7M/s DirectStorage spin-polling & XNU E-core thread demotion** | M1–M6; BareMetalVI #953 | Open | Verified | Replace busy-wait / sched_yield spin loops with event-driven os_sync_wait_on_address / POSIX WaitOnAddress (Apple CPU Tech Talk confirms spin-waiters get demoted to slow E-cores); move Opus/XMA audio (ReVIctory #37) & BCPack decode to QOS_CLASS_UTILITY E-core workers. | -5 to -15 ms CPU; eliminates E-core demotion & improves 1% lows | Low | BareMetalVI #953, Native-Victory #556, ReVIctory #37, Apple CPU Tech Talk |
| **Long-run ~2 GB/min memory leak (>40 GB) & 10.6 s hold_list stalls** | M1–M6; shitisix, BareMetalVI #991 | Solved elsewhere | Verified | Audit all guest readback / MTLBuffer.contents / background PSO threads for missing @autoreleasepool (leaks 617 MiB/86s or 3.7 GB/30m); port MetalVI #27 60s placed-texture eviction, ForjaVI HOLD_RELEASE=1 (serial queue + autoreleasepool), and ensure a GPU CB drains after endResidency (llama.cpp #25937). | Eliminates >40 GB session leaks & 10s hold_list stalls | Low | nxnative #195/#2714, MetalVI #27, ForjaVI, llama.cpp #25937 |
| **Cold PSO compile freezes under TITLE lock & archive bloat** | 16–48 GB Macs; BareMetalVI, VIvid, shitisix | Solved in StrongMetal | Verified | Move PSO compilation off TITLE lock via per-key futures (BareMetalVI: 2.9 s -> 23 ms worst lock hold; StrongMetal defer_render_compile); drop already-persisted raw shader bytes from RAM; normalize unused PSO state keys (-35% archive count in MacNativeGames f3e2f66); harvest offline with WWDC25-254 metal-tt. | Eliminates multi-second lock convoys; -1 to -3 GB RAM | Low–Med | StrongMetal, BareMetalVI, MacNativeGames f3e2f66, WWDC25-254 |
| **32 GB start-slow state (#811) & ~95s GPU 2–4x slow mode (#812)** | M2 Max 32 GB, M5 Max 64 GB; BareMetalVI #811/#812 | Open | Hypothesis | Test per-CB useResidencySet: (nxnative #2715/#2751) first; ship an .app bundle declaring public.app-category.games (Game Mode) + NSActivityLatencyCritical; run macOS 27 metalperftrace collect --last 5m + foreground/present logging (MacBox #49) to separate kernel re-wiring vs thermal fan-ramp lag (~95–120s) vs occlusion throttling. | Recovers 2–4x frame rate in affected runs | Low to diagnose | BareMetalVI #811/#812, nxnative #2715, MacBox #49, WWDC26-388 |

### C. Fast Track / Hybrid Wine & PS5

| Bottleneck | Affected Chips / Repos | Status | Grade | Proven Fix or Attack Path | Impact | Effort | Refs |
| :--- | :--- | :---: | :---: | :--- | :--- | :---: | :--- |
| **watch.rs alias leak growth (5 -> 309 ms), 96% false-dirty textures & streaming hitches** | M1–M6; MacBox GDK #58, ForjaVI (250–500 ms hitches), VIne, MetalVI | Partial | Verified | Fix Tracked::drop* and title_memory_remapped leaking ~50k alias pages in watch.rs; partition guard tables per memory pool + compact dead aliases (nxnative #2507 kept loads flat at 60–86 ms vs 584 ms); add per-range write-sequence counters & coalesced per-submit snapshots (-71% >=40 ms spikes); port MACBOX_NMT_PAGES=1. | -50 to -250 ms/frame in long sessions; -7.3 ms/frame steady false-dirty work | Low–Med | MacBox #58/#19/#26, nxnative #2507, MTF Recomp |
| **BCPack decode throughput & DirectStorage zero-staging queue starvation** | M1–M6; MacBox GDK #55/#57, ForjaVI, VIne | Tested in donor | Verified | Port MacBox #55 cache-local BC7 tables (48.5 -> 77.8 -> 119.0 MB/s on M5 Max) + #57 allowing zero-staging reads to progress ahead of scratch-blocked requests while preserving completion order; run on QOS_CLASS_UTILITY workers. | Up to 2.45x BC7 decode throughput; smoother driving/streaming p99 | Low–Med | MacBox #55 (2444d73), MacBox #57 (5b18c9f) |
| **~1,500 tiny command buffers/frame & CPU texture byte hashing** | M1–M6; MetalVI (~0.8 FPS, 260–430 ms GPU) | Open | Verified | Coalesce submissions into 4–12 pass-grouped command buffers per frame (keeping each CB safely under macOS's 2.0 s GPU watchdog per nxnative #1788); replace per-frame CPU texture byte hashing with monotonic write-sequence counters + zero-copy linear views. | -200 to -350 ms frame time (5–15x potential lift on MetalVI) | Medium | MetalVI roadmap, nxnative #1788, MacBox #49 |
| **Host descriptor prep & 36–40 ms warm copy-back overhead** | 16–32 GB Macs; VIne (M5 16 GB), 3r1-MetalBridge | Partial | Verified | Use indexed address lookup (VIne WrapTable contributed to 103.2 -> 54.4 ms prep drop) + default persistent MTLBinaryArchive shards (0.62 ms warm hit vs 304 ms miss); port 3r1 #39 pooled readbacks moving map/layout outside shared locks. | -30 to -49 ms host prep / copy-back stalls | Medium | VIne docs/m5-air-metal.md, 3r1-MetalBridge #39 |
| **Mullion IOGPUMetalResidencySet 8+ min kernel deadlock & Rosetta 2 16 KiB MTLHeap mismatch** | 16 GB M5; BetterXen #879/#880 + dttdrv/mullion | Partial | Verified | Drop xmem remap_lock before host D3D12/residency calls (#880 3-step Wrapping record); pre-wire file-backed guest buffers with mlock() outside locks (avoids APFS/IOGPU kernel deadlock in nxnative #2715); round Rosetta 2 MTLHeap sizes to >=16 KiB (KosmicKrisp WA8); fix SGPR provenance join (#877) & expose image_get_lod (#878). | Eliminates unkillable ?E kernel freezes; unlocks 65/87 SM 6.6 pixel shaders on 5.6 GB footprint | Medium | BetterXen #877/#878/#879/#880, nxnative #2715, KosmicKrisp WA8 |
| **PS5 (PPSA38500) AGC -> MoltenVK portability & >16 sampler walls** | All Macs; AnyPS5-ARM, KytyPS5, Metaspero | Open | Hypothesis | Run a synthetic >16-sampler & non-uniform updateAfterBind fixture head-to-head on MoltenVK vs Mesa KosmicKrisp (Vulkan 1.4 conformant on Metal 4); evaluate a two-process Rosetta 2 + native ARM64 KosmicKrisp GPU daemon (ps4mac_port pattern: 21–35 FPS on 8 GB M1). | Bypasses MoltenVK primitive-restart, mesh & descriptor limits | Medium–High | AnyPS5-ARM, KosmicKrisp Vulkan 1.4, ps4mac_port |

---

## 3. Darwin / macOS Memory Traps & Apple Metal Compiler Errata

### 3A. Six Darwin / macOS Kernel & Memory Traps

1. **[Critical] Queue-attached MTLResidencySet triggers 53k–93k/s kernel re-wiring**
   - *Symptom:* 2–3x persistent GPU slow mode (70–87% GPU idle) in ~50% of 16–32 GB runs and 100% of M2 runs; kernel samples stuck in IOGPUMemory::prepare_memory_slow.
   - *Fix:* Remove addResidencySet: from MTLCommandQueue; call useResidencySet: per command buffer (hard cap <=32 sets/CB, ~0.03 ms/frame). Eliminated slow mode in 30/30 M2/M4/M5 runs (nxnative #2715/#2751; also MoltenVK#2890, uzu#988).
2. **[Critical] Missing @autoreleasepool on .contents, read_texels & background PSO threads**
   - *Symptom:* Runaway RAM growth (617 MiB in 86s or 3.7 GB in 30m) on long-lived guest/readback threads — #1 suspect for ~2 GB/min leaks like shitisix.
   - *Fix:* Wrap every readback (MTLBuffer.contents, MACBOX_TEXTURE_BACK=1, fence waiters) and every background Dispatch PSO compile job in an explicit @autoreleasepool (nxnative #195/#2714, MacNativeGames 635fb31).
3. **[High] Darwin mprotect(PROT_NONE) + madvise(MADV_FREE) frees 0 bytes**
   - *Symptom:* Released title memory pools stay 100% resident and dirty (1,024 MiB of 1 GiB untouched), causing premature 16–24 GB OOMs.
   - *Fix:* Overlay released anonymous ranges with a fresh mmap(..., PROT_NONE, MAP_FIXED) (saved 765 MiB in nxnative). NEVER unmap over live GPU device-shared pages or zero-copy MTLBuffers will diverge and hang the GPU.
4. **[High] External USB SSD MTLBinaryArchive copies 3.5–5 GB into RAM**
   - *Symptom:* NSDataReadingMappedIfSafe treats USB APFS drives as unsafe to mmap, loading entire binary archives into Malloc Large RAM.
   - *Fix:* Pass NSDataReadingMappedAlways when opening local shader archives (nxnative PR #1817 cut footprint 19.0 -> 12.2 GB and startup 4.6 -> 3.0 s).
5. **[High] Vertex-only pipelines poison MTLBinaryArchive shards permanently**
   - *Symptom:* Inserting a render/mesh pipeline without a fragment shader succeeds, then serializeToURL: fails forever for the entire shard (MacBox #44).
   - *Fix:* Filter out fragment-less pipelines before archive insertion; on serialization failure keep the last-known-good shard intact on disk and rotate new entries to a fresh shard index.
6. **[High] M3 Pro (macOS 27.3) >=4096x4096 Depth clear poisons queue + endResidency unwire lag**
   - *Symptom:* Clear-only render pass on >=4096x4096 Depth32F throws kIOGPUCommandBufferCallbackErrorOutOfMemory regardless of free RAM (nxnative #2306); endResidency does not unwire pages until a GPU CB executes (llama.cpp #25937); macOS 27 reserves ~24 GiB randomly inside <2^39.
   - *Fix:* Zero large Depth16/32F textures via row-band blits from a 4 MiB shared zero buffer; drain a GPU CB after arena eviction; support relocatable guest VAs crossing 2^39 (<2^40).

### 3B. Apple Metal / MSC Compiler Errata Cheat-Sheet (KosmicKrisp + mach9)

| Code / Ref | Affected Chips & macOS | Compiler Bug | Exact Workaround |
| :--- | :--- | :--- | :--- |
| `KK_WORKAROUND_3 (FB20113490)` | macOS 15.4–26.x (fixed macOS 27) | simd_ballot(true) / quad_any / quad_all inside divergent conditional blocks returns all active threads. | Replace with simd_or(1u << simd_lane_id) or hoist half-wave ballots out of divergent branches (MacBox #31). |
| `KK_WORKAROUND_11 (FB22683138) + MSC MT` | macOS 26.5 + libmetalirconverter.dylib | Concurrent multiple MTL4Compiler instances or multi-threaded IRCompilerAllocCompileAndLink calls corrupt heap memory. | Share strictly ONE MTL4Compiler per MTLDevice; serialize in-process MSC calls with a mutex or isolate DXIL->AIR in multi-process workers. |
| `KK_WORKAROUND_18 (mach9 #116)` | M3–M5, macOS 26 AND still reproduces on macOS 27.2.1 M5 Max | Fragment shaders read stale 0 payload from coherent buffer despite atomic_thread_fence(mem_device|mem_texture, seq_cst) (34 corrupt batches / 4.91M draws). | Insert dependent device load + never-taken duplicate barrier after memory fences (dropped failures to 0 / 1.04M draws). |
| `KK_WORKAROUND_19 (FB25516856)` | M1 & M2 (Apple7/8), macOS 26–27 | High-register indirect compute shaders spill to threadgroup memory where bytes past offset 0 silently read back as 0. | Add a dummy 16-byte [[threadgroup(0)]] parameter with a never-executed read/write to suppress threadgroup register spilling. |
| `KK_WORKAROUND_2 (FB21065475)` | M5 on macOS 27 Beta (re-enabled) | while(true) loops with loop-invariant break conditions crash or infinite-loop Apple's MSL compiler. | Emit for (uint64_t i = 0; i < UINT64_MAX; ++i) instead of while(true). |
| `KK_WORKAROUND_6 & 15` | macOS 26 (WA6) vs macOS 27 (WA15) | macOS 26 breaks threadgroup coherence without coherent on single-thread device loops; macOS 27 miscompiles volatile coherent together. | Gate by OS version: emit coherent on macOS 26, volatile-only on macOS 27. |
| `KK_WORKAROUND_8 (FB22579201)` | Rosetta 2, macOS 26.4–26.5 | MTLHeap.size aligns to 4 KiB while currentAllocatedSize aligns to 16 KiB, breaking validation and GPU capture. | Round all MTLHeap allocation sizes up to multiples of 16 KiB under Rosetta 2. |
| `KK_WORKAROUND_13 & 14 (FB23291220)` | macOS 26.5–27 (WA13 unfixed) | Metal 4 OOB bounds guarantees fail on 16-bit index buffers; relaxed pragma folds NaN * 0.0 -> 0.0. | Pad/validate 16-bit index buffers manually; force safe FP pragma when NaN semantics matter. |
| `KK_WORKAROUND_16 & D16 Clear Bug` | M5 macOS 27 (WA16); M1–M5 D16 Depth | M5 clamps OOB texture LOD instead of returning (0,0,0,1); D16 load-clear 0.5 stores 32767 vs shader 32768 (breaks EQUAL depth test). | Clamp/mask OOB LOD reads on M5; snap D16 load-clear values to nearest 16-bit integer with quarter-unit margin. |
| `Fragment 64-Bit Atomic Spin-Lock (mach9 #91)` | Apple7 (M1) software 64-bit atomics | 4,096-word spin-lock tables deadlock Apple Silicon fragment shaders (2.1M–8.3M timed-out lanes, DEVICE_LOST). | Use >=2^20 words (4 MiB) for fragment lock tables or 2-pass 32-bit min/max; use native HW 64-bit ulong min/max on M2+. |

---

## 4. Official Apple7 (M1) -> Apple11 (M6) Porting Limits (Apple Oct 2026 Feature Set Tables)

| Feature / Limit | M1 (Apple7) | M2 (Apple8) | M3/M4 (Apple9) | M5 (Apple10) | M6 (Apple11) | Porting Impact |
| :--- | :---: | :---: | :---: | :---: | :---: | :--- |
| **64-Bit Atomics (buffers & RG32Uint)** | SW only | HW ulong min/max | Full HW | Full HW | Full HW | M2 runs 64-bit culling/visibility min/max natively on macOS; M1 needs >=2^20 lock table or 2-pass 32-bit. |
| **Compute Forward Progress Guarantee** | No | No | No | No | YES | Never use cross-workgroup GPU busy-wait/spinlocks on M1–M5; safe natively on M6 (Apple11). |
| **FP32 Denormals & Vertex INF/NaN** | No | No | No | No | YES | M6 achieves full IEEE-754 RDNA2 parity; M1–M5 require explicit ftz/NaN guards. |
| **Max Mesh Shader Threadgroups / Grid** | 1,024 | 1,024 | 1,048,575 | 4,194,303 | 4,194,303 | Critical M1/M2 trap: split or batch console mesh grids exceeding 1,024 groups on M1/M2. |
| **Indirect Mesh Draws & ICB Mesh** | No | No | HW Native | HW Native | HW Native | M1/M2 need CPU readback or compute lowering for ExecuteIndirect mesh draws. |
| **Max Samplers in Argument Buffer / Stage** | 996 | 996 | 500,000 | 500,000 | 500,000 | Direct slot cap is 16 (incl. constexpr MSL samplers) on all chips; deduplicate AB samplers <=996 on M1/M2. |
| **Query Texture LOD (image_get_lod)** | Check prop | HW Native | HW Native | HW Native | HW Native | Unlocks 65/87 refused SM 6.6 heap pixel shaders in BetterXen #878. |
| **Sampler Min/Max Reduction & LOD Bias** | Shader emu | Shader emu | Shader emu | HW Native | HW Native | M5/M6 natively accelerate D3D12 Hi-Z min/max samplers and MipLODBias. |
| **Depth Bounds Test & Pre-Raster Vertex Pull** | No | No | No | HW Native | HW Native | Native D3D12 OMSetDepthBounds & GetAttributeAtVertex on M5/M6. |
| **Universal Texture Compression (Compute)** | RT only | RT only | RT only | RT + Compute | RT + Compute | M1–M4 lose lossless compression if shaderWrite is set on RTs; M5/M6 compress compute writes too. |
| **Max MSAA / 2D Texture / Imageblock** | 4x / 16K / 128K | 4x / 16K / 128K | 4x / 16K / 256K | 8x / 32K / 256K | 8x / 32K / 256K | Reject 8x MSAA PSOs before compile on M1–M4 (Mullion #34); M3+ doubles tile imageblock. |
| **Max Residency Sets per Queue or CB** | 32 | 32 | 32 | 32 | 32 | Hard ceiling when designing per-CB useResidencySet: partitioning. |
| **Render Encoder Barrier & RT+Mesh Mix** | Forbidden | Forbidden | Forbidden | Forbidden | Forbidden | No fragment/tile/RT barrier inside MTLRenderCommandEncoder (use pass break or [[color(n)]]); no RT function pointers in mesh pipelines. |

---

## 5. Verified Dead Ends (Negative Results — Do Not Repeat)

- **Blanket clean-table descriptor block reuse & fast twin copy** (*BareMetalVI*): Clean-block reuse recorded 0 hits in world runs; fast twin copy regressed by ~17 ms. **Lesson:** Profile actual dirty-span overlap and slot reuse rates before building coarse table caches.
- **UPLOAD_BUDGET_MB=24 combined with NMT_PAGES=1** (*ForjaVI (M2 Pro 32 GB)*): Dropped FPS to 7.6 (3% <5 FPS), slowed loading, and produced corrupted textures. **Lesson:** Throttling texture uploads arbitrarily breaks title assumptions; fix write-watch contention instead.
- **VICTORY_METAL_HIGH_PRIORITY=2 (promoting texture pool threads)** (*ForjaVI (M2 Pro, 6 P-cores)*): Regressed median FPS (9.9 -> 9.45) and spiked <5 FPS windows from 0% to 11% because 10 high-priority threads oversubscribed 6 P-cores. **Lesson:** Keep high-priority threads strictly <= P-core count; leave detile/BCPack/audio on QOS_CLASS_UTILITY.
- **Unguarded MACBOX_METAL_SERIAL_COMPUTE=0** (*MacBox #39 (M5) & ForjaVI (M2 Pro)*): Turned the entire picture white on M5 (implicit auto-exposure ordering) and dropped M2 Pro from 8.8 -> 7.1 FPS (26% <5 FPS). **Lesson:** Only elide compute barriers proven non-dependent; never drop implicit exposure/luminance ordering.
- **Naive top-mip dropping on mutable textures** (*MacBox #20 (closed by maintainer)*): Prevented 24 GB OOM (17.43 -> 14.57 GiB), but later copies mutated the omitted mip without refreshing sampled views. **Lesson:** Restrict mip-drop strictly to provably immutable read-only textures with safe re-materialization on alias write.
- **Blindly porting discrete-GPU VRAM tricks to Apple Silicon UMA** (*foxhound #586 (+22% PC) & VIctory-xmem #408*): foxhound #586 avoided PCIe round-trips (absent on Apple UMA) while worsening p95 (86 -> 105–111 ms); xmem #408 narrowed barriers but increased CPU planning time. **Lesson:** Always benchmark on real Apple Silicon UMA reporting p95/p99 and CPU+GPU totals, not just dispatch time.
- **Skipping compute PSOs on cold cache & ASYNC_RESIDENCY** (*MacBox #47 (M5 24 GB) & ForjaVI*): Short compute skip budgets (138k skipped) corrupted DoF and foliage across temporal history; ASYNC_RESIDENCY caused title exits. **Lesson:** Always wait for compute PSOs (MACBOX_COMPUTE_BUDGET_MS=3000); only skip non-critical geometry draws if needed.

---

## 6. Neutral Architecture Ceiling Comparison & macOS 27 Profiling Toolkit

| Stack | Active Examples | Fastest Path to 30 Native FPS Today | 16 GB Ceiling | Long-Term M3–M6 Ceiling | Highest-ROI Joint Work |
| :--- | :--- | :--- | :--- | :--- | :--- |
| **Pure ARM64 AOT + Direct Metal** | BareMetalVI, StrongMetal, shitisix, VIvid | 3rd — Blocked by ~110 ms single CPU title lock (GPU floor ~56–59 ms / ~17 FPS on M5 Pro Series X). | 1st (Best) — Zero Wine/Rosetta heap; verified ~12.3 GB total RAM (VIvid) + zero-RAM shaders (StrongMetal). | 1st (Highest) — Zero Rosetta/Wine CPU tax; native ARM64 NEON + Metal 4 parallel encoding -> 30–60+ FPS long-term. | Split the ~110 ms CPU lock onto Metal 4 per-thread allocators + GPU descriptors/detiling; test per-CB useResidencySet: on #811/#812. |
| **Hybrid Wine + Direct Metal (Unix-Call Bridge)** | MacBox GDK, ForjaVI, MetalVI | 1st (Fastest open path) — Already 20–30 FPS M4 Max, ~22–23 FPS M5/M6, 50m 0-crash Retina 3K M5 Max. | 2nd–3rd — Saves ~1 GB vs D3DMetal, but Wine+Rosetta+alias guards still pressure 16–24 GB unless Retina is capped. | 2nd — Direct Metal 4 removes GPU overhead, but Rosetta 2 + Wine sync keep a ~15–25% CPU tax ceiling. | Land watch.rs alias compaction (#58), guarded bvh_lanes (+40% RT), decoupled Retina/MetalFX scaling, and share shader lowering with ARM64. |
| **Hybrid Wine + D3D12-on-Metal DLLs** | VIne (victory-d3d12 + winemetal) | 4th — Pays full Wine + Rosetta + D3D12 DLL marshaling (~66–70 ms prep). | 2nd — Clean 6.0 GB VRAM (~974 MB below D3DMetal) + 0.62 ms MTLBinaryArchive hits on base M5 16 GB. | 3rd — Clean multi-title DLL boundary, but extra COM/DLL translation layer sits below Wine+Rosetta permanently. | Share WrapTable address indexing, MTLBinaryArchive sharding, and shader lowering with MacBox GDK / Mullion. |
| **Wine + D3DMetal 4 / Wine + Mullion** | 3r1-MetalBridge (D3DMetal 4), BetterXen + dttdrv/mullion | 2nd (Conditional) — 3r1 posts 30.25–41.3 FPS (n=1, opt-in 540p internal); Mullion/BetterXen still bringing up 3D. | Split — Closed D3DMetal (~17–18 GB) is heaviest; Mullion unified memory (5.6 GB intro) has strong 16 GB promise. | Split — Closed D3DMetal cannot know console mach_vm_remap aliases; open Mullion + Metal 4 parallel encoding scales better. | Contribute directly to dttdrv/mullion (airconv Wave64/SM 6.6) and Mesa KosmicKrisp (Vulkan 1.4 for PS5/AnyPS5-ARM). |

### Autonomous Profiling & Diagnostic Commands

- **metalperftrace (macOS 27, WWDC26-388):** `metalperftrace collect /tmp --last 5m && metalperftrace overview --aggregate --json` — Retroactive 5-min/multi-hour OS trace isolating GPU clock throttling (~95s fan ramp) vs residency re-wiring vs CPU waits without pre-instrumentation.
- **gpucapture + gpudebug CLI (macOS 27, WWDC26-357):** `gpucapture --help && gpudebug --help` — Headless GPU frame capture and binding/buffer/dispatch inspection for autonomous debugging by devs and AI coding agents without Xcode GUI.
- **MetalFX HUD Live Overrides (macOS 27, WWDC26-357):** `MTL_HUD_ENABLED=1` — Visualizes MetalFX exposure, flags out-of-range jitter red, and flips jitter/motion-vector sign live at runtime (30-second diagnostic for DoF/temporal ghosting).
- **Synthetic BCPack BC7 Benchmark (MacBox #55):** `cargo test --release -p gdk-formats bcpack_throughput -- --ignored --nocapture` — Zero-game-asset microbenchmark to validate single-thread cache-local tables vs 2-worker decode on M1–M6 before touching streaming queues.
- **Commit-to-GPU-Start Gap Telemetry (MacBox #49):** `MACBOX_METAL_STATS=1` — Separates late CPU commits from timely commits stalled behind queued GPU work or background presentation throttling (180–800 ms gaps).
