shader: lower non-packed 16-bit integer VOP3 ops #726

Merged
JB2WIN merged 4 commits from upstream-pr/732 into main 2026-11-23 06:45:58 +00:00
JB2WIN commented 2026-11-22 23:49:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-22T23:49:06Z.


Change

tools/pixel_aot.py now lowers the 12 non-packed 16-bit integer VOP3 ops from #669: v_add_nc_u16, v_add_nc_i16, v_sub_nc_u16, v_sub_nc_i16, v_min_u16, v_max_u16, v_min_i16, v_max_i16, v_mul_lo_u16, v_lshlrev_b16, v_lshrrev_b16 and v_ashrrev_i16. The plain and _e64 spellings are accepted, without modifiers.

The change was reworked after review. The result is now a low-16-only value. Only bits 15:0 are defined and tracked, with a tag (("low16", …)), the same mechanism as #713. Nothing is assumed about the high half.

  • Readers allowed to see a low-16 result. Each of them reads only bits 15:0:
    • the 12 ops themselves, so chains work;
    • the 16-bit integer compares v_cmp_*_{i16,u16};
    • v_mov_b32_sdwa with src0_sel:WORD_0, BYTE_0 or BYTE_1, which produces an independently defined word.
  • Refused with a control each. Every whole-word or high-half reader:
    • both export forms, 32-bit integer and float ALU, v_mov_b32_e32, v_cndmask_b32 data operands;
    • DPP, VOP3P int and f16, dot and mix readers, v_cvt_* readers, v_cvt_pkrtz, image coordinates;
    • SDWA WORD_1, BYTE_2, BYTE_3 and DWORD, and an UNUSED_PRESERVE merge into a low-16 destination. The new message is "Reads the undefined high half of a 16-bit result".
  • Lane arithmetic reuses the packed helper: results wrap modulo 2^16, signed ops sign-extend, and shift counts are masked with & 15. The helper's final fallback is now an explicit ashrrev_i16 case followed by a ValueError.
  • Sources: a tracked VGPR (0–255) or low-16 VGPR, a tracked SGPR (0–105), an inline integer from -16 to 64, or a literal up to 0xffff. Also refused: op_sel, clamp, source modifiers, DPP/SDWA spellings, v_mad_u16/v_mad_i16, float tokens and wider literals.
  • Scanner and coverage: the 12 forms are recognised and counted. The scanner is syntactic, so it cannot see the low-16 tags.
  • Docs: the high-word behaviour is kept as a separate paragraph in docs/experiments.md. It cites LLVM's zeroesHigh16BitsOfDest from #669 as an untested hypothesis that needs a native control separating preservation, zeroing and any other behaviour.

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

Verification

Environment: Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818, D3D12 debug layer enabled. Head is rebased on current main.

  • Draw draw-int16-vop3 (pixel_aot_int16_vop3_{hardware,warp}):

    • Four programs. Groups 0 to 2 run four ops each. Group 3 runs a chained op and two 16-bit compares on low-16 results selecting v_cndmask_b32 outputs.
    • Low-16 results are widened with v_mov_b32_sdwa … src0_sel:WORD_0 and exported bit-exactly.
    • The Python reference is written from the semantics and uses only zero-extended low halves.
    • Six word sets cover 0x7fff against 0x8000, 0xffff + 1, 0 - 1, shift counts 15/16/17/31, a negative ashrrev operand, signed/unsigned min/max disagreement, 0x1234 * 0x0567, and sources whose high and low halves differ.
  • Mutations. Each was detected, with the statuses printed by the test:

    • src0's high half instead of its low half;
    • a shift mask of 31;
    • v_min_i16 → v_min_u16;
    • >> 16u on the low-16 read in the chain;
    • >> 16u on the low-16 read in the compare.

    src0_sel:WORD_0 → WORD_1 is refused at lowering.

  • Dev-time checks (not committed): storing the result as a plain value instead of the tag makes the full-word refusal controls fail.

  • Results:

    • ctest --preset dev --no-tests=error -R "^pixel_aot_int16_vop3_": 2/2 passed. Times were 7.3 s on the RTX 3080 and 2.2 s on WARP.
    • Full ctest --preset dev --no-tests=error: 325/325 passed. Skips were bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp, the same as on main.
    • tests/pixel_aot_check.py binary with LLVM 15.0.7 (local llvm-mc through a clang -cc1as shim): exit 0, including the SDWA widening lines.
    • The controls, form_coverage_check.py, rdna2_tools_check.py, pso_readiness_check.py and docs_links_check.py pass.

