Skip to content

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

Merged
tedin7 merged 2 commits into
R0Y00:mainfrom
triggered02:startup/compute-tg-size
Nov 26, 2026
Merged

tedin7 merged 2 commits into
R0Y00:mainfrom
triggered02:startup/compute-tg-size

Conversation

@triggered02

Copy link
Copy Markdown
Contributor

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

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
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.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

legacy-code-archaeologist added a commit to legacy-code-archaeologist/Xbox2Windows that referenced this pull request Nov 25, 2026
# Conflicts:
#	CMakeLists.txt
#	docs/experiments.md
#	tools/startup/gfx2hlsl.py
legacy-code-archaeologist added a commit to legacy-code-archaeologist/Xbox2Windows that referenced this pull request Nov 25, 2026
)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@triggered02
triggered02 force-pushed the startup/compute-tg-size branch from 1fbdd4f to 8d58e78 Compare November 25, 2026 20:06
legacy-code-archaeologist added a commit to legacy-code-archaeologist/Xbox2Windows that referenced this pull request Nov 25, 2026
Main now carries R0Y00#2459, R0Y00#2461, R0Y00#2466, R0Y00#2483, R0Y00#2428 and others in their final form; the
conflicts take main's versions. Kept from this branch: R0Y00#2460's generalized unjoined(),
R0Y00#2432's scalar(mods), the s_setreg MODE check, the cube image kind, the
v_cvt_f64_f32 inline check. Upstream chose R0Y00#2428 for v_{add,sub,subrev}_co_ci_u32,
so the local co_ci handlers are renamed unbound_* and their two checks unregistered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Leyukaka

Copy link
Copy Markdown
Contributor

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.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Pushed c8348bc: 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.

@tedin7
tedin7 enabled auto-merge (squash) November 26, 2026 02:13
@tedin7
tedin7 merged commit 7fa3866 into R0Y00:main Nov 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants