Shaders: use DXIL IsNaN for unordered/ordered and self float compares #154

Closed
github-bot wants to merge 1 commit from gh-pr/154/head into gh-pr/154/base
Owner

@⁠lordon1a on GitHub · 2026-11-24 01:00 UTC · original
fix/fcmp-dxil-isnan → main · +121 −19 · 3 files · 1 commits · closed without merging

Summary

Follow-up to #110 (med3): extends Lower::compare() in crates/victory-shader/src/emit/lower.rs to use DXIL's dx.op.isSpecialFloat.f32 (IsNaN, opcode 8) for float o (ORD), u (UNO), and same-operand NaN-sensitive comparisons (eq, le, ge, neq, nge, nle).

On Intel Iris Xe D3D12 (8086:46a6, driver 32.0.101.7088), the driver's DXIL compiler assumes no NaNs for plain LLVM fcmp, causing all 10 of these cases to return the wrong result on main@9aef3d9:

  • Distinct registers (v1 = NaN, v2 = 1.0): v_cmp_o_f32 returns 1 (want 0), v_cmp_u_f32 returns 0 (want 1).
  • Same register (v1 = NaN, v1 = NaN — standard shader isnan(x) / !isnan(x) idioms): v_cmp_eq_f32, v_cmp_le_f32, v_cmp_ge_f32, v_cmp_o_f32 all return 1 (want 0), and v_cmp_u_f32, v_cmp_nge_f32, v_cmp_nle_f32, v_cmp_neq_f32 all return 0 (want 1).

Because fsrc() may emit two separate bitcast instructions for the same source register (which host CSE then merges into fcmp ... %f, %f), same_src checks both SSA equality and identical source operands/modifiers.

Verification

Tested on Windows 11 (rustc 1.100.0, x86_64-pc-windows-gnullvm, Intel Iris Xe 8086:46a6 driver 32.0.101.7088 + WARP):

  • Negative control (main@9aef3d9 lower.rs with the new test):
    cargo test -p victory-shader v_cmp_f32_nan_matches_rdna2 -> FAILED: hardware: v_cmp_eq_f32(same reg, case 0) = 1, want 0 (and all 9 other cases above fail on hardware while passing on WARP).
  • With this PR:
    • cargo test -p victory-shader v_cmp_f32_nan_matches_rdna2 -> ok on both Intel Iris Xe and WARP.
    • cargo test -p victory-shader -- --skip v_med3_f32_matches_rdna2_with_nan -> 69 passed, 0 failed (skipping only the pre-existing med3 failure fixed in #110).
  • cargo xtask policy: 151 files ok (synthetic GFX10 shader only; zero game data).
  • Zero new compiler warnings.

AI-assisted.

**@⁠lordon1a** on GitHub · 2026-11-24 01:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/154) `fix/fcmp-dxil-isnan` → `main` · +121 −19 · 3 files · 1 commits · closed without merging ## Summary Follow-up to #110 (`med3`): extends `Lower::compare()` in `crates/victory-shader/src/emit/lower.rs` to use DXIL's `dx.op.isSpecialFloat.f32` (`IsNaN`, opcode 8) for float `o` (`ORD`), `u` (`UNO`), and same-operand NaN-sensitive comparisons (`eq`, `le`, `ge`, `neq`, `nge`, `nle`). On Intel Iris Xe D3D12 (`8086:46a6`, driver `32.0.101.7088`), the driver's DXIL compiler assumes no NaNs for plain LLVM `fcmp`, causing all 10 of these cases to return the wrong result on `main@9aef3d9`: - **Distinct registers** (`v1 = NaN, v2 = 1.0`): `v_cmp_o_f32` returns `1` (want `0`), `v_cmp_u_f32` returns `0` (want `1`). - **Same register** (`v1 = NaN, v1 = NaN` — standard shader `isnan(x)` / `!isnan(x)` idioms): `v_cmp_eq_f32`, `v_cmp_le_f32`, `v_cmp_ge_f32`, `v_cmp_o_f32` all return `1` (want `0`), and `v_cmp_u_f32`, `v_cmp_nge_f32`, `v_cmp_nle_f32`, `v_cmp_neq_f32` all return `0` (want `1`). Because `fsrc()` may emit two separate `bitcast` instructions for the same source register (which host CSE then merges into `fcmp ... %f, %f`), `same_src` checks both SSA equality and identical source operands/modifiers. ## Verification Tested on Windows 11 (`rustc 1.100.0`, `x86_64-pc-windows-gnullvm`, Intel Iris Xe `8086:46a6` driver `32.0.101.7088` + WARP): - **Negative control** (`main@9aef3d9` `lower.rs` with the new test): `cargo test -p victory-shader v_cmp_f32_nan_matches_rdna2` -> **FAILED**: `hardware: v_cmp_eq_f32(same reg, case 0) = 1, want 0` (and all 9 other cases above fail on hardware while passing on WARP). - **With this PR**: - `cargo test -p victory-shader v_cmp_f32_nan_matches_rdna2` -> **ok** on both Intel Iris Xe and WARP. - `cargo test -p victory-shader -- --skip v_med3_f32_matches_rdna2_with_nan` -> **69 passed, 0 failed** (skipping only the pre-existing `med3` failure fixed in #110). - `cargo xtask policy`: **151 files ok** (synthetic GFX10 shader only; zero game data). - Zero new compiler warnings. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:52:28 +00:00
github-bot closed this pull request 2026-11-26 03:52:28 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:30 UTC · original

Tested d5fca30 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 56 passed, 0 failed (2 test binaries), including the {adds} test{'s' if adds != 1 else ''} this PR adds.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/154#issuecomment-7119173521) Tested `d5fca30` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **56 passed, 0 failed** (2 test binaries), including the {adds} test{'s' if adds != 1 else ''} this PR adds. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used.
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 05:15 UTC · original

Ran d5fca30 merged onto main d2a4bae (clean; the branch was 2 commits behind) on NVIDIA. valu_tests runs each case on the hardware device and on WARP.

  • NVIDIA GeForce RTX 5070 12 GB (32-lane waves), driver 621.24; Windows 11 Pro 26300; Rust 1.98.1 (pinned) x86_64-pc-windows-msvc, debug
  • v_cmp_f32_nan_matches_rdna2: ok on both
  • cargo test -p victory-shader --lib -- --test-threads=1: 70 passed, 0 failed
  • cargo test --workspace -- --test-threads=1: 265 passed, 0 failed, 4 ignored
**@⁠marquezinii** on GitHub · 2026-11-24 05:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/154#issuecomment-7122782976) Ran `d5fca30` merged onto `main` `d2a4bae` (clean; the branch was 2 commits behind) on NVIDIA. `valu_tests` runs each case on the hardware device and on WARP. - NVIDIA GeForce RTX 5070 12 GB (32-lane waves), driver 621.24; Windows 11 Pro 26300; Rust 1.98.1 (pinned) `x86_64-pc-windows-msvc`, debug - `v_cmp_f32_nan_matches_rdna2`: ok on both - `cargo test -p victory-shader --lib -- --test-threads=1`: 70 passed, 0 failed - `cargo test --workspace -- --test-threads=1`: 265 passed, 0 failed, 4 ignored

Pull request closed

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!154
No description provided.