Shaders: v_cmp_class_f32 applies abs/neg via float ops, flushing denormals and quieting sNaN (fix on a fork) #830

Open
opened 2026-11-26 04:14:02 +00:00 by github-bot · 2 comments
Owner

@⁠AndyLatimer on GitHub · 2026-11-24 11:46 UTC · original

Pull requests are currently restricted to collaborators (#717), so I am sharing this bug report and verified fix from a fork branch off main (ffe310e). This also covers the missing v_cmp_class_f32 hardware test requested in #799.

Bug

In crates/victory-shader/src/emit/lower.rs (Lower::compare), v_cmp_class_f16 reads raw integer bits and applies VOP3/SDWA abs and neg modifiers bitwise (& 0x7FFF / ^ 0x8000), whereas v_cmp_class_f32 routed src0 through self.fsrc(inst, 0) followed by self.as_int(x):

} else {
    let x = self.fsrc(inst, 0)?;
    self.as_int(x)
};

Because fsrc lowers abs as dx.op.unary.f32(FAbs) and neg as fsub -0.0, x, floating-point arithmetic executes on src0 before classification:

  • On D3D12 hardware (FTZ enabled for f32), v_cmp_class_f32 with neg on +denormal (0x0000_0001) flushes to -0.0 (class 5) instead of classifying as -denormal (class 4).
  • Signalling NaNs (0x7F80_0001 / 0xFF80_0001) can be quieted to qNaNs (class 1 instead of class 0) by float negation.

On RDNA2, abs/neg on v_cmp_class_f32 manipulate only bit 31 without flushing denormals or quieting signalling NaNs.

