Translate SMEM 'off' as a zero byte offset in gfx2hlsl #1682

Closed
draarivpatel-ui wants to merge 1 commit from upstream-pr/1689 into main
draarivpatel-ui commented 2026-11-24 17:08:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by draarivpatel-ui on 2026-11-24T17:08:46Z.


Change

Fixes #1674.

s_buffer_load_dword* and s_load_dword* refused the SMEM offset operand off, the encoding with no m0 register and no immediate, so a zero byte offset. op_s_buffer_load_dword passed the operand to the uint helper, which raised operand 'off'; op_s_load_dwordx4 failed in int(ops[2], 0) and reported the misleading s_load with a register offset through ....

off now lowers as a zero byte offset: s_buffer_load_dword s0, s[4:7], off emits s0 = r0.Load(0u + 0); and s_load_dword s0, s[4:5], off emits s0 = r0.Load(0);, the same arithmetic the literal 0 produces. A literal, m0 as a buffer register offset, the s_load register-offset refusal and unknown operands all keep their existing behaviour. The new section in docs/experiments.md records the accepted operand forms.

Verification

On macOS arm64 with Python 3.13:

python3 -B tests/startup_gfx2hlsl_smem_off_check.py

All 11 checks pass. On the commit before this change the same script fails at the first check with Unsupported: operand 'off', matching the issue's table. Neighbouring pure-Python checks also pass: startup_gfx2hlsl_capture_check.py, startup_gfx2hlsl_sdwa_check.py, startup_gfx2hlsl_bit_alu_check.py (controls), startup_sampler_heap_check.py, startup_translator_check.py and startup_tools_lint_check.py (PASS: 7 files under tools/startup parse).

Evidence and follow-up

