shader: support s_load with register offset through resource heap in gfx2hlsl (Part of #1723) #2066

Closed
github-bot wants to merge 2 commits from gh-pr/2066/head into gh-pr/2066/base
Owner

@⁠tedin7 on GitHub · 2026-11-24 23:57 UTC · original
tedin7:x2w-r23-bindless-sload → main · +101 −0 · 4 files · 2 commits · closed without merging

Part of #1723

What this unblocks: s_load from the resource heap (and any descriptor table) now works when the byte offset sits in a register that an earlier move filled with a known constant, so those descriptor loads stop being refused as "register offset" (first slice of the bindless refusals).

Change:

  • tools/startup/gfx2hlsl.py: s_load* reads an offset register with a known constant value as that literal byte offset, plus any offset: modifier. Unknown registers, m0 and the sampler heap keep their old handling.
  • New test tests/startup_gfx2hlsl_sload_const_offset_check.py, registered in CMakeLists.txt as startup_gfx2hlsl_sload_const_offset.

Not in this slice: offsets that are truly run-time values (a heap table indexed in the shader). The manifest still refuses a resheap resource.

Verification:

  • python3 -B tests/startup_gfx2hlsl_sload_const_offset_check.py: 0 failed (same file against the old translator: 3 failed).
  • python3 -B tests/startup_gfx2hlsl_smem_offset_check.py: 0 failed.
  • python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py: 0 failed.
  • python3 -B tests/startup_translator_check.py: 0 failed.
  • Ran on the Linux worker, not on Win2025: no Windows-only code is touched.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 23:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066) `tedin7:x2w-r23-bindless-sload` → `main` · +101 −0 · 4 files · 2 commits · closed without merging Part of #1723 What this unblocks: `s_load` from the resource heap (and any descriptor table) now works when the byte offset sits in a register that an earlier move filled with a known constant, so those descriptor loads stop being refused as "register offset" (first slice of the bindless refusals). Change: - `tools/startup/gfx2hlsl.py`: `s_load*` reads an offset register with a known constant value as that literal byte offset, plus any `offset:` modifier. Unknown registers, `m0` and the sampler heap keep their old handling. - New test `tests/startup_gfx2hlsl_sload_const_offset_check.py`, registered in `CMakeLists.txt` as `startup_gfx2hlsl_sload_const_offset`. Not in this slice: offsets that are truly run-time values (a heap table indexed in the shader). The manifest still refuses a `resheap` resource. Verification: - `python3 -B tests/startup_gfx2hlsl_sload_const_offset_check.py`: 0 failed (same file against the old translator: 3 failed). - `python3 -B tests/startup_gfx2hlsl_smem_offset_check.py`: 0 failed. - `python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py`: 0 failed. - `python3 -B tests/startup_translator_check.py`: 0 failed. - Ran on the Linux worker, not on Win2025: no Windows-only code is touched. AI-assisted; commands listed were executed locally.
Fold only in shaders without branches, sign-extend s_movk_i32, and document the accepted form.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:53:43 +00:00
github-bot closed this pull request 2026-11-26 23:53:43 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:58 UTC · original · edited 2026-11-25 00:05 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-25T00:05:26.511987Z bb93833 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:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#issuecomment-7147991825) · edited 2026-11-25 00:05 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"bb9383321c8da4a0bf8ab1969289f43ca5d8616d","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-25T00:05:26.511987Z">2026-11-25T00:05:26.511987Z</relative-time> | `bb93833` | 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>
@ -2177,2 +2192,4 @@
# 'off' names no offset operand at all, so the byte offset is zero, as for the literal 0.
token = smem_offset(ops[2])
known = self.const_soffset(token) if p[1] != ('smpheap',) else None
if known is not None:
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:05 UTC · original

P1 Badge Require a control-flow-safe proof before folding SGPR offsets

