Skip to content

Shaders: lower v_mov_b32 abs/neg modifiers bitwise - #2548

Open
fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-vmov-b32-bitwise-modifiers-883
Open

fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-vmov-b32-bitwise-modifiers-883

Conversation

@fuzeofficlal

Copy link
Copy Markdown
Contributor

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

@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-vmov-b32-bitwise-modifiers-883 branch from a363be3 to cc7e263 Compare November 25, 2026 16:33

@fyernald fyernald left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@brainbudt

Copy link
Copy Markdown

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.

On RDNA2, source abs/neg on v_mov_b32 clears or flips bit 31 bitwise without quieting sNaN or flushing denormals unless a float output modifier (clamp/omod) is active. Extract Lower::src_bits to apply SDWA selection and bitwise abs/neg consistently for both v_mov_b32 and v_cndmask_b32, and only convert to float for write_f when clamp or omod is set.

Co-authored-by: AscilCH <178020422+AscilCH@users.noreply.github.com>
@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-vmov-b32-bitwise-modifiers-883 branch from cc7e263 to f3809a8 Compare November 25, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants