Skip to content

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

Closed
DenRakEiw wants to merge 1 commit into
Marvisak:mainfrom
DenRakEiw:fix/lane-mask-spills-joins-carries
Closed

DenRakEiw wants to merge 1 commit into
Marvisak:mainfrom
DenRakEiw:fix/lane-mask-spills-joins-carries

Conversation

@DenRakEiw

Copy link
Copy Markdown

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: merged into main 940d32f, 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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@DenRakEiw
DenRakEiw force-pushed the fix/lane-mask-spills-joins-carries branch from 0bd114a to dab2c65 Compare November 26, 2026 00:41
@DenRakEiw

Copy link
Copy Markdown
Author

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

@DenRakEiw DenRakEiw closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants