Shaders: VICTORY_WAVE_VERIFY=check, a report-only checker that proves wave64 forms meet their group barriers #3336

Open
AimLogin wants to merge 1 commit from upstream-pr/3336 into main
AimLogin commented 2026-11-29 21:56:25 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by AimLogin on 2026-11-29T21:56:25Z.


What it changes

On a host of 32-lane waves, a console wave64 compute program runs in one of several forms:

  • folded (crate::fold);
  • the wave-wide forms of widen: modes All, SafeSingleWave and DriverLoop, and the wide fallback;
  • the half meets and the pair meetings.

Several of these forms put group barriers inside control flow that the translator decides per wave. DXIL's contract with the driver is that a group barrier sits only in group-uniform control flow. A barrier that one wave of a group reaches and another does not, or reaches a different number of times, is undefined behaviour. On the card it can hang the group or give a device loss. Nothing in the tree checks this after lowering today.

This PR adds a checker that proves it, report only:

  • VICTORY_WAVE_VERIFY=check switches it on. It is off when the variable is unset or has any other value.
  • After each translation in a barrier-inserting form, it proves the program the lowering actually lowered. The group barriers are counted per IR block where the lowering emits them, not taken from a plan.
  • It writes one line per program to stderr:
    • W64-VERIFY … pass;
    • fail, with the barrier block, the branch it depends on, what that branch reads, and the roots of its non-uniformity;
    • unmodelled, with the reason.
  • victory translate also prints a W64-PROGRAM <label> line before each wave64 compute program, so a verdict can be matched to its program.
  • It never changes which form runs or what is emitted. Its only state is thread-local and read by itself. With the switch off, the lowering notes nothing and no check runs.

The pieces:

  • emit/verify_groups.rs: the group verifier. Its model is one host wave per console wave, with branches of four kinds: group-uniform, group vote, wave-predicated, per wave.
    • B1: every barrier's iterated control dependence holds only group-uniform branches and votes. Post-dominators use a virtual exit, so an early s_endpgm counts. This is the formal form of "a barrier only in uniform control flow".
    • Group uniformity comes from a value analysis, credited to #1140's is_group_uniform_val. Thread ids, LDS and memory results, lane reads and per-wave joins are not uniform. A scalar load is uniform only at a uniform address in a program that does not write memory there.
    • B7, progress: a loop decided per wave must not wait on a word that another wave writes only later.
    • LOOP_LIMIT stops are made explicit. They are modelled conservatively, as leaving the program, as abort_block does.
  • emit/wave_interp.rs (test only): B8, a CPU interpreter that runs a group's waves under several schedules. It is the reference that a proved graph meets under every schedule, and that a divergent one deadlocks.
  • emit/w64_check.rs: the checker and its per-form model.
    • Groups of one console wave (64 threads) in the wave-wide forms: the two host halves are the waves, and a Structured::wide branch is a vote.
    • Fold: one host wave per console wave, with wave-wide branches decided per wave. A folded group of at most 32 host threads is one host wave and passes trivially.
    • Spin meetings (pair meetings, half meets) are reported unmodelled.
  • Hooks, which only count:
    • widen's success return, which covers every wave-wide form, the fallback, the half meets and the pairs;
    • folded;
    • emit_program_plain, which notes the IR and structure it lowers. The note is dropped when it returns, so a later lowering is never checked against another program's IR;
    • the lowering's two group-waiting barrier sites (group_sync and the title's s_barrier), and the half-meet and pair-meeting spins.
  • shader_cache.rs: VICTORY_WAVE_VERIFY is in NOT_TRANSLATION, because it changes no translation.
    • It is not in KEYED: that would change everyone's key with the switch off.
    • As with any change under victory-shader/src, the translator source hash changes, so a build with this PR starts once with a cold shader cache.

How it was tested

