startup: refuse an op_sel the float lowering does not model #1748

Merged
triggered02 merged 3 commits from upstream-pr/1755 into main 2026-11-24 21:47:26 +00:00
triggered02 commented 2026-11-24 18:09:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T18:09:16Z.


Fixes #1754. Follow-up to the review on the conversion-modifier change (#1705), where tedin7 noted that set_vf() silently ignores op_sel while the documentation claims it is refused.

Change

set_vf() ended its modifier loop with elif m.startswith('op_sel'): pass, so a float operation carrying op_sel emitted exactly the text it would without it:

v_add_f32_e64 v1, v1, v2                 -> v1 = U(F(v1) + F(v2));
v_add_f32_e64 v1, v1, v2 op_sel:[0,0,1]  -> v1 = U(F(v1) + F(v2));            (modifier dropped)
v_mad_f32 v1, v1, v2, v2 op_sel:[0,0,0,1] -> v1 = U(F(v1) * F(v2) + F(v2));   (modifier dropped)

op_sel selects which half of a packed source the operation reads, so dropping it silently changes the operand. The float path now refuses it with the modifier spelling:

v_add_f32_e64 ... op_sel:[0,0,1]  -> REFUSED: modifier op_sel:[0,0,1]
v_mad_f32 ... op_sel:[0,0,0,1]    -> REFUSED: modifier op_sel:[0,0,0,1]

Conversions keep refusing op_sel and a source abs (both were already outside their modifier allow-list).

This is the same principle as the closed off-channel export PR: a form whose desktop behaviour would differ from the console is refused and the missing state recorded, rather than approximated.

Test

startup_gfx2hlsl_opsel builds VOP1/VOP2/VOP3A encodings from the checked-in decoder's layout (VOP3A prefix 0b110101, opcode [25:16], op_sel[3:0] at w0[14:11], abs[2:0] at w0[10:8], sources in w1), decodes them, then translates — no game-derived bytes.

It also pins the exact conversion expressions, which the earlier review's mutation check found unguarded (v_cvt_f32_ubyte1 shift 8, ubyte3 shift 24, masks, float(v1) vs float(int(v1))):

v1 = U(float(v1 & 255));            v1 = U(float((v1 >> 8) & 255));
v1 = U(float((v1 >> 16) & 255));    v1 = U(float(v1 >> 24));
v1 = U(float(v1));                  v1 = U(float(int(v1)));
dev:     16/16 python-level tests pass (all startup_gfx2hlsl*, image controls, startup_translator)
release: startup_gfx2hlsl_opsel Passed 0.14 s

Fail-first: restoring pass in place of the refusal fails the test at an op_sel on a three-source float op is refused.

What this does not establish

  • That op_sel can be lowered correctly — that needs the per-instruction packed-source semantics, and is out of scope here.
  • DXC/D3D12 draw results; the numbers above are the translator tests.
  • Anything about the executable-backed tests: the dev tree here has no built binaries, so only the Python-level ctests were run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588329744 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1755). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T18:09:16Z. --- Fixes #1754. Follow-up to the review on the conversion-modifier change (#1705), where tedin7 noted that `set_vf()` silently ignores `op_sel` while the documentation claims it is refused. ## Change `set_vf()` ended its modifier loop with `elif m.startswith('op_sel'): pass`, so a float operation carrying `op_sel` emitted exactly the text it would without it: ``` v_add_f32_e64 v1, v1, v2 -> v1 = U(F(v1) + F(v2)); v_add_f32_e64 v1, v1, v2 op_sel:[0,0,1] -> v1 = U(F(v1) + F(v2)); (modifier dropped) v_mad_f32 v1, v1, v2, v2 op_sel:[0,0,0,1] -> v1 = U(F(v1) * F(v2) + F(v2)); (modifier dropped) ``` `op_sel` selects which half of a packed source the operation reads, so dropping it silently changes the operand. The float path now refuses it with the modifier spelling: ``` v_add_f32_e64 ... op_sel:[0,0,1] -> REFUSED: modifier op_sel:[0,0,1] v_mad_f32 ... op_sel:[0,0,0,1] -> REFUSED: modifier op_sel:[0,0,0,1] ``` Conversions keep refusing `op_sel` and a source `abs` (both were already outside their modifier allow-list). This is the same principle as the closed `off`-channel export PR: a form whose desktop behaviour would differ from the console is refused and the missing state recorded, rather than approximated. ## Test `startup_gfx2hlsl_opsel` builds VOP1/VOP2/VOP3A encodings from the checked-in decoder's layout (VOP3A prefix `0b110101`, opcode `[25:16]`, `op_sel[3:0]` at `w0[14:11]`, `abs[2:0]` at `w0[10:8]`, sources in `w1`), decodes them, then translates — no game-derived bytes. It also **pins the exact conversion expressions**, which the earlier review's mutation check found unguarded (`v_cvt_f32_ubyte1` shift 8, `ubyte3` shift 24, masks, `float(v1)` vs `float(int(v1))`): ``` v1 = U(float(v1 & 255)); v1 = U(float((v1 >> 8) & 255)); v1 = U(float((v1 >> 16) & 255)); v1 = U(float(v1 >> 24)); v1 = U(float(v1)); v1 = U(float(int(v1))); ``` ``` dev: 16/16 python-level tests pass (all startup_gfx2hlsl*, image controls, startup_translator) release: startup_gfx2hlsl_opsel Passed 0.14 s ``` Fail-first: restoring `pass` in place of the refusal fails the test at `an op_sel on a three-source float op is refused`. ## What this does not establish - That `op_sel` can be lowered correctly — that needs the per-instruction packed-source semantics, and is out of scope here. - DXC/D3D12 draw results; the numbers above are the translator tests. - Anything about the executable-backed tests: the dev tree here has no built binaries, so only the Python-level ctests were run. AI-assisted (Claude Code).
