Repository navigation
Hybrid pipelines: draw with the pair's pulling pipeline while the draw's own pipeline is built, on #75's demand-first builds - #124
Merged
Conversation
This was referenced Oct 24, 2026
Contributor
Author
|
A question about the docs: this PR adds a Mermaid diagram of the miss path to
|
v0lumehi
force-pushed
the
pso-c-hybrid
branch
3 times, most recently
from
October 24, 2026 17:28
5b4420a to
355ee08
Compare
v0lumehi
force-pushed
the
pso-c-hybrid
branch
2 times, most recently
from
October 25, 2026 04:48
a8f75e7 to
e3f84e0
Compare
v0lumehi
force-pushed
the
pso-c-hybrid
branch
5 times, most recently
from
October 25, 2026 23:41
a92c5fe to
fe6fe30
Compare
…sh_pull.py with its decoder dmsh_pull.metal)
A side library of every vertex shader with stage inputs, as <key>_bv is, whose main0 / main0_z have no [[stage_in]] and read their inputs from a per-draw layout block at buffer 16: per stream the base address, stride and divisor, per NVN attribute its state word, the base instance from [[base_instance]] (so indirect draws are right too). dm_fetch decodes the NVN format at run time into the register words Maxwell's fetch gives the shader, and the input takes them with as_type, so the body runs unchanged. A pipeline built with it has no vertex descriptor and serves every vertex layout the pair is drawn with; the hybrid pipelines (next change) draw with it while a draw's own pipeline is built.
The words are bit-identical to Metal's vertex-descriptor fetch for every format nvn_mtl.m vfmt knows and to the host's CPU conversion for the integer-read-as-float formats: unorm / snorm through the unpack builtins (a plain division under fast math is a unit in the last place off for up to half the values), R11G11B10F NaNs canonical as from Metal, divisors with Metal's rule base + (instance - base) / divisor. Positions are [[invariant]] and built with preserved invariance, so a pulling pipeline and the vertex-descriptor one compute the same positions. Transform feedback, geometry capture and layer entries get no variant; shaders without stage inputs need none. The run-time decode costs GPU time: +65 % of a vertex-bound draw with 8 attributes on an M2 Max, about 1 ms per million vertices, so it is meant only to bridge the frames until the draw's own pipeline is built.
The iOS app does not use the variants yet (the Metal 4 path is off on iOS by default), so build_ipa.sh leaves the _bp libraries out of the IPA unless IOS_PULL=1 (pack_ipa.py --skip-suffix).
Chain version 8393d85a4eae (on main's 20fe3d62b9f6). Breath of the Wild's full Mac build on chain 97e2f301eb73 (25 min, a full retranslation since the code fingerprint changed): 19,592 shaders ok, 8,888 pulling libraries generated (275 MB), none failed, 43 vertex shaders without stage inputs; every existing library is byte-identical to the previous build (19,592 _b.metallib and _b.metal, 6,254 _bf, 1,070 _bv). Other profiles' shaders were not rebuilt.
Tests: t_pull.m (304 checks: the 76 formats vfmt knows, 73 comparisons with Metal's fetch at aligned, 2-byte and stride-1 placements, 24 with the CPU conversion, stride 0 and divisors 1-3 with a base instance), t_pull_inv.m (2,000 random triangles: a depth prepass with one pipeline and depth-equal with the other passes every covered pixel, both ways round) and test_dmsh_pull.py (the generator: entries, ids it adds or keeps, entries left out, shaders declined; compiles for macOS and iOS); pack_ipa.py's --skip-suffix checked by hand. The other graphics tests and the host unit tests give the results they give on main. docs/reference/rendering.md ("Pulling vertex inputs") describes the variant and its cost; AGENTS.md lists the new chain files.
…ts shader pair's pulling pipeline meanwhile, on main's demand-first pipeline builds On a miss the draw first takes its pipeline without compiling (its base made or in the archive, then a specialization). Failing that it draws with the pair's pulling pipeline (<key>_bp: no vertex descriptor, the streams read through a per-draw layout block at buffer 16, pull_bind), specialized with the draw's colour state, while its own pipeline is built in the background; a later draw takes that one. Both compute the same positions (t_pull_inv), so a draw that switches does not flicker or z-fight. Only a pulling base already made or archived is used; otherwise it is built in the background for the pair's next miss and the draw waits. Merged passes, readable-tile and diagnostic fragments, and layer-writing or transform feedback vertex shaders have no stand-in. DM_PSO_HYBRID=0 turns it off; it needs the Metal 4 path, so it is on by default on the Mac only. On main's demand-first pipelines (seedds#75): pso_pend_kick stays the speculative admission (at most two running, at most two per prediction, the oldest finished entry reclaimed when the table is full). A draw with a stand-in queues its own pipeline before the prediction runs (pso_pend_demand): outside the speculative limit, on serial queues at utility QoS, one per two performance cores (pp_bg_queue), so a demanded build never waits behind speculation and speculation never waits behind it. The prediction spends its budget only on draws that will have no stand-in, since only those would wait. A draw that would wait for a build still queued makes the pipeline itself at once (pso_pend_take; Breath of the Wild's cold start waited 0.5-0.9 s for one pipeline behind a burst before). The first miss of a submission loads the shader libraries the rest of it binds in parallel (shader_prefetch_rest): 248 libraries in about 210 ms where one by one on the submit thread took about 1 s, in the hybrid and the waiting path alike. Diagnostics: a "pipelines up to frame" line every 300 frames (submit-thread pipeline, library and prediction time, archive lookups, specializations, base compiles, hybrid draws, background builds, the draws that waited and why), DM_PSO_WAITLOG=1 (each wait over 20 ms with its pair), DM_PSO_PULL_ALL=1 (every draw with a pulling pipeline draws with it), and the longframe line's count of hybrid draws. Breath of the Wild, Mac (M2 Max), steady state in Zora's Domain: mean GPU p50 over frames 2,400-5,100 was 8.98 ms with the hybrid, 8.98 ms on the Metal 4 path without it, 9.35 ms through the MTLDevice. Cold-start numbers are with the prebuild of the next change. Tests: t_pull (346 checks, now also the layout block the host fills), t_pull_inv, t_pso_pending (48) and t_pso_archive (32) pass; the other graphics tests and the host unit tests give the results they give on main. docs/development.md ("Hybrid pipelines") and dm/gfx/README.md describe it.
…nd specialization, pulling stand-in with the draw's own pipeline queued first, or a build at once with the bounded prediction)
v0lumehi
force-pushed
the
pso-c-hybrid
branch
from
October 26, 2026 00:53
fe6fe30 to
8593d85
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On a pipeline miss the draw first takes its pipeline without compiling: its base made already or in the archive, then a specialization. Failing that, it draws with the pair's pulling pipeline (
<key>_bp,pull_bind), specialized with the draw's colour state, while its own pipeline is built in the background; a later draw takes that one. Both compute the same positions, so a draw that switches neither flickers nor z-fights. Only a pulling base already made or archived is used; otherwise the draw waits, as before, and the base is built for the pair's next miss. Merged passes, readable-tile and diagnostic fragments, and layer-writing or transform feedback vertex shaders have no stand-in.DM_PSO_HYBRID=0turns it off. It needs the Metal 4 path, so it is on by default on the Mac only.Miss path
flowchart TD D[Draw needs a pipeline] --> C{In the cache?} C -- yes --> R[Draw with it] C -- no --> B{Base made already<br/>or in the archive?} B -- yes --> S[Specialize, a few µs] --> R B -- no --> P{Pulling stand-in<br/>for the pair?} P -- yes --> H[Draw with the pulling pipeline now] H --> Q[Queue the draw's own pipeline first<br/>pso_pend_demand, low priority] Q -. later draws .-> R P -- no --> W[Build at once and wait<br/>as on main after #75] W --> R W --> K[Then predict: at most 2 speculative builds,<br/>only for draws without a stand-in]How it builds on #75 (demand-first)
pso_pend_kickstays the speculative admission as NVN: prioritize demanded PSOs and bound speculative precompile #75 made it: at most two running, at most two per prediction, and the oldest finished entry reclaimed when the table is full.t_pso_pendingpasses unchanged.pso_pend_demand). Demanded builds are outside the speculative limit and run on serial queues at utility QoS, one per two performance cores (pp_bg_queue). A demanded build never waits behind speculation, and speculation never waits behind it.pso_pend_take). Breath of the Wild's cold start had waited 0.5–0.9 s for one pipeline behind a burst.shader_prefetch_rest). This helps the waiting path too: 248 libraries took about 210 ms, where loading them one by one on the submit thread took about 1 s.Diagnostics
pipelines up to frameline every 300 frames: submit-thread pipeline, library and prediction time; archive lookups; specializations; base compiles; hybrid draws; background builds; the draws that waited, and why.DM_PSO_WAITLOG=1logs each wait over 20 ms with its pair.DM_PSO_PULL_ALL=1makes every draw that has a pulling pipeline draw with it.Numbers
Breath of the Wild, Mac (M2 Max), Zora's Domain. Steady-state GPU p50 over frames 2,400–5,100: 8.98 ms with the hybrid, 8.98 ms without it, 9.35 ms through the
MTLDevice. The cold-start numbers need the next PR's prebuild.Checked
t_pull(346 checks, now also the layout block the host fills),t_pull_inv,t_pso_pending(48) andt_pso_archive(32).Not checked