shader: allow s_load into high SGPRs s[104:107] in gfx2hlsl (Part of #1723) #2057

Manually merged
github merged 8 commits from gh-pr/2057/head into gh-pr/2057/base 2026-11-26 23:52:57 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-24 23:44 UTC · original
tedin7:x2w-r22-sload-s104 → main · +261 −1 · 3 files · 8 commits · merged 2026-11-25 22:55 UTC

Part of #1723

What this unblocks: 224 draw refusals (s_load into s[104:107]).

The translator refused any s_load whose destination ended above s105. s106/s107 are vcc, so s_load_dwordx4 s[104:107], <table ptr>, imm was refused even though a descriptor load emits no code: it only records which table bytes the registers name. Now a descriptor load may end in s[104:107]. A root constant-buffer load (which must write the registers), a load starting above s105, and a destination past s107 are still refused.

Note: later code must not read vcc before redefining it. Compilers do not do this after a descriptor load.

Verification: (run locally in the worktree on Linux; the Win2025 run is not done)

  • python3 -B tests/startup_gfx2hlsl_sload_s104_check.py -> ok (fails on main with s_load destination s[104:107] for 4 dwords)
  • python3 -B tests/startup_gfx2hlsl_{smem_offset,op_refusals,readfirstlane_uniform,operand_count,capture}_check.py -> all exit 0
  • Test registered in CMakeLists.txt as startup_gfx2hlsl_sload_s104.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 23:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2057) `tedin7:x2w-r22-sload-s104` → `main` · +261 −1 · 3 files · 8 commits · merged 2026-11-25 22:55 UTC Part of #1723 What this unblocks: 224 draw refusals (s_load into s[104:107]). The translator refused any `s_load` whose destination ended above s105. s106/s107 are vcc, so `s_load_dwordx4 s[104:107], <table ptr>, imm` was refused even though a descriptor load emits no code: it only records which table bytes the registers name. Now a descriptor load may end in s[104:107]. A root constant-buffer load (which must write the registers), a load starting above s105, and a destination past s107 are still refused. Note: later code must not read vcc before redefining it. Compilers do not do this after a descriptor load. Verification: (run locally in the worktree on Linux; the Win2025 run is not done) - `python3 -B tests/startup_gfx2hlsl_sload_s104_check.py` -> ok (fails on main with `s_load destination s[104:107] for 4 dwords`) - `python3 -B tests/startup_gfx2hlsl_{smem_offset,op_refusals,readfirstlane_uniform,operand_count,capture}_check.py` -> all exit 0 - Test registered in CMakeLists.txt as `startup_gfx2hlsl_sload_s104`. AI-assisted; commands listed were executed locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:52:56 +00:00
github manually merged commit a4d458099b into gh-pr/2057/base 2026-11-26 23:52:57 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:45 UTC · original · edited 2026-11-24 23:52 UTC

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-24T23:52:14.739675Z de88ff3 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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2057#issuecomment-7147754960) · edited 2026-11-24 23:52 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"de88ff3a01f1418ad7e488d6b930e2854c009212","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-24T23:52:14.739675Z">2026-11-24T23:52:14.739675Z</relative-time> | `de88ff3` | 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>
@ -3622,0 +3695,4 @@
if not dst or dst[0] != 's' or dst[2] - dst[1] + 1 != count or dst[1] > 105 or dst[2] > 107:
raise Unsupported('s_load destination %s for %d dwords' % (ops[0], count))
# s106/s107 are vcc: only a descriptor load, which emits no code, may end there (s[104:107]).
into_vcc = dst[2] > 105
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:52 UTC · original

P2 Badge Guard VCC reads after symbolic loads into s106/s107

When a newly accepted high-SGPR load is followed by a VCC read before redefinition, the read still uses the old runtime mask. For example, s_load_dwordx4 s[104:107], s[8:9], 0, followed by s_waitcnt lgkmcnt(0) and v_cndmask_b32_e32 v0, 0, 1, now translates successfully to a select against the unchanged vcc. Recording descriptor symbols in sym[106] and sym[107] does not protect these reads: u('vcc_lo'), implicit cndmask operands, and VCC branches bypass S()'s numeric-descriptor refusal. Mark VCC unavailable after an overlapping symbolic load and reject reads until it is redefined, rather than silently translating an unmodelled value.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2057#discussion_r4688212708) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Guard VCC reads after symbolic loads into s106/s107** When a newly accepted high-SGPR load is followed by a VCC read before redefinition, the read still uses the old runtime mask. For example, `s_load_dwordx4 s[104:107], s[8:9], 0`, followed by `s_waitcnt lgkmcnt(0)` and `v_cndmask_b32_e32 v0, 0, 1`, now translates successfully to a select against the unchanged `vcc`. Recording descriptor symbols in `sym[106]` and `sym[107]` does not protect these reads: `u('vcc_lo')`, implicit cndmask operands, and VCC branches bypass `S()`'s numeric-descriptor refusal. Mark VCC unavailable after an overlapping symbolic load and reject reads until it is redefined, rather than silently translating an unmodelled value. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:13 UTC · original

Fixed and pushed in e0e712d5 (VCC guard added, tests pass).

**@⁠tedin7** on GitHub · 2026-11-25 01:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2057#issuecomment-7149335895) Fixed and pushed in e0e712d5 (VCC guard added, tests pass).
@ -3622,0 +3695,4 @@
if not dst or dst[0] != 's' or dst[2] - dst[1] + 1 != count or dst[1] > 105 or dst[2] > 107:
raise Unsupported('s_load destination %s for %d dwords' % (ops[0], count))
# s106/s107 are vcc: only a descriptor load, which emits no code, may end there (s[104:107]).
into_vcc = dst[2] > 105
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:28 UTC · original

Fixed in e0e712d5. After a descriptor load into s106/s107, vcc is marked unavailable. Any read (vcc/vcc_lo operands, implicit cndmask mask, s_cbranch_vcc*) is refused until vcc is written again. Covered in tests/startup_gfx2hlsl_sload_s104_check.py. Verification (Linux): python3 tests/startup_gfx2hlsl_sload_s104_check.py -> ok. Windows/WARP not run for this change.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 01:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2057#discussion_r4688947404) Fixed in e0e712d5. After a descriptor load into s106/s107, vcc is marked unavailable. Any read (vcc/vcc_lo operands, implicit cndmask mask, s_cbranch_vcc*) is refused until vcc is written again. Covered in tests/startup_gfx2hlsl_sload_s104_check.py. Verification (Linux): `python3 tests/startup_gfx2hlsl_sload_s104_check.py` -> ok. Windows/WARP not run for this change. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-25 06:55 UTC · original

I fast-forwarded the original branch to 0d2e34f8, preserving your commits. The added control-flow check rejects a VCC read when an incoming path skipped the redefinition, and rejects a descriptor use when the matching symbolic load did not reach it. The focused high-SGPR, SMEM-offset, refusal, readfirstlane and scalar-arity controls passed on the updated head. The PR can now run its usual checks.

**@⁠R0Y00** on GitHub · 2026-11-25 06:55 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2057#issuecomment-7155302977) I fast-forwarded the original branch to `0d2e34f8`, preserving your commits. The added control-flow check rejects a VCC read when an incoming path skipped the redefinition, and rejects a descriptor use when the matching symbolic load did not reach it. The focused high-SGPR, SMEM-offset, refusal, readfirstlane and scalar-arity controls passed on the updated head. The PR can now run its usual checks.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 12:05 UTC · original

Thanks for the fast-forward to 0d2e34f8. I checked the current head 76d0f6c1, which contains it plus a merge of main.

The branch cases from your review are covered on this head, so I made no code change:

  • A VCC read after a branch that skips the only redefinition is refused.
  • A descriptor use after a branch that skips the s_load is refused.
  • A VCC write between the load and the descriptor use is refused.
  • The dominated reads are still accepted.

These are in tests/startup_gfx2hlsl_sload_s104_check.py, and the gfx1013 fixtures, Linux Python checks and Windows build and test jobs all pass on this head.