Fix

  • Unified v_cmp_class_f32 with v_cmp_class_f16 in Lower::compare: read the raw i32 operand (still applying sdwa_src selection if present) and apply abs (& 0x7FFF_FFFF) and neg (^ 0x8000_0000) bitwise.
  • Added emit::valu_tests::v_cmp_class_f32_matches_rdna2 in crates/victory-shader/src/emit/valu_tests.rs covering all 10 IEEE-754 binary32 classes (plain) plus neg, abs, and abs+neg modifier cases on normals, ±0.0, ±inf, ±denormal, and ±sNaN (also addressing #799).

Verification

  • Before fix: v_cmp_class_f32_matches_rdna2 failed on hardware GPU (hardware: v_cmp_class_f32[neg](0x00000001, 0x010) = 0, want 1).
  • After fix (Windows 11, native SM 6.6 hardware GPU + WARP + dxil.dll validation):
    • cargo test -p victory-shader: 121 passed, 0 failed, 1 ignored.
    • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
    • cargo check -p victory --features diagnostics: clean.
    • rustfmt --edition 2024 --check on valu_tests.rs and all modified lines of lower.rs: clean.
    • cargo xtask policy: 154 files ok.

Disclosure

Synthetic tests only; no game data or console SDK assets were used. Assisted by Google Antigravity.

**@⁠AndyLatimer** on GitHub · 2026-11-24 11:46 UTC · [original](https://github.com/Marvisak/VIctory/issues/830) Pull requests are currently restricted to collaborators (#717), so I am sharing this bug report and verified fix from a fork branch off `main` (`ffe310e`). This also covers the missing `v_cmp_class_f32` hardware test requested in #799. - **Branch:** https://github.com/AndyLatimer/VIctory/tree/fix/shader-cmp-class-f32-modifiers - **Commit:** https://github.com/AndyLatimer/VIctory/commit/e08e6f46641ff8ced92b94313f1e143a3ac9fe42 ### Bug In `crates/victory-shader/src/emit/lower.rs` (`Lower::compare`), `v_cmp_class_f16` reads raw integer bits and applies VOP3/SDWA `abs` and `neg` modifiers bitwise (`& 0x7FFF` / `^ 0x8000`), whereas `v_cmp_class_f32` routed `src0` through `self.fsrc(inst, 0)` followed by `self.as_int(x)`: ```rust } else { let x = self.fsrc(inst, 0)?; self.as_int(x) }; ``` Because `fsrc` lowers `abs` as `dx.op.unary.f32(FAbs)` and `neg` as `fsub -0.0, x`, floating-point arithmetic executes on `src0` before classification: - On D3D12 hardware (FTZ enabled for f32), `v_cmp_class_f32` with `neg` on `+denormal` (`0x0000_0001`) flushes to `-0.0` (class 5) instead of classifying as `-denormal` (class 4). - Signalling NaNs (`0x7F80_0001` / `0xFF80_0001`) can be quieted to qNaNs (class 1 instead of class 0) by float negation. On RDNA2, `abs`/`neg` on `v_cmp_class_f32` manipulate only bit 31 without flushing denormals or quieting signalling NaNs. ### Fix - Unified `v_cmp_class_f32` with `v_cmp_class_f16` in `Lower::compare`: read the raw `i32` operand (still applying `sdwa_src` selection if present) and apply `abs` (`& 0x7FFF_FFFF`) and `neg` (`^ 0x8000_0000`) bitwise. - Added `emit::valu_tests::v_cmp_class_f32_matches_rdna2` in `crates/victory-shader/src/emit/valu_tests.rs` covering all 10 IEEE-754 binary32 classes (plain) plus `neg`, `abs`, and `abs+neg` modifier cases on normals, `±0.0`, `±inf`, `±denormal`, and `±sNaN` (also addressing #799). ### Verification - **Before fix:** `v_cmp_class_f32_matches_rdna2` failed on hardware GPU (`hardware: v_cmp_class_f32[neg](0x00000001, 0x010) = 0, want 1`). - **After fix (Windows 11, native SM 6.6 hardware GPU + WARP + `dxil.dll` validation):** - `cargo test -p victory-shader`: 121 passed, 0 failed, 1 ignored. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo check -p victory --features diagnostics`: clean. - `rustfmt --edition 2024 --check` on `valu_tests.rs` and all modified lines of `lower.rs`: clean. - `cargo xtask policy`: 154 files ok. ### Disclosure Synthetic tests only; no game data or console SDK assets were used. Assisted by Google Antigravity.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:02 +00:00
Author
Owner

@⁠26dwh7yy8g-rgb on GitHub · 2026-11-24 12:10 UTC · original

Tested on an RTX 4060 desktop (driver 616.92), Windows 11 Pro 26200, Rust 1.98.1, WARP 10.0.26100.9818.

  • main (ffe310e) with only your valu_tests.rs: the new test fails 3/3, hardware: v_cmp_class_f32[neg](0x00000001, 0x010) = 0, want 1.
  • With that assert turned into a print, so it doesn't stop at the first mismatch: 18 wrong cases on the RTX 4060 and 16 on WARP, all abs/neg on denormals or sNaNs. The 2 extra on hardware are abs on 0xff800001.
  • e08e6f4: passes 3/3 on both. cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored (4 of the passes are diff_tests, which skip themselves here). Both clippy variants and cargo xtask policy are clean.
  • I checked that reading self.operand instead of self.src0 doesn't lose DPP: valu() already refuses compares with DPP.
  • Cherry-picks onto main together with #832 without conflict: victory-shader lib tests 122 passed, 0 failed, 1 ignored, both clippy variants clean.

No game data used. AI-assisted (Claude Code).

**@⁠26dwh7yy8g-rgb** on GitHub · 2026-11-24 12:10 UTC · [original](https://github.com/Marvisak/VIctory/issues/830#issuecomment-7131058773) Tested on an RTX 4060 desktop (driver 616.92), Windows 11 Pro 26200, Rust 1.98.1, WARP 10.0.26100.9818. - `main` (`ffe310e`) with only your `valu_tests.rs`: the new test fails 3/3, `hardware: v_cmp_class_f32[neg](0x00000001, 0x010) = 0, want 1`. - With that assert turned into a print, so it doesn't stop at the first mismatch: 18 wrong cases on the RTX 4060 and 16 on WARP, all abs/neg on denormals or sNaNs. The 2 extra on hardware are `abs` on `0xff800001`. - `e08e6f4`: passes 3/3 on both. `cargo test --workspace --locked`: 343 passed, 0 failed, 6 ignored (4 of the passes are `diff_tests`, which skip themselves here). Both clippy variants and `cargo xtask policy` are clean. - I checked that reading `self.operand` instead of `self.src0` doesn't lose DPP: `valu()` already refuses compares with DPP. - Cherry-picks onto `main` together with #832 without conflict: `victory-shader` lib tests 122 passed, 0 failed, 1 ignored, both clippy variants clean. No game data used. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:48 UTC · original

Automated triage for the maintainers. Confirmed on main. In crates/victory-shader/src/emit/lower.rs, Lower::compare handles v_cmp_class_f16 by reading the raw half and applying abs/neg bitwise. v_cmp_class_f32 still goes through self.fsrc(inst, 0) and then as_int, so abs/neg become float operations before the class test, which can flush denormals and quiet signalling NaNs. Open PR #1327 ("apply bitwise modifiers to v_cmp_class_f32 source operands") addresses this. Your branch e08e6f4 also adds the hardware test that #799 asks for. Pull requests are open to everyone again (see #717), so please open the branch as a pull request and link this issue and #799. Compare it with #1327 first.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:48 UTC · [original](https://github.com/Marvisak/VIctory/issues/830#issuecomment-7152267425) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T12:10:02Z at=2026-11-25T03:48:59Z --> Automated triage for the maintainers. Confirmed on `main`. In `crates/victory-shader/src/emit/lower.rs`, `Lower::compare` handles `v_cmp_class_f16` by reading the raw half and applying `abs`/`neg` bitwise. `v_cmp_class_f32` still goes through `self.fsrc(inst, 0)` and then `as_int`, so `abs`/`neg` become float operations before the class test, which can flush denormals and quiet signalling NaNs. Open PR #1327 ("apply bitwise modifiers to v_cmp_class_f32 source operands") addresses this. Your branch `e08e6f4` also adds the hardware test that #799 asks for. Pull requests are open to everyone again (see #717), so please open the branch as a pull request and link this issue and #799. Compare it with #1327 first. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#830
No description provided.