startup: draw the gfx2hlsl conversion operations #1701

Merged
Asimmimx merged 2 commits from upstream-pr/1708 into main 2026-11-24 18:57:35 +00:00
Asimmimx commented 2026-11-24 17:33:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:33:10Z.


Refs #1149.

Change

No check ran the conversion operations of the VEC_U table in tools/startup/gfx2hlsl.py: v_cvt_f32_u32, v_cvt_f32_i32, v_cvt_u32_f32, v_cvt_f32_ubyte0 to 3, v_cvt_f32_f16 and v_cvt_f16_f32.

This PR adds a check only. The translator does not change.

tests/startup_gfx2hlsl_cvt_alu_check.py draws them with the per-lane runner tests/startup_gfx2hlsl_lane_alu.py. The runner is byte-identical to the copies in #1703 and #1706, so the PRs merge in any order. In each draw:

  • one operation runs per lane on flat inputs, alternating _e32 and _e64;
  • the four result words are compared exactly;
  • the recorded llvm-mc bodies are checked by a binary mode;
  • the controls cover refused modifiers and operand counts.

References, from the AMD RDNA 2 ISA reference:

Operation Reference Inputs that matter
v_cvt_f32_u32, _i32 round to nearest even 0x80000001 → 2^31, 0xffffffff → 2^32, 0x01000001 → 2^24 (tie to even), negative integers
v_cvt_u32_f32 truncate toward zero; negative, -0 and NaN → 0 1.75, -3.5, NaN, 0x4f7fffff (largest below 2^32), 123456.9
v_cvt_f32_ubyteN byte N of S0 words that differ in every byte
v_cvt_f32_f16 S0[15:0] other binary16 values in the high half, ±inf, 65504
v_cvt_f16_f32 bits 15:0, high half clear exactly representable values, 65504, 2^-14, -0

Each operation has one mutated lowering, and the first draw with it must read the mutation's own reference words:

  • signed and unsigned exchanged;
  • rounding instead of truncation;
  • the wrong byte or a 7-bit mask;
  • the high binary16 half;
  • a negated source.

Results

Commit 9d47aec5 on origin/main. Windows 11 26300.9974, DXC 1.8.2502.11, FXC 10.0.26100, debug layer on.

Adapter Driver Draws Mutated draws
WARP 10.0.26100.9818 34/34 match 17/17 read the mutated words
AMD Radeon RX 6600 (RDNA 2) 32.0.21045.29003 34/34 match 17/17 read the mutated words

There were no skips. binary with llvm-mc 19.1.1 gives fixture words match llvm-mc.

FXC and v_cvt_f16_f32. Eight operations are drawn through both FXC ps_5_1 and DXC ps_6_0; v_cvt_f16_f32 is drawn through DXC only.

Its results are 16-bit words, so every exported word is a binary32 denormal in the fixture's float target. The FXC ps_5_1 output of that pixel stage read 00000000,00000000,00000000,00000000 on WARP and on the RX 6600, where 00003c00,0000c100,00007bff,00000400 was expected. A variant with one channel converting a constant read zeros as well. The same words with 0x3f800000 ORed in at the export read back exactly (3f803c00,3f80c100,3f807bff,3f800400), on both adapters. The conversion is therefore right, and the zeros come from how the FXC-compiled stage exports denormal bit patterns.

This may matter beyond the fixture. A translated pixel stage compiled with FXC that exports packed 16-bit data through a float target could lose it. I have not checked any real pipeline for that.

