Repository navigation
Conversation
…sampler with a twin (function constant DMSH_BORDER_FC) The translator's border colour corrections (the dm_bs twin samplers) are in every shader that samples, though a game binds a sampler with a twin to few draws; Ocarina of Time binds none. They cost registers and instructions in every pipeline: its 1080p material passes spilled 300-400 bytes a thread with them. The chain now gives every stage and kernel a bool function constant, dm_border_off (DMSH_BORDER_FC, index 216), and the host specializes a pipeline with it on when its draw or dispatch binds no twinned sampler (border_need): bd_off for the stages, cs_fn for kernels, the mesh and task pipelines' keys and descriptors (mtk_desc4, mtk_pso: k.border). The specialized function is a distinct identity (FnVariant) because Metal returns one MTLFunction per function content; pso_offline.py bakes the specialization into the app's pipeline archive (HOST_CONSTANTS), and cps_new looks up and captures a compute pipeline by that descriptor only for a function that declares dm_border_off, as before for any other function with constants. DM_NVN_BORDER_KEEP=1 keeps the corrections in every pipeline; =ab alternates the two in the DM_AB phases. The picture does not change where no twinned sampler is bound (Ocarina of Time binds none; t_border covers both sides). The chain changes: dmsh_chain.h is regenerated, and every game's shaders are built again. Measured with DM_NVN_BORDER_KEEP=ab on a MacBook Air M4 (10-core GPU, 16 GB), 1920x1080 docked, the Hyrule Field view: see the pull request. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ctions compiled out, DMSH_BORDER_FC), seedds#1930 (native float atomic add), seedds#1920 (GPU-written sliver does not own a texture: terrain tiles), seedds#1917 (depth attachment sampled by a depth-writing draw reads a copy), seedds#1928 (enc_thread on), seedds#1942 (idle-GPU late frames do not step the hold up), seedds#1940 (prewarm lines after the first frame), seedds#1936 (resolution families uncompressed) Hand-resolved: image_texture keeps the virtual pools we admit; fb_prepare keeps our pass split and local dread flag after the depth snapshot; the compute key keeps the NDVE direct draw before the border constant. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014eD437mxrMnW2UwLZhpwc7 Upstream pull requests applied in this commit (their authors' work, brought onto this tree with a three-way merge; the description is in each PR): - seedds#1774 by uncraftablexd (closed): Compute threads that exit before a barrier keep arriving at it, and every shader loop has a cap (GPU hang defences), chain change - seedds#1917 by FifteenPen (closed): A draw that writes depth and samples its own depth attachment reads a copy of it: Ocarina of Time's light-blue dashes over the rock at Death Mountain Trail's cave entrance are gone - seedds#1920 by nawangwe (closed): A GPU-written span's sliver inside a texture does not make it the GPU's: Ocarina of Time's terrain tiles no longer vanish or show another tile's surface (seedds#1566) - seedds#1928 by FeReuss (open): Ocarina of Time: enc_thread on, the replay encodes on a thread of its own - seedds#1929 by FeReuss (open): Unused border corrections are compiled out of pipelines that bind no sampler with a twin (function constant DMSH_BORDER_FC) - seedds#1930 by FeReuss (open): A float add to storage memory with no result read is one native atomic add instead of a compare-and-swap loop - seedds#1936 by TheGoldfish11 (closed): Write resolution-family image textures uncompressed - seedds#1940 by uncraftablexd (open): A prewarm list's lines after its #@after_first_frame line are built after the first frame, in the background, instead of in the prepare step (issue seedds#1747) - seedds#1942 by uncraftablexd (open): Frame step: late frames with the GPU idle do not step up, and a longer hold the GPU does not explain is probed
seedds#1901 seedds#1459 seedds#1928 seedds#1942 seedds#1940 seedds#1952 seedds#1611 seedds#2065 seedds#2083 seedds#2008 seedds#2079 seedds#2022 seedds#2075 seedds#2077 seedds#2020 seedds#2021 onto main 04811a6 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014eD437mxrMnW2UwLZhpwc7 Upstream pull requests applied in this commit (their authors' work, brought onto this tree with a three-way merge; the description is in each PR): - seedds#1459 by PromethOps (open): DM_UPSCALER=metalfx takes agl's agl_ndsr_vr.pck networks too, and a variant with no curve and no power is drawn as one colour space: Ocarina of Time's upscaler is MetalFX's - seedds#1611 by Esteban-V (open): An argument block whose only change is a uniform buffer is patched instead of encoded again - seedds#1774 by uncraftablexd (closed): Compute threads that exit before a barrier keep arriving at it, and every shader loop has a cap (GPU hang defences), chain change - seedds#1824 by cocoman93 (open): Clamp texel fetches past a sampled 2D texture's edge: no hard edge in Ocarina of Time's mist - seedds#1901 by FifteenPen (open): The game's compute dispatches with no game barrier between them run side by side (profile key dispatch_overlap, on for Ocarina of Time): Kokiri Forest GPU p50 15.63 → 14.76 ms - seedds#1928 by FeReuss (open): Ocarina of Time: enc_thread on, the replay encodes on a thread of its own - seedds#1929 by FeReuss (open): Unused border corrections are compiled out of pipelines that bind no sampler with a twin (function constant DMSH_BORDER_FC) - seedds#1930 by FeReuss (open): A float add to storage memory with no result read is one native atomic add instead of a compare-and-swap loop - seedds#1940 by uncraftablexd (open): A prewarm list's lines after its #@after_first_frame line are built after the first frame, in the background, instead of in the prepare step (issue seedds#1747) - seedds#1942 by uncraftablexd (open): Frame step: late frames with the GPU idle do not step up, and a longer hold the GPU does not explain is probed - seedds#1952 by AdyaGMD (open): Compute moves ahead of scene passes past occlusion queries and conditional rendering; clears wait across dispatches - seedds#2008 by bquilty25 (open): nvn: reactive memory watchdog, 16-way view cache, and texture upload batching - seedds#2020 by padsiwono (open): Ocarina of Time v131072: Output Native draws the full output size instead of the game's 80 % frame (`DM_OUTPUT`) - seedds#2021 by padsiwono (open): Ocarina of Time v131072 renders at the launcher's Resolution (`DM_RENDER_SIZE`), docked - seedds#2022 by sleepyeyedjoe (closed): Ocarina of Time: large models no longer go black for one frame twice, 4–5 frames apart, when the game streams new textures into them (a texture ID a shader has read keeps its read mark when it gets another texture) - seedds#2030 by humanperzeus (open): A NaN colour at alpha 0 is returned as 0, as NVIDIA's blender takes a zero factor: Ocarina of Time's white clouds over the ferns are gone - seedds#2035 by Know-It-All-Brother (open): The shader build runs as worker processes, and no shader waits for a batch (Ocarina of Time's cold Mac map: 3,002 s to 1,298 s) - seedds#2065 by Raymon82777 (closed): A vertex library with layer entry points of its own gets bases for its main0 pairs: Ocarina of Time's 230 ms camera-turn hitch in Hyrule Field goes to 39 ms - seedds#2075 by sleepyeyedjoe (closed): Ocarina of Time: a patch of scenery no longer draws dark for one frame when the game gives it a sharper texture (a pool texture the walk does not make holds a stand-in of its own colours until its first read) - seedds#2077 by roandegraaf (closed): Ocarina of Time: fix the "plaid" terrain / missing texture tiles (GPU-drawn textures now reach the storage the game copies) - seedds#2079 by uncraftablexd (open): Render pipelines that share a vertex function are taken from the archive or compiled one at a time: the AGX driver crashes in createVertexProgramVariant's completion block - seedds#2083 by FifteenPen (closed): Ocarina of Time's prewarm list gets 41 more task / mesh pipelines from later play
…sampler with a twin: every pixel shader with border-colour corrections declares the function constant dm_border_off (DMSH_BORDER_FC, 216) and tests it before the mask bit in dm_bs, and the host specializes each function with it true when no sampler bound to the draw's stages has a border twin (border_need, pso_key.border), so the branch and the registers it kept live across every sample are gone from the pipeline instead of skipped per pixel. The mask branch made Apple's compiler keep the sample's operands for the correction that never ran, which spilled registers in shaders with many samples. A pipeline builder takes an explicit off flag from the draw's key (pso_build, pso_build_ex, pso_build_dev, pso_desc4, pbase_key, cps_new_b, the mesh and capture pipelines, the prewarm and pso_offline.py's archives), and the specialized function is found there (fn_off, fn4_of_b, fn_dev_b); descriptors hold only real Metal functions. A draw compares its stages' need with the bound pipeline's (prog_border), so a sampler with a twin bound after the pipeline was picked gets the correcting pipeline. DM_NVN_BORDER_KEEP=1 keeps the corrections in every pipeline and =ab alternates by DM_AB phases. Ocarina of Time standing on the forest deck, in-process A/B on an Apple M6: GPU p50 10.66-10.88 ms without the corrections, 11.01-11.26 ms with them, frame time 16.67 ms both. Compiled for the M1's GPU (applegpu_g13g, 300 of its pixel shaders): mean code 16,232 -> 14,531 bytes, per-thread scratch lower in 77 shaders, higher in 11, the worst 240-352 bytes -> 0. AdyaGMD's measurement of the side-library form on an M1, Splatoon Raiders: 31.6 -> 19.8 ms a frame; not reproduced here. t_border (113 checks), the 136 gfx suites, test_dmsh_border, test_pso_offline, test_docs pass; regress.py check on Bastion and NieR:Automata: 60 fps, every shader builds, no new red line. The side library of PR #1203 is not taken: it compiles every pixel shader with corrections twice. Not run: Tears of the Kingdom (the one known game that binds a twin; its build is not on hand), the iPhone, an M1. The function constant is FeReuss's design and code (PR #1929); the diagnosis of the spill and the M1 numbers are AdyaGMD's (PRs #1203, #1032); the need for a per-draw choice is givethesourceplox's finding (PR #1073) Front-ends: the shader chain version changes; shaders are rebuilt. Co-authored-by: FeReuss <102842515+FeReuss@users.noreply.github.com>
|
Landed on main as 511a0a2, with you as co-author: the function constant
Measured here: Ocarina of Time on the forest deck, in-process A/B on an M6, GPU p50 10.66-10.88 ms without the corrections against 11.01-11.26 ms with them; compiled for the M1's GPU, 300 of its pixel shaders have 10% less code and 77 of them less per-thread scratch. Not run: Tears of the Kingdom (the one known game that binds a twin), an iPhone, an M1. Thank you. |
|
Independent measurements of this change on another game and device. MacBook Air M2 (10-core GPU, 16 GB), macOS 27.0, The Legend of Zelda: Ocarina of Time 0400486024DEC000 v131072, handheld 1440x810, chain cd098f1631bd. Where
The Why it costs with mask 0. The second sample is guarded by a uniform test of the mask, but a sample has no side effects, so the compiler if-converts it. Both samples always issue, and a select picks one. The guarded sample is paid on every pixel, whatever the mask, and it also holds registers and adds waits. Offline, per shader. A full-screen 1440x810 pass of each shader alone, with the uniform blocks dumped from the game, the same chain flags, and 20 rounds; times are net of a null shader. Base against the second sample removed:
In game. The libraries of those four shaders were replaced with copies built without the second sample. The rest of the build is otherwise identical: the unchanged source rebuilt to the image's own libraries byte for byte. A host switch (diagnostic only) drew them in alternate 240-frame phases of one run, against the original libraries in the neighbouring phases, over a scripted 12,000-frame route, with pipelines warmed beforehand. Three runs, each with 20 B phases compared against their two A neighbours (median, bootstrap 95 %):
That is about 0.85 ms a frame from four shaders. Pass count and CPU submit work did not change. No twinned sampler on these routes. The host logs a draw's border mask in its pass dump whenever a bit is set. Full-frame dumps of the route (frames 2400–2402) and of six places (49–50 dumped frames each, 10 camera directions) have no such line. This game's samplers use opaque white (1,1,1,1) or opaque black (0,0,0,1), which Metal provides itself, so the mask is 0 at every draw that was dumped and the second sample never changes a result. 🤖 Generated with Claude Code |
|
A whole-game measurement of this change, following the per-shader one above. MacBook Air M2 (10-core GPU, 16 GB), macOS 27.0, The Legend of Zelda: Ocarina of Time 0400486024DEC000 v131072, handheld 1440x810. The build carries this change as it landed on main (511a0a2), on chain bf6035002b98. Method. Without the change (B − A):
On this route, the change saves about 2.8 ms of GPU time a frame on the M2, about 10 %, almost all of it in the main pass. CPU instructions a frame did not change. Frame times, three runs pooled (each phase's first quarter dropped):
|
What and why
The translator's border colour corrections (the
dm_bstwin samplers) are in every shader that samples, though a game binds a sampler with a twin to few draws: Ocarina of Time binds none. They cost registers and instructions in every pipeline; its 1080p material passes spilled 300-400 bytes a thread with them.The chain now gives every stage and every kernel a
boolfunction constant,dm_border_off(DMSH_BORDER_FC, index 216), and the host specializes a pipeline with it on when its draw or dispatch binds no twinned sampler (border_need):bd_offfor the stages,cs_fnfor the kernels, and the mesh and task pipelines' keys and descriptors (mtk_desc4,mtk_pso:k.border). The specialized function is a distinct identity (FnVariant), because Metal returns oneMTLFunctionper function content.pso_offline.pybakes the specialization into the app's pipeline archive (HOST_CONSTANTS), andcps_newlooks up and captures a compute pipeline by that descriptor only for a function that declaresdm_border_off; any other function with constants is built fromfn_dev's specialization and not captured, as before (t_pso_bundlechecks it).DM_NVN_BORDER_KEEP=1keeps the corrections in every pipeline;=abalternates the two in theDM_ABphases.The picture does not change where no twinned sampler is bound (
t_bordercovers both sides). It is a chain change:dmsh_chain.his regenerated and every game's shaders are built again.Rebased onto the native mesh pipeline prewarm and the mesh-without-task code that
maintook since (mtk_desc4,mtk_build,mtk_pso): the specialization is in the descriptor and the key there.Checked
dm/gfx/teststest_dmsh_border.py(10 tests, 1 skipped, OK) anddm/tools/teststest_pso_offline,test_nsp_chain,test_docs(48 + 28 tests OK);make -C dm/gfx/tests GAME=0400486024DEC000 check_t_...fort_border(107 checks),t_pso_bundle(69),t_pso_archive(222),t_pso_warm(123, MTLDevice and Metal 4),t_pso_depth_stencil(286 + 286),t_pso_stall(43),t_geometry(1,929),t_geometry_feedback(110),t_geometry_hazards(61),t_geometry_mesh(44),t_mesh_first_use(53),t_upscaler_mfx(91 + 12),t_feedback(203),t_pool_chunks(146): all 0 failed, on this branch;t_pso_skeyOK. The host builds (make -C dm/host GAME=0400486024DEC000). The wholemake -C dm/gfx/tests GAME=0400486024DEC000 runon the tree with every PR of the series: 150 suites, 72,812 checks, 0 failed; 525 read-back cases, 0 failed.still_shotsroute, the heaviest), 1920x1080 docked, 210 s, window, 60 fps cap,DM_NVN_BORDER_KEEP=abwithDM_AB=600(phases of 600 frames, the first quarter of each left out), in one process: with the specialization (this PR) span p50 23.10 ms, frame p50 22.61 ms (43.9 fps); with the corrections kept in every pipeline 24.37 ms, 23.98 ms (41.7 fps): -1.27 ms of GPU span, -1.37 ms of frame, +2.2 fps. The kernels (the upscaler's among them) were about 0.3 ms of it. 0[RED]lines. Measured on a tree built on main7f502220(the series), not on7a7acfee: the specialization code is the same, the mesh/task parts were re-applied by hand on the new prewarm, and the shaders of this tree were not built.scripts/regress.py check --gamesis not run. Only Ocarina of Time is built on this Mac, and a chain rebuild of it needs about 10 GB of free disk (4 GB here). The other games that sample with a twinned sampler bound are where it matters, and they are unchecked; with no twinned sampler bound the pipeline is the same as before, with the correction code removed.Front ends
None.
Docs
docs/reference/rendering.md(the border corrections entry) and the symptom index (python3 dm/tools/docs_symptoms.pywas run).dmsh_chain.py --headerwas run anddm/gfx/nvn/dmsh_chain.his part of the change.Series: what these PRs add up to
This PR is one of a set from one effort to make Ocarina of Time (0400486024DEC000 v131072) hold its frame rate on a MacBook Air M4. The set, and how its parts combine into the last measured result:
The result (the Hyrule Field view, the heaviest of the game: 1920x1080 docked, 60 fps cap, window, 120 s runs, M4 with 10 GPU cores, 16 GB, macOS 27.2):
7f502220+ #1304,fps_holdat its defaultfps_hold off(#1927)cut_draws 128below, and the PRs listed as "also in the tree"enc_thread on(#1928)(The step from 33.7 to 40.2 changes the shader chain, so it has no in-process A/B; #1833 is most of it. Kokiri Forest, walking, is at 60 fps on build 4; the Hyrule view is the worst case.)
Each part switched in one process on build 4 (
DM_AB, 210 s, 600-frame phases, frame p50 with the part active against without; the noise between phases is about 0.3 ms): border-FC (#1929) 22.61 vs 23.98 ms; the barrier set (FRAG_ORDER,PASS_OVERLAPandHEAP_RELAXalternating together) 22.41 vs 22.58 ms;CUT_IDLE22.74 vs 22.85 ms;DISPATCH_CHAIN22.32 vs 22.48 ms.Which PRs make that tree:
fps_hold offenc_thread onshader_raw_direct(without it every raw store is dropped on an M4 and the foliage is not drawn: the 48-50 fps of a build without it are false)FeReuss:pr1833-m4-window, one commit on #1833's head (not yet offered on #1833 itself)gpu_ts_hz), #1833 (shader_raw_direct), #1720, #1377, #1840-fwrapv, nowe4e5ff64), #1368 / #1708 (native mesh prewarm and mesh without task: main's own versions), #1707 (withdrawn)FRAG_ORDER+PASS_OVERLAP+HEAP_RELAX),CUT_IDLEpr/pass-overlapandpr/cut-idleinFeReuss/nxnative-ootcut_draws 128(64 and 128 tie on this tree)All of it was measured on main
7f502220plus the above; these PRs are rebased on main8d5d4f1b; the tool and docs tests that touch them were run again there (test_env_switches,test_docs,test_nsp_chain, and each PR's own), while the host build and the graphics suite are those of7a7acfee, and none of it has been run in the game on the newer main (a shader rebuild of the new chain takes about an hour and 10 GB of disk). This PR is #1929.🤖 Generated with Claude Code