Shaders: resolve tracked lane masks in data phis and lazy SCC from mask/EXEC sop #2289
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!2289
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2289/head"
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?
@Xvania7 on GitHub · 2026-11-25 09:56 UTC · original
Xvania7:fix/lane-mask-data-joins→main· +451 −3 · 3 files · 2 commits · closed without mergingSummary
Addresses the remaining
a lane mask read as datafailure modes discussed in #2268:fill_phis): When a scalardata_phiin a compute shader (MaskData::Console) receives a tracked lane mask (inst.masksorst.highs),fill_phispreviously readself.vals(which heldVal::Missing(LANE_MASK)) instead of materializingself.mask_dword(arg).SCCfrom mask/EXECsopinstructions: When a computesopwritesEXECor a tracked lane mask alongsideSCC(e.g.s_and_saveexec_*),sopnow records the result mask inscc_masksand evaluates(lo | hi) != 0lazily inget/fill_phisonly ifSCCis read as data (so instructions whereSCCis unused emit zerowaveActiveBallot/WAVE_OPS).Synthetic tests
data_phi_joining_tracked_lane_mask_lowers_in_computeandsaveexec_scc_read_by_cselect_lowers_in_computeincrates/victory-shader/src/emit/lower.rs.cargo test -p victory-shader --lib emit::lower::tests::— 23 passed, 0 failedcargo clippy -p victory-shader --all-targets -- -D warnings— 0 warningscargo xtask policy— 182 files ok@sinan-cmyk on GitHub · 2026-11-25 10:17 UTC · original
Offline measurement on a retail dump
Result: +4 programs over
main, 0 lost.I merged head
e7213553ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,922 with this PR.mainAnother 40 programs move from "a register joining a lane mask and data, read as data" on to "a lane-mask join of an untracked mask". They still fail, but no longer at the data join this PR targets.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-25 13:33 UTC · original · edited 2026-11-25 16:46 UTC
Automated triage for the maintainers.
Merge candidate (worth a look). New head since the last review. Besides letting
fill_phis(emit/lower.rs) take a tracked lane mask throughmask_dwordat a data phi and evaluating mask/EXECsopSCC lazily inscc_mask_bit, it now:reads_mask_derived, which makes the program require the console wave size when a mask-derived SCC, or a phi joining a mask with data, is read (the fix tyr0nsur's report found was needed);Host::wave_lanes;synthetic_tests.rs. They check values fors_and_saveexec_b32/_b64withs_cselectacross empty, single-lane, high-dword-only and full masks, including after EXEC narrows, and the phi'd mask dwords in wave32 and wave64. They also assert the PSV0 wave size.SCC = (new EXEC != 0) follows the RDNA 2 ISA entries cited in this thread. The commit credits tyr0nsur as co-author. CI
check: passing, with all four tests reported ok. They skip on adapters whose lane counts exclude the wave size, though, and the log does not show whether they ran numerically there. A hardware run of the four tests on this head would settle that.On your reply: the requested pieces are here, so the verdict changes. The RTX 5090 approval you mention is not in this thread, so I have not counted it.
Generated by Claude Code
@tyr0nsur on GitHub · 2026-11-25 14:00 UTC · original
We ran the two numeric readbacks requested in triage on a desktop RTX 4060. The saveexec fixture narrows EXEC, uses
s_cselect_b32to select 7 or 9 from SCC, restores EXEC and writes the selected value from every lane. A second fixture stores the actual dword from a join of a tracked mask and0x0BADF00D. The wave32 readbacks matched a CPU reference for every case, including empty, irregular and single-high-bit masks.There is an extra requirement in this path. Before propagating the required wave size, WARP ran the wave32 shader in four-lane groups. For mask
0x842100F6some groups returned 9 where every lane should return 7. The RTX also accepted a nominal wave64 shader as two wave32 groups and lost the upper mask. Our fix follows mask-derived SCC and data phis into the wave-size decision and takes both words of the same ballot for wave64. The tests assert the wave-size metadata and validate both widths. Numeric wave64 readback still needs compatible hardware. AMD’s RDNA 2 ISA entries forS_AND_SAVEEXEC_B32and_B64define SCC from the updated EXEC mask.Source-authored readbacks and compiler changes · AMD RDNA 2 ISA
@Xvania7 on GitHub · 2026-11-25 14:06 UTC · original
Thanks @tyr0nsur for the rigorous hardware readbacks on RTX 4060 and for citing AMD RDNA 2 ISA §6.2 / S_AND_SAVEEXEC semantics (
SCC = (EXEC != 0)).The verification that wave32 readbacks match CPU reference across empty, irregular, and single-high-bit masks directly resolves the automated triage question on SCC correctness. The wave-size propagation insight for four-lane WARP execution and wave64 ballot pairs also aligns cleanly with the wave constraint handling in #2194.
With @DenRakEiw's approval on RTX 5090 and these hardware readbacks confirming value semantics on RTX 4060, #2289 is fully verified for merge.
@Xvania7 on GitHub · 2026-11-25 15:00 UTC · original
Updated in
70d4a46addressing both triage points, bringing in wave-size propagation and executed value readback tests with full co-authorship credit to @tyr0nsur:1. Wave-size propagation (
reads_mask_derived)reads_mask_derived(p, st)incrates/victory-shader/src/emit/lower.rs. It traverses mask/EXECsopwriters of SCC (scc_masks) and registers joining masks with data or mask-derived SCC across phis.requires_waveis set totrue, declaring the console wave size (wave32orwave64) in DXILPSV0runtime info.Host::wave_lanes(&self) -> Option<(u32, u32)>incrates/victory-shader/src/emit/host.rsto queryWaveLaneCountMin/WaveLaneCountMaxfromD3D12_FEATURE_DATA_D3D12_OPTIONS1.2. Executed value readback tests
Added 4 executed synthetic GPU tests in
crates/victory-shader/src/emit/synthetic_tests.rs:saveexec_scc_reads_whether_the_new_exec_has_a_lane_wave32: exercisess_and_saveexec_b32narrowing EXEC across multiple bit patterns (0x8421_00F6, single high bit, empty, all ones), verifyings_cselect_b32SCC evaluation.saveexec_scc_reads_both_dwords_of_the_new_exec_wave64: exercisess_and_saveexec_b64across 64 lanes, verifying SCC readback when only high-dword lanes (32–63) are active.data_phi_of_a_tracked_mask_or_a_number_wave32: runs a compute shader joining a tracked lane mask (v_cmp+s_and s2, exec, vcc) with numerical constants across a conditional branch, read back into raw UAV memory and verified against expected CPU bitwise results.data_phi_of_a_tracked_mask_or_a_number_wave64: 64-lane form joining both dwords of a 64-bit tracked mask with numbers.3. ISA reference
Per AMD RDNA 2 ISA §6.2.1 / §6.3.3:
S_AND_SAVEEXEC_B32/B64:SCC = (EXEC != 0).S_OR_SAVEEXEC,S_XOR_SAVEEXEC,S_ANDN2_SAVEEXEC,S_ORN2_SAVEEXEC,S_NAND_SAVEEXEC,S_NOR_SAVEEXEC,S_XNOR_SAVEEXEC:SCC = (new_EXEC != 0).The lazy evaluation
(lo | hi) != 0inscc_mask_bitdirectly implements this exact hardware architectural definition.All tests pass, DXIL validation passes, and
cargo xtask policyandclippyare clean. Ready for maintainer re-triage.@Marvisak on GitHub · 2026-11-25 22:07 UTC · original
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because it overrides a deliberate rule in
mainand fails one of its tests.e8e9f0c2added the samemask_dwordarm tofill_phisfor uniform joins only, because at a per-lane join lanes would take edges the console wave did not. This PR's arm has no such condition and comes first, so merged ontomain,emit::lower::tests::a_mask_joined_with_data_needs_a_uniform_joinfails. The SCC rule of part (2) is the ISA's; a rework that drops part (1) and re-measures parts (2) and (3) on currentmainwould be welcome.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
@crashbashash on GitHub · 2026-11-25 22:26 UTC · original
A data point for the rework the triage asks for: one SCC case where this head (
70d4a46) gives the wrongvalue on hardware and on WARP. Not an objection to the closing.
Where it comes from. The four
bvh_skinning:CSComputeSkinningPedBlendShapes*programs (build 1.0.2.1;e.g.
...SecMotionVelocity, shader hash82a2ad6d07417d36) are the +4 this PR adds. Around offset 0x14a8 theyrun a waterfall loop over a per-lane value that ends with
s_andn2_wrexec_b32; after EXEC is restored,s_cselect_b32 sX, exec_lo, 0reads that SCC,s_or_b32addsvcc_lo, andv_cndmask_b32selects per lane bythe result. The loop leaves only when the new EXEC is 0, so SCC is 0 there (
SCC = (D != 0)), thes_cselectgives 0, and the mask is just
vcc.Test (wave32, with this PR's
mask_program/lane_records/run_inputs; our own registers):Expected for a = all lanes, b =
0x842100F6: v3 = 2 in b's lanes and 1 elsewhere, s3 =0x842100F6.0xFFFFFFFF0xFFFFFFFFBoth devices agree, so it is the translation: the
s_cselecttakesexec_lo, as if SCC were 1 after the loop. Inthose programs the next instructions (
v_cndmask_b32 vN, vN, 0xffff, sX, thenv_cmpx_gt_u32 exec_lo, 0xffff, vNands_cbranch_execz) would then switch every lane off and skip the blend-shape block (read from thedisassembly, not measured in the game). In the game the four programs translated and validated with this PR and
their dispatches ran instead of being dropped.
I did not separate which part of the PR gives the 1 (the waterfall's SCC, or the join it reaches). The test is
self-contained, and I can open it as a test-only PR against
mainif that helps the rework.AI-assisted (Claude Code). No game data attached.
Pull request closed