Repository navigation
Conversation
…ayer of one array or cube texture level, with nothing but state, uniform updates and draws between them (no game barrier, clear, copy or dispatch), run as one layered pass (DM_NVN_SLICE_MERGE, on by default) Breath of the Wild filters its environment cube map every tenth frame in 132 one-draw passes (22 levels of 6 faces, 64x64 to 8x8), and on Apple GPUs a render pass costs about 35-40 us whatever it draws: that frame had 284 render passes instead of about 150 and about 5 ms more GPU time, the regular spike in the Metal HUD's frame-time line. A Metal 4 microbenchmark on the M2 Max: 132 such passes 5.4 ms with the host's barriers, 4.2 ms without, 22 layered passes 0.8 ms. The draw that opens a pass looks ahead (sm_scan, sm_plan): when its only target is one layer of an array or cube level and the following targets switch to other layers of that level, the pass is opened over those layers (renderTargetArrayLength) and OP_SET_RT switches layers inside it. Each draw reaches its layer through a vertex amplification view mapping (count 1, renderTargetArrayIndexOffset); a pipeline with the default maxVertexAmplificationCount 1 ignores the mapping (every draw landed in layer 0), so these draws use pipelines built with 2 (sm_amp_get, AMP_MARK in the key, maxVertexAmplificationCount in the base key), compiled in the background (utility QoS) on first use while the passes stay apart. A draw that samples the attachment, or a clear, ends the merged pass. The encoder thread records the mapping (RO_R_AMP). The residency set line counts merged passes, layer switches and waits for an amplified pipeline. Diagnostics: DM_NVN_TEXDUMP=layers=<n>:path dumps the first frame with at least n draws into single layers of small array or cube levels (the same frame with or without the switch). Measured (Zora's Domain, 900p, FPS 120, M2 Max, back to back, means over 300-frame windows): frame p50 10.51 -> 10.23 ms, p95 13.16 -> 11.11 ms, window max 15.6 -> 12.1 ms, GPU p95 13.0 -> 8.7 ms, frame interval p99 14.3 -> 11.5 ms, 92.6 -> 97.5 fps; the cube filter frame 284 -> 173 render passes. Checked: the cube filter frame's 173 render targets dumped with and without the switch match (105 identical, the rest within 1% RMSE, the scene's rain); screenshots with and without the encoder thread; t_nvn (128 checks) and the tool tests pass. Reference entry in docs/reference/rendering.md, the game's note, the switch in dm/gfx/README.md
…N_CS_HOIST, on by default, 0 turns it off), exact for dispatches that sample the pass's depth: such a dispatch moves only while no draw before it in the pass writes depth Metal cannot run a compute dispatch inside a render pass, so every dispatch between two draws of one pass ends it, and on a tile-based GPU each split stores and reloads every attachment and pays a pass's fixed cost. When a draw opens a pass, cs_hoist_try scans the ops after it up to the first one that would end the pass anyway; each dispatch met on the way runs right away, before the pass opens, when moving it ahead of the draws before it in that stretch changes nothing they read or write: it writes no memory those draws read (vertex, index, indirect, uniform and storage buffers; its storage buffers count as written), samples no colour attachment of the pass, writes no image, and the draws write no memory (no storage buffer, image or transform feedback). Replay then skips it (csh_take), and the pass stays open across it. A dispatch that samples the pass's depth would see it as the pass began, so the scan stops at such a dispatch once a draw of the stretch (the one opening the pass included) has depth writes on. Breath of the Wild's NintendoWare VFX particles run one dispatch per emitter between the effect draws of the G-buffer and of the half-resolution passes, and their collision samples the G-buffer depth: no draw before them writes depth (0 stops of that kind). The residency set line counts moved dispatches, those sampling the pass's depth, and why scans stopped; DM_NVN_PASSDUMP prints H lines. Measured (Zora's Domain, 900p, FPS 120, M2 Max, back to back, means over 300-frame windows, slice merging on in both): compute encoders 28 -> 8 and render passes 149 -> 132 a frame, frame p50 9.92 -> 8.97 ms, p95 10.70 -> 9.98 ms, window max 11.55 -> 10.76 ms, GPU p50 7.69 -> 6.70 ms, frame interval p99 11.1 -> 10.4 ms, 100.8 -> 111.4 fps. Checked: the cube-filter frame's 173 render targets dumped with and without (DM_NVN_TEXDUMP=layers=100) match within 0.7% RMSE for every 3D target (only the 2D overlay of the final picture differed: a loading banner's animation, timed by the wall clock); screenshots of the same scene; t_nvn (128 checks) and the docs test pass. Reference entry in docs/reference/rendering.md, the game's note, the switch in dm/gfx/README.md
Integrate fast shared-event wakeups, per-segment publication, array-slice pass merging, and independent compute dispatch hoisting from the PRs. Serialize CPU completion effects before publishing completed fences and validate recycled post records. Preserve submission order for early waits. Guard scheduling against attachment aliases, first-draw and bindless reads, indirect ranges, stencil writes, and explicit barriers. Add direct Metal regression coverage and a gated CPU completion race test with TSAN. Record final BotW and Metroid Dread gameplay validation with optimizations on and off. BotW retains fewer render passes, but the measured 60 Hz M4 Pro runs do not establish a timing speedup. Keep the original higher-load and iOS performance claims explicitly unverified. Co-authored-by: v0lumehi <[email protected]>
|
Integrated into main in 6062518, co-authored with @v0lumehi. Layered slice merging and independent compute hoisting are retained, with conservative dependency guards. The review confirmed missing hazards in the original optimization checks: the first draw could sample an attachment; aliases with different texture offsets and buffer-backed reads could overlap attachment storage; bindless/indirect accesses could have unknown ranges; stencil writes also create depth-stencil dependencies; and explicit barriers must stop hoisting. The fix checks those cases and preserves separate amplification-capable pipeline bases. The optimizations now have direct tests: Fourteen gameplay benchmark runs of the fixed implementation, before rebasing onto current main, cover BotW outdoors and Metroid Dread with switches on/off. BotW's repeated off/on/on/off comparison retains about 7.3% fewer render passes (158.55 -> 146.94), with both optimizations active. It does not demonstrate a timing win: GPU mean 7.051 -> 7.144 ms, submission CPU 3.456 -> 3.653 ms, both about 60 fps. One direct-encoding pair gave 7.331 -> 7.199 ms GPU time, which is insufficient to establish a repeatable gain. Dread remained about 59.9 fps with no obvious rendering regression, but neither pass optimization activated in that room. All runs completed without a red line or crash. Four further on/off execution checks after integrating current main reached frame 5,000 in BotW and 4,400 in Dread, all without errors. Display-link stalls and incomplete screenshots exclude those extra checks from the gameplay/timing evidence. These M4 Pro / 60 Hz results do not verify the original M2 Max / 120 fps or iPhone gains. Measurements, exact source identities, routes and limits are in the BotW note and Dread note. Closing because the changes and review fixes are now incorporated into main. |
Integrate fast shared-event wakeups, per-segment publication, array-slice pass merging, and independent compute dispatch hoisting from the PRs. Serialize CPU completion effects before publishing completed fences and validate recycled post records. Preserve submission order for early waits. Guard scheduling against attachment aliases, first-draw and bindless reads, indirect ranges, stencil writes, and explicit barriers. Add direct Metal regression coverage and a gated CPU completion race test with TSAN. Record final BotW and Metroid Dread gameplay validation with optimizations on and off. BotW retains fewer render passes, but the measured 60 Hz M4 Pro runs do not establish a timing speedup. Keep the original higher-load and iOS performance claims explicitly unverified. Co-authored-by: v0lumehi <[email protected]>
On Apple GPUs a render pass costs about 35–40 µs whatever it draws. Breath of the Wild has two patterns that create many passes. These commits remove them in the host, in a general form.
1. Slice-merged passes (
DM_NVN_SLICE_MERGE, on by default)Every tenth frame, BotW filters its environment cube map in 132 one-draw passes (22 levels × 6 faces, 64×64 down to 8×8). That frame had 284 render passes instead of ~150 and about 5 ms more GPU time. It shows as the regular spike in the Metal HUD's frame-time line.
renderTargetArrayIndexOffset).maxVertexAmplificationCountof 1 ignores the mapping, so these draws use pipelines built with 2. They compile in the background on first use, and the passes stay separate until then.2. Compute dispatches run ahead of the pass (
DM_NVN_CS_HOIST, on by default)Metal can't run a dispatch inside a render pass, so every dispatch between two draws ends the pass. On a tile-based GPU, each split stores and reloads every attachment and pays a pass's fixed cost. BotW's NintendoWare VFX particles run one dispatch per emitter between the effect draws of the G-buffer and half-resolution passes.
Measured
Mac, M2 Max, Zora's Domain, 900p, fps target 120. Each switch was run back to back off/on; values are means over 300-frame windows. Load averages were 4–10 during these runs, and differences of ~0.3 ms in p50 are within noise there. The two pairs ran at different times, so their baselines differ.
So the merge removes the spike (p95), and the hoist brings most of the p50 gain.
iPhone 17 Pro Max, manual play in the open world (not a fixed route, so only an indication):
Not measured: 4K, and games other than BotW.
Checked
DM_NVN_TEXDUMP=layers=100).dmhostfor three profiles, the iOS compile check and the tool tests pass.t_nvnpasses with BotW's profile (152 checks).Diagnostics and docs
DM_NVN_PASSDUMPprintsHlines for moved dispatches.DM_NVN_TEXDUMP=layers=<n>:<path>dumps the first frame with at least n draws into single layers of small array or cube levels.docs/reference/rendering.mdand the symptom index, the game's note, and both switches indm/gfx/README.md.