Not covered:

  • v_cvt_u32_f32 at or above 2^32 and of +inf, where the HLSL conversion of an out-of-range value is not pinned;
  • binary16 denormal inputs;
  • binary32 values that v_cvt_f16_f32 has to round.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587698055 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1708). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T17:33:10Z. --- Refs #1149. ## Change No check ran the conversion operations of the `VEC_U` table in `tools/startup/gfx2hlsl.py`: `v_cvt_f32_u32`, `v_cvt_f32_i32`, `v_cvt_u32_f32`, `v_cvt_f32_ubyte0` to `3`, `v_cvt_f32_f16` and `v_cvt_f16_f32`. This PR adds a check only. The translator does not change. `tests/startup_gfx2hlsl_cvt_alu_check.py` draws them with the per-lane runner `tests/startup_gfx2hlsl_lane_alu.py`. The runner is byte-identical to the copies in #1703 and #1706, so the PRs merge in any order. In each draw: - one operation runs per lane on flat inputs, alternating `_e32` and `_e64`; - the four result words are compared exactly; - the recorded llvm-mc bodies are checked by a `binary` mode; - the controls cover refused modifiers and operand counts. References, from the AMD RDNA 2 ISA reference: | Operation | Reference | Inputs that matter | |---|---|---| | `v_cvt_f32_u32`, `_i32` | round to nearest even | `0x80000001` → 2^31, `0xffffffff` → 2^32, `0x01000001` → 2^24 (tie to even), negative integers | | `v_cvt_u32_f32` | truncate toward zero; negative, -0 and NaN → 0 | 1.75, -3.5, NaN, `0x4f7fffff` (largest below 2^32), 123456.9 | | `v_cvt_f32_ubyteN` | byte N of S0 | words that differ in every byte | | `v_cvt_f32_f16` | S0[15:0] | other binary16 values in the high half, ±inf, 65504 | | `v_cvt_f16_f32` | bits 15:0, high half clear | exactly representable values, 65504, 2^-14, -0 | Each operation has one mutated lowering, and the first draw with it must read the mutation's own reference words: - signed and unsigned exchanged; - rounding instead of truncation; - the wrong byte or a 7-bit mask; - the high binary16 half; - a negated source. ## Results Commit `9d47aec5` on `origin/main`. Windows 11 26300.9974, DXC 1.8.2502.11, FXC 10.0.26100, debug layer on. | Adapter | Driver | Draws | Mutated draws | |---|---|---|---| | WARP | 10.0.26100.9818 | 34/34 match | 17/17 read the mutated words | | AMD Radeon RX 6600 (RDNA 2) | 32.0.21045.29003 | 34/34 match | 17/17 read the mutated words | There were no skips. `binary` with llvm-mc 19.1.1 gives `fixture words match llvm-mc`. **FXC and `v_cvt_f16_f32`.** Eight operations are drawn through both FXC `ps_5_1` and DXC `ps_6_0`; `v_cvt_f16_f32` is drawn through DXC only. Its results are 16-bit words, so every exported word is a binary32 denormal in the fixture's float target. The FXC `ps_5_1` output of that pixel stage read `00000000,00000000,00000000,00000000` on WARP and on the RX 6600, where `00003c00,0000c100,00007bff,00000400` was expected. A variant with one channel converting a constant read zeros as well. The same words with `0x3f800000` ORed in at the export read back exactly (`3f803c00,3f80c100,3f807bff,3f800400`), on both adapters. The conversion is therefore right, and the zeros come from how the FXC-compiled stage exports denormal bit patterns. This may matter beyond the fixture. A translated pixel stage compiled with FXC that exports packed 16-bit data through a float target could lose it. I have not checked any real pipeline for that. **Not covered:** - `v_cvt_u32_f32` at or above 2^32 and of +inf, where the HLSL conversion of an out-of-range value is not pinned; - binary16 denormal inputs; - binary32 values that `v_cvt_f16_f32` has to round. AI-assisted (Claude Code).
tedin7 commented 2026-11-24 18:02:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:42:05Z.

Review: COMMENTED


Review of head 9d47aec5d4b1aa75ca9037de551f563327e662cb (Linux only; no D3D12, WARP or RDNA2 hardware here, so the 34 draws were not reproduced).

Verdict: 0 P1, 1 P2, 2 P3. Translator untouched; references match the RDNA2 ISA text; the fixture words are valid. The P2 is a CMake ordering problem that quietly drops the FXC draws on a fresh configure.

P2: STARTUP_FXC is read before it is defined

