Skip to content

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

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
Razdva122:shader/exact-u32-to-f32
Nov 25, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
Razdva122:shader/exact-u32-to-f32

Conversation

@Razdva122

Copy link
Copy Markdown
Contributor

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.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head b21594a 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

Copy link
Copy Markdown

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, 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

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Owner

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
Marvisak merged commit 084d4ff into Marvisak:main Nov 25, 2026
1 check passed
Gandalem added a commit to Gandalem/VIctory that referenced this pull request Nov 26, 2026
Apply complete, uniquely matching upstream hunks in dependency order, preserving fork-specific raw structured buffer lowering and configurable descriptor capacity. Defer incompatible shader ABI and cross-module changes until GPU reconciliation.

704d25e Shaders: v_mul_legacy_f32 treats denormal operands as zero (Marvisak#682)
cc7ec2a Shaders: 64-bit integer compares on their dwords (AMD orders a shared-dword i64 compare wrong) (Marvisak#1599)
77fd819 Shaders: cube-map face coordinates read denormals as zeros (Marvisak#1766)
084d4ff Shaders: round full-width unsigned integer conversions once (Marvisak#2186)
f3578e3 Shaders: decode f16 inline float constants in whole-wave v_add_f16 simulation (Marvisak#2493)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants