GPU: write half subnormals from f32 rectangle outputs #418

Merged
enzoduarte1 merged 1 commit from upstream-pr/418 into main 2026-11-24 08:10:37 +00:00
enzoduarte1 commented 2026-11-24 03:10:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by enzoduarte1 on 2026-11-24T03:10:15Z.


What

f32_to_half returned signed zero for every exp <= 0, while half_to_f32 does decode half subnormals. An f16 rectangle output with a small value (for example 2^-24, which is exactly 0x0001) was therefore written as zero.

The conversion now rounds the f32 significand into the half subnormal field for exponents down to -10, with ties going to an even mantissa. Values below half the smallest subnormal still become zero, and normal values are untouched. A test covers both conversion directions, the largest subnormal, the tie cases, and sign.

This is separate from PR #260, which fixes the rounding carry at the other end of the normal path.

Tested

  • Windows 11, Rust 1.98.1, x86_64-pc-windows-gnu (no MSVC linker on this machine).
  • cargo test -p victory-gpu --lib primitive::: 3 passed.
  • cargo test --workspace --exclude victory-loader -- --test-threads=1: all suites passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean here; on a full rebuild the pre-existing host.rs warning fixed by PR #355 also appears.
  • rustfmt --edition 2024 --check crates/victory-gpu/src/primitive.rs and git diff --check: clean.
  • cargo xtask policy: 151 files ok. No game files or data taken from them were added.
  • Not tested: cargo test -p victory-loader --test load_probe. Its fixture passes MSVC's /DELAYLOAD flag, which MinGW rejects here; the same failure occurs on unmodified main.

Checklist

  • cargo fmt, cargo clippy --workspace --all-targets and cargo test --workspace pass — see the toolchain limitations above; the changed crate is clean.
  • cargo xtask policy passes. The change adds no game files or data taken from them (docs/asset-policy.md).
  • If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573746398 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/418). Originally posted by [enzoduarte1](https://github.com/enzoduarte1) on 2026-11-24T03:10:15Z. --- ## What `f32_to_half` returned signed zero for every `exp <= 0`, while `half_to_f32` does decode half subnormals. An f16 rectangle output with a small value (for example `2^-24`, which is exactly `0x0001`) was therefore written as zero. The conversion now rounds the f32 significand into the half subnormal field for exponents down to `-10`, with ties going to an even mantissa. Values below half the smallest subnormal still become zero, and normal values are untouched. A test covers both conversion directions, the largest subnormal, the tie cases, and sign. This is separate from PR #260, which fixes the rounding carry at the other end of the normal path. ## Tested - Windows 11, Rust 1.98.1, `x86_64-pc-windows-gnu` (no MSVC linker on this machine). - `cargo test -p victory-gpu --lib primitive::`: 3 passed. - `cargo test --workspace --exclude victory-loader -- --test-threads=1`: all suites passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean here; on a full rebuild the pre-existing `host.rs` warning fixed by PR #355 also appears. - `rustfmt --edition 2024 --check crates/victory-gpu/src/primitive.rs` and `git diff --check`: clean. - `cargo xtask policy`: 151 files ok. No game files or data taken from them were added. - Not tested: `cargo test -p victory-loader --test load_probe`. Its fixture passes MSVC's `/DELAYLOAD` flag, which MinGW rejects here; the same failure occurs on unmodified `main`. ## Checklist - [ ] `cargo fmt`, `cargo clippy --workspace --all-targets` and `cargo test --workspace` pass — see the toolchain limitations above; the changed crate is clean. - [x] `cargo xtask policy` passes. The change adds no game files or data taken from them (`docs/asset-policy.md`). - [x] If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
towiice commented 2026-11-24 06:52:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by towiice on 2026-11-24T03:21:28Z.

Review: COMMENTED


Tested PR head eb30a0d on Windows 11 x64 build 10.0.26300 (26H2), NVIDIA GeForce GTX 1650 SUPER (driver 610.88), Rust 1.100.0 (stable-x86_64-pc-windows-gnullvm):

  • cargo test -p victory-gpu -- --test-threads=4: 44 passed, 0 failed, 1 ignored (0.57 s).

All victory-gpu tests (including the new f32-to-half subnormal output tests) pass cleanly.

<!-- greyfinch-sync:Marvisak/VIctory:review:6033179186 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/418#pullrequestreview-6033179186). Originally posted by [towiice](https://github.com/towiice) on 2026-11-24T03:21:28Z. **Review:** COMMENTED --- Tested PR head `eb30a0d` on Windows 11 x64 build 10.0.26300 (26H2), NVIDIA GeForce GTX 1650 SUPER (driver 610.88), Rust 1.100.0 (`stable-x86_64-pc-windows-gnullvm`): - `cargo test -p victory-gpu -- --test-threads=4`: **44 passed, 0 failed, 1 ignored** (0.57 s). All `victory-gpu` tests (including the new f32-to-half subnormal output tests) pass cleanly.
mercuryVM commented 2026-11-24 06:52:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T06:23:23Z.

Review: APPROVED


Tested eb30a0d on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed).

I checked the subnormal path by hand:

  • For a half exponent e in [-10, 0], the value is sig · 2^(e - 15 - 23), and a half subnormal is m · 2^-24. So m = sig >> (14 - e), which is the shift used.
  • At e = -10 (shift 24), q = 0. Exactly 2^-25 is a tie and rounds to even (0), and anything above it rounds to 1.
  • At e = 0 the rounding can carry m to 0x400. That is the bit pattern of the smallest normal, so the carry encodes correctly with no special case.
  • Values below 2^-25 still flush to signed zero, and the normal path is unchanged.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6034621115 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/418#pullrequestreview-6034621115). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T06:23:23Z. **Review:** APPROVED --- Tested eb30a0d on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (265 passed, 0 failed). I checked the subnormal path by hand: - For a half exponent `e` in `[-10, 0]`, the value is `sig · 2^(e - 15 - 23)`, and a half subnormal is `m · 2^-24`. So `m = sig >> (14 - e)`, which is the shift used. - At `e = -10` (shift 24), `q = 0`. Exactly `2^-25` is a tie and rounds to even (0), and anything above it rounds to 1. - At `e = 0` the rounding can carry `m` to `0x400`. That is the bit pattern of the smallest normal, so the carry encodes correctly with no special case. - Values below `2^-25` still flush to signed zero, and the normal path is unchanged. No issues found. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 09:05:28 +00:00
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!418
No description provided.