Repository navigation
rdna2spirv: raise MAX_STRUCTURED_DEPTH to 64 and add --max-structured-depth (SHADER-427) - #3090
Conversation
…pth (SHADER-427) Since ItsNotRexed#1904 the corpus's deepest structured tree is 29, not 118. With the SHADER-299 bound at 16, 1,031 modules (747 CS, 284 PS) still took the dispatch-loop form, which saves only 12% of their spirv-val time but compiles 1.67x (PS) to 2.0x (CS) slower on an RTX 5070 Ti / 621.24. The bound now sits above the corpus as a guard, and --max-structured-depth N (0 = never) sets it per run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
AI-assisted independent CPU validation at rebased head5c6d0087 against parent16282101: matched all26,503 index entries to disassemblies. Under --wave64-emulate,12,944 produced structured trees;1,031 change routing at cap16→64 (747CS/284PS), maximum depth29. A slice spanning every observed stage/depth combination translated and passed Vulkan1.2 spirv-val50/50 on both revisions, all dispatch on parent and structured on head. This is full-corpus routing evidence with slice assembly/validation, not full-corpus independent validation. On the earlier depth18PS and three deepest CS, cap16 reproduced parent binaries; cap0 reproduced new default. CLI20, semantics4142, translator/CFG545 tests passed (4skips). I reproduced the disclosed override caveat with a synthetic128-thread wave32 CS, top-level barrier and depth6: cap64 selects structured; cap1 selects dispatch while barrier rounds remain disabled. Both validate, so spirv-val does not catch this decision mismatch; no GPU hang established. Please use the same effective capped tree for the barrier decision and assembly, with a regression fixture, either here or a linked follow-up. Also pin the default CLI assertion to64 rather than importing the implementation constant, so reverting the default cannot pass the test. GPU timing remains queued. |
|
SHADER-427: independent bounded pipeline-creation timing on GeForce RTX 5070, NVIDIA 616.56, Windows. Parent 1628210 versus head 5c6d008. Four selected affected modules, not the full 1,031-module population:
All eight pipelines created successfully, zero skips and zero reported application-cache hits; all eight timed binaries passed spirv-val. Parent used dispatch and head structured flow in every pair. Serial fresh processes, separate cache directories, fresh SPIR-V generator words, no application cache file; parent/head-first order alternated between pairs. One observation per case, driver-internal cache state unverified. 150-second process timeout and 6 GiB monitoring threshold. The two wave64 pixel pipelines compiled without a required subgroup size on this subgroup32 device: this is compilation evidence, not execution correctness. The existing low-depth-override barrier caveat remains separate. AI-assisted; private game-derived modules were not published. |
|
Checked 5c6d008 on Windows 11, Python 3.15.2 — CPU only; the routing has no GPU part, but I have no NVIDIA card to reproduce the compile-time numbers. AI-assisted check.
Not verified here: the NVIDIA timings, and the routing on a real depth-20+ shader — a hand-written listing needs per-instruction encodings for branches, so a synthetic nested-loop shader can't go through the CLI without llvm-mc. That rests on |
…427 review) needs_barrier_rounds() looked at the unbounded structured tree, while assemble() emits the dispatch loop once the tree nests deeper than MAX_STRUCTURED_DEPTH. A wave32 compute shader with a top-level s_barrier over the bound then got the dispatch loop without barrier rounds. Both now use capped_tree(). With the default bound (64) no corpus module is affected (the deepest is 29); it matters when --max-structured-depth is set below a shader's depth. The CLI test now pins the default to the literal 64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested 5c6d008 (merged onto main
No regression on this GPU. The suite does not reach a structured depth over 16, so this does not exercise the new bound itself; no corpus run (no game files used). |
|
Tested 5c6d008 on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:
AI-assisted (Claude Code). |
|
Tested 48a4c4d on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass. Python tests:
Full GPU suite:
Note: tested PR head as submitted (PR description lists dependency on #2731). AI-assisted (OpenCode). |
Conflicts: tools/rdna2spirv.py (--pc-tail-ubo and --max-structured-depth both added next to --max-shared-memory: kept both) and docs/design.md (upstream reworded the neighbouring rows: kept theirs and re-applied the SHADER-427 sentence of the "Control flow" row). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @kacper-serewis. Both points are fixed in 48a4c4d. b21c38e merges origin/main (f847748) to clear the conflicts. AI-assisted.
At the default bound nothing in the corpus changes (the deepest tree is 29), so this only affects runs with Re-run on b21c38e (Windows 11, RTX 5070 Ti / 621.24): Thanks also @UNYTIX, @gngsterism, @controldebils, @JRamos1993 and @javdc for the test runs, and @kacper-serewis for the RTX 5070 timings: same direction, by a wider margin on the compute modules. |
|
Independent check, AI-assisted, two GPUs, main branch baseline. Environment: Windows 11 build 26300, Vulkan SDK 1.4.363.0, MSVC RelWithDebInfo, llvm-mc 21.1.8 (WSL Ubuntu). PR #3090 ( Tested on NVIDIA RTX 5070 (driver 32.0.16.2124, subgroup 32..32):
Tested on AMD Radeon Ryzen 7600X iGPU (driver 32.0.21045.29003, subgroup 32..64):
The No game files used; counts only. Verified on both GPUs; no unexpected regressions.
|
|
Tested
Not tested: the NVIDIA compile-time numbers in the description, the retail corpus, wave64, AMD/Intel. Tested with AI assistance (Claude); synthetic programs only, no game data. |
|
Tested on Apple M4 / MoltenVK 1.4.2 (macOS 27.2.1) with my own 1.0.2.1 copy: MoltenVK agrees with the NVIDIA numbers. On the current tree, the structured form of the modules that the bound sends to the dispatch loop creates pipelines 2.2x faster for the pixel shaders (wall time, all 284) and 2.0-2.9x faster for compute (10 modules, each compiled alone). This supersedes the direction of my #1993 note for today's tree: there the flat form was the slow one too, and this PR keeps those modules out of it. Setup
Which modules switch. I ran the whole corpus (25,734 listings, 32 shards) with
Method
The gain grows with how long the module takes. Below are the 234 PS that take at least 0.2 s on both sides, grouped by their time in the dispatch-loop form:
No game data (counts and timings only). The module outputs are deleted again. AI-assisted. |
|
Follow-up: the head moved to Does the new head change them? No.
AI-assisted. |
Conflict in tools/rdna2spirv.py assemble(): main added the x_round_fns helper loop next to the old inline depth check. Kept main's helper loop and this branch's capped_tree() call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
CPU-side verification pass on head The Red before / green after. Suites I ran at head:
CLI behaviour: Docs: the One note for whoever merges: CI is still queued on this head ( AI-assisted. |
Conflicts were both-sides additions: docs/design.md (main's DPP, EXEC and saveexec row updates kept; this branch's Control flow row kept) and tools/rdna2spirv.py (main's _out_inside_input and --opt kept next to _depth_arg and --max-structured-depth). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested Setup: the PR diff applied to
No game files. AI-assisted (Claude Code); I ran the commands above and checked the numbers against the logs. |
|
Tested Tests (llvm-mc 21.1.8 native, SPIRV-Tools v2026.4, Python 3.14.5): Corpus (a 1.0.2.1 package that matches the manifest; counts and timings only). At
Pipeline creation on the AMD Windows driver. Each module alone in a fresh process (
The two PS columns ran three processes at a time. The dispatch-loop PS had been compiled on this machine before, so for that run I changed the generator word of each module to keep the driver's disk cache from serving them; the structured modules were new to the driver. So on The catch: stack. The structured forms nest deeper and the driver's compiler recurses with them. With
Not measured: memory use, other AMD GPU families, and a corpus translated with |
|
Tested fb7f380 merged with main 3faac55 on native Windows (Python 3.13.1, llvm-mc 23.1.6) and with main 98fa503 on Linux (Python 3.12.16): pass. tests/test_rdna2spirv_cli.py, tests/test_translate.py (pytest, 597 tests) and the other rdna2spirv, value_semantics and shader_checks tests: Windows 8/8. Linux 11/12; the one failure, tests/test_translate.py, is a pytest file that cannot import rdna2spirv under |
|
Tested
AI-assisted (Claude Code). |
|
Thanks @PeterGrieffindor, and @cxchhh, @kapitche and @lunarminus for the passes on On the AMD stack catch: this PR doesn't change The thread the runtime creates pipelines on is a separate stack, and I haven't checked what it gets. I can open a follow-up for it if that's useful. Head is still |
|
Thanks. On the runtime's stack: here is what a read of
So with this bound the overflow can happen in the runtime when the game creates one of those pipelines on a thread other than the entry thread, with the default size or a smaller one. Which threads the game uses cannot be checked without the executable. What is measured on this driver: with 1 MB all 54 modules overflow, with 2 MB 10 of the 28 compute modules still do, with 4 MB none. I think a follow-up is useful. AI-assisted (Claude Mythos 5.2). |
|
@PeterGrieffindor please take it, and thanks for checking the runtime side. You have the driver and the modules that reproduce the overflow, which I don't on NVIDIA. AI-assisted (Claude Code). |
SHADER-427 (claim). AI-assisted.
SHADER-299 (#1993) made the translator emit any structured tree deeper than
MAX_STRUCTURED_DEPTH = 16in the flat dispatch-loop form, becausespirv-valtime explodes with depth. At the time the corpus nested up to 118 deep. Since #1904 (cfg_structurehoists tails), the deepest tree in the corpus is 29. At those depths the flat form saves littlespirv-valtime, but NVIDIA compiles it 1.7-2x slower, and players pay that compile cost on their machines. This PR:spirv-valrunning 2.3x and more;--max-structured-depth Ntotools/rdna2spirv.py(0= never fall back), so the trade can be revisited without editing code;MAX_STRUCTURED_DEPTHand the SHADER-299 sentence of thedocs/design.md"Control flow" row (only that sentence);_depth_argvalidation and the option setting the bound (tests/test_rdna2spirv_cli.py), and0keeping a tree that is over the bound structured (tests/test_translate.py::test_deep_structured_nesting_uses_the_dispatch_loop, which still monkeypatches the bound).Numbers (my own 1.0.2.1 copy; counts and timings only)
Depth over the whole corpus on
main49475796: 25,734 disassembled inputs and 26,501 index entries; 12,944 modules get a structured tree.So with the bound at 16 on
main, 1,031 modules (8% of the structured ones) still take the dispatch loop. A 400-module random sample suggested only 4. The whole corpus says otherwise, and @kacper-serewis independently saw a depth-18 pixel shader take the fallback (#1993 comment).spirv-val(SPIRV-Tools v2026.4), all 1,031 modules in both forms (both forms of a module back to back, 6 in parallel): dispatch loop 1,091 s vs structured 1,235 s summed (+13%; about 6 s of wall time spread over 24 threads). The slowest single module takes 5.9 s vs 8.3 s. By depth, median per module: 17-18 140 vs 136 ms, 19-20 1.39 vs 1.60 s, 21-24 0.72 vs 0.85 s, 25-29 0.64 vs 0.78 s. 1,031/1,031 pass in both forms.Pipeline compile, RTX 5070 Ti, NVIDIA 621.24, Windows 11:
vk_pipeline_check --jobs 4 --slow 0, no cache file, and a fresh SPIR-V generator word for every set so the driver's disk cache can't serve it. Two rounds each, run one after another with the PC otherwise quiet:Peak private memory was the same in both forms (CS 2.06-2.30 GB, PS 2.34-2.56 GB). (The 2.3 -> 8.0 GB I reported earlier was measured on #1993's base, where 76 of 400 sample modules switched.) All pipelines were created (284/284 and 4/4 in every run).
The cost isn't NVIDIA-specific: on Apple M4 / MoltenVK, @sovljanskii measured modules switched by #1993 compiling 3.8x slower summed (on #1993's base, before #1904; #1993 comment).
The change trades about 144 s of summed
spirv-valCPU per full build for about 9 minutes less summed driver compile on the 284 pixel shaders alone. The 747 compute modules come on top of that (on the 4 measured, +74 s each).Not changed here: the latent case @sovljanskii found in the same comment, where the barrier-rounds decision uses the unbounded tree, so a wave32 CS with a top-level
s_barrierover the bound gets the dispatch loop without rounds. No corpus module reaches it (the structured wave32 CS withs_barrierhave depth 1), and with the bound above the corpus's maximum it's further out of reach. It's left for its own item.Tested
Windows 11, RTX 5070 Ti / 621.24, Python 3.15 (
py -3 -I), pytest 9.2.0 on Python 3.12. Measurements were taken on49475796; the branch is rebased onto16282101, which changes neithercfg_structure.pynor the bound. On the rebased branch:pytest tests/test_translate.py tests/test_cfg_structure.py: 545 passed, 4 skipped.python -I tests/test_rdna2spirv_cli.py: 20 OK.python -m unittest discover -s tests/semantic: 4,142 OK.python -m compileall -q make_game.py tools tests,python -I make_game.py --help: OK.--wave64-emulate): 400/400 translated and passspirv-val. Control flow is 190 structured / 0 dispatch loop. With--max-structured-depth 16(main's behaviour) it is 186 / 4, and the nesting depth of all 190 trees matches49475796exactly. On49475796, only those 4.spvdiffered frommain's output.--max-structured-depth 0: 1,031/1,031 structured and passspirv-val.Builds on #1993 and #1904 (both merged).
🤖 Generated with Claude Code