Limits

  • Synthetic inputs only. The high half of these ops is not modelled. A native RDNA 2 control is still needed before any reader of it can be allowed.
  • The existing v_cmp_*_i16 scanner pattern still uses the wider INTEGER_SOURCE. I did not change it here.
  • docs/coverage/dashboard.svg is not regenerated.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6549404338 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/732). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-22T23:49:06Z. --- ## Change `tools/pixel_aot.py` now lowers the 12 non-packed 16-bit integer VOP3 ops from #669: `v_add_nc_u16`, `v_add_nc_i16`, `v_sub_nc_u16`, `v_sub_nc_i16`, `v_min_u16`, `v_max_u16`, `v_min_i16`, `v_max_i16`, `v_mul_lo_u16`, `v_lshlrev_b16`, `v_lshrrev_b16` and `v_ashrrev_i16`. The plain and `_e64` spellings are accepted, without modifiers. The change was reworked after review. The result is now a **low-16-only value**. Only bits 15:0 are defined and tracked, with a tag (`("low16", …)`), the same mechanism as #713. Nothing is assumed about the high half. - **Readers allowed to see a low-16 result.** Each of them reads only bits 15:0: - the 12 ops themselves, so chains work; - the 16-bit integer compares `v_cmp_*_{i16,u16}`; - `v_mov_b32_sdwa` with `src0_sel:WORD_0`, `BYTE_0` or `BYTE_1`, which produces an independently defined word. - **Refused with a control each.** Every whole-word or high-half reader: - both export forms, 32-bit integer and float ALU, `v_mov_b32_e32`, `v_cndmask_b32` data operands; - DPP, VOP3P int and f16, dot and mix readers, `v_cvt_*` readers, `v_cvt_pkrtz`, image coordinates; - SDWA `WORD_1`, `BYTE_2`, `BYTE_3` and `DWORD`, and an `UNUSED_PRESERVE` merge into a low-16 destination. The new message is "Reads the undefined high half of a 16-bit result". - **Lane arithmetic** reuses the packed helper: results wrap modulo 2^16, signed ops sign-extend, and shift counts are masked with `& 15`. The helper's final fallback is now an explicit `ashrrev_i16` case followed by a `ValueError`. - **Sources:** a tracked VGPR (0–255) or low-16 VGPR, a tracked SGPR (0–105), an inline integer from -16 to 64, or a literal up to `0xffff`. Also refused: `op_sel`, `clamp`, source modifiers, DPP/SDWA spellings, `v_mad_u16`/`v_mad_i16`, float tokens and wider literals. - **Scanner and coverage:** the 12 forms are recognised and counted. The scanner is syntactic, so it cannot see the low-16 tags. - **Docs:** the high-word behaviour is kept as a separate paragraph in `docs/experiments.md`. It cites LLVM's `zeroesHigh16BitsOfDest` from #669 as an **untested hypothesis** that needs a native control separating preservation, zeroing and any other behaviour. Refs #669. AI-assisted (Claude Code). ## Verification Environment: Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818, D3D12 debug layer enabled. Head is rebased on current `main`. - **Draw `draw-int16-vop3`** (`pixel_aot_int16_vop3_{hardware,warp}`): - Four programs. Groups 0 to 2 run four ops each. Group 3 runs a chained op and two 16-bit compares on low-16 results selecting `v_cndmask_b32` outputs. - Low-16 results are widened with `v_mov_b32_sdwa … src0_sel:WORD_0` and exported bit-exactly. - The Python reference is written from the semantics and uses only zero-extended low halves. - Six word sets cover `0x7fff` against `0x8000`, `0xffff + 1`, `0 - 1`, shift counts 15/16/17/31, a negative `ashrrev` operand, signed/unsigned min/max disagreement, `0x1234 * 0x0567`, and sources whose high and low halves differ. - **Mutations.** Each was detected, with the statuses printed by the test: - src0's high half instead of its low half; - a shift mask of 31; - `v_min_i16` → `v_min_u16`; - `>> 16u` on the low-16 read in the chain; - `>> 16u` on the low-16 read in the compare. `src0_sel:WORD_0` → `WORD_1` is refused at lowering. - **Dev-time checks (not committed):** storing the result as a plain value instead of the tag makes the full-word refusal controls fail. - **Results:** - `ctest --preset dev --no-tests=error -R "^pixel_aot_int16_vop3_"`: 2/2 passed. Times were 7.3 s on the RTX 3080 and 2.2 s on WARP. - Full `ctest --preset dev --no-tests=error`: 325/325 passed. Skips were `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp`, the same as on `main`. - `tests/pixel_aot_check.py binary` with LLVM 15.0.7 (local `llvm-mc` through a `clang -cc1as` shim): exit 0, including the SDWA widening lines. - The controls, `form_coverage_check.py`, `rdna2_tools_check.py`, `pso_readiness_check.py` and `docs_links_check.py` pass. ## Limits - Synthetic inputs only. The high half of these ops is not modelled. A native RDNA 2 control is still needed before any reader of it can be allowed. - The existing `v_cmp_*_i16` scanner pattern still uses the wider `INTEGER_SOURCE`. I did not change it here. - `docs/coverage/dashboard.svg` is not regenerated. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:44:33 +00:00
