Shaders: refuse side effects in whole-wave sections #2874
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!2874
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2874"
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?
@yumaste on GitHub · 2026-11-25 22:54 UTC · original
yumaste:fix/whole-wave-side-effects→main· +134 −9 · 2 files · 4 commits · openSummary
The whole-wave simulator reconstructs values that leave a section. Before this change, the shader translator could accept a section containing an effect such as an
s_barrieror a buffer store and emit the same DXIL as if that instruction were absent.Use the regular lowering path's side-effect classification for instructions inside the section and reject an effect with its byte offset. This includes buffer and global loads that write to LDS. Also reject structured pixel discards inside the section, since the normal discard emission would be skipped there.
#2886 preserves rounding-mode writes in whole-wave sections. A trial merge with #2771 and #2886 onto
mainpassed. Their decoder and rounding-mode fixes both remain in the merged tree.Validation
s_barrierandbuffer_store_dword. Before the fix, putting either instruction inside the section produced byte-identical DXIL to omitting it. With the fix, both are rejected at the expected offset. Both still translate outside the section.6b906eb: regressions cover buffer/global loads into LDS and a structured discard annotation supplied directly to lowering. With #2771 and #2886 merged locally, all 37 lowering tests and the FP16 rounding regression passed under WARP. Clippy with all targets and features passed. Moving the whole-wave regressions to their own module brought the mergedemit/lower.rsto 522,717 bytes, below the 524,288-byte asset-policy limit.victory-shaderlibrary suite withVICTORY_WARP=1reported 299 passed, 4 failed, and 3 ignored. The same four tests failed with the same diagnostics on base commit842b0cb: three wave32 pipeline failures and one texture gather mismatch.victory-shaderwith all targets and features and-D warningspassed. The staged asset policy check passed.AI-assisted (Codex). Only synthetic fixtures were used.
@cloph-dsp on GitHub · 2026-11-25 23:04 UTC · original
Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup.
cargo test --locked -p victory-shader emit::lower::tests::whole_wave_sections_reject_side_effects --quiet-> 1 passed, 305 filtered out.cargo test --locked -p victory-shader emit::lower::tests --quiet-> 34 passed, 0 failed.git diff --checkagainst merge-base842b0cbclean; the PR changes 1 file, +51/-12 (crates/victory-shader/src/emit/lower.rs).This is independent local verification, not a formal approval.
AI-assisted (Hy4 flash).
@fuzeofficlal on GitHub · 2026-11-25 23:04 UTC · original
Reviewed and verified
854cc9e4on Windows 11 (RTX 5090 + WARP +dxil.dll) againstmain(842b0cb):has_side_effect(inst)and checkinghas_side_effect(inst) || self.x.st.discards.contains_key(&(b, i))insection_instcleanly rejects exports, non-global_load_*flat/global/scratch ops, store/atomic ops,s_barrier, non-read/swizzle/permute DS ops, and structured pixel discards with the exact instruction byte offset.emit::lower::tests34/34 passed (includingwhole_wave_sections_reject_side_effects),sectiontests 5/5 passed on RTX 5090 + WARP,cargo clippy --locked -p victory-shader --all-targets -- -D warnings0 warnings,cargo xtask policy(191 files ok).crates/victory-shader/src/emit/lower.rsis at521,946bytes (2,342bytes below the 512 KiBxtask policylimit).Fields::Buffer { lds: true, .. }(buffer_load_* lds) ands_sendmsg*/s_setreg_*aren't matched byhas_side_effect.@Marvisak on GitHub · 2026-11-26 04:25 UTC · original
Automated triage for the maintainers.
Merge candidate. Side-effect classification in
emit/lower.rsmoves intohas_side_effect, andsection_instuses it to refuse an effect or structured discard inside a whole-wave section. Before, stores, LDS writes, exports ors_barrierinside such a span were silently dropped, so failing the shader is the correct outcome. The test checks thats_barrierandbuffer_store_dwordtranslate outside a section and are refused inside one.CI: passing.
Generated by Claude Code
@AwsAli05 on GitHub · 2026-11-25 23:06 UTC · original · reviewed
The focused whole-wave test passed on Windows at
854cc9e. I checked that barriers and stores are still accepted outside a simulated section, while both return the explicit byte-offset refusal inside it.st.discardsis a separate condition fromhas_side_effect. A structured pixel discard case would cover that branch, since removing it would leave the current barrier and store test green.AI-assisted review and test.
@kotekompotek on GitHub · 2026-11-25 23:36 UTC · original · reviewed
Correct conservative boundary: whole-wave simulation can only reconstruct side-effect-free sections — a store/atomic/barrier would execute once in simulation instead of per real lane, and a discard changes which lanes the wave ops reason about. Refusing via the unsupported path is the right failure mode. The has_side_effect table looks right (exp, flat non-global-load, ds non-read/swizzle/permute). LGTM.
@Dukestar69 on GitHub · 2026-11-26 10:09 UTC · original · approved these changes
Verified against
origin/main(63bcca4):cargo test -p victory-shader --lib emit::lower::tests:: -- --test-threads=1: 34/34 passed (includingwhole_wave_sections_reject_side_effects).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly refuses side-effecting instructions inside whole-wave sections.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 10:46 UTC · original · requested changes
Refusing
s_barrier,buffer_store_dword, and structuredst.discardsinside whole-wave sections closes a real silent-omission bug, andgit merge-treeagainst63bcca43is clean (emit/lower.rs=521,946bytes).Two gaps remain in
has_side_effect/ section handling (emit/lower.rs:480-491, 1388-1396):Fields::Buffer { lds: true, .. },gfx10/fields.rs:343):buffer_load_*withldsset writes to LDS without matching"store"or"atomic", so it is still silently skipped inside a section.s_round_mode/s_setreg*toHW_REG_MODE):section_instneither refuses them nor callsround16_after, so a same-block conversion afterEXECis restored uses the stale rounding mode (tracked separately in #2886 if preserved rather than refused).Please cover the
ldsflag (and either reject or preserve rounding-mode updates), and add regression coverage forlds-load andst.discards.Verified locally on Windows 11 x64 (RTX 5090 + WARP +
dxil.dll,854cc9e4):cargo run --locked -p xtask -- policy: passed (191 files ok)cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): cleanemit::lower::tests: 34 passed, 0 failedsection -- --test-threads=1(RTX 5090 andVICTORY_WARP=1): 5 passed, 0 failed on both@yumaste on GitHub · 2026-11-26 12:33 UTC · original
Follow-up to the requested changes in
c9d1fcf. Loads with the LDS flag now count as side effects, and focused regression coverage exercises both the LDS-writing load and the structured discard path. Both tests fail when their corresponding guard is removed.#2886 preserves rounding-mode writes. The two branches now merge together cleanly, so #2886 can land first and #2874 picks up the round-mode behavior on
main.@fuzeofficlal on GitHub · 2026-11-26 12:58 UTC · original · requested changes
The updated tests close both gaps from the earlier review: an LDS-writing buffer load (
Fields::Buffer { lds: true, .. }) and a structured-program discard inside a whole-wave section, with the check now running before every simulated instruction inlower_block(crates/victory-shader/src/emit/lower.rs:1384-1392).Two items still need attention before landing alongside sibling fixes:
has_side_effectatcrates/victory-shader/src/emit/lower.rs:483still excludes allglobal_load_*instructions without checkingFields::Flat { lds: true, .. }, so aglobal_load_* ... ldsinside a whole-wave section can still be skipped and directly conflicts with#2771.origin/main(63bcca43) keeping the shared predicate and both regressions produces a524,348-byteemit/lower.rs(#2874 + #2771, 60 bytes overxtask's524,288-byte limit), or524,437bytes (+149 bytes over) when also retaining#2886's per-instructionmode16rounding-mode update (emit/lower.rs:1382-1395). Please carryFields::Flat { lds: true, .. }intohas_side_effect(and keep#2886's rounding-mode update when integrating) while moving tests out oflower.rsor trimming enough bytes to stay under the 512 KiB cap.Local verification on
c9d1fcfb22e6:xtask policy(191 files ok;lower.rsstandalone =523,549bytes),cargo clippy -p victory-shader --all-targets/--all-features,emit::lower::tests(35 passed), andsectiontests (6 passedon both RTX 5090 andVICTORY_WARP=1).@yumaste on GitHub · 2026-11-26 13:44 UTC · original
Addressed in
6b906eb. Whole-wave lowering now rejectsglobal_load_dword ... ldsat its instruction byte offset, with a synthetic regression. The whole-wave effect tests now live inlower/whole_wave_effect_tests.rs.I merged this branch, #2771 and #2886 onto
main(63bcca4) locally without conflict. The combinedlower.rsis 522,717 bytes. Under WARP the 37 lowering tests and the rounding-mode regression passed, along with all-targets/all-features Clippy and asset policy.@AurumCarlos on GitHub · 2026-11-26 14:08 UTC · original · reviewed
On
6b906eb: refusingglobal_load_* … ldsin whole-wave sections makes sense (it writes LDS once per simulated wave instead of per lane, like the buffer form), and moving the tests intolower/whole_wave_effect_tests.rskeepslower.rsdown.One maintainability point. The new
effectin the instruction lowering ishas_side_effectminus theFlat { lds: true }arm, written out a second time:I assume the difference is on purpose: outside a section, a global LDS load that fails to lower should still mark its results missing instead of refusing the program, as on
main. But nothing says so, and the next arm someone adds tohas_side_effectwill silently not reach this copy. Writing it ashas_side_effect(inst) && !matches!(inst.fields, Fields::Flat { lds: true, .. }), with a one-line comment on why the LDS form is excluded here, would keep the two from drifting apart.@fuzeofficlal on GitHub · 2026-11-26 14:15 UTC · original · approved these changes
Both items from the previous review are cleanly resolved:
has_side_effect(emit/lower.rs:480-498) now explicitly checksmatches!(inst.fields, Fields::Flat { lds: true, .. })so GLOBAL-to-LDS is rejected inside whole-wave sections at the exact instruction offset (16), covered bywhole_wave_sections_reject_global_loads_into_lds.whole_wave_effect_tests.rsbringsemit/lower.rsdown to521,821 B(2,467 B under the 512 KiB policy cap), and a clean 3-way merge with #2771 (26006ae4) produces522,628 B(1,660 B under the cap, zero conflicts).Note for maintainers: outside whole-wave sections, ordinary lowering of GLOBAL-to-LDS still depends on #2771 landing alongside this PR.
Local verification at
6b906eb9(and merged ontoorigin/main63bcca43at88e9b6a5):xtask policypassed (192 files ok),cargo clippy -p victory-shader --all-targets(defaultand--all-features) passed with 0 warnings,emit::lower::passed (36/36), andsectiontests passed on both RTX 5090 andVICTORY_WARP=1(7/7). Approving.@yumaste on GitHub · 2026-11-26 14:22 UTC · original
I documented why the whole-wave classifier has its own rule for global LDS loads and named it accordingly in
ea146a8. I tried refactoring the ordinary error predicate to share more of the expression, but that changed the same hunk as #2771 and made the trial merge conflict. This head still merges cleanly with both #2771 and #2886. The shared helper still covers atomic, barrier and LDS-buffer effects. Under WARP, all 36 lowering tests passed, and all-target/all-feature Clippy passed.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.