startup: treat the SMEM offset form 'off' as zero #1674

Closed
triggered02 wants to merge 1 commit from upstream-pr/1681 into main
triggered02 commented 2026-11-24 17:00:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T17:00:24Z.


Fixes #1674. This is the largest single group in the loading-screen refusal census — 7 of 29 refused shaders (#870).

Problem

off is the SMEM offset form with no m0 offset, so its byte offset is zero. gfx2hlsl passed the operand to the uint helper, which refused the whole translation:

s_buffer_load_dword s0, s[4:7], off
-> REFUSED: operand 'off'

In s_load_dword* the same operand failed earlier inside int(ops[2], 0) and reported s_load with a register offset through ..., which named the wrong cause.

Change

before: s_buffer_load_dword s0, s[4:7], off        -> REFUSED: operand 'off'
after:  s_buffer_load_dword s0, s[4:7], off        -> s0 = r0.Load(0u + 0);
        s_buffer_load_dwordx2 s[2:3], s[4:7], off  -> s2 = r0.Load(0u + 0); s3 = r0.Load(0u + 4);
        s_load_dword s0, s[4:5], off               -> r0.Load(0)

The literal and m0 forms keep their previous behaviour (s_buffer_load keeps m0 as a register offset; s_load still refuses a register offset), and an operand that is neither a literal, m0 nor off is still refused rather than silently treated as zero.

Test

New startup_gfx2hlsl_smem_offset ctest covering:

  • off accepted as zero for s_buffer_load_dword, s_buffer_load_dwordx2 and s_load_dword;
  • the literal forms emit the same offset arithmetic as before;
  • m0 stays a register offset for s_buffer_load, and stays refused for s_load;
  • an unknown operand is still refused;
  • the three refusals below, so a future widening cannot silently start accepting them.
startup_gfx2hlsl_smem_offset  Passed  0.19 s (dev) / 0.17 s (release)
five neighbouring startup_gfx2hlsl tests  Passed

Fail-first: reverting the two lines makes the new test fail with Unsupported: operand 'off' / the int() ValueError.

What this does not establish

  • That the loading-screen shader set now translates. That needs the local cache (#870) and can only be reported as aggregate counts, not here; I will follow up there once re-run.
  • An m0 register offset for s_load_dword* stays refused; this slice does not model it.
  • The other refusal groups in that census (v_cvt_f32_i32 with ['mul:2'], BUF_FMT_16_16_16_16_FLOAT, SQ_RSRC_IMG_1D) are untouched.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587103457 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1681). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T17:00:24Z. --- Fixes #1674. This is the largest single group in the loading-screen refusal census — **7 of 29** refused shaders (#870). ## Problem `off` is the SMEM offset form with **no `m0` offset**, so its byte offset is zero. `gfx2hlsl` passed the operand to the uint helper, which refused the whole translation: ``` s_buffer_load_dword s0, s[4:7], off -> REFUSED: operand 'off' ``` In `s_load_dword*` the same operand failed earlier inside `int(ops[2], 0)` and reported `s_load with a register offset through ...`, which named the wrong cause. ## Change ``` before: s_buffer_load_dword s0, s[4:7], off -> REFUSED: operand 'off' after: s_buffer_load_dword s0, s[4:7], off -> s0 = r0.Load(0u + 0); s_buffer_load_dwordx2 s[2:3], s[4:7], off -> s2 = r0.Load(0u + 0); s3 = r0.Load(0u + 4); s_load_dword s0, s[4:5], off -> r0.Load(0) ``` The literal and `m0` forms keep their previous behaviour (`s_buffer_load` keeps `m0` as a register offset; `s_load` still refuses a register offset), and an operand that is neither a literal, `m0` nor `off` is still refused rather than silently treated as zero. ## Test New `startup_gfx2hlsl_smem_offset` ctest covering: - `off` accepted as zero for `s_buffer_load_dword`, `s_buffer_load_dwordx2` and `s_load_dword`; - the literal forms emit the same offset arithmetic as before; - `m0` stays a register offset for `s_buffer_load`, and stays refused for `s_load`; - an unknown operand is still refused; - the three refusals below, so a future widening cannot silently start accepting them. ``` startup_gfx2hlsl_smem_offset Passed 0.19 s (dev) / 0.17 s (release) five neighbouring startup_gfx2hlsl tests Passed ``` Fail-first: reverting the two lines makes the new test fail with `Unsupported: operand 'off'` / the `int()` `ValueError`. ## What this does not establish - That the loading-screen shader set now translates. That needs the local cache (#870) and can only be reported as aggregate counts, not here; I will follow up there once re-run. - An `m0` register offset for `s_load_dword*` stays refused; this slice does not model it. - The other refusal groups in that census (`v_cvt_f32_i32 with ['mul:2']`, `BUF_FMT_16_16_16_16_FLOAT`, `SQ_RSRC_IMG_1D`) are untouched. AI-assisted (Claude Code).
