victory-shader: fix 32 KiB TGSM guard, f32 wave prefix flag, and DPP/permlane safety #358

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

@⁠Androtim on GitHub · 2026-12-02 15:52 UTC · original
Androtim:fix/shader-tgsm-waveprefix-dpp → main · +330 −7 · 4 files · 1 commits · open

Fixes P1/P2 shader lowering findings #9, #10, and #11 from #282 (related: #276).

Summary

  • Finding #9 (crates/victory-shader/src/emit/lower.rs):
    • Enforce self.s.lds_dwords > HOST_LDS_DWORDS unconditionally in Lower::run (catching ticket, halves, and exchange TGSM overflows even when self.pairs.is_none()).
    • Skip ticket allocation on 1D multiple-of-wave shaders (cs.threads[1] == 1 && cs.threads[2] == 1 && group.is_multiple_of(wave)) already at HOST_LDS_DWORDS (32 KiB) so they use the linear wave base fallback instead of overflowing 32 KiB TGSM, while still catching 2D/3D/unaligned overflows cleanly.
  • Finding #10 (crates/victory-shader/src/emit/lower.rs):
    • Pass unsigned = u8::from(!float) (i.e. 0 for Op::AddF) to dx.op.wavePrefixOp.f32 instead of hardcoded 1. (Bin::Add in bitcode.rs already emits LLVM fadd when operand types are float.)
  • Finding #11 (crates/victory-shader/src/emit/lower.rs):
    • Clamp DPP row_shl/row_shr laneIndex via select(in_row, src, lane) before calling waveReadLaneAt so out-of-row lanes never pass negative/out-of-range lane indices.
    • Check all_lane_blocks_native instead of all_lane_blocks for v_permlane16_b32 / v_permlanex16_b32 fi:1, rejecting fetch-inactive inside divergent loop latches as well as lane branches.

Verification

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (passed)
  • cargo run -p xtask --locked -- policy (325 files ok)
  • Targeted cargo test -p victory-shader --lib -- --test-threads=1 suites including new regression tests (emit::lower::tests, emit::permlane_tests::permlane_fetch_inactive, emit::wave::tests, emit::wave64_tests, emit::size_tests, emit::waterfall_tests, emit::lds_sub_tests, emit::threading::tests, structure::tests, emit::bitcode::tests, bvh::tests, dxbc::tests, dxil::tests, ir::tests, resource::tests, spill::tests, emit::own_bits::tests, emit::container::tests, emit::cost::tests, emit::atomic_tests)
