GPU rectangle CPU fallback: FP16 conversion turns NaN into infinity and rounds ties up #245
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#245
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?
@Bennet0k on GitHub · 2026-11-24 22:59 UTC · original
Source
Reproduction. Exercise
expand_rectswith anR16_FLOATattribute. Corners1.0, 0, 2^-11produce0x3c01for the generated corner, while round-to-nearest ties-to-even gives0x3c00. A quiet NaN corner (0x7e00) with other corners zero produces infinity (0x7c00). Both regressions failed with the original Rust module.Proposed fix. Handle NaN separately from overflow and infinity, with a nonzero quiet NaN mantissa. For normal values use the retained mantissa parity to resolve exact ties, consistent with the subnormal path. With this change in a temporary copy, both regressions and the four existing tests pass. This test covers the CPU fallback.
Found in an AI-assisted audit of
2119b0e.github-bot referenced this issue2026-11-26 03:40:31 +00:00
@x-nihil0 on GitHub · 2026-11-25 00:49 UTC · original
Exhaustive check of the five fixes opened for this issue (#315, #316, #326, #335, #337)
I ran every one of the 2^32
f32bit patterns throughf32_to_halfas it is onmain(tested at2119b0e;primitive.rsis the same ata803c87) and as it is in each PR, and compared the result with the CPU's own conversion (F16Cvcvtps2ph, round to nearest even). A second reference written inf64arithmetic agrees with F16C on every input.main2119b0esign | 0x7e00)sign | 0x7e00)So the issue is confirmed as described, and all five PRs fix it for every number. (#335 has since been closed by its author as a duplicate of #315; its row stays for the comparison.) They differ only in what a NaN turns into: #316, #335 and #337 keep the top ten payload bits and set the quiet bit, as
vcvtps2phdoes; #315 and #326 return one fixed quiet NaN with the input's sign. I don't know which of the two the console does, and for a rectangle corner it may not matter.The 30,720 on
mainare 30 exponents × 2 signs × the 512 ties whose kept mantissa is even: the ones that rounding half up gets wrong. First one:0x3e001000gives0x3001, F16C gives0x3000.Also checked for each PR on its own branch (each is one commit on
2119b0e):cargo test -p victory-gpu --lib --locked primitivepasses. Withmain'sf32_to_halfput back under the PR's tests, at least one new test fails in every PR, so each PR's tests do catch the bug.cargo clippy -p victory-gpu --all-targets --locked -- -D warningsis clean, and so isrustfmt --checkonprimitive.rs.Run on Windows 11 (26300), Core Ultra 9 285, Rust 1.98.1; the whole sweep takes 3 s on 24 threads. The harness is below; its
impls/*.rsfiles aref32_to_halffrommainand from each PR, copied unchanged with onlypubadded.Harness (
src/main.rs)Checked with an AI-assisted harness (Claude); no game files involved.