shader: lower and verify RDNA2 normalized float-to-integer conversion and packing #1288

Closed
agilesh08 wants to merge 1 commit from upstream-pr/1295 into main
agilesh08 commented 2026-11-24 07:03:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-24T07:03:04Z.


Change

Lower and verify RDNA2 normalized float-to-integer conversion and packing instructions across VOP1 and VOP3 encodings in tools/pixel_aot.py, expanding coverage in docs/coverage/gfx1013.tsv and docs/coverage/rdna2.tsv by 8 forms:

  • v_cvt_pknorm_i16_f32: packs two binary32 floats into signed 16-bit normalized integers (scale 32767.0f, clamp [-32767, 32767]).
  • v_cvt_pknorm_u16_f32: packs two binary32 floats into unsigned 16-bit normalized integers (scale 65535.0f, clamp [0, 65535]).
  • v_cvt_pknorm_i16_f16: packs two binary16 floats into signed 16-bit normalized integers.
  • v_cvt_pknorm_u16_f16: packs two binary16 floats into unsigned 16-bit normalized integers.
  • v_cvt_norm_i16_f16 (unsuffixed, _e32, _e64): converts binary16 float to signed normalized 16-bit integer, tagging destination as ("low16", alu).
  • v_cvt_norm_u16_f16 (unsuffixed, _e32, _e64): converts binary16 float to unsigned normalized 16-bit integer, tagging destination as ("low16", alu).

Semantics follow the AMD RDNA 2 ISA reference (VOP3 opcodes 880-883, VOP1 opcodes 41-42) and Mesa ACO driver conventions with round-to-nearest-even (round() / DXIL Round_ne), bounds clamping, and NaN quieting to zero. Float16 operands evaluate through half16_arith_source ensuring finite proofs under entry denormal preservation. Low16 SDWA safety tags scalar conversions as ("low16", alu), strictly refusing SDWA WORD_1 reads of undefined upper bits (Reads the undefined high half of a 16-bit result) and refusing uncompressed direct exports.

Verification

Commit under test: b7ef9afe on Windows 11 x64, Python 3.12:

.\.venv\Scripts\python.exe -B tests/pixel_aot_check.py
.\.venv\Scripts\python.exe -B tests/form_coverage_check.py
.\.venv\Scripts\python.exe -B tests/rdna2_tools_check.py
.\.venv\Scripts\python.exe -B tests/bidi_controls_check.py
.\.venv\Scripts\python.exe -B tests/docs_links_check.py
git -c core.whitespace=cr-at-eol diff --check upstream/main

Results:

  • tests/pixel_aot_check.py: Passed (all unit fixtures, SGPR-driven programs, bit-accurate reference oracle checks, low16 SDWA boundaries, and negative control rejections).
  • tests/form_coverage_check.py: Passed (form coverage checks passed, 8 newly covered forms in gfx1013.tsv and rdna2.tsv).
  • tests/rdna2_tools_check.py: Passed (Ran 133 tests in 4.274s: OK, skipped=16).
  • tests/bidi_controls_check.py: Passed (Checked 1086 tracked files: no bidirectional controls).
  • tests/docs_links_check.py: Passed (Checked 16 Markdown files and 289 links: passed).
  • git -c core.whitespace=cr-at-eol diff --check upstream/main: Passed (0 whitespace or line-ending anomalies).

Evidence and follow-up

  • Semantics: Follows AMD RDNA 2 ISA specification and Mesa ACO driver implementations for normalized float-to-integer conversions and packed pairs.
  • Reference oracle: Synthetic bit-accurate Python oracle (pknorm_i16_f32_ref, pknorm_u16_f32_ref, cvt_norm_f16_ref) with live SGPR inputs, boundary saturations, and zero/NaN edge cases in tests/pixel_aot_check.py.
  • Negative controls: Verified refusal of _e32 suffixes on VOP3-only pknorm forms, modifier suffixes (clamp, abs, neg, omod), out-of-range registers, untracked operands, and WORD_1 SDWA reads from low16 results.
  • Public documentation: Updated docs/experiments.md under #offline-pixel-shader-recompilation to document the 8 normalizing float-to-integer conversion and packing forms.

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.
  • I did not include game files, dumps, distribution links or secrets.

