Repository navigation
Shaders: v_cmp_lg is ordered on AMD hosts too (olt | ogt, not fcmp one) - #706
Conversation
v_cmp_lg_{f32,f16} ("less or greater") is ordered and not equal: false
when either operand is a NaN, on RDNA2 hardware as in the ISA. It was
lowered to `fcmp one`, which says the same, but the AMD D3D12 driver runs
`fcmp one` as unordered and returns true for a NaN. NVIDIA and WARP get it
right. It now lowers as `olt | ogt`, which all three run alike.
New GPU test v_cmp_lg_is_false_for_nan covers both widths: NaN on either
side, both NaN, a signalling NaN, +0 against -0, inf against inf and
against -inf, and junk in the unread high halves for f16.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4) and the Ryzen 9600X iGPU (RDNA2, gfx1036), each picked as the D3D12 device for
|
LAKSHYA-cmd-tech
left a comment
There was a problem hiding this comment.
Verified on Windows 11 MSVC (Rust 1.98.1). \�_cmp_lg_is_false_for_nan\ passes cleanly across all f32 and f16 test vectors (signalling NaN, quiet NaN, infinities, signed zeroes, high-half masks). Lowering \�_cmp_lg\ as \olt | ogt\ avoids the AMD D3D12 driver bug where \cmp one\ was treated as unordered (\UNE). Excellent fix.
catminou4
left a comment
There was a problem hiding this comment.
cargo test -p victory-shader --locked on macOS 26 arm64, rustc 1.98.1: merges cleanly with current main (7374bfb), 64 passed / 0 failed / 1 ignored — same as main's baseline (the new valu_tests coverage is #[cfg(all(test, windows))], needs the Windows host backend). The bitcode/lower changes compile and don't regress anything here. Approving; the AMD ordering behavior itself needs the Windows shader run.
|
I ran On the merged commit - lowers(&words).unwrap();
+ lowers(&words, 0).unwrap();With this one-line test change, both |
v_cmp_lg_{f32,f16} ("less or greater") is ordered and not equal: false
when either operand is a NaN, on RDNA2 hardware as in the ISA. It was
lowered to `fcmp one`, which says the same, but the AMD D3D12 driver runs
`fcmp one` as unordered and returns true for a NaN. NVIDIA and WARP get it
right. It now lowers as `olt | ogt`, which all three run alike.
New GPU test v_cmp_lg_is_false_for_nan covers both widths: NaN on either
side, both NaN, a signalling NaN, +0 against -0, inf against inf and
against -inf, and junk in the unread high halves for f16.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 51f1627, upstream Marvisak#706)
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Shaders: v_cmp_lg is ordered on AMD hosts too (olt | ogt, not fcmp one)
Shaders: v_cmp_lg is ordered on AMD hosts too (olt | ogt, not fcmp one)
What
v_cmp_lg_f32/v_cmp_lg_f16("less or greater") are ordered not-equal compares. They are false when either operand is a NaN, on RDNA2 hardware as in the ISA.comparelowered them tofcmp one, which means the same thing in LLVM. The AMD D3D12 driver runsfcmp oneas unordered and returns true for a NaN. NVIDIA and WARP run it correctly. So on AMD hosts everyv_cmp_lgwith a NaN operand took the wrong side.lgnow lowers asfcmp olt | fcmp ogt, which gives the same answer on all three.pred::ONEis no longer emitted. It stays in the table with a note saying why.How it was found and measured
A differential check of the translator against RDNA2 hardware: the same raw VOP3 words run on a gfx1036 (RDNA2) iGPU through a HIP kernel, and through
build_valu_cson a D3D12 host, 240 inputs per opcode. Out of 70 VOPC compares,v_cmp_lg_f32andv_cmp_lg_f16were the only ones whose results differ on an AMD host: 40 and 33 of 240, all NaN rows. With the same DXIL on other hosts:mainv_cmp_lg_f32(0x7fc00000, 0x3f800000) = 1, want 0The AMD row needs #94's
VICTORY_ADAPTER=amdto put the test on the iGPU. I merged #94 locally for that run only; it is not part of this PR.olt,ogt,ord,une,ueqand the other float predicates matched the hardware on the AMD host in the same check, so onlyoneis affected.Test
v_cmp_lg_is_false_for_naninvalu_tests.rsbuildsv_cmp_lg_{f32,f16}_e64 s20, v1, v2+v_cndmask_b32_e64 v0, 0, 1, s20from hand-written words and runs it on the hardware device and WARP. It covers ordered pairs both ways, equal values,+0against-0,infagainstinfand-inf, NaN on either side and on both, a signalling NaN, and for f16, junk in the unread high halves. The expected values are the ISA's, and the same on the gfx1036 hardware.cargo test --workspace -j 4(Windows 11, RTX 5080 as the default adapter): 265 passed, 0 failed, 4 ignored (264 onmainplus the new test).cargo clippy -p victory-shader --all-targets: no warnings.rustfmt --edition 2024 --checkon the three files: clean.cargo xtask policy: 151 files ok.No game files were used.
AI use: Claude Code (Claude Opus 5.5) found this with the differential check, wrote the change and the test, and ran everything above. I reviewed the diff and the results.
🤖 Generated with Claude Code