Shader tests: f32/int conversions saturate, take NaN as 0, round to even #1602

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

@⁠vladbondarenko97 on GitHub · 2026-11-24 19:41 UTC · original
vladbondarenko97:shader-tests/f32-int-conversions-v2 → main · +110 −0 · 1 files · 1 commits · open

Adds two synthetic GPU tests in crates/victory-shader/src/emit/valu_tests.rs:

  • v_cvt_i32_f32 / v_cvt_u32_f32: truncation, saturation (infinities too) and NaN as 0, over the integer-range edges, a signalling NaN and a denormal.
  • v_cvt_f32_i32 / v_cvt_f32_u32 / v_cvt_f32_ubyte0..3: nearest-even ties past 2^24, 2^31 and 2^32.

The reference is Rust's as, which matches RDNA2. The lowering relies on the host's fptosi / fptoui / uitofp, and its comment says this was checked on an RX 6700 XT and WARP only; this adds an NVIDIA run. One finding on the way: WARP's uitofp is not correctly rounded for some u32 ≥ 2^31 (0xffffff7f gives 0x4f800000 = 2^32, not 0x4f7fffff), in repeated runs. The RTX 3080 Ti is exact. So WARP (what CI runs) gets one ULP on that op for inputs ≥ 2^31, with a printed note; hardware stays exact. Tests only.

Tested

  • NVIDIA GeForce RTX 3080 Ti and WARP, Windows 11, on main ffe310e: both new tests pass on both.
  • cargo test --workspace --locked (idle GPU): 344 passed, 0 failed, 6 ignored.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and with --all-features: clean.

Not tested

  • AMD and Intel hardware.

AI use

  • Claude Code with Claude Opus 5.5 wrote the tests and this description and ran the tests on the hardware named above.

🤖 Generated with Claude Code

**@⁠vladbondarenko97** on GitHub · 2026-11-24 19:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/1602) `vladbondarenko97:shader-tests/f32-int-conversions-v2` → `main` · +110 −0 · 1 files · 1 commits · open Adds two synthetic GPU tests in `crates/victory-shader/src/emit/valu_tests.rs`: - `v_cvt_i32_f32` / `v_cvt_u32_f32`: truncation, saturation (infinities too) and NaN as 0, over the integer-range edges, a signalling NaN and a denormal. - `v_cvt_f32_i32` / `v_cvt_f32_u32` / `v_cvt_f32_ubyte0..3`: nearest-even ties past 2^24, 2^31 and 2^32. The reference is Rust's `as`, which matches RDNA2. The lowering relies on the host's `fptosi` / `fptoui` / `uitofp`, and its comment says this was checked on an RX 6700 XT and WARP only; this adds an NVIDIA run. One finding on the way: **WARP's `uitofp` is not correctly rounded for some u32 ≥ 2^31** (`0xffffff7f` gives `0x4f800000` = 2^32, not `0x4f7fffff`), in repeated runs. The RTX 3080 Ti is exact. So WARP (what CI runs) gets one ULP on that op for inputs ≥ 2^31, with a printed note; hardware stays exact. Tests only. **Tested** - NVIDIA GeForce RTX 3080 Ti and WARP, Windows 11, on `main` `ffe310e`: both new tests pass on both. - `cargo test --workspace --locked` (idle GPU): 344 passed, 0 failed, 6 ignored. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and with `--all-features`: clean. **Not tested** - AMD and Intel hardware. **AI use** - Claude Code with Claude Opus 5.5 wrote the tests and this description and ran the tests on the hardware named above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Runs v_cvt_i32_f32 and v_cvt_u32_f32 on the host GPU and WARP over the
integer range edges, infinities, NaNs and a denormal, and v_cvt_f32_i32,
v_cvt_f32_u32 and v_cvt_f32_ubyte0..3 over the ties past 2^24, 2^31 and
2^32, checked bit for bit against the RDNA2 results (Rust's `as` has the
same truncation, saturation, NaN-as-0 and nearest-even rounding).

The lowering relies on the host's fptosi / fptoui saturating and giving 0
for NaN; its comment says this was checked on the RX 6700 XT and WARP only.

WARP's uitofp is not correctly rounded for some inputs at or above 2^31
(0xffffff7f gave 2^32, not 0xffffff00); the test allows WARP one ULP
there and says so, and keeps the hardware result exact.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:37:58 +00:00
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-24 21:13 UTC · original

Hardware run of the two new tests on head 94a2e99, since the PR asks for a non-WARP reference:

  • Machine: Windows 10 x64, Radeon RX 7800 XT (RDNA3, driver 32.0.32029.2010), Rust 1.98.1 MSVC.
  • The system D3D12 runtime here reports SM 6.5, so the test binary was opted into the Agility SDK runtime 1.616 locally (D3D12Core.dll plus the two exports; not part of the repo) to reach SM 6.6.
  • cargo test -p victory-shader --locked v_cvt_ -- --test-threads=1 --nocapture — 4 passed, 0 failed (the two new tests plus the existing v_cvt_norm_* pair).
    • v_cvt_i32_and_u32_f32_truncate_saturate_and_take_nan_as_zero: passed on hardware.
    • v_cvt_f32_i32_u32_and_ubyte_round_to_nearest_even: passed on hardware, including the tie cases past 2^24/2^31/2^32.
  • WARP was skipped: it stays at SM 6.2 on this machine even with the Agility runtime, so I could not reproduce the WARP uitofp rounding note here. The hardware side agrees with the expectations.
**@⁠Calvix2k** on GitHub · 2026-11-24 21:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1602#issuecomment-7144646963) Hardware run of the two new tests on head 94a2e99, since the PR asks for a non-WARP reference: - **Machine:** Windows 10 x64, Radeon RX 7800 XT (RDNA3, driver 32.0.32029.2010), Rust 1.98.1 MSVC. - The system D3D12 runtime here reports SM 6.5, so the test binary was opted into the Agility SDK runtime 1.616 locally (`D3D12Core.dll` plus the two exports; not part of the repo) to reach SM 6.6. - `cargo test -p victory-shader --locked v_cvt_ -- --test-threads=1 --nocapture` — **4 passed, 0 failed** (the two new tests plus the existing `v_cvt_norm_*` pair). - `v_cvt_i32_and_u32_f32_truncate_saturate_and_take_nan_as_zero`: passed on hardware. - `v_cvt_f32_i32_u32_and_ubyte_round_to_nearest_even`: passed on hardware, including the tie cases past 2^24/2^31/2^32. - WARP was skipped: it stays at SM 6.2 on this machine even with the Agility runtime, so I could not reproduce the WARP `uitofp` rounding note here. The hardware side agrees with the expectations.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:31 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1602#issuecomment-7149651595) <!-- victory-triage v1 head=94a2e994f9d296c2b823b4ffe21fc0a43f149542 verdict=needs-rebase at=2026-11-25T01:31:50Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1602'
git switch 'github-bot/gh-1602'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1602'
git switch 'github-bot/gh-1602'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1602'
git switch 'main'
git merge --squash 'github-bot/gh-1602'
git switch 'main'
git merge --ff-only 'github-bot/gh-1602'
git switch 'main'
git merge 'github-bot/gh-1602'
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!1602
No description provided.