victory-shader: lazily lower non-active console lane-mask SOPs bitwise #1423
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!1423
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1423/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?
@bartikele on GitHub · 2026-11-24 17:56 UTC · original
bartikele:shader-non-active-console-mask→main· +115 −0 · 1 files · 1 commits · closed without mergingIn
Lower::mask_dword, when a compute shader (MaskData::Console) reads a lane mask as data that is not inself.x.st.active(e.g. a bitwise combination of outer-EXECmasks computed under a narrowerEXEC), lazily evaluate the mask's defining bitwise scalar operation (s_mov,s_not,s_and,s_or,s_xor,s_andn2,s_orn2,s_nand,s_nor,s_xnorin_b32/_b64) from its operands instead of failing witha lane mask holding lanes elsewhere read as data.Evaluating lazily inside
mask_dword(rather than eagerly inLower::sop) ensures control-flow-only masks in waterfall loops never triggerwaveActiveBallotorflags::WAVE_OPS.Adds unit test
emit::lower::tests::non_active_console_mask_sop_lowers_bitwise.Tested with:
cargo clippy -p victory-shader --all-targets --locked -- -D warningscargo test -p victory-shader --lockedcargo xtask policy@dpalacios69 on GitHub · 2026-11-24 18:26 UTC · original
Independent check on Linux of head
55f0dc4, merged onto currentmain(ffe310e; a fast-forward):cargo test -p victory-shader --lockedpasses (97 passed, 0 failed, 1 ignored). The 1 test(s) it adds run on Linux and pass.cargo clippy -p victory-shader --all-targets -- -D warningsshows nothing of its own, only the two unused-import errors inemit/mod.rsthatmainalready has on Linux. No GPU run. AI-assisted; no game data.@rezioliver-collab on GitHub · 2026-11-24 19:40 UTC · original
I ran an offline A/B comparison of
ffe310eand55f0dc4on Windows 11 with Rust 1.98.1 (MSVC) anddxil.dll1.8.2502.11. I reused two baseline runs after verifying the archive and validator SHA-256 hashes, then ranvictory translate --validate --list --jobs 1twice on the PR against the sameshaders.rpf.The
a lane mask holding lanes elsewhere read as dataerror dropped from 272 to 7. Of the 265 compute shaders that progressed past it, 260 hit another translation error and five emitted DXIL that the validator rejected.a descriptor read only as dataa structured buffer of unknown stridea select on an untracked maska descriptor's address or format read as dataa scalar memory read as dataa lane-mask join of an untracked masks_getpc_b64Compute DXIL emission rose from 1,441 to 1,446. All five newly emitted shaders received the validator diagnostic about an operation incompatible with the shader stage or another entry property. Both revisions validated 21,724 shaders overall, including 1,417 compute shaders. Comparing all 25,889 listed shaders by archive offset and stage showed zero validation gains or losses. Both repeats agreed within each revision.
For the synthetic check, I copied only
non_active_console_mask_sop_lowers_bitwiseinto a separate baseline checkout. The test builds two masks before narrowing EXEC, combines them withs_and_b32, and reads the result as data withs_bcnt1_i32_b32. It reproduced the targeted error on the baseline and passed on the PR.cargo xtask policypassed on both revisions.AI use : Assisted by GPT 6.2 Sol.
@sinan-cmyk on GitHub · 2026-11-24 19:50 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count change against
main.Offline. I merged head
55f0dc4ontomainffe310e(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: 21,724 onmain, 21,724 with this PR.Another 219 programs move from "a lane mask holding lanes elsewhere read as data" on to "a descriptor read only as data", the reason #1067 handles. So this PR may gain much more stacked on #1402, and I'm measuring that.
Tests: with the same merge,
cargo test --locked -p victory-shader --libpassed 121, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@sinan-cmyk on GitHub · 2026-11-24 20:31 UTC · original
Stacked on #1402: +214 programs, 0 lost
Result: On
mainalone this PR gained nothing (earlier comment). It moved 219 programs from "a lane mask holding lanes elsewhere read as data" to "a descriptor read only as data", which #1067 handles. On top of #1402, which contains #1067, those programs now validate.The merge. This PR conflicts with #1402 in one hunk of
emit/lower.rs: both add a different test at the same place in the test module. I kept both tests. No functional code conflicts.231040955f0dc4)s_getpc_b64.cargo test --locked -p victory-shader --libon the merge: 138 passed, 0 failed (RTX 4070 SUPER).Interaction with #1221. With #1221 also merged on #1402, the result is +213, one fewer than this PR alone. One program goes back to "a lane-mask join of an untracked mask". #1221 alone adds nothing on top of #1402 (details on #1221).
Method:
victory translate --validate --listonshaders.rpf(1.0.2.1), dxil.dll 1.8.2502.11, compared program by program (25,889 programs). No shader names or data are included, per the asset policy. AI-assisted (Claude Code).@sinan-cmyk on GitHub · 2026-11-24 21:30 UTC · original
Static review of #1423 (head
55f0dc4)Summary: I read the diff against
mainffe310eand found no likely bug. The lowering looks right by construction. What is missing is a test that checks the computed values, and wave64 coverage. Line numbers below refer tocrates/victory-shader/src/emit/lower.rsat this head. Context from my earlier measurements: stacked on #1402 this PR gains 214 programs offline, 0 lost, and its tests pass on an RTX 4070 SUPER. Offline counts show only that the DXIL validates.What looks right
mask_dword, ~1191): only a mask read as data thatstructuredid not markactive, and only inMaskData::Console(compute). Masks used as branch conditions (s_cbranch_vccz/execz), asv_cndmaskselectors or as EXEC go throughstructure's per-lane booleans, not throughmask_dword. So no use that already translated changes. Only reads that were refused before now lower. That fits the 0 programs lost.i32_of → get → mask_dword. If it isactive, it gets its ballot at its defining block, and that ballot is exact. If it is a non-active SOP mask, it recurses.ballotingguards the recursion (1255, 1313). A phi mask has no defining SOP and returnsNone, so it keeps the old refusal. Loops cannot recurse forever.self.cur), not at the SOP. Operands are SSA values that dominate the SOP, which dominates the read, and the ops are pure. So the result is the same.Reg::S(code + 1)of each operand, and that maps to the operand'shighsentry, the ballot's second dword. The inline-constant sign extension and the zero-extended literal match the existing 64-bit SOP helper (~2449).Findings, ranked
non_active_console_mask_sop_lowers_bitwise(~7298) only asserts thatlowers()returnsOk. A wrong operand, a wrong op mapping or a wrong half would still pass. This path now produces numbers where the translator used to refuse. Suggestion: onerun_caseshardware/WARP test invalu_tests. Two compares, thenv_cmpxto narrow EXEC, thens_and/s_andn2/s_notof the outer masks, thens_bcnt1orv_movof the result. Assert the console bit count, including lanes outside the narrowed EXEC.lowers()buildswave64: false, so the high-half code (h = 1, theReg::S(code + 1)reads, the const sign extension) never runs in a test. In Console mode on a 32-lane host, the ballot's second dword also depends on how wave64 is emulated. That is not new in this PR, but this path now relies on it too.highin wave32. In a wave32 program,highsshould be empty. Ifhighwere ever true, the code would read the next SGPR as a "high half" without any error.if high && !self.x.native.wave64 { return Ok(None) }makes that impossible.halfclosure (1259) is a copy of the 64-bit operand helper in the SOP lowering (~2449). A shared method would keep both from drifting apart, for example in literal handling.ballotswould keep the DXIL smaller when a mask is read several times.s_cselect_b64/_b32of two masks, and the saveexec forms, returnNoneand keep the old refusal. They are possible follow-ups, not bugs.AI-assisted (Claude Code); static review only, nothing run.
@Marvisak on GitHub · 2026-11-25 00:40 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Lane masks holding lanes elsewhere computed bitwise from their defining scalar op in compute: main has exactly this as
Lower::mask_number(lower.rs 1763, commit8af04727).If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed