Repository navigation
Shaders: track spilled lane masks restored via v_readlane_b32 - #2967
Dukestar69 wants to merge 1 commit into
Conversation
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed and verified against main (63bcca43) on Windows 11 — solid implementation and tests pass:
- Fixed-point convergence & spilled masks:
phi_joins(structure.rs:802-833) feeds allAtom::Phiincoming args (including back-edges) throughwrong_joinswith cachedjoin()results and monotonic progress, guaranteeing termination while closing the loop-carried zero-init mask gap. Wave32v_readlane_b32restoration (structure.rs:1199-1205, 1264-1275) preservesmasksidentity without fabricating EXEC liveness, andmask_operand(lower.rs:1814-1860) unifies constant/scalar/othermask handling acrossv_cndmask_b32and*_co_ci_u32. - Two merge-planning notes:
emit/lower.rsfile-size headroom: on63bcca43,crates/victory-shader/src/emit/lower.rsgrows to 523,264 B (+2,701 B), leaving only 1,024 B under the524,288 B(512 KiB) policy cap.- Overlap with #385: conflicts directly with #385 (which also refactors
Atom::Phimask tracking instructure.rsand moves phi lowering intoemit/lower/phi.rs, freeing ~4.9 KiB inlower.rs). No conflict with #2923.
- (Minor note:
carry_in_constant_and_mad_i64_carry_out_lowerverifies DXIL lowering; adding a GPU execution case invalu_testsforv_mad_i64_i32signed-overflow carry-out((p ^ r) & (addend ^ r)) < 0would be a nice extra check.)
Local verification:
cargo test --locked -p victory-shader --lib structure::: 16/16 passed (1 ignored bench)cargo test --locked -p victory-shader --lib lower::tests: 36/36 passedcargo test --locked -p victory-shader -- mad cndmask carry readlane: 6/6 passedcargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warningscargo xtask policy: 191 files ok
kotekompotek
left a comment
There was a problem hiding this comment.
Verified at the mechanism level: phi_joins defers arg resolution until all edges are known (loop-carried mask phis whose back-edge arg postdates the phi), the restored-map lets a v_readlane'd wave32 mask keep mask identity without claiming EXEC at restore, and *_co_ci_u32 carry-ins resolve like v_cndmask's mask operand. The takes_mask precedence (phi && !loaded || restored) && needs-mask reads right. Each of the three cases has a test that fails without its mechanism.
|
@Dukestar69 @fuzeofficlal I ran the suggested GPU carry-out check. On
The corpus includes boundaries and deterministic pseudorandom inputs. The fourth output dword was a sentinel and matched throughout. The signed-overflow predicate in this PR explains both examples. #171 computes bit 64 with unsigned carry XOR the two operand sign bits. I merged both original PR histories and added a six-case GPU regression. The new test fails on this head and passes after the merge on both adapters. The original loop-phi, restored-mask and carry-lowering checks still pass. Strict shader Clippy passed, and the asset-policy check passed with To apply both commits on top of git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2967-171-signed-mad
git merge --ff-only FETCH_HEAD
cargo test --locked -p victory-shader --lib signed_mad_carry_is_bit_64_of_the_exact_sum -- --nocaptureI also resolved the review's #385 overlap on a separate integration branch. After merging both PRs, three carry-in programs still refused to translate: inline 15, 15 in a scalar register, and a runtime register mask. With the direct-mask fix, the RTX 5080 and WARP 1.0.22 each returned 288/288 correct Wave32 carry-in lane values. Portable WARP additionally passed 512/512 Wave64 lanes. Built-in WARP passed both width-independent controls (64/64 lanes) and skipped fixed Wave32. The two histories and #171 remain intact. Patch, counts and full-suite limits on #385. AI-assisted. All inputs were synthetic. |
|
Automated triage for the maintainers. Merge candidate (recommending a look, not approving). Thanks for splitting it. Now:
The The description says which instruction pattern fails on CI: not run on this head (no check runs yet). Generated by Claude Code |
eb0d782 to
a6923f6
Compare
|
Thanks @steven-seagull27 and triage for the thorough catch and feedback! Updated this PR to address every point:
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon). |
a6923f6 to
039b30c
Compare
|
Independent local verification of head
I ran only the CPU structuring test; the PR's GPU-execution test was not run here. Synthetic inputs only; no game assets, shaders extracted from game data, or DRM material used. AI-assisted (Hy4 flash). |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Tracking st.restored for Wave32 v_readlane_b32 restores works on the v_cndmask_b32 path, and emit/lower.rs stays under the 512 KiB limit (521,065 bytes).
Two blockers need fixing before merge:
- Scalar SCC regression (
structure.rs:1184-1208,emit/lower.rs:3567-3593): Classifying an SOP that reads a restored mask (such ass_and_b32 s7, s6, 1) intost.maskscausesLower::sopto returnErr(LANE_MASK)and recordVal::Missingfor both the SGPR destination andReg::Scc. A subsequent scalar SCC consumer (e.g.,s_cselect_b32) that translated cleanly onmainnow fails onVal::Missing, ands_cbranch_scc*can switch from wave-wide scalar SCC to lane-localscc_lanebranching. Please preserve scalar SCC for numeric consumers and add multi-lane regression coverage. VICTORY_WARP=1test failure (emit/valu_tests.rs:2291-2297): CallingHost::new(false)honorsVICTORY_WARP=1, so whenVICTORY_WARP=1is set in the environment, the("hardware", false)iteration opens WARP, has its Wave32 PSO rejected, and panics onassert!(warp, ...). Also note that the second sub-test can reuse theVal::I32already emitted forv_readlane_b32instead of independently exercising thest.restoredrecursion inmask_dword, andandn1/orn1have no standalone non-EXEC-writing SOP2 entries ingfx10/opcodes.rs.
Verified locally on Windows 11 x64 (039b30c5):
cargo run --locked -p xtask -- policy: passedcargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): cleanstructure::tests/emit::lower::tests: 14 passed (1 ignored) / 33 passed, 0 failedspilled_lane_mask_restored_into_sop_and_select_matches_rdna2 -- --test-threads=1: passed on RTX 5090 (1 passed, 0 failed), failed underVICTORY_WARP=1(exit 101 atvalu_tests.rs:2296:17)
|
@Dukestar69 @fuzeofficlal I reproduced both findings on The shader spills and restores a comparison mask, runs The fix keeps an ordinary scalar use of a restored word on the scalar path. An actual lane-mask consumer can still recover its lane predicate. The regression checks lane 0, lane 31, an unselected bit, and an empty mask.
With git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2967-restored-scc
git cherry-pick 5203c1441420bf6b86ca83a4e5740e59f0ef52cf
cargo test --locked -p victory-shader --lib restored_mask_sop_scc_is_wave_uniform -- --nocaptureAI-assisted with Codex. Synthetic RDNA2 shaders and D3D12 readbacks. |
Summary
Tracks wave32 lane masks restored from VGPR spills (
v_writelane_b32/v_readlane_b32) when consumed by subsequent SOP mask operations or numericmask_dwordreads, and addsandn1/orn1support tomask_number.Changes
crates/victory-shader/src/structure.rs:st.restoredoperands inFields::Sop(takes_mask) so SOP mask ops reading a restored wave32 mask are tracked as lane masks.v_readlane_b32inFields::Valuwithout claimingEXECat the restore.restored_mask_feeds_sop_mask_op.crates/victory-shader/src/emit/lower.rs:st.restoredinmask_dwordso numeric reads of a restored lane mask reuse the original mask's ballot.andn1/orn1(complement ofsrc0) inmask_number.lower.rsdelta is only +10 lines (522,601 / 524,288bytes, 1,687 bytes headroom).crates/victory-shader/src/emit/valu_tests.rs:spilled_lane_mask_restored_into_sop_and_select_matches_rdna2verifying bothv_cndmask_b32selection andmask_dwordreadback after spilling a compare mask throughv_writelane_b32/v_readlane_b32and combining withs_and_b32.(Updated per triage & review feedback: dropped
v_mad_i64_i32carry-out in favor of #171, and droppedAtom::Phi/phi_joins/ carry-in changes to eliminate overlap with #385.)Verification
cargo test -p victory-shader structure::tests: 14 passed, 0 failed.cargo test -p victory-shader spilled_lane_mask_restored_into_sop_and_select_matches_rdna2 -- --test-threads=1: passed on NVIDIA GeForce RTX 5090 (withdxil.dllvalidation).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.rustfmt --edition 2024 --check: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).