Repository navigation
GPU: a half exactly halfway between two rounds to the even one, not up - #1220
BastienRodz wants to merge 1 commit into
Conversation
|
Ran the new rounding test at 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
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. |
f32_to_half adds 0x1000 before dropping the low 13 mantissa bits, so a value exactly halfway between two halves always rounds up: 1 + 2^-11 packs as 0x3c01 instead of 0x3c00. A rectangle's fourth corner computed on such a value gets a half one ulp off. fuzeofficlal measured it in native draws of the direct path on RTX 5090 and WARP (10 of 16 reference pixels before, 16 of 16 after) and wrote the fix: the retained bit decides halfway cases. Co-Authored-By: fuzeofficlal <fuzeofficlal@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71bd075 to
b4e4647
Compare
|
I checked
|
mercuryVM
left a comment
There was a problem hiding this comment.
Tested b4e4647 on Windows 11, RTX 5070, MSVC:
cargo test -p victory-gpuon the head: the primitive tests pass, including the new midpoint test.- In one full run,
frame::tests::waits_end_on_ticks_and_count_framesfailed. That test is timing-based and this PR doesn't touch it, and it passed 3 out of 3 when rerun alone. - Merged into our fork: workspace tests, shader tests and clippy are all clean.
The rounding is right for normal halves. With r the retained bit, +0x0fff + r carries out of the low 13 bits exactly when they are above 0x1000, or equal to it with r = 1. That is round-half-to-even, and a carry into the exponent still saturates at 0x7c00 as before.
AI-assisted (Claude Code).
…two rounds to the even one, not up Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…itives, capture), verified together Merges #124 #119 #515 #934 #484 #143 #1191 #278 #553 #153 #270 #1158 #1204 #1220 #488 #1146 #631 onto main (ffe310e), each head unchanged, no conflicts, no changes of mine. cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, is clean and cargo test --workspace --locked passes (372 passed, 8 ignored; main has 342 passed, 6 ignored). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…o the even one, not up
…o the even one, not up
…) onto Marvisak#334 + integ/next Taken instead of Marvisak#282 (same draws, Marvisak#255; only one can land): Marvisak#346 expands on the GPU after the clamp, so vertex data the GPU wrote earlier in the submission is seen, and its record grouping starts at each record's first vertex. It has the stronger title evidence: the loading screen renders (justlovett0, RTX 3080), the `prepare failed`/topology-17 drops go from 256 per frame to 0 with no device removal (neonbyte1, RTX 5090/Wine; Exorion1er, RX 9070 XT/Proton; iurysf, RTX 4070), and every defect reported on it was fixed by a later commit (scratch layout cee702e, record bounds 0aebe86, count buffer 7ff1184, Wine compiler c256f83). Marvisak#282 expands on the CPU (does not see GPU-written vertices, copies bound buffers whole, three times per draw after 4d3d003) and its last head was only checked in short runs. Conflicts: 1. crates/victory-gpu/src/indirect.rs, module doc: the stack's (Wine-safe clamp in structured buffers, root signature made beside it) kept, with Marvisak#346's sentence on the rectangle expansion added. 2. indirect.rs, `bound`: Marvisak#346 splits it into `clamp_uav` (clamp + UAV barrier) and `bound` (then a fixed UAV -> INDIRECT_ARGUMENT transition); Marvisak#334 (merged just before) replaced the fixed transitions with its buffer states (`bound` asks for BUFFER_WRITE, `execute` for BUFFER_READ). Kept Marvisak#346's split with Marvisak#334's tracking, the resolution justlovett0 and the author agreed on (Marvisak#346 comments 7121242441, 7121274527): `clamp_uav` takes the buffer, starts a command and asks for BUFFER_WRITE; `bound` is `clamp_uav` (the read state comes from `execute`), no fixed transition. 3. crates/victory-gpu/src/host.rs: the stack's `PooledUpload` and Marvisak#346's `RectScratch` added at the same place; both kept. Non-textual fixes: - rectangles.rs calls `clamp_uav(list, &args.buffer, ..)` (new parameter). - rectangles.rs: the rewrite and expand passes bind the count's and the vertex buffers' host copies as root UAVs. With Marvisak#334 those copies' states are tracked, so they now ask for BUFFER_WRITE in the clamp's command (otherwise a copy a draw had moved to GENERIC_READ would be bound as a UAV in a read state). The draw's own `prepare` then asks for the read state as before. The list-owned scratch keeps Marvisak#346's own barriers. - primitive.rs: Marvisak#346's half-float rounding commit (8c7ac43) is already here through Marvisak#1220 (in Marvisak#1418), so `half_midpoints_round_to_even` is not added twice: the PR adds 8 tests, 7 are new here.
…o the even one, not up
Review workers over ~45 more PRs against the merged upstream tree. Integrated: Marvisak#1394 (antisymmetric XUserCompare), Marvisak#1390 (A8_UNORM is not in the R8 typeless family), Marvisak#1499 (deep 3D mips stay out of the thick tail, plus a regression test the PR lacked), Marvisak#1366 (mesh stage I/O does not parse VS inputs), Marvisak#1594 (the title's exit status reaches the shell), Marvisak#1299 (docs: validator prerequisite), Marvisak#1515 (dialog commands before init), Marvisak#1424 (empty submissions skip the lock), Marvisak#1144 (shader differential skips are reported), Marvisak#1129 (64 MB pipeline-worker stacks), Marvisak#1564/Marvisak#1565/Marvisak#1566 (MakeResident, Evict and SetStablePowerState succeed as the console's do), Marvisak#1250 (a zero element count reads to the end of the buffer), Marvisak#1628 (texture-creation failure logs its states). Re-applied after the upstream merge dropped them: f32_to_half NaN and ties-to-even (Marvisak#843), unique-temp library writes (Marvisak#1660), VICTORY_PIPELINE_WORKERS (Marvisak#1728), VICTORY_MODE (Marvisak#1701). Removed: the orphaned depth-bounds test file, whose implementation (9a6d9e6) the merge dropped and which no module compiled. Refused: Marvisak#1099 (writing 0 for an unpaired p1 interpolation computes wrong values; two reviewers upstream and one here reached the same conclusion). Duplicates: Marvisak#1217, Marvisak#529, Marvisak#531, Marvisak#590, Marvisak#1102, Marvisak#398, Marvisak#1150, Marvisak#1220. Gate at efda2c5: fmt 0 differing, both Clippy gates 0 errors, policy 219 files, workspace 674 passed / 0 failed with the 10 documented pre-existing GPU skips.
|
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. |
…e, DXGI, objects, primitives, capture): 9 PRs, Marvisak#553 Marvisak#153 Marvisak#270 Marvisak#1158 Marvisak#1204 Marvisak#1220 Marvisak#488 Marvisak#1146 Marvisak#631 (rebuilt on main 70564ae)
…e, DXGI, objects, primitives, capture): 9 PRs, Marvisak#553 Marvisak#153 Marvisak#270 Marvisak#1158 Marvisak#1204 Marvisak#1220 Marvisak#488 Marvisak#1146 Marvisak#631 (rebuilt on main 70564ae)
…e, DXGI, objects, primitives, capture): 9 PRs, Marvisak#553 Marvisak#153 Marvisak#270 Marvisak#1158 Marvisak#1204 Marvisak#1220 Marvisak#488 Marvisak#1146 Marvisak#631 (rebuilt on main 70564ae)
What'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