Shader: lower WQM QuadAny, clamp LDS accesses, and guard loop budgets & barriers #292

Open
wbkepler wants to merge 1 commit from upstream-pr/292 into main
wbkepler commented 2026-11-24 02:05:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T02:05:11Z.


Summary

Fixes shader WQM divergence, out-of-bounds LDS accesses, and GPU loop/barrier hangs across victory-shader:

  • WQM QuadAny lowering:
    • Preserves the source boolean in Atom::Quad(Value, Bool) for s_wqm_b32/s_wqm_b64 and lowers it to SM 6.6 dx.op.quadOp.i32 OR-reduction (QuadAny) in pixel/4-aligned mesh shaders and waveReadLaneAt quad OR-reduction in console-lane compute shaders instead of hardcoding true, plus scalar SWAR s_wqm_b32/s_wqm_b64.
  • OOB LDS clamping & guarding:
    • Clamps ds_read* dword indices into 0..lds_dwords (returning 0 when OOB) and bounds-checks ds_write* and LDS atomics against lds_dwords.
  • Invocation step budget & s_barrier safety:
    • Replaces per-loop reset counters with function-wide SSA StepTrack (separate lane-loop and group-uniform barrier-loop budgets) and enables VICTORY_SHADER_LOOP_LIMIT in release builds.
    • Detects non-uniform branches controlling active s_barrier via immediate post-dominators, preserves per-lane EXEC guards inside them, and lifts branch conditions with dx.op.waveAllTrue/dx.op.waveAnyTrue.
  • Adds 6 new structuring + dxil.dll + D3D12 hardware/WARP execution tests.

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed (victory-shader: 75/75 passing)
  • cargo xtask policy — passed (151 files ok)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6572947325 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/292). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T02:05:11Z. --- ## Summary Fixes shader WQM divergence, out-of-bounds LDS accesses, and GPU loop/barrier hangs across `victory-shader`: - **WQM `QuadAny` lowering**: - Preserves the source boolean in `Atom::Quad(Value, Bool)` for `s_wqm_b32`/`s_wqm_b64` and lowers it to SM 6.6 `dx.op.quadOp.i32` OR-reduction (`QuadAny`) in pixel/4-aligned mesh shaders and `waveReadLaneAt` quad OR-reduction in console-lane compute shaders instead of hardcoding `true`, plus scalar SWAR `s_wqm_b32`/`s_wqm_b64`. - **OOB LDS clamping & guarding**: - Clamps `ds_read*` dword indices into `0..lds_dwords` (returning `0` when OOB) and bounds-checks `ds_write*` and LDS atomics against `lds_dwords`. - **Invocation step budget & `s_barrier` safety**: - Replaces per-loop reset counters with function-wide SSA `StepTrack` (separate lane-loop and group-uniform barrier-loop budgets) and enables `VICTORY_SHADER_LOOP_LIMIT` in release builds. - Detects non-uniform branches controlling active `s_barrier` via immediate post-dominators, preserves per-lane `EXEC` guards inside them, and lifts branch conditions with `dx.op.waveAllTrue`/`dx.op.waveAnyTrue`. - Adds 6 new structuring + `dxil.dll` + D3D12 hardware/WARP execution tests. ## Verification - `cargo clippy --workspace --all-targets` — passed (zero new warnings) - `cargo clippy -p victory --features diagnostics --all-targets` — passed - `cargo test --workspace` — passed (`victory-shader`: 75/75 passing) - `cargo xtask policy` — passed (151 files ok)
jeremygold02 commented 2026-11-24 06:55:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:17:52Z.


