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

Manually merged
github merged 1 commit from gh-pr/1676/head into gh-pr/1676/base 2026-11-26 23:25:19 +00:00
Owner

@⁠Asimmimx on GitHub · 2026-11-24 16:56 UTC · original
Asimmimx:startup/gfx2hlsl-smem-off → main · +146 −3 · 6 files · 1 commits · merged 2026-11-24 17:07 UTC

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).

**@⁠Asimmimx** on GitHub · 2026-11-24 16:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1676) `Asimmimx:startup/gfx2hlsl-smem-off` → `main` · +146 −3 · 6 files · 1 commits · merged 2026-11-24 17:07 UTC 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).
The offset operand 'off' names no offset, so the byte offset is zero.
s_buffer_load_dword* passed it to the uint helper, which refused it as
"operand 'off'", and s_load_dword* failed in int() and reported the
misleading "s_load with a register offset through ...". Both now map 'off'
to the literal 0 before their existing handling, so the emitted HLSL, the
descriptor offset of a table load and the fixed-word marking of an
s_buffer_load result are the same as for '0'. Literal offsets are unchanged,
s_buffer_load keeps m0 as a register offset, s_load keeps refusing it, and
every other operand is still refused.

tests/startup_gfx2hlsl_smem_offset_check.py drives the load handlers on a
scalar symbol state with no machine code: the 'off' forms of
s_buffer_load_dword/x2/x4, s_load_dword/x2 from a root buffer and
s_load_dwordx8 from a descriptor table against the literal 0, the literal
and m0 forms, five refused operand spellings for both kinds of load, and an
in-process control that removes the 'off' handling and requires both forms
to be refused again. Registered as startup_gfx2hlsl_smem_offset and added
to the platform-independent Python job.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:25:18 +00:00
github manually merged commit 0471170870 into gh-pr/1676/base 2026-11-26 23:25:19 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.