Shaders: v_cmp_class_f32 applies abs/neg via float ops, flushing denormals and quieting sNaN (fix on a fork) #830
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 AndyLatimer on 2026-11-24T11:46:55Z.
Pull requests are currently restricted to collaborators (#717), so I am sharing this bug report and verified fix from a fork branch off
main(ffe310e). This also covers the missingv_cmp_class_f32hardware test requested in #799.github.com/AndyLatimer/VIctory@e08e6f4664Bug
In
crates/victory-shader/src/emit/lower.rs(Lower::compare),v_cmp_class_f16reads raw integer bits and applies VOP3/SDWAabsandnegmodifiers bitwise (& 0x7FFF/^ 0x8000), whereasv_cmp_class_f32routedsrc0throughself.fsrc(inst, 0)followed byself.as_int(x):Because
fsrclowersabsasdx.op.unary.f32(FAbs)andnegasfsub -0.0, x, floating-point arithmetic executes onsrc0before classification:v_cmp_class_f32withnegon+denormal(0x0000_0001) flushes to-0.0(class 5) instead of classifying as-denormal(class 4).0x7F80_0001/0xFF80_0001) can be quieted to qNaNs (class 1 instead of class 0) by float negation.On RDNA2,
abs/negonv_cmp_class_f32manipulate only bit 31 without flushing denormals or quieting signalling NaNs.Fix
v_cmp_class_f32withv_cmp_class_f16inLower::compare: read the rawi32operand (still applyingsdwa_srcselection if present) and applyabs(& 0x7FFF_FFFF) andneg(^ 0x8000_0000) bitwise.emit::valu_tests::v_cmp_class_f32_matches_rdna2incrates/victory-shader/src/emit/valu_tests.rscovering all 10 IEEE-754 binary32 classes (plain) plusneg,abs, andabs+negmodifier cases on normals,±0.0,±inf,±denormal, and±sNaN(also addressing #799).Verification
v_cmp_class_f32_matches_rdna2failed on hardware GPU (hardware: v_cmp_class_f32[neg](0x00000001, 0x010) = 0, want 1).dxil.dllvalidation):cargo test -p victory-shader: 121 passed, 0 failed, 1 ignored.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo check -p victory --features diagnostics: clean.rustfmt --edition 2024 --checkonvalu_tests.rsand all modified lines oflower.rs: clean.cargo xtask policy: 154 files ok.Disclosure
Synthetic tests only; no game data or console SDK assets were used. Assisted by Google Antigravity.
Imported from Marvisak/VIctory. Originally posted by 26dwh7yy8g-rgb on 2026-11-24T12:10:02Z.
Tested on an RTX 4060 desktop (driver 616.92), Windows 11 Pro 26200, Rust 1.98.1, WARP 10.0.26100.9818.
main(ffe310e) with only yourvalu_tests.rs: the new test fails 3/3,hardware: v_cmp_class_f32[neg](0x00000001, 0x010) = 0, want 1.abson0xff800001.e08e6f4: passes 3/3 on both.cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored (4 of the passes arediff_tests, which skip themselves here). Both clippy variants andcargo xtask policyare clean.self.operandinstead ofself.src0doesn't lose DPP:valu()already refuses compares with DPP.maintogether with #832 without conflict:victory-shaderlib tests 122 passed, 0 failed, 1 ignored, both clippy variants clean.No game data used. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:48:59Z.
Automated triage for the maintainers. Confirmed on
main. Incrates/victory-shader/src/emit/lower.rs,Lower::comparehandlesv_cmp_class_f16by reading the raw half and applyingabs/negbitwise.v_cmp_class_f32still goes throughself.fsrc(inst, 0)and thenas_int, soabs/negbecome float operations before the class test, which can flush denormals and quiet signalling NaNs. Open PR #1327 ("apply bitwise modifiers to v_cmp_class_f32 source operands") addresses this. Your branche08e6f4also adds the hardware test that #799 asks for. Pull requests are open to everyone again (see #717), so please open the branch as a pull request and link this issue and #799. Compare it with #1327 first.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-26T18:52:27Z.
Hardware check on gfx1036 (RDNA2):
absandnegonv_cmp_class_f32only move bit 31, and the class test then reads the raw bits, denormals included, even with f32 denormals flushed. That is this issue's model. #1327 matches it on both hosts I have.Setup.
v_cmp_class_f32_e64 s20, <mod>v4, v5+v_cndmask_b32_e64 v10, 0, 1, s20, one row per lane.-v4,|v4|,-|v4|.±0,±1,±inf, the smallest and largest denormals of both signs,0x00400000,±FLT_MIN, quiet and signalling NaNs of both signs, some with payloads.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: all 4 × 200 rows, in both denormal modes, equal the class of the bit-modified pattern. For example,
-0x00000001tests as -denormal (bit 4),|0xff800001|as a signalling NaN (bit 0), and-|0x7fc00000|as a quiet NaN.Translator, rows that differ (of 200):
main63bcca4, Radeonmain, RTX 50807c4663f), Radeon-v4|v4|-|v4|On the 5080,
main's floatabsflushes the denormals, so|0x00000001|tests as +0 (bit 6) rather than +denormal (bit 7). The AMD host keeps them through the float path, somainonly goes wrong on some hosts, as 26dwh7yy8g-rgb saw on the RTX 4060. #1327 ran on a local merge with #3124 and #2915, which don't touch the class compare.AI use: Claude Code (Claude Opus 5.5) wrote the probe and ran it on the GPUs above; the numbers come from those runs.