startup: accept single-wave TG_SIZE_EN wave-ID masking in compute #2424

Merged
triggered02 merged 2 commits from upstream-pr/2432 into main 2026-11-26 02:15:28 +00:00
triggered02 commented 2026-11-25 16:35:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-25T16:35:16Z.


Implements the unclaimed TG_SIZE_EN item from #2274 Part A in tools/startup/gfx2hlsl.py.

What changed

  • tools/startup/gfx2hlsl.py:
    • ComputePipeline.__init__ accepts COMPUTE_PGM_RSRC2.TG_SIZE_EN (bit 10) when x * y * z <= 32 (one wave per workgroup), decoding the base registers via entry_registers(rsrc2 & ~(1 << 10)) and placing tg_size_sgpr = user + len(groups). Groups > 32 threads with TG_SIZE_EN remain refused.
    • Stage.setup_compute_entry tags self.sym[tg_size_sgpr] = ('tg_size',).
    • Stage.scalar accepts only unmodified s_and_b32 R, TG, 0xfc0 (either operand order, R a plain SGPR <= 105, including R == TG), emitting R = 0u; scc = false; and tracking R as ('const', 0) so v_mbcnt_lo_u32_b32 accepts R as a known zero base.
    • Stage.S and Stage.scalar refuse every other read of an untouched ('tg_size',) register by name (other masks, moves, arithmetic, vector instructions, or direct v_mbcnt_lo); overwriting TG restores ordinary scalar behavior. tools/compute_store_aot.py continues to refuse TG_SIZE_EN.
  • tests/startup_compute_tg_size_check.py, CMakeLists.txt, docs/experiments.md, and tests/startup_gfx2hlsl_compute_check.py (updated the TG_SIZE_EN refusal fixture group size from (1, 1, 1) to (8, 4, 2)).

Measured checks (1fbdd4fd on origin/main b442b57f)

  • tests/startup_compute_tg_size_check.py (pure Python): PASS (SGPR placement, s_and_b32 0xfc0, v_mbcnt_lo base, >32-thread & disallowed-read refusals, overwrite recovery, execz / join behavior).
  • tests/startup_compute_tg_size_check.py dispatch <dxc> <offscreen_check> warp (Microsoft Basic Render Driver 1414:008c, 10.0.26100.9818, DXC cs_6_0): PASS (two 4x2x2 groups, 320 words compared, 0 mismatches).
  • tests/startup_compute_tg_size_check.py control {dropped-base,swapped-mask} <dxc> <offscreen_check> warp: PASS (dropped-base rejected at word 5, swapped-mask rejected at word 8).
  • 74 pure-Python checks (startup_gfx2hlsl_*, startup_compute_*, compute_entry_layout_check.py, startup_translator_check.py, docs_links_check.py, bidi_controls_check.py): 74 passed, 0 failed (2 CLI-binary compute checks skipped standalone).
  • 4 fail-first mutations on tools/startup/gfx2hlsl.py (offsetting tg_size_sgpr, dropping <= 32 check, accepting 0x3f, dropping Stage.S refusal): all 4 caught (exit 1).

Not established

  • Physical GPU hardware dispatch was not run here (WARP only).

