Shaders: 64-bit integer compares on their dwords (AMD orders a shared-dword i64 compare wrong) #81
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/Belobug--VIctory-Belobug-AMD!81
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-81"
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?
@alexdeliu on GitHub · 2026-11-25 13:35 UTC · original
alexdeliu:fix/amd-i64-compare→main· +128 −14 · 2 files · 1 commits · openWhat
64-bit integer compares (
v_cmp_{lt,le,gt,ge}_{i64,u64}) are lowered on the two dwords instead of as one i64icmp.Why
AMD's D3D12 shader compiler orders an i64 compare wrongly when the two operands share a dword (for example
v[1:2]againstv[2:3]): it behaves as if each operand's dwords were swapped. Equality is not affected. WARP compares correctly.Upstream this is Marvisak/VIctory#1599. It was reproduced there on RDNA2, RDNA3 (RX 7900 XT) and RDNA4, and there is a standalone DXIL repro in rdna2-conformance. This fork is at upstream
8e79c80and does not have the fix.The lowering compares the high dwords (signed for i64). When those are equal, it compares the low dwords unsigned. Literals and inline constants keep the extension this fork's
raw_src64gives them.Tested
The new GPU test
v_cmp_u64_and_i64_order_by_the_high_dwordcovers 12 ops × 100 operand pairs × {separate, shared} registers. The values are picked so that the two dword orders disagree.71652a2v_cmp_lt_i64(0x0, 0x1_0000_0000)VICTORY_ADAPTER=radeon(tm)cargo test -p victory-shader --lib(VICTORY_DXIL= dxil.dll 1.8.2502.11):71652a2--test-threads=1The 2 gfx1036 failures are #2's wave-size tests, with the same output as on the RX 6950 XT there; this change does not touch them. One parallel run on each GPU ended once with
0xc0000005mid-suite, without and with this PR; reruns were clean.No game data was used; this is a unit-level change.
AI use: Claude Code (Claude Opus 5.5) ported the change and ran the tests on my machine.
🤖 Generated with Claude Code
@enriquebruno12 on GitHub · 2026-11-25 14:43 UTC · original
Confirmed on an RX 9070 XT with Windows driver 32.0.32029.2010. With only the new test applied, v_cmp_lt_i64(0, 0x100000000) returned 0 on hardware instead of 1. After applying the lowering change, the same test passed. No game files were used.
@ySKELLETONX on GitHub · 2026-11-25 16:35 UTC · original
Tested on an RX 7600 XT 16 GB (RDNA3, Navi 33), driver 32.0.32015.2008, Windows 11 Pro build 26300, Rust 1.98.1, at
7c8dc5b:cargo test -p victory-shader --lib --locked: 267 passed, 0 failed, 6 ignored, hardware dispatch tests included (mainat01aadd1: 266 passed). Workspace tests only; not run in the title.@adrianmjim on GitHub · 2026-11-25 17:23 UTC · original
A second RDNA3 card, adding the run without the fix to ySKELLETONX's RX 7600 XT result above. RX 7900 XT (driver 32.0.32029.2010), Windows 11 build 26300, Rust 1.98.1, head
7c8dc5bon01aadd1, each tree with its own target dir:valu_tests.rsapplied to01aadd1):v_cmp_u64_and_i64_order_by_the_high_dwordfails 3 of 3 runs, on the same case as on the RX 9070:hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000).cargo test -p victory-shader --lib -- --test-threads=1gives 267 passed, 0 failed, 6 ignored.I also translated the whole of
shaders.rpf(26,084 programs) withvictory translate --validate --host-lanes 32-64, on01aadd1and with this PR, and compared a hash of each program's DXIL. The output is deterministic: two runs of01aadd1give the same hashes. With this PR, 233 programs change (217 pixel, 16 compute) and all the others are byte for byte the same. Every changed program still emits and passes the DXIL validator, and the totals don't change: VS/PS 14,247/14,247, CS 2,682/2,682, MS 8,694/8,765 (the 71 mesh programs refused onmainfor outputs beyond 32 KiB are refused here too). No game data is in this comment: names and counts only. Not run in the game.@MamaLeVrai on GitHub · 2026-11-26 00:18 UTC · original
RDNA2 result. Hardware: RX 6950 XT, Windows 11 build 26300, Rust 1.98.1. This PR (
7c8dc5b) merged onmain4f62c2a. Command:cargo test --release -p victory-shader --lib, two runs.main: 275 passed, 2 failed.The 2 failures are the same on
main:scalar_counted_in_a_divergent_loop_read_after_itandscalar_counted_in_nested_divergent_loops, the RDNA2 wave-size tests that #110 and #204 fix. So nothing regresses on this card. Not run in the game.harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300
AI-assisted (Claude Code); no game data.
@lcg007xd-c on GitHub · 2026-11-25 21:28 UTC · original · reviewed
Verified on Linux (Rust 1.98.1)
cargo test -p victory-shader --libwith7c8dc5bmerged into current main (--no-commit): 196 passed, 0 failed, 6 ignored. The new test is invalu_tests(Windows + D3D12), so it does not run here. Others in this thread have already shown fail-without-fix on RDNA3 and RDNA4.cargo clippy -p victory-shader --target x86_64-pc-windows-msvc --lib --tests: the same 10 warnings as main and none new. This also type-checks the new test.git merge --no-commit --no-ffinto main: merges cleanly.llvm-mc --disassemble -triple=amdgcn -mcpu=gfx1030: the test's VOP3 opcodes0x0a1..0x0a6/0x0e1..0x0e6decode asv_cmp_{lt,eq,le,gt,ne,ge}_{i64,u64}_e64 s20, v[1:2], v[2:3], the shared-dword form the test is after.(hi_p, lo_p)table inlower.rs:10080-10088with a small Python model: "high dwords decide (signed for i64), equal high dwords fall back to an unsigned low compare". Over all 8 ordered ops × 196 operand pairs (the test's values plus0x8000_0000,0x7FFF_FFFF,i64::MINand-1), it matches a native 64-bit compare with 0 mismatches.Finding: the second copy of the 64-bit operand rules will miss #188
src64_dwords(lower.rs:8592-8620) copiesraw_src64's operand rules (lower.rs:8416-8456): pairs, inline constants sign-extended, and literals plus the null register zero-extended. Today the two agree. But #188 (open) fixesraw_src64so that a literal in a signed_i64operand sign-extends, and its new test exercises exactlyv_cmp_eq_i64/v_cmp_lt_i64 v[1:2], -100.I merged #188 into main and then this PR on top. The merge is textually clean, but #188's new arm is in
raw_src64only (lower.rs:8455in that tree). The i64 compares now go throughsrc64_dwords, whose_ =>arm still returns(x, 0). Whichever of the two lands second will silently undo the other's fix for compares. #188'ssigned_64_bit_operands_sign_extend_their_literalshould then fail on hardware forv_cmp_lt_i64(-200, -100). I reasoned this from the code; I could not run it.Suggestion: keep only one source of the extension rules. For example, handle only the register-pair arms in
src64_dwordsand send every other operand throughraw_src64+split64:This keeps the compare itself off the i64
icmp, which is the point of the fix. It does setflags::INT64for constant operands, as main does today. Alternatively, add #188's_i64literal arm here too, and leave a comment in both places saying they must stay in sync.Minor: there's a double blank line after
src64_dwords(lower.rs:8621-8622).Not verified
Reviewed with Claude Code.
@gut0to on GitHub · 2026-11-26 16:08 UTC · original · reviewed
AI-assisted review. I compared the new operand-lowering branches with the added test coverage; I did not run tests or a game.
@ -8589,0 +8607,4 @@Operand::Scalar { code, .. } if code != NULL => {pair(self, Reg::S(code), Reg::S(code + 1))}Operand::Const(k @ 128..=208) => {@gut0to on GitHub · 2026-11-26 16:08 UTC · original
AI-assisted static review: I checked the new
src64_dwordsmatch against the added compare test; I did not run tests or a game. The test operands are VGPR pairs, so it does not exercise these newly added immediate paths. Could you add cases for a negative inline constant (sign-extended high dword) and a literal orNULLoperand (zero-extended high dword)? A regression in either arm would otherwise leave the hardware comparison suite green.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.