startup: lower v_sat_pk_u8_i16 in gfx2hlsl #3033

Manually merged
github merged 2 commits from github-bot/gh-3033 into gh-pr/3033/base 2026-11-27 20:22:55 +00:00 AGit
Owner

@⁠R0D4X on GitHub · 2026-11-27 09:09 UTC · original
R0D4X:feat/gfx2hlsl-v-sat-pk-u8-i16 → main · +265 −0 · 4 files · 2 commits · merged 2026-11-27 20:21 UTC

What this changes

Adds lowering for v_sat_pk_u8_i16 (VOP1 0x62 / VOP3A 0x1e2) in tools/startup/gfx2hlsl.py (already decoded by tools/disasm_rdna2.py).

  • Semantics: Clamps both signed 16-bit halves of S0 to [0, 255], packs the two resulting uint8 lanes into D[7:0] and D[15:8], and zeroes D[31:16].
  • Encoding & Stage guards: Adds a check_encoding() guard for v_sat_pk_u8_i16_e64 that refuses VOP3A neg/abs bits and non-zero unused src1/src2 fields; VEC_U handles both _e32 and _e64 spellings, EXEC masking, and refuses modifiers or wrong operand counts.

Tests added

  • tests/startup_gfx2hlsl_v_sat_pk_u8_i16_check.py: VOP1 (e32) and VOP3A (e64) binary decode via G.decode(), 169 half-word boundary pairs, EXEC masking, encoding and Stage refusals, unlowered control, and FXC ps_5_1 + DXC ps_6_0 GPU readback draws for both e32 and e64 (including a negative-control draw).
  • Registered via tests/cmake/startup_gfx2hlsl_v_sat_pk_u8_i16.cmake and tests/checks/python-linux/startup_gfx2hlsl_v_sat_pk_u8_i16.txt.

Verification

  • Commit: 23e57e7c (on upstream/main 3b6c38a8)
  • Host: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK 10.0.26100.0, FXC + DXC 1.9.2602.17, D3D12 debug layer enabled
  • Adapters: WARP (1414:008c, driver 10.0.26100.9818) and NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2124)

Results:

  • ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_v_sat_pk_u8_i16|^startup_tools_lint$' -V -> 4/4 passed, 0 skipped (debug_errors=0 debug_warnings=0 on all draws)
  • ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_v_sat_pk_u8_i16' -> 3/3 passed, 0 skipped
  • Repo & neighbor checks (docs_links_check.py, bidi_controls_check.py, startup_gfx2hlsl_cvt_pk_int16_check.py, startup_gfx2hlsl_handler_arity_check.py, startup_gfx2hlsl_refusals_check.py, git diff --check) -> all passed
  • 3 live mutations on gfx2hlsl.py (dropping neg/abs guard, dropping unused src1/src2 guard, wrong high-byte shift) -> 3/3 caught (rc=1)

Scope: Covers synthetic gfx1013 VOP1/VOP3A fixtures translated by gfx2hlsl.py and run on WARP and RTX 5080; does not establish full-title startup or frame rate.

