Shaders: correctly round unsigned-to-float conversion on WARP #2186

Manually merged
github merged 1 commit from gh-pr/2186/head into gh-pr/2186/base 2026-11-26 04:57:49 +00:00
Owner

@⁠Razdva122 on GitHub · 2026-11-25 07:18 UTC · original
Razdva122:shader/exact-u32-to-f32 → main · +28 −3 · 2 files · 1 commits · merged 2026-11-25 21:55 UTC

WARP can round a full-width unsigned integer conversion one ULP away from the console result. The examples from FIND-5 and #1602 both reproduce on the GitHub Windows runner. This addresses the unsigned-conversion part of FIND-5.

For v_cvt_f32_u32, convert the high and low 16-bit halves separately, then compute hi × 65536 + lo. Both halves and the scaled high half are exactly representable in f32. Only the addition rounds, including when the host fuses the multiply and add. This costs five DXIL operations in place of the unsigned cast. Other conversions keep their existing lowering.

The existing conversion probe now compares exact result bits for 84 unsigned inputs, including the reported values and both sides of rounding midpoints. On the same runner, the previous lowering missed two WARP results and the new lowering passed. Both workspace Clippy configurations and the full workspace suite passed. In a separate CPU check, the split conversion matched an integer round-to-nearest-even oracle over all 2³² inputs. Windows comparison and test log

Related PR #1602 adds conversion coverage and documents the discrepancy. This PR changes the production instruction and uses a zero-tolerance regression for it. Physical GPU performance remains unmeasured.

AI-assisted with Codex.

**@⁠Razdva122** on GitHub · 2026-11-25 07:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2186) `Razdva122:shader/exact-u32-to-f32` → `main` · +28 −3 · 2 files · 1 commits · merged 2026-11-25 21:55 UTC WARP can round a full-width unsigned integer conversion one ULP away from the console result. The examples from FIND-5 and #1602 both reproduce on the GitHub Windows runner. This addresses the unsigned-conversion part of [FIND-5](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633). For `v_cvt_f32_u32`, convert the high and low 16-bit halves separately, then compute `hi × 65536 + lo`. Both halves and the scaled high half are exactly representable in f32. Only the addition rounds, including when the host fuses the multiply and add. This costs five DXIL operations in place of the unsigned cast. Other conversions keep their existing lowering. The existing conversion probe now compares exact result bits for 84 unsigned inputs, including the reported values and both sides of rounding midpoints. On the same runner, the previous lowering missed two WARP results and the new lowering passed. Both workspace Clippy configurations and the full workspace suite passed. In a separate CPU check, the split conversion matched an integer round-to-nearest-even oracle over all 2³² inputs. [Windows comparison and test log](https://github.com/Razdva122/VIctory/actions/runs/45566641041/job/139042944213) Related PR #1602 adds conversion coverage and documents the discrepancy. This PR changes the production instruction and uses a zero-tolerance regression for it. Physical GPU performance remains unmeasured. AI-assisted with Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:57:46 +00:00
github manually merged commit b21594a44e into gh-pr/2186/base 2026-11-26 04:57:49 +00:00
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 07:50 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head b21594a4 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 07:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2186#issuecomment-7156307752) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head b21594a4 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 07:57 UTC · original

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head b21594a4 into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 701 passed, 0 failed, 10 ignored, two runs (main alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-25 07:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2186#issuecomment-7156451931) Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head `b21594a4` into `main` `940d32f` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean; the same with `--all-features`: clean. `cargo test --workspace --locked`: 701 passed, 0 failed, 10 ignored, two runs (`main` alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-25 09:18 UTC · original

Confirmed the unsigned-to-float rounding fix at b21594a4 on an RTX 5080 (driver 621.40) and built-in WARP 10.0.26100.10068. Both matched the model bit-for-bit on all 84 v_cvt_f32_u32 inputs, with zero differences between adapters.

For one direct comparison, I ran the same integer through the tests on #1602 (94a2e994) and on this PR. The outputs below are f32 bit patterns.

Unsigned input Expected nearest-even RTX 5080, #1602 → #2186 Built-in WARP, #1602 → #2186
0xffffff7f 0x4f7fffff 0x4f7fffff → 0x4f7fffff 0x4f800000 → 0x4f7fffff

The #1602 test explicitly allows that one-ULP difference on WARP and logged it. The exact check on this head passes. Across the full selected conversion test, each adapter completed 20 dispatches covering 1,154 input records. Windows 11 build 26300.10075.

**@⁠steven-seagull27** on GitHub · 2026-11-25 09:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2186#issuecomment-7158148529) Confirmed the unsigned-to-float rounding fix at `b21594a4` on an RTX 5080 (driver 621.40) and built-in WARP 10.0.26100.10068. Both matched the model bit-for-bit on all 84 `v_cvt_f32_u32` inputs, with zero differences between adapters. For one direct comparison, I ran the same integer through the tests on #1602 (`94a2e994`) and on this PR. The outputs below are f32 bit patterns. | Unsigned input | Expected nearest-even | RTX 5080, #1602 → #2186 | Built-in WARP, #1602 → #2186 | | --- | --- | --- | --- | | `0xffffff7f` | `0x4f7fffff` | `0x4f7fffff` → `0x4f7fffff` | `0x4f800000` → `0x4f7fffff` | The #1602 test explicitly allows that one-ULP difference on WARP and logged it. The exact check on this head passes. Across the full selected conversion test, each adapter completed 20 dispatches covering 1,154 input records. Windows 11 build 26300.10075.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 12:38 UTC · original

Automated triage for the maintainers.

Merge candidate. v_cvt_f32_u32 in Lower::valu_op (crates/victory-shader/src/emit/lower.rs) now converts the two 16-bit halves separately and combines them as hi * 65536 + lo through fmad. Both halves and the scaled high half are exact in f32, so the sum rounds once, to nearest even, whether or not the host fuses. That is correct on every host, not only on WARP, which misrounds the plain uitofp.

The probe in semantics_tests::conversion_probes now compares bit-exactly (INT). Its inputs are the two observed WARP misroundings plus the neighbours of the rounding midpoints at every inexact exponent. The expected values come from Rust's as f32, an independent reference. The thread confirms bit-exact results on an RTX 5080 and on WARP. CI check passes, the offline count is unchanged, and the branch merges cleanly.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 12:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2186#issuecomment-7162647689) <!-- victory-triage v1 head=b21594a44e8f483460e70e9c9014e55870d78884 verdict=merge-candidate at=2026-11-25T13:48:00Z --> Automated triage for the maintainers. **Merge candidate.** `v_cvt_f32_u32` in `Lower::valu_op` (`crates/victory-shader/src/emit/lower.rs`) now converts the two 16-bit halves separately and combines them as `hi * 65536 + lo` through `fmad`. Both halves and the scaled high half are exact in f32, so the sum rounds once, to nearest even, whether or not the host fuses. That is correct on every host, not only on WARP, which misrounds the plain `uitofp`. The probe in `semantics_tests::conversion_probes` now compares bit-exactly (`INT`). Its inputs are the two observed WARP misroundings plus the neighbours of the rounding midpoints at every inexact exponent. The expected values come from Rust's `as f32`, an independent reference. The thread confirms bit-exact results on an RTX 5080 and on WARP. CI `check` passes, the offline count is unchanged, and the branch merges cleanly. --- _Generated by [Claude Code](https://claude.ai/code)_
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!2186
No description provided.