Shaders: v_mov_b32 and v_cndmask_b32 apply abs/neg via float ops, flushing denormals and quieting sNaN (fix on a fork) #883
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#883
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@AscilCH on GitHub · 2026-11-24 13:23 UTC · original
Pull requests are currently restricted to collaborators, so I am sharing this bug report and verified fix from a clean fork branch off
main(ffe310e).github.com/AscilCH/VIctory@cacf6ad1ecBug
In
crates/victory-shader/src/emit/lower.rs, the typeless_b32instructionsv_mov_b32andv_cndmask_b32route source operands throughfsrc()(which emitsdx.op.unary.f32(FAbs)andfsub -0.0, x) wheneverabsornegmodifiers are set:v_mov_b32(lower.rs:3897-3904): routesv.abs != 0 || v.neg != 0throughf(self, 0)andfloat(self, a).v_cndmask_b32(lower.rs:4163-4167): routesv.abs != 0 || v.neg != 0through(f(self, 0), f(self, 1))andfloat(self, r).On RDNA2 (GFX10.3), both
v_mov_b32andv_cndmask_b32are typeless_b32instructions (ReadsModeReg = 0in LLVM AMDGPU) whoseabsandneginput modifiers operate strictly bitwise on bit 31 (& 0x7FFF_FFFF/^ 0x8000_0000) — they do not flush denormals to zero or quiet signalling NaNs. On D3D12 hosts (where f32 arithmetic flushes subnormals and quiets sNaNs), emitting floatFAbs/fsub -0.0, xcorrupts subnormal values and sNaN payloads.Reproduction (Before Fix)
With synthetic RDNA2 compute shaders lowered to DXIL and executed on hardware (NVIDIA RTX 3050 6GB Laptop GPU, driver
32.0.16.1742, Windows 1110.0.26300.0):Fix
Lower::src_bitsincrates/victory-shader/src/emit/lower.rsto read a raw 32-bit operand (preserving DPPself.src0and SDWAselect_bits) and applyabs(& 0x7FFF_FFFF) andneg(^ 0x8000_0000) bitwise.v_mov_b32to usesrc_bits(inst, 0)and write viaint(self, a), converting to float viaas_float+float(self, a)only whenv.clamp || v.omod != 0.v_cndmask_b32to read both operands viasrc_bitsand write viaint(self, r).dxil.dlltests incrates/victory-shader/src/emit/valu_tests.rs:emit::valu_tests::v_mov_b32_modifiers_are_bitwise(VOP3neg,abs,-|x|, SDWAneg, andclamp/mul:2across normals,±0.0,±inf,±denormal,±sNaN, and±qNaNpayloads)emit::valu_tests::v_cndmask_b32_modifiers_are_bitwise(VOP3 mixedneg/abs,-|x|+neg, and one-sidednegwith unmodifiedsrc1across the same value set)Verification
Tested on Windows 11 (
10.0.26300.0), NVIDIA RTX 3050 6GB Laptop GPU (driver32.0.16.1742), WARP, and Windows SDKdxil.dll(10.0.26100.0):rustfmt --edition 2024 --checkonvalu_tests.rsand modified lines oflower.rs: cleancargo xtask policy:154 files okcargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test -p victory-shader --locked -- --skip v_med3_f32_matches_rdna2_with_nan:121 passed, 0 failed, 1 ignoredcargo test --workspace --locked -- --skip v_med3_f32_matches_rdna2_with_nan: all workspace crates passed (0 failed; pre-existing NVIDIA#726test skipped)AI-assisted; synthetic tests only, no game files.
@LAKSHYA-cmd-tech on GitHub · 2026-11-24 13:50 UTC · original
Verified and merged downstream in PR #25. Passing bitwise modifiers through bit 31 preserves subnormal values and sNaN payloads on D3D12 hardware for both v_mov_b32 and v_cndmask_b32.
@DenRakEiw on GitHub · 2026-11-24 14:08 UTC · original
Independent verification of
cacf6ad(AscilCH/VIctory@fix/bitwise-abs-neg-mov-cndmask, fast-forward onmainffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP:cargo test -p victory-shader valu_tests: 15 passed, 0 failed (no skips needed;v_mov_b32_modifiers_are_bitwise,v_cndmask_b32_modifiers_are_bitwise, andv_med3_f32_matches_rdna2_with_nanall pass on both RTX 5090 and WARP)lower.rsreverted toffe310e, new tests kept): bothv_mov_b32_modifiers_are_bitwiseandv_cndmask_b32_modifiers_are_bitwisefail as expected (-0x00000001flushed to0x80000000instead of0x80000001)cargo clippy -p victory-shader --all-targets: 0 warningscargo xtask policy: okAI-assisted (Gemini 4 Neon).
@Marvisak on GitHub · 2026-11-25 06:50 UTC · original
Automated triage for the maintainers.
Half of this is still on current
main. Incrates/victory-shader/src/emit/lower.rs, thev_mov_b32arm still sends anyabs/negthrough the float source path (f(self, 0)thenfloat), so a denormal or signalling NaN can be changed.v_cndmask_b32is already fixed there: it now appliesabs/negasAnd/Xoron the sign bit ("Sign-bit moves on the bits a select passes through"). I found no open pull request for thev_mov_b32part. Pull requests are open to everyone now, so please open one forcacf6ad(or only itsv_mov_b32half and the tests) against currentmain.Generated by Claude Code