Shaders: apply v_mov_b32 and v_cndmask_b32 abs/neg modifiers bitwise #1275

Open
Sakura-Byte wants to merge 2 commits from upstream-pr/1275 into main
Sakura-Byte commented 2026-11-24 17:01:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sakura-Byte on 2026-11-24T17:01:17Z.


Fixes #883.

Summary

  • raw_src / src_bits (crates/victory-shader/src/emit/lower.rs): Reads source operand raw bits (preserving DPP cross-lane inputs and SDWA selection) and applies abs (& 0x7FFF_FFFF) and neg (^ 0x8000_0000) bitwise, while keeping src() rejecting modifiers on integer ALU instructions.
  • v_mov_b32 and v_cndmask_b32: Uses src_bits on v_cndmask_b32 and on v_mov_b32 when clamp and omod are unset, preserving exact bit patterns across denormals, +-0.0, infinities, and sNaN/qNaN payloads instead of quieting or flushing via float operations. v_mov_b32 with clamp or omod continues to take the float output modifier path.
  • Synthetic VALU / DXIL tests (crates/victory-shader/src/emit/valu_tests.rs): Added v_mov_b32_bitwise_abs_and_neg, v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg, and v_cndmask_b32_applies_abs_and_neg_bitwise across 16 floating-point bit patterns, SDWA byte sign-extension + neg, VOP3 clamp/omod, and DPP bitwise lowering inspection (Module::func_names / Module::inst_lines and Lowered::op_names / Lowered::insts).

Verification

Ran cleanly on clean origin/main (ffe310e):

  • cargo xtask policy: asset policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings)
  • VICTORY_D3D12_WARP=1 VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 123 passed; 0 failed; 1 ignored (including all 16 passed; 0 failed in emit::valu_tests, with only the existing release-only benchmark emit::bitcode::tests::bench_write ignored; dxil.dll validation ran; v_mov_b32_dpp validates DXIL and checks bitwise bin:Xor/bin:And without dx.op.unary.f32, executing when a WaveSize(32) compute PSO is supported).