chatgpt-codex-connector[bot commented 2026-11-24 19:01:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T18:14:18Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 748111869a

ℹ️ 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:6044848742 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1755#pullrequestreview-6044848742). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T18:14:18Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `748111869a` <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 19:01:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:46:06Z.

Review: COMMENTED


Reviewed at d1daca3a79bf1c33bb30f97352907e154e64c2fc.

No P1 or P2 defects found in local verification. tools/startup/gfx2hlsl.py now raises Unsupported for op_sel* modifiers in Stage.set_vf() instead of silently dropping them, and Stage.compare() now accepts mods from Stage.one() and refuses any modifier instead of emitting an unselected comparison predicate. CMakeLists.txt adds the startup_gfx2hlsl_opsel CTest entry and tests/startup_gfx2hlsl_opsel_check.py covers op_sel on VOP2/VOP3A/VOP1/VOPC plus exact byte-extraction shift/mask expressions.

Verification executed:

  • git diff --check origin/main...HEAD -> pass
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py -> pass (17 Markdown files, 365 links)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py -> pass (1299 tracked files)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/startup_gfx2hlsl_opsel_check.py -> pass (plus startup_gfx2hlsl_sdwa_check.py, startup_gfx2hlsl_sdwa_cvt_check.py, startup_gfx2hlsl_vcvt_omod_check.py all pass)
  • python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1755 --regex '^startup_gfx2hlsl_(opsel|sdwa|sdwa_cvt|vcvt_omod)$' --py-checks tests/startup_gfx2hlsl_opsel_check.py --wait 600 -> pass on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP): Debug (--preset dev) 4/4 passed (startup_gfx2hlsl_opsel, startup_gfx2hlsl_sdwa, startup_gfx2hlsl_sdwa_cvt, startup_gfx2hlsl_vcvt_omod), Release /O2 (--preset release) 4/4 passed, Windows Python check tests/startup_gfx2hlsl_opsel_check.py ok (0.15s)
  • Local mutation check: reverted elif m.startswith('op_sel'): in tools/startup/gfx2hlsl.py to pass; tests/startup_gfx2hlsl_opsel_check.py failed as expected (an op_sel on the float add is refused: MISMATCH, an op_sel on a three-source float op is refused: MISMATCH), then restored with git checkout -- ..

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045288399 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1755#pullrequestreview-6045288399). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T18:46:06Z. **Review:** COMMENTED --- Reviewed at `d1daca3a79bf1c33bb30f97352907e154e64c2fc`. No P1 or P2 defects found in local verification. `tools/startup/gfx2hlsl.py` now raises `Unsupported` for `op_sel*` modifiers in `Stage.set_vf()` instead of silently dropping them, and `Stage.compare()` now accepts `mods` from `Stage.one()` and refuses any modifier instead of emitting an unselected comparison predicate. `CMakeLists.txt` adds the `startup_gfx2hlsl_opsel` CTest entry and `tests/startup_gfx2hlsl_opsel_check.py` covers `op_sel` on VOP2/VOP3A/VOP1/VOPC plus exact byte-extraction shift/mask expressions. Verification executed: - `git diff --check origin/main...HEAD` -> pass - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py` -> pass (17 Markdown files, 365 links) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py` -> pass (1299 tracked files) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/startup_gfx2hlsl_opsel_check.py` -> pass (plus `startup_gfx2hlsl_sdwa_check.py`, `startup_gfx2hlsl_sdwa_cvt_check.py`, `startup_gfx2hlsl_vcvt_omod_check.py` all pass) - `python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1755 --regex '^startup_gfx2hlsl_(opsel|sdwa|sdwa_cvt|vcvt_omod)$' --py-checks tests/startup_gfx2hlsl_opsel_check.py --wait 600` -> pass on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP): Debug (`--preset dev`) 4/4 passed (`startup_gfx2hlsl_opsel`, `startup_gfx2hlsl_sdwa`, `startup_gfx2hlsl_sdwa_cvt`, `startup_gfx2hlsl_vcvt_omod`), Release `/O2` (`--preset release`) 4/4 passed, Windows Python check `tests/startup_gfx2hlsl_opsel_check.py` ok (`0.15s`) - Local mutation check: reverted `elif m.startswith('op_sel'):` in `tools/startup/gfx2hlsl.py` to `pass`; `tests/startup_gfx2hlsl_opsel_check.py` failed as expected (`an op_sel on the float add is refused: MISMATCH`, `an op_sel on a three-source float op is refused: MISMATCH`), then restored with `git checkout -- .`. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-24 19:01:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T18:09:31Z.


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-24T18:14:20.630406Z 7481118 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:7140241896 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1755#issuecomment-7140241896). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T18:09:31Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"748111869ab8c7c638cc3e7c0e6224f3efcb4cf0","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-24T18:14:20.630406Z">2026-11-24T18:14:20.630406Z</relative-time> | `7481118` | 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>
triggered02 commented 2026-11-24 19:01:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T18:18:37Z.


