shader: accept inline constants in packed binary16 arithmetic and min/max in direct DXIL #3230

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/3230 into main 2026-11-28 00:41:08 +00:00
legacy-code-archaeologist commented 2026-11-28 00:05:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T00:05:08Z.


Accepts inline constant sources in DirectCompute::packed_f16_alu() (v_pk_add_f16, v_pk_mul_f16, v_pk_fma_f16) and DirectCompute::packed_minmax() (v_pk_min_f16, v_pk_max_f16, v_pk_min_{i,u}16, v_pk_max_{i,u}16) in src/gfx1013_direct_compute.inl. This clears the "unsupported packed binary16 arithmetic source" refusal noted on #3224 (Rank 3's follow-on refusal after #3220).

Summary of changes

  • Shared packed_f16_inline_constant() helper (src/gfx1013_direct_compute.inl):
    • Inline binary16 float constants (240..248: 0.5, -0.5, 1.0, -1.0, 2.0, -2.0, 4.0, -4.0, 1/(2*pi)) decode to bits [15:0] with [31:16] zeroed, matching gfx1013 hardware (op_sel_hi = 1 reads +0.0).
    • Inline integer constants (128..208: 0..64 and -1..-16) decode to 32-bit sign-extended values (0..64, 0xFFFFFFFF..0xFFFFFFF0).
    • Integer v_pk_min_{i,u}16 / v_pk_max_{i,u}16 accept 128..208 and continue refusing float 240..248.
    • vcc_lo/vcc_hi, m0, exec_lo/exec_hi, scc, clamp on packed f16 arithmetic, reserved bits, and non-default FP16 MODE writes keep their existing refusals.
  • Tests & Docs:
    • Added tests/cmake/native_packed_f16_inline.cmake, tests/native_packed_f16_inline_check.py (24 cases covering all 9 inline float constants, op_sel_hi high-half zeroing, neg_lo/neg_hi incl. -0.0, single-rounding FMA tie witness with inline 0.5 + 2^-24, inline integer constants, v_pk_min_f16/v_pk_max_f16 incl. 193 NaN selection, and v_pk_min_u16/v_pk_max_i16, plus 10 refusals), and docs/experiments/native-packed-f16-inline.md.

Local verification (main c7215add + this change, Windows 10.0.26100, dev preset)

  • cmake --build --preset dev --target compile_dxil native_compute_ir_dump native_store_replay offscreen_check: passed
  • ctest --preset dev --no-tests=error -R '^native_packed_f16_inline_' -V:
    • native_packed_f16_inline_ir: passed (24 cases + 10 refusals, 0.68s)
    • native_packed_f16_inline_controls: passed (24 compiled + 10 refusals, 1.47s)
    • native_packed_f16_inline_pixel_warp: passed (12 paired draws / 24 cases, 2.18s)
    • native_packed_f16_inline_pixel_hardware: passed (Intel(R) HD Graphics 530, 12 paired draws / 24 cases, 5.20s)
    • native_packed_f16_inline_compute_hardware: skipped (77, Intel(R) HD Graphics 530 31.0.101.2111: requires SM 6.6 with wave32, so GPU compute readback is not measured)
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 65/65 passed (80.10s)
  • 4 broken-lowering sensitivity checks (replicate_high_half, use_f32_inline, zero_extend_neg_int, drop_minmax_float_inline): all exited 1 on native_packed_f16_inline_ir
  • python -B tests/docs_links_check.py: passed (126 Markdown files, 624 links)