R0Y00 commented 2026-11-24 06:44:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T23:58:21Z.

Review: CHANGES_REQUESTED


The desktop draw demonstrates the proposed upper-half model, but the current lowerer exposes that model as a full 32-bit guest value. LLVM evidence in #669 does not independently establish that the old high half is always preserved on gfx1013, and an uninitialized high half cannot be assumed to be zero. For a first mergeable slice, track a low-16-only result and reject consumers that would observe the high word, unless that word is independently defined by a supported instruction. Reuse the low-half tagging approach in the #713 experiment where it fits. Add a positive low-half draw and a rejected full-word export or arithmetic consumer. Keep the high-word experiment separately documented until a native control distinguishes preservation, zeroing and any other defined behavior.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6015226007 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/732#pullrequestreview-6015226007). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T23:58:21Z. **Review:** CHANGES_REQUESTED --- The desktop draw demonstrates the proposed upper-half model, but the current lowerer exposes that model as a full 32-bit guest value. LLVM evidence in #669 does not independently establish that the old high half is always preserved on gfx1013, and an uninitialized high half cannot be assumed to be zero. For a first mergeable slice, track a low-16-only result and reject consumers that would observe the high word, unless that word is independently defined by a supported instruction. Reuse the low-half tagging approach in the #713 experiment where it fits. Add a positive low-half draw and a rejected full-word export or arithmetic consumer. Keep the high-word experiment separately documented until a native control distinguishes preservation, zeroing and any other defined behavior.
R0Y00 commented 2026-11-24 06:44:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T06:44:19Z.

Review: APPROVED


The previous change request is resolved at 90f615b. The non-packed results track only the low 16 bits, unsupported full-word consumers are refused, and the focused WARP draw detects all five mutations. I verified both Windows jobs and both Linux jobs on this commit, and the test registration retains the compressed-export fixture.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6017497686 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/732#pullrequestreview-6017497686). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T06:44:19Z. **Review:** APPROVED --- The previous change request is resolved at `90f615b`. The non-packed results track only the low 16 bits, unsupported full-word consumers are refused, and the focused WARP draw detects all five mutations. I verified both Windows jobs and both Linux jobs on this commit, and the test registration retains the compressed-export fixture.
JB2WIN commented 2026-11-24 06:48:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T00:05:00Z.


Thanks. I'm reworking this as you describe:

  • The 12 ops' results are tracked as a low-16-only value, with a tag like the one in #713.
  • Only the 16-bit ops themselves, the 16-bit compares and v_mov_b32_sdwa with src0_sel:WORD_0/BYTE_0/BYTE_1 may read it. Every whole-word or high-half reader (export, 32-bit arithmetic, moves, DPP, VOP3P, packs, SDWA WORD_1) is refused, each with its own control.
  • I'm adding a drawn low-half path, including a chain and a compare-on-result. The high-word question goes into the docs as a separate, untested hypothesis.

