Shaders: exclude masks widened past block reachability from Structured::active #2627
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!2627
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2627"
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?
@VastyViz on GitHub · 2026-11-25 17:08 UTC · original
VastyViz:shaders/active-mask-reachability→main· +579 −1 · 3 files · 1 commits · openSummary
Fixes a correctness bug in
Structured::active(structure.rs) where lane masks that can hold bits for lanes outside the writing block's reachability (cond[b]) were still markedactive, causingLower::mask_dwordto take awaveActiveBallotinside a divergent block and silently drop lanes that skipped the block.Root Cause
Lanes::stepunconditionally inserted:EXECwrite (r.exec.is_some_and(|e| e.0 == k)) and every VALU compare/carry mask intoself.active, even when a divergent block (cond[b]narrower than the wave) widened or replacedEXECpastcond[b](e.g.s_or_b32 exec_lo, exec_lo, s_savedors_xor_b32 exec_lo, exec_lo, s_savedinside ans_cbranch_execzbody) and ran subsequentv_cmp/ scalar mask ops under that widenedEXEC.exec— whenLanes::joinsimplified a loop'sEXECphi inside a divergent region toBool::TRUE(true for lanes entering the loop),b.implies(m, Bool::TRUE)held trivially for complementing ops (s_not,s_nand,s_nor,s_orn2,s_orn1,s_xnor), leaving bits set for skipped lanes markedactive.Changes
crates/victory-shader/src/structure.rs:Bools(is_uniform_ro,confined_ro) that allocate zero BDD nodes and cannot triggerBools::overflow.Lanes::filter_active(called fromLanes::finish) that drops masks written under widenedEXECor by complementing scalar mask ops under aBool::TRUE-simplifiedEXECphi in divergent blocks, while preserving:is_uniform_ro),s_wqmand non-widening narrowings ofEXEC,*_saveexec,activemask (followingrestoredVGPR spills) whose defining block is confined tocond[b]or post-dominated bybwithin its loop iteration (postdominates).structure::tests:widened_exec_and_masks_in_divergent_block_are_not_activecomplement_inside_divergent_loop_is_not_active_but_uniform_branch_stays_activepost_loop_reconvergence_exec_restore_stays_active_but_back_edge_escape_does_notcrates/victory-shader/src/emit/lower.rs:EXEC-write guard inLower::mask_numberfrominst.write(Reg::S(EXEC)).is_some()to(*code != EXEC && inst.write(Reg::S(EXEC)).is_some()), allowing pures_or/s_xor/s_movwrites toEXEC(while still excluding*_saveexec) to be reconstructed from operand ballots when read as data in compute shaders.widened_exec_read_as_data_reconstructs_scalar_ops_and_refuses_valu_cmp.crates/victory-shader/src/emit/synthetic_tests.rs:widened_exec_in_divergent_block_counts_all_lanesverifying that:s_or_b32 exec_lo, exec_lo, s20+s_bcnt1_i32_b32inside a 16-lane divergent block produces32(previously miscompiled to16),s_xor_b32 exec_lo, exec_lo, s20+s_bcnt1_i32_b32produces16(previously miscompiled to0),v_cmprun under widenedEXECinside a divergent block is refused cleanly with"a lane mask holding lanes elsewhere read as data".Verification
cargo test -p victory-shader --locked -- structure::tests emit::lower::tests widened_exec_in_divergent_block_counts_all_lanes pops_wait_loop_exits_immediately_for_inactive_lanes— 52 passed, 0 failedVICTORY_WARP=1 cargo test -p victory-shader --locked -- widened_exec_in_divergent_block_counts_all_lanes— passedcargo clippy --workspace --all-targets --locked -- -D warnings— passcargo clippy --workspace --all-targets --all-features --locked -- -D warnings— passcargo xtask policy— 191 files okgit diff --check— clean26,599containers /26,177programs against63bcca4):26,177 / 26,177structured (0BDD overflows)14,258 / 14,259VP,2,733 / 2,763CS,8,765 / 8,765MS emitted (exact match withmain,0"a lane mask holding lanes elsewhere read as data"regressions)@oni-swr on GitHub · 2026-11-25 17:38 UTC · original
Independent verification (no physical GPU, no game files, no competing PR). AI-assisted: Claude Code (Claude Sonnet 5.5).
VICTORY_D3D12_WARP=1andVICTORY_WARP=1(software WARP only;VICTORY_WARP=1is what makes the shader test harness skip its "hardware" adapter pass).origin/main=13f91caee2Results
cargo test -p victory-shader --lib --locked structure::: 14 passed, 0 failed, 1 ignored (includes the new device-freestructure::testscases).self.filter_active(cond, execs);call disabled,widened_exec_and_masks_in_divergent_block_are_not_activeandpost_loop_reconvergence_exec_restore_stays_active_but_back_edge_escape_does_notFAIL (12 passed, 2 failed); restored, all 14 pass. The 2-linelower.rschange is not covered by these (they still pass with it reverted); only the GPU test below exercises it.cargo test -p victory-shader --lib --locked -- --test-threads=1: 270 passed, 4 failed, 3 ignored. Three are the same failures as onorigin/main(WARP is not a 32-lane wave device; main: 267 passed, 3 failed, 3 ignored). The fourth is the PR's ownsynthetic_tests::widened_exec_in_divergent_block_counts_all_lanes:hardware/or: no pipeline for a wave of 32. WARP cannot build a wave-32 pipeline, and the test tolerates that only when its loop'swarpflag is true; withVICTORY_WARP=1both passes are WARP, so the first one tripsassert!(warp, ...). The translation half of that test (DXIL validation and theUnsupportedrefusal) runs before that point and passes.cargo clippy -p victory-shader --all-targets --locked: no warnings.Review:
filter_activeis read-only on the BDD (allocates no nodes, so no newoverflowpath) and only runs for non-uniform blocks that write EXEC or have a true-EXEC phi. No correctness issue found in the diff. Note that the runtime assertions ofwidened_exec_in_divergent_block_counts_all_lanesnever execute on WARP (it skips there), so the lane-count claim is only checked on a wave-32 GPU.Not tested: the runtime half of
widened_exec_in_divergent_block_counts_all_lanes(needs a wave-32 GPU; no physical GPU used here) and any retail title.@kotekompotek on GitHub · 2026-11-25 17:49 UTC · original
Reviewed: the guard change is right — when the op's destination IS
exec(*code == EXEC), writing exec is the operation itself, not a side effect to reject; the old condition refuseds_or_b32 exec_lo, exec_lo, s20-style widening.s_and_saveexec-family writes still fail the first check via the extra destination. The wave64-in-wave32-half test (counting 32/16 lanes through widened exec) is a solid repro. CI green.@VastyViz on GitHub · 2026-11-25 17:55 UTC · original
Thanks @oni-swr and @kotekompotek for the review and independent verification!
Pushed follow-up commit
c001191addressing both test-coverage points from @oni-swr:emit::lower::tests::widened_exec_read_as_data_reconstructs_scalar_ops_and_refuses_valu_cmpcovering both theLower::mask_numberscalarEXECreconstruction (s_or_b32/s_xor_b32) and thev_cmpunder widenedEXECrefusal without requiring a GPU."hardware"pass insynthetic_tests::widened_exec_in_divergent_block_counts_all_laneswhenVICTORY_WARP=1is set (matchingHost::new'sVICTORY_WARPoverride), so software-only WARP runs no longer trip the wave-32 assertion while hardware runs still enforce the exact lane counts (32and16).Verified locally with
structure::tests+emit::lower::tests+widened_exec_in_divergent_block_counts_all_lanes(both hardware RTX 3080 andVICTORY_WARP=1),cargo clippy(default and--all-features), andcargo xtask policy.@Marvisak on GitHub · 2026-11-25 22:15 UTC · original · edited 2026-11-26 03:25 UTC
Automated triage for the maintainers.
Verdict: needs work. Thanks for rebasing; it merges cleanly now and CI (
check) passes.The idea is sound: a mask written in a divergent block after
EXEChas been widened pastcond[b]should not be inStructured::active, sincemask_dword's ballot would miss the lanes that skipped the block. TheLower::mask_numberchange (allow*code == EXEC) is small and the tests cover it.What holds it back is the size of
Lanes::filter_active/ActiveCheckincrates/victory-shader/src/structure.rs: about 650 lines of special cases (per-opcode narrowing/restore tables,postdominates, a 16-steprestoredwalk, a 64-deep visit cap, optimistic answers on cycles). Your own archive run shows no program whose output changes againstmain(no new successes, no new refusals). So this is a lot of analysis for a pattern not yet seen in the title's shaders.To change the verdict, either:
main, and ideally one whose output was wrong before (no shader data in the PR), orEXEC-widenings_or/s_xor/s_movwithout theActiveCheckrestore tracking, and keep the rest for when a program needs it.Generated by Claude Code
@VastyViz on GitHub · 2026-11-26 01:28 UTC · original
Rebased onto latest
main(63bcca4, new head54cae73), resolving the append conflict at the end ofcrates/victory-shader/src/emit/synthetic_tests.rs.Re-verified after rebase:
cargo test -p victory-shader --locked -- structure::tests emit::lower::tests widened_exec_in_divergent_block_counts_all_lanes pops_wait_loop_exits_immediately_for_inactive_lanes(52 passed, 0 failed)VICTORY_WARP=1pass onwidened_exec_in_divergent_block_counts_all_lanes(passed)cargo clippy --workspace --all-targets --locked -- -D warnings&--all-features(pass)cargo xtask policy(191 files ok) &git diff --check(clean)54cae73d90to913f8485b5@VastyViz on GitHub · 2026-11-26 15:07 UTC · original
Addressed the triage feedback by cutting
crates/victory-shader/src/structure.rsdown to a single non-recursive RPO pass (new head913f848on63bcca4):What was removed
ActiveCheck, recursiveval_confined/val_confined_bodySSA/phi walking, the 64-deep visit cap, optimistic cycle returns, the 16-steprestoredloop,implies_ro/implies_memo, and the separatesyntactic_narrow/val_mask/true_maskstables.structure.rsdiff dropped from +648 to +414 lines (of which 145 lines are unit tests — implementation cut roughly in half from ~503 to ~266 lines).Why the one-step
op_confined+postdominatescheck stays26,599containers): without checking whether anEXEC-restorings_or/s_xor/s_movrestores anactivemask from a confining or post-dominated block, 203 title programs (88VP,113CS,2MS) regress and fail to emit with"a lane mask holding lanes elsewhere read as data"(due toLanes::joinsimplifying loopEXECphis toBool::TRUEinside divergent regions and post-loop reconvergence blocks keeping unsimplified loop-exit atoms incond[b]).active.contains(&v)+confined_ro(cond[blk], c) || postdominates(block, blk)) fixes all 203 false positives with zero recursion and zero heuristics.0programs currently read a widened-EXECmask as data (14,258/14,259VP,2,733/2,763CS,8,765/8,765MS emitted — identical tomainwith0regressions).Verification
cargo test -p victory-shader --locked -- structure::tests emit::lower::tests widened_exec_in_divergent_block_counts_all_lanes pops_wait_loop_exits_immediately_for_inactive_lanes— 52 passed, 0 failedVICTORY_WARP=1onwidened_exec_in_divergent_block_counts_all_lanes— passedcargo clippy --workspace --all-targets --locked -- -D warnings&--all-features— passcargo xtask policy(191 files ok) &git diff --check(clean)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.