Fixed in d1daca3a — good catch, and it is the same class as the set_vf case.

Cause: Stage.one() dispatched comparisons with self.compare(base, ops), so the modifiers never reached the path that emits the predicate:

v_cmp_lt_f32_e64 vcc_lo, v1, v2                      -> vcc = ((F(v1) < F(v2)) ? 1u : 0u);
v_cmp_lt_f32_e64 vcc_lo, v1, v2 op_sel:[0,0,1]       -> vcc = ((F(v1) < F(v2)) ? 1u : 0u);   (dropped)
v_cmp_eq_f32_e64 vcc_lo, v1, v2 op_sel:[0,0,0,1]     -> same text                            (dropped)

Fix: the dispatch passes the modifiers, and compare() refuses any that reach it — it reads its two operands directly, so op_sel, clamp and omod are all forms it does not model:

v_cmp_lt_f32_e64 … op_sel:[0,0,1]  -> REFUSED: v_cmp_lt_f32 with ['op_sel:[0,0,1]']
v_cmp_lt_f32_e64 … clamp           -> REFUSED: v_cmp_lt_f32 with ['clamp']

Test: the comparison cases are in startup_gfx2hlsl_opsel_check.py — plain compare still translates, op_sel on either operand position refused, clamp refused. 16 checks pass; startup_gfx2hlsl* + startup_translator green in dev; fail-first dropping the mods argument fails the test at a clamp on a float compare is refused.

