Shaders: lower v_mov_b32 abs/neg modifiers bitwise #2546

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/2548 into main
fuzeofficlal commented 2026-11-25 15:38:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T15:38:06Z.


Refs #883

Summary

Ports the remaining v_mov_b32 half of #883 (AscilCH's cacf6ad, with Co-authored-by preserved) onto current main (v_cndmask_b32 already landed there):

  • On RDNA2, source abs and neg modifiers on v_mov_b32 clear or flip bit 31 bitwise without flushing subnormal values or quieting sNaN payloads unless a floating-point output modifier (clamp or omod) is active.
  • Extracts Lower::src_bits in crates/victory-shader/src/emit/lower.rs (preserving DPP src0, low16_src, and SDWA byte/word selection before applying And 0x7FFF_FFFF / Xor 0x8000_0000), sharing it across Lower::src, v_mov_b32, and v_cndmask_b32.
  • Routes v_mov_b32 through as_float + write_f only when v.clamp || v.omod != 0.

Verification

  • Added emit::valu_tests::v_mov_b32_modifiers_are_bitwise (crates/victory-shader/src/emit/valu_tests.rs) covering v_mov_b32_e64 (-v1, |v1|, -|v1|), v_mov_b32_sdwa (-v1, -v1.w0, |sext(v1.b0)|) across normals, ±0.0, ±inf, min/max ±denormal, ±sNaN, and payload ±qNaN, plus v_mov_b32_e64 with clamp and omod = mul:2.
  • Negative control against unpatched lower.rs reproduces subnormal flushing (0x0000_0001 -> 0x8000_0000 instead of 0x8000_0001).
  • cargo test -p victory-shader --lib emit::valu_tests (passed on both RTX 5090 hardware and D3D12 WARP, validated with dxil.dll)
  • cargo clippy -p victory-shader --all-targets -- -D warnings (default and --no-default-features)
  • cargo xtask policy
<!-- greyfinch-sync:Marvisak/VIctory:issue:5494448873 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2548). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T15:38:06Z. --- Refs #883 ## Summary Ports the remaining `v_mov_b32` half of #883 (`AscilCH`'s `cacf6ad`, with `Co-authored-by` preserved) onto current `main` (`v_cndmask_b32` already landed there): - On RDNA2, source `abs` and `neg` modifiers on `v_mov_b32` clear or flip bit 31 bitwise without flushing subnormal values or quieting `sNaN` payloads unless a floating-point output modifier (`clamp` or `omod`) is active. - Extracts `Lower::src_bits` in `crates/victory-shader/src/emit/lower.rs` (preserving DPP `src0`, `low16_src`, and SDWA byte/word selection before applying `And 0x7FFF_FFFF` / `Xor 0x8000_0000`), sharing it across `Lower::src`, `v_mov_b32`, and `v_cndmask_b32`. - Routes `v_mov_b32` through `as_float` + `write_f` only when `v.clamp || v.omod != 0`. ## Verification - Added `emit::valu_tests::v_mov_b32_modifiers_are_bitwise` (`crates/victory-shader/src/emit/valu_tests.rs`) covering `v_mov_b32_e64` (`-v1`, `|v1|`, `-|v1|`), `v_mov_b32_sdwa` (`-v1`, `-v1.w0`, `|sext(v1.b0)|`) across normals, `±0.0`, `±inf`, min/max `±denormal`, `±sNaN`, and payload `±qNaN`, plus `v_mov_b32_e64` with `clamp` and `omod = mul:2`. - Negative control against unpatched `lower.rs` reproduces subnormal flushing (`0x0000_0001 -> 0x8000_0000` instead of `0x8000_0001`). - `cargo test -p victory-shader --lib emit::valu_tests` (passed on both RTX 5090 hardware and D3D12 WARP, validated with `dxil.dll`) - `cargo clippy -p victory-shader --all-targets -- -D warnings` (default and `--no-default-features`) - `cargo xtask policy`
fyernald commented 2026-11-25 17:33:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fyernald on 2026-11-25T17:33:22Z.

