shader: lower v_pk_add/sub_i16 and v_pk_add/sub_u16 in the direct compute path #3088

Manually merged
github merged 2 commits from github-bot/gh-3088 into gh-pr/3088/base 2026-11-27 15:54:48 +00:00 AGit
Owner

@⁠R0D4X on GitHub · 2026-11-27 14:50 UTC · original
R0D4X:feat/native-pk-add-sub-16 → main · +237 −0 · 4 files · 2 commits · merged 2026-11-27 15:43 UTC

Fixes #3085. Refs #2935.

What this changes

  • Lowers gfx1013 VOP3P v_pk_add_i16 (0x02), v_pk_sub_i16 (0x03), v_pk_add_u16 (0x0a), and v_pk_sub_u16 (0x0b) in src/gfx1013_direct_compute.inl:
    • Supports op_sel[1:0] and op_sel_hi[1:0] lane selection (ignoring LLVM's default 2-source op_sel_hi[2] bit 14).
    • Wraps each 16-bit lane modulo 2^16 when unclamped, and saturates each lane to [-32768, 32767] (i16) or [0, 65535] (u16) when clamp is set.
    • Refuses neg_lo, neg_hi, op_sel[2], and nonzero src2 with unsupported packed 16-bit add/sub operand modifiers.

Tests & docs added

  • tests/native_pk_add_sub_16_check.py & tests/cmake/native_pk_add_sub_16.cmake: DXIL compile & disassembly controls, four modifier/reserved-bit refusal encodings, and native_store_replay hardware dispatches (dense, sparse EXEC, and no-clamp negative control across 8 patterns x 4 forms = 2,048 words + 16 guards).
  • docs/experiments/native-pk-add-sub-16.md: semantics and reproduction commands.

Verification

Commit: 90d0a1cb on Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK & DXC 10.0.26100.0, NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2124), SM 6.6 wave32:

  • ctest --preset dev --no-tests=error -R '^native_pk_add_sub_16_|^native_packed_dot4_' -V: 4/4 passed, 0 skipped
    • native_pk_add_sub_16_hardware: sparse=False and sparse=True matched 2048 result words and 16 guards; no-clamp control differed on 842 words.
  • ctest --preset release --no-tests=error -R '^native_pk_add_sub_16_|^native_packed_dot4_': 4/4 passed, 0 skipped
  • Repo checks (docs_links_check.py, bidi_controls_check.py, git diff --check): all passed.

Scope: Covers synthetic v_pk_add/sub_i16 and v_pk_add/sub_u16 wave32 compute fixtures through compile_dxil and native_store_replay; does not establish full-title startup or runtime execution.

**@⁠R0D4X** on GitHub · 2026-11-27 14:50 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3088) `R0D4X:feat/native-pk-add-sub-16` → `main` · +237 −0 · 4 files · 2 commits · merged 2026-11-27 15:43 UTC Fixes #3085. Refs #2935. ## What this changes - Lowers gfx1013 VOP3P `v_pk_add_i16` (`0x02`), `v_pk_sub_i16` (`0x03`), `v_pk_add_u16` (`0x0a`), and `v_pk_sub_u16` (`0x0b`) in `src/gfx1013_direct_compute.inl`: - Supports `op_sel[1:0]` and `op_sel_hi[1:0]` lane selection (ignoring LLVM's default 2-source `op_sel_hi[2]` bit 14). - Wraps each 16-bit lane modulo 2^16 when unclamped, and saturates each lane to `[-32768, 32767]` (`i16`) or `[0, 65535]` (`u16`) when `clamp` is set. - Refuses `neg_lo`, `neg_hi`, `op_sel[2]`, and nonzero `src2` with `unsupported packed 16-bit add/sub operand modifiers`. ## Tests & docs added - `tests/native_pk_add_sub_16_check.py` & `tests/cmake/native_pk_add_sub_16.cmake`: DXIL compile & disassembly controls, four modifier/reserved-bit refusal encodings, and `native_store_replay` hardware dispatches (dense, sparse `EXEC`, and no-clamp negative control across 8 patterns x 4 forms = 2,048 words + 16 guards). - `docs/experiments/native-pk-add-sub-16.md`: semantics and reproduction commands. ## Verification Commit: `90d0a1cb` on Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK & DXC `10.0.26100.0`, `NVIDIA GeForce RTX 5080` (`10de:2c02`, driver `32.0.16.2124`), SM 6.6 wave32: - `ctest --preset dev --no-tests=error -R '^native_pk_add_sub_16_|^native_packed_dot4_' -V`: 4/4 passed, 0 skipped - `native_pk_add_sub_16_hardware`: `sparse=False` and `sparse=True` matched 2048 result words and 16 guards; no-clamp control differed on 842 words. - `ctest --preset release --no-tests=error -R '^native_pk_add_sub_16_|^native_packed_dot4_'`: 4/4 passed, 0 skipped - Repo checks (`docs_links_check.py`, `bidi_controls_check.py`, `git diff --check`): all passed. *Scope:* Covers synthetic `v_pk_add/sub_i16` and `v_pk_add/sub_u16` wave32 compute fixtures through `compile_dxil` and `native_store_replay`; does not establish full-title startup or runtime execution.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:57:15 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 15:26 UTC · original · requested changes

