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

Closed
acleofe wants to merge 1 commit from upstream-pr/1037 into main
acleofe commented 2026-11-24 15:14:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by acleofe on 2026-11-24T15:14:40Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6585031310 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1037). Originally posted by [acleofe](https://github.com/acleofe) on 2026-11-24T15:14:40Z. --- ## 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)
Baconzido commented 2026-11-24 16:05:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Baconzido on 2026-11-24T15:28:26Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7136085212 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1037#issuecomment-7136085212). Originally posted by [Baconzido](https://github.com/Baconzido) on 2026-11-24T15:28:26Z. --- 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.
upstream-sync closed this pull request 2026-11-24 17:03:03 +00:00
Zipettte commented 2026-11-24 17:04:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T16:30:28Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137772746 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1037#issuecomment-7137772746). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T16:30:28Z. --- 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

Sign in to join this conversation.
No reviewers
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!1037
No description provided.