shader: convert signed and unsigned SDWA words to f32 #1637

Closed
itzJaack wants to merge 1 commit from upstream-pr/1644 into main
itzJaack commented 2026-11-24 15:42:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by itzJaack on 2026-11-24T15:42:57Z.


Lower v_cvt_f32_i32_sdwa and v_cvt_f32_u32_sdwa with a full DWORD destination. Apply the source selection and optional sign extension before interpreting the word as signed or unsigned. Apply optional clamp after conversion. The scanner accepts the same operand spellings. The draw fixture covers signed and unsigned interpretations of an extended negative byte, output clamp, and two rounding ties. An incorrect expected pixel is a negative control.

Local verification on Linux

  • python -B tests/pixel_aot_check.py passed.
  • LLVM 19 decoded the independent MC encodings f90a0a7e01060e00 and f90c0a7e01060e00 on gfx1013 and gfx1030. All four decoded cases passed the scanner and lowered.
  • The draw is integrated into the Windows conversion tests. The contributor's RTX was not used for this patch.

AI Driven - Specs: AMD Ryzen 7 9850X3D | NVIDIA GeForce RTX 5070 Ti | 16 GB DDR5 | Windows 11 Pro | Model: 6.2 Astra Medium

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6585621793 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1644). Originally posted by [itzJaack](https://github.com/itzJaack) on 2026-11-24T15:42:57Z. --- Lower `v_cvt_f32_i32_sdwa` and `v_cvt_f32_u32_sdwa` with a full DWORD destination. Apply the source selection and optional sign extension before interpreting the word as signed or unsigned. Apply optional clamp after conversion. The scanner accepts the same operand spellings. The draw fixture covers signed and unsigned interpretations of an extended negative byte, output clamp, and two rounding ties. An incorrect expected pixel is a negative control. **Local verification on Linux** - `python -B tests/pixel_aot_check.py` passed. - LLVM 19 decoded the independent MC encodings `f90a0a7e01060e00` and `f90c0a7e01060e00` on gfx1013 and gfx1030. All four decoded cases passed the scanner and lowered. - The draw is integrated into the Windows conversion tests. The contributor's RTX was not used for this patch. AI Driven - Specs: AMD Ryzen 7 9850X3D | NVIDIA GeForce RTX 5070 Ti | 16 GB DDR5 | Windows 11 Pro | Model: 6.2 Astra Medium
chatgpt-codex-connector[bot commented 2026-11-24 16:03:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T15:48:42Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d7b5a5c2a0

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6042589605 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1644#pullrequestreview-6042589605). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T15:48:42Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `d7b5a5c2a0` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
tedin7 commented 2026-11-24 16:03:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:55:57Z.

Review: COMMENTED


Dual-platform peer review at commit d7b5a5c2a0989ff1b28b56d29180cba4aebb0d7f: 0 blocking issues.

Findings

  • tools/pixel_aot.py & tools/scan_unsupported_shaders.py: lowers v_cvt_f32_i32_sdwa and v_cvt_f32_u32_sdwa with dst_sel:DWORD, dst_unused:UNUSED_(?:PAD|PRESERVE), src0_sel:(BYTE_[0-3]|WORD_[01]|DWORD), optional sext(...) on [vs]\d+, and optional clamp.
    • Uses int_operand(..., signed=False) (rejecting non-numeric/16-bit-tuple registers and pending sample hazards) followed by sdwa_source(word, field, sext) and asint(...) for i32 vs unsigned for u32, wrapping in saturate(...) when clamp is present.
    • Enforces mask == "entry", v0..v255 destination bounds, and sample_dest overlap refusal.
  • tests/pixel_aot_check.py & tests/form_coverage_check.py: includes static rejection checks (invalid dst_sel, malformed sext, literal source, v256), WARP draw verification covering sext sign-extension (-128.0), unsigned sext rounding (2**32), clamp, WORD_1/DWORD nearest-even midpoint rounding, and a negative mismatch control.

Verification

  • Linux:
    • python3 tests/docs_links_check.py: passed (16 Markdown files, 348 links).
    • python3 tests/bidi_controls_check.py: passed (1263 tracked files).
    • python3 tests/pixel_aot_check.py: passed.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Python checks: tests/form_coverage_check.py (46.9s), tests/pixel_aot_check.py (14.2s) — passed.
    • Debug (--preset dev): cmake --build --preset dev --target d3d12_xs_shim -- -j 6 (4.35s); ctest --preset dev -R '^(pixel_aot_cvt_float_int_e64_warp|pixel_aot_warp|rdna2_tools_check)$' --parallel 4 --no-tests=error --output-on-failure — 3/3 passed (16.91s).
    • Release /O2 (--preset release): cmake --build --preset release --target d3d12_xs_shim -- -j 6 (1.56s); ctest --preset release -R '^(pixel_aot_cvt_float_int_e64_warp|pixel_aot_warp|rdna2_tools_check)$' --parallel 4 --no-tests=error --output-on-failure — 3/3 passed (17.11s).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6042723129 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1644#pullrequestreview-6042723129). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T15:55:57Z. **Review:** COMMENTED --- Dual-platform peer review at commit `d7b5a5c2a0989ff1b28b56d29180cba4aebb0d7f`: **0 blocking issues**. ### Findings - `tools/pixel_aot.py` & `tools/scan_unsupported_shaders.py`: lowers `v_cvt_f32_i32_sdwa` and `v_cvt_f32_u32_sdwa` with `dst_sel:DWORD`, `dst_unused:UNUSED_(?:PAD|PRESERVE)`, `src0_sel:(BYTE_[0-3]|WORD_[01]|DWORD)`, optional `sext(...)` on `[vs]\d+`, and optional `clamp`. - Uses `int_operand(..., signed=False)` (rejecting non-numeric/16-bit-tuple registers and pending sample hazards) followed by `sdwa_source(word, field, sext)` and `asint(...)` for `i32` vs unsigned for `u32`, wrapping in `saturate(...)` when `clamp` is present. - Enforces `mask == "entry"`, `v0..v255` destination bounds, and `sample_dest` overlap refusal. - `tests/pixel_aot_check.py` & `tests/form_coverage_check.py`: includes static rejection checks (invalid `dst_sel`, malformed `sext`, literal source, `v256`), WARP draw verification covering `sext` sign-extension (`-128.0`), unsigned `sext` rounding (`2**32`), `clamp`, `WORD_1`/`DWORD` nearest-even midpoint rounding, and a negative mismatch control. ### Verification - **Linux**: - `python3 tests/docs_links_check.py`: passed (16 Markdown files, 348 links). - `python3 tests/bidi_controls_check.py`: passed (1263 tracked files). - `python3 tests/pixel_aot_check.py`: passed. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - Python checks: `tests/form_coverage_check.py` (`46.9s`), `tests/pixel_aot_check.py` (`14.2s`) — passed. - Debug (`--preset dev`): `cmake --build --preset dev --target d3d12_xs_shim -- -j 6` (`4.35s`); `ctest --preset dev -R '^(pixel_aot_cvt_float_int_e64_warp|pixel_aot_warp|rdna2_tools_check)$' --parallel 4 --no-tests=error --output-on-failure` — **3/3 passed** (`16.91s`). - Release `/O2` (`--preset release`): `cmake --build --preset release --target d3d12_xs_shim -- -j 6` (`1.56s`); `ctest --preset release -R '^(pixel_aot_cvt_float_int_e64_warp|pixel_aot_warp|rdna2_tools_check)$' --parallel 4 --no-tests=error --output-on-failure` — **3/3 passed** (`17.11s`). AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-24 16:03:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T15:43:12Z.


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-24T15:48:44.942550Z d7b5a5c 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:7136497188 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1644#issuecomment-7136497188). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T15:43:12Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"d7b5a5c2a0989ff1b28b56d29180cba4aebb0d7f","has_any_findings":true,"has_unresolved_findings":true,"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-24T15:48:44.942550Z">2026-11-24T15:48:44.942550Z</relative-time> | `d7b5a5c` | 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>
chatgpt-codex-connector[bot commented 2026-11-24 16:03:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T15:48:42Z.

Code review location: tools/pixel_aot.py; line 4437

@@ -4434,6 +4434,22 @@ def sample_coord(reg):
             result = sdwa_dest(sdwa_source(word, src_sel, bool(sext)), dst_sel, unused, old_value)
             vector[dst] = f"alu{i}"
             lines.append(f"    precise float alu{i} = asfloat({result});")
+        elif m := match(r"v_cvt_f32_([iu])32_sdwa (v\d+), (sext\([vs]\d+\)|[vs]\d+)( clamp)? dst_sel:DWORD dst_unused:UNUSED_(?:PAD|PRESERVE) src0_sel:(BYTE_[0-3]|WORD_[01]|DWORD)"):

P1 Badge Update the published conversion limits for SDWA support

The new lowering contradicts docs/experiments.md:5762, which still says SDWA variants of these conversions are refused. Contributors consulting the supported-instruction notes are therefore given an incorrect capability boundary. AGENTS.md requires documentation updates for public capability changes; update the conversion notes to describe the DWORD-only destination, supported source selection/sext/clamp, and the existing conversion draw that now exercises these forms.

AGENTS.md reference: AGENTS.md:L192-L193

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4682626797 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1644#discussion_r4682626797). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T15:48:42Z. **Code review location:** `tools/pixel_aot.py`; line 4437 ~~~~diff @@ -4434,6 +4434,22 @@ def sample_coord(reg): result = sdwa_dest(sdwa_source(word, src_sel, bool(sext)), dst_sel, unused, old_value) vector[dst] = f"alu{i}" lines.append(f" precise float alu{i} = asfloat({result});") + elif m := match(r"v_cvt_f32_([iu])32_sdwa (v\d+), (sext\([vs]\d+\)|[vs]\d+)( clamp)? dst_sel:DWORD dst_unused:UNUSED_(?:PAD|PRESERVE) src0_sel:(BYTE_[0-3]|WORD_[01]|DWORD)"): ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Update the published conversion limits for SDWA support** The new lowering contradicts `docs/experiments.md:5762`, which still says SDWA variants of these conversions are refused. Contributors consulting the supported-instruction notes are therefore given an incorrect capability boundary. `AGENTS.md` requires documentation updates for public capability changes; update the conversion notes to describe the DWORD-only destination, supported source selection/`sext`/clamp, and the existing conversion draw that now exercises these forms. AGENTS.md reference: [AGENTS.md:L192-L193](https://github.com/R0Y00/Xbox2Windows/blob/d7b5a5c2a0989ff1b28b56d29180cba4aebb0d7f/AGENTS.md#L192-L193) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-25 13:01:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:44:26Z.


@itzJaack could you rebase this branch onto current main and force-push?

GitHub reports head d7b5a5c2 as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (b1a644ae):

  • tests/pixel_aot_check.py

Commands run locally:

git fetch origin main pull/1644/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1644 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7162789147 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1644#issuecomment-7162789147). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:44:26Z. --- @itzJaack could you rebase this branch onto current `main` and force-push? GitHub reports head `d7b5a5c2` as conflicting with `main`, so it cannot be merged as is. Files that conflict with current `main` (`b1a644ae`): - `tests/pixel_aot_check.py` Commands run locally: ``` git fetch origin main pull/1644/head git merge-tree --write-tree --name-only origin/main FETCH_HEAD gh pr view 1644 --json mergeable # CONFLICTING ``` Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 03:03:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:41:55Z.


Superseded by #2571 (merged): v_cvt_f32_i32_sdwa and v_cvt_f32_u32_sdwa are already lowered on main.

What I checked on current main (4c03e071):

  • tools/pixel_aot.py has SDWA_CVT_INT_TO_F32 (the SDWA int-to-float rule, cvt_f32_i32 and cvt_f32_u32 among 13 forms) and docs/experiments.md already lists both opcodes under "Binary32 conversion ... SDWA forms in pixel_aot".
  • The four-line SDWA program this PR adds (sext() on BYTE_1, clamp with UNUSED_PRESERVE on WORD_1, plain DWORD) translates on main as is. Two of its refusal controls also hold on main (sext(v18 and v256 are refused). The dst_sel:WORD_0 control is the one difference: main accepts a partial destination, so that control would fail.
  • Merging main into this branch conflicts in tests/pixel_aot_check.py. Resolving it would leave a second, narrower rule for the same opcodes next to the one on main, so I did not push to the branch.

Suggestion for @R0Y00 / @itzJaack: close this one as a duplicate. If the readback draw (sdwa_int_to_float, with the 2**32 and 16777220 rounding rows) is wanted, it can go in a small follow-up that extends the existing draw of #2571 and drops the dst_sel:WORD_0 control.

Commands run locally:

git merge origin/main            # conflict in tests/pixel_aot_check.py
rg -n 'SDWA_CVT_INT_TO_F32' tools/pixel_aot.py
python3 -c "import pixel_aot_check as c; c.translate(c.uncompressed_export(SDWA_INT_TO_FLOAT))"   # on origin/main

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181038698 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1644#issuecomment-7181038698). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:41:55Z. --- Superseded by #2571 (merged): `v_cvt_f32_i32_sdwa` and `v_cvt_f32_u32_sdwa` are already lowered on `main`. What I checked on current `main` (`4c03e071`): - `tools/pixel_aot.py` has `SDWA_CVT_INT_TO_F32` (the SDWA int-to-float rule, `cvt_f32_i32` and `cvt_f32_u32` among 13 forms) and `docs/experiments.md` already lists both opcodes under "Binary32 conversion ... SDWA forms in pixel_aot". - The four-line SDWA program this PR adds (`sext()` on `BYTE_1`, `clamp` with `UNUSED_PRESERVE` on `WORD_1`, plain `DWORD`) translates on `main` as is. Two of its refusal controls also hold on `main` (`sext(v18` and `v256` are refused). The `dst_sel:WORD_0` control is the one difference: `main` accepts a partial destination, so that control would fail. - Merging `main` into this branch conflicts in `tests/pixel_aot_check.py`. Resolving it would leave a second, narrower rule for the same opcodes next to the one on `main`, so I did not push to the branch. Suggestion for @R0Y00 / @itzJaack: close this one as a duplicate. If the readback draw (`sdwa_int_to_float`, with the 2**32 and 16777220 rounding rows) is wanted, it can go in a small follow-up that extends the existing draw of #2571 and drops the `dst_sel:WORD_0` control. Commands run locally: ``` git merge origin/main # conflict in tests/pixel_aot_check.py rg -n 'SDWA_CVT_INT_TO_F32' tools/pixel_aot.py python3 -c "import pixel_aot_check as c; c.translate(c.uncompressed_export(SDWA_INT_TO_FLOAT))" # on origin/main ``` AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 05:02:06 +00:00
R0Y00 commented 2026-11-26 05:02:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T04:46:50Z.


The signed and unsigned SDWA integer-to-f32 conversions are on main through #2571. The current conversion controls pass and cover full and partial destinations. Thanks for the independent encodings and rounding cases. The exact high-end rounding rows can supplement the existing fixture by themselves. Closing this implementation as superseded by #2571.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7182895954 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1644#issuecomment-7182895954). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T04:46:50Z. --- The signed and unsigned SDWA integer-to-f32 conversions are on main through #2571. The current conversion controls pass and cover full and partial destinations. Thanks for the independent encodings and rounding cases. The exact high-end rounding rows can supplement the existing fixture by themselves. Closing this implementation as superseded by #2571.

Pull request closed

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!1637
No description provided.