Shaders: use DXIL IsNaN in med3 so Intel Xe does not fold fcmp uno #110

Closed
github-bot wants to merge 3 commits from gh-pr/110/head into gh-pr/110/base
Owner

@⁠lordon1a on GitHub · 2026-11-24 00:36 UTC · original
fix/med3-dxil-isnan → main · +75 −6 · 2 files · 3 commits · closed without merging

Summary

Replaces fcmp uno in Lower::med3() (crates/victory-shader/src/emit/lower.rs) with DXIL's explicit dx.op.isSpecialFloat.f32 (IsNaN, opcode 8).

On Intel Iris Xe D3D12 (8086:46a6, driver 32.0.101.7088), the shader compiler folds fcmp uno third, third to false under default shader fast-math, causing v_med3_f32(1.0, 2.0, NaN) to return median (2.0, 0x40000000) instead of least (1.0, 0x3f800000) as RDNA2 specifies. Discovered while running #37's synthetic GPU VALU tests on Intel Iris Xe.

Using dx.op.isSpecialFloat.f32(8, x) preserves NaN detection across Intel Xe and NVIDIA drivers without conflicting with #37's fract() hunks.

Verification

Tested on Windows 11 (rustc 1.100.0, x86_64-pc-windows-gnullvm):

  • Negative control (main@35b054ec0 lower.rs on Intel Iris Xe 8086:46a6, driver 32.0.101.7088):
    cargo test -p victory-shader med3_uses_dxil_isnan_for_nan_operands -> FAILED: v_med3_f32(1.0, 2.0, NaN) got 0x40000000, want 1.
  • With this PR on Intel Iris Xe:
    cargo test -p victory-shader -> 58 passed, 0 failed (including med3_uses_dxil_isnan_for_nan_operands).
  • Stacked with #37's full valu_tests:
    • Intel Iris Xe (8086:46a6): 7/7 passed (previously 6/7)
    • NVIDIA GeForce RTX 3070 Ti Laptop GPU (10de:24e0, driver 616.64): 7/7 passed
  • cargo xtask policy: 150 files ok (synthetic GFX10 shader only; zero game data).
  • cargo clippy -p victory-shader --all-targets: 0 new warnings.

AI-assisted.

**@⁠lordon1a** on GitHub · 2026-11-24 00:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/110) `fix/med3-dxil-isnan` → `main` · +75 −6 · 2 files · 3 commits · closed without merging ## Summary Replaces `fcmp uno` in `Lower::med3()` (`crates/victory-shader/src/emit/lower.rs`) with DXIL's explicit `dx.op.isSpecialFloat.f32` (`IsNaN`, opcode 8). On Intel Iris Xe D3D12 (`8086:46a6`, driver `32.0.101.7088`), the shader compiler folds `fcmp uno third, third` to `false` under default shader fast-math, causing `v_med3_f32(1.0, 2.0, NaN)` to return `median` (`2.0`, `0x40000000`) instead of `least` (`1.0`, `0x3f800000`) as RDNA2 specifies. Discovered while running #37's synthetic GPU VALU tests on Intel Iris Xe. Using `dx.op.isSpecialFloat.f32(8, x)` preserves NaN detection across Intel Xe and NVIDIA drivers without conflicting with #37's `fract()` hunks. ## Verification Tested on Windows 11 (`rustc 1.100.0`, `x86_64-pc-windows-gnullvm`): - **Negative control** (`main@35b054ec0` `lower.rs` on Intel Iris Xe `8086:46a6`, driver `32.0.101.7088`): `cargo test -p victory-shader med3_uses_dxil_isnan_for_nan_operands` -> **FAILED**: `v_med3_f32(1.0, 2.0, NaN) got 0x40000000, want 1`. - **With this PR on Intel Iris Xe**: `cargo test -p victory-shader` -> **58 passed, 0 failed** (including `med3_uses_dxil_isnan_for_nan_operands`). - **Stacked with #37's full `valu_tests`**: - **Intel Iris Xe (`8086:46a6`)**: **7/7 passed** (previously 6/7) - **NVIDIA GeForce RTX 3070 Ti Laptop GPU (`10de:24e0`, driver `616.64`)**: **7/7 passed** - `cargo xtask policy`: **150 files ok** (synthetic GFX10 shader only; zero game data). - `cargo clippy -p victory-shader --all-targets`: 0 new warnings. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:31 +00:00
github-bot closed this pull request 2026-11-26 03:50:31 +00:00
Author
Owner

