shader: lower compute v_cvt_u32_f32 with RDNA2 saturation #1898

Merged
henriazz10 merged 1 commit from upstream-pr/1905 into main 2026-11-24 21:23:47 +00:00
henriazz10 commented 2026-11-24 20:44:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by henriazz10 on 2026-11-24T20:44:40Z.


Change

Refs #721. This is the v_cvt_u32_f32 slice (item 5) claimed in https://github.com/R0Y00/Xbox2Windows/issues/721#issuecomment-7143412663. It touches only tools/compute_store_aot.py, tests/compute_store_check.py, CMakeLists.txt and docs/experiments.md.

  • v_cvt_u32_f32_e32 vD, S0 converts a binary32 source to an unsigned 32-bit integer with RDNA2 saturation: NaN and values <= 0.0 give 0, values >= 2^32 (including +inf) give 0xffffffff, and values in (0, 2^32) truncate toward zero.
  • Emits the cvt_u32_f32 helper only when called, clamping finite values to 4294967040.0f (2^32 - 256) before uint() so even speculatively evaluated casts stay in range.
  • S0 accepts a VGPR holding a known word, a ready SGPR, a 32-bit literal, an integer inline constant or an inline float constant (FLOAT_INLINE), including NaN, infinity and denormal constants.
  • Refused, each with its own control:
    • unknown SGPR (s30), pending SGPR (s12), unknown VGPR (v40), unaccepted float literal (1.5), out-of-range integer literal (0x100000000);
    • destination past v255 (v256);
    • other spellings (v_cvt_u32_f32_e64, bare v_cvt_u32_f32), input modifiers (-v1, |v1|), output modifiers (clamp, mul:2) and register range (v[1:2]).

Verification

