shader: lower v_sat_pk_u8_i16 in pixel_aot #1245

Merged
FAJIFBEFJHA merged 2 commits from upstream-pr/1252 into main 2026-11-24 07:05:09 +00:00
FAJIFBEFJHA commented 2026-11-24 05:32:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by FAJIFBEFJHA on 2026-11-24T05:32:21Z.


Change

Add plain e32 and e64 lowering for v_sat_pk_u8_i16 in pixel_aot. The fixture previously stopped at Unsupported instruction 22: v_sat_pk_u8_i16_e32 v12, s44.

The integer lowering sign-extends each packed halfword, clamps it to 0–255, and places the results in the corresponding low two bytes. AMD RDNA 2 specifies a 32-bit destination with bits 31:16 cleared. LLVM 15 declares the instruction with the VOP_I32_I32 profile, which corroborates the destination width. AMD RDNA 2 ISA, §12.8, opcode 98 · AMD signed saturation bounds · LLVM 15.0.7 TableGen

The DPP conversion was removed before #421 merged. The low16 contract in #732 covers non-packed 16-bit destinations. #779 deferred this opcode. #421 · #732 · #779

Verification

Tested d8a478b352bb706a9d00c60e8dd132ab4d147c3b based on upstream main at 0fa43ad6216b711b8e81daf2aa04362f1cc3f99c.

Windows Debug on Windows 11 x64 build 26300.9974, DXC 1.8.2502.11.