Refs #2274. AI-assisted (Gemini).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6609048353 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2432). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-25T16:35:16Z. --- Implements the unclaimed `TG_SIZE_EN` item from #2274 Part A in `tools/startup/gfx2hlsl.py`. ### What changed - **`tools/startup/gfx2hlsl.py`**: - `ComputePipeline.__init__` accepts `COMPUTE_PGM_RSRC2.TG_SIZE_EN` (bit 10) when `x * y * z <= 32` (one wave per workgroup), decoding the base registers via `entry_registers(rsrc2 & ~(1 << 10))` and placing `tg_size_sgpr = user + len(groups)`. Groups `> 32` threads with `TG_SIZE_EN` remain refused. - `Stage.setup_compute_entry` tags `self.sym[tg_size_sgpr] = ('tg_size',)`. - `Stage.scalar` accepts only unmodified `s_and_b32 R, TG, 0xfc0` (either operand order, `R` a plain SGPR `<= 105`, including `R == TG`), emitting `R = 0u; scc = false;` and tracking `R` as `('const', 0)` so `v_mbcnt_lo_u32_b32` accepts `R` as a known zero base. - `Stage.S` and `Stage.scalar` refuse every other read of an untouched `('tg_size',)` register by name (other masks, moves, arithmetic, vector instructions, or direct `v_mbcnt_lo`); overwriting `TG` restores ordinary scalar behavior. `tools/compute_store_aot.py` continues to refuse `TG_SIZE_EN`. - **`tests/startup_compute_tg_size_check.py`**, **`CMakeLists.txt`**, **`docs/experiments.md`**, and **`tests/startup_gfx2hlsl_compute_check.py`** (updated the `TG_SIZE_EN` refusal fixture group size from `(1, 1, 1)` to `(8, 4, 2)`). ### Measured checks (`1fbdd4fd` on `origin/main` `b442b57f`) - `tests/startup_compute_tg_size_check.py` (pure Python): PASS (SGPR placement, `s_and_b32 0xfc0`, `v_mbcnt_lo` base, `>32`-thread & disallowed-read refusals, overwrite recovery, `execz` / join behavior). - `tests/startup_compute_tg_size_check.py dispatch <dxc> <offscreen_check> warp` (Microsoft Basic Render Driver `1414:008c`, `10.0.26100.9818`, DXC `cs_6_0`): PASS (two `4x2x2` groups, `320` words compared, `0` mismatches). - `tests/startup_compute_tg_size_check.py control {dropped-base,swapped-mask} <dxc> <offscreen_check> warp`: PASS (`dropped-base` rejected at word 5, `swapped-mask` rejected at word 8). - 74 pure-Python checks (`startup_gfx2hlsl_*`, `startup_compute_*`, `compute_entry_layout_check.py`, `startup_translator_check.py`, `docs_links_check.py`, `bidi_controls_check.py`): 74 passed, 0 failed (2 CLI-binary compute checks skipped standalone). - 4 fail-first mutations on `tools/startup/gfx2hlsl.py` (offsetting `tg_size_sgpr`, dropping `<= 32` check, accepting `0x3f`, dropping `Stage.S` refusal): all 4 caught (exit 1). ### Not established - Physical GPU `hardware` dispatch was not run here (WARP only). Refs #2274. AI-assisted (Gemini).
chatgpt-codex-connector[bot commented 2026-11-25 17:01:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T16:35: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-25T16:39:21.334327Z 1fbdd4f 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:7168224849 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2432#issuecomment-7168224849). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T16:35:31Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"1fbdd4fdf25989371a66d560c024fdce22b09f7f","has_any_findings":false,"has_unresolved_findings":false,"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-25T16:39:21.334327Z">2026-11-25T16:39:21.334327Z</relative-time> | `1fbdd4f` | 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>
tedin7 commented 2026-11-25 19:03:42 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 1fbdd4fd (comment only, no merge action).

What I checked

  • Diff read against origin/main: gfx2hlsl.py entry placement of TG_SIZE (user + len(groups)), the <= 32 threads guard, the narrow s_and_b32 R, TG, 0xfc0 fold, and the refusal of every other read of an untouched TG register. Logic is sound and additive.
  • The test file covers placement, both operand orders, R == TG, overwrite recovery, the > 32 refusal and a WARP dispatch with CPU reference. The two control cases (dropped-base, swapped-mask) are wired into CTest for warp and hardware. The sibling refusal fixture in startup_gfx2hlsl_compute_check.py was updated correctly.
  • No other open or merged PR covers TG_SIZE_EN (searched PRs: #1608, #2182 and #2223 are the compute base only).
  • The author's WARP results in the PR body are stated for head 1fbdd4fd, the same SHA I reviewed. I did not run Windows tests myself. Hardware dispatch was not run by the author either, as they say.
  • The branch is 23 commits behind main. I did not update it, so the author's results stay valid for this SHA.

Commands run locally (Linux)

  • python3 -B tests/startup_compute_tg_size_check.py: pass
  • python3 -B tests/startup_gfx2hlsl_compute_check.py: pass
  • python3 tests/docs_links_check.py: pass
  • python3 tests/bidi_controls_check.py: pass
  • git diff --check origin/main...HEAD: clean
  • Mutation 1: tg_size_sgpr offset by +1. The test fails (exit 1).
  • Mutation 2: mask 0xfc0 changed to 0x3f. The test fails (exit 1).
  • Both mutations reverted.

No blocking findings.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6062827019 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2432#pullrequestreview-6062827019). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T18:23:46Z. **Review:** COMMENTED --- Review of head `1fbdd4fd` (comment only, no merge action). **What I checked** - Diff read against origin/main: `gfx2hlsl.py` entry placement of TG_SIZE (`user + len(groups)`), the `<= 32` threads guard, the narrow `s_and_b32 R, TG, 0xfc0` fold, and the refusal of every other read of an untouched TG register. Logic is sound and additive. - The test file covers placement, both operand orders, `R == TG`, overwrite recovery, the `> 32` refusal and a WARP dispatch with CPU reference. The two control cases (`dropped-base`, `swapped-mask`) are wired into CTest for warp and hardware. The sibling refusal fixture in `startup_gfx2hlsl_compute_check.py` was updated correctly. - No other open or merged PR covers TG_SIZE_EN (searched PRs: #1608, #2182 and #2223 are the compute base only). - The author's WARP results in the PR body are stated for head `1fbdd4fd`, the same SHA I reviewed. I did not run Windows tests myself. Hardware dispatch was not run by the author either, as they say. - The branch is 23 commits behind main. I did not update it, so the author's results stay valid for this SHA. **Commands run locally (Linux)** - `python3 -B tests/startup_compute_tg_size_check.py`: pass - `python3 -B tests/startup_gfx2hlsl_compute_check.py`: pass - `python3 tests/docs_links_check.py`: pass - `python3 tests/bidi_controls_check.py`: pass - `git diff --check origin/main...HEAD`: clean - Mutation 1: `tg_size_sgpr` offset by +1. The test fails (exit 1). - Mutation 2: mask `0xfc0` changed to `0x3f`. The test fails (exit 1). - Both mutations reverted. No blocking findings. AI-assisted; commands listed were executed locally.
Leyukaka commented 2026-11-26 00:01:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-25T23:08:43Z.


Review of head 8d58e787, by reading the diff against main (not run).

s_cselect_b64 reaches the TG_SIZE SGPR without the new guard. With 7 user SGPRs and no TGIDs enabled, TG_SIZE is s7:

s_mov_b32 s6, 0
s_cselect_b64 s[20:21], s[6:7], s[6:7]   ; either SCC value selects the pair
v_mov_b32 v3, s21                        ; guest: the packed TG_SIZE word

scalar_select (main fc97ade, gfx2hlsl.py:3551-3576) reads only the low registers of a 64-bit pair and emits s21 = 0u, so S(7) is never called and the guard this PR puts in S() and scalar() does not see the read. The translation leaves v3 at 0. The mechanism is older than this PR (a TGID in the high half is dropped the same way on main), but TG_SIZE becomes reachable here only with this change. The test docstring says every other read of the untouched TG_SIZE SGPR is refused; a refusal control with this sequence would hold the PR to that.

A smaller fix than changing scalar_select: refuse a 64-bit s_cselect whose source pair includes the TG_SIZE SGPR.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7177197607 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2432#issuecomment-7177197607). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-25T23:08:43Z. --- Review of head `8d58e787`, by reading the diff against main (not run). `s_cselect_b64` reaches the TG_SIZE SGPR without the new guard. With 7 user SGPRs and no TGIDs enabled, TG_SIZE is `s7`: ``` s_mov_b32 s6, 0 s_cselect_b64 s[20:21], s[6:7], s[6:7] ; either SCC value selects the pair v_mov_b32 v3, s21 ; guest: the packed TG_SIZE word ``` `scalar_select` (main `fc97ade`, `gfx2hlsl.py:3551-3576`) reads only the low registers of a 64-bit pair and emits `s21 = 0u`, so `S(7)` is never called and the guard this PR puts in `S()` and `scalar()` does not see the read. The translation leaves `v3` at 0. The mechanism is older than this PR (a TGID in the high half is dropped the same way on main), but TG_SIZE becomes reachable here only with this change. The test docstring says every other read of the untouched TG_SIZE SGPR is refused; a refusal control with this sequence would hold the PR to that. A smaller fix than changing `scalar_select`: refuse a 64-bit `s_cselect` whose source pair includes the TG_SIZE SGPR. AI-assisted.
upstream-sync closed this pull request 2026-11-26 03:02:54 +00:00
tedin7 commented 2026-11-26 03:03:21 +00:00 (Migrated from github.com)

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


Pushed c8348bc08: a merge of main into this branch (no force, no rebase) so the PR is mergeable again. No code changes from me.

Two conflicts, both kept on both sides:

  • tools/startup/gfx2hlsl.py: this branch's scalar(base, ops, mods) call, followed by main's new s_addc_u32 block.
  • CMakeLists.txt: the startup_compute_tg_size_* tests and main's startup_compute_lds_b128_* tests, each with its own controls.

Commands executed locally:

  • python3 -I tests/startup_compute_tg_size_check.py, tests/startup_gfx2hlsl_compute_check.py, tests/startup_gfx2hlsl_shift64_check.py: pass
  • python3 x2w_pipe.py win2025 2432 --patch <merge diff> --regex 'startup_compute_tg_size|startup_compute_lds_b128' (default slots): 22/22 passed on WARP and hardware, including the dropped-base and swapped-mask controls

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7180579846 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2432#issuecomment-7180579846). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:13:11Z. --- Pushed c8348bc08: a merge of main into this branch (no force, no rebase) so the PR is mergeable again. No code changes from me. Two conflicts, both kept on both sides: - `tools/startup/gfx2hlsl.py`: this branch's `scalar(base, ops, mods)` call, followed by main's new `s_addc_u32` block. - `CMakeLists.txt`: the `startup_compute_tg_size_*` tests and main's `startup_compute_lds_b128_*` tests, each with its own controls. Commands executed locally: - `python3 -I tests/startup_compute_tg_size_check.py`, `tests/startup_gfx2hlsl_compute_check.py`, `tests/startup_gfx2hlsl_shift64_check.py`: pass - `python3 x2w_pipe.py win2025 2432 --patch <merge diff> --regex 'startup_compute_tg_size|startup_compute_lds_b128'` (default slots): 22/22 passed on WARP and hardware, including the dropped-base and swapped-mask controls 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!2424
No description provided.