**@⁠R0D4X** on GitHub · 2026-11-27 09:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3033) `R0D4X:feat/gfx2hlsl-v-sat-pk-u8-i16` → `main` · +265 −0 · 4 files · 2 commits · merged 2026-11-27 20:21 UTC ## What this changes Adds lowering for `v_sat_pk_u8_i16` (VOP1 `0x62` / VOP3A `0x1e2`) in `tools/startup/gfx2hlsl.py` (already decoded by `tools/disasm_rdna2.py`). - **Semantics:** Clamps both signed 16-bit halves of `S0` to `[0, 255]`, packs the two resulting `uint8` lanes into `D[7:0]` and `D[15:8]`, and zeroes `D[31:16]`. - **Encoding & Stage guards:** Adds a `check_encoding()` guard for `v_sat_pk_u8_i16_e64` that refuses VOP3A `neg`/`abs` bits and non-zero unused `src1`/`src2` fields; `VEC_U` handles both `_e32` and `_e64` spellings, `EXEC` masking, and refuses modifiers or wrong operand counts. ## Tests added - `tests/startup_gfx2hlsl_v_sat_pk_u8_i16_check.py`: VOP1 (`e32`) and VOP3A (`e64`) binary decode via `G.decode()`, 169 half-word boundary pairs, `EXEC` masking, encoding and Stage refusals, unlowered control, and FXC `ps_5_1` + DXC `ps_6_0` GPU readback draws for both `e32` and `e64` (including a negative-control draw). - Registered via `tests/cmake/startup_gfx2hlsl_v_sat_pk_u8_i16.cmake` and `tests/checks/python-linux/startup_gfx2hlsl_v_sat_pk_u8_i16.txt`. ## Verification - **Commit:** `23e57e7c` (on `upstream/main` `3b6c38a8`) - **Host:** Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK `10.0.26100.0`, FXC + DXC `1.9.2602.17`, D3D12 debug layer enabled - **Adapters:** WARP (`1414:008c`, driver `10.0.26100.9818`) and NVIDIA GeForce RTX 5080 (`10de:2c02`, driver `32.0.16.2124`) Results: - `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_v_sat_pk_u8_i16|^startup_tools_lint$' -V` -> **4/4 passed, 0 skipped** (`debug_errors=0 debug_warnings=0` on all draws) - `ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_v_sat_pk_u8_i16'` -> **3/3 passed, 0 skipped** - Repo & neighbor checks (`docs_links_check.py`, `bidi_controls_check.py`, `startup_gfx2hlsl_cvt_pk_int16_check.py`, `startup_gfx2hlsl_handler_arity_check.py`, `startup_gfx2hlsl_refusals_check.py`, `git diff --check`) -> **all passed** - 3 live mutations on `gfx2hlsl.py` (dropping `neg`/`abs` guard, dropping unused `src1`/`src2` guard, wrong high-byte shift) -> **3/3 caught (`rc=1`)** *Scope:* Covers synthetic gfx1013 VOP1/VOP3A fixtures translated by `gfx2hlsl.py` and run on WARP and RTX 5080; does not establish full-title startup or frame rate.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 09:10:48 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-27 10:05 UTC · original · reviewed

Review of head 23e57e7c (comment only).

Read the diff of tools/startup/gfx2hlsl.py (11 lines): the new v_sat_pk_u8_i16 lowering (two signed 16-bit lanes saturated to unsigned 8-bit, packed in the low 16 bits) and the _e64 encoding guard (refuses abs/neg and non-zero unused src1/src2). Both match the ISA description in the code comment.

The PR's check does what a lowering needs: startup_gfx2hlsl_v_sat_pk_u8_i16_warp / _hardware draw the translated shader and compare the readback with ref_sat_pk_u8_i16, a CPU reference written independently of the HLSL template (dxc, and fxc when set), plus a _controls test.

Ran locally (Linux): python3 -B tests/startup_gfx2hlsl_v_sat_pk_u8_i16_check.py (the controls): ok.

  • Mutation A: removed the unused src1/src2 guard: the controls fail ("encoding guard refuses unused_src1").
  • Mutation B: clamp bound 255 changed to 254 in the lowering: the Linux controls do NOT catch it (their eval_hlsl mirrors the formula instead of running it), so only the WARP draw can; it needs a Windows run.

