Shaders: v_mov_b32 and v_cndmask_b32 apply abs/neg via float ops, flushing denormals and quieting sNaN (fix on a fork) #883

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

@⁠AscilCH on GitHub · 2026-11-24 13:23 UTC · original

Pull requests are currently restricted to collaborators, so I am sharing this bug report and verified fix from a clean fork branch off main (ffe310e).

Bug

In crates/victory-shader/src/emit/lower.rs, the typeless _b32 instructions v_mov_b32 and v_cndmask_b32 route source operands through fsrc() (which emits dx.op.unary.f32(FAbs) and fsub -0.0, x) whenever abs or neg modifiers are set:

  • v_mov_b32 (lower.rs:3897-3904): routes v.abs != 0 || v.neg != 0 through f(self, 0) and float(self, a).
  • v_cndmask_b32 (lower.rs:4163-4167): routes v.abs != 0 || v.neg != 0 through (f(self, 0), f(self, 1)) and float(self, r).

On RDNA2 (GFX10.3), both v_mov_b32 and v_cndmask_b32 are typeless _b32 instructions (ReadsModeReg = 0 in LLVM AMDGPU) whose abs and neg input modifiers operate strictly bitwise on bit 31 (& 0x7FFF_FFFF / ^ 0x8000_0000) — they do not flush denormals to zero or quiet signalling NaNs. On D3D12 hosts (where f32 arithmetic flushes subnormals and quiets sNaNs), emitting float FAbs / fsub -0.0, x corrupts subnormal values and sNaN payloads.

Reproduction (Before Fix)

With synthetic RDNA2 compute shaders lowered to DXIL and executed on hardware (NVIDIA RTX 3050 6GB Laptop GPU, driver 32.0.16.1742, Windows 11 10.0.26300.0):

hardware: v_mov_b32_e64(-0x00000001) = 0x80000000, want 0x80000001
hardware: v_cndmask_b32_e64(-0x00000001, |0x3f800000|, 0) = 0x80000000, want 0x80000001

Fix

  • Added Lower::src_bits in crates/victory-shader/src/emit/lower.rs to read a raw 32-bit operand (preserving DPP self.src0 and SDWA select_bits) and apply abs (& 0x7FFF_FFFF) and neg (^ 0x8000_0000) bitwise.
  • Updated v_mov_b32 to use src_bits(inst, 0) and write via int(self, a), converting to float via as_float + float(self, a) only when v.clamp || v.omod != 0.
  • Updated v_cndmask_b32 to read both operands via src_bits and write via int(self, r).
  • Added two hardware + WARP + dxil.dll tests in crates/victory-shader/src/emit/valu_tests.rs:
    • emit::valu_tests::v_mov_b32_modifiers_are_bitwise (VOP3 neg, abs, -|x|, SDWA neg, and clamp/mul:2 across normals, ±0.0, ±inf, ±denormal, ±sNaN, and ±qNaN payloads)
    • emit::valu_tests::v_cndmask_b32_modifiers_are_bitwise (VOP3 mixed neg/abs, -|x| + neg, and one-sided neg with unmodified src1 across the same value set)

Verification