When a branch can skip the offset's defining move, self.sym does not prove its runtime value: Stage.translate() processes instructions linearly without merging symbols at control-flow joins. I reproduced a synthetic root-buffer pipeline that initializes s12 to 0, conditionally skips s_movk_i32 s12, 0x40, then loads through s12; this fold emits r0.Load(64) even on the path that requires offset 0. The parent commit refused this pipeline. Restrict the new folding to straight-line code until a CFG-aware constant proof is available, rather than silently loading the wrong buffer word or descriptor.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#discussion_r4688341231) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Require a control-flow-safe proof before folding SGPR offsets** When a branch can skip the offset's defining move, `self.sym` does not prove its runtime value: `Stage.translate()` processes instructions linearly without merging symbols at control-flow joins. I reproduced a synthetic root-buffer pipeline that initializes `s12` to 0, conditionally skips `s_movk_i32 s12, 0x40`, then loads through `s12`; this fold emits `r0.Load(64)` even on the path that requires offset 0. The parent commit refused this pipeline. Restrict the new folding to straight-line code until a CFG-aware constant proof is available, rather than silently loading the wrong buffer word or descriptor. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -2162,0 +2171,4 @@
if r and r[0] == 's' and r[1] == r[2] and r[1] <= 105:
value = self.is_const(r[1])
if value is not None and 0 <= value <= 0xfffff:
return value
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:05 UTC · original

P2 Badge Sign-extend MOVK constants before accepting them as offsets

