shader: lower v_cvt_f16_u16, v_cvt_f16_i16, v_cvt_u16_f16 and v_cvt_i16_f16 in the direct compute path #3161

Manually merged
github merged 2 commits from github-bot/gh-3159 into gh-pr/3159/base 2026-11-27 20:47:08 +00:00 AGit
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-27 19:09 UTC · original
legacy-code-archaeologist:shader/direct-cvt-f16-i16 → main · +525 −1 · 4 files · 2 commits · merged 2026-11-27 20:43 UTC

Lowers v_cvt_f16_u16, v_cvt_f16_i16, v_cvt_u16_f16, and v_cvt_i16_f16 (VOP1 and VOP3A) in the direct C++ compute path (src/gfx1013_direct_compute.inl), preserving D[31:16] and enforcing the binary16 MODE contract via half_binary.

Verification

Measured on Windows 10.0.26100 (dev preset) at upstream/main 429f11d5 + 6772a597:

  • ctest --preset dev --no-tests=error -R '^native_cvt_f16_i16_' -V:
    • native_cvt_f16_i16_ir (passed, 1.09s): evaluates DXIL IR via native_compute_ir_dump across 82 conversion cases (VGPR, SGPR, literal, inline ints/floats, VOP3 clamp/abs/neg/-|x|, RNE ties, saturation, subnormals, infinities, NaNs, non-zero upper halves) and 38 refusals (DPP, SDWA, omod, op_sel, illegal abs/neg/clamp, src1, and MODE writes).
    • native_cvt_f16_i16_controls (passed, 3.84s): compiles all 82 conversions to DXIL via compile_dxil and verifies all 38 refusals.
    • native_cvt_f16_i16_hardware (skipped, exit 77): Quadro M1000M does not support shader model 6.6 with wave32, so GPU readback is not measured.
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 47/47 passed (54.43s).
  • python -B tests/docs_links_check.py: passed (101 Markdown files, 589 links).
  • Broken-lowering sensitivity check: 5 deliberate mutations (zero_high_half, drop_ordered_nan, swap_signed, drop_clamp, wrong_inline_float) each failed native_cvt_f16_i16_ir (exit 1).

Fixes #3150
Refs #2935

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-27 19:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3159) `legacy-code-archaeologist:shader/direct-cvt-f16-i16` → `main` · +525 −1 · 4 files · 2 commits · merged 2026-11-27 20:43 UTC Lowers `v_cvt_f16_u16`, `v_cvt_f16_i16`, `v_cvt_u16_f16`, and `v_cvt_i16_f16` (VOP1 and VOP3A) in the direct C++ compute path (`src/gfx1013_direct_compute.inl`), preserving `D[31:16]` and enforcing the binary16 MODE contract via `half_binary`. ## Verification Measured on Windows 10.0.26100 (`dev` preset) at `upstream/main` `429f11d5` + `6772a597`: - `ctest --preset dev --no-tests=error -R '^native_cvt_f16_i16_' -V`: - `native_cvt_f16_i16_ir` (**passed**, `1.09s`): evaluates DXIL IR via `native_compute_ir_dump` across 82 conversion cases (VGPR, SGPR, literal, inline ints/floats, VOP3 `clamp`/`abs`/`neg`/`-|x|`, RNE ties, saturation, subnormals, infinities, NaNs, non-zero upper halves) and 38 refusals (DPP, SDWA, `omod`, `op_sel`, illegal `abs`/`neg`/`clamp`, `src1`, and MODE writes). - `native_cvt_f16_i16_controls` (**passed**, `3.84s`): compiles all 82 conversions to DXIL via `compile_dxil` and verifies all 38 refusals. - `native_cvt_f16_i16_hardware` (**skipped**, exit `77`): Quadro M1000M does not support shader model 6.6 with wave32, so GPU readback is not measured. - `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure`: **47/47 passed** (`54.43s`). - `python -B tests/docs_links_check.py`: **passed** (101 Markdown files, 589 links). - Broken-lowering sensitivity check: 5 deliberate mutations (`zero_high_half`, `drop_ordered_nan`, `swap_signed`, `drop_clamp`, `wrong_inline_float`) each failed `native_cvt_f16_i16_ir` (exit `1`). Fixes #3150 Refs #2935 AI-assisted.
Lower VOP1 and VOP3A v_cvt_f16_u16, v_cvt_f16_i16, v_cvt_u16_f16 and v_cvt_i16_f16 in DirectCompute::float_alu() preserving D[31:16] on gfx10.

Int16/u16 -> f16 converts via sitofp/uitofp and packed_half_rne() round-to-nearest-even (with optional VOP3 clamp to [0.0, 1.0]); f16 -> i16/u16 widens via legacyF16ToF32, truncates toward zero, saturates to [-32768, 32767] / [0, 65535], maps NaN to 0, and supports VOP3 abs/neg.

Also add all four conversions to half_binary in DirectCompute::lower() so the default binary16 rounding/denormal MODE contract is enforced.

Fixes #3148

Refs #2935

AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 19:14:44 +00:00
github-bot changed target branch from main to gh-pr/3159/base 2026-11-27 20:47:03 +00:00
github manually merged commit 7adec5b78f into gh-pr/3159/base 2026-11-27 20:47:08 +00:00
Author
Owner

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

Review of 7adec5b78f (updated with main). Comment only.