No defect found. This PR only lacks a Windows receipt on this head: ctest -R "startup_gfx2hlsl_v_sat_pk_u8_i16" (dev + release).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-27 10:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3033#pullrequestreview-6086476806) · **reviewed** Review of head 23e57e7c (comment only). Read the diff of `tools/startup/gfx2hlsl.py` (11 lines): the new `v_sat_pk_u8_i16` lowering (two signed 16-bit lanes saturated to unsigned 8-bit, packed in the low 16 bits) and the `_e64` encoding guard (refuses abs/neg and non-zero unused src1/src2). Both match the ISA description in the code comment. The PR's check does what a lowering needs: `startup_gfx2hlsl_v_sat_pk_u8_i16_warp` / `_hardware` draw the translated shader and compare the readback with `ref_sat_pk_u8_i16`, a CPU reference written independently of the HLSL template (dxc, and fxc when set), plus a `_controls` test. Ran locally (Linux): `python3 -B tests/startup_gfx2hlsl_v_sat_pk_u8_i16_check.py` (the controls): ok. - Mutation A: removed the unused src1/src2 guard: the controls fail ("encoding guard refuses unused_src1"). - Mutation B: clamp bound 255 changed to 254 in the lowering: the Linux controls do NOT catch it (their `eval_hlsl` mirrors the formula instead of running it), so only the WARP draw can; it needs a Windows run. No defect found. This PR only lacks a Windows receipt on this head: `ctest -R "startup_gfx2hlsl_v_sat_pk_u8_i16"` (dev + release). AI-assisted; commands listed were executed locally.
github-bot force-pushed github-bot/gh-3033 from 23e57e7c59 to 142ca42896 2026-11-27 14:24:59 +00:00 Compare
github-bot changed target branch from main to gh-pr/3033/base 2026-11-27 20:22:53 +00:00
github manually merged commit 39de43ebb5 into gh-pr/3033/base 2026-11-27 20:22:55 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-27 20:21 UTC · original · reviewed

Review of 39de43ebb5 (updated with main). Comment only.

The VEC_U template sign-extends each 16-bit half (asint(x << 16) >> 16 for the low half, asint(x) >> 16 for the high half), clamps to [0, 255] and packs the two bytes into D[15:0] with D[31:16] zero. The _e64 guard refuses abs/neg and nonzero unused src1/src2 fields. The _warp and _hardware draws compare with ref_sat_pk_u8_i16, written independently of the template. This is the gfx2hlsl path; #3095 (merged) covers the direct C++ compute path, so the two do not overlap.

Windows results are in the comment below.

Commands: git diff origin/main...pull/3033/head (read), plus the Windows commands listed in the comment.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-27 20:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3033#pullrequestreview-6093016670) · **reviewed** Review of 39de43ebb591e80396f1bd3a4a037d6c09853d75 (updated with main). Comment only. The `VEC_U` template sign-extends each 16-bit half (`asint(x << 16) >> 16` for the low half, `asint(x) >> 16` for the high half), clamps to [0, 255] and packs the two bytes into D[15:0] with D[31:16] zero. The `_e64` guard refuses abs/neg and nonzero unused src1/src2 fields. The `_warp` and `_hardware` draws compare with `ref_sat_pk_u8_i16`, written independently of the template. This is the gfx2hlsl path; #3095 (merged) covers the direct C++ compute path, so the two do not overlap. Windows results are in the comment below. Commands: `git diff origin/main...pull/3033/head` (read), plus the Windows commands listed in the comment. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-27 20:21 UTC · original

Windows Server 2025 verification of 39de43ebb591e80396f1bd3a4a037d6c09853d75 (D3D12 WARP, MSVC 14.44.35207):

  • dev: cmake --build --preset dev --target offscreen_check; ctest --preset dev -R '^startup_gfx2hlsl_': 382/382 passed, including startup_gfx2hlsl_v_sat_pk_u8_i16_controls, _warp and _hardware
  • release: cmake --build --preset release --target offscreen_check; ctest --preset release -R '^startup_gfx2hlsl_': 382/382 passed
  • Windows Python checks selected for tools/startup/gfx2hlsl.py: all ok; tests/startup_run_sh_check.py skips (77) on Windows

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-27 20:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3033#issuecomment-7227420150) Windows Server 2025 verification of `39de43ebb591e80396f1bd3a4a037d6c09853d75` (D3D12 WARP, MSVC 14.44.35207): - dev: `cmake --build --preset dev --target offscreen_check`; `ctest --preset dev -R '^startup_gfx2hlsl_'`: 382/382 passed, including `startup_gfx2hlsl_v_sat_pk_u8_i16_controls`, `_warp` and `_hardware` - release: `cmake --build --preset release --target offscreen_check`; `ctest --preset release -R '^startup_gfx2hlsl_'`: 382/382 passed - Windows Python checks selected for `tools/startup/gfx2hlsl.py`: all ok; `tests/startup_run_sh_check.py` skips (77) on Windows AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.