**@⁠Androtim** on GitHub · 2026-12-02 15:52 UTC · [original](https://github.com/Androtim/MiniVI/pull/358) `Androtim:fix/shader-tgsm-waveprefix-dpp` → `main` · +330 −7 · 4 files · 1 commits · open Fixes P1/P2 shader lowering findings **#9**, **#10**, and **#11** from #282 (related: #276). ### Summary - **Finding #9 (`crates/victory-shader/src/emit/lower.rs`)**: - Enforce `self.s.lds_dwords > HOST_LDS_DWORDS` unconditionally in `Lower::run` (catching `ticket`, `halves`, and `exchange` TGSM overflows even when `self.pairs.is_none()`). - Skip `ticket` allocation on 1D multiple-of-wave shaders (`cs.threads[1] == 1 && cs.threads[2] == 1 && group.is_multiple_of(wave)`) already at `HOST_LDS_DWORDS` (32 KiB) so they use the linear wave base fallback instead of overflowing 32 KiB TGSM, while still catching 2D/3D/unaligned overflows cleanly. - **Finding #10 (`crates/victory-shader/src/emit/lower.rs`)**: - Pass `unsigned = u8::from(!float)` (i.e. `0` for `Op::AddF`) to `dx.op.wavePrefixOp.f32` instead of hardcoded `1`. (`Bin::Add` in `bitcode.rs` already emits LLVM `fadd` when operand types are `float`.) - **Finding #11 (`crates/victory-shader/src/emit/lower.rs`)**: - Clamp DPP `row_shl`/`row_shr` `laneIndex` via `select(in_row, src, lane)` before calling `waveReadLaneAt` so out-of-row lanes never pass negative/out-of-range lane indices. - Check `all_lane_blocks_native` instead of `all_lane_blocks` for `v_permlane16_b32` / `v_permlanex16_b32` `fi:1`, rejecting fetch-inactive inside divergent loop latches as well as lane branches. ### Verification - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (passed) - `cargo run -p xtask --locked -- policy` (325 files ok) - Targeted `cargo test -p victory-shader --lib -- --test-threads=1` suites including new regression tests (`emit::lower::tests`, `emit::permlane_tests::permlane_fetch_inactive`, `emit::wave::tests`, `emit::wave64_tests`, `emit::size_tests`, `emit::waterfall_tests`, `emit::lds_sub_tests`, `emit::threading::tests`, `structure::tests`, `emit::bitcode::tests`, `bvh::tests`, `dxbc::tests`, `dxil::tests`, `ir::tests`, `resource::tests`, `spill::tests`, `emit::own_bits::tests`, `emit::container::tests`, `emit::cost::tests`, `emit::atomic_tests`)
Fixes findings #9, #10, and #11 from #282 (see also #276):
- Enforce the 32 KiB HOST_LDS_DWORDS limit unconditionally (including halves/exchange/ticket without pair meetings) and omit ticket allocation on 1D multiple-of-wave shaders already using all 32 KiB.
- Pass unsigned = 0 for float dx.op.wavePrefixOp.f32 (Bin::Add already emits float fadd).
- Clamp DPP row_shl/row_shr lane indices via select before waveReadLaneAt, and check all_lane_blocks_native on v_permlane16/v_permlanex16 fi:1.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 15:55:30 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-12-02 16:08 UTC · original

Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

CI is passing and all three fixes in crates/victory-shader/src/emit/lower.rs are clean, tightly scoped, and backed by targeted unit/DXIL-validation tests:

  • 32 KiB TGSM guard & 1D ticket fallback (Lower::run, Lower setup in crates/victory-shader/src/emit/lower.rs):
    • Making self.s.lds_dwords > HOST_LDS_DWORDS unconditional in Lower::run properly catches TGSM overflows from halves, exchange, ticket, and oversized program LDS even when self.pairs.is_none().
    • Skipping ticket allocation only when s.lds_dwords >= HOST_LDS_DWORDS on 1D multiple-of-wave groups (cs.threads[1] == 1 && cs.threads[2] == 1 && group.is_multiple_of(wave)) preserves lowering for full-32 KiB 1D shaders (e.g., CS_CollectTriangles_Meshlets) while still rejecting 2D/3D/unaligned overflows cleanly.
  • wavePrefixOp.f32 signed/unsigned flag (crates/victory-shader/src/emit/lower.rs):
    • Passing u8::from(!float) (0 for Op::AddF, 1 for Op::AddU) to dx.op.wavePrefixOp.{sfx} aligns with waveActiveOp and the DXIL specification.
  • DPP row shift clamping & permlane fi:1 guard (crates/victory-shader/src/emit/lower.rs):
    • Clamping src via select(in_row, src, lane) before self.read_lane(x, safe) prevents out-of-range/negative laneIndex values from reaching dx.op.waveReadLaneAt on row_shl/row_shr boundary lanes.
    • Switching v_permlane16_b32 / v_permlanex16_b32 fetch_inactive from all_lane_blocks to all_lane_blocks_native closes the gap for divergent loop latches.
  • Tests (crates/victory-shader/src/emit/bitcode.rs, lower_tests.rs, permlane_tests.rs):
    • New #[cfg(test)] inspection helpers and regression tests cover each fix (including DXIL validation on Windows).

Next Step

Because this changes emitted DXIL and shader acceptance rules (32 KiB TGSM/ticket fallback, float wave prefix ops, DPP waveReadLaneAt clamping, and permlane fi:1 rejection), a local real-GPU smoke test is recommended before merging to confirm no regressions in title shader compilation or rendering.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-12-02 16:08 UTC · [original](https://github.com/Androtim/MiniVI/pull/358#issuecomment-7351498950) <!-- minivi-triage v1 head=e2282e17fc29e6c073d1400d79b5f7e2b653f041 verdict=needs-gpu-test ci=passing at=2026-12-02T16:08:58Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary CI is passing and all three fixes in `crates/victory-shader/src/emit/lower.rs` are clean, tightly scoped, and backed by targeted unit/DXIL-validation tests: - **32 KiB TGSM guard & 1D `ticket` fallback (`Lower::run`, `Lower` setup in `crates/victory-shader/src/emit/lower.rs`)**: - Making `self.s.lds_dwords > HOST_LDS_DWORDS` unconditional in `Lower::run` properly catches TGSM overflows from `halves`, `exchange`, `ticket`, and oversized program LDS even when `self.pairs.is_none()`. - Skipping `ticket` allocation only when `s.lds_dwords >= HOST_LDS_DWORDS` on 1D multiple-of-wave groups (`cs.threads[1] == 1 && cs.threads[2] == 1 && group.is_multiple_of(wave)`) preserves lowering for full-32 KiB 1D shaders (e.g., `CS_CollectTriangles_Meshlets`) while still rejecting 2D/3D/unaligned overflows cleanly. - **`wavePrefixOp.f32` signed/unsigned flag (`crates/victory-shader/src/emit/lower.rs`)**: - Passing `u8::from(!float)` (`0` for `Op::AddF`, `1` for `Op::AddU`) to `dx.op.wavePrefixOp.{sfx}` aligns with `waveActiveOp` and the DXIL specification. - **DPP row shift clamping & permlane `fi:1` guard (`crates/victory-shader/src/emit/lower.rs`)**: - Clamping `src` via `select(in_row, src, lane)` before `self.read_lane(x, safe)` prevents out-of-range/negative `laneIndex` values from reaching `dx.op.waveReadLaneAt` on `row_shl`/`row_shr` boundary lanes. - Switching `v_permlane16_b32` / `v_permlanex16_b32` `fetch_inactive` from `all_lane_blocks` to `all_lane_blocks_native` closes the gap for divergent loop latches. - **Tests (`crates/victory-shader/src/emit/bitcode.rs`, `lower_tests.rs`, `permlane_tests.rs`)**: - New `#[cfg(test)]` inspection helpers and regression tests cover each fix (including DXIL validation on Windows). ### Next Step Because this changes emitted DXIL and shader acceptance rules (32 KiB TGSM/ticket fallback, float wave prefix ops, DPP `waveReadLaneAt` clamping, and `permlane` `fi:1` rejection), a local real-GPU smoke test is recommended before merging to confirm no regressions in title shader compilation or rendering. --- _Generated with Antigravity CLI (`agy`)._
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/lower_tests.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/358/head:github-bot/gh-358'
git switch 'github-bot/gh-358'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-358'
git switch 'github-bot/gh-358'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-358'
git switch 'github-bot/gh-358'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-358'
git switch 'main'
git merge --squash 'github-bot/gh-358'
git switch 'main'
git merge --ff-only 'github-bot/gh-358'
git switch 'main'
git merge 'github-bot/gh-358'
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/Androtim--MiniVI!358
No description provided.