shader: lower constant-lane SGPR spills in gfx2hlsl pixel stages (Part of #2125) #2171

Manually merged
github merged 3 commits from gh-pr/2171/head into gh-pr/2171/base 2026-11-27 00:02:37 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-25 02:39 UTC · original
tedin7:x2w-2125e-pixel-sgpr-spill → main · +362 −0 · 6 files · 3 commits · merged 2026-11-25 07:17 UTC

Part of #2125

What this unblocks: pixel programs that park SGPRs in VGPR lanes (v_writelane_b32 vN, sM, k ... v_readlane_b32 sD, vN, k, constant k) now translate (item E).

What changed

  • tools/startup/gfx2hlsl.py: one scalar slot per (VGPR, lane). Both instructions ignore EXEC and touch only lane k, so with a constant k and a VGPR no other instruction names, no cross-lane read needs modelling. A constant value reloads as a constant.
  • Refused with a reason: lane from an SGPR, lane > 31, VGPR also used as a vector or in a register range, read of an unwritten slot, branches, lane mask / m0 / modifier on the value, non-SGPR destination, vertex stage.
  • tests/startup_gfx2hlsl_sgpr_spill_check.py: Python controls, binary assembler check, and a 16 x 16 D3D12 draw compared with an integer reference; four wrong lowerings must read a different image.
  • CMake tests startup_gfx2hlsl_sgpr_spill_{controls,warp,hardware}, CI list, AGENTS.md, docs/experiments.md.

Semantics: AMD RDNA 2 ISA reference (VOP3 lane operations); LLVM 15 AMDGPU.

Verification:

  • Linux: python3 -I -B tests/startup_gfx2hlsl_sgpr_spill_check.py -> PASS; ... binary llvm-mc -> PASS (LLVM 19 locally)
  • Linux: docs_links_check, startup_translator_check, readfirstlane_uniform, dpp_quad_swap, swap, refusals, handler_arity -> pass
  • Win2025 (Build 26100, MSVC 14.44, D3D12 WARP) at 2a111e5e: ctest --preset dev and ctest --preset release with -R 'startup_gfx2hlsl_sgpr_spill_|startup_gfx2hlsl_dpp_quad_swap_|startup_gfx2hlsl_swap' --parallel 3 --no-tests=error -> 7/7 passed on each, zero skips

Note: #2032 also adds an op_v_readlane_b32 (uniform-source form); whichever lands second needs a small merge.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 02:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2171) `tedin7:x2w-2125e-pixel-sgpr-spill` → `main` · +362 −0 · 6 files · 3 commits · merged 2026-11-25 07:17 UTC Part of #2125 What this unblocks: pixel programs that park SGPRs in VGPR lanes (`v_writelane_b32 vN, sM, k` ... `v_readlane_b32 sD, vN, k`, constant k) now translate (item E). ## What changed - `tools/startup/gfx2hlsl.py`: one scalar slot per (VGPR, lane). Both instructions ignore EXEC and touch only lane k, so with a constant k and a VGPR no other instruction names, no cross-lane read needs modelling. A constant value reloads as a constant. - Refused with a reason: lane from an SGPR, lane > 31, VGPR also used as a vector or in a register range, read of an unwritten slot, branches, lane mask / m0 / modifier on the value, non-SGPR destination, vertex stage. - `tests/startup_gfx2hlsl_sgpr_spill_check.py`: Python controls, `binary` assembler check, and a 16 x 16 D3D12 draw compared with an integer reference; four wrong lowerings must read a different image. - CMake tests `startup_gfx2hlsl_sgpr_spill_{controls,warp,hardware}`, CI list, AGENTS.md, docs/experiments.md. Semantics: AMD RDNA 2 ISA reference (VOP3 lane operations); LLVM 15 AMDGPU. Verification: - Linux: `python3 -I -B tests/startup_gfx2hlsl_sgpr_spill_check.py` -> PASS; `... binary llvm-mc` -> PASS (LLVM 19 locally) - Linux: docs_links_check, startup_translator_check, readfirstlane_uniform, dpp_quad_swap, swap, refusals, handler_arity -> pass - Win2025 (Build 26100, MSVC 14.44, D3D12 WARP) at 2a111e5e: `ctest --preset dev` and `ctest --preset release` with `-R 'startup_gfx2hlsl_sgpr_spill_|startup_gfx2hlsl_dpp_quad_swap_|startup_gfx2hlsl_swap' --parallel 3 --no-tests=error` -> 7/7 passed on each, zero skips Note: #2032 also adds an `op_v_readlane_b32` (uniform-source form); whichever lands second needs a small merge. AI-assisted; commands listed were executed locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:02:36 +00:00
github manually merged commit e0f6587354 into gh-pr/2171/base 2026-11-27 00:02:37 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 02:59 UTC · original

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 2a111e5e6d518302dc6ace1ed55b2b4beee8dfb8:

  • Build: cmake --build --preset dev --target offscreen_check -- -j 4
  • Test: ctest --preset dev -R '^startup_gfx2hlsl_sgpr_spill_(controls|warp)$' --parallel 3 --no-tests=error --output-on-failure -> 2/2 passed (DXC and FXC ps_5_1 draws, 256 pixels each, all four wrong-lowering controls fail as required)
  • tests/startup_gfx2hlsl_sgpr_spill_check.py -> ok

The first Win2025 run (31df9f30) caught one control that did not bite: a constant slot folds into the export, so the lane mutation had no effect. Fixed in 2a111e5e by mutating the folded word.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 02:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2171#issuecomment-7151479442) Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `2a111e5e6d518302dc6ace1ed55b2b4beee8dfb8`: - Build: `cmake --build --preset dev --target offscreen_check -- -j 4` - Test: `ctest --preset dev -R '^startup_gfx2hlsl_sgpr_spill_(controls|warp)$' --parallel 3 --no-tests=error --output-on-failure` -> 2/2 passed (DXC and FXC ps_5_1 draws, 256 pixels each, all four wrong-lowering controls fail as required) - `tests/startup_gfx2hlsl_sgpr_spill_check.py` -> ok The first Win2025 run (31df9f30) caught one control that did not bite: a constant slot folds into the export, so the lane mutation had no effect. Fixed in 2a111e5e by mutating the folded word. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 03:12 UTC · original · edited 2026-11-25 03:17 UTC

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-25T03:17:13.631750Z 2a111e5 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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 03:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2171#issuecomment-7151688864) · edited 2026-11-25 03:17 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"2a111e5e6d518302dc6ace1ed55b2b4beee8dfb8","has_any_findings":true,"has_unresolved_findings":true,"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-25T03:17:13.631750Z">2026-11-25T03:17:13.631750Z</relative-time> | `2a111e5` | 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>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 03:17 UTC · original

P2 Badge Accept numeric fixed-buffer words as spill sources

When an SGPR comes directly from s_buffer_load_dword* with an immediate offset, the existing load handler tags it as ('fixed_buffer_word',). This whitelist rejects that ordinary numeric value as a lane mask or descriptor, even though S() and uniform_source() already support it. Consequently, a load/spill/reload sequence satisfying the straight-line pixel-stage restrictions still fails translation. I reproduced this with assembled gfx1013 code; replacing the immediate zero offset with an SGPR containing zero, or inserting s_or_b32 s0, s0, 0 after the load, makes it translate. Include fixed_buffer_word among the numeric spill-source tags and add a memory-loaded spill control.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 03:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2171#discussion_r4689945211) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Accept numeric fixed-buffer words as spill sources** When an SGPR comes directly from `s_buffer_load_dword*` with an immediate offset, the existing load handler tags it as `('fixed_buffer_word',)`. This whitelist rejects that ordinary numeric value as a lane mask or descriptor, even though `S()` and `uniform_source()` already support it. Consequently, a load/spill/reload sequence satisfying the straight-line pixel-stage restrictions still fails translation. I reproduced this with assembled gfx1013 code; replacing the immediate zero offset with an SGPR containing zero, or inserting `s_or_b32 s0, s0, 0` after the load, makes it translate. Include `fixed_buffer_word` among the numeric spill-source tags and add a memory-loaded spill control. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 03:32 UTC · original

Fixed in 59f23fb5: fixed_buffer_word is now accepted as a numeric spill source in op_v_writelane_b32, and startup_gfx2hlsl_sgpr_spill_check.py has a control for a buffer word loaded at an immediate offset (fails before, passes after).

Verification:

  • Linux: python3 -B tests/startup_gfx2hlsl_sgpr_spill_check.py PASS (control FAILs with the old whitelist); docs_links_check, startup_gfx2hlsl_refusals_check, startup_gfx2hlsl_handler_arity_check, startup_gfx2hlsl_smem_offset_check, startup_gfx2hlsl_scalar_m0_check, mesh_lane_spill_check, startup_gfx2hlsl_readfirstlane_uniform_check all PASS.
  • Win2025 WARP, dev and release: startup_gfx2hlsl_sgpr_spill_(controls|warp) 2/2 passed each.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 03:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2171#discussion_r4690042948) Fixed in 59f23fb5: `fixed_buffer_word` is now accepted as a numeric spill source in `op_v_writelane_b32`, and `startup_gfx2hlsl_sgpr_spill_check.py` has a control for a buffer word loaded at an immediate offset (fails before, passes after). Verification: - Linux: `python3 -B tests/startup_gfx2hlsl_sgpr_spill_check.py` PASS (control FAILs with the old whitelist); `docs_links_check`, `startup_gfx2hlsl_refusals_check`, `startup_gfx2hlsl_handler_arity_check`, `startup_gfx2hlsl_smem_offset_check`, `startup_gfx2hlsl_scalar_m0_check`, `mesh_lane_spill_check`, `startup_gfx2hlsl_readfirstlane_uniform_check` all PASS. - Win2025 WARP, dev and release: `startup_gfx2hlsl_sgpr_spill_(controls|warp)` 2/2 passed each. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-25 05:43 UTC · original

Ran head 59f23fb5 on three adapters. All pass. Windows 11 build 26100, debug layer unavailable, DXC and FXC from SDK 10.0.26100.0.

Test Adapter Driver Result
startup_gfx2hlsl_sgpr_spill_controls n/a n/a pass
startup_gfx2hlsl_sgpr_spill_warp Microsoft Basic Render Driver 10.0.26100.8972 pass
startup_gfx2hlsl_sgpr_spill_hardware (XBOX2WINDOWS_ADAPTER=Quadro) NVIDIA Quadro M1000M (Maxwell) 32.0.15.7371 pass
startup_gfx2hlsl_sgpr_spill_hardware (XBOX2WINDOWS_ADAPTER=Intel) Intel HD Graphics 530 (Gen9) 31.0.101.2111 pass

On each adapter all 33 checks printed ok, including hardware dxc: all 256 pixels equal the slot reference and the same line for fxc. The hardware draws do not print the adapter line; I selected the adapter with XBOX2WINDOWS_ADAPTER, the same way the other draws report it.

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-25 05:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2171#issuecomment-7154073915) Ran head `59f23fb5` on three adapters. All pass. Windows 11 build 26100, debug layer unavailable, DXC and FXC from SDK 10.0.26100.0. | Test | Adapter | Driver | Result | |---|---|---|---| | `startup_gfx2hlsl_sgpr_spill_controls` | n/a | n/a | pass | | `startup_gfx2hlsl_sgpr_spill_warp` | Microsoft Basic Render Driver | 10.0.26100.8972 | pass | | `startup_gfx2hlsl_sgpr_spill_hardware` (`XBOX2WINDOWS_ADAPTER=Quadro`) | NVIDIA Quadro M1000M (Maxwell) | 32.0.15.7371 | pass | | `startup_gfx2hlsl_sgpr_spill_hardware` (`XBOX2WINDOWS_ADAPTER=Intel`) | Intel HD Graphics 530 (Gen9) | 31.0.101.2111 | pass | On each adapter all 33 checks printed ok, including `hardware dxc: all 256 pixels equal the slot reference` and the same line for fxc. The hardware draws do not print the adapter line; I selected the adapter with `XBOX2WINDOWS_ADAPTER`, the same way the other draws report it. _AI-assisted._
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 03:17 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2a111e5e6d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 03:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2171#pullrequestreview-6051341919) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `2a111e5e6d` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
This discussion has been locked. Commenting is limited to contributors.
No description provided.