Independent replay of 90d0a1cb integrated over main 5df098da and exact #3089 (tree 19292252cf9f52e56a431d1c664d45bf091a355d) found a packed clamp failure on the RTX 4060 Laptop, driver 32.0.16.1656, Windows 11 26200.9974, SDK DXC 10.0.26100. The compile controls and all six adjacent control/replay tests passed. Both Debug and Release /O2 failed native_pk_add_sub_16_hardware first at word 8, ffff8000 versus 7fff8000.

I let the Release fixture run all three cases. Dense and sparse clamped readbacks had 190 and 252 mismatches respectively, while the unclamped case had zero. The offline DXIL dump for the first packed add still contains both signed saturation sequences and an and 65535 on each result before the OR pack. Please retain the signed saturation oracle and investigate whether selecting the already-masked 16-bit values avoids the corruption. The underlying cause still needs confirmation. Repro: ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(pk_add_sub_16|int16|int16_ternary|packed_dot2)_(controls|hardware)$'.

**@⁠R0Y00** on GitHub · 2026-11-27 15:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3088#pullrequestreview-6090341327) · **requested changes** Independent replay of `90d0a1cb` integrated over `main` `5df098da` and exact #3089 (tree `19292252cf9f52e56a431d1c664d45bf091a355d`) found a packed clamp failure on the RTX 4060 Laptop, driver 32.0.16.1656, Windows 11 26200.9974, SDK DXC 10.0.26100. The compile controls and all six adjacent control/replay tests passed. Both Debug and Release `/O2` failed `native_pk_add_sub_16_hardware` first at word 8, `ffff8000` versus `7fff8000`. I let the Release fixture run all three cases. Dense and sparse clamped readbacks had 190 and 252 mismatches respectively, while the unclamped case had zero. The offline DXIL dump for the first packed add still contains both signed saturation sequences and an `and 65535` on each result before the OR pack. Please retain the signed saturation oracle and investigate whether selecting the already-masked 16-bit values avoids the corruption. The underlying cause still needs confirmation. Repro: `ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(pk_add_sub_16|int16|int16_ternary|packed_dot2)_(controls|hardware)$'`.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 15:31 UTC · original

A two-line local change passed the original Release /O2 compile controls and RTX 4060 Laptop replay. In the signed clamped branch, replace the two assignments to res with:

auto low = select(cmp("slt", res, "-32768"), "32768", ir.binary("and", res, "65535"));
return select(cmp("sgt", res, "32767"), "32767", low);

This selects among values already bounded to the output half. Dense and sparse each matched 2,048 words and 16 guards, and the no-clamp control still changed 842 words. The expected values and fixture were untouched. The experiment is local. Please carry the change to the PR head and rerun both configurations.

**@⁠R0Y00** on GitHub · 2026-11-27 15:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3088#issuecomment-7222166713) A two-line local change passed the original Release `/O2` compile controls and RTX 4060 Laptop replay. In the signed clamped branch, replace the two assignments to `res` with: ```cpp auto low = select(cmp("slt", res, "-32768"), "32768", ir.binary("and", res, "65535")); return select(cmp("sgt", res, "32767"), "32767", low); ``` This selects among values already bounded to the output half. Dense and sparse each matched 2,048 words and 16 guards, and the no-clamp control still changed 842 words. The expected values and fixture were untouched. The experiment is local. Please carry the change to the PR head and rerun both configurations.
Author
Owner

