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

Closed
lordon1a wants to merge 1 commit from upstream-pr/154 into main
lordon1a commented 2026-11-24 01:00:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T01:00:38Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572174589 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/154). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T01:00:38Z. --- ## 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.
copilot-pull-request-reviewer[bot] commented 2026-11-24 01:00:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T01:00:49Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:Marvisak/VIctory:review:6032016433 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/154#pullrequestreview-6032016433). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-24T01:00:49Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
DaviTostes commented 2026-11-24 06:54:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:30:52Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119173521 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/154#issuecomment-7119173521). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:30:52Z. --- 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.
marquezinii commented 2026-11-24 06:55:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T05:15:54Z.


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
<!-- greyfinch-sync:Marvisak/VIctory:comment:7122782976 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/154#issuecomment-7122782976). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T05:15:54Z. --- 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
upstream-sync closed this pull request 2026-11-24 19:01:54 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!154
No description provided.