startup: s_load with a constant register offset reaches the heap descriptor (continues #2066, Part of #1723) #2509

Merged
Leyukaka merged 3 commits from upstream-pr/2517 into main 2026-11-25 20:13:11 +00:00
Leyukaka commented 2026-11-25 19:25:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-25T19:25:50Z.


Continues #2066 by @tedin7 (paused to keep the Windows test queue short; takeover note). Part of #1723.

The first commit is tedin7's eb931ba9, cherry-picked onto main 6d2d3be with his authorship. It includes his fixes for the three review findings on #2066.

An s_load_dword* whose offset register holds a known constant now uses it as the literal byte offset, plus any offset: modifier. Such a constant comes from an s_mov_b32 or s_movk_i32 before the load. This reaches descriptors in the resource heap. Limits, unchanged from #2066:

  • The proof is used only in shaders without branches, because symbols are not merged at control-flow joins.
  • An unknown register, m0 and the run-time sampler heap keep their old handling. A constant whose total with the offset: modifier is above 0xfffff is refused (SMEM register offset ...).
  • The manifest still refuses a resheap resource.

Rebase. One conflict in CMakeLists.txt: both sides add a test next to startup_gfx2hlsl_loop_constants, so I kept both.

Two commits of mine on top.

The first drops #2066's s_movk_i32 sign extension in Stage.scalar. Main has sign-extended the SOPK i32 immediates through sopk_imm since 8e0ef148, so s_movk_i32 s9, 0x8000 already records 0xffff8000, and the removed branch could no longer run. The checks for that value, and for the refused negative offset, now exercise main's path. The behaviour #2066 asked for is kept.

The second:

  • makes const_soffset take only an untagged ('const', value) symbol, so the ('const', 0, 'unassigned') default-sampler placeholder is not folded to offset 0;
  • adds checks for s_mov_b32 0x8000 (not sign-extended), a total above 0xfffff, the placeholder and a sampler-heap register offset;
  • lists the check in AGENTS.md and the Linux CI Python list;
  • drops the OS from the docs' evidence line.

Tests. Run on Windows 11 with Python 3.14 at this branch's head, all passing:

  • tests/startup_gfx2hlsl_sload_const_offset_check.py (new, from #2066);
  • startup_gfx2hlsl_smem_offset_check.py;
  • startup_translator_check.py;
  • startup_gfx2hlsl_scalar_m0_check.py;
  • startup_gfx2hlsl_loop_constants_check.py;
  • startup_gfx2hlsl_join_symbols_check.py;
  • startup_gfx2hlsl_sopk_signext_check.py.

docs_links_check.py was not run: it needs a git checkout, and these tests ran on a copy of the tree without .git.

Mutation checks, run by hand. startup_gfx2hlsl_sload_const_offset_check.py fails on each:

  • the branch guard removed;
  • the 0..0xfffff range check removed;
  • the offset: modifier ignored;
  • main's s_movk_i32 sign extension turned off (sopk_imm(..., False)), which startup_gfx2hlsl_sopk_signext_check.py also catches;
  • a tagged constant accepted.

Why. In a local first-refusal census of captured start-up requests at main 6d2d3be, s_load with a register offset through ('resheap',) is the first refusal for 174 requests (private inputs, counts only). I have not measured how many of those are branch-free shaders with a constant offset, which is the case this slice handles.

No GPU run; the checks drive the load handlers on a scalar symbol state.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6612028860 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2517). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-25T19:25:50Z. --- Continues #2066 by @tedin7 (paused to keep the Windows test queue short; [takeover note](https://github.com/R0Y00/Xbox2Windows/pull/2066#issuecomment-7172045166)). Part of #1723. The first commit is tedin7's `eb931ba9`, cherry-picked onto main `6d2d3be` with his authorship. It includes his fixes for the three review findings on #2066. An `s_load_dword*` whose offset register holds a known constant now uses it as the literal byte offset, plus any `offset:` modifier. Such a constant comes from an `s_mov_b32` or `s_movk_i32` before the load. This reaches descriptors in the resource heap. Limits, unchanged from #2066: - The proof is used only in shaders without branches, because symbols are not merged at control-flow joins. - An unknown register, `m0` and the run-time sampler heap keep their old handling. A constant whose total with the `offset:` modifier is above 0xfffff is refused (`SMEM register offset ...`). - The manifest still refuses a `resheap` resource. **Rebase.** One conflict in `CMakeLists.txt`: both sides add a test next to `startup_gfx2hlsl_loop_constants`, so I kept both. **Two commits of mine on top.** The first drops #2066's `s_movk_i32` sign extension in `Stage.scalar`. Main has sign-extended the SOPK i32 immediates through `sopk_imm` since 8e0ef148, so `s_movk_i32 s9, 0x8000` already records `0xffff8000`, and the removed branch could no longer run. The checks for that value, and for the refused negative offset, now exercise main's path. The behaviour #2066 asked for is kept. The second: - makes `const_soffset` take only an untagged `('const', value)` symbol, so the `('const', 0, 'unassigned')` default-sampler placeholder is not folded to offset 0; - adds checks for `s_mov_b32 0x8000` (not sign-extended), a total above 0xfffff, the placeholder and a sampler-heap register offset; - lists the check in AGENTS.md and the Linux CI Python list; - drops the OS from the docs' evidence line. **Tests.** Run on Windows 11 with Python 3.14 at this branch's head, all passing: - `tests/startup_gfx2hlsl_sload_const_offset_check.py` (new, from #2066); - `startup_gfx2hlsl_smem_offset_check.py`; - `startup_translator_check.py`; - `startup_gfx2hlsl_scalar_m0_check.py`; - `startup_gfx2hlsl_loop_constants_check.py`; - `startup_gfx2hlsl_join_symbols_check.py`; - `startup_gfx2hlsl_sopk_signext_check.py`. `docs_links_check.py` was not run: it needs a git checkout, and these tests ran on a copy of the tree without `.git`. **Mutation checks**, run by hand. `startup_gfx2hlsl_sload_const_offset_check.py` fails on each: - the branch guard removed; - the 0..0xfffff range check removed; - the `offset:` modifier ignored; - main's `s_movk_i32` sign extension turned off (`sopk_imm(..., False)`), which `startup_gfx2hlsl_sopk_signext_check.py` also catches; - a tagged constant accepted. **Why.** In a local first-refusal census of captured start-up requests at main `6d2d3be`, `s_load with a register offset through ('resheap',)` is the first refusal for 174 requests (private inputs, counts only). I have not measured how many of those are branch-free shaders with a constant offset, which is the case this slice handles. No GPU run; the checks drive the load handlers on a scalar symbol state. AI-assisted.
tedin7 commented 2026-11-25 20:04:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:37:45Z.

Review: COMMENTED


Review of head 75141d9b (comment only, no approval).

Code (tools/startup/gfx2hlsl.py, const_soffset and the op_s_load_dwordx4 hook): looks correct.

  • The constant is used only without branches, only for an untagged ('const', v) symbol, only for s0..s105, and only when the total with offset: is within 0..0xfffff. has_branches is set at line 1961 and the default is the safe one.
  • The sampler heap keeps its old handling. The refusal message for a too-large total is kept.
  • Sibling checks left out: none found. startup_gfx2hlsl_smem_offset_check.py still passes.
  • No other open or merged PR covers this slice (#2066 is closed, this continues it).

Tests (Linux, at this head):

  • tests/startup_gfx2hlsl_sload_const_offset_check.py: 0 failed.
  • tests/startup_gfx2hlsl_smem_offset_check.py: 0 failed.
  • tests/docs_links_check.py: passed. tests/bidi_controls_check.py: passed. git diff --check origin/main...HEAD: clean.
  • Mutations (each made the new check fail, then reverted): the branch guard removed; the 0xfffff total check removed.

Scope notes:

  • This is a scalar symbol-state change, not an HLSL math lowering, so the checks that drive the handlers are fair. There is no GPU readback and none is needed for this slice.
  • The title and the "first refusal for 174 requests" figure frame it as advancing start-up. I have no executable to confirm that, so I report only code and fixture results. The merge and any start-up claim stay with MasterDomino or @R0Y00, who can verify on the game.
  • .github/workflows/windows.yml only adds the new check to the Python list (one line). Its own CI run exercises it.
  • No Windows WARP run was done by me; this change has no GPU path.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6063843056 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2517#pullrequestreview-6063843056). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T19:37:45Z. **Review:** COMMENTED --- Review of head 75141d9b (comment only, no approval). Code (`tools/startup/gfx2hlsl.py`, `const_soffset` and the `op_s_load_dwordx4` hook): looks correct. - The constant is used only without branches, only for an untagged `('const', v)` symbol, only for s0..s105, and only when the total with `offset:` is within 0..0xfffff. `has_branches` is set at line 1961 and the default is the safe one. - The sampler heap keeps its old handling. The refusal message for a too-large total is kept. - Sibling checks left out: none found. `startup_gfx2hlsl_smem_offset_check.py` still passes. - No other open or merged PR covers this slice (#2066 is closed, this continues it). Tests (Linux, at this head): - `tests/startup_gfx2hlsl_sload_const_offset_check.py`: 0 failed. - `tests/startup_gfx2hlsl_smem_offset_check.py`: 0 failed. - `tests/docs_links_check.py`: passed. `tests/bidi_controls_check.py`: passed. `git diff --check origin/main...HEAD`: clean. - Mutations (each made the new check fail, then reverted): the branch guard removed; the 0xfffff total check removed. Scope notes: - This is a scalar symbol-state change, not an HLSL math lowering, so the checks that drive the handlers are fair. There is no GPU readback and none is needed for this slice. - The title and the "first refusal for 174 requests" figure frame it as advancing start-up. I have no executable to confirm that, so I report only code and fixture results. The merge and any start-up claim stay with MasterDomino or @R0Y00, who can verify on the game. - `.github/workflows/windows.yml` only adds the new check to the Python list (one line). Its own CI run exercises it. - No Windows WARP run was done by me; this change has no GPU path. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 21:01:13 +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!2509
No description provided.