Shaders/Lower: guard global_atomic_fmin and global_atomic_fmax against NaN operands #3056
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!3056
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3056"
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?
@RVZO6 on GitHub · 2026-11-26 05:43 UTC · original
RVZO6:rvzo/global-atomic-fminmax-nan→main· +170 −7 · 2 files · 1 commits · openProblem
In
crates/victory-shader/src/emit/lower.rs(Lower::flat_write),global_atomic_fminandglobal_atomic_fmaxlower via two integer atomics split by sign bit (SLT(x, 0)) without checking forNaN:0x7FC0_0000/0x7F80_0001) hasnegative == false, soglobal_atomic_fmaxexecutesSMAX(mem, +NaN)and overwrites any finite or+Infvalue in memory with+NaN(since0x7FC0_0000 > 0x7F80_0000as signedi32).0xFFC0_0000/0xFF80_0001) hasnegative == true, soglobal_atomic_fminexecutesUMAX(mem, -NaN)and overwrites any finite or-Infvalue in memory with-NaN(since0xFFC0_0000 > 0xFF80_0000as unsignedu32).Per AMD RDNA2/GFX10.3
GLOBAL_ATOMIC_FMIN/GLOBAL_ATOMIC_FMAXIEEEminNum/maxNumsemantics, aNaNoperand must leave a non-NaN value in memory unchanged.Fix
When lowering float min/max atomics (
ops.len() > 1), computenan = (x & 0x7FFF_FFFF) >_u 0x7F80_0000(pred::IUGT) and select the pass'sneutralelement in both passes whennanis true. Disjoint from #1915 (which covers integer global atomics).Verification
emit::memory_tests::global_atomic_fmin_and_fmax_ignore_nan_operandstesting+qNaN,-qNaN,+sNaN, and-sNaNagainst both finite and±Infmemory cells, plus±Infand-0.0updates.windows-latestMSVC + WARP SM 6.6 +dxil.dllCI (cargo clippy --workspace --all-targets --locked -- -D warnings,--all-features,xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45762903919AI-assisted: T3 Code (Antigravity, gemini-4-neon)
@oni-swr on GitHub · 2026-11-26 06:04 UTC · original
Independent Windows x64 verification of
26ee5818dffab1deaee89c199991987d6c3451fcagainst its exact parent63bcca43c6a00a758510398fa43096ce7e4f7df0.+qNaN vs finite: the max cell read back0x7fc00000, expected0xbf800000(-1.0). The assertion ended the run at that case.0x1414, device0x008c, software flag0x2) before device creation. The fixture used the Windows SDK10.0.26100.0x64dxil.dlland ran only the WARP branch.Command:
cargo test --locked -j 4 -p victory-shader --lib --features host -- --exact emit::memory_tests::global_atomic_fmin_and_fmax_ignore_nan_operands --nocapture.AI-assisted (Codex, gpt-6.2-sol).
@Marvisak on GitHub · 2026-11-26 06:16 UTC · original
Automated triage for the maintainers.
Merge candidate. In
crates/victory-shader/src/emit/lower.rs(Lower::flat_write), the two-pass integer lowering ofglobal_atomic_fmin/global_atomic_fmaxlet a NaN operand win: a positive NaN is the largest signed integer seen by the SMAX pass, and a negative NaN the largest unsigned one seen by the UMAX pass. The PR computes(x & 0x7FFF_FFFF) >u 0x7F80_0000once and feeds each pass its neutral element for NaN lanes; I checked the neutral values against the existingopstable, and integer atomics (ops.len() == 1) are unchanged. The new test drives the existingprogram()cells at +0x80/+0x84 with all four NaN classes, infinities and -0.0.One point to confirm when reviewing: the test also asserts that a signalling NaN leaves memory unchanged. Under the IEEE 754-2008
minNum/maxNumthe description cites, an sNaN operand gives a quiet NaN instead; a pointer to the RDNA2 ISA section that defines float memory-atomic NaN handling would settle which one the hardware does. A NaN already in memory is still not replaced by a number (out of scope here, but worth noting).CI:
checkpassing.Generated by Claude Code
@passerbyyhx on GitHub · 2026-11-26 06:22 UTC · original
Native RTX 4090 Laptop readback (driver 621.14): all 9 min/max output pairs match at
26ee5818. At parent63bcca43, the same test inputs produce 6 mismatches out of 9. Both runs resolved the D3D12 device LUID to NVIDIA10de:2757with the software flag clear. Both shaders passed DXIL validation with the Windows SDK 10.0.26100.0 validator.With min/max cells initialized to +1/−1, the parent wrote the positive quiet or signaling NaN bits into the max cell (
7fc00000or7f800001). Negative quiet or signaling NaNs overwrote the min cell (ffc00000orff800001). Positive and negative quiet NaNs also overwrote one cell when the pair started at −∞/+∞. At this head each of those six input pairs retained its initial bits. The three numeric controls (+∞, −∞, −0) passed on both revisions, including80000000in both cells for −0.I used the PR fixture on both production revisions, locally making it hardware-only, logging the adapter and every pair, and checking the mismatch count after the ninth readback. Coordination.
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.