shader: lower v_cvt_pknorm_i16_f16 and v_cvt_pknorm_u16_f16 in the direct compute path #3319

Manually merged
github merged 2 commits from github-bot/gh-3317 into main 2026-11-29 10:32:10 +00:00 AGit
Owner

@⁠R0D4X on GitHub · 2026-11-28 09:28 UTC · original
R0D4X:feat/native-cvt-pknorm-f16 → main · +272 −1 · 4 files · 2 commits · merged 2026-11-29 10:29 UTC

Fixes #3318. Refs #2935.

What this changes

  • Lowers v_cvt_pknorm_i16_f16 (VOP3 0x312) and v_cvt_pknorm_u16_f16 (VOP3 0x313) in src/gfx1013_direct_compute.inl using exact 32-bit integer RNE normalization of two binary16 inputs into a packed 2×16-bit integer destination.
  • Maps inline float constants 240..248 through packed_f16_inline_constant, supports VOP3 op_sel[1:0] and abs/neg, enforces graphics_input and binary16 MODE guards (and registers both ops in the half_binary scan), and refuses unsupported modifiers (clamp, omod, op_sel[3:2], non-VGPR high-half op_sel, unused src2).

Tests & docs added

  • tests/native_cvt_pknorm_f16_check.py & tests/cmake/native_cvt_pknorm_f16.cmake:
    • native_cvt_pknorm_f16_controls: validates emitted integer DXIL (mul i32, 32767, 65535), refuses invalid modifiers and non-default s_round_mode, and verifies that the truncate and inline_as_zero negative controls each differ.
    • native_cvt_pknorm_f16_hardware: dispatches 8 packed binary16 pairs (normals, subnormals, 0x3801–0x3804 RNE boundaries, ±0.5h ties, saturation, ±Inf, qNaN) across plain, op_sel[1:0] + abs/neg, and inline 0.5 (src0=240) forms, matching 2048 result words and 16 sentinel guards.
  • docs/experiments/native-cvt-pknorm-f16.md: experiment note and reproduction commands.

Verification

  • Commit: 693e9f1f
  • Environment: 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.2140).
  • ctest --preset dev --no-tests=error -R '^native_cvt_pknorm_|^native_cvt_norm_f16_' -V: 12/12 passed (0 skipped).
  • ctest --preset release --no-tests=error -R '^native_cvt_pknorm_f16_' -V: 2/2 passed (0 skipped).
  • tests/docs_links_check.py & tests/bidi_controls_check.py: passed.

Scope: covers synthetic direct-DXIL compute fixtures for v_cvt_pknorm_i16_f16 and v_cvt_pknorm_u16_f16 only; does not establish full-game execution.

**@⁠R0D4X** on GitHub · 2026-11-28 09:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3317) `R0D4X:feat/native-cvt-pknorm-f16` → `main` · +272 −1 · 4 files · 2 commits · merged 2026-11-29 10:29 UTC Fixes #3318. Refs #2935. ## What this changes - Lowers `v_cvt_pknorm_i16_f16` (VOP3 `0x312`) and `v_cvt_pknorm_u16_f16` (VOP3 `0x313`) in `src/gfx1013_direct_compute.inl` using exact 32-bit integer RNE normalization of two binary16 inputs into a packed 2×16-bit integer destination. - Maps inline float constants `240..248` through `packed_f16_inline_constant`, supports VOP3 `op_sel[1:0]` and `abs`/`neg`, enforces `graphics_input` and binary16 `MODE` guards (and registers both ops in the `half_binary` scan), and refuses unsupported modifiers (`clamp`, `omod`, `op_sel[3:2]`, non-VGPR high-half `op_sel`, unused `src2`). ## Tests & docs added - `tests/native_cvt_pknorm_f16_check.py` & `tests/cmake/native_cvt_pknorm_f16.cmake`: - `native_cvt_pknorm_f16_controls`: validates emitted integer DXIL (`mul i32`, `32767`, `65535`), refuses invalid modifiers and non-default `s_round_mode`, and verifies that the `truncate` and `inline_as_zero` negative controls each differ. - `native_cvt_pknorm_f16_hardware`: dispatches 8 packed binary16 pairs (normals, subnormals, `0x3801`–`0x3804` RNE boundaries, `±0.5h` ties, saturation, `±Inf`, `qNaN`) across plain, `op_sel[1:0]` + `abs`/`neg`, and inline `0.5` (`src0=240`) forms, matching 2048 result words and 16 sentinel guards. - `docs/experiments/native-cvt-pknorm-f16.md`: experiment note and reproduction commands. ## Verification - Commit: `693e9f1f` - Environment: 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.2140`). - `ctest --preset dev --no-tests=error -R '^native_cvt_pknorm_|^native_cvt_norm_f16_' -V`: **12/12 passed** (0 skipped). - `ctest --preset release --no-tests=error -R '^native_cvt_pknorm_f16_' -V`: **2/2 passed** (0 skipped). - `tests/docs_links_check.py` & `tests/bidi_controls_check.py`: **passed**. *Scope: covers synthetic direct-DXIL compute fixtures for `v_cvt_pknorm_i16_f16` and `v_cvt_pknorm_u16_f16` only; does not establish full-game execution.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 09:39:26 +00:00
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-28 20:08 UTC · original · requested changes

