startup: translate the SMEM offset 'off' as the literal 0 in gfx2hlsl #1669

Merged
Asimmimx merged 1 commit from upstream-pr/1676 into main 2026-11-24 17:07:34 +00:00
Asimmimx commented 2026-11-24 16:56:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T16:56:24Z.


Fixes #1674.

Change

tools/startup/gfx2hlsl.py: the SMEM offset operand off names no offset, so the byte offset is zero. A small smem_offset() helper maps off to the literal 0 before the existing handling in both load families:

  • s_buffer_load_dword* used to refuse it with operand 'off'. It now emits exactly what the literal 0 emits, rN.Load(0x00000000u + 4 * i), and marks the result as a fixed buffer word in the same way.
  • s_load_dword* used to fail in int(ops[2], 0) and report the misleading s_load with a register offset through .... It now takes offset 0: rN.Load(0) from a root buffer, or descriptor offset 0 from a table.
Offset operand s_buffer_load_dword* s_load_dword*
literal unchanged unchanged
off same as literal 0 (was refused) same as literal 0 (was refused)
m0 register offset, unchanged refused, unchanged (sampler-heap path untouched)
anything else refused refused

Out of scope, as the issue says: an m0 register offset for s_load_dword*, and the count of locally refused shaders.

Test

tests/startup_gfx2hlsl_smem_offset_check.py follows startup_translator_check.py. It drives the handlers on a scalar symbol state with no machine code and checks:

  1. off against the literal 0. Emitted lines and the resulting symbols must be equal for s_buffer_load_dword, _dwordx2 and _dwordx4, for s_load_dword and _dwordx2 from a root buffer, and for s_load_dwordx8 from a descriptor table, where all eight registers must be ('desc', table, 0, i).
  2. The literal and m0 forms keep their behaviour: 0x4 and 0x8 are unchanged, s_buffer_load_dword ... m0 gives r0.Load(m0 + 0) and is not marked as a fixed word, and s_load_dword ... m0 is still refused.
  3. Five other spellings (of, OFF, offset, null, off:0) are refused by both kinds of load. So off is not loosened into "anything means zero".
  4. Negative control: with smem_offset replaced by the identity in-process, both off forms must be refused again with the old messages.

The test is registered as startup_gfx2hlsl_smem_offset and added to the platform-independent Python job and the list in AGENTS.md. docs/experiments.md gets a short section with the operand table.

Results

Commit 04711708 on f121513e, Windows 11 26300.9974, Python 3.12:

python -B tests/startup_gfx2hlsl_smem_offset_check.py
...
control: s_buffer_load_dword off refused without the handling: ok
control: s_load_dword off refused without the handling: ok
SMEM offset checks: 0 failed          (exit 0)

On f121513e without the change, the same file fails at the first check (s_buffer_load_dword: off accepted: MISMATCH "operand 'off'") and exits non-zero.

These also still pass: startup_translator_check.py, startup_uniform_lane_check.py (whose fixed-element read depends on the fixed-word marking), startup_gfx2hlsl_sdwa_check.py, startup_sampler_heap_check.py, startup_gfx2hlsl_capture_check.py, startup_inline_sampler_check.py, startup_flat_param_check.py, startup_image_load_mip_check.py, docs_links_check.py and bidi_controls_check.py.

Not measured: whether the locally refused loading-screen shaders now translate. That needs the local cache, as the issue notes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587029482 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1676). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T16:56:24Z. --- Fixes #1674. ## Change `tools/startup/gfx2hlsl.py`: the SMEM offset operand `off` names no offset, so the byte offset is zero. A small `smem_offset()` helper maps `off` to the literal `0` before the existing handling in both load families: - `s_buffer_load_dword*` used to refuse it with `operand 'off'`. It now emits exactly what the literal `0` emits, `rN.Load(0x00000000u + 4 * i)`, and marks the result as a fixed buffer word in the same way. - `s_load_dword*` used to fail in `int(ops[2], 0)` and report the misleading `s_load with a register offset through ...`. It now takes offset 0: `rN.Load(0)` from a root buffer, or descriptor offset 0 from a table. | Offset operand | `s_buffer_load_dword*` | `s_load_dword*` | |---|---|---| | literal | unchanged | unchanged | | `off` | **same as literal 0** (was refused) | **same as literal 0** (was refused) | | `m0` | register offset, unchanged | refused, unchanged (sampler-heap path untouched) | | anything else | refused | refused | Out of scope, as the issue says: an `m0` register offset for `s_load_dword*`, and the count of locally refused shaders. ## Test `tests/startup_gfx2hlsl_smem_offset_check.py` follows `startup_translator_check.py`. It drives the handlers on a scalar symbol state with no machine code and checks: 1. `off` against the literal `0`. Emitted lines and the resulting symbols must be equal for `s_buffer_load_dword`, `_dwordx2` and `_dwordx4`, for `s_load_dword` and `_dwordx2` from a root buffer, and for `s_load_dwordx8` from a descriptor table, where all eight registers must be `('desc', table, 0, i)`. 2. The literal and `m0` forms keep their behaviour: `0x4` and `0x8` are unchanged, `s_buffer_load_dword ... m0` gives `r0.Load(m0 + 0)` and is not marked as a fixed word, and `s_load_dword ... m0` is still refused. 3. Five other spellings (`of`, `OFF`, `offset`, `null`, `off:0`) are refused by both kinds of load. So `off` is not loosened into "anything means zero". 4. Negative control: with `smem_offset` replaced by the identity in-process, both `off` forms must be refused again with the old messages. The test is registered as `startup_gfx2hlsl_smem_offset` and added to the platform-independent Python job and the list in `AGENTS.md`. `docs/experiments.md` gets a short section with the operand table. ## Results Commit `04711708` on `f121513e`, Windows 11 26300.9974, Python 3.12: ``` python -B tests/startup_gfx2hlsl_smem_offset_check.py ... control: s_buffer_load_dword off refused without the handling: ok control: s_load_dword off refused without the handling: ok SMEM offset checks: 0 failed (exit 0) ``` On `f121513e` without the change, the same file fails at the first check (`s_buffer_load_dword: off accepted: MISMATCH "operand 'off'"`) and exits non-zero. These also still pass: `startup_translator_check.py`, `startup_uniform_lane_check.py` (whose fixed-element read depends on the fixed-word marking), `startup_gfx2hlsl_sdwa_check.py`, `startup_sampler_heap_check.py`, `startup_gfx2hlsl_capture_check.py`, `startup_inline_sampler_check.py`, `startup_flat_param_check.py`, `startup_image_load_mip_check.py`, `docs_links_check.py` and `bidi_controls_check.py`. Not measured: whether the locally refused loading-screen shaders now translate. That needs the local cache, as the issue notes. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 18:02:26 +00:00
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!1669
No description provided.