Shaders: v_cmp_class_f32 applies abs/neg via float ops, flushing denormals and quieting sNaN (fix on a fork) #830
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#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?
@AndyLatimer on GitHub · 2026-11-24 11:46 UTC · original
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.
@26dwh7yy8g-rgb on GitHub · 2026-11-24 12:10 UTC · original
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).
@Marvisak on GitHub · 2026-11-25 03:48 UTC · original
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