AI-assisted; synthetic tests only, zero game assets.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6587119428 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1275). Originally posted by [Sakura-Byte](https://github.com/Sakura-Byte) on 2026-11-24T17:01:17Z. --- Fixes #883. ### Summary - **`raw_src` / `src_bits` (`crates/victory-shader/src/emit/lower.rs`)**: Reads source operand raw bits (preserving DPP cross-lane inputs and SDWA selection) and applies `abs` (`& 0x7FFF_FFFF`) and `neg` (`^ 0x8000_0000`) bitwise, while keeping `src()` rejecting modifiers on integer ALU instructions. - **`v_mov_b32` and `v_cndmask_b32`**: Uses `src_bits` on `v_cndmask_b32` and on `v_mov_b32` when `clamp` and `omod` are unset, preserving exact bit patterns across denormals, `+-0.0`, infinities, and `sNaN`/`qNaN` payloads instead of quieting or flushing via float operations. `v_mov_b32` with `clamp` or `omod` continues to take the float output modifier path. - **Synthetic VALU / DXIL tests (`crates/victory-shader/src/emit/valu_tests.rs`)**: Added `v_mov_b32_bitwise_abs_and_neg`, `v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg`, and `v_cndmask_b32_applies_abs_and_neg_bitwise` across 16 floating-point bit patterns, SDWA byte sign-extension + neg, VOP3 clamp/omod, and DPP bitwise lowering inspection (`Module::func_names` / `Module::inst_lines` and `Lowered::op_names` / `Lowered::insts`). ### Verification Ran cleanly on clean `origin/main` (`ffe310e`): - `cargo xtask policy`: `asset policy: 154 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed (0 warnings) - `VICTORY_D3D12_WARP=1 VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1`: `123 passed; 0 failed; 1 ignored` (including all `16 passed; 0 failed` in `emit::valu_tests`, with only the existing release-only benchmark `emit::bitcode::tests::bench_write` ignored; `dxil.dll` validation ran; `v_mov_b32_dpp` validates DXIL and checks bitwise `bin:Xor`/`bin:And` without `dx.op.unary.f32`, executing when a `WaveSize(32)` compute PSO is supported). *AI-assisted; synthetic tests only, zero game assets.*
catminou4 commented 2026-11-24 18:04:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T17:06:55Z.

Review: APPROVED


v_mov_b32/v_cndmask_b32 abs/neg modifiers now apply bitwise (And 0x7FFFFFFF / Xor 0x80000000) instead of routing through the float path or erroring — matches the ISA (integer modifiers, denormal/NaN payload preserving). src() keeps rejecting modifiers for integer ops; src_bits is used only where the ISA defines them. SDWA/DPP raw-source preservation is kept via raw_src. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p victory-shader --locked. Shader execution tests (valu_tests/host) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 96 passed, 0 failed; the three new tests are valu_tests (Windows-gated), so execution semantics need a Windows run — the bitwise construction itself is straightforward.

<!-- greyfinch-sync:Marvisak/VIctory:review:6043853699 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1275#pullrequestreview-6043853699). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T17:06:55Z. **Review:** APPROVED --- v_mov_b32/v_cndmask_b32 abs/neg modifiers now apply bitwise (And 0x7FFFFFFF / Xor 0x80000000) instead of routing through the float path or erroring — matches the ISA (integer modifiers, denormal/NaN payload preserving). src() keeps rejecting modifiers for integer ops; src_bits is used only where the ISA defines them. SDWA/DPP raw-source preservation is kept via raw_src. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, `cargo test -p victory-shader --locked`. Shader execution tests (valu_tests/host) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. 96 passed, 0 failed; the three new tests are valu_tests (Windows-gated), so execution semantics need a Windows run — the bitwise construction itself is straightforward.
marquezinii commented 2026-11-24 20:03:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T19:12:54Z.


On an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at 2d44b99, cargo test -p victory-shader --lib -- --test-threads=1 --nocapture gives 122 passed, 1 failed:

test emit::valu_tests::v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg ... FAILED
warp: compute_pipeline failed: The parameter is incorrect.

The values are fine: in each run_cases the hardware leg runs first, and it passed every case. The failure comes from the test's gate.

  • The DPP shader (dpp_neg) declares WaveSize(32) (waveReadLaneAt/waveGetLaneIndex in the dump).
  • can_run_dpp only asks whether the hardware adapter can make that pipeline, and run_cases then runs it on hardware and WARP.
  • WARP here offers only 4-lane waves, so its CreateComputePipelineState returns E_INVALIDARG.
  • On a host where the hardware adapter can't make the pipeline, the whole block is skipped, which may be why it passed where you ran it.
  • On any GPU with wave32 (NVIDIA, or AMD in wave32 mode) it fails on the WARP leg.

The fix is a per-host wave-size check like run_cases_with_wave_size in #1412/#1416, or checking compute_pipeline for each host inside the loop instead of once for the hardware.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7141766799 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1275#issuecomment-7141766799). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T19:12:54Z. --- On an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `2d44b99`, `cargo test -p victory-shader --lib -- --test-threads=1 --nocapture` gives 122 passed, **1 failed**: ``` test emit::valu_tests::v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg ... FAILED warp: compute_pipeline failed: The parameter is incorrect. ``` The values are fine: in each `run_cases` the hardware leg runs first, and it passed every case. The failure comes from the test's gate. - The DPP shader (`dpp_neg`) declares `WaveSize(32)` (`waveReadLaneAt`/`waveGetLaneIndex` in the dump). - `can_run_dpp` only asks whether the **hardware** adapter can make that pipeline, and `run_cases` then runs it on hardware **and** WARP. - WARP here offers only 4-lane waves, so its `CreateComputePipelineState` returns `E_INVALIDARG`. - On a host where the hardware adapter can't make the pipeline, the whole block is skipped, which may be why it passed where you ran it. - On any GPU with wave32 (NVIDIA, or AMD in wave32 mode) it fails on the WARP leg. The fix is a per-host wave-size check like `run_cases_with_wave_size` in #1412/#1416, or checking `compute_pipeline` for each host inside the loop instead of once for the hardware.
Sakura-Byte commented 2026-11-24 20:03:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sakura-Byte on 2026-11-24T19:48:32Z.


Thank you @marquezinii for catching that and pinning down the exact cause! You were right: the old can_run_dpp pre-check only probed the hardware adapter and then ran run_cases unconditionally across both hardware and 4-lane WARP, hitting E_INVALIDARG on WARP's CreateComputePipelineState for the WaveSize(32) DPP shader.

Fixed in commit cdbe178 (cdbe1789185578baa7130eae642f4fec58287687) in crates/victory-shader/src/emit/valu_tests.rs:

  • Factored run_cases into run_cases_with and added run_cases_if_supported, which checks host.compute_pipeline(shader) per host inside the ("hardware", false) / ("warp", true) loop and skips only hosts whose wave size refuses to build the pipeline (instead of panicking on WARP while still asserting that at least one SM 6.6 device was found).
  • Switched the v_mov_b32_dpp execution check in v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg to run_cases_if_supported.

Re-verified on cdbe178 (Windows 11, NVIDIA GeForce RTX 5090 D + WARP):

  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default and --all-features): 0 warnings
  • cargo test -p victory-shader --locked --lib -- --test-threads=1 (with hardware + WARP): 123 passed, 0 failed, 1 ignored (v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg executed and passed all 16 cases on RTX 5090 D while cleanly skipping 4-lane WARP)
  • VICTORY_WARP=1 VICTORY_D3D12_WARP=1 cargo test -p victory-shader --locked --lib -- --test-threads=1 v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg: 1 passed, 0 failed