Fixes #3226
Refs #2935
Refs #3224

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5534741730 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3230). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-28T00:05:08Z. --- Accepts inline constant sources in `DirectCompute::packed_f16_alu()` (`v_pk_add_f16`, `v_pk_mul_f16`, `v_pk_fma_f16`) and `DirectCompute::packed_minmax()` (`v_pk_min_f16`, `v_pk_max_f16`, `v_pk_min_{i,u}16`, `v_pk_max_{i,u}16`) in `src/gfx1013_direct_compute.inl`. This clears the `"unsupported packed binary16 arithmetic source"` refusal noted on `#3224` (Rank 3's follow-on refusal after `#3220`). ### Summary of changes - **Shared `packed_f16_inline_constant()` helper (`src/gfx1013_direct_compute.inl`):** - Inline binary16 float constants (`240..248`: `0.5`, `-0.5`, `1.0`, `-1.0`, `2.0`, `-2.0`, `4.0`, `-4.0`, `1/(2*pi)`) decode to bits `[15:0]` with `[31:16]` zeroed, matching `gfx1013` hardware (`op_sel_hi = 1` reads `+0.0`). - Inline integer constants (`128..208`: `0..64` and `-1..-16`) decode to 32-bit sign-extended values (`0..64`, `0xFFFFFFFF..0xFFFFFFF0`). - Integer `v_pk_min_{i,u}16` / `v_pk_max_{i,u}16` accept `128..208` and continue refusing float `240..248`. - `vcc_lo`/`vcc_hi`, `m0`, `exec_lo`/`exec_hi`, `scc`, `clamp` on packed f16 arithmetic, reserved bits, and non-default FP16 MODE writes keep their existing refusals. - **Tests & Docs:** - Added `tests/cmake/native_packed_f16_inline.cmake`, `tests/native_packed_f16_inline_check.py` (24 cases covering all 9 inline float constants, `op_sel_hi` high-half zeroing, `neg_lo`/`neg_hi` incl. `-0.0`, single-rounding FMA tie witness with inline `0.5` + `2^-24`, inline integer constants, `v_pk_min_f16`/`v_pk_max_f16` incl. `193` NaN selection, and `v_pk_min_u16`/`v_pk_max_i16`, plus 10 refusals), and `docs/experiments/native-packed-f16-inline.md`. ### Local verification (`main` `c7215add` + this change, Windows 10.0.26100, `dev` preset) - `cmake --build --preset dev --target compile_dxil native_compute_ir_dump native_store_replay offscreen_check`: passed - `ctest --preset dev --no-tests=error -R '^native_packed_f16_inline_' -V`: - `native_packed_f16_inline_ir`: passed (`24` cases + `10` refusals, `0.68s`) - `native_packed_f16_inline_controls`: passed (`24` compiled + `10` refusals, `1.47s`) - `native_packed_f16_inline_pixel_warp`: passed (`12` paired draws / `24` cases, `2.18s`) - `native_packed_f16_inline_pixel_hardware`: passed (`Intel(R) HD Graphics 530`, `12` paired draws / `24` cases, `5.20s`) - `native_packed_f16_inline_compute_hardware`: skipped (`77`, `Intel(R) HD Graphics 530` `31.0.101.2111`: requires SM 6.6 with wave32, so GPU compute readback is not measured) - `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure`: **65/65 passed** (`80.10s`) - 4 broken-lowering sensitivity checks (`replicate_high_half`, `use_f32_inline`, `zero_extend_neg_int`, `drop_minmax_float_inline`): all exited `1` on `native_packed_f16_inline_ir` - `python -B tests/docs_links_check.py`: passed (`126` Markdown files, `624` links) Fixes #3226 Refs #2935 Refs #3224 AI-assisted.
RonLogic commented 2026-11-28 00:22:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-28T00:22:51Z.


I ran this on RTX 4070 (32.0.16.2124) in Release at 2c964029, DXC 1.9.2602.17, Windows 11 26300.10075. The four IR, compile and Pixel tests passed. The GPU Compute case reached guard overwritten.

The Compute shader's prologue leaves all 32 lanes active and writes at group*4096 + lane*128 bytes. The reference checks two 128-dword-spaced rows and treats the other lane records as guards. The second checked row therefore happens to cover a lane of group 0. I tested the following layout for the full 2,064-word reference in hardware():

expected = [F.SENTINEL] * F.WORDS
for group in range(F.GROUPS):
    for lane in range(32):
        head = F.BASE + group * 1024 + lane * 32
        expected[head:head + len(want)] = want
assert words_out == expected

With this fixture-only adjustment, ctest --preset release --no-tests=error -R '^native_packed_f16_inline_' -V passed 5/5 on RTX 4070 plus WARP Pixel. I also ran the same Compute probe with --direct-warp on WARP 1.0.22. Both Compute adapters matched all 24 cases in 64 lanes (1,536 output words and 528 guards). An extra store immediately after each lane's result range tripped both at word 32, expected 0x69696969, actual 0xffffffff.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7230866508 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3230#issuecomment-7230866508). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-28T00:22:51Z. --- I ran this on RTX 4070 (32.0.16.2124) in Release at `2c964029`, DXC 1.9.2602.17, Windows 11 26300.10075. The four IR, compile and Pixel tests passed. The GPU Compute case reached `guard overwritten`. The Compute shader's prologue leaves all 32 lanes active and writes at `group*4096 + lane*128` bytes. The reference checks two 128-dword-spaced rows and treats the other lane records as guards. The second checked row therefore happens to cover a lane of group 0. I tested the following layout for the full 2,064-word reference in `hardware()`: ```python expected = [F.SENTINEL] * F.WORDS for group in range(F.GROUPS): for lane in range(32): head = F.BASE + group * 1024 + lane * 32 expected[head:head + len(want)] = want assert words_out == expected ``` With this fixture-only adjustment, `ctest --preset release --no-tests=error -R '^native_packed_f16_inline_' -V` passed 5/5 on RTX 4070 plus WARP Pixel. I also ran the same Compute probe with `--direct-warp` on WARP 1.0.22. Both Compute adapters matched all 24 cases in 64 lanes (1,536 output words and 528 guards). An extra store immediately after each lane's result range tripped both at word 32, expected `0x69696969`, actual `0xffffffff`.
legacy-code-archaeologist commented 2026-11-28 00:33:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T00:33:05Z.


@RonLogic Thank you for testing on RTX 4070 + WARP 1.0.22 and catching that! Indeed PROLOGUE activates all 32 lanes per group (group*4096 + lane*128 bytes), so checking only the first row per group treated the other 31 lanes' outputs as 0x69696969 guards.

Updated hardware() in tests/native_packed_f16_inline_check.py to verify all 2 x 32 x 24 lane output words and 528 guard words (2,064 dwords total) and force-pushed.

Re-verified locally (dev preset, Windows 10.0.26100):

  • native_packed_f16_inline_ir: passed (24 cases + 10 refusals)
  • native_packed_f16_inline_controls: passed (24 compiled + 10 refusals)
  • native_packed_f16_inline_pixel_warp: passed (12 paired draws / 24 cases)
  • native_packed_f16_inline_pixel_hardware: passed (Intel(R) HD Graphics 530, 12 paired draws / 24 cases)
  • native_packed_f16_inline_compute_hardware: skipped (77, Intel(R) HD Graphics 530 lacks SM 6.6 wave32)

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7231003527 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3230#issuecomment-7231003527). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-28T00:33:05Z. --- @RonLogic Thank you for testing on RTX 4070 + WARP 1.0.22 and catching that! Indeed `PROLOGUE` activates all 32 lanes per group (`group*4096 + lane*128` bytes), so checking only the first row per group treated the other 31 lanes' outputs as `0x69696969` guards. Updated `hardware()` in `tests/native_packed_f16_inline_check.py` to verify all `2 x 32 x 24` lane output words and `528` guard words (`2,064` dwords total) and force-pushed. Re-verified locally (`dev` preset, Windows 10.0.26100): - `native_packed_f16_inline_ir`: passed (`24` cases + `10` refusals) - `native_packed_f16_inline_controls`: passed (`24` compiled + `10` refusals) - `native_packed_f16_inline_pixel_warp`: passed (`12` paired draws / `24` cases) - `native_packed_f16_inline_pixel_hardware`: passed (`Intel(R) HD Graphics 530`, `12` paired draws / `24` cases) - `native_packed_f16_inline_compute_hardware`: skipped (`77`, `Intel(R) HD Graphics 530` lacks SM 6.6 wave32) AI-assisted.
R0Y00 commented 2026-11-28 00:41:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-28T00:41:04Z.

Review: APPROVED


Independently reviewed 37e76fb26e on main 350785e8 (candidate tree ee670c8ac9). Float literals 240–248 supply low half bits with zero upper half, and integer literals 128–208 retain their signed packed representation. Integer min/max still refuses float literals. The corrected GPU Compute fixture now compares all 1,536 result words and 528 sentinel words across 2 groups of 32 lanes. It passed both configurations on RTX 4060 Laptop. The Pixel slice passed on RTX and Microsoft WARP. This is the packed-inline slice only.

Windows 11 26200.9974, RTX 4060 Laptop 32.0.16.1656, WARP 10.0.26100.9818. Debug and Release /O2 each passed all 10 selected tests, including the neighbor descriptor SCC test and existing f16 FMA controls. No skips.

ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^native_(packed_f16_inline_.*|packed_f16_controls|packed_minmax_controls|fma_f16_(controls|ir)|descriptor_scc_hardware)$'
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6094697755 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3230#pullrequestreview-6094697755). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-28T00:41:04Z. **Review:** APPROVED --- Independently reviewed 37e76fb26efa293cc8b84bd9e1093f8d5b8c64cc on main 350785e8 (candidate tree ee670c8ac9845876a5d47f65a576b0ebd4fd3f6c). Float literals 240–248 supply low half bits with zero upper half, and integer literals 128–208 retain their signed packed representation. Integer min/max still refuses float literals. The corrected GPU Compute fixture now compares all 1,536 result words and 528 sentinel words across 2 groups of 32 lanes. It passed both configurations on RTX 4060 Laptop. The Pixel slice passed on RTX and Microsoft WARP. This is the packed-inline slice only. Windows 11 26200.9974, RTX 4060 Laptop 32.0.16.1656, WARP 10.0.26100.9818. Debug and Release /O2 each passed all 10 selected tests, including the neighbor descriptor SCC test and existing f16 FMA controls. No skips. ```powershell ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^native_(packed_f16_inline_.*|packed_f16_controls|packed_minmax_controls|fma_f16_(controls|ir)|descriptor_scc_hardware)$' ```
pigalot commented 2026-11-28 00:52:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T00:52:29Z.

Review: APPROVED


Independently reviewed 37e76fb2 integrated over main 86beae95 (tree ee670c8a). The merge is clean and git diff --cached --check is clean. I started on 2c964029; the only difference is the compute GPU check, covered below.

What I traced.

  • Inline constants. packed_f16_inline_constant() maps 240..248 to the binary16 bits in [15:0] with [31:16] zero. Integer constants 128..208 become 32-bit sign-extended values, so -1 is 0xffffffff. That matches LLVM's VOP3P encoding rule (isInlinableLiteralV216): a v2f16 inline constant is the 16-bit value with a zero high half, and a replicated constant is encoded with op_sel_hi clear. 0x3118 is 1/(2π) in binary16.
  • Other sources. packed_f16_alu() still refuses vcc, m0, exec, scc and the reserved encodings. The integer v_pk_{min,max}_{i,u}16 forms take 128..208 through operand32() and still refuse 240..248.

What I ran. I built compile_dxil native_compute_ir_dump native_store_replay offscreen_check in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_packed_f16_inline_.+$'

The _hardware tests ran at -j 1. All 5 pass in Debug and in Release /O2, with no skips:

  • _ir and _controls: 24 cases and 10 refusals.
  • _pixel_warp and _pixel_hardware: 12 paired draws each.
  • _compute_hardware: "24 cases matched across 2x32 lanes and guards" on the RTX 5090.

The 65 ^native_.*_(controls|ir)$ neighbours pass in dev, except native_raw_buffer_view_controls, which is Not Run because its executable isn't in my build.

The compute GPU check. On 2c964029, native_packed_f16_inline_compute_hardware failed on the RTX 5090 with guard overwritten, the same failure RonLogic reported on an RTX 4070. PROLOGUE lets all 32 lanes store at 8 + 1024 * group + 32 * lane + slot, but the old check modelled only F.BASE + group * 128. I read the whole readback independently: all 1,536 written words (2 groups × 32 lanes × 24 cases) matched the model at those offsets, and every other word was the sentinel. 37e76fb2 builds exactly that expected buffer and compares all 2,064 words, and it passes.

Negative control and mutants. These ran on 2c964029, whose source is the same. Each mutant was rebuilt in dev and run against _ir, _controls, _pixel_warp and _pixel_hardware:

Mutant Result
src/gfx1013_direct_compute.inl back to main killed: "unsupported packed binary16 arithmetic source" in all four
inline float replicated into [31:16] killed (_ir case 9 add_inline_242_hi_zero, both pixel tests)
negative inline integer zero-extended to 16 bits killed (_ir case 16 fma_inline_int_193_nan, both pixel tests)
1/(2π) as 0x3119 killed (_ir case 8, both pixel tests)
integer min/max accepts 240..248 killed (_ir and _controls refusal 7)
packed f16 arithmetic accepts vcc_lo/vcc_hi killed (_ir and _controls refusal 0)
float min/max refuses inline integers killed (_ir, _controls, both pixel tests)

Restored and rebuilt afterwards; git diff --quiet is clean.

Non-blocking. The comment above fma_inline_src0_242_src2_241 ("neg_lo/neg_hi on inline 240 and inline 129 in src2 + SGPR src0") doesn't describe that case. The case has no negation, takes inline 242 in src0, takes v1 in src1 and takes 241 in src2.

Verdict: approve on 37e76fb2.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 dxc.exe (the one CTest picked up); Python 3.12.10; wave32; D3D12 debug layer enabled in the pixel tests.
CI: Build and test on Windows passes on 37e76fb2 (the pr preset doesn't include these tests).

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6094754669 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3230#pullrequestreview-6094754669). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-28T00:52:29Z. **Review:** APPROVED --- Independently reviewed `37e76fb2` integrated over `main` `86beae95` (tree `ee670c8a`). The merge is clean and `git diff --cached --check` is clean. I started on `2c964029`; the only difference is the compute GPU check, covered below. **What I traced.** - **Inline constants.** `packed_f16_inline_constant()` maps 240..248 to the binary16 bits in `[15:0]` with `[31:16]` zero. Integer constants 128..208 become 32-bit sign-extended values, so -1 is `0xffffffff`. That matches LLVM's VOP3P encoding rule (`isInlinableLiteralV216`): a v2f16 inline constant is the 16-bit value with a zero high half, and a replicated constant is encoded with `op_sel_hi` clear. `0x3118` is 1/(2π) in binary16. - **Other sources.** `packed_f16_alu()` still refuses `vcc`, `m0`, `exec`, `scc` and the reserved encodings. The integer `v_pk_{min,max}_{i,u}16` forms take 128..208 through `operand32()` and still refuse 240..248. **What I ran.** I built `compile_dxil native_compute_ir_dump native_store_replay offscreen_check` in `dev` and `release`, then ran ```powershell ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_packed_f16_inline_.+$' ``` The `_hardware` tests ran at `-j 1`. All 5 pass in Debug and in Release `/O2`, with no skips: - `_ir` and `_controls`: 24 cases and 10 refusals. - `_pixel_warp` and `_pixel_hardware`: 12 paired draws each. - `_compute_hardware`: "24 cases matched across 2x32 lanes and guards" on the RTX 5090. The 65 `^native_.*_(controls|ir)$` neighbours pass in `dev`, except `native_raw_buffer_view_controls`, which is Not Run because its executable isn't in my build. **The compute GPU check.** On `2c964029`, `native_packed_f16_inline_compute_hardware` failed on the RTX 5090 with `guard overwritten`, the same failure RonLogic reported on an RTX 4070. `PROLOGUE` lets all 32 lanes store at `8 + 1024 * group + 32 * lane + slot`, but the old check modelled only `F.BASE + group * 128`. I read the whole readback independently: all 1,536 written words (2 groups × 32 lanes × 24 cases) matched the model at those offsets, and every other word was the sentinel. `37e76fb2` builds exactly that expected buffer and compares all 2,064 words, and it passes. **Negative control and mutants.** These ran on `2c964029`, whose source is the same. Each mutant was rebuilt in `dev` and run against `_ir`, `_controls`, `_pixel_warp` and `_pixel_hardware`: | Mutant | Result | |---|---| | `src/gfx1013_direct_compute.inl` back to `main` | killed: "unsupported packed binary16 arithmetic source" in all four | | inline float replicated into `[31:16]` | killed (`_ir` case 9 `add_inline_242_hi_zero`, both pixel tests) | | negative inline integer zero-extended to 16 bits | killed (`_ir` case 16 `fma_inline_int_193_nan`, both pixel tests) | | 1/(2π) as `0x3119` | killed (`_ir` case 8, both pixel tests) | | integer min/max accepts 240..248 | killed (`_ir` and `_controls` refusal 7) | | packed f16 arithmetic accepts `vcc_lo`/`vcc_hi` | killed (`_ir` and `_controls` refusal 0) | | float min/max refuses inline integers | killed (`_ir`, `_controls`, both pixel tests) | Restored and rebuilt afterwards; `git diff --quiet` is clean. **Non-blocking.** The comment above `fma_inline_src0_242_src2_241` ("neg_lo/neg_hi on inline 240 and inline 129 in src2 + SGPR src0") doesn't describe that case. The case has no negation, takes inline 242 in src0, takes `v1` in src1 and takes 241 in src2. **Verdict:** approve on `37e76fb2`. Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 `dxc.exe` (the one CTest picked up); Python 3.12.10; wave32; D3D12 debug layer enabled in the pixel tests. CI: `Build and test on Windows` passes on `37e76fb2` (the `pr` preset doesn't include these tests). This reply was AI-assisted.
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!3230
No description provided.