Shaders: track SGPR origins across cancelling s_xor_b32/b64 swaps (#815) #2387
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!2387
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@fuzeofficlal on GitHub · 2026-11-25 12:29 UTC · original
fuzeofficlal:fix/shader-xor-register-exchanges-815→main· +370 −0 · 2 files · 1 commits · openSummary
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
@welisonzika14-jpg on GitHub · 2026-11-25 13:08 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 14:59 UTC · original
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.