shader(fold): mark EXEC_LO dirty at basic-block leaders #3097
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3097"
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?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by RanoGames on 2026-11-29T20:00:35Z.
What it changes
Fixes cross-basic-block
EXEC_LOsettling incrates/victory-shader/src/fold.rs:Fold::dirtytracks whetherEXEC_LOmight differ fromE.lo | E.hi. Previously, at basic-block leaders (leaders.contains(&inst.offset)),f.flush()returned early whenf.runwas empty without markingf.dirty = true.dirty == false(such as a!lives_cbranch_execz/nz) while another predecessor jumped to the leader withEXEC_LOholding only one half (for example after a vector flush and a live-SCCbranch), the leader inheriteddirty == falseand skippeds_or_b32 EXEC_LO, e, e + 1before a subsequent!lives_cbranch_execz/nz.f.dirty = true;at every basic-block leader afterf.flush().emit::folded_tests::exec_branch_at_join_leader_settles_exec_from_other_predecessors.How it was tested
folded_testson host GPU/WARP)dirty == falseinheriteddirty == falseand branched on staleEXEC_LO.f.dirty = trueat each leader forcessettle()/scalar_inst()to restoreEXEC_LO = E.lo | E.hi.emit::folded_tests)cargo testpassed for the crates it touches: yes (cargo test --locked -p victory-shader --lib -- emit::folded_tests: 18 passed, 0 failed;cargo xtask policy --stagedpassed)Checked for overlap
fold.rs,e_written, ands_cbranch_execnz.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-29T20:46:51Z.
Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch
janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with--profile diag --features diagnostics, and the CPU tests of the touched crates pass. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T06:11:33Z.
Checked this against a Radeon gfx1036 (RDNA 2) running the same kernels natively in wave64, and ran the folded form for main and for this PR on an RTX 5080 and on that Radeon through D3D12.
Setup
mainat41adb551with this PR's head (4401982) merged locally, no conflict. The victory-shader test binary was built from that merged tree (own tree and target directory).super::folded(the two-lanes-per-host-lane rewrite),dxil.dllvalidation, dispatched on the 5080 and on the Radeon (VICTORY_ADAPTER=radeon).super::emitwas run too (32 and 64 host lanes); this PR does not change it.Cases (the shape of your regression, with my own code)
join_leader2/hi{0,1}_scc{0,1}: as above. Nothing reads SCC after.Lt, so thes_cbranch_execzbefore it is a!liveone.join_leader/hi{0,1}_scc{0,1}: the same with ans_cbranch_scc0 .Ldat.Ltand ans_cselect_b32after the join, so SCC is live through every branch (your test'ss_cbranch_scc0attargetalso keeps SCC live at thes_cbranch_execz).On the gfx1036, v11 = 7 in the lanes EXEC holds (0..31 for hi0, all 64 for hi1) and 0 elsewhere. v10 = 42 in the same lanes for all four
join_leader2cases and forjoin_leader/*_scc1;join_leader/*_scc0leave through thes_cbranch_scc0(v10 = 0).Results (values that differ from the gfx1036, out of 64 lanes x 2 outputs)
join_leader2/hi0_scc1join_leader2/hi0_scc0join_leader2/hi1_scc1,hi1_scc0join_leader/*(4 cases, SCC live)hi0_scc1is the case your description names: thes_cbranch_scc1arrives at.Ltwith EXEC_LO = E.hi = 0 after the run's upper copy, the layout-preceding!lives_cbranch_execzleftdirty == false, and thes_cbranch_execnzthen reads the stale EXEC_LO and skips.Lkfor the lower half. With hi1, E.hi is all ones and the stale value happens to be right; with scc0 the path goes through thes_cbranch_execz, which settles EXEC_LO.Verdict: correct. The one case that shows the bug on main is exact with this PR on both cards, and no other case changed: the other 26 wave64 cases give the same values as main in the folded form and in
super::emit(32 and 64 host lanes), and so do the 24 wave32 cases.One remark on your test:
exec_branch_at_join_leader_settles_exec_from_other_predecessorspasses on main without the fix as well (its hunk applied to main alone, run on the 5080: "ran on the hardware device", ok). With thes_cbranch_scc0 doneattarget, SCC is live at thes_cbranch_execzbefore it, so that branch takes the live path and setsdirty = true. Myjoin_leader2/hi0_scc1is the same shape without thats_cbranch_scc0(SCC from av_readfirstlane_b32, so nothing is constant): it fails on main and passes with this PR, so I expect your test to fail on main once that one branch is dropped (not run in that form).Outside this PR:
super::emitwrites v11 = 7 (and v10 = 42 where the branch is taken) into lanes 32..63 for the four hi0 cases, where EXEC's high dword is 0, on both cards and with 64 host lanes, main and this PR alike: with EXEC from twos_mov_b32constants, its upper half follows the low dword.(The upper-half value from EXEC built out of two
s_mov_b32constants looks like what #3402 fixes: "a lane mask written a dword at a time keeps its high dword".)AI use: Claude Code (Claude Opus 5.5) ran the oracle and host cases and wrote this comment.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.