Repository navigation
Translator: structured --wave64-emulate and acyclic single-write execz folding (#884) - #2089
edwin042331-hue wants to merge 4 commits into
Conversation
|
GPU check of #2089 on NVIDIA Turing (32-wide subgroups): no regressions; the 7 shaders that switch to the new structured path all pass. AI-assisted.
Every test has the same status on main and on the PR in both modes. With emulation on, CPU checks on the PR head: Not covered: game-corpus shaders ( |
|
Code review of 1a40ad2 (first read at 4d9ef4e, the bug reproduces on both), AI-assisted. Checked on the repo's semantic interpreter ( 1.
Fix: add 2. Verification notes (minor):
Checked and found correct (with the fix above aside):
Differential fuzz, PR vs base emulation: about 2,900 random programs at 40, 64 and 128 threads (execz folds, other-half loads, LDS, |
|
Tested 1a40ad2 on AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.2.6-arch3.1, Linux 7.3.4-1-cachyos: pass (GPU tests +
AI-assisted. |
|
Full-corpus translation check on my own 1.0.2.1 copy: no regression in translated or
AI-assisted; counts only, no game data. |
|
@edwin042331-hue this now conflicts with
Checks on the merged tree, with the runtime rebuilt from it (GTX 1660 SUPER, driver 621.14, Windows 11 Pro 26300, llvm-mc 23.1.6, Vulkan SDK 1.4.363.0):
|
|
Thanks @CharlyRien, @ElsCiber, @Faterek, and @Thatters for the thorough reviews, GPU runs (GTX 1660 SUPER & RX 9070 XT), 2,900-program differential fuzzing, and full 26,503-shader corpus verification! Pushed
AI-assisted. |
|
RTX 4080 / NVIDIA 621.01: the larger giant still fails to compile at Setup: GeForce RTX 4080 (Ada, 16 GB), driver 621.01, Windows 10 22H2 (19045), 32 GB RAM. I translated the two ScreenProbes giants from my own 1.0.2.1 copy with
Each run reached its cap, then NVVM reported the failure (checker exit 1, no crash). On this GPU and driver, the structured form still needs more than 24 GiB for the larger giant, and memory climbs early. The The smaller giant at |
bc9fb7b to
de5d616
Compare
|
@Proudnoob4 @Thatters Pushed
Measured Impact & Verification
AI-assisted. |
|
@edwin042331-hue I'm testing
On the real giants, the known- #2089 also moves the two #884 InstanceCulling BatchCull CS from |
|
@Proudnoob4 Great catch on those structural counts (
Pushed Verified locally with |
|
@edwin042331-hue Two results on the RTX 4080 / 621.01 (each module alone, 24 GiB cap). AI-assisted; counts only.
That's about 2,950 spine guards unwrapped per giant (two labels each), in line with your ~3,000 estimate. |
|
@edwin042331-hue
So on this card and driver, neither reduction changes the outcome; the time to the cap stays within about 8%. Memory also climbs early here: one The smaller giant at |
|
RTX 4080 / NVIDIA 621.01 / Windows 10 19045, translator Smaller ScreenProbes pipeline: InstanceCulling BatchCull is a different story. Same input shaders and checker, each compiled alone:
These are pipeline-creation times and peak process commit, not shader execution or output-correctness tests. The two older isolated peaks do not establish that the peaks overlapped or caused the 8-job failure in #884. |
# Conflicts: # docs/design.md
- shader_disasm: prune stale listings against every input, not the --skip-existing remainder (a resumed run deleted every listing it had just reused). - progress_dashboard: a drive-letter path is never inside the repository off Windows (it printed user names); its own read_text helper is read_utf8, so the encoding check does not take it for pathlib's. - Translator tests follow this round's rules: desc_lookup's BroadcastFirst in the typed-load condition walker; resinfo sizes are 0 past the last level and a 2D depth word is 0 (SHADER-388); SHADER-315 constant folding in the perm and i16 tests; ItsNotRexed#2089's structured wave64 emulation. - test_semantic_translator_use: 57 oracle-only files merged before it are DEBT; test_spirv_tools_required is allowed (CI meta-test). - Test fixes: image_fuzz fake writes the programs, preflight follows c506d00's loader hint rule, feature_scan reads the first line of a pytest-decorated message, w64_graphics wording. - docs: rows merged again in design.md, README.md, d3d12_vulkan.md; GameInput table rebuilt from ItsNotRexed#3172's rows; orphan rows in models.md and embedded_shaders.md; repeated bullets; anchors; a flag not on main. - Repo rules: stdout guard on 14 programs; LF writes; csv lineterminator in bink_play. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…me-V# addressing into helper OpFunctions
|
Thank you @Proudnoob4 for the A/B measurements on Seeing the two
and seeing the hoisted guard-spine coalescing unwrap 2,955 Why
|
|
Rerun on the current head
These are the synthetic fixtures only. Your outlining and coalescing commits target the corpus giants, which I can't test without game files; this run only shows they don't break the hand-written wave64 tests on a 32-wide NVIDIA part. |
There was a problem hiding this comment.
Independent Linux test at 5f1a95b8 versus d0835dd9, with Mesa 26.1.6 RADV targeting GFX1201 via Mesa's DRM shim. All inputs are hand-written synthetic RDNA2. Each pipeline build used the same vk_pipeline_check, one worker in a fresh process, MESA_SHADER_CACHE_DISABLE=true, and an 8 GiB address-space limit.
Dynamic typed-load outlining
The fixture accumulates the result of repeated buffer_load_format_x instructions with distinct offsets and a runtime V# descriptor. All four module sizes (8, 32, 128, and 512 loads) translate and pass Vulkan 1.2 spirv-val on both trees.
| Workload | Main SPIR-V / cold pipeline time | PR SPIR-V / cold pipeline time |
|---|---|---|
| 128 loads | 521,036 B / 7.274 s median (7.075–7.323) | 111,900 B / 7.360 s median (7.144–7.694) |
| 512 loads | 1,981,772 B / 100 s timeout | 331,548 B / 100 s timeout |
Three interleaved samples per build at 128 loads. Median peak RSS was 185.3 MiB on main and 184.4 MiB with outlining. At 512 loads, one bounded run per build reached the timeout. The same 512-load fixture compiled in 3.40 s with a separate single-component decoder prototype.
This is a large reduction in SPIR-V stored on disk. RADV inlines the helper functions before optimization, which is consistent with the similar time and memory at 128 loads. The bounds and format differential gave 5,120 bit-identical words against main across the 128 descriptor formats, eight destination selectors and five byte offsets. The 23 emulation tests and 156 buffer tests also passed.
Control flow already available on main
Separately, I measured the default structured emulation against the same translator with --dispatch-loop. A two-wave synthetic workgroup repeatedly evaluates an EXEC mask, conditionally updates a wave-wide scalar, runs two dependent integer multiply/add pairs on active lanes, and uses the scalar after restoring EXEC.
| Workload | Structured | Forced round scheduler |
|---|---|---|
| 512 EXECZ branches | 0.633–0.677 s, 126 MiB RSS, 0 switch cases | 10.222–12.789 s, 687 MiB RSS, 1,537 switch cases |
| 2,048 EXECZ branches | 5.709 s, 339 MiB RSS, 0 switch cases | 60 s timeout, 2,528 MiB RSS at timeout, 6,145 switch cases |
Both modes pass spirv-val. On llvmpipe, both returned 128/128 expected words in each of six dispatches with 32 or 128 branches and three starting masks, including one with different outcomes across the two waves. These separate fixtures show a cold-compile improvement from structured lowering where it applies. The typed-load-only result still points to the cost of the decoder after inlining.
AI-assisted. No physical GPU or game files used.
Mesa 26.3.1 and llvmpipe follow-up
I built Mesa 26.3.1 RADV and its matching DRM shim from source to match the Mesa release in #4315. One new cold sample per build on the same GFX1201 target confirmed the direction of both results.
| Workload | Measured pipeline creation (peak process RSS) |
|---|---|
| 128 typed loads | Main 6.901 s (142 MiB), outlining 7.336 s (149 MiB), single-component decoder 0.492 s (39 MiB) |
| 512 EXECZ branches | Main structured 0.638 s (88 MiB), main forced rounds 7.939 s (650 MiB) |
I also built and ran five checked-in GPU fixtures on llvmpipe with wave64 emulation enabled. The official harness verified the complete expected output for cs_fmt_1010102, cs_fmt_int_narrow, cs_fmt_sint32, cs_fmt_xy_xyz and cs_fmt_d16_xyz on both trees.
Combined decoder and outlining
Research commit 4efad11f applies the single-component decoder inside this head's outlined helper. It keeps the address, bounds and memory-access path shared with other loads and uses a distinct helper key for non-D16 buffer_load_format_x. D16 and wider loads use the existing helpers.
| Synthetic typed loads | Standalone decoder: SPIR-V / RADV 26.3.1 cold compile | Combined: SPIR-V / RADV 26.3.1 cold compile |
|---|---|---|
| 128 | 491,336 B / 0.441 s median (0.403–0.495) | 88,072 B / 0.475 s median (0.427–0.479) |
| 512 | 1,932,088 B / 3.811 s median (3.634–4.230) | 307,704 B / 3.706 s median (3.626–3.858) |
| 3,280 | 12,282,104 B / 116.527 s | 1,855,480 B / 113.705 s |
Three interleaved runs at 128 and 512 loads. One run per build at 3,280 loads, with 3,119 MiB and 3,112 MiB peak RSS respectively. The combined build retains the compile-time gain while storing a smaller module. All measured binaries passed spirv-val.
On the 32-load fixture, RADV's ACO stats reported 43,011 native instructions and 1,430 spilled SGPRs for both main and outlining alone. Both single-component variants emitted 5,704 instructions and reported zero spills. This is compiler output from the DRM-shim target.
The Intel Xe2 (BMG) Mesa 26.1.6 ANV compiler accepted the wave64-emulated, 128-byte push-constant build. With 128 loads, main and outlining alone reached a 45 s timeout, while both decoder variants compiled in 3.91 s. One run per build, via Intel's DRM shim.
Verification includes 24 wave64 emulation tests, 157 buffer semantic tests, all 5,120 format/selector/offset reference outputs, and the five llvmpipe fixtures above. An exhaustive llvmpipe dispatch over each 16-bit input value gave 131,072/131,072 exact UNORM16/SNORM16 results, matching main, outlining alone, and the arithmetic CPU reference. These checks are synthetic. The effect on either large game pipeline still needs a local replay.
… wave64 emulation The merge of ItsNotRexed#2089 (1cc7497) made a reducible multi-block loop take the structured emulation and outlined the per-round exchange setup into single-block helpers called with OpFunctionCall. The test's own workgroup interpreter could not run the calls and still expected the round scheduler, so five subtests failed on main. The interpreter now expands single-block helper calls inline (as test_wave64_emulate_opt.py does), the emulated cases expect "emulated wave64 structured", and the same cases also run with --dispatch-loop to keep the round scheduler covered against the same native words. AI-assisted.
Follow-up to #1904 and #1905 targeting the remaining
--wave64-emulateOpSwitchblow-up on Issue #884 (the ~11,150 cases remaining incs_screenprobes_activate/cs_screenprobes_targetand ~1,727–1,795 cases in#22496/#21097after #1905).What changes
s_cbranch_execzfolding (tools/wave64_emulate_opt.py,tools/rdna2spirv.py):find_local_exec_foldsso an acyclic lane-locals_cbranch_execz/execnzregion may contain an EXEC-masked store/atomic (buffer_store*,tbuffer_store*,global_store*,flat_store*,image_store*,ds_write*,*_atomic*) when that instruction is the sole access to its memory domain ("mem"or"lds") inside the region.x_memory_ordersplit/barrier in uniform control flow beforeif (%active)(handling WAR/WAW/RAW) and records(kind, "w")after the merge label, with zero splits/barriers inside divergent control flow (asserted at translate time).--wave64-emulateemission (plan_structured_emulation,control_flow = "emulated wave64 structured"):K_{1,N}round-loopOpSwitchon multi-superblock reducible wave64 compute/mesh CFGs (when no wave64 32-bit half-maskscc_nonzerowrites liveSCC; straight-line / single-superblock shaders stay onx_scheduler):<= 64threads,mode = "inline_all"): All wave-uniform branches are workgroup-uniform, so the entire post-foldcfg_structuretree emits inline with directOpControlBarriers (0OpSwitchcases,0x_spillvariables,0schedulerOpAtomicIAdds) and an exact 4-bit forwarddirty_infixed point ordering cross-block and loop-carried RAW/WAR/WAW hazards.> 64threads,mode = "structured_hybrid"): When no non-top-level guard/loop containss_barrier(divergents_barrierlikecs_barrier_divergentfalls back cleanly to"emulated wave64 rounds"), unwraps post-dominating spine guards whose predecessors are already emitted, runs top-level spine blocks and barrier-free guards/loops (including live-out scalars, single-write stores,EXEC-widening,s_cbranch_vccz/nz, and read-onlys_cbranch_sccloops) inline with0OpSwitch, and isolates any remaining wave-divergent barrier regions into tiny localx_mini_schedulerloops (or atail_schedulerat earlys_endpgm).docs/design.md,make_game.py):wave64_emulate_opt.pytomake_game.TRANSLATION_SOURCES(fixingtests/test_shader_stage_resume.py).docs/design.md(Wave64 emulation (--wave64-emulate)row).Verification (CPU-only; no local
spirv-val,llvm-mc, GPU harness, or game files)python -I tests/semantic/test_wave64_emulate_opt.py -v: 18/18 OK (adds single-store WAR/RAW ordering on 64 & 128 threads, 64- & 40-thread partial-waveinline_allwith 0OpSwitchand loop-carried WAR, 128-threadstructured_hybridwith inline sync-free live-out scalar + localmini_scheduler+ top-levels_barriercross-wave LDS exchange bit-exact vs baseline, and multi-wave divergents_barrierfallback).python -I -m unittest discover -s tests/semantic -p "test_*.py": 1,662 passed, 0 failed (skipped=2).python -I tests/semantic/test_w64x_scalar_load_order.py -v: 5/5 OK;tests/semantic/test_valu_permlane16.py: 16/16 OK;tests/test_shader_stage_resume.py: 39/39 OK;tests/test_split_big_switch.py: OK (1 skipped, nospirv-as).python -I tools/cf_diff.py --programs 50 --seed 1 --wave 64: 50/50 pass, 0 mismatch.vccz, wave-divergentv_readlane/loops, top-levels_barrier, and earlys_endpgm) + structural SPIR-V SSA/CFG/OpPhichecker: 120/120 bit-identical vs baselinex_scheduler,OpSwitchcases 4,149 -> 318 (-92.3%), dynamic barriers 3,503 -> 1,431 (-59.1%).tests/semantic/fixtures/disasm/: 15/15 A/B bit-identical.if/elsediamonds):OpSwitchcases 2,002 -> 0,x_spills = 0(1.37 stranslate).OpSwitchcases 2,002 -> 0,x_spills = 0(1.66 stranslate).spirv-as/spirv-val,llvm-mc, GPU execution, or real game corpus modules (cs_screenprobes_activate,cs_screenprobes_target,#22496,#21097).Claimed in #1902. AI-assisted.