Tested PR #292 at head a2a1b1e9445242777a6a566637432e601a0c600d (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at a2a1b1e9445242777a6a566637432e601a0c600d.

  • cargo test --locked -p victory-shader wqm_tracks_source_mask_and_folds_constants — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.00s ); cases: structure::tests::wqm_tracks_source_mask_and_folds_constants.
  • cargo test --locked -p victory-shader barrier_branches_keep_inner_guards_unless_barrier_post_dominates — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.00s ); cases: structure::tests::barrier_branches_keep_inner_guards_unless_barrier_post_dominates.
  • cargo test --locked -p victory-shader nested_loops_share_invocation_step_budget — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.45s ); cases: emit::valu_tests::nested_loops_share_invocation_step_budget.
  • cargo test --locked -p victory-shader divergent_loop_and_barrier_branches_do_not_deadlock — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.62s ); cases: emit::valu_tests::divergent_loop_and_barrier_branches_do_not_deadlock.
  • cargo test --locked -p victory-shader s_wqm_pixel_loop_and_skip_run_per_quad — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.36s ); cases: emit::valu_tests::s_wqm_pixel_loop_and_skip_run_per_quad.
  • cargo test --locked -p victory-shader oob_lds_reads_writes_and_atomics_clamp_and_drop — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.37s ); cases: emit::valu_tests::oob_lds_reads_writes_and_atomics_clamp_and_drop.

Behavior covered: Checks WQM source-mask propagation, barrier guard preservation, divergent-loop budgets, per-quad behavior and clamped out-of-range LDS operations.
Code: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/structure.rs

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121889533 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/292#issuecomment-7121889533). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:17:52Z. --- Tested PR #292 at head `a2a1b1e9445242777a6a566637432e601a0c600d` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `a2a1b1e9445242777a6a566637432e601a0c600d`. - `cargo test --locked -p victory-shader wqm_tracks_source_mask_and_folds_constants` — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.00s ); cases: structure::tests::wqm_tracks_source_mask_and_folds_constants. - `cargo test --locked -p victory-shader barrier_branches_keep_inner_guards_unless_barrier_post_dominates` — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.00s ); cases: structure::tests::barrier_branches_keep_inner_guards_unless_barrier_post_dominates. - `cargo test --locked -p victory-shader nested_loops_share_invocation_step_budget` — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.45s ); cases: emit::valu_tests::nested_loops_share_invocation_step_budget. - `cargo test --locked -p victory-shader divergent_loop_and_barrier_branches_do_not_deadlock` — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.62s ); cases: emit::valu_tests::divergent_loop_and_barrier_branches_do_not_deadlock. - `cargo test --locked -p victory-shader s_wqm_pixel_loop_and_skip_run_per_quad` — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.36s ); cases: emit::valu_tests::s_wqm_pixel_loop_and_skip_run_per_quad. - `cargo test --locked -p victory-shader oob_lds_reads_writes_and_atomics_clamp_and_drop` — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 74 filtered out; finished in 0.37s ); cases: emit::valu_tests::oob_lds_reads_writes_and_atomics_clamp_and_drop. Behavior covered: Checks WQM source-mask propagation, barrier guard preservation, divergent-loop budgets, per-quad behavior and clamped out-of-range LDS operations. Code: [crates/victory-shader/src/emit/lower.rs](https://github.com/Marvisak/VIctory/blob/a2a1b1e9445242777a6a566637432e601a0c600d/crates/victory-shader/src/emit/lower.rs), [crates/victory-shader/src/structure.rs](https://github.com/Marvisak/VIctory/blob/a2a1b1e9445242777a6a566637432e601a0c600d/crates/victory-shader/src/structure.rs)
wbkepler commented 2026-11-24 21:03:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T20:46:38Z.


Rebased onto current main (ffe310e) as e065026; add/add conflicts in structure.rs and valu_tests.rs were kept on both sides, and the new test helpers now call resource::track with the structured lanes as main's signature requires. Gate clean.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144041480 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/292#issuecomment-7144041480). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T20:46:38Z. --- Rebased onto current main (`ffe310e`) as `e065026`; add/add conflicts in structure.rs and valu_tests.rs were kept on both sides, and the new test helpers now call `resource::track` with the structured lanes as main's signature requires. Gate clean. _AI-assisted (Claude Code); checked on Windows 11 / RTX 5090._
Marvisak commented 2026-11-25 01:07:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:26:17Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/valu_tests.rs, crates/victory-shader/src/structure.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148509350 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/292#issuecomment-7148509350). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:26:17Z. --- <!-- victory-triage v1 head=e065026b6ed8d25baa67bf47d236586f2c51fee9 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/valu_tests.rs`, `crates/victory-shader/src/structure.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/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/292:upstream-pr/292'
git switch 'upstream-pr/292'

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