Commit 0c560c21, rebased onto 27cf223d (after #1904 merged). The draws, controls() and the LLVM 15 round trip were re-run on 0c560c21. Windows 11, DXC 10.0.26100.0, Python 3.12 (out/pe-env), debug layer enabled. offscreen_check was built from an earlier main; this PR does not change it.

python -B tests/compute_store_check.py draw-cvt-u32-f32 <dxc> <offscreen_check> warp
python -B tests/compute_store_check.py draw-cvt-u32-f32 <dxc> <offscreen_check> hardware
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
git diff --check HEAD~1
docker run --rm -v "<worktree>:/src" x2w-llvm15 bash -c 'cp -r /src /w && cd /w && python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 /usr/lib/x86_64-linux-gnu/libLLVM-15.so.1; echo binary_exit=$?'
Backend / Check Adapter / driver Result
WARP Microsoft Basic Render Driver 10.0.26100.9818 exit 0, groups=1 compared_words=320 mismatches=0, debug_errors=0 debug_warnings=0
hardware NVIDIA GeForce RTX 5080, 32.0.16.1692 exit 0, groups=1 compared_words=320 mismatches=0, debug_errors=0 debug_warnings=0
LLVM 15 binary x2w-llvm15 Docker binary_exit=0
docs_links_check.py — exit 0 (Checked 18 Markdown files and 376 links.)
bidi_controls_check.py — exit 0 (Checked 1330 tracked source, script and build/CI files: no bidirectional controls.)
git diff --check HEAD~1 — exit 0

cvt_u32_f32_binary() decodes the assembled fixture back to the same v_cvt_u32_f32_e32 lines and requires the same translation.

Negative control. With tools/compute_store_aot.py from origin/main (b80058f0), cvt_u32_f32_controls() fails with ValueError: Unsupported compute instruction: v_cvt_u32_f32_e32 v4, v1.

Evidence

The fixture is source-built in LLVM 15 spelling (CVT_U32_F32, 32 threads, stride 16, 128 active words and 128..319 sentinel). It covers 0.75, 1.5, 3.0..3*2^29, 2^32 - 256, 2^32, > 2^32, FLT_MAX, +inf, sNaN, qNaN, -0.0, -denorm, -inf, -1.0, 4.0 and an SGPR 5.0, comparing all 320 words against an independent Python model (cvt_u32_f32_word).

  • Translation controls. cvt_u32_f32_controls() checks the emitted cvt_u32_f32 helper, helper omission when unused, integer inline 0, NaN/denormal constants and all rejection conditions.
  • Reference controls. Each must fail at its first differing word:
    • round instead of trunc: word 0;
    • wrap at 2^32: word 65;
    • NaN saturates to 0xffffffff: word 3;
    • sentinel past group: word 128.
  • Recompiled-HLSL mutations. Each must fail on the device:
    • 2^32 saturation dropped;
    • 4.0 replaced by 2.0;
    • 0.75 replaced by 1.0.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed (docs/experiments.md).
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6591048032 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1905). Originally posted by [henriazz10](https://github.com/henriazz10) on 2026-11-24T20:44:40Z. --- ## Change Refs #721. This is the `v_cvt_u32_f32` slice (item 5) claimed in https://github.com/R0Y00/Xbox2Windows/issues/721#issuecomment-7143412663. It touches only `tools/compute_store_aot.py`, `tests/compute_store_check.py`, `CMakeLists.txt` and `docs/experiments.md`. - `v_cvt_u32_f32_e32 vD, S0` converts a binary32 source to an unsigned 32-bit integer with RDNA2 saturation: NaN and values `<= 0.0` give `0`, values `>= 2^32` (including `+inf`) give `0xffffffff`, and values in `(0, 2^32)` truncate toward zero. - Emits the `cvt_u32_f32` helper only when called, clamping finite values to `4294967040.0f` (`2^32 - 256`) before `uint()` so even speculatively evaluated casts stay in range. - `S0` accepts a VGPR holding a known word, a ready SGPR, a 32-bit literal, an integer inline constant or an inline float constant (`FLOAT_INLINE`), including NaN, infinity and denormal constants. - Refused, each with its own control: - unknown SGPR (`s30`), pending SGPR (`s12`), unknown VGPR (`v40`), unaccepted float literal (`1.5`), out-of-range integer literal (`0x100000000`); - destination past `v255` (`v256`); - other spellings (`v_cvt_u32_f32_e64`, bare `v_cvt_u32_f32`), input modifiers (`-v1`, `|v1|`), output modifiers (`clamp`, `mul:2`) and register range (`v[1:2]`). ## Verification Commit `0c560c21`, rebased onto `27cf223d` (after #1904 merged). The draws, `controls()` and the LLVM 15 round trip were re-run on `0c560c21`. Windows 11, DXC 10.0.26100.0, Python 3.12 (`out/pe-env`), debug layer enabled. `offscreen_check` was built from an earlier `main`; this PR does not change it. ```powershell python -B tests/compute_store_check.py draw-cvt-u32-f32 <dxc> <offscreen_check> warp python -B tests/compute_store_check.py draw-cvt-u32-f32 <dxc> <offscreen_check> hardware python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py git diff --check HEAD~1 ``` ```sh docker run --rm -v "<worktree>:/src" x2w-llvm15 bash -c 'cp -r /src /w && cd /w && python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 /usr/lib/x86_64-linux-gnu/libLLVM-15.so.1; echo binary_exit=$?' ``` | Backend / Check | Adapter / driver | Result | |---|---|---| | WARP | Microsoft Basic Render Driver 10.0.26100.9818 | exit 0, `groups=1 compared_words=320 mismatches=0`, `debug_errors=0 debug_warnings=0` | | hardware | NVIDIA GeForce RTX 5080, 32.0.16.1692 | exit 0, `groups=1 compared_words=320 mismatches=0`, `debug_errors=0 debug_warnings=0` | | LLVM 15 binary | `x2w-llvm15` Docker | `binary_exit=0` | | `docs_links_check.py` | — | exit 0 (`Checked 18 Markdown files and 376 links.`) | | `bidi_controls_check.py` | — | exit 0 (`Checked 1330 tracked source, script and build/CI files: no bidirectional controls.`) | | `git diff --check HEAD~1` | — | exit 0 | `cvt_u32_f32_binary()` decodes the assembled fixture back to the same `v_cvt_u32_f32_e32` lines and requires the same translation. **Negative control.** With `tools/compute_store_aot.py` from `origin/main` (`b80058f0`), `cvt_u32_f32_controls()` fails with `ValueError: Unsupported compute instruction: v_cvt_u32_f32_e32 v4, v1`. ## Evidence The fixture is source-built in LLVM 15 spelling (`CVT_U32_F32`, 32 threads, stride 16, 128 active words and 128..319 sentinel). It covers `0.75`, `1.5`, `3.0..3*2^29`, `2^32 - 256`, `2^32`, `> 2^32`, `FLT_MAX`, `+inf`, `sNaN`, `qNaN`, `-0.0`, `-denorm`, `-inf`, `-1.0`, `4.0` and an SGPR `5.0`, comparing all 320 words against an independent Python model (`cvt_u32_f32_word`). - **Translation controls.** `cvt_u32_f32_controls()` checks the emitted `cvt_u32_f32` helper, helper omission when unused, integer inline `0`, NaN/denormal constants and all rejection conditions. - **Reference controls.** Each must fail at its first differing word: - round instead of trunc: word `0`; - wrap at `2^32`: word `65`; - NaN saturates to `0xffffffff`: word `3`; - sentinel past group: word `128`. - **Recompiled-HLSL mutations.** Each must fail on the device: - `2^32` saturation dropped; - `4.0` replaced by `2.0`; - `0.75` replaced by `1.0`. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed (`docs/experiments.md`). - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tedin7 commented 2026-11-24 21:01:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:57:12Z.

Review: COMMENTED


Review of head 74446809f5 (TIER_D_ISOLATED_SHADER_OPS; files: CMakeLists.txt, docs/experiments.md, tests/compute_store_check.py, tools/compute_store_aot.py).

Commands executed locally:

  • git diff --check origin/main...HEAD: rc 0
  • python3 tests/docs_links_check.py: pass (18 Markdown files, 376 links)
  • python3 tests/bidi_controls_check.py: pass (1330 files, no bidirectional controls)
  • python3 -B tests/compute_store_check.py (controls run before the mode argument): pass; the usage error afterwards is the missing mode argument only
  • win2025 1905 --wait 900 at 74446809f5: Debug (--preset dev) 66/66 passed, Release /O2 (--preset release) 66/66 passed, including compute_store_aot_cvt_u32_f32_warp

Mutations of tool logic (each reverted with git checkout -- .):

  1. tools/compute_store_aot.py: helper emission gate replaced by "if False": cvt_u32_f32_controls fails (rc 1, helper assertion). Killed.
  2. tools/compute_store_aot.py: the "Unverified float operand" refusal removed (unknown operand becomes word 0): cvt_u32_f32_controls fails with "Expected rejection: Unverified float operand" (rc 1). Killed.

P1: 0. P2: 0. The lowering matches the documented saturation (NaN and <= 0 give 0, >= 2^32 gives 0xffffffff, otherwise truncate), and the clamp below 2^32 keeps speculative casts in range.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047275962 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1905#pullrequestreview-6047275962). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T20:57:12Z. **Review:** COMMENTED --- Review of head 74446809f58b6a0b95afce2c10e3c2febd0c50a2 (TIER_D_ISOLATED_SHADER_OPS; files: CMakeLists.txt, docs/experiments.md, tests/compute_store_check.py, tools/compute_store_aot.py). Commands executed locally: - git diff --check origin/main...HEAD: rc 0 - python3 tests/docs_links_check.py: pass (18 Markdown files, 376 links) - python3 tests/bidi_controls_check.py: pass (1330 files, no bidirectional controls) - python3 -B tests/compute_store_check.py (controls run before the mode argument): pass; the usage error afterwards is the missing mode argument only - win2025 1905 --wait 900 at 74446809f58b6a0b95afce2c10e3c2febd0c50a2: Debug (--preset dev) 66/66 passed, Release /O2 (--preset release) 66/66 passed, including compute_store_aot_cvt_u32_f32_warp Mutations of tool logic (each reverted with git checkout -- .): 1. tools/compute_store_aot.py: helper emission gate replaced by "if False": cvt_u32_f32_controls fails (rc 1, helper assertion). Killed. 2. tools/compute_store_aot.py: the "Unverified float operand" refusal removed (unknown operand becomes word 0): cvt_u32_f32_controls fails with "Expected rejection: Unverified float operand" (rc 1). Killed. P1: 0. P2: 0. The lowering matches the documented saturation (NaN and <= 0 give 0, >= 2^32 gives 0xffffffff, otherwise truncate), and the clamp below 2^32 keeps speculative casts in range. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 21:27:30 +00:00
tedin7 commented 2026-11-24 21:27:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:10:18Z.

Review: COMMENTED


Review of head bc349a3e9fc04365085e8ac432fae12aac4ba54a (technical comment only, no merge from this pass).

Blocked: the branch conflicts with current main, and the head has moved. GitHub reports CONFLICTING / DIRTY. git merge-tree --write-tree --name-only origin/main <head> reports a content conflict in tests/compute_store_check.py; the other files merge cleanly. The last review on record is for 74446809, so this head has no receipt. Please rebase on main and resolve it, then ask for a new review.

Commands run (Linux): git fetch origin pull/1905/head, git merge-tree --write-tree --name-only origin/main <head> (rc=1), python3 x2w_pipe.py safe-merge-check (verdict BLOCK: conflict, receipt missing).

No receipt and no merge.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047461601 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1905#pullrequestreview-6047461601). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T21:10:18Z. **Review:** COMMENTED --- Review of head `bc349a3e9fc04365085e8ac432fae12aac4ba54a` (technical comment only, no merge from this pass). **Blocked: the branch conflicts with current main, and the head has moved.** GitHub reports `CONFLICTING` / `DIRTY`. `git merge-tree --write-tree --name-only origin/main <head>` reports a content conflict in `tests/compute_store_check.py`; the other files merge cleanly. The last review on record is for `74446809`, so this head has no receipt. Please rebase on main and resolve it, then ask for a new review. Commands run (Linux): `git fetch origin pull/1905/head`, `git merge-tree --write-tree --name-only origin/main <head>` (rc=1), `python3 x2w_pipe.py safe-merge-check` (verdict BLOCK: conflict, receipt missing). No receipt and no merge. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 21:27:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:23:22Z.

Review: COMMENTED


Review of head 0c560c218e

Scope: TIER_D_ISOLATED_SHADER_OPS. Files: CMakeLists.txt (one new ctest entry plus its SKIP_RETURN_CODE for the hardware variant, nothing else), docs/experiments.md, tests/compute_store_check.py, tools/compute_store_aot.py. Author henriazz10. New head after the rebase; the earlier reviews on 74446809 and bc349a3e are superseded. Merge state: MERGEABLE, no conflict (git merge-tree --write-tree --name-only origin/main HEAD: rc=0).

Semantics read against the RDNA2 definition of v_cvt_u32_f32: NaN -> 0, values <= 0 -> 0, values >= 2^32 (including +inf) -> 0xffffffff, otherwise truncation toward zero. The helper forces NaN to 0, clamps finite values to [0, 4294967040.0f] (the largest binary32 below 2^32, so no value is lost) and saturates at 2^32 before uint(). Operands are limited to known words, modifiers/_e64/range are refused, and the helper is emitted only when used. The independent Python model in the test agrees.

Commands executed locally:

  • git diff --check origin/main...HEAD: rc=0
  • python3 tests/docs_links_check.py: rc=0 (18 files, 384 links)
  • python3 tests/bidi_controls_check.py: rc=0 (1344 files)
  • python3 -B tests/compute_store_check.py (controls run at import, incl. cvt_u32_f32_controls): all controls passed
  • x2w_pipe.py win2025 1905 --wait 900: Debug (preset dev) 68/68 passed and Release /O2 (preset release) 68/68 passed, both including compute_store_aot_cvt_u32_f32_warp
  • GitHub checks: Build and test on Windows = pass, Linux Python checks = pass, gfx1013 fixtures = pass

Mutation checks (logic in tools/compute_store_aot.py, each reverted with git checkout -- .):

  1. helper emission gate disabled: the lowered text no longer contains the helper, the control assertion failed (AssertionError), rc=1
  2. removed the Unverified float operand refusal: the rejection control failed (Expected rejection: Unverified float operand), rc=1
    Note: the helper body itself is checked on the device side, where the test recompiles HLSL with the 2^32 saturation dropped and with 4.0 replaced by 2.0 and requires each to fail (this ran in the Win2025 passes above).

Findings: P1=0, P2=0.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047639826 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1905#pullrequestreview-6047639826). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T21:23:22Z. **Review:** COMMENTED --- Review of head 0c560c218e837a0cc0badc47ea8007efb8d56a9e Scope: TIER_D_ISOLATED_SHADER_OPS. Files: CMakeLists.txt (one new ctest entry plus its SKIP_RETURN_CODE for the hardware variant, nothing else), docs/experiments.md, tests/compute_store_check.py, tools/compute_store_aot.py. Author henriazz10. New head after the rebase; the earlier reviews on 74446809 and bc349a3e are superseded. Merge state: MERGEABLE, no conflict (git merge-tree --write-tree --name-only origin/main HEAD: rc=0). Semantics read against the RDNA2 definition of v_cvt_u32_f32: NaN -> 0, values <= 0 -> 0, values >= 2^32 (including +inf) -> 0xffffffff, otherwise truncation toward zero. The helper forces NaN to 0, clamps finite values to [0, 4294967040.0f] (the largest binary32 below 2^32, so no value is lost) and saturates at 2^32 before uint(). Operands are limited to known words, modifiers/_e64/range are refused, and the helper is emitted only when used. The independent Python model in the test agrees. Commands executed locally: - git diff --check origin/main...HEAD: rc=0 - python3 tests/docs_links_check.py: rc=0 (18 files, 384 links) - python3 tests/bidi_controls_check.py: rc=0 (1344 files) - python3 -B tests/compute_store_check.py (controls run at import, incl. cvt_u32_f32_controls): all controls passed - x2w_pipe.py win2025 1905 --wait 900: Debug (preset dev) 68/68 passed and Release /O2 (preset release) 68/68 passed, both including compute_store_aot_cvt_u32_f32_warp - GitHub checks: Build and test on Windows = pass, Linux Python checks = pass, gfx1013 fixtures = pass Mutation checks (logic in tools/compute_store_aot.py, each reverted with git checkout -- .): 1. helper emission gate disabled: the lowered text no longer contains the helper, the control assertion failed (AssertionError), rc=1 2. removed the Unverified float operand refusal: the rejection control failed (Expected rejection: Unverified float operand), rc=1 Note: the helper body itself is checked on the device side, where the test recompiles HLSL with the 2^32 saturation dropped and with 4.0 replaced by 2.0 and requires each to fail (this ran in the Win2025 passes above). Findings: P1=0, P2=0. AI-assisted; commands listed were executed locally.
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
R0Y00/Xbox2Windows!1898
No description provided.