Commands run locally on 76d0f6c1:

  • python3 tests/startup_gfx2hlsl_sload_s104_check.py → ok
  • every tests/startup_gfx2hlsl_*_check.py (52 scripts) → all passed

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 12:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2057#issuecomment-7161910788) Thanks for the fast-forward to `0d2e34f8`. I checked the current head `76d0f6c1`, which contains it plus a merge of main. The branch cases from your review are covered on this head, so I made no code change: - A VCC read after a branch that skips the only redefinition is refused. - A descriptor use after a branch that skips the `s_load` is refused. - A VCC write between the load and the descriptor use is refused. - The dominated reads are still accepted. These are in `tests/startup_gfx2hlsl_sload_s104_check.py`, and the gfx1013 fixtures, Linux Python checks and Windows build and test jobs all pass on this head. Commands run locally on `76d0f6c1`: - `python3 tests/startup_gfx2hlsl_sload_s104_check.py` → ok - every `tests/startup_gfx2hlsl_*_check.py` (52 scripts) → all passed AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 13:50 UTC · original

Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.

We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 13:50 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2057#issuecomment-7164376602) Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is. We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠ChazY11 on GitHub · 2026-11-25 22:56 UTC · original

Post-merge audit of e0da6b39: five mutations of the VCC/descriptor path walk, three caught — and the biggest survivor is caused by an or in the fixture's own assertion

python -B tests/startup_gfx2hlsl_sload_s104_check.py
    ok

The change lets s_load write s[104:107], which overlaps VCC, so translation now has to prove two things along every path
(check_vcc_paths, gfx2hlsl.py:1885): a descriptor load reaches its use on all paths, and VCC is numeric at a mask
read. The walk is a small worklist over blocks with a state taken from the last load_descriptor and cleared by
write_vcc.

mutation caught
the VCC read refusal removed (read_vcc while a descriptor is live) caught
write_vcc stops clearing the state caught
jump edges no longer followed caught
the multi-path descriptor check forced true (if state is None or any(…) → if False) survived
sequential fallthrough edges no longer added survived

Survivor 1, and why it is the fixture's fault rather than the code's

The fixture does build the "load bypassed on one path" case:

try:
    translate('s_cbranch_scc0 label_000C', load, 's_nop 0', fetch, 's_endpgm')
except G.Unsupported as error:
    assert ('without a matching load on every path' in str(error)
            or 'joined at a branch target' in str(error)), error

That or is the problem. With the multi-path check disabled, a different guard (joined at a branch target) still
raises, the assertion still passes, and the case cannot tell the two apart. The regression I injected — "a descriptor read
on a path that never loaded it is accepted" — is exactly the bug this PR exists to prevent, and the assertion would stay
green.

Splitting it into two cases would close it: one whose CFG has no join (so only check_vcc_paths can refuse), and one that
genuinely joins (so the join guard is the one under test). Asserting the message exactly rather than with or is the
cheap version.

Survivor 2: every branch in the fixture has both edges leading somewhere that already decides

s_cbranch_scc0 produces a taken edge and a fallthrough edge. In the fixture's cases the taken edge reaches a state that
resolves the question, so removing the fallthrough edge changes no verdict. That means the (not term or term[0] == 'branch') conjunct — the one that makes straight-line code work at all — has no case where it is the deciding edge.

A load in one block with the reader reachable only by falling into the next block would pin it, and that is the most
common real shape: a straight-line prologue that loads, followed by the code that uses the word, with no branch at all.

What the three catches do cover

The VCC side is well covered: a mask read after a descriptor load is refused, a write_vcc re-enables the read, and
jump edges are followed. Those three are the semantics a title would hit, and each has a case that fails when broken.

AI-assisted; pure Python, Windows 11 build 26300, no DXC or GPU for the rows above.

