Skip to content

rdna2spirv: raise MAX_STRUCTURED_DEPTH to 64 and add --max-structured-depth (SHADER-427) - #3090

Merged
ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
Thatters:fix/shader-427-structured-depth
Nov 23, 2026
Merged

ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
Thatters:fix/shader-427-structured-depth

Conversation

@Thatters

@Thatters Thatters commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

SHADER-427 (claim). AI-assisted.

SHADER-299 (#1993) made the translator emit any structured tree deeper than MAX_STRUCTURED_DEPTH = 16 in the flat dispatch-loop form, because spirv-val time explodes with depth. At the time the corpus nested up to 118 deep. Since #1904 (cfg_structure hoists tails), the deepest tree in the corpus is 29. At those depths the flat form saves little spirv-val time, but NVIDIA compiles it 1.7-2x slower, and players pay that compile cost on their machines. This PR:

  • raises the default bound to 64: above the corpus, but still a guard where the SHADER-299 data showed spirv-val running 2.3x and more;
  • adds --max-structured-depth N to tools/rdna2spirv.py (0 = never fall back), so the trade can be revisited without editing code;
  • updates the comment above MAX_STRUCTURED_DEPTH and the SHADER-299 sentence of the docs/design.md "Control flow" row (only that sentence);
  • tests: _depth_arg validation and the option setting the bound (tests/test_rdna2spirv_cli.py), and 0 keeping 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 main 49475796: 25,734 disassembled inputs and 26,501 index entries; 12,944 modules get a structured tree.

depth > 16 > 18 > 20 > 24 > 28 > 29
modules 1,031 (747 CS, 284 PS) 712 57 24 1 0

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:

set form round 1 summed / wall round 2 summed / wall ratio
all 284 deep PS (depth 17-29) structured 872 s / 221 s 783 s / 199 s
dispatch loop 1,404 s / 354 s 1,360 s / 343 s 1.67x
4 deep CS (depth 19-24) structured 284 s / 285 s 310 s / 310 s
dispatch loop 594 s / 595 s 589 s / 590 s 2.0x (1.6-2.7x per module)

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-val CPU 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_barrier over the bound gets the dispatch loop without rounds. No corpus module reaches it (the structured wave32 CS with s_barrier have 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 on 49475796; the branch is rebased onto 16282101, which changes neither cfg_structure.py nor 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.
  • 400-module sample (--wave64-emulate): 400/400 translated and pass spirv-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 matches 49475796 exactly. On 49475796, only those 4 .spv differed from main's output.
  • The 1,031 corpus modules over depth 16, translated with --max-structured-depth 0: 1,031/1,031 structured and pass spirv-val.

Builds on #1993 and #1904 (both merged).

🤖 Generated with Claude Code

…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>
@kacper-serewis

Copy link
Copy Markdown
Contributor

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.

@kacper-serewis

Copy link
Copy Markdown
Contributor

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:

Stage/depth Parent compile seconds Head compile seconds Parent/head wall seconds Parent/head peak job commit MiB
PS18 2.079 1.312 2.534 / 1.502 215.3 / 163.8
PS21 6.849 4.713 7.068 / 4.924 544.1 / 343.3
CS19 128.481 20.982 128.739 / 21.258 796.4 / 752.8
CS29 35.947 14.146 36.285 / 14.431 2293.8 / 1060.6

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.

@UNYTIX

UNYTIX commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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.

  • python -I tests/test_rdna2spirv_cli.py: 20 tests, OK.
  • python -m pytest tests/test_translate.py -q: 541 passed, 4 skipped (the make_shader tests skip on this machine: no llvm-mc).
  • python -I tests/test_cfg_structure.py: ok: 18228 graphs structured and run, 1772 irreducible (1755 split-structured, 17 capped), 12692 with loops.
  • Read the guard in assemble and _depth_arg: 0 disables the bound (if MAX_STRUCTURED_DEPTH and nesting > …), negatives and non-integers are refused, and the only behaviour the new default changes is that modules nesting 17–64 deep keep the structured form, which is what the measurement in docs/design.md argues for. The --help text and the Control flow row match the code, and nothing else reads MAX_STRUCTURED_DEPTH.

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 test_deep_structured_nesting_uses_the_dispatch_loop and on CI.

…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>
@controldebils

Copy link
Copy Markdown
Contributor

Tested 5c6d008 (merged onto main 16282101) on AMD Radeon RX 6900 XT (RDNA2, gfx1030), AMD proprietary driver 26.11.2 (Windows 32.0.21045.29003), Windows 11. AI-assisted.

  • pytest tests/test_rdna2spirv_cli.py tests/test_translate.py: 561 passed, 4 skipped.
  • scripts/run_gpu_tests.py (runtime built from 16282101, MSVC Build Tools 2022): 174/189 passed, 15 skipped, 0 failed; the per-test results are identical to main 16282101 on the same card. The skips are the 14 tests run by the d3d12 tests and ps_w64x_readlane (no 64-wide fragment subgroup).

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).

@JRamos1993

Copy link
Copy Markdown
Contributor

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:

  • scripts/run_gpu_tests.py: 143/189 passed, 46 skipped, 0 failed. main 1628210 gives 143/189, 46 skipped, 0 failed. All 194 test shaders translate and pass spirv-val.
  • tests/test_rdna2spirv_cli.py: ran 20 tests in 2.297s; OK.
  • tests/test_translate.py (pytest): 541 passed, 4 skipped.

AI-assisted (Claude Code).

@javdc

javdc commented Nov 22, 2026

Copy link
Copy Markdown

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:

  • python3 -m pytest tests/test_rdna2spirv_cli.py tests/test_translate.py -q — 562 passed, 4 skipped, 29 subtests passed

Full GPU suite:

  • python3 -I scripts/run_gpu_tests.py --build /home/deck/opencode/Leonida/runtime/build — 175/189 passed, 14 skipped, 0 failed. Skips are the expected D3D12-owned skips on this Deck.

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>
@Thatters

Copy link
Copy Markdown
Contributor Author

Thanks @kacper-serewis. Both points are fixed in 48a4c4d. b21c38e merges origin/main (f847748) to clear the conflicts. AI-assisted.

  1. Barrier decision vs assembly: the new capped_tree(succ) returns the tree assemble() emits, or None once it nests deeper than MAX_STRUCTURED_DEPTH, and needs_barrier_rounds() now decides from that same tree. It is the only call to cfg_structure.structure left in the translator. Regression fixture: test_top_level_barrier_over_the_depth_bound_runs_in_barrier_rounds, a hand-written wave32 CS with a top-level s_barrier followed by four nested guards. At the default bound it is structured with a single in-place OpControlBarrier. With the bound set one below its depth it now runs in barrier rounds, with no OpControlBarrier left in the switch cases. Both pass spirv-val. With the old line restored, the test fails at the barrier-rounds assertion.

  2. The CLI test now pins the default to the literal 64 (it also checks the module constant against 64 first).

At the default bound nothing in the corpus changes (the deepest tree is 29), so this only affects runs with --max-structured-depth below a shader's depth. On the 400-module sample the output at 48a4c4d is byte-identical to 5c6d008.

Re-run on b21c38e (Windows 11, RTX 5070 Ti / 621.24): pytest tests/test_translate.py tests/test_cfg_structure.py 567 passed, 4 skipped. tests/test_rdna2spirv_cli.py 27 OK (1 skipped). unittest discover -s tests/semantic 7,322 OK (1 expected failure). compileall and make_game.py --help OK. 400-module sample: 400/400 translated and pass spirv-val, with 190 structured and 0 dispatch loop; --max-structured-depth 16 gives main's 186 / 4. Nesting depths are unchanged on all 190 trees.

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.

@maxhurst131

Copy link
Copy Markdown
Contributor

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 (rdna2spirv: raise MAX_STRUCTURED_DEPTH to 64 and add --max-structured-depth, SHADER-427).

Tested on NVIDIA RTX 5070 (driver 32.0.16.2124, subgroup 32..32):

  • python -I scripts/run_gpu_tests.py --llvm-mc "wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc" -> 143/189 passed, 46 skipped
  • Same count as main branch baseline: no regression introduced.

Tested on AMD Radeon Ryzen 7600X iGPU (driver 32.0.21045.29003, subgroup 32..64):

  • Same command -> 168/189 passed, 21 skipped
  • Same count as main branch baseline: no regression introduced.

The --max-structured-depth N flag controls the maximum depth of structured trees before falling back to the dispatch-loop form. On both tested GPUs, the default bound of 64 (raised from 16) does not change test outcomes, as the corpus depth distribution shows most structures are well within this limit.

No game files used; counts only. Verified on both GPUs; no unexpected regressions.

- maxhurst131 (second agent), 2026-11-22

@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested b21c38e1 (merged with main f847748c) on RTX 4070 (Ada, NVIDIA 621.01, subgroup 32..32), Windows 11 (10.0.26300), llvm-mc 23.1.6 (AMDGPU), spirv-val from Vulkan SDK 1.4.363.1, Python 3.14.6: pass.

  • scripts/run_gpu_tests.py: 153/199 passed, 46 skipped, 0 failed, identical to f847748c. pytest tests/test_translate.py tests/test_rdna2spirv_cli.py: 589 passed, 5 skipped (586 on the base; the skips are synthetic-DXBC and symlink-privilege ones, same as the base). The full tests/semantic suite: 7322 OK on both. The docs tests pass.
  • Negative control: with only tools/rdna2spirv.py restored to f847748c, four of the new tests fail (test_top_level_barrier_over_the_depth_bound_runs_in_barrier_rounds, test_deep_structured_nesting_uses_the_dispatch_loop, ArgumentTypes.test_max_structured_depth and ArgumentTypes.test_max_structured_depth_sets_the_bound); with the change all 589 pass.

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.

@sovljanskii

Copy link
Copy Markdown
Contributor

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 --max-structured-depth 16, which is main's behaviour.

  • 1,031 modules take the dispatch loop: 747 CS and 284 PS. That is exactly your count.
  • I re-translated only the timed listings (all 284 PS + 10 CS) with the PR's default (64), not the whole corpus. They are 294/294 translated, 294/294 spirv-val valid and 294/294 structured.

Method

  • Both sides use the same module names, the same index.json entries and the same stubs. No pipeline cache file.
  • Metal keeps its own shader cache, so each module is timed once per side, and the side that goes first alternates.
  • PS: 12 chunks of 24 (the last one 20) with --jobs 4 --slow 0, dispatch loop then structured or the reverse.
  • CS: the 10 picked at the 5th, 15th, …, 95th size percentile of the 747 (3.0-6.7 MB), one module at a time with --jobs 1.
set dispatch loop (bound 16) structured (bound 64) ratio
284 PS, wall summed over the 12 chunks 1,204 s 543 s 2.22x
284 PS, per-pipeline time summed 4,160 s 1,919 s 2.17x
284 PS, median per pipeline 4.55 s 2.70 s
10 CS, alone (wall) 2,289 s 918 s 2.49x (2.00-2.93x per module, structured faster on all 10)
10 CS, median 209.9 s 92.0 s
pipelines created 294 ok, 0 failed, 0 skipped 294 ok, 0 failed, 0 skipped

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:

dispatch-loop time modules dispatch loop structured ratio structured slower on
0.2-2 s 22 19.3 s 19.0 s 1.02x 5
2-10 s 116 540.1 s 395.0 s 1.37x 5
10-60 s 82 2,424.3 s 1,181.6 s 2.05x 2
over 60 s 14 1,167.0 s 318.7 s 3.66x 0
  • Small modules. 43 PS are under 0.2 s in the dispatch-loop form and 46 in the structured form; the ones under 0.2 s in the dispatch-loop form are 0.0-0.2 s in the structured form as well, except one at 0.8 s. They are tiny modules or Metal cache hits from my earlier corpus runs, equal on both sides, so they are left out of the bands.
  • Where structured was slower. Of the 234, 12 are slower structured, mostly by tenths of a second. Three are slower by a lot: 6.9 → 82.4 s, 45.3 → 83.1 s and 50.5 → 86.5 s.
    • Under --jobs 4 the per-pipeline time includes waiting in MTLCompilerService, so those three may have queued behind a large module in their chunk.
    • Metal now has both forms cached, so I can't re-time them alone. The chunk walls, which include them, still come out 2.22x in favour of structured.

No game data (counts and timings only). The module outputs are deleted again. AI-assisted.

@sovljanskii

Copy link
Copy Markdown
Contributor

Follow-up: the head moved to b21c38e1 while I was timing. The timings above are for 5c6d0087.

Does the new head change them? No. 5c6d0087 is unchanged on the new head, which only adds 48a4c4d1 and a merge of main. The barrier change can't move the timed modules: at bound 64 none of them is capped (the corpus maximum is 29), so capped_tree returns the same tree as before.

48a4c4d1 (barrier rounds from the depth-capped tree) is the fix I suggested in the #1993 note, and it works:

  • On b21c38e1, pytest tests/test_translate.py -k "barrier or deep_structured or dispatch_loop" gives 17 passed (with llvm-mc on PATH), and tests/test_rdna2spirv_cli.py is OK.
  • Negative control: I reverse-applied only the tools/rdna2spirv.py part of 48a4c4d1. test_top_level_barrier_over_the_depth_bound_runs_in_barrier_rounds then fails on assert gen.bar_rounds and gen.control_flow == "barrier rounds", the case from rdna2spirv: bound structured nesting depth with the dispatch-loop form (SHADER-299) #1993. With the fix in place it passes.

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>
@SebSilent

Copy link
Copy Markdown
Contributor

CPU-side verification pass on head 0d10f72ee (no GPU here, so nothing about the timing numbers, just the code and the tests).

The capped_tree refactor holds up. Both call sites now agree on which tree the emitter will actually produce: assemble() at tools/rdna2spirv.py:12553 and needs_barrier_rounds() at :14216. That closes the mismatch from the #1993 review, where the barrier decision looked at the uncapped tree while the emitter fell back to the dispatch loop. The over-the-bound case is handled the right way round too: tree is None makes top the empty set, so any barrier forces rounds instead of being read as top-level, and MAX_STRUCTURED_DEPTH = 0 short-circuits the bound so --max-structured-depth 0 really means never fall back.

Red before / green after. pytest tests/test_translate.py -q -k "deep_structured or barrier": 17 passed here, 16 on origin/main, the extra one being the new test_top_level_barrier_over_the_depth_bound_runs_in_barrier_rounds. As my own negative control I deleted just the if MAX_STRUCTURED_DEPTH and nesting > MAX_STRUCTURED_DEPTH: return None, nesting arm from capped_tree and re-ran that single test: it fails. Restored, tree clean.

Suites I ran at head:

  • tests/test_rdna2spirv_cli.py: 26 passed, 1 skipped, 29 subtests.
  • tests/test_translate.py (full): the 16 failures I get in this checkout are the same failing set on origin/main, so nothing new from this PR.
  • tests/semantic -k barrier: 5 failed, 35 passed. The 5 are the emulate=True cases in test_loop_ballot_barrier.py, byte-identical failing set on origin/main, i.e. the known wave64 emulation ones from tests/semantic: restore test_loop_ballot_barrier after structured wave64 emulation #3953, not this change.
  • tests/test_docs_cli_flags.py, test_docs_design_rows.py, test_docs_links.py, test_docs_list_items.py, test_docs_repo_paths.py: 15 passed, 3 subtests.
  • python -m compileall tools/rdna2spirv.py: clean. Diff is the four files it should be, git diff --check clean.

CLI behaviour: --max-structured-depth abc, -3 and 1.5 all exit 2 with a single error: line (not a whole number: 'abc' / must be 0 (no bound) or a positive depth), same shape as the tool's other argparse failures. 0 is accepted.

Docs: the docs/design.md edit is the one SHADER-299 sentence in the Control flow row, nothing else in that file moved.

One note for whoever merges: CI is still queued on this head (change-scope, no-game-data, windows, linux-gpu-tools all show no result yet), and mergeStateStatus is UNSTABLE, which lines up with that rather than with anything in the diff.

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>
@cxchhh

cxchhh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested fb7f380c on Tesla V100-SXM2-32GB (Volta, subgroup 32..32), NVIDIA 580.95.05, Ubuntu 24.04 (kernel 6.14.11), Python 3.12: pass.

Setup: the PR diff applied to main 98fa503f (applies cleanly), Linux Vulkan test programs built from that tree (cmake -S runtime -G Ninja), compared against an untouched main 98fa503f built the same way.

  • scripts/run_gpu_tests.py: native 161/217 passed, 56 skipped; LEONIDA_W64_EMULATE=1 LEONIDA_BARY_FALLBACK=1 194/217 passed, 23 skipped. 0 failures, and the same per-test result as main in both modes (the skips are the 64-wide, mesh-shader (Volta has no VK_EXT_mesh_shader), barycentric-only and run by d3d12_* tests).
  • python -m unittest discover -s tests/semantic (llvm-mc 23.1.6, SPIRV-Tools 2026.4 on PATH): 6245 tests, failures=3, errors=2: the same five test_loop_ballot_barrier cases that fail on main here, nothing new.
  • tests/test_rdna2spirv_cli.py: 32 OK, 1 skipped (main: 30). pytest tests/test_translate.py (with llvm-mc/spirv-as/spirv-val on PATH, so nothing skips): 597 passed (main: 596).
  • Negative control: the PR's two test files on main's tools/: test_rdna2spirv_cli 1 failure + 1 error, test_translate 2 failed.
  • Not measured: NVIDIA compile time of the corpus at the new bound (no game shaders used here).

No game files. AI-assisted (Claude Code); I ran the commands above and checked the numbers against the logs.

@PeterGrieffindor

Copy link
Copy Markdown

Tested 0d10f72e (the head before main was merged in again; this PR's own change is identical at fb7f380c) on AMD Radeon RX 9070 XT (RDNA4), AMD 26.11.2 (LLPC), Windows driver 32.0.32029.2010, Windows 11 build 26300: pass, and on this driver the PR matters far more than 2x. One catch: the structured forms need more than the checker's 1 MB stack. AI-assisted (Claude Code).

Tests (llvm-mc 21.1.8 native, SPIRV-Tools v2026.4, Python 3.14.5): python -I tests/test_rdna2spirv_cli.py 27 tests OK (1 skipped); pytest tests/test_translate.py -q 582 passed, 4 skipped.

Corpus (a 1.0.2.1 package that matches the manifest; counts and timings only). At main aa2988cc, translated with native wave64, 1,065 modules take the dispatch loop: 781 CS and 284 PS. I translated those 1,065 listings with this head twice:

  • default bound (64): 1,065 translated, 1,065 pass spirv-val; 1,063 structured, 2 small CS still in the dispatch loop;
  • --max-structured-depth 16: 1,065 translated, 1,065 pass spirv-val; all in the dispatch loop, every .spv the same size as main's.

Pipeline creation on the AMD Windows driver. Each module alone in a fresh process (vk_pipeline_check <dir> --jobs 1 --start N --count 1), no pipeline cache file, several processes side by side.

set dispatch loop (bound 16) structured (bound 64)
all 284 PS 284 created; 9,702 s summed, median 12.9 s, max 252 s 284 created; 817 s summed, median 1.5 s, max 18.7 s (11.9x less)
7 CS picked by size, 3.5 to 8.5 MB one took 689 s; the other six were not finished after 25 minutes each 16, 20, 34, 43, 40, 42 and 86 s
all 781 CS not run to the end: in the pipelines stage one took 39 minutes, and two more were stopped at 30 minutes 778 created within 10 minutes each (median 45 s, 90% within 65 s, max 266 s, 35,671 s summed); the three largest modules (19 to 30 MB) were not finished after 10 minutes

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 main the pipelines stage cannot finish on this driver (I stopped mine), and with this PR it can. NVIDIA's 1.7 to 2x is not the size of the effect on AMD.

The catch: stack. The structured forms nest deeper and the driver's compiler recurses with them. With vk_pipeline_check as it is built (the PE default, a 1 MB stack):

  • all 284 structured PS pass;
  • of 60 structured CS picked evenly by size, 28 exit 0xC00000FD (stack overflow): every one from 4.76 MB up. The 32 up to 4.6 MB pass.
  • The same 28 with only the stack reserve changed (editbin /STACK on a copy of the binary): 18 pass and 10 still overflow at 2 MB, all 28 pass at 4 MB. The 778 above were measured at 8 MB.

main already has the same overflow on 26 mesh modules (finding), so this is not new with the PR, but the PR moves several hundred compute modules onto it. On AMD the two belong together: a larger stack for the checker (and for the threads the runtime creates pipelines on), then this bound.

Not measured: memory use, other AMD GPU families, and a corpus translated with --wave64-emulate.

@kapitche

Copy link
Copy Markdown
Contributor

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 python -I and fails the same way on main. Negative control (Windows) with main's tools/rdna2spirv.py: test_rdna2spirv_cli (1 failure, 1 error) and test_translate (2 failed) fail.

@lunarminus

Copy link
Copy Markdown

Tested fb7f380c merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • What I tested: fb7f380c already contains main up to 2d3369a4. Merging it onto d0835dd9 was a fast-forward, so the tree I tested is fb7f380c itself.
    • I built the Linux test programs from that tree (cmake --build runtime/build/linux).
    • For the per-test comparison I also ran 2d3369a4 without the PR on the same build.
  • scripts/run_gpu_tests.py, native: 202/217 passed, 15 skipped, 0 failed.
  • scripts/run_gpu_tests.py, LEONIDA_W64_EMULATE=1: 202/217 passed, 15 skipped, 0 failed.
  • Per test against 2d3369a4 without the PR: identical in both modes.
  • Per test against main d0835dd9 without the PR (196/210, 14 skipped): identical for every test the baseline has.
    • Seven tests exist only in the newer main (not added by this PR): cs_smem_sconst_off, ps_far_branch, ps_sample_c, ps_sample_c_b, ps_texture_b_cl, ps_texture_cl pass and ps_m2_literal is skipped, in both modes.
    • The suite does not exercise the new bound. Its 221 inputs translate byte-identically with --max-structured-depth 16 and with the default 64, both natively and with LEONIDA_W64_EMULATE=1. So the GPU suite shows that nothing regressed, but not that the bound works.
  • pytest tests/test_translate.py tests/test_cfg_structure.py (AMDGPU clang/llvm-mc 23.1.5, so the make_shader tests run): 601 passed, 0 skipped (2d3369a4: 600).
    • test_top_level_barrier_over_the_depth_bound_runs_in_barrier_rounds and test_deep_structured_nesting_uses_the_dispatch_loop both PASSED.
  • python -I tests/test_rdna2spirv_cli.py: 32 tests OK, 1 skipped (2d3369a4: 30).
  • unittest discover -s tests/semantic -p 'test_*barrier*': 40 run, 3 failures and 2 errors, the same set on 2d3369a4. They are the emulate cases of test_loop_ballot_barrier.
  • tests/test_docs_*.py: 30 passed. compileall and make_game.py --help: OK.
  • Nit: test_max_structured_depth_sets_the_bound passes, but its --out sits inside the input folder.
    • Since BUILD-1044, main() therefore prints ERROR: --out ... is the input folder or inside it three times and returns 2 after the bound is set.
    • A sibling output folder would keep the test off that path.
  • Not run: the full tests/semantic suite (it did not finish before this report) and the corpus or pipeline-compile timings (they need game shaders).

AI-assisted (Claude Code).

@Thatters

Copy link
Copy Markdown
Contributor Author

Thanks @PeterGrieffindor, and @cxchhh, @kapitche and @lunarminus for the passes on fb7f380c.

On the AMD stack catch: this PR doesn't change vk_pipeline_check, so I've left the stack size out of it. The two open PRs that link the checker with an 8 MB stack on Windows, #4940 and #4979, cover it, and your 4 MB result says either one is enough for the 28 compute modules that overflow. So on AMD Windows this bound should land with or after one of those. Until then, --max-structured-depth 16 keeps main's dispatch-loop form, byte for byte as your run showed, for anyone checking on that driver.

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 fb7f380c, with main up to 2d3369a4 merged in, and mergeable. CI is waiting on workflow approval. AI-assisted (Claude Code).

@PeterGrieffindor

Copy link
Copy Markdown

Thanks. On the runtime's stack: here is what a read of main 3faac557 and a build of it show, in case it saves you the look.

  • Pipelines are created on the caller's thread. shims/d3d12_vulkan_device.cpp calls vkCreateComputePipelines and vkCreateGraphicsPipelines inline while it creates the pipeline state, so the stack is the one of whichever game thread makes the call.
  • The entry thread has 8 MB. run_entry starts the game's entry point with CreateThread(..., stack_bytes, ..., STACK_SIZE_PARAM_IS_A_RESERVATION), and the default is 8u << 20 (shims/process_shim.h). That is the size at which all 26 mesh and 28 compute modules pass here.
  • Other threads are not covered. The runtime has no other CreateThread, and system imports resolve to the real DLLs (src/pe_loader.cpp). So a thread the game starts with dwStackSize 0, and any thread-pool or std::thread thread, gets the reserve in gta6rt.exe's header. That is the linker default: SizeOfStackReserve is 0x100000 in my MSVC build. A thread with an explicit size gets what the game asks for.

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. /STACK:8388608 on gta6rt would cover the default-size threads. It would not cover a small explicit size; for that, pipeline creation would have to move to a thread the runtime owns. I hold BUILD-1457 and have the driver and the modules to test with, so I can take it if you prefer. Say which.

AI-assisted (Claude Mythos 5.2).

@Thatters

Copy link
Copy Markdown
Contributor Author

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.