Reviewed 693e9f1f.

Run on a release build of main f2972840 with this PR and 17 other open PRs merged locally, Windows Sandbox, network off, vGPU: native_cvt_pknorm_f16_controls and native_cvt_pknorm_f16_hardware pass. _hardware ran on the NVIDIA GeForce RTX 5080 (driver 32.0.16.2101) and matched 2048 result words and 16 guards. Making signed_out test v_cvt_pknorm_u16_f16 made _hardware fail; _controls still passed.

Test gaps. Each mutation below leaves every fixture word unchanged, so both tests still pass:

  1. The only nonzero op_sel tested is 3, which selects the high half in both lanes. Mutation: src/gfx1013_direct_compute.inl:1907 if (op_sel & (1u << j)) -> if (op_sel & 1u). Add op_sel=1 and op_sel=2 forms. For example, v_cvt_pknorm_i16_f16 v4, v2, v3 op_sel:[1,0] on CASES[1] (0x3C003801, 0xB801BC00) should give 0x80017FFF; the mutant gives 0xBFF17FFF.
  2. The only inline constant tested is 240 (0.5), and only in S0. Mutation: :1909 r <= 248 -> r <= 240, which sends 241-248 to operand32 & 65535. Add v_cvt_pknorm_i16_f16 v4, 242, 243, expecting 0x80017FFF.
  3. Three refusals have no control: src2 != 0, high-half op_sel on a non-VGPR source, and abs/neg bit 2. Mutation: :1896 drop || i.src[2]. Add refusal cases with src2 = v1 (... operand modifiers), op_sel=1 with S0 = s4 (... high-half op_sel on non-VGPR source), and neg = 4 (... operand modifiers).
  4. abs is tested only on S1 and neg only on S0, and every S0 half in CASES is positive, so abs on S0 has no observable effect. Mutation: :1914 if (i.abs & (1u << j)) -> if (j == 1 && (i.abs & (1u << j))). Add a case (S0, S1) = (0x0000BC00, 0x00003C00) with v_cvt_pknorm_i16_f16 v4, |v2|, -v3, expecting 0x80017FFF. The mutant gives 0x80018001.

Request changes for the test gaps above.

**@⁠Leyukaka** on GitHub · 2026-11-28 20:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3317#pullrequestreview-6099895859) · **requested changes** Reviewed `693e9f1f`. Run on a release build of `main` `f2972840` with this PR and 17 other open PRs merged locally, Windows Sandbox, network off, vGPU: `native_cvt_pknorm_f16_controls` and `native_cvt_pknorm_f16_hardware` pass. `_hardware` ran on the NVIDIA GeForce RTX 5080 (driver 32.0.16.2101) and matched 2048 result words and 16 guards. Making `signed_out` test `v_cvt_pknorm_u16_f16` made `_hardware` fail; `_controls` still passed. Test gaps. Each mutation below leaves every fixture word unchanged, so both tests still pass: 1. The only nonzero op_sel tested is 3, which selects the high half in both lanes. Mutation: `src/gfx1013_direct_compute.inl:1907` `if (op_sel & (1u << j))` -> `if (op_sel & 1u)`. Add op_sel=1 and op_sel=2 forms. For example, `v_cvt_pknorm_i16_f16 v4, v2, v3 op_sel:[1,0]` on `CASES[1]` (`0x3C003801`, `0xB801BC00`) should give `0x80017FFF`; the mutant gives `0xBFF17FFF`. 2. The only inline constant tested is `240` (0.5), and only in S0. Mutation: `:1909` `r <= 248` -> `r <= 240`, which sends 241-248 to `operand32 & 65535`. Add `v_cvt_pknorm_i16_f16 v4, 242, 243`, expecting `0x80017FFF`. 3. Three refusals have no control: `src2 != 0`, high-half op_sel on a non-VGPR source, and abs/neg bit 2. Mutation: `:1896` drop `|| i.src[2]`. Add refusal cases with src2 = v1 (`... operand modifiers`), op_sel=1 with S0 = s4 (`... high-half op_sel on non-VGPR source`), and neg = 4 (`... operand modifiers`). 4. `abs` is tested only on S1 and `neg` only on S0, and every S0 half in `CASES` is positive, so `abs` on S0 has no observable effect. Mutation: `:1914` `if (i.abs & (1u << j))` -> `if (j == 1 && (i.abs & (1u << j)))`. Add a case `(S0, S1) = (0x0000BC00, 0x00003C00)` with `v_cvt_pknorm_i16_f16 v4, |v2|, -v3`, expecting `0x80017FFF`. The mutant gives `0x80018001`. Request changes for the test gaps above.
Author
Owner