**@⁠ChazY11** on GitHub · 2026-11-25 22:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2057#issuecomment-7176961448) ## Post-merge audit of `e0da6b39`: five mutations of the VCC/descriptor path walk, three caught — and the biggest survivor is caused by an `or` in the fixture's own assertion ```text python -B tests/startup_gfx2hlsl_sload_s104_check.py ok ``` The change lets `s_load` write `s[104:107]`, which overlaps VCC, so translation now has to prove two things along every path (`check_vcc_paths`, `gfx2hlsl.py:1885`): a descriptor load reaches its use on **all** paths, and VCC is numeric at a mask read. The walk is a small worklist over blocks with a `state` taken from the last `load_descriptor` and cleared by `write_vcc`. | mutation | caught | |---|---| | the VCC read refusal removed (`read_vcc` while a descriptor is live) | **caught** | | `write_vcc` stops clearing the state | **caught** | | jump edges no longer followed | **caught** | | the multi-path descriptor check forced true (`if state is None or any(…)` → `if False`) | survived | | sequential fallthrough edges no longer added | survived | ### Survivor 1, and why it is the fixture's fault rather than the code's The fixture *does* build the "load bypassed on one path" case: ```python try: translate('s_cbranch_scc0 label_000C', load, 's_nop 0', fetch, 's_endpgm') except G.Unsupported as error: assert ('without a matching load on every path' in str(error) or 'joined at a branch target' in str(error)), error ``` That `or` is the problem. With the multi-path check disabled, a **different** guard (`joined at a branch target`) still raises, the assertion still passes, and the case cannot tell the two apart. The regression I injected — "a descriptor read on a path that never loaded it is accepted" — is exactly the bug this PR exists to prevent, and the assertion would stay green. Splitting it into two cases would close it: one whose CFG has no join (so only `check_vcc_paths` can refuse), and one that genuinely joins (so the join guard is the one under test). Asserting the message **exactly** rather than with `or` is the cheap version. ### Survivor 2: every branch in the fixture has both edges leading somewhere that already decides `s_cbranch_scc0` produces a taken edge and a fallthrough edge. In the fixture's cases the taken edge reaches a state that resolves the question, so removing the fallthrough edge changes no verdict. That means the `(not term or term[0] == 'branch')` conjunct — the one that makes straight-line code work at all — has no case where it is the deciding edge. A load in one block with the reader reachable **only** by falling into the next block would pin it, and that is the most common real shape: a straight-line prologue that loads, followed by the code that uses the word, with no branch at all. ### What the three catches do cover The VCC side is well covered: a mask read after a descriptor load is refused, a `write_vcc` re-enables the read, and jump edges are followed. Those three are the semantics a title would hit, and each has a case that fails when broken. AI-assisted; pure Python, Windows 11 build 26300, no DXC or GPU for the rows above.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:52 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de88ff3a01

ℹ️ 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".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2057#pullrequestreview-6049332786) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `de88ff3a01` <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>
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-25 06:13 UTC · original · reviewed

I verified the straight-line VCC guard and reproduced two branch cases that still need checks on this head. s_load_dwordx4 s[104:107], s[4:5], 0x20; s_cbranch_scc0 can skip the only VCC redefinition and reach an implicit v_cndmask_b32 read. Also, a branch can skip the descriptor load itself, while a later buffer load still uses the descriptor recorded in translation order. A VCC redefinition before a high-SGPR descriptor use can likewise clobber the recorded descriptor.

I prepared a local candidate against 8150d800 that checks these reads along the stage’s branch edges and preserves a matching descriptor on every path. The focused check passes the branch-bypass refusals, accepts the dominated reads, and refuses reuse after a VCC write. All 46 local startup_gfx2hlsl_*_check.py scripts passed. A separate replay on the local diagnostic translator with Windows SDK 10.0.26100.0 FXC newly produced a manifest and both shader binaries for one captured request; four others advanced to a separate unsupported instruction. This verifies translation only.

**@⁠R0Y00** on GitHub · 2026-11-25 06:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2057#pullrequestreview-6052698252) · **reviewed** I verified the straight-line VCC guard and reproduced two branch cases that still need checks on this head. `s_load_dwordx4 s[104:107], s[4:5], 0x20; s_cbranch_scc0` can skip the only VCC redefinition and reach an implicit `v_cndmask_b32` read. Also, a branch can skip the descriptor load itself, while a later buffer load still uses the descriptor recorded in translation order. A VCC redefinition before a high-SGPR descriptor use can likewise clobber the recorded descriptor. I prepared a local candidate against `8150d800` that checks these reads along the stage’s branch edges and preserves a matching descriptor on every path. The focused check passes the branch-bypass refusals, accepts the dominated reads, and refuses reuse after a VCC write. All 46 local `startup_gfx2hlsl_*_check.py` scripts passed. A separate replay on the local diagnostic translator with Windows SDK `10.0.26100.0` FXC newly produced a manifest and both shader binaries for one captured request; four others advanced to a separate unsupported instruction. This verifies translation only.
This discussion has been locked. Commenting is limited to contributors.
No description provided.