Test/shader random control flow #3596

Open
Levichu51 wants to merge 5 commits from upstream-pr/3596 into main
Levichu51 commented 2026-11-27 20:05:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Levichu51 on 2026-11-27T20:05:19Z.


Builds on #1335 and #3591 (random vertex and mesh programs). Until those land, this branch also carries their commits; only the last one, cd0a7da, is new here.

Why

structure removes EXEC: lane masks become per-lane booleans, wave-wide mask tests become per-lane branches, and each vector instruction keeps a guard only where a lane can reach it outside EXEC. It is the most involved part of the translator, and the part most open PRs touch.

The random programs branched at random, but almost never in the shapes the console's compiler emits, so that work was barely tested.

What

Now and then a body item is divergent control flow as the compiler emits it. These constructs:

  • nest up to three deep, around random bodies;
  • come in 32- and 64-lane mask forms;
  • keep their masks in SGPRs (s48 on) that no random instruction writes.
Construct Shape
if v_cmp; s_and_saveexec; s_cbranch_execz; body; s_or exec
if-else (LLVM's form) s_xor of the else lanes; at the else, s_or_saveexec + s_xor exec
loop the lanes leave one by one s_or of the exits, s_andn2 exec, s_cbranch_execnz, s_or exec after
waterfall over a VGPR's values v_readfirstlane, v_cmp_eq, s_and_saveexec, body using the scalar, s_xor exec, s_cbranch_execnz
if on v_cmpx exec saved and restored
discard (pixel) v_cmpx of the killed lanes, s_andn2 from the live mask, s_cbranch_scc0 to an exp null kill block after the end

Of 16,384 programs, the number that translate with each construct:

if if-else loop waterfall v_cmpx discard wave64 saveexec
157 38 74 71 304 24 46

Also

  • Pixel programs mostly avoid v0–v1. The colour export used to read v0–v3; it now reads v2–v5, and depth v6–v7. A direct read of the barycentrics is refused, so pixel programs now translate about 7% of the time, up from 2.5%. Random operands also mostly avoid v0–v1. All seven barycentric kinds at once is now 1 program in 10 rather than 1 in 4.
  • Pixel programs also run as 64 lanes.
  • Run time: every program is still translated and checked for panics. Every third one is translated twice for determinism, with write marks on and off among them. This keeps the default run at about 6 s in a debug build even though programs are now longer.

Results

  • 1,500,000 programs pass in release with overflow checks and debug assertions.
  • A stress variant also passes: 300,000 programs with constructs five deep, four times as often. None took more than 200 ms.
  • The slowest of 8,192 default programs takes 13 ms in a debug build, so there is no structurisation blow-up.
  • No translator bug found.
  • cargo test -p victory-shader: 174 passed
  • cargo clippy -p victory-shader --all-targets [--all-features] --target x86_64-pc-windows-msvc -- -D warnings: clean
  • rustfmt on the changed file: clean; cargo xtask policy: ok

As with #1335, I ran it on Linux only. The Windows target was checked with clippy, not run; the test uses no GPU and no dxil.dll.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5532454539 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3596). Originally posted by [Levichu51](https://github.com/Levichu51) on 2026-11-27T20:05:19Z. --- Builds on #1335 and #3591 (random vertex and mesh programs). Until those land, this branch also carries their commits; only the last one, `cd0a7da`, is new here. ## Why `structure` removes EXEC: lane masks become per-lane booleans, wave-wide mask tests become per-lane branches, and each vector instruction keeps a guard only where a lane can reach it outside EXEC. It is the most involved part of the translator, and the part most open PRs touch. The random programs branched at random, but almost never in the shapes the console's compiler emits, so that work was barely tested. ## What Now and then a body item is divergent control flow as the compiler emits it. These constructs: - nest up to three deep, around random bodies; - come in 32- and 64-lane mask forms; - keep their masks in SGPRs (s48 on) that no random instruction writes. | Construct | Shape | |---|---| | if | `v_cmp`; `s_and_saveexec`; `s_cbranch_execz`; body; `s_or exec` | | if-else (LLVM's form) | `s_xor` of the else lanes; at the else, `s_or_saveexec` + `s_xor exec` | | loop the lanes leave one by one | `s_or` of the exits, `s_andn2 exec`, `s_cbranch_execnz`, `s_or exec` after | | waterfall over a VGPR's values | `v_readfirstlane`, `v_cmp_eq`, `s_and_saveexec`, body using the scalar, `s_xor exec`, `s_cbranch_execnz` | | if on `v_cmpx` | exec saved and restored | | discard (pixel) | `v_cmpx` of the killed lanes, `s_andn2` from the live mask, `s_cbranch_scc0` to an `exp null` kill block after the end | Of 16,384 programs, the number that translate with each construct: | if | if-else | loop | waterfall | `v_cmpx` | discard | wave64 saveexec | |---|---|---|---|---|---|---| | 157 | 38 | 74 | 71 | 304 | 24 | 46 | ## Also - **Pixel programs mostly avoid v0–v1.** The colour export used to read v0–v3; it now reads v2–v5, and depth v6–v7. A direct read of the barycentrics is refused, so pixel programs now translate about 7% of the time, up from 2.5%. Random operands also mostly avoid v0–v1. All seven barycentric kinds at once is now 1 program in 10 rather than 1 in 4. - **Pixel programs also run as 64 lanes.** - **Run time:** every program is still translated and checked for panics. Every third one is translated twice for determinism, with write marks on and off among them. This keeps the default run at about 6 s in a debug build even though programs are now longer. ## Results - 1,500,000 programs pass in release with overflow checks and debug assertions. - A stress variant also passes: 300,000 programs with constructs five deep, four times as often. None took more than 200 ms. - The slowest of 8,192 default programs takes 13 ms in a debug build, so there is no structurisation blow-up. - No translator bug found. - `cargo test -p victory-shader`: 174 passed - `cargo clippy -p victory-shader --all-targets [--all-features] --target x86_64-pc-windows-msvc -- -D warnings`: clean - rustfmt on the changed file: clean; `cargo xtask policy`: ok As with #1335, I ran it on Linux only. The Windows target was checked with clippy, not run; the test uses no GPU and no `dxil.dll`.
futurepro62 commented 2026-11-29 17:36:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-29T17:36:13Z.


Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head cd0a7da (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 868 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: random_programs_translate_or_are_refused_the_same_way_every_time, random_programs_are_reproducible_from_their_seed.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7259819947 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3596#issuecomment-7259819947). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-29T17:36:13Z. --- Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `cd0a7da` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **868 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `random_programs_translate_or_are_refused_the_same_way_every_time`, `random_programs_are_reproducible_from_their_seed`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Levichu51 commented 2026-11-29 19:18:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Levichu51 on 2026-11-29T19:18:08Z.


Thanks for the full run. Corrections to my description (and to the message of cd0a7da):

  • The construct table counted by instruction name, so random instructions inflated or hid the numbers. Counting the constructs actually generated, of 16,384 programs these translate: if 107, if-else 75, loop 106, waterfall 126, v_cmpx 115, discard 40, wave64 saveexec 76.
  • "Now and then" undersells it: 74% of programs contain a construct.
  • "SGPRs no random instruction writes" is wrong: a random 16-dword scalar load can reach s48 and up (at least 2.7% of programs). The test still holds, but those masks can be clobbered.
  • The stress run had constructs 4x as often at the top level and about 2.7x when nested.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7261170974 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3596#issuecomment-7261170974). Originally posted by [Levichu51](https://github.com/Levichu51) on 2026-11-29T19:18:08Z. --- Thanks for the full run. Corrections to my description (and to the message of cd0a7da): - The construct table counted by instruction name, so random instructions inflated or hid the numbers. Counting the constructs actually generated, of 16,384 programs these translate: if 107, if-else 75, loop 106, waterfall 126, v_cmpx 115, discard 40, wave64 saveexec 76. - "Now and then" undersells it: 74% of programs contain a construct. - "SGPRs no random instruction writes" is wrong: a random 16-dword scalar load can reach s48 and up (at least 2.7% of programs). The test still holds, but those masks can be clobbered. - The stress run had constructs 4x as often at the top level and about 2.7x when nested.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3596:upstream-pr/3596'
git switch 'upstream-pr/3596'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3596'
git switch 'upstream-pr/3596'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3596'
git switch 'upstream-pr/3596'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3596'
git switch 'main'
git merge --squash 'upstream-pr/3596'
git switch 'main'
git merge --ff-only 'upstream-pr/3596'
git switch 'main'
git merge 'upstream-pr/3596'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!3596
No description provided.