GPU: a half exactly halfway between two rounds to the even one, not up #1220
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!1220
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1220/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?
@BastienRodz on GitHub · 2026-11-24 16:30 UTC · original
BastienRodz:split/346-half-ties-even→main· +15 −3 · 1 files · 1 commits · closed without mergingWhat's wrong
f32_to_half(crates/victory-gpu/src/primitive.rs), which packs the fourth corner of a rectangle-list draw into a half-float vertex attribute, rounds by adding0x1000before dropping the low 13 mantissa bits:So a value exactly halfway between two halves always rounds up. For example,
1 + 2^-11packs as0x3c01where round-to-nearest-even (IEEE 754, and the GPU's own conversion) gives0x3c00. The corner computed on such a value lands one ulp off the other three.@fuzeofficlal measured it in native draws on an RTX 5090 and on WARP: 10 of 16 reference pixels matched before, 16 of 16 after. They wrote the fix (#346 comment, their
c256b97).What the fix does
The retained bit decides halfway cases:
(man + 0x0fff + retained) >> 13, whereretainedis bit 13 of the mantissa. A carry out of the mantissa still goes into the exponent, as before. The subnormal branch above already rounded halfway values to even and is unchanged.Tests
primitive::tests::half_midpoints_round_to_even:1 + 2^-11gives0x3c00(even);1 + 3·2^-11gives0x3c02(even);0x3c01.On
main, the first assertion fails withleft: 15361(0x3c01),right: 15360(0x3c00).On GitHub's
windows-latestwith the upstream CI's commands (clippy-D warningswith and without--all-features, thencargo test --workspace --locked), everything passes;victory-gpu51 passed, 0 failed: https://github.com/BastienRodz/VIctory/actions/runs/45437173565Related
This is the CPU-path half of the rounding fix carried in #346, split out so it can land on its own. #346 keeps the GPU expander's copy of the same rounding. @SkillIssueXO checked the pair on an RTX 5070 Ti there: with only the old rounding put back, the byte-for-byte CPU/GPU test fails.
No game data used. AI-assisted: fix by @fuzeofficlal, split out and verified with Claude Code.
🤖 Generated with Claude Code
@Aniseto on GitHub · 2026-11-24 16:37 UTC · original
Ran the new rounding test at
71bd075:Environment: Windows 11 Pro build 26200 x64, Intel Core i5-12400F, 64 GB RAM, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only) driver 32.0.16.2124, Rust 1.98.1 (pinned by
rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.primitive::tests::half_midpoints_round_to_evenpasses and the rest of the module is unaffected. It is a unit-level test, so the adapter is not the variable; the datapoint is the pinned 1.98.1 toolchain. No test report on this PR yet.Not tested: a title whose rasterizer actually hits the midpoint case (no game data here), RDNA2/RDNA4 and Intel GPUs.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; no game data was used.
@shortselow-byte on GitHub · 2026-11-24 16:54 UTC · original
I checked
f32_to_halfat headb4e4647(same result at the earlier71bd075) on every f32 bit pattern (2^32 values) against an independent reference (exactf64arithmetic withround_ties_even):0x7f800001gives0x7c00). That is the other half of #843, out of this PR's scope; #1069 (closed) fixed both and passed the same check with 0 mismatches overall.@Zipettte on GitHub · 2026-11-24 17:59 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
b4e4647:cargo test -p victory-gpupasses, 51 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@Marvisak on GitHub · 2026-11-25 00:35 UTC · original
Automated triage for the maintainers. Closing because another open pull request covers the same change.
See #1732. The same round-half-to-even formula as #1732, which also fixes NaN and has the fuller test (every half round-trips).
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed