Skip to content

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

Closed
lordon1a wants to merge 1 commit into
Marvisak:mainfrom
lordon1a:fix/fcmp-dxil-isnan
Closed

lordon1a wants to merge 1 commit into
Marvisak:mainfrom
lordon1a:fix/fcmp-dxil-isnan

Conversation

@lordon1a

Copy link
Copy Markdown
Contributor

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 xtask policy: 151 files ok (synthetic GFX10 shader only; zero game data).
  • Zero new compiler warnings.

AI-assisted.

Copilot AI balanced review requested due to automatic review settings November 24, 2026 01:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

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

No game data used.

AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
…and self float compares) into the integration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@marquezinii

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants