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

Open
github-bot wants to merge 2 commits from github-bot/gh-1275 into main AGit
Owner

@⁠Sakura-Byte on GitHub · 2026-11-24 17:01 UTC · original
Sakura-Byte:pr/bitwise-mov-cndmask-883 → main · +401 −16 · 3 files · 2 commits · open

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.

**@⁠Sakura-Byte** on GitHub · 2026-11-24 17:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1275) `Sakura-Byte:pr/bitwise-mov-cndmask-883` → `main` · +401 −16 · 3 files · 2 commits · open 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.*
Compute source operand abs (& 0x7FFF_FFFF) and neg (^ 0x8000_0000) modifiers bitwise via raw_src/src_bits on v_mov_b32 (when clamp and omod are unset) and v_cndmask_b32 instead of rounding/quieting via float unary/fsub paths.

Preserves exact bit patterns across denormals, +-0.0, infinities, sNaN/qNaN payloads, SDWA selections, and DPP transfers.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:26:00 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 19:12 UTC · original

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.

**@⁠marquezinii** on GitHub · 2026-11-24 19:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1275#issuecomment-7141766799) 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.
Author
Owner

@⁠Sakura-Byte on GitHub · 2026-11-24 19:48 UTC · original

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.

**@⁠Sakura-Byte** on GitHub · 2026-11-24 19:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1275#issuecomment-7142618650) 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.*
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 19:55 UTC · original

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.

**@⁠marquezinii** on GitHub · 2026-11-24 19:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/1275#issuecomment-7142797355) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:20 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 01:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/1275#issuecomment-7149453572) <!-- 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 has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1275/head:github-bot/gh-1275'
git switch 'github-bot/gh-1275'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1275'
git switch 'github-bot/gh-1275'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1275'
git switch 'github-bot/gh-1275'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1275'
git switch 'main'
git merge --squash 'github-bot/gh-1275'
git switch 'main'
git merge --ff-only 'github-bot/gh-1275'
git switch 'main'
git merge 'github-bot/gh-1275'
git push origin 'main'
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!1275
No description provided.