Shaders: 64-bit integer compares on their dwords (AMD orders a shared-dword i64 compare wrong) #1599
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!1599
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1599/head"
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-24 19:41 UTC · original
alexdeliu:fix/amd-i64-compare→main· +132 −14 · 2 files · 4 commits · merged 2026-11-25 21:51 UTCv_cmp_{lt,le,gt,ge}_{i64,u64}are lowered to oneicmpon ani64built from the two dwords. AMD's D3D12 driver gets that wrong when the two operands share a dword.Minimal case:
v_cmp_lt_i64 s20, v[1:2], v[2:3]with v1 = v2 = 0, v3 = 1, i.e.0 < 0x1_00000000.The wrong answers look as if the dwords were swapped. Disjoint register pairs give the right result, and so do
eqandne.Change
i64); when they are equal, the low dwords decide (unsigned).eq/necompare both dwords.INT64.src64_dwordsreads operands assrc64does: register pairs, inline constants sign-extended, literals and null zero-extended.Test
v_cmp_u64_and_i64_order_by_the_high_dword(GPU, hardware + WARP):v[1:2],v[3:4]) and on shared ones (v[1:2],v[2:3]);Without the lowering change, the test fails on the RX 9070:
hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000). With it, it passes on both AMD GPUs and on WARP.Checks
On Windows 11 with the RX 9070, both CI clippy runs are clean and
cargo test --workspace --lockedpasses (343).How it was found
A cross-device fuzzer ran every lowered VOP3 opcode as a one-thread compute shader on each adapter and on WARP, on the same special and random inputs, and compared the results. These compares were the only integer opcodes where the devices disagreed. The fuzzer is coming as a separate PR.
🤖 Generated with Claude Code
v_cmp_{lt,le,gt,ge}_{i64,u64} lowered to one i64 icmp give the wrong answer on AMD's D3D12 driver when the operands share a dword: `v_cmp_lt_i64 s20, v[1:2], v[2:3]` with v1 = v2 = 0, v3 = 1 (0 < 0x1_00000000) is false on an RX 9070 (32.0.32029.2010) and on a Ryzen 7700 iGPU, gfx1036 (32.0.21045.29003), as if the dwords were swapped; WARP gets it right. Disjoint pairs are fine there, and so is equality. The compare now runs on the dwords: the high ones decide (signed for i64), equal ones leave it to the low ones (unsigned). It needs no INT64. The GPU test runs all twelve compares over values whose dword orders disagree, on disjoint and on shared registers; without the change it fails on the AMD hardware. Found by a cross-device fuzzer that compares single VALU instructions on every adapter and WARP. Co-Authored-By: Claude Opus 5.5 <[email protected]>@DrDarkDK on GitHub · 2026-11-24 20:26 UTC · original
I tested #1599 (
faccfbc) on native Windows using the unchanged fuzzer from #1614 (a01156e). I ran the eight ordered i64/u64 compare opcodes with 32 identical seeded inputs per opcode on both builds. The adapters were an RTX 4070 Ti (621.01), a Ryzen 9 7900X Radeon iGPU (32.0.11024.2), and WARP.ffe310e, 131 of 256 cases disagreed across adapters. In all 64 mismatch rows printed by the harness, the RTX 4070 Ti and WARP agreed and the Radeon iGPU differed.This was a targeted synthetic comparison covering the eight ordered opcodes.
AI-assisted with Codex.
@alexdeliu on GitHub · 2026-11-24 20:33 UTC · original
@DrDarkDK thank you for the independent run. It adds an NVIDIA adapter (RTX 4070 Ti agreeing with WARP) and a third AMD device: your 7900X iGPU, after my RX 9070 and gfx1036. That pins the bug on AMD's D3D12 compiler rather than on the translation.
@tumbubu on GitHub · 2026-11-24 21:51 UTC · original
First RDNA3 device: the bug reproduces on an RX 7900 XT, and
faccfbcfixes it there.On top of the RX 9070, gfx1036 and the 7900X iGPU, this adds a discrete RDNA3 card on a newer driver.
dxil.dllfrom SDK 10.0.26100, so every module was validatedv_cmp_u64_and_i64_order_by_the_high_dword, lowering left atffe310ehardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000)faccfbc,cargo test -p victory-shader --locked -- --test-threads=1main: 120). The new test passes on the 7900 XT and on WARP.mainv_cmp_{lt,le,gt,ge}_{i64,u64}differ from WARP, on 57 to 110 of 160 inputs;eq/neagreeSo it is the same bug on RDNA2, RDNA3 and RDNA4. AI-assisted (Claude Code); every run was on this machine.
@alexdeliu on GitHub · 2026-11-24 21:56 UTC · original
@tumbubu thank you, that's the RDNA3 data point that was missing. With your RX 7900 XT, the bug now reproduces on RDNA2 (gfx1036), RDNA3 (7900 XT) and RDNA4 (RX 9070), plus a 7900X iGPU. NVIDIA and WARP agree with the reference, and this PR fixes it on all of them.
It also still applies on the new
main(70564ae): I merged it in (1f6b392). There the test still fails on the RX 9070 without the change and passes with it. Clippy ×2 is clean, and the workspace passes apart from the two PSV0 tests that fail onmainitself with the SDK's 1.7 validator (see #1744).@Marvisak on GitHub · 2026-11-25 03:31 UTC · original · edited 2026-11-25 07:20 UTC
Automated triage for the maintainers.
Merge candidate. This lowers the
v_cmp_*_{i64,u64}compares on the two dwords, which avoids AMD's misordering of a 64-biticmp. The high dwords decide (signed for i64); when they are equal, the low dwords decide, unsigned.eq/necompare both dwords. Update after the new head (e60eb70):src64_dwordsnow sign-extends an_i64instruction's 32-bit literal into the high dword, exactly assrc64onmaindoes. Register pairs, sign-extended inline constants, zero-extended other literals and null are also read the same way. The predicates are right for all eight ordered cases, and the test computes its expected values in Rust. The failure is reproduced on several AMD generations in this thread, and WARP agrees with the fix. It merges cleanly withmain, and CI passes.Generated by Claude Code
@alexdeliu on GitHub · 2026-11-25 05:00 UTC · original
Merged
main(940d32f) in. Its newsigned_64_bit_operands_sign_extend_their_literalcaught a real gap in this PR: the dword split read an_i64literal's high dword as zero, wheresrc64now sign-extends it.e60eb70makessrc64_dwordstake the same high dword assrc64. On the RX 9070 + gfx1036 machine: both CI clippy runs are clean, andcargo test --workspace --lockedpasses, including that test and this PR's shared-dword compare test. The only failures are the 2 PSV0 testsmainitself fails with the SDK'sdxil.dll1.7.@alexdeliu on GitHub · 2026-11-25 06:31 UTC · original
A standalone repro of the bug this PR fixes, outside VIctory: https://github.com/alexdeliu/rdna2-conformance runs VIctory's own DXIL for
v_cmp_{lt,gt}_{i64,u64}andv_cmp_eq_i64onv[1:2]vsv[2:3](lowered as onmainwithout this fix) on every D3D12 adapter (cargo run --release, no game files).Anyone with an NVIDIA/Intel/RDNA3 card can add a column. Reports go in the repo's
results/.