. .\tools\dev.ps1
$env:XBOX2WINDOWS_ADAPTER = 'RX 7600'
cmake --preset dev
cmake --build --preset dev --target offscreen_check -j 5
$x2wOut = (New-Item -ItemType Directory -Force out/x2w-009/pr).FullName
$x2wJUnit = Join-Path $x2wOut 'ctest.xml'
$x2wFilter = '^(pixel_aot_(core_vector|pack_int16|pack_b32|plain_bitscan)_(warp|hardware)|rdna2_tools_check|pso_readiness_check|docs_links)$'
ctest --preset dev --no-tests=error -j 1 -R $x2wFilter -V --output-junit $x2wJUnit
foreach ($x2wArch in 'gfx1013', 'gfx1030') {
    .\out\pe-env\Scripts\python.exe -B tools/form_coverage.py $x2wJUnit `
        --records out/build/dev/form_coverage --gaps $x2wArch --json "$x2wOut/coverage-$x2wArch.json"
}
.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py
git diff --check origin/main...HEAD
  • Build passed. CTest reported 11 passed, 0 failed and 0 skipped. The Windows rdna2_tools_check entry recorded 15 internal LLVM-dependent skips.
  • Radeon RX 7600 (1002:7480, driver 32.0.32029.2010) and in-box WARP (1414:008c, driver 10.0.26100.9818) each matched two draws and detected all three intentionally wrong references. The D3D12 debug layer was enabled and reported zero errors and warnings for those draws.
  • The coverage checks passed. Both encodings appear in the gfx1013 and gfx1030 coverage reports. git diff --check passed.

Binary and Python checks on Ubuntu 22.04.5 x86-64 under WSL 2, LLVM 15.0.7.

python3 -B tests/pixel_aot_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1
python3 -B tests/pixel_aot_check.py
env LLVM_LIB=libLLVM-15.so.1 LLVM_MC=llvm-mc-15 LLVM_OBJCOPY=llvm-objcopy-15 \
    python3 -B tests/rdna2_tools_check.py
  • The binary and static pixel_aot checks passed. The binary fixture assembles and disassembles both gfx1013 encodings and checks that they lower identically to the source fixture.
  • With LLVM configured, rdna2_tools_check.py ran 129 tests with 128 passed and one capability skip. LLVM 15 could not decode buffer_load_format_d16_hi_x for gfx1013.

Evidence and follow-up

The fixture is synthetic assembly covered by the project's MIT license. It reads back full uint32 values from an R32G32B32A32_UINT render target, including an e64 instruction that overwrites its source register. The three negative controls detect swapped bytes, unsigned input handling, and stale destination bits 31:16. The draws measure the translated desktop DXIL. Reproduction notes

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact commands and results for the verification checks.
  • The new fixture includes negative controls.
  • I updated the README and experiment notes for the new coverage.
  • The change includes no game files, dumps, distribution links, or secrets.

AI-assisted (Codex).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6575359503 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1252). Originally posted by [FAJIFBEFJHA](https://github.com/FAJIFBEFJHA) on 2026-11-24T05:32:21Z. --- ## Change Add plain e32 and e64 lowering for `v_sat_pk_u8_i16` in `pixel_aot`. The fixture previously stopped at `Unsupported instruction 22: v_sat_pk_u8_i16_e32 v12, s44`. The integer lowering sign-extends each packed halfword, clamps it to 0–255, and places the results in the corresponding low two bytes. AMD RDNA 2 specifies a 32-bit destination with bits 31:16 cleared. LLVM 15 declares the instruction with the `VOP_I32_I32` profile, which corroborates the destination width. [AMD RDNA 2 ISA, §12.8, opcode 98](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) · [AMD signed saturation bounds](https://www.amd.com/content/dam/amd/en/documents/instinct-tech-docs/instruction-set-architectures/amd-instinct-cdna4-instruction-set-architecture.pdf) · [LLVM 15.0.7 TableGen](https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/llvm/lib/Target/AMDGPU/VOP1Instructions.td#L489-L490) The DPP conversion was removed before #421 merged. The `low16` contract in #732 covers non-packed 16-bit destinations. #779 deferred this opcode. [#421](https://github.com/R0Y00/Xbox2Windows/pull/421) · [#732](https://github.com/R0Y00/Xbox2Windows/pull/732) · [#779](https://github.com/R0Y00/Xbox2Windows/pull/779) ## Verification Tested `d8a478b352bb706a9d00c60e8dd132ab4d147c3b` based on upstream `main` at `0fa43ad6216b711b8e81daf2aa04362f1cc3f99c`. **Windows Debug** on Windows 11 x64 build `26300.9974`, DXC `1.8.2502.11`. ```powershell . .\tools\dev.ps1 $env:XBOX2WINDOWS_ADAPTER = 'RX 7600' cmake --preset dev cmake --build --preset dev --target offscreen_check -j 5 $x2wOut = (New-Item -ItemType Directory -Force out/x2w-009/pr).FullName $x2wJUnit = Join-Path $x2wOut 'ctest.xml' $x2wFilter = '^(pixel_aot_(core_vector|pack_int16|pack_b32|plain_bitscan)_(warp|hardware)|rdna2_tools_check|pso_readiness_check|docs_links)$' ctest --preset dev --no-tests=error -j 1 -R $x2wFilter -V --output-junit $x2wJUnit foreach ($x2wArch in 'gfx1013', 'gfx1030') { .\out\pe-env\Scripts\python.exe -B tools/form_coverage.py $x2wJUnit ` --records out/build/dev/form_coverage --gaps $x2wArch --json "$x2wOut/coverage-$x2wArch.json" } .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py git diff --check origin/main...HEAD ``` - Build passed. CTest reported 11 passed, 0 failed and 0 skipped. The Windows `rdna2_tools_check` entry recorded 15 internal LLVM-dependent skips. - Radeon RX 7600 (`1002:7480`, driver `32.0.32029.2010`) and in-box WARP (`1414:008c`, driver `10.0.26100.9818`) each matched two draws and detected all three intentionally wrong references. The D3D12 debug layer was enabled and reported zero errors and warnings for those draws. - The coverage checks passed. Both encodings appear in the gfx1013 and gfx1030 coverage reports. `git diff --check` passed. **Binary and Python checks** on Ubuntu 22.04.5 x86-64 under WSL 2, LLVM `15.0.7`. ```bash python3 -B tests/pixel_aot_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 python3 -B tests/pixel_aot_check.py env LLVM_LIB=libLLVM-15.so.1 LLVM_MC=llvm-mc-15 LLVM_OBJCOPY=llvm-objcopy-15 \ python3 -B tests/rdna2_tools_check.py ``` - The binary and static `pixel_aot` checks passed. The binary fixture assembles and disassembles both gfx1013 encodings and checks that they lower identically to the source fixture. - With LLVM configured, `rdna2_tools_check.py` ran 129 tests with 128 passed and one capability skip. LLVM 15 could not decode `buffer_load_format_d16_hi_x` for gfx1013. ## Evidence and follow-up The fixture is synthetic assembly covered by the project's MIT license. It reads back full uint32 values from an `R32G32B32A32_UINT` render target, including an e64 instruction that overwrites its source register. The three negative controls detect swapped bytes, unsigned input handling, and stale destination bits 31:16. The draws measure the translated desktop DXIL. [Reproduction notes](docs/experiments.md#offline-pixel-shader-recompilation) ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact commands and results for the verification checks. - [x] The new fixture includes negative controls. - [x] I updated the README and experiment notes for the new coverage. - [x] The change includes no game files, dumps, distribution links, or secrets. AI-assisted (Codex).
tedin7 commented 2026-11-24 06:47:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:39:13Z.

Review: COMMENTED


Dual-platform review of d8a478b352bb706a9d00c60e8dd132ab4d147c3b (shader: lower v_sat_pk_u8_i16 in pixel_aot).

Linux Checks (LLVM 19.1.7)

  • docs_links_check.py: PASS (16 Markdown files, 281 links)
  • bidi_controls_check.py: PASS (1053 tracked files, no bidirectional controls)
  • form_coverage_check.py: PASS
  • pixel_aot_check.py (static): PASS
  • check_sat_pack_u8_lowering(): PASS
  • sat_pack_u8_program() LLVM-19 binary round-trip (llvm-mc-19 -mcpu=gfx1013, llvm-objcopy-19, libLLVM-19.so disassemble + translate_int): PASS
  • git diff --check origin/main...HEAD: PASS
  • AGENTS.md / title-neutrality audit: PASS (all 4 changed files are title-neutral)
  • Note on full pixel_aot_check.py binary and rdna2_tools_check.py under LLVM 19 (vs CI's LLVM 15): pixel_aot_check.py binary stopped earlier at pre-existing check_f16_cvt_int16_binary (v_cvt_f16_i16_e32 v1, 0xfff0), and rdna2_tools_check.py had 3 failures / 3 errors out of 129 tests due to LLVM 19 vs LLVM 15 assembly/disassembly differences unrelated to this PR.

Windows Server 2025 (MSVC 14.44 + sccache + WARP)

Command: run_pr_test.ps1 -Pr 1252 -Targets offscreen_check,d3d12_xs_shim -Regex pixel_aot_core_vector_warp

  • dev (Debug): configure 1.55s, build 21.46s, ctest (pixel_aot_core_vector_warp) 1/1 Passed in 5.10s
  • release (/O2): configure 1.58s, build 21.27s, ctest (pixel_aot_core_vector_warp) 1/1 Passed in 4.70s

Code Audit & Edge Cases (tools/pixel_aot.py, tests/pixel_aot_check.py)

  • Lowering uint(clamp(asint({0} << 16) >> 16, 0, 255)) | (uint(clamp(asint({0}) >> 16, 0, 255)) << 8):
    • Low lane: {0} << 16 then arithmetic asint(...) >> 16 sign-extends bits[15:0] to [-32768, 32767]; clamp(..., 0, 255) saturates negative inputs (-32768..-1 -> 0) and values >255 -> 255, placing the result in bits[7:0].
    • High lane: asint({0}) >> 16 sign-extends bits[31:16] to [-32768, 32767]; clamp(..., 0, 255) saturates identically and shifts into bits[15:8].
    • Packing order lo | (hi << 8) and upper 16 bits (bits[31:16]) zeroed: verified both statically and in check_sat_pack_u8_draw on WARP (including negative controls for swapped lanes, unsigned source, and stale upper word, plus in-place v15, v15).
    • Unsupported modifiers/forms (clamp, -v18, extra operand, 64-bit literal, SDWA) are all rejected by check_sat_pack_u8_lowering().
  • No blocking issues found.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034244308 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1252#pullrequestreview-6034244308). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:39:13Z. **Review:** COMMENTED --- Dual-platform review of `d8a478b352bb706a9d00c60e8dd132ab4d147c3b` (`shader: lower v_sat_pk_u8_i16 in pixel_aot`). ### Linux Checks (LLVM 19.1.7) - `docs_links_check.py`: **PASS** (16 Markdown files, 281 links) - `bidi_controls_check.py`: **PASS** (1053 tracked files, no bidirectional controls) - `form_coverage_check.py`: **PASS** - `pixel_aot_check.py` (static): **PASS** - `check_sat_pack_u8_lowering()`: **PASS** - `sat_pack_u8_program()` LLVM-19 binary round-trip (`llvm-mc-19 -mcpu=gfx1013`, `llvm-objcopy-19`, `libLLVM-19.so` disassemble + `translate_int`): **PASS** - `git diff --check origin/main...HEAD`: **PASS** - `AGENTS.md` / title-neutrality audit: **PASS** (all 4 changed files are title-neutral) - Note on full `pixel_aot_check.py binary` and `rdna2_tools_check.py` under LLVM 19 (vs CI's LLVM 15): `pixel_aot_check.py binary` stopped earlier at pre-existing `check_f16_cvt_int16_binary` (`v_cvt_f16_i16_e32 v1, 0xfff0`), and `rdna2_tools_check.py` had 3 failures / 3 errors out of 129 tests due to LLVM 19 vs LLVM 15 assembly/disassembly differences unrelated to this PR. ### Windows Server 2025 (MSVC 14.44 + sccache + WARP) Command: `run_pr_test.ps1 -Pr 1252 -Targets offscreen_check,d3d12_xs_shim -Regex pixel_aot_core_vector_warp` - `dev` (Debug): configure 1.55s, build 21.46s, `ctest` (`pixel_aot_core_vector_warp`) **1/1 Passed** in 5.10s - `release` (`/O2`): configure 1.58s, build 21.27s, `ctest` (`pixel_aot_core_vector_warp`) **1/1 Passed** in 4.70s ### Code Audit & Edge Cases (`tools/pixel_aot.py`, `tests/pixel_aot_check.py`) - Lowering `uint(clamp(asint({0} << 16) >> 16, 0, 255)) | (uint(clamp(asint({0}) >> 16, 0, 255)) << 8)`: - Low lane: `{0} << 16` then arithmetic `asint(...) >> 16` sign-extends `bits[15:0]` to `[-32768, 32767]`; `clamp(..., 0, 255)` saturates negative inputs (`-32768..-1 -> 0`) and values `>255 -> 255`, placing the result in `bits[7:0]`. - High lane: `asint({0}) >> 16` sign-extends `bits[31:16]` to `[-32768, 32767]`; `clamp(..., 0, 255)` saturates identically and shifts into `bits[15:8]`. - Packing order `lo | (hi << 8)` and upper 16 bits (`bits[31:16]`) zeroed: verified both statically and in `check_sat_pack_u8_draw` on WARP (including negative controls for swapped lanes, unsigned source, and stale upper word, plus in-place `v15, v15`). - Unsupported modifiers/forms (`clamp`, `-v18`, extra operand, 64-bit literal, SDWA) are all rejected by `check_sat_pack_u8_lowering()`. - No blocking issues found.
upstream-sync closed this pull request 2026-11-24 07:07:36 +00:00
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!1245
No description provided.