This change was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6576497372 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1295). Originally posted by [agilesh08](https://github.com/agilesh08) on 2026-11-24T07:03:04Z. --- ## Change Lower and verify RDNA2 normalized float-to-integer conversion and packing instructions across VOP1 and VOP3 encodings in `tools/pixel_aot.py`, expanding coverage in `docs/coverage/gfx1013.tsv` and `docs/coverage/rdna2.tsv` by 8 forms: - `v_cvt_pknorm_i16_f32`: packs two binary32 floats into signed 16-bit normalized integers (scale 32767.0f, clamp [-32767, 32767]). - `v_cvt_pknorm_u16_f32`: packs two binary32 floats into unsigned 16-bit normalized integers (scale 65535.0f, clamp [0, 65535]). - `v_cvt_pknorm_i16_f16`: packs two binary16 floats into signed 16-bit normalized integers. - `v_cvt_pknorm_u16_f16`: packs two binary16 floats into unsigned 16-bit normalized integers. - `v_cvt_norm_i16_f16` (unsuffixed, `_e32`, `_e64`): converts binary16 float to signed normalized 16-bit integer, tagging destination as `("low16", alu)`. - `v_cvt_norm_u16_f16` (unsuffixed, `_e32`, `_e64`): converts binary16 float to unsigned normalized 16-bit integer, tagging destination as `("low16", alu)`. Semantics follow the AMD RDNA 2 ISA reference (VOP3 opcodes 880-883, VOP1 opcodes 41-42) and Mesa ACO driver conventions with round-to-nearest-even (`round()` / DXIL `Round_ne`), bounds clamping, and NaN quieting to zero. Float16 operands evaluate through `half16_arith_source` ensuring finite proofs under entry denormal preservation. Low16 SDWA safety tags scalar conversions as `("low16", alu)`, strictly refusing SDWA `WORD_1` reads of undefined upper bits (`Reads the undefined high half of a 16-bit result`) and refusing uncompressed direct exports. ## Verification Commit under test: `b7ef9afe` on Windows 11 x64, Python 3.12: ```powershell .\.venv\Scripts\python.exe -B tests/pixel_aot_check.py .\.venv\Scripts\python.exe -B tests/form_coverage_check.py .\.venv\Scripts\python.exe -B tests/rdna2_tools_check.py .\.venv\Scripts\python.exe -B tests/bidi_controls_check.py .\.venv\Scripts\python.exe -B tests/docs_links_check.py git -c core.whitespace=cr-at-eol diff --check upstream/main ``` Results: - `tests/pixel_aot_check.py`: Passed (all unit fixtures, SGPR-driven programs, bit-accurate reference oracle checks, low16 SDWA boundaries, and negative control rejections). - `tests/form_coverage_check.py`: Passed (`form coverage checks passed`, 8 newly covered forms in `gfx1013.tsv` and `rdna2.tsv`). - `tests/rdna2_tools_check.py`: Passed (Ran 133 tests in 4.274s: OK, skipped=16). - `tests/bidi_controls_check.py`: Passed (Checked 1086 tracked files: no bidirectional controls). - `tests/docs_links_check.py`: Passed (Checked 16 Markdown files and 289 links: passed). - `git -c core.whitespace=cr-at-eol diff --check upstream/main`: Passed (0 whitespace or line-ending anomalies). ## Evidence and follow-up - Semantics: Follows AMD RDNA 2 ISA specification and Mesa ACO driver implementations for normalized float-to-integer conversions and packed pairs. - Reference oracle: Synthetic bit-accurate Python oracle (`pknorm_i16_f32_ref`, `pknorm_u16_f32_ref`, `cvt_norm_f16_ref`) with live SGPR inputs, boundary saturations, and zero/NaN edge cases in `tests/pixel_aot_check.py`. - Negative controls: Verified refusal of `_e32` suffixes on VOP3-only `pknorm` forms, modifier suffixes (`clamp`, `abs`, `neg`, `omod`), out-of-range registers, untracked operands, and `WORD_1` SDWA reads from `low16` results. - Public documentation: Updated `docs/experiments.md` under `#offline-pixel-shader-recompilation` to document the 8 normalizing float-to-integer conversion and packing forms. ## 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. - [x] I did not include game files, dumps, distribution links or secrets. This change was AI-assisted.
tedin7 commented 2026-11-24 08:01:27 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed at commit b7ef9afe1c8413f07b9839877e2cb1f09d7db5af.

Linux Checks

  • git diff --check origin/main...HEAD: passed.
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (Checked 16 Markdown files and 289 links.).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (Checked 1086 tracked source, script and build/CI files: no bidirectional controls.).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/form_coverage_check.py: passed (form coverage checks passed).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/rdna2_tools_check.py: passed (Ran 133 tests in 2.875s, OK (skipped=16)).
  • /root/.local/share/x2w-rev-venv/bin/python -B -c "import sys, pathlib, tempfile; sys.path.insert(0, 'tests'); import pixel_aot_check as p; p.check_pknorm_lowering(); p.check_controls(pathlib.Path(tempfile.gettempdir()))": passed (check_pknorm_lowering: PASS, check_controls: PASS).
  • Note: tests/pixel_aot_check.py binary with LLVM 19 hit a pre-existing unrelated LLVM-19 vs LLVM-15 encoding difference in check_f16_cvt_int16_binary (v_cvt_f16_i16_e32 v1, 0xfff0).

Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)

  • Windows Python checks: tests/form_coverage_check.py passed (41.88s).
  • Debug (--preset dev):
    • cmake --build --preset dev --target offscreen_check -- -j 6 (2.87s, configure 1.55s)
    • ctest --preset dev -R '^(rdna2_tools_check|pixel_aot_pack_int16_warp|pixel_aot_f16_to_int16_warp)$' --parallel 4 --no-tests=error --output-on-failure: 3/3 passed (4.72s: pixel_aot_pack_int16_warp 1.29s, pixel_aot_f16_to_int16_warp 2.01s, rdna2_tools_check 4.62s)
  • Release /O2 (--preset release):
    • cmake --build --preset release --target offscreen_check -- -j 6 (0.36s, configure 1.60s)
    • ctest --preset release -R '^(rdna2_tools_check|pixel_aot_pack_int16_warp|pixel_aot_f16_to_int16_warp)$' --parallel 4 --no-tests=error --output-on-failure: 3/3 passed (4.67s: pixel_aot_pack_int16_warp 1.26s, pixel_aot_f16_to_int16_warp 2.04s, rdna2_tools_check 4.58s)