The new block (CMakeLists.txt ~1638-1647) uses $<$<BOOL:${STARTUP_FXC}>:${STARTUP_FXC}>, but find_program(STARTUP_FXC ...) is at line 1650, after it. ${} expands at configure time, so on a clean build dir the argument is empty and the draw runs DXC only. FXC is picked up only after the cache holds the variable (second configure). Minimal CMake reproduction run locally: first configure prints USE_BEFORE=[], second prints the path.

  • Effect: the reported FXC ps_5_1 draws (16 of the 34) can be missing from a fresh CI or developer run, silently; the run still passes.
  • Suggestion: place the new block after the find_program line, as startup_gfx2hlsl_bit_alu is.

Semantics

  • References are plain Python from the ISA text: RNE int to binary32, truncation with negative/NaN to 0, byte N, S0[15:0], low-half binary16 result. The inputs hit the cases the PR lists. Counts check out: 9 ops x 2 chunks = 18 DXC draws, 16 FXC (f16_f32 excluded), 17 mutated draws.
  • P3 (not verifiable here): the "bits 31:16 clear" reference for v_cvt_f16_f32 rests on the author's reading of the ISA; this review cannot check it against hardware.
  • P3: on Linux the controls are structural. They match the translated text (any lowering change fails the count == 4 check on the mutation pattern) but evaluate no value, unlike the bit_alu sibling, which has a CPU evaluator. Numeric correctness exists only in the Windows draws.

Commands executed locally

  • python3 -B tests/startup_gfx2hlsl_cvt_alu_check.py: 29 ok, 0 MISMATCH, exit 0.
  • ... cvt_alu_check.py binary llvm-mc-19: fixture words match llvm-mc (CI uses llvm-mc-15).
  • Local mutations, each reverted afterwards (restored clean):
    • translator: ubyte1 shift 8 to 16, cvt_u32_f32 without max, cvt_f32_i32 without int(), cvt_f16_f32 negated. All four fail the controls (pattern no longer matches).
    • test: ubyte1 mutation replacement made a no-op fails count == 4; recorded body words of ubyte2 swapped for ubyte1 fails binary; NaN guard removed from the cvt_u32_f32 reference crashes the controls.
  • A CPU emulation I wrote of the translated expressions over all 72 draw inputs agrees with the references (0 differences) and reports differences for each of the four translator mutations, so the chosen inputs separate the right and wrong lowerings. It is an independent model, not the HLSL compilers.
  • Minimal CMake script for the P2.

