MetalWatch VI / Apple Silicon Porting Playbook
ENGINEERING DOSSIER (v1.0) · UPDATED

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.

10 Quick Wins 18 Bottlenecks (3 Tracks) 6 Darwin Traps 10 Compiler Errata 7 Dead Ends
LIVING AI AGENT PLAYBOOK · RAW MARKDOWN · CONTINUOUSLY UPDATED Zero Game Files · Pure Engineering

Living AI Agent Dossier — Feed Straight to Claude Code, Antigravity or Codex

Every verified cross-repo quick win, Darwin memory bomb, Apple Metal compiler erratum, Apple7–Apple11 hardware limit, and dead-end experiment is compiled into one continuously updated plain-Markdown file at /playbook.md. Copy or curl it into your coding agent before hunting a bottleneck.

Open raw /playbook.md ↗
curl -sL https://metalwatch-vi.github.io/playbook.md
Agent Quick-Start Protocol (5 Rules embedded in /playbook.md)+
  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.
BLOCK 1 · CROSS-REPO TRANSFER MATRIX (LOW EFFORT -> HIGH GAIN)

Top 10 Quick-Win Patches Worth Porting

Fixes already verified in one Apple Silicon repo or Metal 4 driver that remain missing in sibling ports. Respect caveats before toggling.

1. Guarded bvh_lanes RT traversal (+40% RT FPS)

Verified
-16 to -18 ms GPU (+40% indoor RT FPS: 16.2–17.4 -> 22.9–24.1 FPS on M4 Max)

Targets: MacBox GDK, ForjaVI, BareMetalVI, VIvid, VIa, MetalVI. 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
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)

Targets: BareMetalVI (#811/#812), StrongMetal, BetterXen (#879), VIvid. 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
Drops Apple 9 mesh XPC register-allocator refusals from 2 -> 0 on M4 Max with zero compute rewrite

Targets: MacBox GDK (M4 Pro/Max), ForjaVI, VIne, MetalVI. 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
BC7 decode 48.5 -> 77.8 -> 119.0 MB/s on M5 Max (2.45x); #57 unblocks zero-staging reads (22/22 storage tests)

Targets: ForjaVI, BareMetalVI (#953), VIne, MetalVI, VIvid. 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
Eliminates 1–3 FPS driving freezes (20–30 FPS M4 Max) and targets 5 -> 309 ms lock growth & 96% false-dirty texture churn

Targets: MacBox GDK, ForjaVI, VIne, MetalVI. 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
Fixes MetalFX temporal GPU timeouts; saves 3–6 GB RAM & eliminates 24–36 GB Retina OOM/black screens

Targets: ForjaVI, VIne, MetalVI, BetterXen, 3r1-MetalBridge, MacBox GDK. 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
Fixes black/flat-colour 3D worlds across both M1/M2 (Apple7/8) and M3/M4 (Apple9) GPUs

Targets: ForjaVI, VIne, MetalVI, MacBox GDK, VIvid, BetterXen. 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
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)

Targets: ForjaVI, VIne, MetalVI, native MetalFX backends. 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
Caps wired growth (~25–27 GB steady vs 44 GB OOM); cold compute lock holds drop 2.9 s -> 23 ms; 2h15m leak-free

Targets: shitisix (~2 GB/min leak), BareMetalVI (#991), MacBox GDK (#47), VIvid. 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
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)

Targets: Direct Metal backends (only after per-pass barrier classification). 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).
BLOCK 2 · THREE-TRACK ENGINEERING MATRIX

Remaining Walls Blocking 30–60 Native FPS & 16 GB

Filter by Shared Apple Silicon GPU/UMA, Pure ARM64 (Zero Wine), or Fast Track / Hybrid Wine & PS5.