Tested on Windows 11 (10.0.26300.0), NVIDIA RTX 3050 6GB Laptop GPU (driver 32.0.16.1742), WARP, and Windows SDK dxil.dll (10.0.26100.0):

  • rustfmt --edition 2024 --check on valu_tests.rs and modified lines of lower.rs: clean
  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test -p victory-shader --locked -- --skip v_med3_f32_matches_rdna2_with_nan: 121 passed, 0 failed, 1 ignored
  • cargo test --workspace --locked -- --skip v_med3_f32_matches_rdna2_with_nan: all workspace crates passed (0 failed; pre-existing NVIDIA #726 test skipped)

AI-assisted; synthetic tests only, no game files.

**@⁠AscilCH** on GitHub · 2026-11-24 13:23 UTC · [original](https://github.com/Marvisak/VIctory/issues/883) Pull requests are currently restricted to collaborators, so I am sharing this bug report and verified fix from a clean fork branch off `main` (`ffe310e`). - **Branch:** https://github.com/AscilCH/VIctory/tree/fix/bitwise-abs-neg-mov-cndmask - **Commit:** https://github.com/AscilCH/VIctory/commit/cacf6ad1ec743fe4a1111c84baa9f6114040976c ### Bug In `crates/victory-shader/src/emit/lower.rs`, the typeless `_b32` instructions `v_mov_b32` and `v_cndmask_b32` route source operands through `fsrc()` (which emits `dx.op.unary.f32(FAbs)` and `fsub -0.0, x`) whenever `abs` or `neg` modifiers are set: - `v_mov_b32` (`lower.rs:3897-3904`): routes `v.abs != 0 || v.neg != 0` through `f(self, 0)` and `float(self, a)`. - `v_cndmask_b32` (`lower.rs:4163-4167`): routes `v.abs != 0 || v.neg != 0` through `(f(self, 0), f(self, 1))` and `float(self, r)`. On RDNA2 (GFX10.3), both `v_mov_b32` and `v_cndmask_b32` are typeless `_b32` instructions (`ReadsModeReg = 0` in LLVM AMDGPU) whose `abs` and `neg` input modifiers operate strictly bitwise on bit 31 (`& 0x7FFF_FFFF` / `^ 0x8000_0000`) — they do not flush denormals to zero or quiet signalling NaNs. On D3D12 hosts (where f32 arithmetic flushes subnormals and quiets sNaNs), emitting float `FAbs` / `fsub -0.0, x` corrupts subnormal values and sNaN payloads. ### Reproduction (Before Fix) With synthetic RDNA2 compute shaders lowered to DXIL and executed on hardware (NVIDIA RTX 3050 6GB Laptop GPU, driver `32.0.16.1742`, Windows 11 `10.0.26300.0`): ```text hardware: v_mov_b32_e64(-0x00000001) = 0x80000000, want 0x80000001 hardware: v_cndmask_b32_e64(-0x00000001, |0x3f800000|, 0) = 0x80000000, want 0x80000001 ``` ### Fix - Added `Lower::src_bits` in `crates/victory-shader/src/emit/lower.rs` to read a raw 32-bit operand (preserving DPP `self.src0` and SDWA `select_bits`) and apply `abs` (`& 0x7FFF_FFFF`) and `neg` (`^ 0x8000_0000`) bitwise. - Updated `v_mov_b32` to use `src_bits(inst, 0)` and write via `int(self, a)`, converting to float via `as_float` + `float(self, a)` only when `v.clamp || v.omod != 0`. - Updated `v_cndmask_b32` to read both operands via `src_bits` and write via `int(self, r)`. - Added two hardware + WARP + `dxil.dll` tests in `crates/victory-shader/src/emit/valu_tests.rs`: - `emit::valu_tests::v_mov_b32_modifiers_are_bitwise` (VOP3 `neg`, `abs`, `-|x|`, SDWA `neg`, and `clamp`/`mul:2` across normals, `±0.0`, `±inf`, `±denormal`, `±sNaN`, and `±qNaN` payloads) - `emit::valu_tests::v_cndmask_b32_modifiers_are_bitwise` (VOP3 mixed `neg`/`abs`, `-|x|` + `neg`, and one-sided `neg` with unmodified `src1` across the same value set) ### Verification Tested on Windows 11 (`10.0.26300.0`), NVIDIA RTX 3050 6GB Laptop GPU (driver `32.0.16.1742`), WARP, and Windows SDK `dxil.dll` (`10.0.26100.0`): - `rustfmt --edition 2024 --check` on `valu_tests.rs` and modified lines of `lower.rs`: clean - `cargo xtask policy`: `154 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test -p victory-shader --locked -- --skip v_med3_f32_matches_rdna2_with_nan`: `121 passed, 0 failed, 1 ignored` - `cargo test --workspace --locked -- --skip v_med3_f32_matches_rdna2_with_nan`: all workspace crates passed (`0 failed`; pre-existing NVIDIA `#726` test skipped) *AI-assisted; synthetic tests only, no game files.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:06 +00:00
Author
Owner

@⁠LAKSHYA-cmd-tech on GitHub · 2026-11-24 13:50 UTC · original

Verified and merged downstream in PR #25. Passing bitwise modifiers through bit 31 preserves subnormal values and sNaN payloads on D3D12 hardware for both v_mov_b32 and v_cndmask_b32.

**@⁠LAKSHYA-cmd-tech** on GitHub · 2026-11-24 13:50 UTC · [original](https://github.com/Marvisak/VIctory/issues/883#issuecomment-7133409735) Verified and merged downstream in PR #25. Passing bitwise modifiers through bit 31 preserves subnormal values and sNaN payloads on D3D12 hardware for both v_mov_b32 and v_cndmask_b32.
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-24 14:08 UTC · original

Independent verification of cacf6ad (AscilCH/VIctory@fix/bitwise-abs-neg-mov-cndmask, fast-forward on main ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP:

  • cargo test -p victory-shader valu_tests: 15 passed, 0 failed (no skips needed; v_mov_b32_modifiers_are_bitwise, v_cndmask_b32_modifiers_are_bitwise, and v_med3_f32_matches_rdna2_with_nan all pass on both RTX 5090 and WARP)
  • Negative control (lower.rs reverted to ffe310e, new tests kept): both v_mov_b32_modifiers_are_bitwise and v_cndmask_b32_modifiers_are_bitwise fail as expected (-0x00000001 flushed to 0x80000000 instead of 0x80000001)
  • cargo clippy -p victory-shader --all-targets: 0 warnings
  • cargo xtask policy: ok

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-24 14:08 UTC · [original](https://github.com/Marvisak/VIctory/issues/883#issuecomment-7133906071) Independent verification of `cacf6ad` (`AscilCH/VIctory@fix/bitwise-abs-neg-mov-cndmask`, fast-forward on `main` `ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC) with **NVIDIA GeForce RTX 5090** (Blackwell) and **WARP**: - `cargo test -p victory-shader valu_tests`: **15 passed, 0 failed** (no skips needed; `v_mov_b32_modifiers_are_bitwise`, `v_cndmask_b32_modifiers_are_bitwise`, and `v_med3_f32_matches_rdna2_with_nan` all pass on both RTX 5090 and WARP) - **Negative control** (`lower.rs` reverted to `ffe310e`, new tests kept): both `v_mov_b32_modifiers_are_bitwise` and `v_cndmask_b32_modifiers_are_bitwise` fail as expected (`-0x00000001` flushed to `0x80000000` instead of `0x80000001`) - `cargo clippy -p victory-shader --all-targets`: **0 warnings** - `cargo xtask policy`: ok AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:50 UTC · original

Automated triage for the maintainers.

Half of this is still on current main. In crates/victory-shader/src/emit/lower.rs, the v_mov_b32 arm still sends any abs/neg through the float source path (f(self, 0) then float), so a denormal or signalling NaN can be changed. v_cndmask_b32 is already fixed there: it now applies abs/neg as And/Xor on the sign bit ("Sign-bit moves on the bits a select passes through"). I found no open pull request for the v_mov_b32 part. Pull requests are open to everyone now, so please open one for cacf6ad (or only its v_mov_b32 half and the tests) against current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:50 UTC · [original](https://github.com/Marvisak/VIctory/issues/883#issuecomment-7155213901) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T14:08:35Z at=2026-11-25T06:50:28Z --> Automated triage for the maintainers. Half of this is still on current `main`. In `crates/victory-shader/src/emit/lower.rs`, the `v_mov_b32` arm still sends any `abs`/`neg` through the float source path (`f(self, 0)` then `float`), so a denormal or signalling NaN can be changed. `v_cndmask_b32` is already fixed there: it now applies `abs`/`neg` as `And`/`Xor` on the sign bit ("Sign-bit moves on the bits a select passes through"). I found no open pull request for the `v_mov_b32` part. Pull requests are open to everyone now, so please open one for `cacf6ad` (or only its `v_mov_b32` half and the tests) against current `main`. --- _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#883
No description provided.