Shaders: track spilled lane masks restored via v_readlane_b32 #2967
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2967
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2967"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Dukestar69 on GitHub · 2026-11-26 01:44 UTC · original
Dukestar69:fix/lane-mask-spills-joins-carries→main· +204 −9 · 3 files · 2 commits · openSummary
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).
Shaders: track spilled lane masks, Atom::Phi back-edges, and carry masksto Shaders: track spilled lane masks restored via v_readlane_b32eb0d782fa1to039b30c58f@steven-seagull27 on GitHub · 2026-11-26 02:58 UTC · original · edited 2026-11-26 03:13 UTC
@Dukestar69 @fuzeofficlal I ran the suggested GPU carry-out check. On
eb0d782,v_mad_i64_i32writes the correct 64-bit vector result but the wrong SDST bit in 32,759 of 65,536 inputs on both the RTX 5080 and built-in Microsoft WARP. AMD's RDNA 2 ISA, §12.12, opcode 375 defines the destination as the concatenation of the carry bit and the low 64 bits. I computed the exact signed multiply-add in Rusti128and compared bit 64 against a shader readback throughv_cndmask_b32.-3 * 5 + 00xfffffffffffffff11 * 1 + i64::MAX0x8000000000000000The 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
lower.rsat 523,370 bytes (918 bytes free).To apply both commits on top of
eb0d782:I 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.
@Marvisak on GitHub · 2026-11-26 05:25 UTC · original · edited 2026-11-26 07:19 UTC
Automated triage for the maintainers.
Merge candidate (recommending a look, not approving). Thanks for splitting it. Now:
v_writelane_b32and restored withv_readlane_b32.structure.rs(Lanes) treats a restored mask as a mask, both at the restore and in SOP mask ops.Lower::mask_dwordfollowsst.restoredto the original mask's ballot.mask_numbergainsandn1/orn1, which complement src0 as the RDNA2 ISA defines.The
v_mad_i64_i32carry,Atom::Phiand carry-in changes are gone, so this no longer overlaps #171 or #385.spilled_lane_mask_restored_into_sop_and_select_matches_rdna2checks values on the GPU for both thev_cndmaskselect and the numeric read, andrestored_mask_feeds_sop_mask_opcovers the tracking.The description says which instruction pattern fails on
mainbut not whether title shaders hit it. Saying whether they do would help prioritise.CI: not run on this head (no check runs yet).
Generated by Claude Code
@Dukestar69 on GitHub · 2026-11-26 05:58 UTC · original
Thanks @steven-seagull27 and triage for the thorough catch and feedback! Updated this PR to address every point:
v_mad_i64_i32carry-out (covered cleanly by #171).v_writelane_b32/v_readlane_b32) +andn1/orn1inmask_number, dropping theAtom::Phi/phi_joinsand carry-in changes so there is zero overlap with #385.spilled_lane_mask_restored_into_sop_and_select_matches_rdna2inemit/valu_tests.rs), verified on NVIDIA GeForce RTX 5090 withdxil.dllvalidation.lower.rsis now only +10 lines (522,601 / 524,288bytes, 1,687 bytes free),clippy --all-targets -- -D warningsclean,rustfmt --edition 2024 --checkclean,cargo xtask policy191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 01:54 UTC · original · reviewed
Reviewed and verified against
main(63bcca43) on Windows 11 — solid implementation and tests pass: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.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.Atom::Phimask tracking instructure.rsand moves phi lowering intoemit/lower/phi.rs, freeing ~4.9 KiB inlower.rs). No conflict with #2923.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 on GitHub · 2026-11-26 02:31 UTC · original · reviewed
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.
@cloph-dsp on GitHub · 2026-11-26 09:08 UTC · original
Independent local verification of head
039b30con Windows 11, Rust 1.100.0/MSVC:cargo test --locked -p victory-shader --lib structure::tests::restored_mask_feeds_sop_mask_op— 1 passed, 0 failed.git diff --check origin/main HEAD— clean.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 on GitHub · 2026-11-26 10:17 UTC · original · requested changes
Tracking
st.restoredfor Wave32v_readlane_b32restores works on thev_cndmask_b32path, andemit/lower.rsstays under the 512 KiB limit (521,065bytes).Two blockers need fixing before merge:
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)@steven-seagull27 on GitHub · 2026-11-26 10:39 UTC · original
@Dukestar69 @fuzeofficlal I reproduced both findings on
039b30cand put the fix and a 32-lane regression in one commit directly on your head. Review · Patch and testThe shader spills and restores a comparison mask, runs
s_and_b32to test bits 0 and 31, then consumes SCC with eithers_cbranch_scc0ors_cselect_b32. On the PR head, when bit 0 was set, the branch wrote 7 only on lane 0. The other 31 lanes wrote 11, although all 32 should write 7. The select failed translation at byte offset 56 witha lane mask read as data. Both symptoms reproduced on the RTX 5080 and WARP 1.0.22.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.
63bcca4, new regressionWith
VICTORY_WARP=1, the original PR test treated built-in WARP as hardware and panicked when its Wave32 pipeline was refused. The patched test checks the selected adapter once and reports the unsupported width. On WARP 1.0.22 the original one-thread numeric-mask case still returns 0 instead of 1 for equal inputs. I reproduced it on the parent with the same fixture, on this PR head, and with the patch. The original fixture passed on the RTX. The structuring and lowering unit tests, strict shader Clippy, and repository asset policy also passed.AI-assisted with Codex. Synthetic RDNA2 shaders and D3D12 readbacks.
@Dukestar69 on GitHub · 2026-11-26 16:34 UTC · original
@fuzeofficlal Thanks for the thorough catch! Both blockers are now fixed in the latest commit:
structure.rs): When a non-EXEC SOP only has restored mask operand(s) alongside a non-mask scalar or bitmask constant (such ass_and_b32 s7, s6, 1),takes_maskis cleared so neither the destination SGPR norReg::Sccis placed inst.masks/st.scc_lane. Boths_cselect_b32and wave-wides_cbranch_scc*keep their original scalar SCC semantics. Addedstructure::tests::restored_mask_numeric_bit_test_keeps_scalar_scc(verifyingLaneExit::BranchusesAtom::Uniform(and_scc)) and updated the GPU test invalu_tests.rsto executes_and_b32 s7, s6, 1->s_cselect_b32 s7, 10, 20.VICTORY_WARP=1test fix (valu_tests.rs) & cleanup (lower.rs): Checkedwarp || std::env::var("VICTORY_WARP").is_ok_and(|v| v == "1")before asserting hardware Wave32 PSO creation, and removed the unusedandn1/orn1arms inmask_number(lower.rsis now520,673bytes —3,615bytes under the 512 KiB limit).Verified locally on Windows 11 x64:
cargo test -p victory-shader --lib structure::tests:: -- --test-threads=1: 15 passed, 0 failed, 1 ignored.cargo test -p victory-shader --lib emit::lower::tests:: -- --test-threads=1: 33 passed, 0 failed.cargo test -p victory-shader --lib spilled_lane_mask_restored_into_sop_and_select_matches_rdna2 -- --test-threads=1: passed on RTX 5090 and withVICTORY_WARP=1.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.