shader: lower the 16-bit integer to binary16 conversions in pixel_aot #914

Merged
JB2WIN merged 2 commits from upstream-pr/921 into main 2026-11-23 17:53:06 +00:00
JB2WIN commented 2026-11-23 17:10:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T17:10:39Z.


Change

This is the third binary16 slice from #839. tools/pixel_aot.py now lowers v_cvt_f16_i16 and v_cvt_f16_u16 in the plain, _e32 and _e64 spellings. It follows the scope set in #839.

  • v_cvt_f16_i16 accepts runtime sources. The source goes through the existing audited low-16 integer reader (int16_operand, signed), which sign-extends bits 15:0. Every i16 value converts to a finite binary16, so no constant proof is needed. A runtime result has no known value, so the #854/#881 finite-proof ops refuse it as an operand. A control covers this.
  • v_cvt_f16_u16 needs a proven value below 65520. A runtime source is refused with binary16 conversion source lacks a range proof: <tok>. A proven value of 65520 or more is refused with binary16 result overflows: v_cvt_f16_u16. This includes the inline constants -16…-1, which read as 0xfff0…0xffff. 65519 becomes 65504 (0x7bff).
  • Conversion. The integer converts to binary32 exactly, because |x| ≤ 65535 < 2^24. One narrow16 then gives round-to-nearest-even. The source is LLVM 15.0.7 VOP1Instructions.td L432-433: uint_to_fp and sint_to_fp.
  • Unchanged from earlier slices. Both forms require the explicit half_denorm="preserve\" entry profile. The result is a half16 low half that only the audited readers may read. Modifiers, clamp, omod, op_sel, DPP and SDWA are refused.
  • Changed expectation. check_int16_vop3_forms listed ("VOP3","v_cvt_f16_u16_e64") as a refused neighbour. It is replaced by ("VOP3","v_cvt_i16_f16_e64"), which is still refused.

Refs #839. AI-assisted (Claude Code).

Verification

