Repository navigation
Pulling vertex shader variants in the translation chain (<key>_bp) - #123
Merged
Merged
Conversation
v0lumehi
force-pushed
the
pso-b-pull
branch
3 times, most recently
from
October 24, 2026 17:28
494a2f7 to
dbb31de
Compare
This was referenced Oct 25, 2026
Closed
v0lumehi
force-pushed
the
pso-b-pull
branch
2 times, most recently
from
October 25, 2026 12:42
bfc55d9 to
86b21c4
Compare
v0lumehi
added a commit
to v0lumehi/nxnative
that referenced
this pull request
Oct 25, 2026
… change) nvn_mtl.m (9,473 lines) keeps its includes, the residency set, deferred release, mtl_init and the memory pools (557 lines with the include lines); the rest moved, in contiguous blocks and in the original order, into 14 files nvn_mtl_<topic>.inc beside it that nvn_mtl.m #includes at the place they were cut from: submit, ubuf, tex, pass, shader, state, pso, args, lookahead, merge, indirect, draw, shot, present. One translation unit, every static still shared; the Makefiles, tests (MTL_T_SRC) and the iOS project compile the same single file. The .inc extension (as nvn_geometry.inc and rt_range_check.inc) keeps the parts out of the Makefiles' nvn/*.m wildcard; dm/host/Makefile's GFX_H already lists nvn/*.inc on main, so make rebuilds when a part changes. Each part opens with a comment saying what it holds; dm/gfx/README.md lists the parts. Cut again on main with the pipeline series (seedds#123-seedds#125): the parts start at the same top-level blocks as before. Checked, against the same tree unsplit: - The parts with their header comments removed, put back in place of the include lines, give the unsplit nvn_mtl.m byte for byte. - clang -E -P of nvn_mtl.m with the host's flags (Mac) and with iOS flags (arm64-apple-ios18.0, apple-a18): identical text apart from the line number argument of res_add_at (35 sites, __LINE__ now counts from the part's top; the sites stay distinct). - Object code (otool -tvV of nvn_mtl.m compiled with the Makefile's flags): the same instructions at the same addresses on both platforms; the only differences are those line immediates. Same compiler warnings.
v0lumehi
force-pushed
the
pso-b-pull
branch
3 times, most recently
from
October 25, 2026 23:41
3b378b5 to
dd7cd3f
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.
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
A side library for every vertex shader with stage inputs, as
<key>_bvis. Itsmain0/main0_zhave no[[stage_in]]and read their inputs from a per-draw layout block at buffer 16. The block holds, per stream, the base address, stride and divisor, and per NVN attribute its state word; the base instance comes from[[base_instance]].dm_fetch(dmsh_pull.metal) decodes the NVN format at run time into the register words Maxwell's fetch gives, so the shader body runs unchanged. A pipeline made with it has no vertex descriptor and serves every vertex layout a pair is drawn with.Why
A draw can then use the pair's pipeline while the pipeline for its own vertex layout is still being built (the hybrid pipelines in the next PR).
Correctness
The words are bit-identical to Metal's vertex-descriptor fetch for every format
vfmtknows, and to the host's CPU conversion for the integer-read-as-float formats:unpack_*builtins; a plain division under fast math is one ULP off for up to half the values;base + (instance - base) / divisor.Positions are
[[invariant]]and built with preserved invariance. Transform feedback, geometry capture and layer entries get no variant.Cost
The run-time decode makes a vertex-bound draw with 8 attributes 65 % slower on an M2 Max, about 1 ms per million vertices, so the variant only bridges frames.
The iOS app does not use the variants yet, so
build_ipa.shleaves the_bplibraries out of the IPA unlessIOS_PULL=1(pack_ipa.py --skip-suffix).Numbers
Breath of the Wild's full Mac build took 25 min (a full retranslation: the chain fingerprint changed):
Checked
t_pull.m(304 checks): 76 formats; 73 comparisons with Metal's fetch at aligned, 2-byte and stride-1 placements; 24 comparisons with the CPU conversion; stride 0 and divisors.t_pull_inv.m: 2,000 random triangles, a depth prepass with one pipeline and depth-equal with the other, both ways round.test_dmsh_pull.py: compiles for macOS and iOS.pack_ipa.py --skip-suffixby hand.Not checked
IOS_PULL=1.