Shaders: abs/neg on v_mov_b32 and v_cndmask_b32 change only the sign bit (fixes #883) #1037

Closed
github-bot wants to merge 1 commit from gh-pr/1037/head into gh-pr/1037/base
Owner

@⁠acleofe on GitHub · 2026-11-24 15:14 UTC · original
fix/shader-move-modifiers-bitwise → main · +99 −9 · 2 files · 1 commits · closed without merging

What

v_mov_b32 and v_cndmask_b32 with abs/neg source modifiers now apply them to the sign bit of the source's bits (& 0x7fffffff, ^ 0x80000000) and write the result as an integer, through a new sign_modified_src. v_mov_b32 with clamp or omod keeps the float path. src keeps refusing integer modifiers; its body moved to unmodified_src, which both use.

Why

On RDNA2 a move or select copies bits; abs and neg on them only clear or flip bit 31. The lowering went through fsrc, which applies them as float operations (FAbs, -0.0 - x), so the host flushes denormals and quiets signaling NaNs: v_mov_b32 v0, |v1| with v1 = 0x00000001 gave 0 instead of 0x00000001. Integer or packed data moved with a modifier came out changed.

Test

  • move_and_select_modifiers_change_only_the_sign_bit (valu_tests, hardware GPU and WARP): abs, neg and both, on denormals, signaling NaNs and 1.0, for v_mov_b32 and both arms of v_cndmask_b32. Before this change it fails on the hardware GPU (0x00000001 with abs gave 0).
  • cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings and cargo test --workspace --locked pass.

🤖 Generated with Claude Code

**@⁠acleofe** on GitHub · 2026-11-24 15:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1037) `fix/shader-move-modifiers-bitwise` → `main` · +99 −9 · 2 files · 1 commits · closed without merging ## What `v_mov_b32` and `v_cndmask_b32` with abs/neg source modifiers now apply them to the sign bit of the source's bits (`& 0x7fffffff`, `^ 0x80000000`) and write the result as an integer, through a new `sign_modified_src`. `v_mov_b32` with clamp or omod keeps the float path. `src` keeps refusing integer modifiers; its body moved to `unmodified_src`, which both use. ## Why On RDNA2 a move or select copies bits; abs and neg on them only clear or flip bit 31. The lowering went through `fsrc`, which applies them as float operations (FAbs, `-0.0 - x`), so the host flushes denormals and quiets signaling NaNs: `v_mov_b32 v0, |v1|` with v1 = `0x00000001` gave `0` instead of `0x00000001`. Integer or packed data moved with a modifier came out changed. ## Test - `move_and_select_modifiers_change_only_the_sign_bit` (valu_tests, hardware GPU and WARP): abs, neg and both, on denormals, signaling NaNs and 1.0, for `v_mov_b32` and both arms of `v_cndmask_b32`. Before this change it fails on the hardware GPU (`0x00000001` with abs gave `0`). - `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings` and `cargo test --workspace --locked` pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
RDNA2 moves and selects copy bits; their abs/neg modifiers only clear or
flip bit 31. Applying them as float operations flushed denormals and
quieted signaling NaNs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:17:53 +00:00
github-bot closed this pull request 2026-11-26 04:17:53 +00:00
Author
Owner

@⁠Baconzido on GitHub · 2026-11-24 15:28 UTC · original

Tested 6afa565 (on main ffe310e) on Windows 11 26300, AMD Radeon RX 5700 (RDNA1, driver 26.11.2) and WARP, dxil.dll from SDK 10.0.26100, Rust 1.98.1:

Result
move_and_select_modifiers_change_only_the_sign_bit ok on the RX 5700 and WARP
cargo test -p victory-shader -- --test-threads=1 121 passed, 0 failed, 1 ignored
cargo clippy -p victory-shader --all-targets clean
negative control: lower.rs from ffe310e, the new test kept fails on WARP (v_mov_b32 abs=1 neg=0 [1, 0, 0, 0]: 0, want 1)

One AMD data point for #883: with main's float path, the new test's hardware pass succeeds on the RX 5700. run_cases runs the hardware device first and stops at the first mismatch, and the first mismatch came from WARP. So this AMD driver keeps the denormals and signalling NaNs through FAbs and -0.0 - x here, and the bug shows on WARP (and the NVIDIA cards in #883), not on this card. The fix is still right: it no longer depends on what the host driver does with denormals.

No game data used.

AI use: Claude Code (Claude Opus 5.5) ran the tests over SSH and drafted this comment; the runs are on my machine.

**@⁠Baconzido** on GitHub · 2026-11-24 15:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1037#issuecomment-7136085212) Tested `6afa565` (on `main` `ffe310e`) on Windows 11 26300, **AMD Radeon RX 5700** (RDNA1, driver 26.11.2) and WARP, `dxil.dll` from SDK 10.0.26100, Rust 1.98.1: | | Result | |---|---| | `move_and_select_modifiers_change_only_the_sign_bit` | ok on the RX 5700 and WARP | | `cargo test -p victory-shader -- --test-threads=1` | 121 passed, 0 failed, 1 ignored | | `cargo clippy -p victory-shader --all-targets` | clean | | negative control: `lower.rs` from `ffe310e`, the new test kept | fails on WARP (`v_mov_b32 abs=1 neg=0 [1, 0, 0, 0]`: `0`, want `1`) | One AMD data point for #883: with `main`'s float path, the new test's hardware pass **succeeds on the RX 5700**. `run_cases` runs the hardware device first and stops at the first mismatch, and the first mismatch came from WARP. So this AMD driver keeps the denormals and signalling NaNs through `FAbs` and `-0.0 - x` here, and the bug shows on WARP (and the NVIDIA cards in #883), not on this card. The fix is still right: it no longer depends on what the host driver does with denormals. No game data used. AI use: Claude Code (Claude Opus 5.5) ran the tests over SSH and drafted this comment; the runs are on my machine.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 16:30 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 6afa565: cargo test -p victory-shader passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 16:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1037#issuecomment-7137772746) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 6afa565: `cargo test -p victory-shader` passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._

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