Shaders: v_cmp_lg is ordered on AMD hosts too (olt | ogt, not fcmp one) #706
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/706"
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 Lyrnc on 2026-11-24T07:09:04Z.
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
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T07:40:59Z.
Review: APPROVED
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.
Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T07:35:02Z.
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4) and the Ryzen 9600X iGPU (RDNA2, gfx1036), each picked as the D3D12 device for
cargo test -p victory-shader --release(local adapter-selection patch, not part of this PR).victory-shadersuite: 70 passed, 0 failed on both GPUs.lower.rs/bitcode.rsreverted to main and only the new test kept,v_cmp_lg_is_false_for_nanfails on both AMD GPUs (left: 1, right: 0). So main'sfcmp onelowering really returns true for NaN on AMD hardware, and this PR fixes it there.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T08:04:01Z.
Review: APPROVED
cargo test -p victory-shader --lockedon 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.upstream-sync referenced this pull request2026-11-24 09:06:05 +00:00
Imported from Marvisak/VIctory. Originally posted by sambagarandawertanda on 2026-11-24T08:47:11Z.
I ran
v_cmp_lg_is_false_for_nanon the original PR head51f1627with an RTX 3080 (driver 621.14) and WARP. All 20 input cases passed on each backend. This used Windows 11 and Rust 1.98.1 MSVC.On the merged commit
58fed370, the shader tests fail to compile withE0061inscalar_bit_tests_lower. The same call is already present on the merge's first parent,a51bdfa. The old helper usedrsrc2 = 0, so I restored that value at the call site.With this one-line test change, both
v_cmp_lg_is_false_for_nanandscalar_bit_tests_lowerpassed on58fed370. The former again exercised all 40 comparisons across both backends. Tests used synthetic inputs. AI assistance with Codex.