Not folded in: a scan of gfx2hlsl.py shows 12 other handlers that take mods and never read them (op_v_mov_b32, the v_interp_* family, op_v_cvt_pkrtz_f16_f32, several SALU ops). Some cannot carry a modifier in their encoding, but the ones that can are the same silent-drop class. That is a mechanical sweep across many dispatch paths, so it belongs in its own change rather than growing this PR — I'll open an issue for it rather than claim they are all safe.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7140461742 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1755#issuecomment-7140461742). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T18:18:37Z. --- Fixed in `d1daca3a` — good catch, and it is the same class as the `set_vf` case. **Cause:** `Stage.one()` dispatched comparisons with `self.compare(base, ops)`, so the modifiers never reached the path that emits the predicate: ``` v_cmp_lt_f32_e64 vcc_lo, v1, v2 -> vcc = ((F(v1) < F(v2)) ? 1u : 0u); v_cmp_lt_f32_e64 vcc_lo, v1, v2 op_sel:[0,0,1] -> vcc = ((F(v1) < F(v2)) ? 1u : 0u); (dropped) v_cmp_eq_f32_e64 vcc_lo, v1, v2 op_sel:[0,0,0,1] -> same text (dropped) ``` **Fix:** the dispatch passes the modifiers, and `compare()` refuses any that reach it — it reads its two operands directly, so `op_sel`, `clamp` and `omod` are all forms it does not model: ``` v_cmp_lt_f32_e64 … op_sel:[0,0,1] -> REFUSED: v_cmp_lt_f32 with ['op_sel:[0,0,1]'] v_cmp_lt_f32_e64 … clamp -> REFUSED: v_cmp_lt_f32 with ['clamp'] ``` **Test:** the comparison cases are in `startup_gfx2hlsl_opsel_check.py` — plain compare still translates, `op_sel` on either operand position refused, `clamp` refused. 16 checks pass; `startup_gfx2hlsl*` + `startup_translator` green in dev; fail-first dropping the `mods` argument fails the test at `a clamp on a float compare is refused`. **Not folded in:** a scan of `gfx2hlsl.py` shows 12 other handlers that take `mods` and never read them (`op_v_mov_b32`, the `v_interp_*` family, `op_v_cvt_pkrtz_f16_f32`, several SALU ops). Some cannot carry a modifier in their encoding, but the ones that can are the same silent-drop class. That is a mechanical sweep across many dispatch paths, so it belongs in its own change rather than growing this PR — I'll open an issue for it rather than claim they are all safe. AI-assisted (Claude Code).
chatgpt-codex-connector[bot commented 2026-11-24 19:01:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T18:14:18Z.

Code review location: tools/startup/gfx2hlsl.py; line 265

@@ -260,7 +260,9 @@ def set_vf(self, n, expr, mods=()):
             elif m == 'div:2':
                 scale *= 0.5
             elif m.startswith('op_sel'):
-                pass
+                # op_sel selects which half of a packed source the operation reads. This path does not
+                # model that, so dropping it would change the operand: refuse instead of ignoring it.
+                raise Unsupported('modifier %s' % m)

P2 Badge Reject op_sel on float comparisons too

When a VOP3 v_cmp_*_f32 carries op_sel, Stage.one() dispatches it to compare(base, ops) without passing mods, so it bypasses this check and emits a comparison using the unselected operands. Such input can produce a different predicate instead of being refused; reject or model modifiers in the comparison path as well.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4684504672 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1755#discussion_r4684504672). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T18:14:18Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 265 ~~~~diff @@ -260,7 +260,9 @@ def set_vf(self, n, expr, mods=()): elif m == 'div:2': scale *= 0.5 elif m.startswith('op_sel'): - pass + # op_sel selects which half of a packed source the operation reads. This path does not + # model that, so dropping it would change the operand: refuse instead of ignoring it. + raise Unsupported('modifier %s' % m) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Reject `op_sel` on float comparisons too** When a VOP3 `v_cmp_*_f32` carries `op_sel`, `Stage.one()` dispatches it to `compare(base, ops)` without passing `mods`, so it bypasses this check and emits a comparison using the unselected operands. Such input can produce a different predicate instead of being refused; reject or model modifiers in the comparison path as well. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
upstream-sync closed this pull request 2026-11-24 22:00:41 +00:00
R0Y00 commented 2026-11-24 22:01:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:38:32Z.


Resolved the current main conflicts while keeping the non-SDWA modifier refusal and the validated SDWA source selectors. On the integrated tree, the op_sel, VOPC SDWA, SDWA conversion, 64-bit shift and scalar m0 fixtures all pass, and the startup translator suite reports zero failures.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7145198682 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1755#issuecomment-7145198682). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T21:38:32Z. --- Resolved the current main conflicts while keeping the non-SDWA modifier refusal and the validated SDWA source selectors. On the integrated tree, the op_sel, VOPC SDWA, SDWA conversion, 64-bit shift and scalar m0 fixtures all pass, and the startup translator suite reports zero failures.
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!1748
No description provided.