Shaders: min, max and med3 read f32 denormals as signed zeros (#136) #229
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!229
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-229"
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?
@bawhen on GitHub · 2026-11-24 22:49 UTC · original
bawhen:shader/min-max-med3-denormals→main· +112 −10 · 2 files · 1 commits · openRefs #136: the "fp32 denormals and the sign of a flushed zero (
v_min/max/med3_f32)" row.Problem. The console's float mode reads an f32 denormal operand of
v_min/max/min3/max3/med3_f32as a zero of its sign. The translation left that to the host's denormal mode, which varies. Andv_med3_f32didn't order -0 below +0 the wayv_min/max_f32already do here: it used the host'sFMin/FMaxdirectly.Change. A port of the min/max/med3 part of upstream Marvisak/VIctory
77053a0("accuracy fixes for discards, f16 rounding, denormals, med3 and signed zeros"). The fork's code here still matched upstream's from before that commit.ftz: an f32 denormal becomes a zero of its sign, decided on the bits.max_minflushes both operands, then callsmax_min_flushed, the existing -0-below-+0 ordering.med3flushes its three operands and is built frommax_min_flushed, so its median orders -0 below +0 too. The fork's NaN rule (the minimum of the three) is unchanged.The f16 forms (
v_max/min/med3_f16,v_pk_min/max_f16) go through the same helpers on values widened to f32.ftznever changes those, since the smallest f16 denormal (2^-24) is a normal f32.The rest of
77053a0is out of scope: discards, the f16 rounding mode, output modifiers, the FMA probe, and its test file.Test.
min_max_and_med3_read_denormals_as_signed_zerosruns all five instructions over every triple of seven values on the hardware adapter and WARP: ±0, ±denormal, the largest denormal, the smallest normal, and -1. Each result is compared bit for bit with a CPU reference that flushes and orders -0 below +0.Results on an AMD Radeon RX 7700 (RDNA3, 16 GB, driver 32.0.32029.2010) and WARP, Windows 11:
main(4e17478)v_min35,v_max35,v_min350,v_max337,v_med366Examples on
main(WARP):v_min_f32(-0, +denormal) = +0, want -0. WARP flushes the denormal, so the -0/+0 rule never sees two zeros.v_med3_f32(+0, +0, -0) = -0, want +0. No denormal is involved: the median ignored the zero ordering.This RX 7700 is not affected. It already gives the console's result in all 343 cases for all five instructions. The fix is for hosts that don't flush, plus CI's WARP adapter. Upstream's
77053a0names an RX 6700 XT (RDNA2) as one that doesn't flush, which suggests RDNA3 and RDNA2 drivers differ here. I haven't tested an RDNA2 card or NVIDIA.cargo test --workspace --locked: 497 passed, 0 failed, 7 ignored (main's 496 plus the new test).cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings: clean.cargo xtask policy: ok.cargo fmt --checkadds no differences in the two changed files beyond whatmainalready has.AI use: Claude Code (Claude Opus 5.5) found the upstream fix, wrote the port and the test, and ran them on my card; opened at my request.
🤖 Generated with Claude Code
@YeokiNoewChi on GitHub · 2026-11-25 00:37 UTC · original
RTX 3070 Ti 8 GB (32-lane waves), Windows 11, Series X profile. Tree: this fork with Emiriley's
bench7stack (which merges this PR) plus a few NVIDIA-side changes,VICTORY_SHADER_LOOP_LIMIT=256.With this PR the main character's hair breaks. In the prologue cell, with a warm cache and in steady state, the hair is drawn as scattered shards with a dark wedge through it, and draws per frame drop from about 5,100 to about 3,400. Reverting only this PR's merge (and nothing else) brings the hair back to normal on the same cache and camera position.
Offline, the hair-strand program is where it changes. I translated the 70 programs whose names contain "hair" with
VICTORY_EMIT_DUMPand compared the emitted DXIL with and without this PR: 60 differ. Inbvh_skinning_smh:CSGenerateHairVB(#72f552f4553fb5f9), which builds the strands' vertex buffer, the only change is this pattern added five times around min/max operands:So any operand whose exponent bits are zero is replaced by a signed zero. My guess is that this program runs
v_min_f32/v_max_f32on values that are not normal floats (small integer or packed bit patterns, which look like denormals), and the flush destroys them. That would match the shards.A possible way forward: limit the flush to operands known to be floats, or put it behind a switch until the console's denormal mode for these instructions is confirmed.
Hashes and counts only, nothing from the game. AI-assisted (Claude Code).
@HAL9000RELOADED on GitHub · 2026-11-25 19:29 UTC · original
RX 7900 XTX (RDNA3), Windows 10 + #402, main
d510ee4:min_max_and_med3_read_denormals_as_signed_zerospasses with this PR. It also passes with the test alone on main, so this card already reads those denormals as the console does. The PR changes nothing on RDNA3 and breaks nothing. Run table: #129 (#129).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.