shader: lower finite in-range binary16 to 16-bit integer conversions in pixel_aot #1070

Merged
tedin7 merged 3 commits from upstream-pr/1077 into main 2026-11-24 01:26:20 +00:00
tedin7 commented 2026-11-24 00:26:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T00:26:36Z.


Change

Adds v_cvt_i16_f16 and v_cvt_u16_f16 (plain, _e32, _e64) to pixel_aot, the follow-up to the integer-to-binary16 slice in #839. The work is AI-assisted (Claude Code).

  • Truncates the binary16 low half toward zero (AMD RDNA 2 ISA section 12.8, VOP1 entries 82 and 83; LLVM 15.0.7 VOP1Instructions.td L436-437 selects fp_to_sint and fp_to_uint) and keeps the two's-complement low half as a low16 result for the audited 16-bit integer readers. The high-half refusals stay.
  • Accepts only a statically proven finite source (inline constant, literal, tracked SGPR, VGPR copy, or a proven binary16 result) under the explicit binary16 entry profile. The range check applies to the truncated integer: -32768..32767 for i16, 0..65535 for u16, so -0.5 gives 0 for both.
  • Refuses modifiers, clamp, omod, DPP/SDWA, non-finite and unproven or runtime sources, and out-of-range values (32768 and -32800 for i16, -1 for u16), plus the round-toward-zero mode.
  • Updates the two form-coverage neighbour lists that named these forms as uncovered, and adds the CTest entries for the new draw.

Refs #839

Verification

Commit under test: 6ef8952a on top of d33845b9. Environment: Linux, Python 3.13 venv from requirements-dev.txt, LLVM 19 tools (llvm-mc-19, llvm-objcopy-19, libLLVM.so.19.1). No Windows, DXC or D3D12 adapter here.

Ran and passed:

  • ./out/pe-env/bin/python -B tests/pixel_aot_check.py: exit 0, including the new check_f16_to_int_controls (every spelling, operand kind, exact refusal messages, range boundaries, mode, scheduling, readers) and a reference check over all 65,536 binary16 values for both kinds against struct format e and math.trunc.
  • ./out/pe-env/bin/python -B tests/form_coverage_check.py: passed, with a new check_f16_to_int16_forms.
  • New check_f16_to_int16_binary (LLVM encodings plus clamp/omod/modifier spellings) and an assemble, disassemble and re-translate round trip of the 9 new draw programs: passed.
  • tests/rdna2_tools_check.py (OK, 97 tests, 8 skipped), tests/docs_links_check.py, tests/bidi_controls_check.py, tests/pso_readiness_check.py, tests/compute_store_check.py binary ...: passed.

Negative control: with the lowering branch disabled (same helper kept), pixel_aot_check.py, form_coverage_check.py and the binary check all fail with Unsupported instruction ... v_cvt_u16_f16_e32 v24, v34 (controls and form coverage) and the v_cvt_i16_f16_e64 v24, -v18 refusal case (binary); with it restored they pass.

Not run: the GPU draw draw-f16-to-int16 (CTest pixel_aot_f16_to_int16_warp and _hardware) needs DXC and a D3D12 adapter. Its Python side (expected words for all 9 programs, the three mutation models and the WORD_1 refusal) was exercised; the WARP and hardware results are pending, so no adapter, driver or Windows build to report. Also not run on LLVM 15: with LLVM 19 the existing check_f16_cvt_int16_binary and the full check_binary fixture loop fail on LLVM-version spelling differences unrelated to this change, so I ran only the new binary check and fixtures.

Evidence and follow-up