The new check tests/startup_gfx2hlsl_smem_off_check.py is registered as startup_gfx2hlsl_smem_off and added to the platform-independent Python list in .github/workflows/windows.yml. It feeds source text to Stage.one the way startup_gfx2hlsl_bit_alu_check.py does, so no binary fixture or assembler is needed. Not in this slice, matching the issue: an m0 register offset for s_load_dword* (still refused) and proving the whole loading-screen shader set translates.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Devin).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587258326 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1689). Originally posted by [draarivpatel-ui](https://github.com/draarivpatel-ui) on 2026-11-24T17:08:46Z. --- ## Change Fixes #1674. `s_buffer_load_dword*` and `s_load_dword*` refused the SMEM offset operand `off`, the encoding with no `m0` register and no immediate, so a zero byte offset. `op_s_buffer_load_dword` passed the operand to the uint helper, which raised `operand 'off'`; `op_s_load_dwordx4` failed in `int(ops[2], 0)` and reported the misleading `s_load with a register offset through ...`. `off` now lowers as a zero byte offset: `s_buffer_load_dword s0, s[4:7], off` emits `s0 = r0.Load(0u + 0);` and `s_load_dword s0, s[4:5], off` emits `s0 = r0.Load(0);`, the same arithmetic the literal `0` produces. A literal, `m0` as a buffer register offset, the `s_load` register-offset refusal and unknown operands all keep their existing behaviour. The new section in `docs/experiments.md` records the accepted operand forms. ## Verification On macOS arm64 with Python 3.13: ``` python3 -B tests/startup_gfx2hlsl_smem_off_check.py ``` All 11 checks pass. On the commit before this change the same script fails at the first check with `Unsupported: operand 'off'`, matching the issue's table. Neighbouring pure-Python checks also pass: `startup_gfx2hlsl_capture_check.py`, `startup_gfx2hlsl_sdwa_check.py`, `startup_gfx2hlsl_bit_alu_check.py` (controls), `startup_sampler_heap_check.py`, `startup_translator_check.py` and `startup_tools_lint_check.py` (`PASS: 7 files under tools/startup parse`). ## Evidence and follow-up The new check `tests/startup_gfx2hlsl_smem_off_check.py` is registered as `startup_gfx2hlsl_smem_off` and added to the platform-independent Python list in `.github/workflows/windows.yml`. It feeds source text to `Stage.one` the way `startup_gfx2hlsl_bit_alu_check.py` does, so no binary fixture or assembler is needed. Not in this slice, matching the issue: an `m0` register offset for `s_load_dword*` (still refused) and proving the whole loading-screen shader set translates. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Devin).
upstream-sync closed this pull request 2026-11-24 18:02:32 +00:00
copilot-pull-request-reviewer[bot commented 2026-11-24 18:02:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T17:08:59Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043886559 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1689#pullrequestreview-6043886559). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-24T17:08:59Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
tedin7 commented 2026-11-24 18:02:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:15:18Z.

Review: COMMENTED


Review of head d252298c21c5a181613b29a112c091f0692ffde3. Superseded: #1676 (same issue #1674) was merged to main at 17:07:34 UTC today, and main already contains the fix. This PR also conflicts with it (git merge-tree origin/main reports a content conflict in tools/startup/gfx2hlsl.py).

Linux limits. Linux x86_64, llvm-mc-19, no Windows, no DXC, no GPU. Python-level translation only.

Compared with origin/main (685dcc3a)

  • Same behavior: off is a zero byte offset for s_load_dword* and s_buffer_load_dword*; both mark the buffer word fixed_buffer_word. Main does it through a shared smem_offset() helper.
  • One cosmetic difference: this PR emits r0.Load(0u + 0), main emits r0.Load(0x00000000u + 0), the same text the literal 0 produces.
  • I copied this PR's tests/startup_gfx2hlsl_smem_off_check.py onto main and ran it: it fails at the first check because it expects 0u + 0. Main's own startup_gfx2hlsl_smem_offset_check.py passes (0 failed). On its own head this PR's test passes.
  • Useful additions over main: none found. Main's test already covers the m0, literal, refusal and negative-control cases, and main's refusal list is wider (of, OFF, offset, null, off:0). The two tests are otherwise equivalent in intent, so keeping both would be a duplicate with a conflicting expected string.
  • It also adds a windows.yml line for its test; main's version of the test is already listed.

Still open, applies to main too: I could not make the in-tree decoder (tools/disasm_rdna2.py) print off for SMEM (64 opcodes x 128 soffset values fuzzed), and llvm-mc-19 rejects off for gfx1010/gfx1013. off is printed for MUBUF/global addresses. A real shader that produced operand 'off' would confirm which instruction the original refusals came from.

Suggest closing as superseded by #1676. Not approving.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043983737 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1689#pullrequestreview-6043983737). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:15:18Z. **Review:** COMMENTED --- Review of head `d252298c21c5a181613b29a112c091f0692ffde3`. **Superseded: #1676 (same issue #1674) was merged to `main` at 17:07:34 UTC today, and `main` already contains the fix.** This PR also conflicts with it (`git merge-tree origin/main` reports a content conflict in `tools/startup/gfx2hlsl.py`). **Linux limits.** Linux x86_64, `llvm-mc-19`, no Windows, no DXC, no GPU. Python-level translation only. **Compared with `origin/main` (`685dcc3a`)** - Same behavior: `off` is a zero byte offset for `s_load_dword*` and `s_buffer_load_dword*`; both mark the buffer word `fixed_buffer_word`. Main does it through a shared `smem_offset()` helper. - One cosmetic difference: this PR emits `r0.Load(0u + 0)`, main emits `r0.Load(0x00000000u + 0)`, the same text the literal `0` produces. - I copied this PR's `tests/startup_gfx2hlsl_smem_off_check.py` onto main and ran it: it fails at the first check because it expects `0u + 0`. Main's own `startup_gfx2hlsl_smem_offset_check.py` passes (0 failed). On its own head this PR's test passes. - Useful additions over main: none found. Main's test already covers the `m0`, literal, refusal and negative-control cases, and main's refusal list is wider (`of`, `OFF`, `offset`, `null`, `off:0`). The two tests are otherwise equivalent in intent, so keeping both would be a duplicate with a conflicting expected string. - It also adds a `windows.yml` line for its test; main's version of the test is already listed. **Still open, applies to main too:** I could not make the in-tree decoder (`tools/disasm_rdna2.py`) print `off` for SMEM (64 opcodes x 128 soffset values fuzzed), and `llvm-mc-19` rejects `off` for gfx1010/gfx1013. `off` is printed for MUBUF/global addresses. A real shader that produced `operand 'off'` would confirm which instruction the original refusals came from. Suggest closing as superseded by #1676. Not approving. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-24 18:02:56 +00:00 (Migrated from github.com)

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


Thanks for the independent reproduction. #1676 has already landed for #1674 with both SMEM load families and the literal, m0, refusal and fixed-word controls. This overlaps the landed change, so I am closing it as a duplicate.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7138967824 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1689#issuecomment-7138967824). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T17:17:16Z. --- Thanks for the independent reproduction. #1676 has already landed for #1674 with both SMEM load families and the literal, m0, refusal and fixed-word controls. This overlaps the landed change, so I am closing it as a duplicate.

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