Byte identity (offline census, the switch on and off). victory translate --list --jobs 1 over the title's shaders.rpf, with VICTORY_HOST_WAVE=32 VICTORY_HOST_MAX_WAVE=32:

  • On 829188e9: 0 of 25,693 emitted modules differ between the checker on, the checker off and the unpatched build. The --list module hashes and the VICTORY_SHADER_CENSUS instruction counts are both identical.
  • On f889bb07 with VICTORY_WAVE_FOLDED=1 plus #2853 and #2265: 0 of 25,693 modules differ with the checker on.
  • On this branch's base, cec481f4, with the upstream default switches: 0 of 25,693 emitted modules differ between the unpatched build and this branch with the checker on.
    • With the checker on, it printed 1,151 W64-PROGRAM lines and 148 verdicts.
    • The verdicts are 136 folded: pass, 10 folded: fail and 2 pair meetings: unmodelled.
    • (The measured build predates two clippy::manual_is_multiple_of fixes, x % n == 0 → x.is_multiple_of(n). They change no behaviour, and the tests were re-run on the final patch.)
  • No game data is in the tree or in this PR. The checker's lines hold digests, block numbers and instruction names only.

What it reports on the title (f889bb07 + FOLDED=1 + #2853 + #2265):

  • folded: 264 pass, 10 fail;
  • pair meetings: 2 unmodelled;
  • the wave-wide forms: no title program reaches them there.
  • Every fail is a title s_barrier in a region that a folded s_cbranch_execz skips when a console wave has no lane left. The branch's condition comes from thread ids (in 4 of them, also a scalar load).
  • In the end-to-end test below, widen (mode All) emits a title s_barrier inside a per-lane branch it does not widen. The checker fails it. No title program takes that path today.

Unit tests (cargo test -p victory-shader --lib, no GPU, no game data). Every fixture is hand-written GFX10 machine code or a hand-written group graph. Each negative case has a control that must give the other result:

test fails (as it must) control passes
t1: a barrier in a per-lane branch of a wave-wide form (All, fallback, SafeSingleWave, DriverLoop) Divergent the same branch taken wave-wide; the barrier after the join
t1b: a host_wide branch is per wave Divergent –
t2: a wave-wide latch fed by an LDS word written after the loop VoteWaitsOnLater the word written before the loop
t5: fold, a barrier under a per-wave branch and an early end fail no branch or no end; one host wave
t6: pair meetings, half meets, any spin unmodelled the same program without a spin is decided
t7: the wide fallback on an unprovable fixture fail switch off: nothing taken, nothing noted
t8: barrier dedup (#42) only removes barriers removing any block's barriers keeps a pass a barrier added in the lane region fails
t11: B8 over the passing graphs – 2 host waves meet under every schedule; the divergent control deadlocks
mutation probe: a checker that passes everything caught by every negative case –
e2e: widen on the wave OR fixture – pass; DXIL equal with the checker on and off
e2e: widen with a title s_barrier in a lane branch fail DXIL equal on and off
a lowering that no note names; another program's run unmodelled the right program is decided
barrier inventory fails on any new or moved dx.op.barrier site in production code, so each site is classified (waits for the group or not) before it can go uncounted –

In addition:

  • verify_groups has 41 tests and wave_interp 14, each with negative controls.
  • victory-gpu's every_switch_of_the_translator_is_in_the_key covers the new switch.
  • On cec481f4:
    • cargo test --release --locked -p victory-shader --lib -- emit::w64_check emit::verify_groups emit::wave_interp: 73 passed;
    • cargo test --release --locked -p victory --bin victory: 79 passed;
    • cargo clippy --locked -p victory-shader -p victory --all-targets: no warning in a file this PR touches.
    • The tree already has warnings elsewhere (for example shader_cache.rs:14's unused AtomicBool and lower.rs:594's unused import), so a workspace-wide -D warnings run fails without this PR as well.
  • every_switch_of_the_translator_is_in_the_key fails on cec481f4 with and without this PR, on VICTORY_SCALAR_SPLITS, which is still in KEYED but no longer read (#3189; #3061 fixes it). The check this PR's switch needs, that no translator switch is left out of the lists, comes before that assertion and passes.

Test details:

  • Hardware: RTX 4060 Ti 16 GB, Windows 11. The checker runs on the CPU only; no GPU test is part of this PR.
  • Wave sizes: a 32-lane host (VICTORY_HOST_WAVE=32). On a 64-lane host the wave64 forms are not taken.
  • cargo test passed for the crates it touches: yes (victory-shader and victory on cec481f4). The victory-gpu key test fails on #3189 only (fixed by #3061), as it does without this PR.

Limits (stated plainly)

  • Liveness and progress only, not data races. LDS ordering across meetings is not checked.
  • Values are not checked. The fold's value correctness and approximate forms are outside a liveness checker.
  • Spin meetings are unmodelled. This covers the pair meetings and the half meets. Proving them needs a subgroup model of the meeting words.
  • Wave-wide forms in groups of several console waves are unmodelled.
  • LOOP_LIMIT is modelled as leaving the program, as abort_block does. A per-wave loop ahead of a later barrier therefore fails the barrier. That is conservative, and real on the host: a wave that leaves does not meet the barrier.
  • Barriers are counted before bitcode::opt. The barrier dedup (#42) only drops barriers inside one DXIL block, which keeps liveness (t8). On the title at 829188e9, it changes the barrier count of no checked program (measured with VICTORY_SHADER_OPT=191).
  • With the switch on, a program served from the shader cache prints nothing. Use victory translate or a cold cache.
  • Report only. A gate that refuses failing forms is a separate decision, and would then have to enter the cache key.

Provenance and licence

  • verify_groups.rs, wave_interp.rs and w64_check.rs, with their tests, are our own work, GPL-3.0-or-later like this workspace. Each file carries an SPDX line.
  • Existing code is only hooked into, not copied.
  • The value analysis follows #1140's is_group_uniform_val.
  • safe_single_wave_widen (#1006) is a possible cross-check of the uniformity verdicts. It is not used here.
  • AI-assisted: written with Claude (Anthropic) under human direction. The tests and the corpus census above were run, and their results are measured, not assumed.

Checked for overlap

  • I searched the open pull requests for a group or barrier verifier, uniformity checks after lowering, and VICTORY_WAVE_VERIFY: there are none.
  • Related, no conflict: #2265 and #2261 (fold), #2389 (lane_uniform), #2421 (cross-half barriers; adds barriers, so this checker would see them).

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5555554436 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3336). Originally posted by [AimLogin](https://github.com/AimLogin) on 2026-11-29T21:56:25Z. --- ## What it changes On a host of 32-lane waves, a console wave64 compute program runs in one of several forms: - folded (`crate::fold`); - the wave-wide forms of `widen`: modes All, SafeSingleWave and DriverLoop, and the wide fallback; - the half meets and the pair meetings. Several of these forms put group barriers inside control flow that the translator decides per wave. DXIL's contract with the driver is that a group barrier sits only in group-uniform control flow. A barrier that one wave of a group reaches and another does not, or reaches a different number of times, is undefined behaviour. On the card it can hang the group or give a device loss. Nothing in the tree checks this after lowering today. This PR adds a checker that proves it, report only: - `VICTORY_WAVE_VERIFY=check` switches it on. It is off when the variable is unset or has any other value. - After each translation in a barrier-inserting form, it proves the program the lowering actually lowered. The group barriers are counted per IR block where the lowering emits them, not taken from a plan. - It writes one line per program to stderr: - `W64-VERIFY … pass`; - `fail`, with the barrier block, the branch it depends on, what that branch reads, and the roots of its non-uniformity; - `unmodelled`, with the reason. - `victory translate` also prints a `W64-PROGRAM <label>` line before each wave64 compute program, so a verdict can be matched to its program. - **It never changes which form runs or what is emitted.** Its only state is thread-local and read by itself. With the switch off, the lowering notes nothing and no check runs. The pieces: - `emit/verify_groups.rs`: the group verifier. Its model is one host wave per console wave, with branches of four kinds: group-uniform, group vote, wave-predicated, per wave. - **B1:** every barrier's iterated control dependence holds only group-uniform branches and votes. Post-dominators use a virtual exit, so an early `s_endpgm` counts. This is the formal form of "a barrier only in uniform control flow". - Group uniformity comes from a value analysis, credited to #1140's `is_group_uniform_val`. Thread ids, LDS and memory results, lane reads and per-wave joins are not uniform. A scalar load is uniform only at a uniform address in a program that does not write memory there. - **B7, progress:** a loop decided per wave must not wait on a word that another wave writes only later. - `LOOP_LIMIT` stops are made explicit. They are modelled conservatively, as leaving the program, as `abort_block` does. - `emit/wave_interp.rs` (test only): **B8**, a CPU interpreter that runs a group's waves under several schedules. It is the reference that a proved graph meets under every schedule, and that a divergent one deadlocks. - `emit/w64_check.rs`: the checker and its per-form model. - Groups of one console wave (64 threads) in the wave-wide forms: the two host halves are the waves, and a `Structured::wide` branch is a vote. - Fold: one host wave per console wave, with wave-wide branches decided per wave. A folded group of at most 32 host threads is one host wave and passes trivially. - Spin meetings (pair meetings, half meets) are reported `unmodelled`. - Hooks, which only count: - `widen`'s success return, which covers every wave-wide form, the fallback, the half meets and the pairs; - `folded`; - `emit_program_plain`, which notes the IR and structure it lowers. The note is dropped when it returns, so a later lowering is never checked against another program's IR; - the lowering's two group-waiting barrier sites (`group_sync` and the title's `s_barrier`), and the half-meet and pair-meeting spins. - `shader_cache.rs`: `VICTORY_WAVE_VERIFY` is in `NOT_TRANSLATION`, because it changes no translation. - It is not in `KEYED`: that would change everyone's key with the switch off. - As with any change under victory-shader/src, the translator source hash changes, so a build with this PR starts once with a cold shader cache. ## How it was tested **Byte identity (offline census, the switch on and off).** `victory translate --list --jobs 1` over the title's `shaders.rpf`, with `VICTORY_HOST_WAVE=32 VICTORY_HOST_MAX_WAVE=32`: - On 829188e9: 0 of 25,693 emitted modules differ between the checker on, the checker off and the unpatched build. The `--list` module hashes and the `VICTORY_SHADER_CENSUS` instruction counts are both identical. - On f889bb07 with `VICTORY_WAVE_FOLDED=1` plus #2853 and #2265: 0 of 25,693 modules differ with the checker on. - On this branch's base, cec481f4, with the upstream default switches: 0 of 25,693 emitted modules differ between the unpatched build and this branch with the checker on. - With the checker on, it printed 1,151 `W64-PROGRAM` lines and 148 verdicts. - The verdicts are 136 folded: pass, 10 folded: fail and 2 pair meetings: unmodelled. - (The measured build predates two `clippy::manual_is_multiple_of` fixes, `x % n == 0` → `x.is_multiple_of(n)`. They change no behaviour, and the tests were re-run on the final patch.) - No game data is in the tree or in this PR. The checker's lines hold digests, block numbers and instruction names only. **What it reports on the title** (f889bb07 + FOLDED=1 + #2853 + #2265): - folded: 264 pass, 10 fail; - pair meetings: 2 unmodelled; - the wave-wide forms: no title program reaches them there. - Every fail is a title `s_barrier` in a region that a folded `s_cbranch_execz` skips when a console wave has no lane left. The branch's condition comes from thread ids (in 4 of them, also a scalar load). - In the end-to-end test below, `widen` (mode All) emits a title `s_barrier` inside a per-lane branch it does not widen. The checker fails it. No title program takes that path today. **Unit tests** (`cargo test -p victory-shader --lib`, no GPU, no game data). Every fixture is hand-written GFX10 machine code or a hand-written group graph. Each negative case has a control that must give the other result: | test | fails (as it must) | control passes | |---|---|---| | t1: a barrier in a per-lane branch of a wave-wide form (All, fallback, SafeSingleWave, DriverLoop) | Divergent | the same branch taken wave-wide; the barrier after the join | | t1b: a `host_wide` branch is per wave | Divergent | – | | t2: a wave-wide latch fed by an LDS word written after the loop | VoteWaitsOnLater | the word written before the loop | | t5: fold, a barrier under a per-wave branch and an early end | fail | no branch or no end; one host wave | | t6: pair meetings, half meets, any spin | unmodelled | the same program without a spin is decided | | t7: the wide fallback on an unprovable fixture | fail | switch off: nothing taken, nothing noted | | t8: barrier dedup (#42) only removes barriers | removing any block's barriers keeps a pass | a barrier added in the lane region fails | | t11: B8 over the passing graphs | – | 2 host waves meet under every schedule; the divergent control deadlocks | | mutation probe: a checker that passes everything | caught by every negative case | – | | e2e: `widen` on the wave OR fixture | – | pass; DXIL equal with the checker on and off | | e2e: `widen` with a title `s_barrier` in a lane branch | fail | DXIL equal on and off | | a lowering that no note names; another program's run | unmodelled | the right program is decided | | barrier inventory | fails on any new or moved `dx.op.barrier` site in production code, so each site is classified (waits for the group or not) before it can go uncounted | – | In addition: - `verify_groups` has 41 tests and `wave_interp` 14, each with negative controls. - `victory-gpu`'s `every_switch_of_the_translator_is_in_the_key` covers the new switch. - On cec481f4: - `cargo test --release --locked -p victory-shader --lib -- emit::w64_check emit::verify_groups emit::wave_interp`: 73 passed; - `cargo test --release --locked -p victory --bin victory`: 79 passed; - `cargo clippy --locked -p victory-shader -p victory --all-targets`: no warning in a file this PR touches. - The tree already has warnings elsewhere (for example `shader_cache.rs:14`'s unused `AtomicBool` and `lower.rs:594`'s unused import), so a workspace-wide `-D warnings` run fails without this PR as well. - `every_switch_of_the_translator_is_in_the_key` fails on cec481f4 with and without this PR, on `VICTORY_SCALAR_SPLITS`, which is still in `KEYED` but no longer read (#3189; #3061 fixes it). The check this PR's switch needs, that no translator switch is left out of the lists, comes before that assertion and passes. Test details: - Hardware: RTX 4060 Ti 16 GB, Windows 11. The checker runs on the CPU only; no GPU test is part of this PR. - Wave sizes: a 32-lane host (`VICTORY_HOST_WAVE=32`). On a 64-lane host the wave64 forms are not taken. - `cargo test` passed for the crates it touches: yes (victory-shader and victory on cec481f4). The victory-gpu key test fails on #3189 only (fixed by #3061), as it does without this PR. ## Limits (stated plainly) - **Liveness and progress only, not data races.** LDS ordering across meetings is not checked. - **Values are not checked.** The fold's value correctness and approximate forms are outside a liveness checker. - **Spin meetings are `unmodelled`.** This covers the pair meetings and the half meets. Proving them needs a subgroup model of the meeting words. - **Wave-wide forms in groups of several console waves are `unmodelled`.** - **`LOOP_LIMIT` is modelled as leaving the program**, as `abort_block` does. A per-wave loop ahead of a later barrier therefore fails the barrier. That is conservative, and real on the host: a wave that leaves does not meet the barrier. - **Barriers are counted before `bitcode::opt`.** The barrier dedup (#42) only drops barriers inside one DXIL block, which keeps liveness (t8). On the title at 829188e9, it changes the barrier count of no checked program (measured with `VICTORY_SHADER_OPT=191`). - **With the switch on, a program served from the shader cache prints nothing.** Use `victory translate` or a cold cache. - **Report only.** A gate that refuses failing forms is a separate decision, and would then have to enter the cache key. ## Provenance and licence - verify_groups.rs, wave_interp.rs and w64_check.rs, with their tests, are our own work, GPL-3.0-or-later like this workspace. Each file carries an SPDX line. - Existing code is only hooked into, not copied. - The value analysis follows #1140's `is_group_uniform_val`. - `safe_single_wave_widen` (#1006) is a possible cross-check of the uniformity verdicts. It is not used here. - AI-assisted: written with Claude (Anthropic) under human direction. The tests and the corpus census above were run, and their results are measured, not assumed. ## Checked for overlap - [x] I searched the open pull requests for a group or barrier verifier, uniformity checks after lowering, and `VICTORY_WAVE_VERIFY`: there are none. - Related, no conflict: #2265 and #2261 (fold), #2389 (`lane_uniform`), #2421 (cross-half barriers; adds barriers, so this checker would see them). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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/3336:upstream-pr/3336'
git switch 'upstream-pr/3336'

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/3336'
git switch 'upstream-pr/3336'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3336'
git switch 'upstream-pr/3336'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3336'
git switch 'main'
git merge --squash 'upstream-pr/3336'
git switch 'main'
git merge --ff-only 'upstream-pr/3336'
git switch 'main'
git merge 'upstream-pr/3336'
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
trustno1-coder/VIctory-NVIDIA!3336
No description provided.