shader: lower gfx1013 v_cvt_u32_f32 and v_cvt_i32_f32 in pixel_aot #432

Merged
JB2WIN merged 8 commits from upstream-pr/438 into main 2026-11-22 11:01:50 +00:00
JB2WIN commented 2026-11-22 03:10:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-22T03:10:18Z.


Change

Stage 3 of #360: tools/pixel_aot.py lowers the plain e32 float-to-integer conversions v_cvt_u32_f32_e32 and
v_cvt_i32_f32_e32. The source can be a VGPR, an SGPR or a hex literal. Two HLSL helpers, emitted once before
main, implement the issue's reading of the RDNA 2 ISA: truncate toward zero, NaN gives 0, and out-of-range values
saturate. The cast only ever sees an operand that is NaN-free and clamped to the largest binary32 below 2^32 or
2^31, because an out-of-range or NaN uint()/int() is undefined in HLSL and poison in LLVM. The result word goes
out through the lossless integer readback from #363.

Stacked on #392 (stage 1), which is itself stacked on #363. The branch carries #363 as rebased (d0683ed) and a
conflict-free rebase of #392's commit. When #392 is rebased, I'll realign onto it. Please merge those first, and I'll rebase this. The issue's
"stage 2" (the e64 forms of stage 1) is separate work and not part of this PR.

Refs #360. This change was AI-assisted (Claude Code).

Refused and tested as rejections: e64 spellings (including |x|, -x, clamp and omod), DPP, SDWA, float
inline constants, decimal integer inline constants, v_cvt_rpi_i32_f32 and v_cvt_flr_i32_f32, a scalar read before
its load completes, a write that overlaps an outstanding sample, and a non-entry exec mask. Decimal inline constants
are refused because fp_operand reads them as bit patterns, and I have not checked that reading for an f32 source
against the ISA. Hex sources are read as 32-bit literal bit patterns. LLVM's disassembly prints integer inline
constants in decimal, so in translated disassembly a hex token is always a literal. A hand-written 0x1 would be
read as the bit pattern 1, not as the inline constant 1.

A float export of a conversion result is translated as well, as with v_mov_b32 literals: the register bits pass
through. No draw checks that path. docs/experiments.md says so.

tools/scan_unsupported_shaders.py gets the matching pattern, written with the same literal spacing as the
translator regex, and TestRdna2Scanner covers it.

Verification