The four conversions read inline float sources 240-248 as their binary16 values (the same nine constants as inline_half_words, which #3149 just made a shared member; the local halves[] copy here could use it in a follow-up), and literal and inline integer sources as their low 16 bits. f16 -> i16/u16 truncates through fptosi/fptoui only on an in-range value, saturates out-of-range values to the type bounds and maps NaN to 0; i16/u16 -> f16 goes through f32 and packed_half_rne, which is exact because every 16-bit integer is exact in f32. Unsupported forms (DPP, SDWA, omod, op_sel high half, modifiers on the integer source, an unknown rounding or denormal mode) are refused. native_cvt_f16_i16_ir checks 82 cases at the IR level without a GPU, so the semantics are covered on WARP hosts and in CI even though the _hardware leg skips.

src/gfx1013_direct_compute.inl is also changed on cpp-migration; this merges cleanly there and the native sweep passes on that merge (comment below).

Commands: git diff origin/main...pull/3159/head (read), git merge-tree --write-tree origin/cpp-migration pull/3159/head, plus the Windows commands in the comment below.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-27 20:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3159#pullrequestreview-6093174936) · **reviewed** Review of 7adec5b78f8c0467765ef7857bb4db10be3ed5f5 (updated with main). Comment only. The four conversions read inline float sources 240-248 as their binary16 values (the same nine constants as `inline_half_words`, which #3149 just made a shared member; the local `halves[]` copy here could use it in a follow-up), and literal and inline integer sources as their low 16 bits. `f16 -> i16/u16` truncates through `fptosi`/`fptoui` only on an in-range value, saturates out-of-range values to the type bounds and maps NaN to 0; `i16/u16 -> f16` goes through f32 and `packed_half_rne`, which is exact because every 16-bit integer is exact in f32. Unsupported forms (DPP, SDWA, omod, op_sel high half, modifiers on the integer source, an unknown rounding or denormal mode) are refused. `native_cvt_f16_i16_ir` checks 82 cases at the IR level without a GPU, so the semantics are covered on WARP hosts and in CI even though the `_hardware` leg skips. `src/gfx1013_direct_compute.inl` is also changed on `cpp-migration`; this merges cleanly there and the native sweep passes on that merge (comment below). Commands: `git diff origin/main...pull/3159/head` (read), `git merge-tree --write-tree origin/cpp-migration pull/3159/head`, plus the Windows commands in the comment below. AI-assisted; commands listed were executed locally.
Author
Owner

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

Windows Server 2025 verification of 7adec5b78f8c0467765ef7857bb4db10be3ed5f5 (D3D12 WARP, MSVC 14.44.35207):

  • dev: cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump; ctest --preset dev -R <native sweep>: 100% tests passed out of 143 (84 passed, 59 hardware legs skipped), including native_cvt_f16_i16_ir and native_cvt_f16_i16_controls
  • release: same targets with --preset release; ctest --preset release -R <native sweep>: 100% tests passed out of 143 (84 passed, 59 skipped)
  • The same dev and release sweep on this head merged with cpp-migration (a0f67731): 100% tests passed out of 143 in both presets

<native sweep> = every native_* test except native_startup_request_cache_hardware, which fails on WARP-only hosts with or without this PR.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-27 20:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3159#issuecomment-7227769071) Windows Server 2025 verification of `7adec5b78f8c0467765ef7857bb4db10be3ed5f5` (D3D12 WARP, MSVC 14.44.35207): - dev: `cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump`; `ctest --preset dev -R <native sweep>`: 100% tests passed out of 143 (84 passed, 59 hardware legs skipped), including `native_cvt_f16_i16_ir` and `native_cvt_f16_i16_controls` - release: same targets with `--preset release`; `ctest --preset release -R <native sweep>`: 100% tests passed out of 143 (84 passed, 59 skipped) - The same dev and release sweep on this head merged with `cpp-migration` (`a0f67731`): 100% tests passed out of 143 in both presets `<native sweep>` = every `native_*` test except `native_startup_request_cache_hardware`, which fails on WARP-only hosts with or without this PR. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠xiaoqi72665 on GitHub · 2026-11-27 21:35 UTC · original

@⁠legacy-code-archaeologist Thanks for #3161. During #3187's rebase regression on 5b145ca, the stock conversion hardware fixture reached its last guard assertion and raised AttributeError: module 'native_f16_alu_check' has no attribute 'SENTINEL' (tests/native_cvt_f16_i16_check.py). The preceding 82 conversion comparisons across both groups passed. With an ignored local diagnostic copy comparing the entire 2064-DWORD buffer to the expected conversion positions plus 0x69696969 guards, RX 7900 XT and app-local WARP passed in both Debug and Release on Win10. Suggested minimal fix: construct the full expected buffer (including zeros in the actual guard check), rather than filtering zero words. IR and compile controls also passed. No changes to your files in #3187. AI-assisted, tested locally by Buhe.

**@⁠xiaoqi72665** on GitHub · 2026-11-27 21:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3159#issuecomment-7228580104) @⁠legacy-code-archaeologist Thanks for #3161. During #3187's rebase regression on 5b145ca, the stock conversion hardware fixture reached its last guard assertion and raised `AttributeError: module 'native_f16_alu_check' has no attribute 'SENTINEL'` (tests/native_cvt_f16_i16_check.py). The preceding 82 conversion comparisons across both groups passed. With an ignored local diagnostic copy comparing the entire 2064-DWORD buffer to the expected conversion positions plus 0x69696969 guards, RX 7900 XT and app-local WARP passed in both Debug and Release on Win10. Suggested minimal fix: construct the full expected buffer (including zeros in the actual guard check), rather than filtering zero words. IR and compile controls also passed. No changes to your files in #3187. AI-assisted, tested locally by Buhe.
This discussion has been locked. Commenting is limited to contributors.
No description provided.