Shaders: v_cmp_lg is ordered on AMD hosts too (olt | ogt, not fcmp one) #706

Manually merged
github merged 1 commit from gh-pr/706/head into gh-pr/706/base 2026-11-26 04:13:43 +00:00
Owner

@⁠Lyrnc on GitHub · 2026-11-24 07:09 UTC · original
Lyrnc:fix/cmp-lg-ordered → main · +84 −20 · 3 files · 1 commits · merged 2026-11-24 08:24 UTC

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. compare lowered them to fcmp one, which means the same thing in LLVM. The AMD D3D12 driver runs fcmp one as unordered and returns true for a NaN. NVIDIA and WARP run it correctly. So on AMD hosts every v_cmp_lg with a NaN operand took the wrong side.

lg now lowers as fcmp olt | fcmp ogt, which gives the same answer on all three. pred::ONE is 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_cs on a D3D12 host, 240 inputs per opcode. Out of 70 VOPC compares, v_cmp_lg_f32 and v_cmp_lg_f16 were 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:

Host main this PR
AMD Radeon iGPU (gfx1036), driver 32.0.21042.62 fails: v_cmp_lg_f32(0x7fc00000, 0x3f800000) = 1, want 0 passes
NVIDIA RTX 5080, driver 610.88 passes passes
WARP passes passes

The AMD row needs #94's VICTORY_ADAPTER=amd to 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, ueq and the other float predicates matched the hardware on the AMD host in the same check, so only one is affected.

Test

v_cmp_lg_is_false_for_nan in valu_tests.rs builds v_cmp_lg_{f32,f16}_e64 s20, v1, v2 + v_cndmask_b32_e64 v0, 0, 1, s20 from hand-written words and runs it on the hardware device and WARP. It covers ordered pairs both ways, equal values, +0 against -0, inf against inf and -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 on main plus the new test).
  • cargo clippy -p victory-shader --all-targets: no warnings. rustfmt --edition 2024 --check on 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

**@⁠Lyrnc** on GitHub · 2026-11-24 07:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/706) `Lyrnc:fix/cmp-lg-ordered` → `main` · +84 −20 · 3 files · 1 commits · merged 2026-11-24 08:24 UTC ## 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. `compare` lowered them to `fcmp one`, which means the same thing in LLVM. The **AMD D3D12 driver runs `fcmp one` as unordered** and returns true for a NaN. NVIDIA and WARP run it correctly. So on AMD hosts every `v_cmp_lg` with a NaN operand took the wrong side. `lg` now lowers as `fcmp olt | fcmp ogt`, which gives the same answer on all three. `pred::ONE` is 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_cs` on a D3D12 host, 240 inputs per opcode. Out of 70 VOPC compares, `v_cmp_lg_f32` and `v_cmp_lg_f16` were 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: | Host | `main` | this PR | |---|---|---| | AMD Radeon iGPU (gfx1036), driver 32.0.21042.62 | **fails**: `v_cmp_lg_f32(0x7fc00000, 0x3f800000) = 1, want 0` | passes | | NVIDIA RTX 5080, driver 610.88 | passes | passes | | WARP | passes | passes | The AMD row needs #94's `VICTORY_ADAPTER=amd` to 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`, `ueq` and the other float predicates matched the hardware on the AMD host in the same check, so only `one` is affected. ## Test `v_cmp_lg_is_false_for_nan` in `valu_tests.rs` builds `v_cmp_lg_{f32,f16}_e64 s20, v1, v2` + `v_cndmask_b32_e64 v0, 0, 1, s20` from hand-written words and runs it on the hardware device and WARP. It covers ordered pairs both ways, equal values, `+0` against `-0`, `inf` against `inf` and `-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 on `main` plus the new test). - `cargo clippy -p victory-shader --all-targets`: no warnings. `rustfmt --edition 2024 --check` on 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](https://claude.com/claude-code)
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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:41 +00:00
github manually merged commit 51f1627d88 into gh-pr/706/base 2026-11-26 04:13:43 +00:00
Author
Owner

@⁠slint6614-dev on GitHub · 2026-11-24 07:35 UTC · original

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).

  • Whole victory-shader suite: 70 passed, 0 failed on both GPUs.
  • Negative control: with this PR's lower.rs/bitcode.rs reverted to main and only the new test kept, v_cmp_lg_is_false_for_nan fails on both AMD GPUs (left: 1, right: 0). So main's fcmp one lowering really returns true for NaN on AMD hardware, and this PR fixes it there.
**@⁠slint6614-dev** on GitHub · 2026-11-24 07:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/706#issuecomment-7125148300) 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). - Whole `victory-shader` suite: 70 passed, 0 failed on both GPUs. - Negative control: with this PR's `lower.rs`/`bitcode.rs` reverted to main and only the new test kept, `v_cmp_lg_is_false_for_nan` fails on both AMD GPUs (`left: 1, right: 0`). So main's `fcmp one` lowering really returns true for NaN on AMD hardware, and this PR fixes it there.
Author
Owner

@⁠sambagarandawertanda on GitHub · 2026-11-24 08:47 UTC · original

I ran v_cmp_lg_is_false_for_nan on the original PR head 51f1627 with 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 with E0061 in scalar_bit_tests_lower. The same call is already present on the merge's first parent, a51bdfa. The old helper used rsrc2 = 0, so I restored that value at the call site.

-            lowers(&words).unwrap();
+            lowers(&words, 0).unwrap();

With this one-line test change, both v_cmp_lg_is_false_for_nan and scalar_bit_tests_lower passed on 58fed370. The former again exercised all 40 comparisons across both backends. Tests used synthetic inputs. AI assistance with Codex.

**@⁠sambagarandawertanda** on GitHub · 2026-11-24 08:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/706#issuecomment-7126561005) I ran `v_cmp_lg_is_false_for_nan` on the original PR head `51f1627` with 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 with `E0061` in `scalar_bit_tests_lower`. The same call is already present on the merge's first parent, `a51bdfa`. The old helper used `rsrc2 = 0`, so I restored that value at the call site. ```diff - lowers(&words).unwrap(); + lowers(&words, 0).unwrap(); ``` With this one-line test change, both `v_cmp_lg_is_false_for_nan` and `scalar_bit_tests_lower` passed on `58fed370`. The former again exercised all 40 comparisons across both backends. Tests used synthetic inputs. AI assistance with Codex.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!706
No description provided.