@⁠R0D4X on GitHub · 2026-11-29 08:35 UTC · original

Thanks @⁠Leyukaka! Closed all four test gaps in tests/native_cvt_pknorm_f16_check.py:

  1. Added asymmetric op_sel=1 (op_sel:[1,0]) and op_sel=2 (op_sel:[0,1]) cases on CASES[1] (0x3C003801, 0xB801BC00).
  2. Added v_cvt_pknorm_i16_f16 v4, 242, 243 (inline 1.0, -1.0 -> 0x80017FFF).
  3. Added the three refusal controls (src2 = v1, op_sel=1 with S0 = s4, and neg = 4).
  4. Added (0x0000BC00, 0x00003C00) with v_cvt_pknorm_i16_f16 v4, |v2|, -v3 (abs_m=1, neg_m=2 -> 0x80017FFF).

Re-verified on NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2140), Windows 11 (10.0.26300.9974), MSVC 19.44.35230, SDK DXC 10.0.26100.0:

  • ctest --preset dev --no-tests=error -R '^native_cvt_pknorm_f16_' -V: 2/2 passed (0 skipped); 2048 result words and 16 guards matched.
  • ctest --preset release --no-tests=error -R '^native_cvt_pknorm_f16_' -V: 2/2 passed (0 skipped); 2048 result words and 16 guards matched.
**@⁠R0D4X** on GitHub · 2026-11-29 08:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3317#issuecomment-7253204586) Thanks @⁠Leyukaka! Closed all four test gaps in `tests/native_cvt_pknorm_f16_check.py`: 1. Added asymmetric `op_sel=1` (`op_sel:[1,0]`) and `op_sel=2` (`op_sel:[0,1]`) cases on `CASES[1]` (`0x3C003801`, `0xB801BC00`). 2. Added `v_cvt_pknorm_i16_f16 v4, 242, 243` (inline `1.0`, `-1.0` -> `0x80017FFF`). 3. Added the three refusal controls (`src2 = v1`, `op_sel=1` with `S0 = s4`, and `neg = 4`). 4. Added `(0x0000BC00, 0x00003C00)` with `v_cvt_pknorm_i16_f16 v4, |v2|, -v3` (`abs_m=1, neg_m=2` -> `0x80017FFF`). Re-verified on NVIDIA GeForce RTX 5080 (`10de:2c02`, driver `32.0.16.2140`), Windows 11 (`10.0.26300.9974`), MSVC `19.44.35230`, SDK DXC `10.0.26100.0`: - `ctest --preset dev --no-tests=error -R '^native_cvt_pknorm_f16_' -V`: **2/2 passed** (0 skipped); 2048 result words and 16 guards matched. - `ctest --preset release --no-tests=error -R '^native_cvt_pknorm_f16_' -V`: **2/2 passed** (0 skipped); 2048 result words and 16 guards matched.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-29 08:56 UTC · original · approved these changes

Head b9fdb5ae, by reading the diff from 693e9f1f (nothing built or run).

The four gaps are closed:

  1. op_sel 1 and 2 on CASES[1]: with op_sel & 1u, lane 1 reads 0xB801 in the op_sel=1 slot and the low half 0xBC00 in the op_sel=2 slot, so both words change.
  2. v_cvt_pknorm_i16_f16 v4, 242, 243 expects 0x80017FFF. With r <= 240, both operands take the low half of the f32 constant (0).
  3. The src2, opsel_sgpr and neg_bit2 refusals each have a control case that expects its message.
  4. |v2|, -v3 on (0x0000BC00, 0x00003C00) expects 0x80017FFF; the S1-only abs mutant gives 0x80018001.

native_cvt_pknorm_f16_* is not in the pr preset filter (CMakePresets.json:51), so CI does not run these tests. git merge-tree against main 184b15db: clean.

**@⁠Leyukaka** on GitHub · 2026-11-29 08:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3317#pullrequestreview-6102173242) · **approved these changes** Head `b9fdb5ae`, by reading the diff from `693e9f1f` (nothing built or run). The four gaps are closed: 1. op_sel 1 and 2 on `CASES[1]`: with `op_sel & 1u`, lane 1 reads `0xB801` in the op_sel=1 slot and the low half `0xBC00` in the op_sel=2 slot, so both words change. 2. `v_cvt_pknorm_i16_f16 v4, 242, 243` expects `0x80017FFF`. With `r <= 240`, both operands take the low half of the f32 constant (0). 3. The `src2`, `opsel_sgpr` and `neg_bit2` refusals each have a control case that expects its message. 4. `|v2|, -v3` on `(0x0000BC00, 0x00003C00)` expects `0x80017FFF`; the S1-only abs mutant gives `0x80018001`. `native_cvt_pknorm_f16_*` is not in the `pr` preset filter (`CMakePresets.json:51`), so CI does not run these tests. `git merge-tree` against main `184b15db`: clean.
github manually merged commit 8af7eca75a into main 2026-11-29 10:32:10 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.