Round rectangle half-float attributes to even and preserve NaNs #2702

Open
VlREX wants to merge 1 commit from upstream-pr/2704 into main
VlREX commented 2026-11-25 18:28:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by VlREX on 2026-11-25T18:28:39Z.


The CPU rectangle expansion rounded normal half-float midpoints upward even when the lower neighbour was even. It also converted NaNs into infinities. Correct both conversions when encoding the generated fourth vertex. The new tests cover all adjacent positive finite half pairs and both signs at every midpoint, plus three NaN encodings. Both tests failed before the fix. All 11 primitive module tests passed in an isolated Windows GNU run.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6611042972 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2704). Originally posted by [VlREX](https://github.com/VlREX) on 2026-11-25T18:28:39Z. --- The CPU rectangle expansion rounded normal half-float midpoints upward even when the lower neighbour was even. It also converted NaNs into infinities. Correct both conversions when encoding the generated fourth vertex. The new tests cover all adjacent positive finite half pairs and both signs at every midpoint, plus three NaN encodings. Both tests failed before the fix. All 11 primitive module tests passed in an isolated Windows GNU run.
fuzeofficlal commented 2026-11-25 19:06:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T18:43:42Z.


Independent Windows 11 + WARP verification and IEEE-754 review of 0544d491 (on 13f91ca):

Verification (rustc 1.98.1 MSVC)

  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings and --features diagnostics: 0 warnings.
  • cargo test --locked -p victory-gpu --lib primitive::tests: 11 passed, 0 failed (including half_midpoints_round_to_the_even_neighbour across all 0..0x7bff positive/negative midpoints and half_nan_attributes_remain_nan).
  • VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1: 200 passed, 0 failed, 1 ignored.

Review Notes

  • IEEE-754 binary32 -> binary16 edge cases all check out: NaN quietening (sign | 0x7e00 | (man >> 13) keeps sign/top payload bits and ensures sNaNs with only low payload bits never collapse to ±Inf), -0.0 sign preservation, subnormal round-to-nearest-even (exp == -10 exact midpoint to 0, exp == 0 max subnormal carry 0x3ff + 1 -> 0x0400), normal round-to-nearest-even (rounding_bias = 0xfff + ((man >> 13) & 1)), and overflow at 65520.0 -> ±Inf.
  • Cleanly orthogonal to #2603 (victory-shader/src/emit/rect.rs).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7171311807 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2704#issuecomment-7171311807). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T18:43:42Z. --- Independent Windows 11 + WARP verification and IEEE-754 review of `0544d491` (on `13f91ca`): ### Verification (`rustc 1.98.1` MSVC) - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` and `--features diagnostics`: **0 warnings**. - `cargo test --locked -p victory-gpu --lib primitive::tests`: **11 passed, 0 failed** (including `half_midpoints_round_to_the_even_neighbour` across all `0..0x7bff` positive/negative midpoints and `half_nan_attributes_remain_nan`). - `VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1`: **200 passed, 0 failed, 1 ignored**. ### Review Notes - IEEE-754 binary32 -> binary16 edge cases all check out: NaN quietening (`sign | 0x7e00 | (man >> 13)` keeps sign/top payload bits and ensures sNaNs with only low payload bits never collapse to `±Inf`), `-0.0` sign preservation, subnormal round-to-nearest-even (`exp == -10` exact midpoint to `0`, `exp == 0` max subnormal carry `0x3ff + 1 -> 0x0400`), normal round-to-nearest-even (`rounding_bias = 0xfff + ((man >> 13) & 1)`), and overflow at `65520.0 -> ±Inf`. - Cleanly orthogonal to #2603 (`victory-shader/src/emit/rect.rs`).
kotekompotek commented 2026-11-25 19:06:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T18:50:08Z.


Both fixes are textbook: the 0xfff + ((man>>13)&1) bias is round-to-nearest-even, and the NaN path keeps sign + payload under a set quiet bit instead of collapsing to infinity. Exhaustive adjacent-pair coverage is the right test here.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171465777 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2704#issuecomment-7171465777). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T18:50:08Z. --- Both fixes are textbook: the 0xfff + ((man>>13)&1) bias is round-to-nearest-even, and the NaN path keeps sign + payload under a set quiet bit instead of collapsing to infinity. Exhaustive adjacent-pair coverage is the right test here.
oni-swr commented 2026-11-25 19:06:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T18:56:58Z.


Independent WARP/CPU verification (claim: Marvisak/VIctory#1633)

  • PR head: 0544d491f469debd5a7b5d367e911121e87b7c1c / origin/main: 13f91caee25f2fdf2c062be5f7a27f058e51cbca
  • State: OPEN, non-draft; git merge-tree --write-tree origin/main <head> merges cleanly; no prior oni-swr comment on this head.
  • Environment: Windows 11 Pro 10.0.26200, VICTORY_WARP=1 + VICTORY_D3D12_WARP=1 (WARP only, no physical GPU, no game files/dumps/retail hashes), dxil.dll 1.8.2502.11 (Windows SDK 10.0.26100.0, via VICTORY_DXIL), rustc 1.98.1 (48a229cea 2026-09-01), debug profile, --locked.

Commands / results (baseline = origin/main, same environment)

cargo test -p victory-shader --locked
cargo test -p victory-gpu --locked
cargo clippy -p victory-gpu --locked --all-targets
  • victory-gpu: 197 passed / 0 failed / 1 ignored (+2 vs baseline 195). New primitive::tests::half_midpoints_round_to_the_even_neighbour and half_nan_attributes_remain_nan ok.
  • victory-shader: 267 / 3 / 3, identical to baseline (the same 3 pre-existing WARP failures; unaffected by this PR).
  • clippy -p victory-gpu: 0 warnings, 0 errors (baseline 0).

Negative control: with rounding_bias reverted to 0x1000 and the NaN branch disabled, both new tests FAIL (the existing third primitive test still passes); reverted afterwards.

Code review: No bugs found. Round-to-even via 0xfff + lsb is correct for normals including carry into the exponent / infinity; subnormals already rounded to even. NaN keeps its sign, is forced quiet (0x7e00) and keeps the top 10 payload bits, so a signaling NaN with payload only in the low bits becomes a quiet NaN, never infinity. The midpoint test covers every adjacent half pair 0..0x7bff incl. subnormals; the largest-finite-to-infinity midpoint is not covered.

Not tested: physical GPU hardware (RX 7800 XT or any), retail game run, release build, other crates.

AI use: Claude Code (Claude Sonnet 5.5) ran the commands and reviewed the diff; the results above are from the actual runs.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171619759 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2704#issuecomment-7171619759). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T18:56:58Z. --- **Independent WARP/CPU verification** (claim: Marvisak/VIctory#1633) - PR head: `0544d491f469debd5a7b5d367e911121e87b7c1c` / `origin/main`: `13f91caee25f2fdf2c062be5f7a27f058e51cbca` - State: OPEN, non-draft; `git merge-tree --write-tree origin/main <head>` merges cleanly; no prior `oni-swr` comment on this head. - Environment: Windows 11 Pro 10.0.26200, `VICTORY_WARP=1` + `VICTORY_D3D12_WARP=1` (WARP only, no physical GPU, no game files/dumps/retail hashes), `dxil.dll` 1.8.2502.11 (Windows SDK 10.0.26100.0, via `VICTORY_DXIL`), rustc 1.98.1 (48a229cea 2026-09-01), debug profile, `--locked`. **Commands / results** (baseline = `origin/main`, same environment) ``` cargo test -p victory-shader --locked cargo test -p victory-gpu --locked cargo clippy -p victory-gpu --locked --all-targets ``` - victory-gpu: 197 passed / 0 failed / 1 ignored (+2 vs baseline 195). New `primitive::tests::half_midpoints_round_to_the_even_neighbour` and `half_nan_attributes_remain_nan` ok. - victory-shader: 267 / 3 / 3, identical to baseline (the same 3 pre-existing WARP failures; unaffected by this PR). - clippy -p victory-gpu: 0 warnings, 0 errors (baseline 0). **Negative control:** with `rounding_bias` reverted to `0x1000` and the NaN branch disabled, both new tests FAIL (the existing third primitive test still passes); reverted afterwards. **Code review:** No bugs found. Round-to-even via `0xfff + lsb` is correct for normals including carry into the exponent / infinity; subnormals already rounded to even. NaN keeps its sign, is forced quiet (0x7e00) and keeps the top 10 payload bits, so a signaling NaN with payload only in the low bits becomes a quiet NaN, never infinity. The midpoint test covers every adjacent half pair 0..0x7bff incl. subnormals; the largest-finite-to-infinity midpoint is not covered. **Not tested:** physical GPU hardware (RX 7800 XT or any), retail game run, release build, other crates. **AI use:** Claude Code (Claude Sonnet 5.5) ran the commands and reviewed the diff; the results above are from the actual runs.
cloph-dsp commented 2026-11-25 20:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T19:26:46Z.


Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC, --locked, CARGO_BUILD_JOBS=2, no game files and no GPU.

  • cargo test --locked -p victory-gpu --lib half --quiet → 3 passed, 0 failed (198 filtered).
  • cargo test --locked -p victory-gpu --lib primitive::tests --quiet → 11 passed, 0 failed (187 filtered).
  • Negative control: the two new test names (half_midpoints_round_to_the_even_neighbour, half_nan_attributes_remain_nan) are absent from origin/main in crates/victory-gpu/src/primitive.rs (git grep returned no matches).
  • git diff --check origin/main..HEAD was clean for the PR branch.

No blocking findings. The only output noise is two pre-existing deprecation warnings in crates/victory-gpu/src/object.rs (Atomic::fetch_update), unrelated to this diff.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7172307497 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2704#issuecomment-7172307497). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T19:26:46Z. --- Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC, `--locked`, `CARGO_BUILD_JOBS=2`, no game files and no GPU. - `cargo test --locked -p victory-gpu --lib half --quiet` → 3 passed, 0 failed (198 filtered). - `cargo test --locked -p victory-gpu --lib primitive::tests --quiet` → 11 passed, 0 failed (187 filtered). - Negative control: the two new test names (`half_midpoints_round_to_the_even_neighbour`, `half_nan_attributes_remain_nan`) are absent from `origin/main` in `crates/victory-gpu/src/primitive.rs` (`git grep` returned no matches). - `git diff --check origin/main..HEAD` was clean for the PR branch. No blocking findings. The only output noise is two pre-existing deprecation warnings in `crates/victory-gpu/src/object.rs` (`Atomic::fetch_update`), unrelated to this diff. AI-assisted (Hy4 flash).
Marvisak commented 2026-11-25 23:06:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:21:44Z.


Automated triage for the maintainers.

Merge candidate (recommend a look). f32_to_half in crates/victory-gpu/src/primitive.rs (used when the CPU writes the fourth vertex of a rectangle with half-float attributes) rounded normal midpoints up regardless of parity and turned NaNs into infinities. Now normals use the standard round-to-nearest-even bias (0xfff + lsb), matching the subnormal path that already rounded to even, and NaNs stay quiet NaNs with their sign. I checked the overflow edge: 65520.0 still becomes infinity, as the existing test expects, and infinite inputs still give infinity because the NaN test comes first. The new test checks every adjacent pair of finite halves against the even neighbour, so it compares against IEEE rounding rather than repeating the code.

CI: check passing on this head.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176266904 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2704#issuecomment-7176266904). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:21:44Z. --- <!-- victory-triage v1 head=0544d491f469debd5a7b5d367e911121e87b7c1c verdict=merge-candidate at=2026-11-25T22:22:30Z --> Automated triage for the maintainers. **Merge candidate (recommend a look).** `f32_to_half` in `crates/victory-gpu/src/primitive.rs` (used when the CPU writes the fourth vertex of a rectangle with half-float attributes) rounded normal midpoints up regardless of parity and turned NaNs into infinities. Now normals use the standard round-to-nearest-even bias (`0xfff + lsb`), matching the subnormal path that already rounded to even, and NaNs stay quiet NaNs with their sign. I checked the overflow edge: 65520.0 still becomes infinity, as the existing test expects, and infinite inputs still give infinity because the NaN test comes first. The new test checks every adjacent pair of finite halves against the even neighbour, so it compares against IEEE rounding rather than repeating the code. CI: `check` passing on this head. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 05:02:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T04:23:02Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-gpu --lib primitive::tests: 11 passed, 0 failed (including new half_midpoints_round_to_the_even_neighbour and half_nan_attributes_remain_nan).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068523184 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2704#pullrequestreview-6068523184). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T04:23:02Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-gpu --lib primitive::tests`: **11 passed, 0 failed** (including new `half_midpoints_round_to_the_even_neighbour` and `half_nan_attributes_remain_nan`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2704:upstream-pr/2704'
git switch 'upstream-pr/2704'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2704'
git switch 'upstream-pr/2704'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2704'
git switch 'upstream-pr/2704'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2704'
git switch 'main'
git merge --squash 'upstream-pr/2704'
git switch 'main'
git merge --ff-only 'upstream-pr/2704'
git switch 'main'
git merge 'upstream-pr/2704'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2702
No description provided.