startup: refuse a VOPC compare into a non-SGPR destination in gfx2hlsl #2302

Merged
denn0x merged 1 commit from upstream-pr/2310 into main 2026-11-25 11:49:34 +00:00
denn0x commented 2026-11-25 11:40:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T11:40:49Z.


What

The e64 (VOP3) form of a VOPC compare names its scalar destination. In tools/startup/gfx2hlsl.py the generic compare path handled exec / exec_lo and vcc / vcc_lo, then took reg_range(dst)[1] for anything else. For vcc_hi, exec_hi or m0, reg_range returns None, so the TypeError ended the whole translation instead of refusing one instruction.

The destination is now checked the same way the class-compare path and the v_add_co_u32 carry-out already check theirs. It is refused as <op> into <dst>. Every accepted form emits the same lines as before.

Test

tests/startup_gfx2hlsl_compare_dst_check.py (new). It is registered in CMake as startup_gfx2hlsl_compare_dst_controls, in the Python CI job and in AGENTS.md.

  • Refusals: v_cmp_lt_u32_e64, v_cmp_eq_i32_e64, v_cmp_gt_f32_e64 and v_cmp_neq_f32_e64 into vcc_hi, exec_hi and m0 must raise gfx2hlsl.Unsupported naming the destination, not another exception.
  • Controls:
    • into s20: lowered, and s20 is marked as a lane mask;
    • into vcc_lo: writes vcc;
    • into exec_lo: writes exec.
python -B tests/startup_gfx2hlsl_compare_dst_check.py
compare destination checks: 0 failed

On main without the change, the 12 refusal cases fail with TypeError: 'NoneType' object is not subscriptable.

  • Translator checks: every tests/startup_gfx2hlsl_*_check.py, tests/startup_image_*_check.py, startup_translator_check.py and startup_flat_param_check.py passes on this branch.
  • Build: all builds (Ninja Release, MSVC Build Tools 18, Windows 11). Device-free, so there were no GPU runs and no capability skips.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6603658993 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2310). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-25T11:40:49Z. --- ## What The e64 (VOP3) form of a VOPC compare names its scalar destination. In `tools/startup/gfx2hlsl.py` the generic compare path handled `exec` / `exec_lo` and `vcc` / `vcc_lo`, then took `reg_range(dst)[1]` for anything else. For `vcc_hi`, `exec_hi` or `m0`, `reg_range` returns `None`, so the `TypeError` ended the whole translation instead of refusing one instruction. The destination is now checked the same way the class-compare path and the `v_add_co_u32` carry-out already check theirs. It is refused as `<op> into <dst>`. Every accepted form emits the same lines as before. ## Test `tests/startup_gfx2hlsl_compare_dst_check.py` (new). It is registered in CMake as `startup_gfx2hlsl_compare_dst_controls`, in the Python CI job and in AGENTS.md. - **Refusals:** `v_cmp_lt_u32_e64`, `v_cmp_eq_i32_e64`, `v_cmp_gt_f32_e64` and `v_cmp_neq_f32_e64` into `vcc_hi`, `exec_hi` and `m0` must raise `gfx2hlsl.Unsupported` naming the destination, not another exception. - **Controls:** - into `s20`: lowered, and `s20` is marked as a lane mask; - into `vcc_lo`: writes `vcc`; - into `exec_lo`: writes `exec`. ``` python -B tests/startup_gfx2hlsl_compare_dst_check.py compare destination checks: 0 failed ``` On `main` without the change, the 12 refusal cases fail with `TypeError: 'NoneType' object is not subscriptable`. - **Translator checks:** every `tests/startup_gfx2hlsl_*_check.py`, `tests/startup_image_*_check.py`, `startup_translator_check.py` and `startup_flat_param_check.py` passes on this branch. - **Build:** `all` builds (Ninja Release, MSVC Build Tools 18, Windows 11). Device-free, so there were no GPU runs and no capability skips.
upstream-sync closed this pull request 2026-11-25 12:01:48 +00:00
tedin7 commented 2026-11-25 12:01:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:45:42Z.

Review: COMMENTED


Review of head f3b4d7e5b1295d9fb7fa9961836474ac84e7b54c (comment only).

Verdict: no P1, no P2. Logic is correct; one test-coverage nit.

