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

Open
github-bot wants to merge 1 commit from github-bot/gh-292 into main AGit
Owner

@⁠wbkepler on GitHub · 2026-11-24 02:05 UTC · original
wbkepler:shader/fix-wqm-and-hangs → main · +1293 −112 · 4 files · 1 commits · open

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)
**@⁠wbkepler** on GitHub · 2026-11-24 02:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/292) `wbkepler:shader/fix-wqm-and-hangs` → `main` · +1293 −112 · 4 files · 1 commits · open ## 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)
- Preserve the source boolean mask in Atom::Quad(Value, Bool) during lane-mask structuring (s_wqm_b32/s_wqm_b64) and lower Atom::Quad 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.

- Clamp ds_read* dword indices into 0..lds_dwords (returning 0 when out of bounds so inactive EXEC lanes never read OOB groupshared memory) and bounds-check ds_write* and LDS atomics against lds_dwords.

- Replace per-loop reset counters with function-wide SSA invocation step tracking (StepTrack) so nested loops share a single step budget, track barrier-enclosing loops on a dedicated group-uniform counter separate from divergent per-lane loops, and enable VICTORY_SHADER_LOOP_LIMIT in release builds.

- Detect non-uniform branches controlling an active s_barrier via immediate post-dominators, retain per-lane EXEC guards on inner instructions, and lift branch conditions via dx.op.waveAllTrue/dx.op.waveAnyTrue so lanes do not diverge across dx.op.barrier.

- Add structuring, DXIL validation, and D3D12 hardware + WARP tests covering pixel s_wqm quad loops/skips, OOB LDS reads/writes/atomics, nested loop step budgets, and divergent loop + barrier uniformity.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:11 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:17 UTC · original

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

**@⁠jeremygold02** on GitHub · 2026-11-24 04:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/292#issuecomment-7121889533) 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)
Author
Owner

@⁠wbkepler on GitHub · 2026-11-24 20:46 UTC · original

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.

**@⁠wbkepler** on GitHub · 2026-11-24 20:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/292#issuecomment-7144041480) 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._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:26 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 00:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/292#issuecomment-7148509350) <!-- 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 has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/valu_tests.rs
  • crates/victory-shader/src/structure.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/292/head:github-bot/gh-292'
git switch 'github-bot/gh-292'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-292'
git switch 'github-bot/gh-292'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-292'
git switch 'github-bot/gh-292'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-292'
git switch 'main'
git merge --squash 'github-bot/gh-292'
git switch 'main'
git merge --ff-only 'github-bot/gh-292'
git switch 'main'
git merge 'github-bot/gh-292'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!292
No description provided.