TrackBottleneck & AffectedStatus / Grade Proven Fix or Attack PathEst. ImpactEffort
Shared GPU/Metal
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).
Refs: nxnative #2715/#2751, KosmicKrisp WA20, BetterXen #879/#880, StrongMetal
2–4x FPS recovery; eliminates 16 GB panics & 8m deadlocks; -2–5 GB wiredLow–Med
Shared GPU/Metal
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.
Refs: Metal 4 VisibilityOptions, MacNativeGames, MacBox GDK #43
Eliminates ~4% stale textures and silent aliased-memory corruptionLow–Med
Shared GPU/Metal
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).
Refs: Apple Tech Talk 111431, Apple Texture Docs, MacNativeGames, nxnative #1860/#2574
-10 to -25 ms GPU (~20–35% GPU speedup); -0.5–1.5 GB RAMMedium
Shared GPU/Metal
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.
Refs: MacBox #44/#47, WWDC26-356 (Cyberpunk 2077), nxnative
-3 to -6 GB RAM (4x fewer pixels on scaled RTs); removes 24/36 GB OOM & 40 FPS capLow
Shared GPU/Metal
>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.
Refs: Apple Feature Tables (Oct 2026), KosmicKrisp, BetterXen #877/#878, BareMetalVI #914
Unlocks 179–636 refused shaders & removes sampler fallback bugsMedium
Shared GPU/Metal
>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.
Refs: MacBox #41, 3r1 #38, MetalVI, Apple Feature Tables p. 9, Mesa libpoly
Eliminates M4 Pro compiler crashes & missing interior geometryLow–Med
Shared GPU/Metal
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).
Refs: MacBox #53, BareMetalVI #920/#405, xmem #429, mach9 #91, Apple Tables p. 6
-16 to -18 ms GPU in RT scenes; crash-free RTGI & M1/M2 cullingLow–Med
Pure ARM64
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).
Refs: BareMetalVI #46/#997, Mullion 17f8ffd, nxnative #3554, VKD3D-Proton
-50 to -85 ms CPU (2–3x FPS lift toward ~17+ FPS GPU floor)Med–High
Pure ARM64
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.
Refs: BareMetalVI #953, Native-Victory #556, ReVIctory #37, Apple CPU Tech Talk
-5 to -15 ms CPU; eliminates E-core demotion & improves 1% lowsLow
Pure ARM64
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).
Refs: nxnative #195/#2714, MetalVI #27, ForjaVI, llama.cpp #25937
Eliminates >40 GB session leaks & 10s hold_list stallsLow
Pure ARM64
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.
Refs: StrongMetal, BareMetalVI, MacNativeGames f3e2f66, WWDC25-254
Eliminates multi-second lock convoys; -1 to -3 GB RAMLow–Med
Pure ARM64
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.
Refs: BareMetalVI #811/#812, nxnative #2715, MacBox #49, WWDC26-388
Recovers 2–4x frame rate in affected runsLow to diagnose
Fast Track / Hybrid
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.
Refs: MacBox #58/#19/#26, nxnative #2507, MTF Recomp
-50 to -250 ms/frame in long sessions; -7.3 ms/frame steady false-dirty workLow–Med
Fast Track / Hybrid
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.
Refs: MacBox #55 (2444d73), MacBox #57 (5b18c9f)
Up to 2.45x BC7 decode throughput; smoother driving/streaming p99Low–Med
Fast Track / Hybrid
~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.
Refs: MetalVI roadmap, nxnative #1788, MacBox #49
-200 to -350 ms frame time (5–15x potential lift on MetalVI)Medium
Fast Track / Hybrid
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.
Refs: VIne docs/m5-air-metal.md, 3r1-MetalBridge #39
-30 to -49 ms host prep / copy-back stallsMedium
Fast Track / Hybrid
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).
Refs: BetterXen #877/#878/#879/#880, nxnative #2715, KosmicKrisp WA8
Eliminates unkillable ?E kernel freezes; unlocks 65/87 SM 6.6 pixel shaders on 5.6 GB footprintMedium
Fast Track / Hybrid
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).
Refs: AnyPS5-ARM, KosmicKrisp Vulkan 1.4, ps4mac_port
Bypasses MoltenVK primitive-restart, mesh & descriptor limitsMedium–High
BLOCK 3 · PLATFORM LANDMINES & COMPILER BUGS

Darwin Memory Traps & Apple Metal Compiler Errata

Primary-source macOS kernel memory traps (nxnative, llama.cpp, MacBox) and verified MSL/Metal compiler bugs (KosmicKrisp KK_WORKAROUND_* & mach9).

Queue-attached MTLResidencySet triggers 53k–93k/s kernel re-wiring

Critical

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).

Missing @autoreleasepool on .contents, read_texels & background PSO threads

Critical

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).

Darwin mprotect(PROT_NONE) + madvise(MADV_FREE) frees 0 bytes

High

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.

External USB SSD MTLBinaryArchive copies 3.5–5 GB into RAM

High

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).

