Repository navigation
Conversation
This was referenced Oct 24, 2026
v0lumehi
force-pushed
the
pso-a-archive
branch
from
October 24, 2026 12:50
3874d53 to
4f6e048
Compare
This was referenced Oct 24, 2026
Closed
v0lumehi
force-pushed
the
pso-a-archive
branch
from
October 24, 2026 17:18
4f6e048 to
81535e6
Compare
… colour state unspecialized, specialized per colour state, and a per-game pipeline archive of the bases pso_desc still describes each pipeline. pso_build turns it into an MTL4RenderPipelineDescriptor whose colour attachments (format, blending, factors, operations, write mask) are unspecialized, builds that base once and makes each pipeline from it by specialization: about 4 µs on an M2 Max, where a pipeline whose colour state alone differed took 3-5 ms to build. Metal 4 pipelines name no depth or stencil format, so one base serves every depth / stencil attachment. Breath of the Wild's 4,829 recorded pipeline keys came from 1,818 bases, and 2,845 of the keys differed only in the blend factors of targets whose blending was off, which the key no longer holds (pso_key_norm; the depth / stencil formats stay in the key for pipelines built through the MTLDevice). MTL4Compiler takes function descriptors, so every function made from a library is noted with its library, entry name and constant values as it is made (fn4_note), keyed by identity. A function with no note (the diagnostic DM_NVN_HILITE and DM_NVN_MAGSCAN overrides) keeps the MTLDevice path, and so does a device without a Metal 4 compiler (t_pso_pending's fake device). The archive: pso_archive/ beside pso_user.tsv, files written by an MTL4PipelineDataSetSerializer that captures binaries only (with the descriptor capture as well it writes no archive and reports no error). Each flush (after the prewarm, and 10 s after a burst of new bases) writes what was captured since the one before; at start every file is opened and a base found in one is taken from it directly, about 0.06 ms against 10-80 ms to build one. Compiles hold a read lock and a flush the write lock (g_arch_rw): a compile that finished during a flush crashed in Metal. With more than 8 files the archive is compacted: the bases the prewarm takes from them are taken again through the compiler with those files as its lookup archives, which captures them, the flush after the prewarm writes them into one file and the old files are removed (Breath of the Wild wrote 5-7 files per start). On by default on the Mac only. On iOS DM_PSO_MTL4=1 turns it on: the archive's memory is not measured against an iPhone's limit yet, and metal-tt rejects the Metal 4 serializer's pipeline script, so no archive can be made offline for an iPhone. DM_PSO_MTL4=0 builds through the MTLDevice as before; DM_PSO_ARCHIVE=off or =<folder>. Tests: t_pso_archive (32 checks, validation layer on): pipelines differing only in colour state share one base and draw the same pixels as pipelines built through the MTLDevice, into a pass with a depth attachment the base does not name; a flushed archive file gives the base back without compiling; an unregistered function keeps the MTLDevice path; the key normalization; compaction of nine files into one that gives every base back without compiling. t_pso_pending passes (48). The other graphics tests give the results they give on main here (t_refl, t_fuse_check, t_reorder_chain, t_defer_chain, t_mip_extent, t_rt_range_ro and t_rt_range fail on main as well); the host unit tests pass. docs/development.md and dm/gfx/README.md describe the bases and the archive.
v0lumehi
force-pushed
the
pso-a-archive
branch
from
October 24, 2026 17:28
81535e6 to
a92ac67
Compare
seedds
added a commit
that referenced
this pull request
Oct 25, 2026
Adapt PR #122: compile reusable bases with unspecialized colour state, specialize per draw state, and persist bases between launches. Keep iOS opt-in and the MTLDevice fallback. Preserve rasterizing depth-only pipelines through the legacy path. Share in-progress base builds, including errors, while unrelated bases compile in parallel. Defer timed flushes during compaction and finish flush/cleanup together; synchronize the pending count with serializer capture. Checked on Apple M4 Pro: t_pso_archive 48 checks with Metal validation, t_pso_pending 48, t_integer_blend 63, t_geometry 95, and t_pso_skey pass. The Breath of the Wild Mac host builds and nvn_mtl.m passes the iOS arm64 syntax check. Real-game memory usage and iPhone runtime behavior were not measured. Co-authored-by: v0lumehi <[email protected]>
Owner
|
Landed on main in 66abbc3, with co-author credit to @v0lumehi. Thanks for the pipeline-base and archive implementation. The landed version includes these fixes:
Checked on an Apple M4 Pro: t_pso_archive passes 48 checks with Metal validation enabled, t_pso_pending 48, t_integer_blend 63, t_geometry 95, and the pipeline-key round-trip tests pass. The Breath of the Wild Mac host builds, and nvn_mtl.m passes the iOS arm64 syntax check. Real-game memory usage and iPhone runtime behavior remain unmeasured; iOS stays opt-in. Closing this PR because its implementation, with the fixes above, is now on main. |
Know-It-All-Brother
pushed a commit
to Know-It-All-Brother/nxnative
that referenced
this pull request
Nov 9, 2026
Adapt PR seedds#122: compile reusable bases with unspecialized colour state, specialize per draw state, and persist bases between launches. Keep iOS opt-in and the MTLDevice fallback. Preserve rasterizing depth-only pipelines through the legacy path. Share in-progress base builds, including errors, while unrelated bases compile in parallel. Defer timed flushes during compaction and finish flush/cleanup together; synchronize the pending count with serializer capture. Checked on Apple M4 Pro: t_pso_archive 48 checks with Metal validation, t_pso_pending 48, t_integer_blend 63, t_geometry 95, and t_pso_skey pass. The Breath of the Wild Mac host builds and nvn_mtl.m passes the iOS arm64 syntax check. Real-game memory usage and iPhone runtime behavior were not measured. Co-authored-by: v0lumehi <[email protected]>
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
Render pipelines are built through Metal 4's
MTL4Compiler.pso_buildturnspso_desc's descriptor into a base whose colour attachments (format, blending, factors, operations, write mask) are unspecialized. It builds that base once and makes every pipeline from it by specialization. The bases go into a per-game archive (pso_archive/besidepso_user.tsv): one file per flush, written by anMTL4PipelineDataSetSerializerthat captures binaries only. Every file is opened at start, and a base found in one is taken from it directly. Once there are more than 8 files, the archive is compacted: the bases the prewarm takes from the old files are captured again through the compiler, written into one file, and the old files are removed. Compiles and flushes are serialized by a read-write lock.Why
A pipeline whose colour state alone differed took 3–5 ms to build; a specialization takes about 4 µs on an M2 Max. A base taken from the archive costs about 0.06 ms, against 10–80 ms to build one. Breath of the Wild's 4,829 recorded pipeline keys come from 1,818 bases. 2,845 of the keys differed only in the blend factors of targets whose blending is off, which the key no longer holds (
pso_key_norm).On by default on the Mac only. On iOS
DM_PSO_MTL4=1turns it on: the archive's memory is not measured against an iPhone's limit yet, andmetal-ttrejects the Metal 4 serializer's pipeline script, so no archive can be made offline for an iPhone.DM_PSO_MTL4=0keeps theMTLDevicepath. So does a device without a Metal 4 compiler (t_pso_pending's fake device), and so do functions with no Metal 4 descriptor (theDM_NVN_HILITE/DM_NVN_MAGSCANdiagnostics).Checked
t_pso_archive, 32 checks with the validation layer on:MTLDeviceones, into a pass with a depth attachment the base does not name;MTLDevicepath;t_pso_pendingpasses (48 checks).t_refl,t_fuse_check,t_reorder_chain,t_defer_chain,t_mip_extent,t_rt_range_roandt_rt_rangefail on main as well.MTLDevice.Not checked