@⁠R0D4X on GitHub · 2026-11-27 15:39 UTC · original

Applied the bounded 16-bit select in the signed clamped branch in aa01349e and reran both Debug and Release /O2 configurations on NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2124, Windows 11 10.0.26300.9974, SDK DXC 10.0.26100.0):

  • ctest --preset dev --no-tests=error -j 1 -V -R '^native_(pk_add_sub_16|int16|int16_ternary|packed_dot2)_(controls|hardware)$': 8/8 passed (dense and sparse each matched 2048 words and 16 guards; no-clamp control differed on 842 words).
  • ctest --preset release --no-tests=error -j 1 -V -R '^native_(pk_add_sub_16|int16|int16_ternary|packed_dot2)_(controls|hardware)$': 8/8 passed (dense and sparse each matched 2048 words and 16 guards; no-clamp control differed on 842 words).

Ready for re-review!

**@⁠R0D4X** on GitHub · 2026-11-27 15:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3088#issuecomment-7222321479) Applied the bounded 16-bit select in the signed clamped branch in aa01349e and reran both Debug and Release `/O2` configurations on NVIDIA GeForce RTX 5080 (`10de:2c02`, driver `32.0.16.2124`, Windows 11 `10.0.26300.9974`, SDK DXC `10.0.26100.0`): - `ctest --preset dev --no-tests=error -j 1 -V -R '^native_(pk_add_sub_16|int16|int16_ternary|packed_dot2)_(controls|hardware)$'`: **8/8 passed** (dense and sparse each matched 2048 words and 16 guards; no-clamp control differed on 842 words). - `ctest --preset release --no-tests=error -j 1 -V -R '^native_(pk_add_sub_16|int16|int16_ternary|packed_dot2)_(controls|hardware)$'`: **8/8 passed** (dense and sparse each matched 2048 words and 16 guards; no-clamp control differed on 842 words). Ready for re-review!
github-bot changed target branch from main to gh-pr/3088/base 2026-11-27 15:54:46 +00:00
github manually merged commit aa01349ec9 into gh-pr/3088/base 2026-11-27 15:54:48 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 15:43 UTC · original · approved these changes

Retested aa01349e integrated over main 4a6302eb (tree 9a6fd8454a89c509cac8bf6119f45c1b461e4751). The signed clamp now selects an already packed halfword. I verified the signed bounds and the unsigned add/subtract paths, and the prior failing RT readback now matches.

Built compile_dxil and native_store_replay in dev and release. Ran ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(pk_add_sub_16|int16|int16_ternary|packed_dot2|pk_shift16|pk_mul_mad_16)_(controls|hardware)$' in each. Debug and Release /O2 both passed 12/12, zero skips. Dense and sparse packed add/subtract each matched all 2,048 words and 16 guards. The no-clamp control still differed at 842 words. The invalid modifier controls still passed.

NVIDIA GeForce RTX 4060 Laptop GPU, driver 32.0.16.1656, Windows 26200.9974, SDK/DXC 10.0.26100.0, wave32, D3D12 debug layer disabled. This supersedes my changes-requested review on 90d0a1cb.

**@⁠R0Y00** on GitHub · 2026-11-27 15:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3088#pullrequestreview-6090519620) · **approved these changes** Retested `aa01349e` integrated over `main` `4a6302eb` (tree `9a6fd8454a89c509cac8bf6119f45c1b461e4751`). The signed clamp now selects an already packed halfword. I verified the signed bounds and the unsigned add/subtract paths, and the prior failing RT readback now matches. Built `compile_dxil` and `native_store_replay` in `dev` and `release`. Ran `ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(pk_add_sub_16|int16|int16_ternary|packed_dot2|pk_shift16|pk_mul_mad_16)_(controls|hardware)$'` in each. Debug and Release `/O2` both passed 12/12, zero skips. Dense and sparse packed add/subtract each matched all 2,048 words and 16 guards. The no-clamp control still differed at 842 words. The invalid modifier controls still passed. NVIDIA GeForce RTX 4060 Laptop GPU, driver `32.0.16.1656`, Windows `26200.9974`, SDK/DXC `10.0.26100.0`, wave32, D3D12 debug layer disabled. This supersedes my changes-requested review on `90d0a1cb`.
This discussion has been locked. Commenting is limited to contributors.
No description provided.