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

Open
github-bot wants to merge 1 commit from github-bot/gh-2704 into main AGit
Owner

@⁠VlREX on GitHub · 2026-11-25 18:28 UTC · original
VlREX:fix/rect-half-rounding → main · +25 −1 · 1 files · 1 commits · open

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.

**@⁠VlREX** on GitHub · 2026-11-25 18:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2704) `VlREX:fix/rect-half-rounding` → `main` · +25 −1 · 1 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:12:24 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 18:43 UTC · original

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).
**@⁠fuzeofficlal** on GitHub · 2026-11-25 18:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2704#issuecomment-7171311807) 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`).
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 18:50 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 18:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2704#issuecomment-7171465777) 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.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 18:56 UTC · original

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.

**@⁠oni-swr** on GitHub · 2026-11-25 18:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2704#issuecomment-7171619759) **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.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 19:26 UTC · original

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).

**@⁠cloph-dsp** on GitHub · 2026-11-25 19:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2704#issuecomment-7172307497) 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:21 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 22:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2704#issuecomment-7176266904) <!-- 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)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2704/head:github-bot/gh-2704'
git switch 'github-bot/gh-2704'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2704'
git switch 'github-bot/gh-2704'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2704'
git switch 'github-bot/gh-2704'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2704'
git switch 'main'
git merge --squash 'github-bot/gh-2704'
git switch 'main'
git merge --ff-only 'github-bot/gh-2704'
git switch 'main'
git merge 'github-bot/gh-2704'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2704
No description provided.