Shaders: v_mov_b32 and v_cndmask_b32 apply abs/neg via float ops, flushing denormals and quieting sNaN (fix on a fork) #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?
Imported from Marvisak/VIctory. Originally posted by AscilCH on 2026-11-24T13:23:24Z.
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.
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T13:50:15Z.
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.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T14:08:35Z.
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).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T06:50:29Z.
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
upstream-sync referenced this issue2026-11-25 19:06:24 +00:00
Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-26T18:52:23Z.
Hardware check of the claim here, on gfx1036 (RDNA2). It holds:
absandnegonv_mov_b32andv_cndmask_b32only move bit 31. The measurement also shows something no fix here covers:v_mov_b32ignoresclampand the output modifier.mainand #2548 both apply them as float operations.Setup.
clamp/omodforms).±0,±1,±inf, the smallest and largest denormals of both signs,0x00400000,±FLT_MIN, quiet and signalling NaNs with payloads.v_cndmask_b32picks per row between that pattern and a small denormal.build_valu_cs, on that Radeon and on an RTX 5080 (driver 610.88), one adapter at a time with a local switch.PC RDNA2 silicon, not the console's GPU. No game data.
gfx1036 results. The same with f32 denormals flushed or kept, and the
clamp/omodrows also with IEEE on:v_mov_b32_e64withneg,abs, or-|x|: the source with bit 31 flipped, cleared or set. Nothing else changes:-0x00000001gives0x80000001,|0xff800001|gives0x7f800001, and0xffc00000stays0xffc00000under-|x|.v_mov_b32_e64withclamp,mul:2,mul:4ordiv:2: the source, unchanged. Examples:-1.0 clamp → 0xbf800000,1.0 mul:2 → 0x3f800000,0.5 mul:4 → 0x3f000000,-0 clamp → 0x80000000,0x7f800001 clamp → 0x7f800001.v_mov_b32_e64 -v clamp: the negation applies and the clamp doesn't:1.0 → 0xbf800000.v_cndmask_b32_e64:neg/abson either source are the same sign-bit moves on the selected value.clampandmul:2are ignored there too (-1.0,2.0and0x80000001come through unchanged).Translator, rows that differ from the hardware (of 200):
main63bcca4, Radeonmain, RTX 5080f3809a8), Radeon-v|v|-|v|clampmul:2/div:2-v clampv_cndmask_b32neg/abs, either sourceThe 120 on the 5080 are the denormals flushed to
±0and the NaNs rewritten, as this issue describes. The AMD driver happens to keep them through the float path. #2548 fixes those on both hosts.The
clampand multiplier rows still differ with #2548. It sendsv_mov_b32throughwrite_fwhenclamporomodis set, and its test asserts that:-(-0.25) clamp mul:2should be0.5. On the hardware that instruction gives0x3e800000(0.25).A fix stacked on #2548 is on
Lyrnc:fix/v-mov-b32-ignores-clamp-omod. It writes the moved bits whateverclamp/omodsay. It adds a GPU test from the rows above that fails onmainand on #2548, and changes #2548's float-modifier case to the hardware's value. I'll open it as a PR once #2548 is settled, or fold it in if fuzeofficlal prefers.AI use: Claude Code (Claude Opus 5.5) wrote the probe and ran it on the GPUs above; the numbers come from those runs.