Checked:

  • CI: Linux Python checks, Windows build/test and gfx1013 fixtures all pass. /O2 and chart jobs are skipped. Mergeable, title neutral, no clean-room concerns in the diff.
  • tools/startup/gfx2hlsl.py:3365-3372: the new guard (reg = reg_range(dst); if not reg or reg[0] != 's': raise Unsupported(...)) is identical to the class-compare path at :3304-3307. The exec/exec_lo and vcc/vcc_lo branches are untouched, so accepted forms emit the same lines. reg_range returns None for vcc_hi, m0 and ttmp0, so those used to hit TypeError and now refuse.
  • Registration is complete: CMake startup_gfx2hlsl_compare_dst_controls, the Python CI job, and the AGENTS.md list.

Commands run locally in a worktree at this head:

  • python3 -B tests/startup_gfx2hlsl_compare_dst_check.py -> compare destination checks: 0 failed
  • startup_gfx2hlsl_add_sub_co_check.py, cselect_mask_check.py, mask_overwrite_check.py, startup_translator_check.py -> all pass (translator: 0 failed)
  • python3 tests/docs_links_check.py -> Checked 18 Markdown files and 446 links.
  • python3 tests/bidi_controls_check.py -> no bidirectional controls
  • git diff --check origin/main...HEAD -> clean
  • Mutation 1: restored the main version of gfx2hlsl.py -> compare destination checks: 12 failed (the refusal cases are killed, as the PR says).
  • Mutation 2: weakened the guard to if not reg: (drop the reg[0] != 's' kind check) -> test still 0 failed. This mutant survives.

Findings:

  • nit tests/startup_gfx2hlsl_compare_dst_check.py: no case where the destination is a VGPR. reg_range('v3') returns ('v', 3, 3), so only the reg[0] != 's' half of the guard rejects it. Without that half, v_cmp_*_e64 v3, ... would be lowered as an SGPR write to index 3 and marked as a mask. Adding one refusal row (for example v_cmp_lt_u32_e64 v3, ...) would pin it. Not blocking.
  • Windows WARP run not needed: Python-only change in the translator's refusal path, no HLSL emitted for the changed branch, and no math lowering.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6057006933 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2310#pullrequestreview-6057006933). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:45:42Z. **Review:** COMMENTED --- Review of head `f3b4d7e5b1295d9fb7fa9961836474ac84e7b54c` (comment only). **Verdict: no P1, no P2. Logic is correct; one test-coverage nit.** Checked: - CI: Linux Python checks, Windows build/test and gfx1013 fixtures all pass. `/O2` and chart jobs are skipped. Mergeable, title neutral, no clean-room concerns in the diff. - `tools/startup/gfx2hlsl.py:3365-3372`: the new guard (`reg = reg_range(dst); if not reg or reg[0] != 's': raise Unsupported(...)`) is identical to the class-compare path at `:3304-3307`. The `exec`/`exec_lo` and `vcc`/`vcc_lo` branches are untouched, so accepted forms emit the same lines. `reg_range` returns `None` for `vcc_hi`, `m0` and `ttmp0`, so those used to hit `TypeError` and now refuse. - Registration is complete: CMake `startup_gfx2hlsl_compare_dst_controls`, the Python CI job, and the AGENTS.md list. Commands run locally in a worktree at this head: - `python3 -B tests/startup_gfx2hlsl_compare_dst_check.py` -> `compare destination checks: 0 failed` - `startup_gfx2hlsl_add_sub_co_check.py`, `cselect_mask_check.py`, `mask_overwrite_check.py`, `startup_translator_check.py` -> all pass (translator: `0 failed`) - `python3 tests/docs_links_check.py` -> `Checked 18 Markdown files and 446 links.` - `python3 tests/bidi_controls_check.py` -> no bidirectional controls - `git diff --check origin/main...HEAD` -> clean - Mutation 1: restored the `main` version of `gfx2hlsl.py` -> `compare destination checks: 12 failed` (the refusal cases are killed, as the PR says). - Mutation 2: weakened the guard to `if not reg:` (drop the `reg[0] != 's'` kind check) -> test still `0 failed`. This mutant survives. Findings: - **nit** `tests/startup_gfx2hlsl_compare_dst_check.py`: no case where the destination is a VGPR. `reg_range('v3')` returns `('v', 3, 3)`, so only the `reg[0] != 's'` half of the guard rejects it. Without that half, `v_cmp_*_e64 v3, ...` would be lowered as an SGPR write to index 3 and marked as a mask. Adding one refusal row (for example `v_cmp_lt_u32_e64 v3, ...`) would pin it. Not blocking. - Windows WARP run not needed: Python-only change in the translator's refusal path, no HLSL emitted for the changed branch, and no math lowering. AI-assisted; commands listed were executed locally.
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!2302
No description provided.