Limits: no ctest run, no Windows draw, no FXC denormal check (the v_cvt_f16_f32 FXC claim is the author's measurement only).

AI-assisted review.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044380176 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1708#pullrequestreview-6044380176). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:42:05Z. **Review:** COMMENTED --- Review of head `9d47aec5d4b1aa75ca9037de551f563327e662cb` (Linux only; no D3D12, WARP or RDNA2 hardware here, so the 34 draws were not reproduced). **Verdict: 0 P1, 1 P2, 2 P3. Translator untouched; references match the RDNA2 ISA text; the fixture words are valid. The P2 is a CMake ordering problem that quietly drops the FXC draws on a fresh configure.** ### P2: `STARTUP_FXC` is read before it is defined The new block (`CMakeLists.txt` ~1638-1647) uses `$<$<BOOL:${STARTUP_FXC}>:${STARTUP_FXC}>`, but `find_program(STARTUP_FXC ...)` is at line 1650, after it. `${}` expands at configure time, so on a clean build dir the argument is empty and the draw runs DXC only. FXC is picked up only after the cache holds the variable (second configure). Minimal CMake reproduction run locally: first configure prints `USE_BEFORE=[]`, second prints the path. - Effect: the reported FXC ps_5_1 draws (16 of the 34) can be missing from a fresh CI or developer run, silently; the run still passes. - Suggestion: place the new block after the `find_program` line, as `startup_gfx2hlsl_bit_alu` is. ### Semantics - References are plain Python from the ISA text: RNE int to binary32, truncation with negative/NaN to 0, byte N, `S0[15:0]`, low-half binary16 result. The inputs hit the cases the PR lists. Counts check out: 9 ops x 2 chunks = 18 DXC draws, 16 FXC (f16_f32 excluded), 17 mutated draws. - P3 (not verifiable here): the "bits 31:16 clear" reference for `v_cvt_f16_f32` rests on the author's reading of the ISA; this review cannot check it against hardware. - P3: on Linux the controls are structural. They match the translated text (any lowering change fails the `count == 4` check on the mutation pattern) but evaluate no value, unlike the `bit_alu` sibling, which has a CPU evaluator. Numeric correctness exists only in the Windows draws. ### Commands executed locally - `python3 -B tests/startup_gfx2hlsl_cvt_alu_check.py`: 29 ok, 0 MISMATCH, exit 0. - `... cvt_alu_check.py binary llvm-mc-19`: `fixture words match llvm-mc` (CI uses llvm-mc-15). - Local mutations, each reverted afterwards (restored clean): - translator: ubyte1 shift 8 to 16, `cvt_u32_f32` without `max`, `cvt_f32_i32` without `int()`, `cvt_f16_f32` negated. All four fail the controls (pattern no longer matches). - test: ubyte1 mutation replacement made a no-op fails `count == 4`; recorded body words of ubyte2 swapped for ubyte1 fails `binary`; NaN guard removed from the `cvt_u32_f32` reference crashes the controls. - A CPU emulation I wrote of the translated expressions over all 72 draw inputs agrees with the references (0 differences) and reports differences for each of the four translator mutations, so the chosen inputs separate the right and wrong lowerings. It is an independent model, not the HLSL compilers. - Minimal CMake script for the P2. Limits: no ctest run, no Windows draw, no FXC denormal check (the `v_cvt_f16_f32` FXC claim is the author's measurement only). AI-assisted review.
R0Y00 commented 2026-11-24 18:03:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T17:53:27Z.


#1707 is now on main at 49634a12. It enables output modifiers on float-result conversions, so the refusal in this fixture for v_cvt_f32_f16 with mul:2 is stale on the combined code. Please keep the conversion draw and replace that refusal with an integer-result case, for example v_cvt_f16_f32 with mul:2. The plain conversion and its existing output mutations should stay intact.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7139852732 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1708#issuecomment-7139852732). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T17:53:27Z. --- #1707 is now on main at 49634a12. It enables output modifiers on float-result conversions, so the refusal in this fixture for v_cvt_f32_f16 with mul:2 is stale on the combined code. Please keep the conversion draw and replace that refusal with an integer-result case, for example v_cvt_f16_f32 with mul:2. The plain conversion and its existing output mutations should stay intact.
upstream-sync closed this pull request 2026-11-24 19:01:03 +00:00
KainanP commented 2026-11-24 19:01:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KainanP on 2026-11-24T18:18:54Z.


On the "Not covered" item, v_cvt_u32_f32 at or above 2^32 and of +inf: here is data for both sides of it.

Hardware. On RDNA 2 silicon (gfx1036, desktop APU of the console's generation), @4usphs ran v_cvt_u32_f32 as inline assembly over xcl's #639 inputs, including ±inf and the integer range limits. It saturates: an out-of-range value gives 0xFFFFFFFF and negative values give 0. NaN gives 0 for v_cvt_u32_f32 / v_cvt_i32_f32: https://github.com/xcl-dev/xcl/pull/639#issuecomment-7127563021. (In the same run, v_cvt_flr/rpi_i32_f32 of a NaN gave 0x7FFFFFFF / 0x80000000 by the NaN's sign, not 0. That is not relevant to this table, but it matters if those two are added later.)

HLSL side. uint(max(F(x), 0.0)) leaves values ≥ 2^32 to an out-of-range cast, which HLSL leaves undefined. What comes out depends on whether the value gets constant-folded:

  • In LooperSalty/AnyXboxX#138, a plain (int)asfloat(x) gave 0 for ±inf on an RTX 4060 Laptop (driver 32.0.16.1047) and on WARP, instead of saturating. With a constant NaN, dxc folded the cast to an undefined value and the validator refused the shader (Assignment of undefined values to UAV): https://github.com/LooperSalty/AnyXboxX/pull/138
  • With runtime values, xcl found a plain cast that already saturated on RTX 4060 / 5070 (drivers 610.88 / 621.24) (same #639 thread). So a fixture with runtime inputs can pass on one adapter while a folded case fails.

So to pin the row rather than leave it adapter-dependent, an explicit clamp is the usual approach. xcl uses select(isnan(f) || f <= 0, 0, select(f >= 4294967296.0, 0xFFFFFFFF, (uint)f)); AnyXboxX tests NaN on the bits, because dxc folds x != x to false. A row with 0x4f800000 (2^32) and +inf expecting 0xffffffff would then cover it. None of this was measured on Scarlett or through FXC.

AI-assisted (Claude Code). The figures are quoted from the linked threads.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7140468743 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1708#issuecomment-7140468743). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-24T18:18:54Z. --- On the "Not covered" item, `v_cvt_u32_f32` at or above 2^32 and of +inf: here is data for both sides of it. **Hardware.** On RDNA 2 silicon (gfx1036, desktop APU of the console's generation), @4usphs ran `v_cvt_u32_f32` as inline assembly over xcl's #639 inputs, including ±inf and the integer range limits. It saturates: an out-of-range value gives `0xFFFFFFFF` and negative values give 0. NaN gives 0 for `v_cvt_u32_f32` / `v_cvt_i32_f32`: https://github.com/xcl-dev/xcl/pull/639#issuecomment-7127563021. (In the same run, `v_cvt_flr/rpi_i32_f32` of a NaN gave `0x7FFFFFFF` / `0x80000000` by the NaN's sign, not 0. That is not relevant to this table, but it matters if those two are added later.) **HLSL side.** `uint(max(F(x), 0.0))` leaves values ≥ 2^32 to an out-of-range cast, which HLSL leaves undefined. What comes out depends on whether the value gets constant-folded: - In LooperSalty/AnyXboxX#138, a plain `(int)asfloat(x)` gave **0** for ±inf on an RTX 4060 Laptop (driver 32.0.16.1047) and on WARP, instead of saturating. With a constant NaN, dxc folded the cast to an undefined value and the validator refused the shader (`Assignment of undefined values to UAV`): https://github.com/LooperSalty/AnyXboxX/pull/138 - With runtime values, xcl found a plain cast that already saturated on RTX 4060 / 5070 (drivers 610.88 / 621.24) (same #639 thread). So a fixture with runtime inputs can pass on one adapter while a folded case fails. So to pin the row rather than leave it adapter-dependent, an explicit clamp is the usual approach. xcl uses `select(isnan(f) || f <= 0, 0, select(f >= 4294967296.0, 0xFFFFFFFF, (uint)f))`; AnyXboxX tests NaN on the bits, because dxc folds `x != x` to false. A row with `0x4f800000` (2^32) and +inf expecting `0xffffffff` would then cover it. None of this was measured on Scarlett or through FXC. _AI-assisted (Claude Code). The figures are quoted from the linked threads._
R0Y00 commented 2026-11-24 19:01:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T18:48:44Z.


Correction to my earlier note: this candidate already refused the integer-result v_cvt_f16_f32 modifier. I kept that case and added an explicit accepted float-result modifier after integrating main. I also moved the registration after FXC discovery so a clean build runs both compilers where supported. Windows Release controls, WARP and RTX 4060 Laptop passed 3/3 with the existing per-operation negative controls. The merged candidate now needs its own CI.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141185764 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1708#issuecomment-7141185764). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T18:48:44Z. --- Correction to my earlier note: this candidate already refused the integer-result v_cvt_f16_f32 modifier. I kept that case and added an explicit accepted float-result modifier after integrating main. I also moved the registration after FXC discovery so a clean build runs both compilers where supported. Windows Release controls, WARP and RTX 4060 Laptop passed 3/3 with the existing per-operation negative controls. The merged candidate now needs its own CI.
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!1701
No description provided.