chatgpt-codex-connector[bot commented 2026-11-24 17:02:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T17:00:39Z.


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-24T17:04:00.617735Z 0f00121 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:7138547591 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1681#issuecomment-7138547591). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T17:00:39Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"0f00121d524707a350a02252a04108ee66bc34d1","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-24T17:04:00.617735Z">2026-11-24T17:04:00.617735Z</relative-time> | `0f00121` | 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>
upstream-sync closed this pull request 2026-11-24 18:02:28 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 18:02:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T17:03:58Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0f00121d52

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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043807583 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1681#pullrequestreview-6043807583). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T17:03:58Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `0f00121d52` <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>
R0Y00 commented 2026-11-24 18:02:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T17:07:44Z.


Thanks for filing #1674 and providing an independent implementation. #1676 is on main and covers the same two SMEM forms, including the fixed-buffer-word classification and descriptor-table case. Closing the overlapping implementation here. The loading-cache rescan you offered remains valuable in #870 as aggregate evidence.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7138728184 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1681#issuecomment-7138728184). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T17:07:44Z. --- Thanks for filing #1674 and providing an independent implementation. #1676 is on main and covers the same two SMEM forms, including the fixed-buffer-word classification and descriptor-table case. Closing the overlapping implementation here. The loading-cache rescan you offered remains valuable in #870 as aggregate evidence.
triggered02 commented 2026-11-24 18:02:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T17:09:01Z.


You are right and I am closing this PR rather than reworking it in place — the fix targets a path the decoder never produces, so it does not help the shaders the issue is about.

Confirmation of your finding. With Stage.one annotating the refusing instruction, re-running translation over the same 29 refused cache entries gives:

7 x operand 'off'   [at exp mrt0 v0, v0, off, off done compr vm]

Every one of the seven is an exp export whose unused channels are spelled off. None is an SMEM load, and the decoder's SMEM path does emit a hex literal for selector 125 as you said (tools/disasm_rdna2.py:2674-2681). The s_setreg-style text I patched only appears in hand-written assembly, which is exactly what my test injected through Stage.one — so the test proved the branch works while never exercising a decoded instruction. That is the more serious of the two errors: an unreachable fix is harmless, an unreachable test is not.

My independent check agrees with yours on the mechanism as well: buffer_load_dword v5, off, s[8:11], s3 from 000030e000050203 reaches the buffer path with a different failure, and SMEM 0x4-style literals translate fine.

What happens next. I am filing a corrected issue for the real form — exp with off channels — with a test that starts from encoded bytes and goes through decode(), not from hand-written assembly, and I will send that as a new PR. #1674 will be corrected or closed, since its diagnosis (SMEM offset operand) was wrong.

Thanks for reading the call site instead of the diff. The u('off') message survives to the .fail file, which made the wrong group look plausible; the annotated re-run is what actually located it.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7138760066 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1681#issuecomment-7138760066). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T17:09:01Z. --- You are right and I am closing this PR rather than reworking it in place — the fix targets a path the decoder never produces, so it does not help the shaders the issue is about. **Confirmation of your finding.** With `Stage.one` annotating the refusing instruction, re-running translation over the same 29 refused cache entries gives: ``` 7 x operand 'off' [at exp mrt0 v0, v0, off, off done compr vm] ``` Every one of the seven is an `exp` export whose unused channels are spelled `off`. None is an SMEM load, and the decoder's SMEM path does emit a hex literal for selector 125 as you said (`tools/disasm_rdna2.py:2674-2681`). The `s_setreg`-style text I patched only appears in hand-written assembly, which is exactly what my test injected through `Stage.one` — so the test proved the branch works while never exercising a decoded instruction. That is the more serious of the two errors: an unreachable fix is harmless, an unreachable *test* is not. My independent check agrees with yours on the mechanism as well: `buffer_load_dword v5, off, s[8:11], s3` from `000030e000050203` reaches the buffer path with a different failure, and SMEM `0x4`-style literals translate fine. **What happens next.** I am filing a corrected issue for the real form — `exp` with `off` channels — with a test that starts from encoded bytes and goes through `decode()`, not from hand-written assembly, and I will send that as a new PR. #1674 will be corrected or closed, since its diagnosis (SMEM offset operand) was wrong. Thanks for reading the call site instead of the diff. The `u('off')` message survives to the .fail file, which made the wrong group look plausible; the annotated re-run is what actually located it. AI-assisted (Claude Code).
chatgpt-codex-connector[bot commented 2026-11-24 18:03:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T17:03:58Z.

Code review location: tools/startup/gfx2hlsl.py; line 597

@@ -591,7 +592,9 @@ def op_s_load_dword(self, ops, mods):
     def op_s_buffer_load_dword(self, ops, mods, count=1):
         dst = reg_range(ops[0])
         buf = self.pipe.resource(self.descriptor(ops[1]), 'buf')
-        offset = self.u(ops[2])
+        # The SMEM offset operand is either a literal, m0 (a register offset) or `off`, which means no m0
+        # offset at all: zero. Treating `off` as an unknown uint operand refused the whole translation.
+        offset = '0u' if ops[2] == 'off' else self.u(ops[2])

P2 Badge Make the off branch reachable for decoded shader bytes

In the real pipeline, Stage.__init__ populates instructions through decode(), which calls D.decode_instruction; tools/disasm_rdna2.py:2674-2681 emits an SMEM operand as a hex literal for selector 125 or via decode_s_reg otherwise, never as off. This condition—and the test that injects handwritten assembly into Stage.one—is therefore unreachable for shader bytes, so the reported refused shaders will still refuse. Update the decoder or input path, or test this through a real decoded instruction.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4683627039 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1681#discussion_r4683627039). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T17:03:58Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 597 ~~~~diff @@ -591,7 +592,9 @@ def op_s_load_dword(self, ops, mods): def op_s_buffer_load_dword(self, ops, mods, count=1): dst = reg_range(ops[0]) buf = self.pipe.resource(self.descriptor(ops[1]), 'buf') - offset = self.u(ops[2]) + # The SMEM offset operand is either a literal, m0 (a register offset) or `off`, which means no m0 + # offset at all: zero. Treating `off` as an unknown uint operand refused the whole translation. + offset = '0u' if ops[2] == 'off' else self.u(ops[2]) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Make the `off` branch reachable for decoded shader bytes** In the real pipeline, `Stage.__init__` populates instructions through `decode()`, which calls `D.decode_instruction`; `tools/disasm_rdna2.py:2674-2681` emits an SMEM operand as a hex literal for selector 125 or via `decode_s_reg` otherwise, never as `off`. This condition—and the test that injects handwritten assembly into `Stage.one`—is therefore unreachable for shader bytes, so the reported refused shaders will still refuse. Update the decoder or input path, or test this through a real decoded instruction. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->

Pull request closed

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!1674
No description provided.