Skip to content

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

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
Leyukaka:sload-const-offset
Nov 25, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
Leyukaka:sload-const-offset

Conversation

@Leyukaka

Copy link
Copy Markdown
Contributor

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 8e0ef14, 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:

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 and others added 3 commits November 25, 2026 20:22
…riptor (R0Y00#1723)

Fold only in shaders without branches, sign-extend s_movk_i32, and document the accepted form.
8e0ef14 sign-extends the SOPK i32 immediates through sopk_imm before this
branch, so a 0x8000..0xffff value can no longer reach it. The
startup_gfx2hlsl_sload_const_offset checks for the sign-extended value and
the refused negative offset still pass on main's path.

AI-assisted.
const_soffset now takes only an untagged ('const', value) symbol, so the
('const', 0, 'unassigned') default-sampler placeholder is not folded to
offset 0. New checks: s_mov_b32 0x8000 stays 0x8000, a constant plus an
offset: modifier above 0xfffff is refused, the placeholder is refused, and a
sampler-heap register offset is not folded.

List startup_gfx2hlsl_sload_const_offset_check.py in AGENTS.md and the Linux
CI Python list next to startup_gfx2hlsl_smem_offset_check.py, and drop the
OS from the docs' evidence line.

AI-assisted.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head 75141d9 (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.

@R0Y00
R0Y00 merged commit 3ef8f24 into R0Y00:main Nov 25, 2026
5 checks passed
legacy-code-archaeologist added a commit to legacy-code-archaeologist/Xbox2Windows that referenced this pull request Nov 25, 2026
# Conflicts:
#	docs/experiments.md
#	tests/startup_gfx2hlsl_sload_const_offset_check.py
#	tools/startup/gfx2hlsl.py
legacy-code-archaeologist added a commit to legacy-code-archaeologist/Xbox2Windows that referenced this pull request Nov 25, 2026
…on (R0Y00#2517 union merge)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants