startup: fold s_mov_b32 copies of a constant SGPR so inline samplers translate (Part of #1723) #2700

Merged
tedin7 merged 6 commits from upstream-pr/2708 into main 2026-11-26 06:04:21 +00:00
tedin7 commented 2026-11-26 02:59:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:59:47Z.


Part of #1723

What this unblocks: an inline sampler whose words are built by copying a zero register (the way LLVM builds <0, N, M, 0>) now translates to a static sampler instead of being refused as a descriptor held in an unknown register.

Small follow-up to #2319, which folds s_brev_b32 of a known constant; the copy form was still missing.

What changed

s_mov_b32 sD, sS where sS holds a plain known constant now makes sD that constant (same word, same symbolic value), so const_words() can read the four sampler words. Example: s_mov_b32 s15, 0 then s_mov_b32 s12, s15 for sampler word 0.

The second commit narrows the fold to a plain constant. A register with an unassigned placeholder, a run-time value or a descriptor symbol is not copied as a constant, so a sampler built from run-time words stays refused.

What stays refused

A sampler with any word from a run-time register, a table or the sampler heap; vector or 64-bit moves; copies of non-constant registers.

Tests

tests/startup_inline_sampler_check.py (already registered in CMakeLists.txt): check_copied_constant_sampler (a copied-zero sampler folds to the expected smp line), check_copy_only_folds_plain_constants (copies of non-constant symbols are not folded), and check_copied_sampler_after_overwrite (a run-time source is refused, a new constant wins). On origin/main the check fails (descriptor operand s[24:27] holds ('const', 0)); with the change it passes.

Verification

  • python3 -B tests/startup_inline_sampler_check.py: PASS (fails on origin/main)
  • python3 -B tests/startup_inline_sampler_check.py binary llvm-mc-19: PASS (fixture words assemble to the recorded words)
  • All tests/startup_gfx2hlsl_*_check.py run with no arguments on this branch and on origin/main: identical result per script (108 scripts, export_null_draw and mul24_align_draw need a compiler and renderer and exit 1 on both).
  • Win2025 (dev + release, head a52f1d75e): x2w_pipe.py win2025 2708 --regex startup_inline_sampler: 3/3 passed (controls, warp, hardware). The draw now includes a shader whose sampler word 0 is built in s29 and copied into s24 (it must read the clamped texel with its own sampler and mismatch with the wrap sampler), so a GPU readback depends on the copy fold.
  • Build and run: cmake --build --preset dev --target offscreen_check then ctest --preset dev --no-tests=error -R '^startup_inline_sampler' -V.
  • Branch merged with current main (no rebase) so it builds on Windows after #2706.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6618533808 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2708). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:59:47Z. --- Part of #1723 What this unblocks: an inline sampler whose words are built by copying a zero register (the way LLVM builds `<0, N, M, 0>`) now translates to a static sampler instead of being refused as a descriptor held in an unknown register. Small follow-up to #2319, which folds `s_brev_b32` of a known constant; the copy form was still missing. ## What changed `s_mov_b32 sD, sS` where `sS` holds a plain known constant now makes `sD` that constant (same word, same symbolic value), so `const_words()` can read the four sampler words. Example: `s_mov_b32 s15, 0` then `s_mov_b32 s12, s15` for sampler word 0. The second commit narrows the fold to a plain constant. A register with an unassigned placeholder, a run-time value or a descriptor symbol is not copied as a constant, so a sampler built from run-time words stays refused. ## What stays refused A sampler with any word from a run-time register, a table or the sampler heap; vector or 64-bit moves; copies of non-constant registers. ## Tests `tests/startup_inline_sampler_check.py` (already registered in `CMakeLists.txt`): `check_copied_constant_sampler` (a copied-zero sampler folds to the expected `smp` line), `check_copy_only_folds_plain_constants` (copies of non-constant symbols are not folded), and `check_copied_sampler_after_overwrite` (a run-time source is refused, a new constant wins). On `origin/main` the check fails (`descriptor operand s[24:27] holds ('const', 0)`); with the change it passes. ## Verification - `python3 -B tests/startup_inline_sampler_check.py`: PASS (fails on `origin/main`) - `python3 -B tests/startup_inline_sampler_check.py binary llvm-mc-19`: PASS (fixture words assemble to the recorded words) - All `tests/startup_gfx2hlsl_*_check.py` run with no arguments on this branch and on `origin/main`: identical result per script (108 scripts, `export_null_draw` and `mul24_align_draw` need a compiler and renderer and exit 1 on both). - Win2025 (dev + release, head a52f1d75e): `x2w_pipe.py win2025 2708 --regex startup_inline_sampler`: 3/3 passed (controls, warp, hardware). The draw now includes a shader whose sampler word 0 is built in s29 and copied into s24 (it must read the clamped texel with its own sampler and mismatch with the wrap sampler), so a GPU readback depends on the copy fold. - Build and run: `cmake --build --preset dev --target offscreen_check` then `ctest --preset dev --no-tests=error -R '^startup_inline_sampler' -V`. - Branch merged with current `main` (no rebase) so it builds on Windows after #2706. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:40:46Z.


@MasterDomino Ready for review on head a52f1d75e.

Independent gate review of the fold (s_mov_b32 copy of a plain constant SGPR): tried a branch-arm sampler word, copies of a run-time/placeholder/descriptor source, a 64-bit pair, vcc and m0 sources, and two one-line mutations of the fix (drop the plain-constant guard; copy a wrong value). The first set stays refused or unfolded, both mutations fail startup_inline_sampler_check.py.

Gap found and closed: only translation controls covered the copy form. check_draw now also draws a shader whose sampler word 0 is built in s29 and copied into s24; it must read the clamped texel with its own sampler and mismatch with the wrap sampler (wrong-value control). The branch was also merged with current main (no rebase, no force) so it builds on Windows after #2706.

Verification:

  • Linux: python3 -B tests/startup_inline_sampler_check.py and ... binary llvm-mc-19 pass; on origin/main's translator the check fails.
  • Win2025 (dev + release): x2w_pipe.py win2025 2708 --patch <diff> --targets offscreen_check --regex startup_inline_sampler: 3/3 passed (controls, warp, hardware).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181929313 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2708#issuecomment-7181929313). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:40:46Z. --- @MasterDomino Ready for review on head a52f1d75e. Independent gate review of the fold (`s_mov_b32` copy of a plain constant SGPR): tried a branch-arm sampler word, copies of a run-time/placeholder/descriptor source, a 64-bit pair, `vcc` and `m0` sources, and two one-line mutations of the fix (drop the plain-constant guard; copy a wrong value). The first set stays refused or unfolded, both mutations fail `startup_inline_sampler_check.py`. Gap found and closed: only translation controls covered the copy form. `check_draw` now also draws a shader whose sampler word 0 is built in `s29` and copied into `s24`; it must read the clamped texel with its own sampler and mismatch with the wrap sampler (wrong-value control). The branch was also merged with current `main` (no rebase, no force) so it builds on Windows after #2706. Verification: - Linux: `python3 -B tests/startup_inline_sampler_check.py` and `... binary llvm-mc-19` pass; on `origin/main`'s translator the check fails. - Win2025 (dev + release): `x2w_pipe.py win2025 2708 --patch <diff> --targets offscreen_check --regex startup_inline_sampler`: 3/3 passed (controls, warp, hardware). AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 04:04:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:40:44Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T03:46:36.169545Z a52f1d7 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181928847 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2708#issuecomment-7181928847). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T03:40:44Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"a52f1d75e6223a3a29beb627ffa06b35a07c14a7","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-26T03:46:36.169545Z">2026-11-26T03:46:36.169545Z</relative-time> | `a52f1d7` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
MasterDomino commented 2026-11-26 06:01:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T05:34:59Z.

Review: CHANGES_REQUESTED


Reviewed head a52f1d75 (21 commits behind main, merges cleanly).

The fold itself looks right:

  • Only a plain ('const', v) source is copied. The tagged unassigned placeholder, ud, descriptor and unknown sources are not.
  • The value is copied at that point, so a later write to the source can't reach the copy.
  • set_s still assigns the register at run time.
  • At a join, the copy's constant is dropped exactly as a literal move's would be.

Blocking: this needs a shader-cache revision bump. A register copied from a constant now folds at every later read, so programs that already translated emit different HLSL. For example, s_mov_b32 s15, 5; s_mov_b32 s12, s15; s_add_u32 s13, s12, 1 lowers to s13 = s12 + 0x00000001u; on main and to s13 = 0x00000005u + 0x00000001u; here. #2319 bumped the revision for the same kind of change (the s_brev_b32 fold).

Please move to x2w-startup-shader-19 / 19cs (main is at 18 / 18cs) in:

  • gfx2hlsl.py (pipeline_key, compute_key);
  • src/startup_stubs/d3d12_draw.inl (revision, compute_revision);
  • the tests that pin the revision;
  • the revision note in docs/startup-runtime.md.

Moving the slot-57 mesh key is your call.

Non-blocking:

  • Untested run-time write: a one-line mutant that keeps the constant symbol but drops the run-time sD = … write passes every inline-sampler and join check. A case where a join drops the copy's constant and the copy is read afterwards would pin it.
  • Misleading test comment: in check_copy_only_folds_plain_constants, the case commented "A copy after the source was overwritten takes the new value" doesn't overwrite anything.

Environment: Windows 11 build 26300; AMD Radeon RX 9070 XT (driver 32.0.32029.2010); WARP 10.0.26100.9818; debug layer on, 0 errors; dev preset.

Runs and mutants:

  • ctest --preset dev --no-tests=error -R '^startup_inline_sampler|^startup_gfx2hlsl|^startup_image_3d': 256 passed, 0 skipped, 1 failed. The failure is startup_gfx2hlsl_fma_mix_dispatch_hardware, which fails the same way on main on this adapter (#2746), so it's unrelated.
  • A trial merge with main passed the 114 non-GPU checks.
  • Mutants caught by startup_inline_sampler_controls, _warp and _hardware: dropping the plain-constant guard, copying a wrong value, and disabling the fold.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6069038868 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2708#pullrequestreview-6069038868). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-26T05:34:59Z. **Review:** CHANGES_REQUESTED --- Reviewed head `a52f1d75` (21 commits behind `main`, merges cleanly). **The fold itself looks right:** - Only a plain `('const', v)` source is copied. The tagged unassigned placeholder, `ud`, descriptor and unknown sources are not. - The value is copied at that point, so a later write to the source can't reach the copy. - `set_s` still assigns the register at run time. - At a join, the copy's constant is dropped exactly as a literal move's would be. **Blocking: this needs a shader-cache revision bump.** A register copied from a constant now folds at every later read, so programs that already translated emit different HLSL. For example, `s_mov_b32 s15, 5; s_mov_b32 s12, s15; s_add_u32 s13, s12, 1` lowers to `s13 = s12 + 0x00000001u;` on `main` and to `s13 = 0x00000005u + 0x00000001u;` here. #2319 bumped the revision for the same kind of change (the `s_brev_b32` fold). Please move to `x2w-startup-shader-19` / `19cs` (main is at 18 / 18cs) in: - `gfx2hlsl.py` (`pipeline_key`, `compute_key`); - `src/startup_stubs/d3d12_draw.inl` (`revision`, `compute_revision`); - the tests that pin the revision; - the revision note in `docs/startup-runtime.md`. Moving the slot-57 mesh key is your call. **Non-blocking:** - **Untested run-time write:** a one-line mutant that keeps the constant symbol but drops the run-time `sD = …` write passes every inline-sampler and join check. A case where a join drops the copy's constant and the copy is read afterwards would pin it. - **Misleading test comment:** in `check_copy_only_folds_plain_constants`, the case commented "A copy after the source was overwritten takes the new value" doesn't overwrite anything. Environment: Windows 11 build 26300; AMD Radeon RX 9070 XT (driver 32.0.32029.2010); WARP 10.0.26100.9818; debug layer on, 0 errors; dev preset. **Runs and mutants:** - `ctest --preset dev --no-tests=error -R '^startup_inline_sampler|^startup_gfx2hlsl|^startup_image_3d'`: 256 passed, 0 skipped, 1 failed. The failure is `startup_gfx2hlsl_fma_mix_dispatch_hardware`, which fails the same way on `main` on this adapter (#2746), so it's unrelated. - A trial merge with `main` passed the 114 non-GPU checks. - **Mutants caught** by `startup_inline_sampler_controls`, `_warp` and `_hardware`: dropping the plain-constant guard, copying a wrong value, and disabling the fold. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 06:04:43 +00:00
MasterDomino commented 2026-11-26 06:04:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T06:04:16Z.

Review: APPROVED


Approving 2381d5c6; the change request is resolved.

  • Revision bump: x2w-startup-shader-19 / 19cs now appear in gfx2hlsl.py (pipeline_key, compute_key), in d3d12_draw.inl (revision, compute_revision), in the tests that pin the key, and in the revision note in docs/startup-runtime.md.
  • New check: startup_gfx2hlsl_const_copy_join_check pins the run-time write. I replayed the mutant that survived my earlier review, keeping the copy's constant symbol but dropping its run-time sD = … write: it now fails with "FAIL: straight line: the copy is still assigned at run time" (exit 1), and passes again once restored.

Pure-Python checks at this head, all passing (Windows 11 build 26300):

  • startup_gfx2hlsl_const_copy_join_check
  • startup_inline_sampler_check
  • startup_compute_request_offline_check
  • startup_gfx2hlsl_fract_check
  • startup_gfx2hlsl_buffer_store_check
  • startup_shader_cache_key_check

The GPU results from my earlier review (inline sampler WARP and RX 9070 XT) were at a52f1d75; the fold itself is unchanged since then. CI is green at this head.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6069271960 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2708#pullrequestreview-6069271960). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-26T06:04:16Z. **Review:** APPROVED --- Approving `2381d5c6`; the change request is resolved. - **Revision bump:** `x2w-startup-shader-19` / `19cs` now appear in `gfx2hlsl.py` (`pipeline_key`, `compute_key`), in `d3d12_draw.inl` (`revision`, `compute_revision`), in the tests that pin the key, and in the revision note in `docs/startup-runtime.md`. - **New check:** `startup_gfx2hlsl_const_copy_join_check` pins the run-time write. I replayed the mutant that survived my earlier review, keeping the copy's constant symbol but dropping its run-time `sD = …` write: it now fails with "FAIL: straight line: the copy is still assigned at run time" (exit 1), and passes again once restored. Pure-Python checks at this head, all passing (Windows 11 build 26300): - `startup_gfx2hlsl_const_copy_join_check` - `startup_inline_sampler_check` - `startup_compute_request_offline_check` - `startup_gfx2hlsl_fract_check` - `startup_gfx2hlsl_buffer_store_check` - `startup_shader_cache_key_check` The GPU results from my earlier review (inline sampler WARP and RX 9070 XT) were at `a52f1d75`; the fold itself is unchanged since then. CI is green at this head. AI-assisted; commands listed were executed locally.
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!2700
No description provided.