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

Closed
DenRakEiw wants to merge 1 commit from upstream-pr/2347 into main
DenRakEiw commented 2026-11-25 11:17:26 +00:00 (Migrated from github.com)

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


## 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).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6603272414 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2347). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T11:17:26Z. --- ## 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).
catminou4 commented 2026-11-25 12:03:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T11:51:53Z.

Review: APPROVED


Tested locally: merged into main 940d32f69b, cargo test -p victory-shader --locked on macOS arm64 — 150 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — spilled lane masks tracked, Atom::Phi back-edges, +6 tests.

<!-- greyfinch-sync:Marvisak/VIctory:review:6057088364 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2347#pullrequestreview-6057088364). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T11:51:53Z. **Review:** APPROVED --- Tested locally: merged into main 940d32f69b, `cargo test -p victory-shader --locked` on macOS arm64 — 150 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — spilled lane masks tracked, Atom::Phi back-edges, +6 tests.
Marvisak commented 2026-11-25 16:09:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:30:03Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166939292 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2347#issuecomment-7166939292). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:30:03Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-26 01:03:04 +00:00
DenRakEiw commented 2026-11-26 01:04:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-26T00:53:59Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179226520 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2347#issuecomment-7179226520). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-26T00:53:59Z. --- Closing this PR — stepping back from code contributions on this account. Feel free to reuse the approach if helpful.

Pull request closed

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