GPU: f32_to_half keeps NaN and rounds normals to nearest even (#843) #1732
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!1732
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1732"
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?
@moe-miau on GitHub · 2026-11-24 21:30 UTC · original
moe-miau:fix/gpu-f32-to-half-nan-rne→main· +83 −4 · 1 files · 2 commits · openFixes #843.
This is AndyLatimer's fix from the issue (branch
fix/gpu-f32-to-half-nan-and-rne,63111de), cherry-picked unchanged ontomainwith the original author kept on the commit. It was posted as a fork branch while PRs were limited to collaborators. The only PR that carried it (#1069) was closed without being merged, so nothing open fixes #843 now.f32_to_half(crates/victory-gpu/src/primitive.rs, used forF16attributes in the rectangle-list expansion) had two IEEE-754 errors:0xff, so it fell intoexp >= 31and returned±0x7c00. It now returns a quiet half NaN that keeps the sign and the upper payload bits (0x7e00 | man >> 13), so a signalling NaN with a low payload stays a NaN.(man + 0x1000) >> 13rounded1.0 + 2^-11up to odd0x3c01. It now rounds to nearest even (man + 0x0fff + lsb), matching the subnormal branch just above it. The carry still stops at0x7c00(65520 rounds to infinity).The added test covers quiet and signalling NaNs of both signs, infinities, ties on both sides, the overflow boundary, and a round trip of every half bit pattern.
Checked on Windows 11 x64, Rust 1.98.1 MSVC,
mainffe310e+ this commit:cargo clippy --workspace --all-targets --locked -- -D warningsand the--all-featuresvariant: cleancargo test --workspace --locked: pass (victory-gpu: 51 passed, including the new test)cargo xtask policy: okIndependent checks are posted on #843: the new test fails on
main, and an exhaustive comparison over all 2^32 f32 inputs against Rust'sas f16found 0 mismatches on non-NaN inputs.AI-assisted (Claude Code): I reviewed the diff and reran the checks. The fix itself is AndyLatimer's (commit author Manuel Pérez).
🤖 Generated with Claude Code
@upipibi on GitHub · 2026-11-24 22:52 UTC · original
NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, at the PR head
5c781cf.cargo test -p victory-gpu -- f32_to_half_preserves_nan_and_rounds_normals_to_nearest_even: passes.AI-assisted (Claude Code). Synthetic tests only.
@Marvisak on GitHub · 2026-11-25 01:35 UTC · original · edited 2026-11-26 00:26 UTC
Automated triage for the maintainers.
Merge candidate. The
f32_to_halffix incrates/victory-gpu/src/primitive.rsis unchanged from the head judged before: NaN becomes a quiet half NaN that keeps its sign, and normals round to nearest even with(man + 0x0fff + lsb) >> 13. The new commitbe58082only adds a test.reconstructed_fp16_corners_preserve_nan_and_infinityruns the F16 rectangle expansion (expand_rects) and checks that a NaN input stays NaN, that infinities are kept, and that infinity minus infinity in the fourth-corner arithmetic gives NaN. It keeps its original author.On your reply: noted, and it merges cleanly with current
main.CI: passing (
check).Generated by Claude Code
@moe-miau on GitHub · 2026-11-25 02:38 UTC · original
Rebased onto
main940d32f(head1b97ccd). The only conflict wasprimitive.rs's tests:mainadded new tests at the end of the module and so does this PR; both are kept, and thef32_to_halfchange applied unchanged.Checked on Windows 11, RTX 4070 SUPER, Rust 1.98.1 MSVC: both clippy configurations are clean,
cargo xtask policypasses (182 files), andf32_to_half_preserves_nan_and_rounds_normals_to_nearest_evenpasses.cargo test --workspacehas 5 failures, the same 5 that fail on unmodified940d32fon this NVIDIA card (dynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_viewsfrom the 1,000,000-descriptor heap cap, plusgathers_at_a_level_match_the_hardwareand the twostride_testshardware checks); none involves this change.AI-assisted (Claude Code).
@StExpeditus on GitHub · 2026-11-25 08:58 UTC · original
Test report: RTX 5060 Ti (Blackwell), Windows 11 Pro 26200, driver 621.24. Branch at
1b97ccd.cargo test --workspace --locked --no-fail-fast-> 697 passed, 5 failed, 10 ignored. The failures are the same 5 pre-existing NVIDIA 1M-view-heap-cap failures (also on main; see my reports on #2030 and #1940). Nothing introduced by this PR fails on this machine.@andrewpozdnakov7-jpg on GitHub · 2026-11-25 09:54 UTC · original
I reran the FP16 rectangle fallback from #2264 on
1b97ccd. The same synthetic Windows/WARP point draw read[+inf, +inf, -inf, -inf]on940d32fand[NaN, +inf, -inf, NaN]on this head. This covers both an input NaN and a NaN generated by the fourth-corner arithmetic.The test-only
541917bsits directly on1b97ccd. It verifies the generated FP16 vertex throughexpand_rectsalongside the converter tests already here. All 10 primitive tests, strict GPU Clippy with diagnostics and the staged asset policy pass.If the extra regression is useful, it can be cherry-picked as-is. If it is folded into another commit, please retain
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.@moe-miau on GitHub · 2026-11-25 22:53 UTC · original
@andrewpozdnakov7-jpg Thanks: cherry-picked as-is (
541917b→be58082, your authorship kept).cargo test -p victory-gpu --lib primitive: 10 passed.@fuzeofficlal on GitHub · 2026-11-26 00:44 UTC · original
Code review and RTX 5090 + WARP verification at head
be58082eb266merged cleanly ontomain(63bcca43c6a0):crates/victory-gpu/src/primitive.rs:158-192):raw_exp == 0xff && man != 0returnssign | 0x7e00 | (man >> 13) as u16, preserving sign + top 10 payload bits and forcing the quiet bit (0x0200) so low-payload sNaNs (e.g.0x7f80_0001) quiet properly instead of collapsing to±Inf.±Inf:exp >= 31returnssign | 0x7c00; max finite boundary0x477f_efff -> 0x7bff, tie-to-even65520.0(0x477f_f000) rounds to0x7c00.exp < -10(< 2^-25) returnssign(±0);-10 <= exp <= 0rounds to nearest-even with carry naturally promoting max subnormal to min normal0x0400.lsb = (man >> 13) & 1; sign | (half + ((man + 0x0fff + lsb) >> 13)) as u16handles RNE and mantissa-to-exponent carry cleanly. Confirmedprimitive.rs:128(expand_rects) is the sole call site.VICTORY_D3D12_DEBUG=1, Rust 1.98.1):cargo xtask policy:191 files ok;cargo clippy(default +--features diagnostics): 0 warningsprimitive:: draw::tests: 31/31 passed on both RTX 5090 and WARP (including exhaustive 65,536u16round-trip check).LGTM.
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.