Vertex-only pipelines poison MTLBinaryArchive shards permanently

High

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.

M3 Pro (macOS 27.3) >=4096x4096 Depth clear poisons queue + endResidency unwire lag

High

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).

Erratum / CodeAffected Chips & OSCompiler BugExact 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 MTmacOS 26.5 + libmetalirconverter.dylibConcurrent 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 MaxFragment 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–27High-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 & 15macOS 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.5MTLHeap.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 BugM5 macOS 27 (WA16); M1–M5 D16 DepthM5 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 atomics4,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+.
BLOCK 4 · APPLE METAL FEATURE SET TABLES (OCT 23, 2026)

Official Apple7 (M1) -> Apple11 (M6) Porting Limits

Hard silicon capabilities and ceilings that dictate shader lowering, mesh grid splitting, and residency partitioning across M1–M6.

Hardware Feature / LimitM1 (A7)M2 (A8) M3/M4 (A9)M5 (A10)M6 (A11)Porting Impact
64-Bit Atomics (buffers & RG32Uint)SW onlyHW ulong min/maxFull HWFull HWFull HWM2 runs 64-bit culling/visibility min/max natively on macOS; M1 needs >=2^20 lock table or 2-pass 32-bit.
Compute Forward Progress GuaranteeNoNoNoNoYESNever use cross-workgroup GPU busy-wait/spinlocks on M1–M5; safe natively on M6 (Apple11).
FP32 Denormals & Vertex INF/NaNNoNoNoNoYESM6 achieves full IEEE-754 RDNA2 parity; M1–M5 require explicit ftz/NaN guards.
Max Mesh Shader Threadgroups / Grid1,0241,0241,048,5754,194,3034,194,303Critical M1/M2 trap: split or batch console mesh grids exceeding 1,024 groups on M1/M2.
Indirect Mesh Draws & ICB MeshNoNoHW NativeHW NativeHW NativeM1/M2 need CPU readback or compute lowering for ExecuteIndirect mesh draws.
Max Samplers in Argument Buffer / Stage996996500,000500,000500,000Direct 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 propHW NativeHW NativeHW NativeHW NativeUnlocks 65/87 refused SM 6.6 heap pixel shaders in BetterXen #878.
Sampler Min/Max Reduction & LOD BiasShader emuShader emuShader emuHW NativeHW NativeM5/M6 natively accelerate D3D12 Hi-Z min/max samplers and MipLODBias.
Depth Bounds Test & Pre-Raster Vertex PullNoNoNoHW NativeHW NativeNative D3D12 OMSetDepthBounds & GetAttributeAtVertex on M5/M6.
Universal Texture Compression (Compute)RT onlyRT onlyRT onlyRT + ComputeRT + ComputeM1–M4 lose lossless compression if shaderWrite is set on RTs; M5/M6 compress compute writes too.
Max MSAA / 2D Texture / Imageblock4x / 16K / 128K4x / 16K / 128K4x / 16K / 256K8x / 32K / 256K8x / 32K / 256KReject 8x MSAA PSOs before compile on M1–M4 (Mullion #34); M3+ doubles tile imageblock.
Max Residency Sets per Queue or CB3232323232Hard ceiling when designing per-CB useResidencySet: partitioning.
Render Encoder Barrier & RT+Mesh MixForbiddenForbiddenForbiddenForbiddenForbiddenNo fragment/tile/RT barrier inside MTLRenderCommandEncoder (use pass break or [[color(n)]]); no RT function pointers in mesh pipelines.
BLOCK 5 · VERIFIED NEGATIVE RESULTS

Dead Ends — Save Yourself 2 Days

Approaches already benchmarked on Apple Silicon that recorded zero gain, visual corruption, or frame-time regressions.

Blanket clean-table descriptor block reuse & fast twin copy

BareMetalVI

Observed failure: 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)

Observed failure: 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)

Observed failure: 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)

Observed failure: 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)

Observed failure: 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

Observed failure: 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

Observed failure: 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.
BLOCK 6 · NEUTRAL STACK COMPARISON & MACOS 27 TOOLING

Architecture Ceilings & Autonomous Profiling Toolkit

Objective engineering trade-offs across all four active Mac compatibility architectures, plus zero-GUI macOS 27 CLI profiling commands.

StackFastest Path to 30 Native FPS16 GB Ceiling Long-Term M3–M6 CeilingHighest-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).
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).