Shaders: track SGPR origins across cancelling s_xor_b32/b64 swaps (#815) #2385
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2387"
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 Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T12:29:34Z.
Summary
Resolves cancelling
s_xor_b32ands_xor_b64chains inTracer::propagate_copies(crates/victory-shader/src/resource.rs) so temporary-free three-XOR SGPR exchanges (a ^= b; b ^= a; a ^= b, including swaps throughvcc_lo/vcc_hiand 64-bit SGPR pairs) preserve root-parameter and descriptor origins across loops and control-flow joins.In the native compute corpus measurements reported in #815 (and #1481 Class C), register permutations emitted via three-XOR exchanges caused root pointers and descriptor words to lose their SSA origin and fail with
"an address not from a root parameter"(418 -> 339 -> 64when includingvcc_lo/vcc_hi) or"an address from a phi"(193 -> 24).Details
x ^ x == 0,x ^ 0 == x):Tracer::xor_cancelledcollects XOR operands with bounded expansion (MAX_XOR_STEPS = 32, expanding the latests_xor_b32/s_xor_b64definition in(rpo[block], inst_index)order so local swaps cancel cleanly without oscillating across loop phis).Values and folds constant terms (NULL, 32-bit inline/literal constants, and sign-extended 64-bit inline integers128..=208):Values ->Some(Moved::Const(const_acc))Valueandconst_acc == 0->Some(Moved::Value(v))None(any non-cancelling XOR remains opaque).Verification
resource::tests::three_xor_swap_tracks_32bit_64bit_and_vcc_exchanges&three_xor_swap_preserves_phi_origins_and_non_cancelling_xor_stays_opaque: cover 32-bit SGPR swaps, 64-bit SGPR pair swaps,vcc_lo(code = 106) swaps, join/loop phi convergence, and negative non-cancelling/mutated-descriptor checks.emit::valu_tests::three_xor_swap_tracks_table_through_vcc_and_64bit_pair: validates DXIL withdxil.dlland executes on both hardware GPU andWARP.cargo clippy -p victory-shader --lib --tests --all-features --locked -- -D warnings&cargo xtask policypass.Refs #815, #1481
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T12:41:45Z.
Review: APPROVED
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 146 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — SGPR origins tracked across cancelling s_xor_b32/b64 swaps, +1 test.Imported from Marvisak/VIctory. Originally posted by welisonzika14-jpg on 2026-11-25T13:08:10Z.
First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head
87317bemerged ontomain940d32f,cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast.The PR's new test(s) pass on this card:
emit::valu_tests::three_xor_swap_tracks_table_through_vcc_and_64bit_pair,resource::tests::three_xor_swap_tracks_32bit_64bit_and_vcc_exchanges,resource::tests::three_xor_swap_preserves_phi_origins_and_non_cancelling_xor_stays_opaque. The rest is the same asmainon this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests invictory-gpu, 3 invictory-shader), nothing new.One run, unit tests only, title not run.
Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T14:59:03Z.
Automated triage for the maintainers.
Merge candidate.
Tracer::xor_cancelled(crates/victory-shader/src/resource.rs) lets copy propagation see through three-XOR register exchanges (a ^= b; b ^= a; a ^= b, also viavcc_loand 64-bit pairs). It expandss_xor_b32/s_xor_b64definitions, at most 32 steps, cancels equal SSA values pairwise and folds constants. It yields an origin only when exactly one value (with zero constant) or only a constant remains, else nothing. Cancelling identical SSA values is exact, so this cannot invent an origin. Phis are not expanded. The 64-bit inline integers are sign-extended per half, and wide literals and float inline constants are refused. Tests cover 32/64-bit and VCC swaps, phi joins and non-cancelling XORs staying opaque, plus a GPU run on hardware and WARP.CI:
checkpassing. A contributor reports the new tests passing on an RTX 5070.Generated by Claude Code
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.