Shaders: v_mul_legacy_f32 treats denormal operands as zero #682
No reviewers
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!682
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/682/head"
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?
@senchsus on GitHub · 2026-11-24 06:45 UTC · original
senchsus:shaders/legacy-mul-denormals→main· +48 −5 · 2 files · 3 commits · merged 2026-11-25 21:49 UTCRDNA2 treats denormal operands of the legacy multiplies (
v_mul_legacy_f32,v_mac_legacy_f32,v_mad_legacy_f32) as zero, so0 × anything = 0also holds for them. The lowering only compared each operand with0.0, so a denormal times inf/NaN gave NaN instead of 0, and the result depended on the host's denormal mode.legacy_mulnow checks each operand's exponent bits (bits & 0x7F800000 == 0), which covers ±0 and denormals and does not depend on how the host handles denormals. Follow-up to the lower-priority item in #2.Tests
v_mul_legacy_f32_treats_denormals_as_zeroinvalu_tests.rs: zero/denormal × inf/NaN/large gives +0, the smallest normal is not flushed, and ordinary products still match.cargo test -p victory-shader,clippyandcargo check --tests --target x86_64-pc-windows-msvcpass;cargo xtask policypasses.@lameloball2813-ui on GitHub · 2026-11-24 07:40 UTC · original
Ran it on a GPU and WARP: Windows 11, RTX 5060 Ti (the only adapter), NVIDIA driver 32.0.16.1088, Rust 1.98.1, debug.
v_mul_legacy_f32_treats_denormals_as_zero3d73ea9maind2a4baewith only this PR'svalu_tests.rsAll 8
valu_testson3d73ea9pass with--test-threads=1.So on this NVIDIA card and on WARP the old lowering already gives +0 for denormal × inf/NaN. Most likely those hosts flush the denormal operand, so the old
== 0.0compare is true, which fits the PR's note that the old result "depended on the host's denormal mode". The fix makes it independent of that, but on these two hosts the test can't tell the old code from the new. A host that keeps fp32 denormals (an AMD GPU, maybe) would be needed to see it fail onmain; I don't have one.@slint6614-dev on GitHub · 2026-11-24 10:16 UTC · original
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4) and Ryzen 9600X iGPU (RDNA2, gfx1036), each picked as the hardware device of
run_cases(local adapter-selection patch, not part of this PR);cargo test -p victory-shader --release valu_testsat the PR head. Negative control: the PR's non-test files reverted to its merge base, its new tests kept.v_mul_legacy_f32_treats_denormals_as_zeropasses on both AMD GPUs.run_cases. Those hosts already flush the denormal operands (D3D's default f32 denormal mode), so main's lowering gives +0 there anyway.@ErRusso on GitHub · 2026-11-24 11:19 UTC · original
Audit: ✅ Looks good — verified & tested
Reviewed this PR as part of an audit of mergeable PRs.
crates/victory-shader/src/emit/lower.rs+valu_tests.rs(+48/-5).v_mul_legacy_f32now treats denormal operands as zero via bit-level exponent check (0x7F80_0000mask) instead of a float compare, whose result would depend on the host's denormal mode. Matches RDNA2 semantics.main.cargo test -p victory-shader -- emit::lower::→ 5/5 passed; the new GPU diff testv_mul_legacy_f32_treats_denormals_as_zerocompiles cleanly (needs a Windows/D3D12 host to execute — this environment is Linux).No issues found. The exponent-bit probe is the right approach for denormal-as-zero on RDNA2.
@upipibi on GitHub · 2026-11-24 14:14 UTC · original
A cross-check from AnyPS5's hardware-matched model; behaviour only, no code. It narrows when this PR's rule holds.
0 × anything = 0only when it is exactly ±0 ((bits & 0x7fffffff) == 0) after the operand has gone through the f32 input-denormal handling of the current mode (FP_DENORM).This only matters if VIctory ever runs a program in a mode that keeps f32 denormals (
s_setregof MODE, or a title setting FLOAT_MODE). If it always assumes the flushing default, the exponent test is the host-independent way to get the hardware answer, and this PR is right for that. Derived from AnyPS5's sources and its measured rows; I have not run RDNA2 hardware in a preserving mode myself.AI-assisted (Claude Code).
@senchsus on GitHub · 2026-11-24 18:00 UTC · original
Thanks, this is a fair point and I should have qualified the RDNA2 claim, which I didn't verify on hardware. VIctory doesn't set float mode anywhere (s_denorm_mode is a no-op in ir.rs), so the fix assumes the flushing default. I'll state that assumption in the PR description. If a title ever switches to preserving denormals, this rule would be wrong for denormal × inf, so it would need to read the mode first.
@Marvisak on GitHub · 2026-11-25 00:34 UTC · original · edited 2026-11-25 09:16 UTC
Automated triage for the maintainers.
Merge candidate. The branch now merges cleanly.
legacy_mulincrates/victory-shader/src/emit/lower.rsdecides "operand is zero" on the exponent bits instead of a float== 0.0. That covers ±0 and f32 denormals, and the result no longer depends on the host's denormal mode. The change reachesv_mul_legacy_f32,v_mac_legacy_f32andv_mad_legacy_f32. It matches main's existing convention that f32 denormals are read as zero (ftz,max_min), and VIctory does not model a mode that keeps denormals (s_denorm_modeis a no-op inir.rs). The author acknowledged that limit after the cross-check in the thread. Recommending a look, not approving.Notes (not blocking):
v_mul_legacy_f32_treats_denormals_as_zerotest cannot tell old code from new on the hosts reported in this thread (NVIDIA, AMD RDNA2/RDNA4, WARP), because they all flush denormals by default. It documents the intended result but is not a regression guard there.ftzhelper (e.g. compareftz(a)with 0) instead of repeating the mask.legacy_mulchange is also part of the larger bundle in #1330; this PR is the focused version.CI: passing (
check).Generated by Claude Code
@senchsus on GitHub · 2026-11-25 08:26 UTC · original
Merged main into the branch, the conflict in valu_tests.rs is resolved (kept both the new tests and this one). It merges cleanly now.