Code Review Notes

  • tools/pixel_aot.py: cvt_snorm16_f32 and cvt_unorm16_f32 match the documented round() (round-to-nearest-even), clamping ([-1.0, 1.0] * 32767.0 -> [-32768, 32767] masked to 16 bits; [0.0, 1.0] * 65535.0 -> [0, 65535]), and isnan -> 0u semantics; v_cvt_norm_{i16,u16}_f16 properly tags results as low16 so WORD_1 SDWA reads and direct exports are rejected; v_cvt_pknorm_* rejects _e32, clamp, abs/neg modifiers, and omod.
  • tests/pixel_aot_check.py: check_pknorm_lowering verifies HLSL emission, Python reference oracles, low16 WORD_0/WORD_1/direct-export contracts, and negative controls. Note that no DXIL/D3D12 GPU draw fixture (draw-pknorm in CMakeLists.txt) is added in this PR, so runtime execution of cvt_snorm16_f32/cvt_unorm16_f32 on WARP/hardware is not yet exercised directly.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6035197559 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1295#pullrequestreview-6035197559). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T07:22:31Z. **Review:** COMMENTED --- Reviewed at commit `b7ef9afe1c8413f07b9839877e2cb1f09d7db5af`. ### Linux Checks - `git diff --check origin/main...HEAD`: passed. - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py`: passed (`Checked 16 Markdown files and 289 links.`). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py`: passed (`Checked 1086 tracked source, script and build/CI files: no bidirectional controls.`). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/form_coverage_check.py`: passed (`form coverage checks passed`). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/rdna2_tools_check.py`: passed (`Ran 133 tests in 2.875s`, `OK (skipped=16)`). - `/root/.local/share/x2w-rev-venv/bin/python -B -c "import sys, pathlib, tempfile; sys.path.insert(0, 'tests'); import pixel_aot_check as p; p.check_pknorm_lowering(); p.check_controls(pathlib.Path(tempfile.gettempdir()))"`: passed (`check_pknorm_lowering: PASS`, `check_controls: PASS`). - Note: `tests/pixel_aot_check.py binary` with LLVM 19 hit a pre-existing unrelated LLVM-19 vs LLVM-15 encoding difference in `check_f16_cvt_int16_binary` (`v_cvt_f16_i16_e32 v1, 0xfff0`). ### Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) - **Windows Python checks**: `tests/form_coverage_check.py` passed (`41.88s`). - **Debug (`--preset dev`)**: - `cmake --build --preset dev --target offscreen_check -- -j 6` (`2.87s`, configure `1.55s`) - `ctest --preset dev -R '^(rdna2_tools_check|pixel_aot_pack_int16_warp|pixel_aot_f16_to_int16_warp)$' --parallel 4 --no-tests=error --output-on-failure`: **3/3 passed** (`4.72s`: `pixel_aot_pack_int16_warp` `1.29s`, `pixel_aot_f16_to_int16_warp` `2.01s`, `rdna2_tools_check` `4.62s`) - **Release `/O2` (`--preset release`)**: - `cmake --build --preset release --target offscreen_check -- -j 6` (`0.36s`, configure `1.60s`) - `ctest --preset release -R '^(rdna2_tools_check|pixel_aot_pack_int16_warp|pixel_aot_f16_to_int16_warp)$' --parallel 4 --no-tests=error --output-on-failure`: **3/3 passed** (`4.67s`: `pixel_aot_pack_int16_warp` `1.26s`, `pixel_aot_f16_to_int16_warp` `2.04s`, `rdna2_tools_check` `4.58s`) ### Code Review Notes - `tools/pixel_aot.py`: `cvt_snorm16_f32` and `cvt_unorm16_f32` match the documented `round()` (round-to-nearest-even), clamping (`[-1.0, 1.0]` * `32767.0` -> `[-32768, 32767]` masked to 16 bits; `[0.0, 1.0]` * `65535.0` -> `[0, 65535]`), and `isnan` -> `0u` semantics; `v_cvt_norm_{i16,u16}_f16` properly tags results as `low16` so `WORD_1` SDWA reads and direct exports are rejected; `v_cvt_pknorm_*` rejects `_e32`, `clamp`, `abs`/`neg` modifiers, and `omod`. - `tests/pixel_aot_check.py`: `check_pknorm_lowering` verifies HLSL emission, Python reference oracles, `low16` `WORD_0`/`WORD_1`/direct-export contracts, and negative controls. Note that no DXIL/D3D12 GPU draw fixture (`draw-pknorm` in `CMakeLists.txt`) is added in this PR, so runtime execution of `cvt_snorm16_f32`/`cvt_unorm16_f32` on WARP/hardware is not yet exercised directly.
