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-24 11:46:55 +00:00 by AndyLatimer · 3 comments
AndyLatimer commented 2026-11-24 11:46:55 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by AndyLatimer on 2026-11-24T11:46:55Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6581047598 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/830). Originally posted by [AndyLatimer](https://github.com/AndyLatimer) on 2026-11-24T11:46:55Z. --- 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.
26dwh7yy8g-rgb commented 2026-11-24 13:01:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by 26dwh7yy8g-rgb on 2026-11-24T12:10:02Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7131058773 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/830#issuecomment-7131058773). Originally posted by [26dwh7yy8g-rgb](https://github.com/26dwh7yy8g-rgb) on 2026-11-24T12:10:02Z. --- 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).
Marvisak commented 2026-11-25 04:07:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Marvisak on 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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152267425 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/830#issuecomment-7152267425). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:48:59Z. --- <!-- 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)_
Lyrnc commented 2026-11-26 18:52:27 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-26T18:52:27Z.


Hardware check on gfx1036 (RDNA2): abs and neg on v_cmp_class_f32 only move bit 31, and the class test then reads the raw bits, denormals included, even with f32 denormals flushed. That is this issue's model. #1327 matches it on both hosts I have.

Setup.

  • Hardware: the Radeon iGPU of a Ryzen 7 9800X3D, gfx1036, AMD driver 32.0.21042.62, Windows 11. A HIP kernel (assembled by the driver's amd_comgr) runs v_cmp_class_f32_e64 s20, <mod>v4, v5 + v_cndmask_b32_e64 v10, 0, 1, s20, one row per lane.
  • Modifiers: none, -v4, |v4|, -|v4|.
  • Inputs: 20 patterns × each of the 10 class bits as the mask, 200 rows. The patterns are ±0, ±1, ±inf, the smallest and largest denormals of both signs, 0x00400000, ±FLT_MIN, quiet and signalling NaNs of both signs, some with payloads.
  • Mode: IEEE off with f32 denormals flushed (the console's mode), and again with them kept.
  • Translator: the same words through build_valu_cs, on that Radeon and on an RTX 5080 (driver 610.88), one adapter at a time with a local switch.

PC RDNA2 silicon, not the console's GPU. No game data.

gfx1036: all 4 × 200 rows, in both denormal modes, equal the class of the bit-modified pattern. For example, -0x00000001 tests as -denormal (bit 4), |0xff800001| as a signalling NaN (bit 0), and -|0x7fc00000| as a quiet NaN.

Translator, rows that differ (of 200):

modifier main 63bcca4, Radeon main, RTX 5080 #1327 (7c4663f), Radeon #1327, RTX 5080
none 0 0 0 0
-v4 0 0 0 0
|v4| 0 18 0 0
-|v4| 0 18 0 0

On the 5080, main's float abs flushes the denormals, so |0x00000001| tests as +0 (bit 6) rather than +denormal (bit 7). The AMD host keeps them through the float path, so main only goes wrong on some hosts, as 26dwh7yy8g-rgb saw on the RTX 4060. #1327 ran on a local merge with #3124 and #2915, which don't touch the class compare.

AI use: Claude Code (Claude Opus 5.5) wrote the probe and ran it on the GPUs above; the numbers come from those runs.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7200946066 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/830#issuecomment-7200946066). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-26T18:52:27Z. --- Hardware check on gfx1036 (RDNA2): `abs` and `neg` on `v_cmp_class_f32` only move bit 31, and the class test then reads the raw bits, denormals included, even with f32 denormals flushed. That is this issue's model. #1327 matches it on both hosts I have. **Setup.** - **Hardware:** the Radeon iGPU of a Ryzen 7 9800X3D, **gfx1036**, AMD driver 32.0.21042.62, Windows 11. A HIP kernel (assembled by the driver's amd_comgr) runs `v_cmp_class_f32_e64 s20, <mod>v4, v5` + `v_cndmask_b32_e64 v10, 0, 1, s20`, one row per lane. - **Modifiers:** none, `-v4`, `|v4|`, `-|v4|`. - **Inputs:** 20 patterns × each of the 10 class bits as the mask, 200 rows. The patterns are `±0`, `±1`, `±inf`, the smallest and largest denormals of both signs, `0x00400000`, `±FLT_MIN`, quiet and signalling NaNs of both signs, some with payloads. - **Mode:** IEEE off with f32 denormals flushed (the console's mode), and again with them kept. - **Translator:** the same words through `build_valu_cs`, on that Radeon and on an RTX 5080 (driver 610.88), one adapter at a time with a local switch. PC RDNA2 silicon, not the console's GPU. No game data. **gfx1036:** all 4 × 200 rows, in both denormal modes, equal the class of the bit-modified pattern. For example, `-0x00000001` tests as -denormal (bit 4), `|0xff800001|` as a signalling NaN (bit 0), and `-|0x7fc00000|` as a quiet NaN. **Translator, rows that differ (of 200):** | modifier | `main` `63bcca4`, Radeon | `main`, RTX 5080 | #1327 (`7c4663f`), Radeon | #1327, RTX 5080 | |---|---|---|---|---| | none | 0 | 0 | 0 | 0 | | `-v4` | 0 | 0 | 0 | 0 | | `\|v4\|` | 0 | **18** | 0 | 0 | | `-\|v4\|` | 0 | **18** | 0 | 0 | On the 5080, `main`'s float `abs` flushes the denormals, so `|0x00000001|` tests as +0 (bit 6) rather than +denormal (bit 7). The AMD host keeps them through the float path, so `main` only goes wrong on some hosts, as 26dwh7yy8g-rgb saw on the RTX 4060. #1327 ran on a local merge with #3124 and #2915, which don't touch the class compare. AI use: Claude Code (Claude Opus 5.5) wrote the probe and ran it on the GPUs above; the numbers come from those runs.
Sign in to join this conversation.
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#830
No description provided.