Review: APPROVED


Verified on RTX 3080 (617.42), Windows 10 (19045) plus WARP, main 67e8ae1 + #486 + #2596 (the suite crashes on NVIDIA without #2596, #2571). cargo test -p victory-shader --lib --locked -- --test-threads=1: 268 passed, 3 failed (the #1835 ones, also on the base). v_mov_b32_modifiers_are_bitwise passes on both adapters.

Making abs/neg sign-bit operations (AND 0x7FFFFFFF, XOR 0x80000000) in one src_bits is cleaner than the select-only special case it replaces, and it keeps denormals and NaN payloads, which a host fabs/fneg may not. src still refuses modifiers for its integer users, so nothing else changes.

<!-- greyfinch-sync:Marvisak/VIctory:review:6062136760 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2548#pullrequestreview-6062136760). Originally posted by [fyernald](https://github.com/fyernald) on 2026-11-25T17:33:22Z. **Review:** APPROVED --- Verified on **RTX 3080 (617.42), Windows 10 (19045)** plus WARP, `main` `67e8ae1` + #486 + #2596 (the suite crashes on NVIDIA without #2596, #2571). `cargo test -p victory-shader --lib --locked -- --test-threads=1`: 268 passed, 3 failed (the #1835 ones, also on the base). `v_mov_b32_modifiers_are_bitwise` passes on both adapters. Making `abs`/`neg` sign-bit operations (AND `0x7FFFFFFF`, XOR `0x80000000`) in one `src_bits` is cleaner than the select-only special case it replaces, and it keeps denormals and NaN payloads, which a host `fabs`/`fneg` may not. `src` still refuses modifiers for its integer users, so nothing else changes.
Marvisak commented 2026-11-25 19:06:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:35:51Z.


Automated triage for the maintainers.

Verdict: merge candidate (unchanged). The new head is a rebase onto current main, and it merges cleanly. I reread the whole diff. Lower::src_bits (crates/victory-shader/src/emit/lower.rs) applies abs/neg to the bits after the DPP, low16 and SDWA selection. Lower::src still refuses modifiers on other integer operations. v_mov_b32 goes through the float path only with clamp/omod. v_cndmask_b32 now uses the shared helper in place of its own copy of the same loop. The test in valu_tests.rs is unchanged in what it covers.

As noted before, #1275 makes the same change on an old base, and only one of the two should land.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171128276 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2548#issuecomment-7171128276). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T18:35:51Z. --- <!-- victory-triage v1 head=f3809a892f860c761e338326add17c30c2af0125 verdict=merge-candidate at=2026-11-26T03:23:25Z --> Automated triage for the maintainers. **Verdict: merge candidate (unchanged).** The new head is a rebase onto current `main`, and it merges cleanly. I reread the whole diff. `Lower::src_bits` (`crates/victory-shader/src/emit/lower.rs`) applies `abs`/`neg` to the bits after the DPP, `low16` and SDWA selection. `Lower::src` still refuses modifiers on other integer operations. `v_mov_b32` goes through the float path only with `clamp`/`omod`. `v_cndmask_b32` now uses the shared helper in place of its own copy of the same loop. The test in `valu_tests.rs` is unchanged in what it covers. As noted before, #1275 makes the same change on an old base, and only one of the two should land. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
brainbudt commented 2026-11-25 22:04:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by brainbudt on 2026-11-25T21:10:55Z.


Note

🤖 Gemini 4 Neon (with GPT-6.2 Astra, Mistral Large 4, and DeepSeek V4.1 Flash) responding on behalf of brainbudt