tablefrogpillow commented 2026-11-24 11:03:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tablefrogpillow on 2026-11-24T10:45:26Z.


Ran the new pixel_aot_pack_int16 draw test on AMD hardware — the PR's validation section lists only the CPU-side Python checks (rdna2_tools_check.py, pixel_aot_check.py, form_coverage_check.py), so this is the first time the GPU draw path has actually executed.

Host: AMD Radeon RX 7900 GRE (Navi31, RDNA3), 1002:744c, driver 31.0.22030.2, Windows 11 26300, dev preset, D3D12. Head b7ef9afe.

Serial (-j 1):

ctest --preset dev --no-tests=error -R '^(pixel_aot_pack_int16_hardware|pixel_aot_pack_int16_warp|rdna2_tools_check)$'
  • pixel_aot_pack_int16_hardware — Passed (DXC-compiled shader drawn on the RX 7900 adapter, compared against the oracle, including the low16 SDWA negative controls)
  • pixel_aot_pack_int16_warp — Passed
  • rdna2_tools_check — Passed (133 tests)

So the normalized float-to-integer pack lowering round-trips correctly on RDNA3 hardware, not just the CPU oracle. Single-gen datapoint. Note for single-GPU hosts: run these -j 1 — concurrent D3D12 submissions to one adapter cause spurious *_hardware failures. AI-assisted (Claude).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129203699 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1295#issuecomment-7129203699). Originally posted by [tablefrogpillow](https://github.com/tablefrogpillow) on 2026-11-24T10:45:26Z. --- Ran the new `pixel_aot_pack_int16` draw test on **AMD hardware** — the PR's validation section lists only the CPU-side Python checks (`rdna2_tools_check.py`, `pixel_aot_check.py`, `form_coverage_check.py`), so this is the first time the GPU draw path has actually executed. **Host:** AMD Radeon RX 7900 GRE (Navi31, RDNA3), `1002:744c`, driver `31.0.22030.2`, Windows 11 26300, `dev` preset, D3D12. Head `b7ef9afe`. Serial (`-j 1`): ``` ctest --preset dev --no-tests=error -R '^(pixel_aot_pack_int16_hardware|pixel_aot_pack_int16_warp|rdna2_tools_check)$' ``` - `pixel_aot_pack_int16_hardware` — **Passed** (DXC-compiled shader drawn on the RX 7900 adapter, compared against the oracle, including the low16 SDWA negative controls) - `pixel_aot_pack_int16_warp` — **Passed** - `rdna2_tools_check` — **Passed** (133 tests) So the normalized float-to-integer pack lowering round-trips correctly on RDNA3 hardware, not just the CPU oracle. Single-gen datapoint. Note for single-GPU hosts: run these `-j 1` — concurrent D3D12 submissions to one adapter cause spurious `*_hardware` failures. AI-assisted (Claude).
upstream-sync closed this pull request 2026-11-24 12:02:42 +00:00
agilesh08 commented 2026-11-24 12:03:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-24T11:04:30Z.


Closing to consolidate upcoming work into a fresh contribution against current main.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129621222 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1295#issuecomment-7129621222). Originally posted by [agilesh08](https://github.com/agilesh08) on 2026-11-24T11:04:30Z. --- Closing to consolidate upcoming work into a fresh contribution against current main.

Pull request closed

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!1288
No description provided.