For an encoded s_movk_i32 s12, 0x8000, the disassembler prints the raw 16-bit immediate and scalar() currently records ('const', 0x8000), so this new check accepts it as a positive offset. However, MOVK sign-extends its immediate, making the actual SGPR word 0xffff8000. A complete synthetic root-buffer pipeline now succeeds and emits r0.Load(32768) where the parent commit refused the register-offset load. Track the sign-extended MOVK value before using it in this fold, or keep these cases refused, so newly accepted shaders do not read the wrong address.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#discussion_r4688341235) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Sign-extend MOVK constants before accepting them as offsets** For an encoded `s_movk_i32 s12, 0x8000`, the disassembler prints the raw 16-bit immediate and `scalar()` currently records `('const', 0x8000)`, so this new check accepts it as a positive offset. However, MOVK sign-extends its immediate, making the actual SGPR word `0xffff8000`. A complete synthetic root-buffer pipeline now succeeds and emits `r0.Load(32768)` where the parent commit refused the register-offset load. Track the sign-extended MOVK value before using it in this fold, or keep these cases refused, so newly accepted shaders do not read the wrong address. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -3404,1 +3404,4 @@
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_loop_constants_check.py")
# Startup shader translator: s_load with a register offset holding a known constant reaches the heap descriptor (#1723).
add_test(NAME startup_gfx2hlsl_sload_const_offset COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sload_const_offset_check.py")
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:05 UTC · original

P1 Badge Document the newly supported constant-register SMEM offsets

This adds a public scalar-load capability and a reproduction check, but the commit updates neither the README nor docs/experiments.md. In particular, the existing “SMEM offset operands” table still classifies offsets other than literal, off, and m0 forms as refused, which is now incorrect for constant SGPR offsets. AGENTS.md explicitly requires documenting public capability or reproduction-command changes; update the relevant experiment entry with the accepted form, bounds, remaining refusals, and Linux-only translation evidence.

AGENTS.md reference: AGENTS.md:L211-L212

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#discussion_r4688341243) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the newly supported constant-register SMEM offsets** This adds a public scalar-load capability and a reproduction check, but the commit updates neither the README nor `docs/experiments.md`. In particular, the existing “SMEM offset operands” table still classifies offsets other than literal, `off`, and `m0` forms as refused, which is now incorrect for constant SGPR offsets. `AGENTS.md` explicitly requires documenting public capability or reproduction-command changes; update the relevant experiment entry with the accepted form, bounds, remaining refusals, and Linux-only translation evidence. AGENTS.md reference: [AGENTS.md:L211-L212](https://github.com/R0Y00/Xbox2Windows/blob/bb9383321c8da4a0bf8ab1969289f43ca5d8616d/AGENTS.md#L211-L212) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -2177,2 +2192,4 @@
# 'off' names no offset operand at all, so the byte offset is zero, as for the literal 0.
token = smem_offset(ops[2])
known = self.const_soffset(token) if p[1] != ('smpheap',) else None
if known is not None:
Author
Owner

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

Fixed in c28366b3 (rebased on current main, pending push to this branch). The fold now applies only in shaders without branches; s_movk_i32 sign-extends its immediate (0x8000 and above stay refused as offsets); docs/experiments.md has the accepted form, limits and CPU-only evidence. Controls added to tests/startup_gfx2hlsl_sload_const_offset_check.py.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_sload_const_offset_check.py, startup_gfx2hlsl_smem_offset_check.py, startup_translator_check.py, startup_gfx2hlsl_scalar_m0_check.py, docs_links_check.py.

**@⁠tedin7** on GitHub · 2026-11-25 01:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#discussion_r4688758199) Fixed in c28366b3 (rebased on current main, pending push to this branch). The fold now applies only in shaders without branches; s_movk_i32 sign-extends its immediate (0x8000 and above stay refused as offsets); docs/experiments.md has the accepted form, limits and CPU-only evidence. Controls added to tests/startup_gfx2hlsl_sload_const_offset_check.py. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_sload_const_offset_check.py, startup_gfx2hlsl_smem_offset_check.py, startup_translator_check.py, startup_gfx2hlsl_scalar_m0_check.py, docs_links_check.py.
@ -2162,0 +2171,4 @@
if r and r[0] == 's' and r[1] == r[2] and r[1] <= 105:
value = self.is_const(r[1])
if value is not None and 0 <= value <= 0xfffff:
return value
Author
Owner

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

Fixed in c28366b3 (rebased on current main, pending push to this branch). The fold now applies only in shaders without branches; s_movk_i32 sign-extends its immediate (0x8000 and above stay refused as offsets); docs/experiments.md has the accepted form, limits and CPU-only evidence. Controls added to tests/startup_gfx2hlsl_sload_const_offset_check.py.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_sload_const_offset_check.py, startup_gfx2hlsl_smem_offset_check.py, startup_translator_check.py, startup_gfx2hlsl_scalar_m0_check.py, docs_links_check.py.

**@⁠tedin7** on GitHub · 2026-11-25 01:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#discussion_r4688758478) Fixed in c28366b3 (rebased on current main, pending push to this branch). The fold now applies only in shaders without branches; s_movk_i32 sign-extends its immediate (0x8000 and above stay refused as offsets); docs/experiments.md has the accepted form, limits and CPU-only evidence. Controls added to tests/startup_gfx2hlsl_sload_const_offset_check.py. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_sload_const_offset_check.py, startup_gfx2hlsl_smem_offset_check.py, startup_translator_check.py, startup_gfx2hlsl_scalar_m0_check.py, docs_links_check.py.
@ -3404,1 +3404,4 @@
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_loop_constants_check.py")
# Startup shader translator: s_load with a register offset holding a known constant reaches the heap descriptor (#1723).
add_test(NAME startup_gfx2hlsl_sload_const_offset COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sload_const_offset_check.py")
Author
Owner

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

Fixed in c28366b3 (rebased on current main, pending push to this branch). The fold now applies only in shaders without branches; s_movk_i32 sign-extends its immediate (0x8000 and above stay refused as offsets); docs/experiments.md has the accepted form, limits and CPU-only evidence. Controls added to tests/startup_gfx2hlsl_sload_const_offset_check.py.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_sload_const_offset_check.py, startup_gfx2hlsl_smem_offset_check.py, startup_translator_check.py, startup_gfx2hlsl_scalar_m0_check.py, docs_links_check.py.

**@⁠tedin7** on GitHub · 2026-11-25 01:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#discussion_r4688758738) Fixed in c28366b3 (rebased on current main, pending push to this branch). The fold now applies only in shaders without branches; s_movk_i32 sign-extends its immediate (0x8000 and above stay refused as offsets); docs/experiments.md has the accepted form, limits and CPU-only evidence. Controls added to tests/startup_gfx2hlsl_sload_const_offset_check.py. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_sload_const_offset_check.py, startup_gfx2hlsl_smem_offset_check.py, startup_translator_check.py, startup_gfx2hlsl_scalar_m0_check.py, docs_links_check.py.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 13:51 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:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#issuecomment-7164403309) 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

@⁠Leyukaka on GitHub · 2026-11-25 18:40 UTC · original

@⁠tedin7, a question about this PR and #2086, which you paused today.

In a local first-refusal census of captured start-up requests at main dbab543, the refusal this PR targets, s_load with a register offset through ('resheap',), is the first refusal for 174 requests. I have not checked how many of those have the constant offset in a branch-free shader that this PR handles. s_pack_ll_b32_b16 (#2086) is the first refusal for 59. These are counts only; the inputs are private.

Two offers, whichever helps more:

  1. The body says the tests here ran on the Linux worker only. I can run the tests this PR lists in an isolated Windows 11 VM with WARP and post the results here. That is not the Win2025 runner, so it would be extra evidence, not a replacement for your checks.
  2. You said you will reopen these once the queue is clear. If it would help to hand #2066 and #2086 off instead, say so. I would continue from your branches, keep your authorship on the commits, and link back here.

Note: v_add_co_ci_u32 from #2033 is now on main through #2428.

If neither is useful, ignore this.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-25 18:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#issuecomment-7171240515) @⁠tedin7, a question about this PR and #2086, which you paused today. In a local first-refusal census of captured start-up requests at main `dbab543`, the refusal this PR targets, `s_load with a register offset through ('resheap',)`, is the first refusal for 174 requests. I have not checked how many of those have the constant offset in a branch-free shader that this PR handles. `s_pack_ll_b32_b16` (#2086) is the first refusal for 59. These are counts only; the inputs are private. Two offers, whichever helps more: 1. The body says the tests here ran on the Linux worker only. I can run the tests this PR lists in an isolated Windows 11 VM with WARP and post the results here. That is not the Win2025 runner, so it would be extra evidence, not a replacement for your checks. 2. You said you will reopen these once the queue is clear. If it would help to hand #2066 and #2086 off instead, say so. I would continue from your branches, keep your authorship on the commits, and link back here. Note: `v_add_co_ci_u32` from #2033 is now on main through #2428. If neither is useful, ignore this. AI-assisted.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-25 19:15 UTC · original

@⁠tedin7, no reply here yet to my question from 18:40Z, and you said you plan to reopen this, so tell me if you'd rather I stop: I'm picking this up the same way as #2086 (now #2512): a new PR with your commits rebased on current main, keeping your authorship, linked here. Your fixes for the three review findings (branch-free shaders only, s_movk_i32 sign extension, docs) stay as they are. If you'd rather reopen this one yourself, say so and I'll close mine.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-25 19:15 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#issuecomment-7172045166) @⁠tedin7, no reply here yet to my question from 18:40Z, and you said you plan to reopen this, so tell me if you'd rather I stop: I'm picking this up the same way as #2086 (now #2512): a new PR with your commits rebased on current main, keeping your authorship, linked here. Your fixes for the three review findings (branch-free shaders only, `s_movk_i32` sign extension, docs) stay as they are. If you'd rather reopen this one yourself, say so and I'll close mine. AI-assisted.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-25 19:26 UTC · original

Opened as #2517: your commit rebased on current main with your authorship. On top: the s_movk_i32 sign extension is dropped because main already applies it (8e0ef148), the default-sampler placeholder is no longer taken as an offset, and there are a few more edge checks.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-25 19:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#issuecomment-7172289658) Opened as #2517: your commit rebased on current main with your authorship. On top: the `s_movk_i32` sign extension is dropped because main already applies it (8e0ef148), the default-sampler placeholder is no longer taken as an offset, and there are a few more edge checks. AI-assisted.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:05 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb9383321c

ℹ️ 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-25 00:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2066#pullrequestreview-6049473170) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `bb9383321c` <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>

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.