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

Merged
Razdva122 merged 1 commit from upstream-pr/2186 into main 2026-11-25 21:55:44 +00:00
Razdva122 commented 2026-11-25 07:18:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Razdva122 on 2026-11-25T07:18:52Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6599344431 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2186). Originally posted by [Razdva122](https://github.com/Razdva122) on 2026-11-25T07:18:52Z. --- 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://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155589904). 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.
DenRakEiw commented 2026-11-25 08:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T07:24:28Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib emit::semantics_tests:: — 32 passed, 0 failed (1 ignored) on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean rounding fix for unsigned-to-float conversion on WARP, verified across both RTX 5090 and WARP. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6053417559 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2186#pullrequestreview-6053417559). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T07:24:28Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC): - `cargo test -p victory-shader --lib emit::semantics_tests::` — **32 passed, 0 failed** (1 ignored) on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean rounding fix for unsigned-to-float conversion on WARP, verified across both RTX 5090 and WARP. Looks good. AI-assisted (Gemini 4 Neon).
sinan-cmyk commented 2026-11-25 08:06:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T07:50:16Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156307752 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2186#issuecomment-7156307752). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T07:50:16Z. --- ### 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).
MamaLeVrai commented 2026-11-25 08:06:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-25T07:57:59Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156451931 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2186#issuecomment-7156451931). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T07:57:59Z. --- 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.
catminou4 commented 2026-11-25 09:05:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:10:09Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. Unsigned-to-float conversion correctly rounded on WARP... — cvt rounding fix; relates to #1326's fcmp WARP fix theme.

<!-- greyfinch-sync:Marvisak/VIctory:review:6053923135 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2186#pullrequestreview-6053923135). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:10:09Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 144 passed / 0 failed / 2 ignored. Unsigned-to-float conversion correctly rounded on WARP... — cvt rounding fix; relates to #1326's fcmp WARP fix theme.
steven-seagull27 commented 2026-11-25 10:07:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-25T09:18:13Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158148529 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2186#issuecomment-7158148529). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-25T09:18:13Z. --- 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.
Marvisak commented 2026-11-25 13:02:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T12:38:15Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7162647689 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2186#issuecomment-7162647689). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T12:38:15Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-25 22:03:33 +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!2184
No description provided.