APPROVE — independently verified cc7e263 merged onto main (13f91ca).

  • Windows 11 WARP: 31/31 VALU tests passed, including exact-bit checks for -0.0, subnormals, signaling and quiet NaNs, and combined abs/neg. Negative control with main's lowering confirmed negating 0x00000001 returned 0x80000000 instead of 0x80000001; this PR preserves the payload.
  • Microsoft DXIL Validator (1.9.2609.5): accepted 8/8 containers (all 7 regression shaders plus an additional DPP shader whose disassembly shows WaveReadLaneAt -> and i32 -> xor i32).
  • Windows MSVC: cargo check -p victory-shader --target x86_64-pc-windows-msvc --tests --locked passed.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7174720927 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2548#issuecomment-7174720927). Originally posted by [brainbudt](https://github.com/brainbudt) on 2026-11-25T21:10:55Z. --- > [!NOTE] > 🤖 **Gemini 4 Neon (with GPT-6.2 Astra, Mistral Large 4, and DeepSeek V4.1 Flash) responding on behalf of brainbudt** **APPROVE** — independently verified `cc7e263` merged onto `main` (`13f91ca`). - **Windows 11 WARP:** 31/31 VALU tests passed, including exact-bit checks for `-0.0`, subnormals, signaling and quiet NaNs, and combined `abs`/`neg`. Negative control with `main`'s lowering confirmed negating `0x00000001` returned `0x80000000` instead of `0x80000001`; this PR preserves the payload. - **Microsoft DXIL Validator (`1.9.2609.5`):** accepted 8/8 containers (all 7 regression shaders plus an additional DPP shader whose disassembly shows `WaveReadLaneAt -> and i32 -> xor i32`). - **Windows MSVC:** `cargo check -p victory-shader --target x86_64-pc-windows-msvc --tests --locked` passed.
andrewpozdnakov7-jpg commented 2026-11-27 13:51:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T13:51:09Z.


Lyrnc measured an extra case that affects the current PR's test expectation. On the gfx1036 hardware, v_mov_b32 ignores clamp and all three output multipliers while still applying the source sign modifier. For example, -(-0.25) clamp mul:2 gives 0.25. Hardware report in #883

I ran the reporter's existing regression on 40ede2b (this change applied to current main 63bcca4) and on Lyrnc's follow-up a9cc700. The control changes 0xbf800000 to zero with clamp. The follow-up passes all 63 modifier/input combinations on app-local WARP 1.0.22, and the corrected existing source-modifier test passes too. All 37 VALU tests, strict shader Clippy and the asset check passed with SDK DXIL validation enabled.

@fuzeofficlal the follow-up is ready to review with this PR, with Lyrnc's test and authorship already in the commit.

AI-assisted with Codex. Synthetic shaders only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7220023749 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2548#issuecomment-7220023749). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T13:51:09Z. --- Lyrnc measured an extra case that affects the current PR's test expectation. On the gfx1036 hardware, `v_mov_b32` ignores `clamp` and all three output multipliers while still applying the source sign modifier. For example, `-(-0.25) clamp mul:2` gives 0.25. [Hardware report in #883](https://github.com/Marvisak/VIctory/issues/883#issuecomment-7200944888) I ran the reporter's existing regression on `40ede2b` (this change applied to current main `63bcca4`) and on [Lyrnc's follow-up a9cc700](https://github.com/Lyrnc/VIctory/commit/a9cc700a6e0382d9ce4bbcf2552a6c444a930a83). The control changes `0xbf800000` to zero with `clamp`. The follow-up passes all 63 modifier/input combinations on app-local WARP 1.0.22, and the corrected existing source-modifier test passes too. All 37 VALU tests, strict shader Clippy and the asset check passed with SDK DXIL validation enabled. @fuzeofficlal the follow-up is ready to review with this PR, with Lyrnc's test and authorship already in the commit. AI-assisted with Codex. Synthetic shaders only.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2548:upstream-pr/2548'
git switch 'upstream-pr/2548'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2548'
git switch 'upstream-pr/2548'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2548'
git switch 'upstream-pr/2548'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2548'
git switch 'main'
git merge --squash 'upstream-pr/2548'
git switch 'main'
git merge --ff-only 'upstream-pr/2548'
git switch 'main'
git merge 'upstream-pr/2548'
git push origin 'main'
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!2546
No description provided.