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

Manually merged
github merged 1 commit from gh-pr/2310/head into gh-pr/2310/base 2026-11-27 00:14:40 +00:00
Owner

@⁠denn0x on GitHub · 2026-11-25 11:40 UTC · original
denn0x:startup/compare-dst-refusal → main · +90 −1 · 5 files · 1 commits · merged 2026-11-25 11:49 UTC

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.
**@⁠denn0x** on GitHub · 2026-11-25 11:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2310) `denn0x:startup/compare-dst-refusal` → `main` · +90 −1 · 5 files · 1 commits · merged 2026-11-25 11:49 UTC ## 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.
The e64 form of a VOPC compare names its scalar destination. The generic compare path handled exec
and vcc and took reg_range(dst)[1] for everything else, so a compare into vcc_hi, exec_hi or m0
raised TypeError and ended the whole translation. The destination is now checked as the class-compare
path and the v_add_co_u32 carry-out already do, and refused as "<op> into <dst>".

Test: tests/startup_gfx2hlsl_compare_dst_check.py checks integer and float compares into vcc_hi,
exec_hi and m0 for a named refusal. Controls: compares into s20 are lowered and leave s20 a lane mask,
compares into vcc_lo write vcc and compares into exec_lo write exec. On main the 12 refusal cases
raise TypeError.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:14:39 +00:00
github manually merged commit f3b4d7e5b1 into gh-pr/2310/base 2026-11-27 00:14:40 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 11:45 UTC · original · reviewed

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.

**@⁠tedin7** on GitHub · 2026-11-25 11:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2310#pullrequestreview-6057006933) · **reviewed** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.