Environment: Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP, at da9bc9c.

  • Draw draw-f16-cvt-int16 (pixel_aot_f16_cvt_int16_{hardware,warp}):

    • One compiled signed shader runs 10 cases from the constant buffer. The high halves vary independently of the low halves. The cases include -32768, 32767, 2049 and -2049 (ties to 2048 and -2048), 0 (expected +0, 0x0000), halfway values in several binades (4098, 4102, 16392, 16408, 32760 and their negatives) and the non-ties 4097 and 4099. One value appears under four different high halves.
    • Six baked programs cover proven u16 and i16 constants, including 65519 → 65504, plus two chains into the #854 arithmetic.
    • All results are read back as raw bits and compared with an independent Python reference. That reference matches struct format e over all 65,536 values of both kinds.
  • Mutations. Each must mismatch, and each did on both adapters:

    • zero-extension instead of sign-extension (8 of 10 runtime cases, plus a baked case);
    • ties away from zero instead of ties to even (7 of 10, plus a baked case);
    • the source read from its high half (10 of 10).

    A check before the GPU run confirms that each mutation changes an expected row.

  • Dev-time check (not committed). With the new branch disabled, the new controls fail inside check_controls.

  • Commands:

    • ctest --preset dev --no-tests=error -R "^pixel_aot_f16_cvt_int16_": 2/2 passed (4.7 s on hardware).
    • Full ctest --preset dev --no-tests=error -j4: 478/478 passed. Only capability skips occurred.
    • The LLVM 15 binary round trip passes, with pinned encodings 02 a3 02 7e (i16 e32), 02 a1 02 7e (u16 e32) and 01 80 d1 d5 … (e64 clamp, which is refused). llvm-mc runs locally through a clang -cc1as shim.
    • The controls, form_coverage_check.py, rdna2_tools_check.py, pso_readiness_check.py and docs_links_check.py pass.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6564646611 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/921). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T17:10:39Z. --- ## Change This is the third binary16 slice from #839. `tools/pixel_aot.py` now lowers `v_cvt_f16_i16` and `v_cvt_f16_u16` in the plain, `_e32` and `_e64` spellings. It follows the scope set in #839. - **`v_cvt_f16_i16` accepts runtime sources.** The source goes through the existing audited low-16 integer reader (`int16_operand`, signed), which sign-extends bits 15:0. Every i16 value converts to a finite binary16, so no constant proof is needed. A runtime result has no known value, so the #854/#881 finite-proof ops refuse it as an operand. A control covers this. - **`v_cvt_f16_u16` needs a proven value below 65520.** A runtime source is refused with `binary16 conversion source lacks a range proof: <tok>`. A proven value of 65520 or more is refused with `binary16 result overflows: v_cvt_f16_u16`. This includes the inline constants -16…-1, which read as 0xfff0…0xffff. 65519 becomes 65504 (`0x7bff`). - **Conversion.** The integer converts to binary32 exactly, because |x| ≤ 65535 < 2^24. One `narrow16` then gives round-to-nearest-even. The source is LLVM 15.0.7 `VOP1Instructions.td` L432-433: `uint_to_fp` and `sint_to_fp`. - **Unchanged from earlier slices.** Both forms require the explicit `half_denorm="preserve\"` entry profile. The result is a `half16` low half that only the audited readers may read. Modifiers, `clamp`, omod, `op_sel`, DPP and SDWA are refused. - **Changed expectation.** `check_int16_vop3_forms` listed `("VOP3","v_cvt_f16_u16_e64")` as a refused neighbour. It is replaced by `("VOP3","v_cvt_i16_f16_e64")`, which is still refused. Refs #839. AI-assisted (Claude Code). ## Verification Environment: Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP, at `da9bc9c`. - **Draw `draw-f16-cvt-int16`** (`pixel_aot_f16_cvt_int16_{hardware,warp}`): - One compiled signed shader runs 10 cases from the constant buffer. The high halves vary independently of the low halves. The cases include -32768, 32767, 2049 and -2049 (ties to 2048 and -2048), 0 (expected +0, `0x0000`), halfway values in several binades (4098, 4102, 16392, 16408, 32760 and their negatives) and the non-ties 4097 and 4099. One value appears under four different high halves. - Six baked programs cover proven u16 and i16 constants, including 65519 → 65504, plus two chains into the #854 arithmetic. - All results are read back as raw bits and compared with an independent Python reference. That reference matches `struct` format `e` over all 65,536 values of both kinds. - **Mutations.** Each must mismatch, and each did on both adapters: - zero-extension instead of sign-extension (8 of 10 runtime cases, plus a baked case); - ties away from zero instead of ties to even (7 of 10, plus a baked case); - the source read from its high half (10 of 10). A check before the GPU run confirms that each mutation changes an expected row. - **Dev-time check (not committed).** With the new branch disabled, the new controls fail inside `check_controls`. - **Commands:** - `ctest --preset dev --no-tests=error -R "^pixel_aot_f16_cvt_int16_"`: 2/2 passed (4.7 s on hardware). - Full `ctest --preset dev --no-tests=error -j4`: 478/478 passed. Only capability skips occurred. - The LLVM 15 binary round trip passes, with pinned encodings `02 a3 02 7e` (i16 e32), `02 a1 02 7e` (u16 e32) and `01 80 d1 d5 …` (e64 clamp, which is refused). `llvm-mc` runs locally through a `clang -cc1as` shim. - The controls, `form_coverage_check.py`, `rdna2_tools_check.py`, `pso_readiness_check.py` and `docs_links_check.py` pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:45:25 +00:00
R0Y00 commented 2026-11-24 06:49:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T17:26:32Z.


1591a01 resolves the test-runner conflict and keeps the SMEM and i16-to-binary16 draw modes. WARP passed all four cases in the combined tree: the new conversion, half arithmetic, half rounding and SMEM pointers. The zero-extension, ties-away and high-half readback mutations fired. The signed runtime path stays low-half-only, and the unsigned overflow/unproven-source refusals remain in the fixture. Fresh CI is running.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7108663129 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/921#issuecomment-7108663129). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T17:26:32Z. --- 1591a01 resolves the test-runner conflict and keeps the SMEM and i16-to-binary16 draw modes. WARP passed all four cases in the combined tree: the new conversion, half arithmetic, half rounding and SMEM pointers. The zero-extension, ties-away and high-half readback mutations fired. The signed runtime path stays low-half-only, and the unsigned overflow/unproven-source refusals remain in the fixture. Fresh CI is running.
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!914
No description provided.