AI-assisted; synthetic tests only, zero game assets.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142618650 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1275#issuecomment-7142618650). Originally posted by [Sakura-Byte](https://github.com/Sakura-Byte) on 2026-11-24T19:48:32Z. --- Thank you @marquezinii for catching that and pinning down the exact cause! You were right: the old `can_run_dpp` pre-check only probed the hardware adapter and then ran `run_cases` unconditionally across both hardware and 4-lane WARP, hitting `E_INVALIDARG` on WARP's `CreateComputePipelineState` for the `WaveSize(32)` DPP shader. Fixed in commit `cdbe178` (`cdbe1789185578baa7130eae642f4fec58287687`) in `crates/victory-shader/src/emit/valu_tests.rs`: - Factored `run_cases` into `run_cases_with` and added `run_cases_if_supported`, which checks `host.compute_pipeline(shader)` per host inside the `("hardware", false)` / `("warp", true)` loop and skips only hosts whose wave size refuses to build the pipeline (instead of panicking on WARP while still asserting that at least one SM 6.6 device was found). - Switched the `v_mov_b32_dpp` execution check in `v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg` to `run_cases_if_supported`. Re-verified on `cdbe178` (Windows 11, NVIDIA GeForce RTX 5090 D + WARP): - `cargo xtask policy`: `154 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default and `--all-features`): `0` warnings - `cargo test -p victory-shader --locked --lib -- --test-threads=1` (with hardware + WARP): **123 passed, 0 failed, 1 ignored** (`v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg` executed and passed all 16 cases on RTX 5090 D while cleanly skipping 4-lane WARP) - `VICTORY_WARP=1 VICTORY_D3D12_WARP=1 cargo test -p victory-shader --locked --lib -- --test-threads=1 v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg`: **1 passed, 0 failed** *AI-assisted; synthetic tests only, zero game assets.*
marquezinii commented 2026-11-24 20:03:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T19:55:53Z.


Confirmed at cdbe178 on the same RTX 5070 (driver 621.40, Windows 11 26300, Rust 1.98.1). cargo test -p victory-shader --lib -- --test-threads=1 --nocapture gives 123 passed, 0 failed, 1 ignored. In v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg the DPP check runs on the hardware adapter and passes, and WARP now prints compute_pipeline unsupported ...; skipped instead of failing.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142797355 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1275#issuecomment-7142797355). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T19:55:53Z. --- Confirmed at `cdbe178` on the same RTX 5070 (driver 621.40, Windows 11 26300, Rust 1.98.1). `cargo test -p victory-shader --lib -- --test-threads=1 --nocapture` gives 123 passed, 0 failed, 1 ignored. In `v_mov_b32_sdwa_and_dpp_apply_bitwise_abs_and_neg` the DPP check runs on the hardware adapter and passes, and WARP now prints `compute_pipeline unsupported ...; skipped` instead of failing.
Marvisak commented 2026-11-25 02:05:54 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149453572 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1275#issuecomment-7149453572). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:20:51Z. --- <!-- victory-triage v1 head=cdbe1789185578baa7130eae642f4fec58287687 verdict=needs-rebase at=2026-11-25T01:20:49Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
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/1275:upstream-pr/1275'
git switch 'upstream-pr/1275'

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