Shaders: track spilled lane masks, Atom::Phi back-edges, and carry masks #2347

Closed
github-bot wants to merge 1 commit from gh-pr/2347/head into gh-pr/2347/base
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 11:17 UTC · original
fix/lane-mask-spills-joins-carries → main · +259 −75 · 2 files · 1 commits · closed without merging

## Summary

Closes the lane-mask tracking and lowering gaps identified in #2268 item 4 (separate from #2289's data-phi mask resolution):

  1. Spilled lane masks (v_writelane_b32 / v_readlane_b32):

    • structure.rs: Lanes::step now checks self.restored for Fields::Sop so scalar mask ops reading a restored mask keep mask tracking, and tracks Wave32 v_readlane_b32 restores of tracked masks in self.masks (without marking active at the restore block).
    • lower.rs: mask_dword forwards st.restored to the original mask value so ballots are taken at the original write block; mask_number also supports andn1 / orn1.
  2. Lane-mask phi joins (Atom::Phi):

    • structure.rs: records incoming arguments of Atom::Phi joins in phi_joins and resolves every edge (including loop back-edges) in wrong_joins.
    • lower.rs: pending_masks in fill_phis skips never_taken edges, maps Wave64 high args via st.highs, and looks up st.masks or st.other (unblocking constant-initialized mask phis such as s_mov_b32 s0, 0 before a loop).
  3. Carry-in & carry-out masks:

    • structure.rs: Lanes::step resolves src[2] via self.mask(k) for *_co_ci_u32 instructions as well as v_cndmask_b32.
    • lower.rs: unifies v_cndmask_b32 and *_co_ci_u32 through mask_operand (supporting NULL, st.masks, st.other, and inline constants), and emits the signed 64-bit overflow carry for v_mad_i64_i32 into lane_bits.

Testing

  • Added 3 synthetic RDNA2 tests in structure::tests (restored_mask_feeds_sop_mask_op, loop_mask_phi_with_zero_init_resolves_all_args, carry_in_from_constant_is_tracked) and 3 in emit::lower::tests (loop_mask_phi_initialized_to_zero_lowers, spilled_mask_feeds_sop_and_reads_as_data, carry_in_constant_and_mad_i64_carry_out_lower).
  • cargo test -p victory-shader structure::tests: 14/14 passed (RTX 5090 & WARP).
  • cargo test -p victory-shader emit::lower::tests: 24/24 passed (RTX 5090 & WARP, dxil.dll validated).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

Related to #2268, #1633.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 11:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2347) `fix/lane-mask-spills-joins-carries` → `main` · +259 −75 · 2 files · 1 commits · closed without merging ## Summary Closes the lane-mask tracking and lowering gaps identified in #2268 item 4 (separate from #2289's data-phi mask resolution): 1. **Spilled lane masks (`v_writelane_b32` / `v_readlane_b32`):** - `structure.rs`: `Lanes::step` now checks `self.restored` for `Fields::Sop` so scalar mask ops reading a restored mask keep mask tracking, and tracks Wave32 `v_readlane_b32` restores of tracked masks in `self.masks` (without marking `active` at the restore block). - `lower.rs`: `mask_dword` forwards `st.restored` to the original mask value so ballots are taken at the original write block; `mask_number` also supports `andn1` / `orn1`. 2. **Lane-mask phi joins (`Atom::Phi`):** - `structure.rs`: records incoming arguments of `Atom::Phi` joins in `phi_joins` and resolves every edge (including loop back-edges) in `wrong_joins`. - `lower.rs`: `pending_masks` in `fill_phis` skips `never_taken` edges, maps Wave64 high args via `st.highs`, and looks up `st.masks` or `st.other` (unblocking constant-initialized mask phis such as `s_mov_b32 s0, 0` before a loop). 3. **Carry-in & carry-out masks:** - `structure.rs`: `Lanes::step` resolves `src[2]` via `self.mask(k)` for `*_co_ci_u32` instructions as well as `v_cndmask_b32`. - `lower.rs`: unifies `v_cndmask_b32` and `*_co_ci_u32` through `mask_operand` (supporting `NULL`, `st.masks`, `st.other`, and inline constants), and emits the signed 64-bit overflow carry for `v_mad_i64_i32` into `lane_bits`. ## Testing - Added 3 synthetic RDNA2 tests in `structure::tests` (`restored_mask_feeds_sop_mask_op`, `loop_mask_phi_with_zero_init_resolves_all_args`, `carry_in_from_constant_is_tracked`) and 3 in `emit::lower::tests` (`loop_mask_phi_initialized_to_zero_lowers`, `spilled_mask_feeds_sop_and_reads_as_data`, `carry_in_constant_and_mad_i64_carry_out_lower`). - `cargo test -p victory-shader structure::tests`: 14/14 passed (RTX 5090 & WARP). - `cargo test -p victory-shader emit::lower::tests`: 24/24 passed (RTX 5090 & WARP, `dxil.dll` validated). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. Related to #2268, #1633. AI-assisted (Gemini 4 Neon).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:03:00 +00:00
github-bot closed this pull request 2026-11-26 05:03:00 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:30 UTC · original · edited 2026-11-25 16:00 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2347#issuecomment-7166939292) · edited 2026-11-25 16:00 UTC <!-- victory-triage v1 head=0bd114a3f4dbceac25218e39f0fd65ed603d27e2 verdict=needs-rebase at=2026-11-25T15:59:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/lower.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-26 00:53 UTC · original

Closing this PR — stepping back from code contributions on this account. Feel free to reuse the approach if helpful.

**@⁠DenRakEiw** on GitHub · 2026-11-26 00:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2347#issuecomment-7179226520) Closing this PR — stepping back from code contributions on this account. Feel free to reuse the approach if helpful.

Pull request closed

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!2347
No description provided.