@⁠lordon1a on GitHub · 2026-11-24 00:43 UTC · original

Updated against latest main (fc0c4dd, which merged #37's valu_tests.rs and #56) — dropped the now-redundant test in emit/mod.rs so the diff is just the 1-file fix in crates/victory-shader/src/emit/lower.rs (+13/-3 lines).

Re-verified on Windows 11 (Intel Iris Xe 8086:46a6, driver 32.0.101.7088): cargo xtask policy (151 files ok), cargo test -p victory-shader -> 68 passed, 0 failed (including main's emit::valu_tests::v_med3_f32_matches_rdna2_with_nan, which fails on main@fc0c4dd). AI-assisted.

**@⁠lordon1a** on GitHub · 2026-11-24 00:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/110#issuecomment-7118361513) Updated against latest `main` (`fc0c4dd`, which merged #37's `valu_tests.rs` and #56) — dropped the now-redundant test in `emit/mod.rs` so the diff is just the 1-file fix in `crates/victory-shader/src/emit/lower.rs` (+13/-3 lines). Re-verified on Windows 11 (`Intel Iris Xe 8086:46a6`, driver `32.0.101.7088`): `cargo xtask policy` (151 files ok), `cargo test -p victory-shader` -> **68 passed, 0 failed** (including `main`'s `emit::valu_tests::v_med3_f32_matches_rdna2_with_nan`, which fails on `main@fc0c4dd`). AI-assisted.
Author
Owner

@⁠raffclar on GitHub · 2026-11-24 00:58 UTC · original

Your tests only work on Intel hardware.... I don't have an Intel GPU

Do a small test checking that med3 emits IsNaN instead of fcmp uno to make this more portable

**@⁠raffclar** on GitHub · 2026-11-24 00:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/110#issuecomment-7118629951) Your tests only work on Intel hardware.... I don't have an Intel GPU Do a small test checking that `med3` emits `IsNaN` instead of `fcmp uno` to make this more portable
Author
Owner

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

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

  • cargo test -p victory-shader: 55 passed, 0 failed (2 test binaries).
  • The Intel Xe fast-math case this addresses cannot be reproduced here (RADV), and the diff adds no test; the DXIL IsNaN path is unexercised by the suite.
  • The full workspace still needs #112 for the victory-gpu E0425.
**@⁠DaviTostes** on GitHub · 2026-11-24 01:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/110#issuecomment-7118823719) Tested `0322732` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **55 passed, 0 failed** (2 test binaries). - The Intel Xe fast-math case this addresses cannot be reproduced here (RADV), and the diff adds no test; the DXIL `IsNaN` path is unexercised by the suite. - The full workspace still needs #112 for the `victory-gpu` E0425.
Author
Owner

@⁠lordon1a on GitHub · 2026-11-24 02:53 UTC · original

AI-assisted. Thanks for the feedback @⁠raffclar! Added a hardware-independent unit test (\emit::lower::tests::med3_f32_emits_dxil_isnan_instead_of_fcmp_uno) that lowers \ _med3_f32\ and inspects the emitted DXIL module directly to verify it emits \dx.op.isSpecialFloat.f32\ (opcode 8, \IsNaN) and does not emit \ cmp uno\ (\pred::UNO). Verified \cargo xtask policy\ (151 files ok) and \cargo test -p victory-shader\ (69/69 passed).

**@⁠lordon1a** on GitHub · 2026-11-24 02:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/110#issuecomment-7120575375) AI-assisted. Thanks for the feedback @⁠raffclar! Added a hardware-independent unit test (\emit::lower::tests::med3_f32_emits_dxil_isnan_instead_of_fcmp_uno\) that lowers \ _med3_f32\ and inspects the emitted DXIL module directly to verify it emits \dx.op.isSpecialFloat.f32\ (opcode 8, \IsNaN\) and does not emit \ cmp uno\ (\pred::UNO\). Verified \cargo xtask policy\ (151 files ok) and \cargo test -p victory-shader\ (69/69 passed).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 18:05 UTC · original

Cross-checked med3 NaN lowering alongside #971 / #1259 across NVIDIA GeForce RTX 5090, AMD Radeon(TM) Graphics, D3D12 WARP, and dxil.dll. Two notes if this PR is rebased onto current main:

  1. Bitwise i32 NaN test ((as_int(x) & 0x7FFF_FFFF) >u 0x7F80_0000) + +inf substitution: Testing NaN on integer bits avoids both fcmp uno folding and dx.op.isSpecialFloat fast-math edge cases without adding #[cfg(test)] fields to Lowered, and replacing NaN lanes with +inf before self.max_min(false, ...) also preserves RDNA2's -0.0 < +0.0 ordering (med3(-0.0, +0.0, NaN) == -0.0) and returns a quiet NaN (0x7FC0_0000) when all three inputs are signaling NaNs (sNaN).
  2. Reference commit with f32 + f16 qNaN/sNaN/±0.0/±inf GPU readback tests: fuzeofficlal/VIctory@cc27bcb.
**@⁠fuzeofficlal** on GitHub · 2026-11-24 18:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/110#issuecomment-7140152652) Cross-checked `med3` NaN lowering alongside `#971` / `#1259` across **NVIDIA GeForce RTX 5090**, **AMD Radeon(TM) Graphics**, **D3D12 WARP**, and **`dxil.dll`**. Two notes if this PR is rebased onto current `main`: 1. **Bitwise `i32` NaN test (`(as_int(x) & 0x7FFF_FFFF) >u 0x7F80_0000`) + `+inf` substitution**: Testing NaN on integer bits avoids both `fcmp uno` folding and `dx.op.isSpecialFloat` fast-math edge cases without adding `#[cfg(test)]` fields to `Lowered`, and replacing NaN lanes with `+inf` before `self.max_min(false, ...)` also preserves RDNA2's `-0.0 < +0.0` ordering (`med3(-0.0, +0.0, NaN) == -0.0`) and returns a quiet NaN (`0x7FC0_0000`) when all three inputs are signaling NaNs (`sNaN`). 2. Reference commit with `f32` + `f16` `qNaN`/`sNaN`/`±0.0`/`±inf` GPU readback tests: [`fuzeofficlal/VIctory@cc27bcb`](https://github.com/fuzeofficlal/VIctory/commit/cc27bcb991c5540cb06c31007831b8bf64883191).
Author
Owner

@⁠artor410 on GitHub · 2026-11-25 21:53 UTC · original

Tested on RTX 3070 Ti, driver 610.88, Windows 11 26300, rustc 1.98.1. main 13f91ca. This PR is closed and does not merge, so only the head d53fa58 was tested.

  • cargo test -p victory-shader on the head (old base): 69 passed, 0 failed, including med3_f32_emits_dxil_isnan_instead_of_fcmp_uno.
  • On main, v_med3_f32_matches_rdna2_with_nan passes on this card, so the bug does not reproduce here.
  • The same change is in Belobug/VIctory-Belobug-AMD as a5837b8.

(Claude Code, Claude Opus 5.5.)

**@⁠artor410** on GitHub · 2026-11-25 21:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/110#issuecomment-7175670233) Tested on RTX 3070 Ti, driver 610.88, Windows 11 26300, rustc 1.98.1. main 13f91ca. This PR is closed and does not merge, so only the head d53fa58 was tested. - `cargo test -p victory-shader` on the head (old base): 69 passed, 0 failed, including `med3_f32_emits_dxil_isnan_instead_of_fcmp_uno`. - On main, `v_med3_f32_matches_rdna2_with_nan` passes on this card, so the bug does not reproduce here. - The same change is in Belobug/VIctory-Belobug-AMD as a5837b8. (Claude Code, Claude Opus 5.5.)

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