I'll push it here and ask for a re-review.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7088048448 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/732#issuecomment-7088048448). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T00:05:00Z. --- Thanks. I'm reworking this as you describe: - The 12 ops' results are tracked as a low-16-only value, with a tag like the one in #713. - Only the 16-bit ops themselves, the 16-bit compares and `v_mov_b32_sdwa` with `src0_sel:WORD_0/BYTE_0/BYTE_1` may read it. Every whole-word or high-half reader (export, 32-bit arithmetic, moves, DPP, VOP3P, packs, SDWA `WORD_1`) is refused, each with its own control. - I'm adding a drawn low-half path, including a chain and a compare-on-result. The high-word question goes into the docs as a separate, untested hypothesis. I'll push it here and ask for a re-review.
JB2WIN commented 2026-11-24 06:48:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T00:25:30Z.


Reworked as requested and rebased on main. Results are now low-16-only values, with refusal controls for each whole-word and high-half reader and a drawn chain and compare path. The high-word model is documented separately as an untested hypothesis. Details and results are in the updated description. Full suite: 325/325 on RTX 3080 + WARP.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7088337624 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/732#issuecomment-7088337624). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T00:25:30Z. --- Reworked as requested and rebased on `main`. Results are now low-16-only values, with refusal controls for each whole-word and high-half reader and a drawn chain and compare path. The high-word model is documented separately as an untested hypothesis. Details and results are in the updated description. Full suite: 325/325 on RTX 3080 + WARP.
JB2WIN commented 2026-11-24 06:48:56 +00:00 (Migrated from github.com)

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


Rebased on 37ed46d and squashed into one commit, with no change in content. Full suite: 333/333 on RTX 3080 + WARP. pixel_aot_int16_vop3_* takes 7.2 s / 2.2 s.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7089352136 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/732#issuecomment-7089352136). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T01:42:10Z. --- Rebased on `37ed46d` and squashed into one commit, with no change in content. Full suite: 333/333 on RTX 3080 + WARP. `pixel_aot_int16_vop3_*` takes 7.2 s / 2.2 s.
JB2WIN commented 2026-11-24 06:49:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T04:42:54Z.


A related question for a follow-up, not for this PR. On main, v_cvt_f16_f32 (from #324) still merges the destination's old high half into its result (tools/pixel_aot.py, comment: "the high half of the destination is kept"). That is the preserve model this PR now drops. Once this lands, should v_cvt_f16_f32 move to the same low-16-only result, with v_cvt_f32_f16, v_pack_b32_f16 and the SDWA WORD_0 move as its readers? Or should it keep the preserve model until a native control exists? I'd open that separately in whichever direction you prefer.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7091807160 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/732#issuecomment-7091807160). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T04:42:54Z. --- A related question for a follow-up, not for this PR. On `main`, `v_cvt_f16_f32` (from #324) still merges the destination's old high half into its result (`tools/pixel_aot.py`, comment: "the high half of the destination is kept"). That is the preserve model this PR now drops. Once this lands, should `v_cvt_f16_f32` move to the same low-16-only result, with `v_cvt_f32_f16`, `v_pack_b32_f16` and the SDWA `WORD_0` move as its readers? Or should it keep the preserve model until a native control exists? I'd open that separately in whichever direction you prefer.
R0Y00 commented 2026-11-24 06:49:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T04:51:28Z.


Keep the existing v_cvt_f16_f32 behavior for now. The low-16 contract here is specific to the twelve integer forms and their verified readers. A separate control should establish what the native conversion leaves in the upper half before changing it. The conversion follow-up does not need to block this PR.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7091922434 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/732#issuecomment-7091922434). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T04:51:28Z. --- Keep the existing `v_cvt_f16_f32` behavior for now. The low-16 contract here is specific to the twelve integer forms and their verified readers. A separate control should establish what the native conversion leaves in the upper half before changing it. The conversion follow-up does not need to block this PR.
R0Y00 commented 2026-11-24 06:49:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T05:35:59Z.


I pushed cbf7fa0 to resolve conflicts while keeping the current main fixtures and this PR’s low-16-only scope. The Windows Release WARP draw passed and detected all five injected mutations. The form coverage and Python controls passed; the local decoder suite’s LLVM-dependent case was skipped. Waiting for the full CI on this SHA.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7092546267 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/732#issuecomment-7092546267). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T05:35:59Z. --- I pushed `cbf7fa0` to resolve conflicts while keeping the current main fixtures and this PR’s low-16-only scope. The Windows Release WARP draw passed and detected all five injected mutations. The form coverage and Python controls passed; the local decoder suite’s LLVM-dependent case was skipped. Waiting for the full CI on this SHA.
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!726
No description provided.