Commit under test: 17a654a (this change on top of e726864, the #392 head). After #363 was rebased, this branch
was rebased onto #363 d0683ed plus #392's single commit, and is now 763e743. That rebased stack passed the full
suite (156/156, same three skips) and merges cleanly into current main. Environment: Windows 11 26200, VS Build Tools 2026 /
MSVC 19.51, SDK 10.0.26100.8249 (DXC 1.8.2502.11), Python 3.13.

Command Result
ctest --preset dev --no-tests=error -R '^(pixel_aot_|rdna2_tools_check$|pso_readiness)' 4/4 passed
Trial merge onto current main (c2fc84c), full ctest --preset dev --no-tests=error 149/149 passed; skips bvh_wave64_hardware, bvh_wave64_warp, wave_shuffle_warp
Adapters NVIDIA GeForce RTX 3080 (driver 32.0.16.2124, debug layer enabled) and WARP 10.0.26100.9818
python -B tests/form_coverage_check.py passed
ctest --preset dev --no-tests=error Last two full runs: 146/146, then 145/146 with only cpu_aot_exe_entry failing (the #281 hang, see below). Skips in both: bvh_wave64_hardware, bvh_wave64_warp, wave_shuffle_warp, the same as before the change

The draws cover 18 binary32 words in 9 pairs: both zeros, 1.5, -2.75, -0.5, -1.0, a quiet NaN and a negative NaN
with payload, both infinities, 2^32, 4294967040, 2^31, 2147483520, -2^31, the next value below -2^31, the smallest
subnormal and 0.99999994. A further draw reads 3.75, -3.75, 1e10 and -1e10 from SGPRs. The issue's -2^31-1 is not
representable in binary32, so the next binary32 below -2^31 stands in for it.

Negative control: swapping the two conversions on the -0.5/-1.0 pair must give pixel_mismatch, and it does.

Dev-time mutants (not in CI), evaluated per row on both adapters. A local script, not part of this PR, imports
tests/pixel_aot_check.py (translate_int, compile_shader, write_case), patches pixel_aot.CVT_HELPERS in
memory, and runs every pair through offscreen_check.exe <backend> --check-pixel-case without stopping at the first
mismatch. During the mutant runs DXC printed "Declared output SV_Target0 not fully written" a few times, which I
couldn't match to specific compiles. The unmutated final runs printed no such warning.

  • Unchanged helpers: all 9 pairs pass on both.
  • Unsigned helper replaced by a bare uint(x): the pairs containing +Inf and 2^32 fail on both, because u32(+Inf)
    and u32(2^32) give 0 instead of 0xFFFFFFFF.
  • NaN replacement of the clamped operand dropped from both helpers: only the NaN pair fails on both, where the signed
    conversion gives 0x80000000 instead of 0.

Known flakes (unrelated to this change): this branch's base e726864 predates #394. On this host,
cpu_aot_exe_entry fails in most runs (the #281 hang), and cpu_native_exe_chain and cpu_native_exe_start fail
in some, at the rates below. On current main (c2fc84c, with #394), cpu_aot_exe_entry and
cpu_native_exe_chain passed 20/20 on the same host. That measurement doesn't show which commit fixed them. The failures seen were 15 s and 60 s test timeouts, plus one
"does not run the TLS callback" assertion. The rates are about the same with and without this change (n=20 each, not
a significance test). All three run the native cpu_exe_* EXEs (cf. #281). None of them
imports pixel_aot or the scanner, and this change touches no C++, MASM or CMake.
Over 20 single-test runs on this host:

Test Clean e726864 With this change
cpu_aot_exe_entry 13/20 failed 15/20 failed
cpu_native_exe_chain 5/20 failed 5/20 failed
cpu_native_exe_start 1/20 failed 1/20 failed

Evidence and follow-up

  • No game data. All inputs are shader literals or synthetic constants.
  • Not run locally: the LLVM 15 round trip of the new check_binary fixture (the Ubuntu pixel-binary job runs it).
  • Assumptions: the truncation, NaN and saturation rule (F32_TRUNC_ASSUMPTION) comes from the issue's ISA reading.
    It was not re-checked against the ISA document and not measured on the console. Result words
    0x00000001..0x007FFFFF are binary32 subnormal patterns, and the harness compiles with -denorm preserve. Whether
    an FTZ build would flush them is not tested.
  • Deviation from #360 condition 7: docs/coverage/*.tsv lists every LLVM form and is regenerated by
    tools/form_reference.py, so it has nothing to change. dashboard.svg needs recorded runs plus a --source line,
    so I left it to maintainers, as stage 1 did. Please say if you want either one regenerated in this PR.
  • Gap noticed in passing: the scanner has no pattern for stage 1's v_cvt_f32_u32/i32_e32 either. That belongs to
    #392 and is not touched here.
  • Related site: tools/ffx_dispatch_aot.py:64-65 lowers the same conversions for the FidelityFX dispatch translator
    with a bare uint(asfloat(x)) and no saturation or NaN handling. That could be a follow-up issue.

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; no README row lists individual pixel_aot instructions).
  • I did not include game files, dumps, distribution links or secrets.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6537746427 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/438). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-22T03:10:18Z. --- ## Change Stage 3 of #360: `tools/pixel_aot.py` lowers the plain e32 float-to-integer conversions `v_cvt_u32_f32_e32` and `v_cvt_i32_f32_e32`. The source can be a VGPR, an SGPR or a hex literal. Two HLSL helpers, emitted once before `main`, implement the issue's reading of the RDNA 2 ISA: truncate toward zero, NaN gives 0, and out-of-range values saturate. The cast only ever sees an operand that is NaN-free and clamped to the largest binary32 below 2^32 or 2^31, because an out-of-range or NaN `uint()`/`int()` is undefined in HLSL and poison in LLVM. The result word goes out through the lossless integer readback from #363. Stacked on #392 (stage 1), which is itself stacked on #363. The branch carries #363 as rebased (`d0683ed`) and a conflict-free rebase of #392's commit. When #392 is rebased, I'll realign onto it. Please merge those first, and I'll rebase this. The issue's "stage 2" (the e64 forms of stage 1) is separate work and not part of this PR. Refs #360. This change was AI-assisted (Claude Code). Refused and tested as rejections: e64 spellings (including `|x|`, `-x`, `clamp` and `omod`), DPP, SDWA, float inline constants, decimal integer inline constants, `v_cvt_rpi_i32_f32` and `v_cvt_flr_i32_f32`, a scalar read before its load completes, a write that overlaps an outstanding sample, and a non-entry exec mask. Decimal inline constants are refused because `fp_operand` reads them as bit patterns, and I have not checked that reading for an f32 source against the ISA. Hex sources are read as 32-bit literal bit patterns. LLVM's disassembly prints integer inline constants in decimal, so in translated disassembly a hex token is always a literal. A hand-written `0x1` would be read as the bit pattern 1, not as the inline constant 1. A float export of a conversion result is translated as well, as with `v_mov_b32` literals: the register bits pass through. No draw checks that path. `docs/experiments.md` says so. `tools/scan_unsupported_shaders.py` gets the matching pattern, written with the same literal spacing as the translator regex, and `TestRdna2Scanner` covers it. ## Verification Commit under test: `17a654a` (this change on top of `e726864`, the #392 head). After #363 was rebased, this branch was rebased onto #363 `d0683ed` plus #392's single commit, and is now `763e743`. That rebased stack passed the full suite (156/156, same three skips) and merges cleanly into current `main`. Environment: Windows 11 26200, VS Build Tools 2026 / MSVC 19.51, SDK 10.0.26100.8249 (DXC 1.8.2502.11), Python 3.13. | Command | Result | |---|---| | `ctest --preset dev --no-tests=error -R '^(pixel_aot_\|rdna2_tools_check$\|pso_readiness)'` | 4/4 passed | | Trial merge onto current `main` (`c2fc84c`), full `ctest --preset dev --no-tests=error` | 149/149 passed; skips `bvh_wave64_hardware`, `bvh_wave64_warp`, `wave_shuffle_warp` | | Adapters | NVIDIA GeForce RTX 3080 (driver 32.0.16.2124, debug layer enabled) and WARP 10.0.26100.9818 | | `python -B tests/form_coverage_check.py` | passed | | `ctest --preset dev --no-tests=error` | Last two full runs: 146/146, then 145/146 with only `cpu_aot_exe_entry` failing (the #281 hang, see below). Skips in both: `bvh_wave64_hardware`, `bvh_wave64_warp`, `wave_shuffle_warp`, the same as before the change | The draws cover 18 binary32 words in 9 pairs: both zeros, 1.5, -2.75, -0.5, -1.0, a quiet NaN and a negative NaN with payload, both infinities, 2^32, 4294967040, 2^31, 2147483520, -2^31, the next value below -2^31, the smallest subnormal and 0.99999994. A further draw reads 3.75, -3.75, 1e10 and -1e10 from SGPRs. The issue's -2^31-1 is not representable in binary32, so the next binary32 below -2^31 stands in for it. Negative control: swapping the two conversions on the -0.5/-1.0 pair must give `pixel_mismatch`, and it does. Dev-time mutants (not in CI), evaluated per row on both adapters. A local script, not part of this PR, imports `tests/pixel_aot_check.py` (`translate_int`, `compile_shader`, `write_case`), patches `pixel_aot.CVT_HELPERS` in memory, and runs every pair through `offscreen_check.exe <backend> --check-pixel-case` without stopping at the first mismatch. During the mutant runs DXC printed "Declared output SV_Target0 not fully written" a few times, which I couldn't match to specific compiles. The unmutated final runs printed no such warning. - Unchanged helpers: all 9 pairs pass on both. - Unsigned helper replaced by a bare `uint(x)`: the pairs containing +Inf and 2^32 fail on both, because u32(+Inf) and u32(2^32) give 0 instead of 0xFFFFFFFF. - NaN replacement of the clamped operand dropped from both helpers: only the NaN pair fails on both, where the signed conversion gives 0x80000000 instead of 0. Known flakes (unrelated to this change): this branch's base `e726864` predates #394. On this host, `cpu_aot_exe_entry` fails in most runs (the #281 hang), and `cpu_native_exe_chain` and `cpu_native_exe_start` fail in some, at the rates below. On current `main` (`c2fc84c`, with #394), `cpu_aot_exe_entry` and `cpu_native_exe_chain` passed 20/20 on the same host. That measurement doesn't show which commit fixed them. The failures seen were 15 s and 60 s test timeouts, plus one "does not run the TLS callback" assertion. The rates are about the same with and without this change (n=20 each, not a significance test). All three run the native `cpu_exe_*` EXEs (cf. #281). None of them imports `pixel_aot` or the scanner, and this change touches no C++, MASM or CMake. Over 20 single-test runs on this host: | Test | Clean `e726864` | With this change | |---|---|---| | `cpu_aot_exe_entry` | 13/20 failed | 15/20 failed | | `cpu_native_exe_chain` | 5/20 failed | 5/20 failed | | `cpu_native_exe_start` | 1/20 failed | 1/20 failed | ## Evidence and follow-up - No game data. All inputs are shader literals or synthetic constants. - Not run locally: the LLVM 15 round trip of the new `check_binary` fixture (the Ubuntu `pixel-binary` job runs it). - Assumptions: the truncation, NaN and saturation rule (`F32_TRUNC_ASSUMPTION`) comes from the issue's ISA reading. It was not re-checked against the ISA document and not measured on the console. Result words 0x00000001..0x007FFFFF are binary32 subnormal patterns, and the harness compiles with `-denorm preserve`. Whether an FTZ build would flush them is not tested. - Deviation from #360 condition 7: `docs/coverage/*.tsv` lists every LLVM form and is regenerated by `tools/form_reference.py`, so it has nothing to change. `dashboard.svg` needs recorded runs plus a `--source` line, so I left it to maintainers, as stage 1 did. Please say if you want either one regenerated in this PR. - Gap noticed in passing: the scanner has no pattern for stage 1's `v_cvt_f32_u32/i32_e32` either. That belongs to #392 and is not touched here. - Related site: `tools/ffx_dispatch_aot.py:64-65` lowers the same conversions for the FidelityFX dispatch translator with a bare `uint(asfloat(x))` and no saturation or NaN handling. That could be a follow-up issue. ## 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`; no README row lists individual pixel_aot instructions). - [x] I did not include game files, dumps, distribution links or secrets. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:43:03 +00:00
R0Y00 commented 2026-11-24 06:48:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T10:38:21Z.


I reviewed the remaining stage-three coverage at d351029. #392 has landed. #545 is preparing the plain unsigned e32 lowering, so once it lands, please rebase #438 onto that main and keep your signed e32 change and the independent integer readback cases. The shared src/ffx_float_to_int.hlsli already exposes cvt_i32_f32(uint bits), so the signed path can use it alongside #545's unsigned path. Please preserve the signed endpoints and adjacent representable inputs, NaN, infinities, negative fractional truncation, the SGPR draw, and the signed/unsigned swap mutation. The signed path can keep its existing entry-mask scope.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7077921790 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/438#issuecomment-7077921790). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T10:38:21Z. --- I reviewed the remaining stage-three coverage at d351029. #392 has landed. #545 is preparing the plain unsigned e32 lowering, so once it lands, please rebase #438 onto that main and keep your signed e32 change and the independent integer readback cases. The shared src/ffx_float_to_int.hlsli already exposes cvt_i32_f32(uint bits), so the signed path can use it alongside #545's unsigned path. Please preserve the signed endpoints and adjacent representable inputs, NaN, infinities, negative fractional truncation, the SGPR draw, and the signed/unsigned swap mutation. The signed path can keep its existing entry-mask scope.
JB2WIN commented 2026-11-24 06:48:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-22T10:48:28Z.


Updated after #363 and #392 landed. I merged main into the branch with a normal merge (f64b856, no force push, so your d351029 stays in the history). The stage-3 change is ported onto main's current structure: the helpers now go through SALU_HELPERS, the code uses translate_int/integer_rt from #363, and the draw lives in check_e64_render (draw-e64). git diff upstream/main HEAD is now only this change: 5 files, +207.

Verification on the merged head (Windows 11 26200, RTX 3080 driver 32.0.16.2124 + WARP):

  • ctest --preset dev --no-tests=error -R "^(pixel_aot_|rdna2_tools_check$|pso_readiness)": 18/18 passed. pixel_aot_e64_hardware went from 7.35 s to 8.77 s.
  • full ctest --preset dev --no-tests=error: 254/254 passed; skips bvh_wave64_hardware, bvh_wave64_warp, wave_shuffle_warp.
  • tests/pixel_aot_check.py binary with LLVM 15.0.7, run locally: passed.
  • negative control (swapped conversions) reports pixel_mismatch. A mutant without the NaN/saturation guards fails draw-e64 on the RTX 3080.

On semantics, following @MoonYueya's correction in #360: the truncate / NaN→0 / saturate rule is not confirmed by the ISA text I could reach. It follows the rule you set for both translators in #439. Overlap with #540 is noted there.

This comment is AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7078029137 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/438#issuecomment-7078029137). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-22T10:48:28Z. --- Updated after #363 and #392 landed. I merged `main` into the branch with a normal merge (`f64b856`, no force push, so your `d351029` stays in the history). The stage-3 change is ported onto main's current structure: the helpers now go through `SALU_HELPERS`, the code uses `translate_int`/`integer_rt` from #363, and the draw lives in `check_e64_render` (`draw-e64`). `git diff upstream/main HEAD` is now only this change: 5 files, +207. Verification on the merged head (Windows 11 26200, RTX 3080 driver 32.0.16.2124 + WARP): - `ctest --preset dev --no-tests=error -R "^(pixel_aot_|rdna2_tools_check$|pso_readiness)"`: 18/18 passed. `pixel_aot_e64_hardware` went from 7.35 s to 8.77 s. - full `ctest --preset dev --no-tests=error`: 254/254 passed; skips `bvh_wave64_hardware`, `bvh_wave64_warp`, `wave_shuffle_warp`. - `tests/pixel_aot_check.py binary` with LLVM 15.0.7, run locally: passed. - negative control (swapped conversions) reports `pixel_mismatch`. A mutant without the NaN/saturation guards fails `draw-e64` on the RTX 3080. On semantics, following @MoonYueya's correction in #360: the truncate / NaN→0 / saturate rule is not confirmed by the ISA text I could reach. It follows the rule you set for both translators in #439. Overlap with #540 is noted there. This comment is AI-assisted.
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!432
No description provided.