Shaders/structure: require masks in scc_some, active, and wave_any to vanish outside block reach #445
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!445
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-445"
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?
@AscilCH on GitHub · 2026-11-25 00:52 UTC · original
AscilCH:fix/shader-structure-vccz-and-scc-some-active→main· +127 −9 · 1 files · 1 commits · openProblem
In
crates/victory-shader/src/structure.rs, three exported wave-mask invariants assumed that lanes not running blockb(!cond[b]) hold0in the tested mask, without verifyingimplies(m, cond[b])against the final block reachabilitycond[b]:Structured::scc_some: Exported every non-scc_everyentry ofself.scc_lane. BecauseLower::scc_somecomputeswaveAnyTrue(m)over only the lanes executing the defining blockb, operations whose result has1bits in inactive lanes outsidecond[b](such ass_not_b32 s2, exec_loors_cmp_lg_u32 exec_lo, -1inside a divergent branch) evaluated tofalsewhen hardware setsSCC = 1.Structured::active: Unconditionally inserted anyr.execwrite (e.g.,s_or_saveexec_b32 s5, -1wideningEXECto all lanes inside a divergent block) intoactive, even though lanes outsidecond[b]do not participate inb'swaveActiveBallot.Structured::wave_any[b]: KeptSome(any)even when a lane outsidecond[b]could determine the branch (!implies(set_bit, cond[b])), which would causeLower::wave_wideto evaluatewaveAnyTrue/waveAllTrueover onlycond[b]lanes.s_cbranch_vccz/s_cbranch_vccnzinbranch(): Performed a deadself.b.and(vcc, exec)even thoughs_cbranch_vccz/vccnztestsVCCindependently ofEXEC.Fix
Builder::finish():(&scc, &m)intoscc_someonly when!self.scc_every.contains(&scc)and eitherself.b.implies(m, cond[b])orm's support is purelyAtom::Uniform(_).self.activeentries whose maskmdoes not implycond[b]at their defining blockb.self.wave_any[b]if a non-uniform wave-mask branch in a reachable block has!self.b.implies(set_bit, cond[b]).vccdirectly inbranch()fors_cbranch_vccz/s_cbranch_vccnz.scc_some_and_active_require_mask_zero_outside_block_reach.Verification
cargo test -p victory-shader --locked structure::tests: 13 passed, 0 failedcargo test -p victory-shader --locked wave64_tests: 5 passed, 0 failedcargo xtask policy: 169 files okcargo clippy -p victory-shader --all-targets --locked -- -D warnings: cleancargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic unit tests only, no game data.)
@avt0m4t48 on GitHub · 2026-11-25 02:12 UTC · original
I verified
308efd726e621e564115b120522849979b7df6a8with independent synthetic GFX10 instructions on Linux. I also applied the single PR commit to currentmain(c96b4f2b8365bf43d54ab074940923ef8267f4c6) and ran the same checks there.-1. The parent and unpatched main advertised bothscc_someand wave-wide reduction. Both patched trees dropped them. The AND control (EXEC & VCC) retainedscc_some,active, and the corresponding wave-wide reduction in both widths.The parent and unpatched main each passed the two controls and failed the two absent-lane tests. The PR head and patched main passed all four tests (16 total cases). The shader library suite also passed at the PR head (171 passed, 2 ignored) and on patched main (172 passed, 2 ignored).
Synthetic instruction words
The words below are passed little-endian to
ir::build, with the correspondingwave64setting, then checked throughstructure::structure.cargo check --locked --target x86_64-pc-windows-msvc -p victory-shader --testspassed for both patched trees. These were Windows-target type checks from Linux. The fixture checks the structuring decisions and was run without a D3D12 dispatch.AI-assisted using Codex.
@deepdev237 on GitHub · 2026-11-25 04:26 UTC · original · edited 2026-11-25 05:11 UTC
Full test environment
x86_64-pc-windows-msvccargo build --profile diag -p victory --features diagnostics(diag= release + debug info)main310c6eb6c16822ab95076aad61fce19bba86bb98levels.rpf,audio.rpf,pack/story000/story000.rpf,navmeshes.rpfand sixdata/ttdb/*.ttpf), so failures that depend on those bytes are not emulator bugs.Regression report: with this PR, about 1,300 more shader programs are refused (
emit: a lane mask holding lanes elsewhere read as data).I measured it with
victory translate --jobs 16 shaders.rpf(diagnostics build,cargo build --profile diag -p victory --features diagnostics). The same game files were used for every build (Series X, 26,503 containers, 614 duplicates skipped, 26,084 programs).lane mask holding lanes elsewhere read as datamain310c6ebmain310c6eb+ this PR (head merged alone)310c6eb+ about 110 other open PRs, with this PRCompute takes the biggest hit: 895 compute programs that translate on
mainare refused with this PR. Examples of programs that translate onmainand are refused with it:MSNC_VS_PropFoliageSkinDeferredFire_4352f5e1_Wrapped #e9b286358963f668 ~4623c785 Ms at 0x2624MS_VS_PropFoliageDeferredFire_7cf79608_Wrapped #3e3a42eff1581db4 ~ae28707a Ms at 0x7830Reproduce in under a second, with no full-pack run:
On
mainit gives1 emitted of 1 mesh programs; with this PR,0 emittedand the reason above.Where it comes from, as far as I can tell:
Lower::mask_dword(emit/lower.rs) refuses withMASK_ELSEWHEREwhen the mask's value is not inself.x.st.activeand the "whole" exception does not apply. This PR makesactivestricter ("vanish outside block reach"), so many more masks read as data leaveactiveand hit thatreturn Err(MASK_ELSEWHERE). The stricteractivemay well be more correct forscc_some/wave_any. If so,mask_dword, or what feeds its "whole" exception, probably needs a matching change so these masks are still turned into ballots instead of refused. Otherwise this trades a theoretical miscompile for about 1,300 shaders the game simply goes without (foliage, fire and a large part of the compute work).Machine: AMD Radeon RX 9060 XT (RDNA4, host wave lanes min 32 / max 64, driver 32.0.32015.7029), Ryzen 9 5950X, 24 GB RAM, Windows 11 build 26300, rustc 1.98.1. I have reverted this PR in my integration build for now.
Full
victory translatesummaries of the four buildsmain310c6ebmain310c6eb+ this PR (head308efd726e621e564115b120522849979b7df6a8) merged aloneintegration (
310c6eb+ about 110 open PRs) with this PRthe same integration with only this PR reverted
Command for each:
victory translate --jobs 16 shaders.rpfwith that build's diagnostics executable (main's executable SHA-256f435e71eed706b620cbaff0f513e83e4506a56bdd2225ea24dd9b2d6b97d80bd). Every build used the same game files and the same machine. The single-shader reproduction runs in 0.3 s.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.