Fixtures are synthetic assembly generated in the test (no external inputs). The draw has 6 baked programs (24 u16 and 24 i16 constants in four operand forms, junk in bits 31:16: signed zeros, -0.5, 0.9995, +-1.5, +-2.5, +-1023.5, 32752, -32752, -32768, 32768 to 65504 for u16), two chains and one reader program, read back through the lossless R32G32B32A32_UINT target. Three mutations (round to nearest even, flipped sign, source read from bits 31:16) must each mismatch. Assumptions: the truncation behaviour comes from the ISA text, not from a native measurement, and the high half of the destination is unmeasured. docs/experiments.md has the new paragraph with the exact messages and what is not measured. Runtime sources, saturation and NaN/infinity results stay out of scope for a later slice.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6571760246 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1077). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T00:26:36Z. --- ## Change Adds `v_cvt_i16_f16` and `v_cvt_u16_f16` (plain, `_e32`, `_e64`) to `pixel_aot`, the follow-up to the integer-to-binary16 slice in #839. The work is AI-assisted (Claude Code). - Truncates the binary16 low half toward zero (AMD RDNA 2 ISA section 12.8, VOP1 entries 82 and 83; LLVM 15.0.7 `VOP1Instructions.td` L436-437 selects `fp_to_sint` and `fp_to_uint`) and keeps the two's-complement low half as a `low16` result for the audited 16-bit integer readers. The high-half refusals stay. - Accepts only a statically proven finite source (inline constant, literal, tracked SGPR, VGPR copy, or a proven binary16 result) under the explicit binary16 entry profile. The range check applies to the truncated integer: -32768..32767 for i16, 0..65535 for u16, so -0.5 gives 0 for both. - Refuses modifiers, `clamp`, omod, DPP/SDWA, non-finite and unproven or runtime sources, and out-of-range values (32768 and -32800 for i16, -1 for u16), plus the round-toward-zero mode. - Updates the two form-coverage neighbour lists that named these forms as uncovered, and adds the CTest entries for the new draw. Refs #839 ## Verification Commit under test: `6ef8952a` on top of `d33845b9`. Environment: Linux, Python 3.13 venv from `requirements-dev.txt`, LLVM 19 tools (`llvm-mc-19`, `llvm-objcopy-19`, `libLLVM.so.19.1`). No Windows, DXC or D3D12 adapter here. Ran and passed: - `./out/pe-env/bin/python -B tests/pixel_aot_check.py`: exit 0, including the new `check_f16_to_int_controls` (every spelling, operand kind, exact refusal messages, range boundaries, mode, scheduling, readers) and a reference check over all 65,536 binary16 values for both kinds against `struct` format `e` and `math.trunc`. - `./out/pe-env/bin/python -B tests/form_coverage_check.py`: passed, with a new `check_f16_to_int16_forms`. - New `check_f16_to_int16_binary` (LLVM encodings plus clamp/omod/modifier spellings) and an assemble, disassemble and re-translate round trip of the 9 new draw programs: passed. - `tests/rdna2_tools_check.py` (OK, 97 tests, 8 skipped), `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `tests/pso_readiness_check.py`, `tests/compute_store_check.py binary ...`: passed. Negative control: with the lowering branch disabled (same helper kept), `pixel_aot_check.py`, `form_coverage_check.py` and the binary check all fail with `Unsupported instruction ... v_cvt_u16_f16_e32 v24, v34` (controls and form coverage) and the `v_cvt_i16_f16_e64 v24, -v18` refusal case (binary); with it restored they pass. Not run: the GPU draw `draw-f16-to-int16` (CTest `pixel_aot_f16_to_int16_warp` and `_hardware`) needs DXC and a D3D12 adapter. Its Python side (expected words for all 9 programs, the three mutation models and the WORD_1 refusal) was exercised; the WARP and hardware results are pending, so no adapter, driver or Windows build to report. Also not run on LLVM 15: with LLVM 19 the existing `check_f16_cvt_int16_binary` and the full `check_binary` fixture loop fail on LLVM-version spelling differences unrelated to this change, so I ran only the new binary check and fixtures. ## Evidence and follow-up Fixtures are synthetic assembly generated in the test (no external inputs). The draw has 6 baked programs (24 u16 and 24 i16 constants in four operand forms, junk in bits 31:16: signed zeros, -0.5, 0.9995, +-1.5, +-2.5, +-1023.5, 32752, -32752, -32768, 32768 to 65504 for u16), two chains and one reader program, read back through the lossless `R32G32B32A32_UINT` target. Three mutations (round to nearest even, flipped sign, source read from bits 31:16) must each mismatch. Assumptions: the truncation behaviour comes from the ISA text, not from a native measurement, and the high half of the destination is unmeasured. `docs/experiments.md` has the new paragraph with the exact messages and what is not measured. Runtime sources, saturation and NaN/infinity results stay out of scope for a later slice. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-24 06:46:11 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:49:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T00:26:51Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T00:30:39.239525Z 6ef8952 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7118077348 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1077#issuecomment-7118077348). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T00:26:51Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"6ef8952a1e9c37cacee903b8b18bfe7822508c79","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T00:30:39.239525Z">2026-11-24T00:30:39.239525Z</relative-time> | `6ef8952` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
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!1070
No description provided.