gfx2hlsl: lower compute image_gather4_lz_o with signed 6-bit NSA offsets #3886

Manually merged
github merged 3 commits from github-bot/gh-3884 into gh-pr/3884/base 2026-12-02 21:05:13 +00:00 AGit
Owner

@⁠Holastor on GitHub · 2026-12-02 19:28 UTC · original
Holastor:dxil/compute-image-ops → main · +277 −9 · 4 files · 3 commits · merged 2026-12-02 21:01 UTC

Summary

Adds op_image_gather4_lz_o to the Python compute translator (tools/startup/gfx2hlsl.py) to unblock the highest-weight compute image refusal class (image_gather4_lz_o across 2D shadow/sampling compute shaders).

  • NSA offset unpacking & HLSL emission (tools/startup/gfx2hlsl.py): Extends gather_2d_setup with nsa=True to parse bracketed [vOFF, vU, vV] operands (verifying single distinct VGPRs per entry), unpacks the two signed 6-bit offsets sx = asint(vOFF << 26) >> 26 and sy = asint(vOFF << 18) >> 26 matching the native C++ lowering (src/gfx1013_direct_compute.inl), and emits tex.Gather{Red,Green,Blue,Alpha}(smp, float2(u, v), int2(sx, sy)) for cs_6_0.
  • Strict MIMG & sampler guards: Validates raw MIMG instruction words (raw_code[pc]) to refuse unprinted LWE, R128, TFE, A16/D16, and bit-14 flags alongside unorm/d16 modifiers, non-NSA addresses, non-one-hot dmask, non-2D dimensions, duplicate address registers, and unsupported gather samplers.
  • Test suite & CI wiring (tests/startup_compute_gather_lz_offset_check.py, CMakeLists.txt, .github/workflows/windows.yml): Covers all four one-hot channels, boundary offsets (31, -32), overlapping dst/address registers, image_gather4_lz regression, refusal controls, real DXC compilation (--compile), GPU dispatch (--dispatch with dropped_offset mutation control), and --cache dry-run.

Verification

  • python -B tests/startup_compute_gather_lz_offset_check.py (controls, --llvm-mc, --compile, and --dispatch GPU verification — pass; reverting the raw MIMG bit guard fails the negative control)
  • python -B tests/startup_compute_gather_lz_check.py — pass
  • python -B tests/startup_gfx2hlsl_compute_check.py — pass
  • python -B tests/docs_links_check.py, tests/bidi_controls_check.py, tests/script_state_check.py, and tests/form_coverage_check.py — pass
**@⁠Holastor** on GitHub · 2026-12-02 19:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3884) `Holastor:dxil/compute-image-ops` → `main` · +277 −9 · 4 files · 3 commits · merged 2026-12-02 21:01 UTC ## Summary Adds `op_image_gather4_lz_o` to the Python compute translator (`tools/startup/gfx2hlsl.py`) to unblock the highest-weight compute image refusal class (`image_gather4_lz_o` across 2D shadow/sampling compute shaders). - **NSA offset unpacking & HLSL emission (`tools/startup/gfx2hlsl.py`):** Extends `gather_2d_setup` with `nsa=True` to parse bracketed `[vOFF, vU, vV]` operands (verifying single distinct VGPRs per entry), unpacks the two signed 6-bit offsets `sx = asint(vOFF << 26) >> 26` and `sy = asint(vOFF << 18) >> 26` matching the native C++ lowering (`src/gfx1013_direct_compute.inl`), and emits `tex.Gather{Red,Green,Blue,Alpha}(smp, float2(u, v), int2(sx, sy))` for `cs_6_0`. - **Strict MIMG & sampler guards:** Validates raw MIMG instruction words (`raw_code[pc]`) to refuse unprinted `LWE`, `R128`, `TFE`, `A16`/`D16`, and bit-14 flags alongside `unorm`/`d16` modifiers, non-NSA addresses, non-one-hot `dmask`, non-2D dimensions, duplicate address registers, and unsupported gather samplers. - **Test suite & CI wiring (`tests/startup_compute_gather_lz_offset_check.py`, `CMakeLists.txt`, `.github/workflows/windows.yml`):** Covers all four one-hot channels, boundary offsets (`31`, `-32`), overlapping `dst`/address registers, `image_gather4_lz` regression, refusal controls, real DXC compilation (`--compile`), GPU dispatch (`--dispatch` with `dropped_offset` mutation control), and `--cache` dry-run. ## Verification - `python -B tests/startup_compute_gather_lz_offset_check.py` (controls, `--llvm-mc`, `--compile`, and `--dispatch` GPU verification — pass; reverting the raw MIMG bit guard fails the negative control) - `python -B tests/startup_compute_gather_lz_check.py` — pass - `python -B tests/startup_gfx2hlsl_compute_check.py` — pass - `python -B tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `tests/script_state_check.py`, and `tests/form_coverage_check.py` — pass
The non-sequential address lists [vOFF, vU, vV]; vOFF packs the signed
six-bit texel offsets in bits [5:0] and [13:8], sign-extended into the
int2 offset of Texture2D.Gather*, the same unpacking as the direct C++
lowering (gfx1013_direct_compute.inl, #3319). gather_2d_setup gains an
nsa form that checks the register list; the modifier bits the
disassembler does not print are checked in the words. DXC cs_6_0 takes
the per-lane offset, so vOFF stays a VGPR.

Every cached gather4_lz_o request now passes the op (four of the five
still stop earlier on unrelated SDWA and execz forms), and the fully
lowered 34623b0c85ffe77b compiles through dxc.

Co-Authored-By: Claude <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 19:43:15 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 20:26 UTC · original · reviewed

I checked the two failing jobs on b30c04a3. The Python job hit the shared standin_exports: d3d12_xs entries 84 != 83 mismatch corrected by #3887. The LLVM 15 job also has an independent failure: tests/startup_compute_gather_lz_offset_check.py --llvm-mc llvm-mc-15 asserts on the Red instruction byte sequence. Please refresh from main and reproduce that command with LLVM 15 so we can preserve the machine-code control while making it portable.

**@⁠R0Y00** on GitHub · 2026-12-02 20:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3884#pullrequestreview-6158356861) · **reviewed** I checked the two failing jobs on `b30c04a3`. The Python job hit the shared `standin_exports: d3d12_xs entries 84 != 83` mismatch corrected by #3887. The [LLVM 15 job](https://github.com/R0Y00/Xbox2Windows/actions/runs/46952247811/job/143716568204) also has an independent failure: `tests/startup_compute_gather_lz_offset_check.py --llvm-mc llvm-mc-15` asserts on the Red instruction byte sequence. Please refresh from main and reproduce that command with LLVM 15 so we can preserve the machine-code control while making it portable.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 20:53 UTC · original · approved these changes

Reviewed 84e61a59. The LLVM 15 failure was an instruction order mismatch at +0x38: the pinned bytes wait for LGKM before writing v6, while the source string wrote v6 before the wait. The follow-up aligns the source with the pinned bytes; the lowering is unchanged. LLVM 15 now reassembles the fixture exactly, the existing flag refusals pass, and DXC compiles the translated cs_6_0 shaders. With the debug layer enabled on Windows 11 build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 each passed all 32 two-mip/channel/offset cases; dropping the offset gave four mismatches. A separate source-built four-thread fixture derived the offset from the lane and wrote each lane's four words to its own output slot. It matched all 320 words on each adapter, and forcing a zero offset caused 12 mismatches on each.

**@⁠R0Y00** on GitHub · 2026-12-02 20:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3884#pullrequestreview-6158830841) · **approved these changes** Reviewed `84e61a59`. The LLVM 15 failure was an instruction order mismatch at +0x38: the pinned bytes wait for LGKM before writing v6, while the source string wrote v6 before the wait. The follow-up aligns the source with the pinned bytes; the lowering is unchanged. LLVM 15 now reassembles the fixture exactly, the existing flag refusals pass, and DXC compiles the translated cs_6_0 shaders. With the debug layer enabled on Windows 11 build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 each passed all 32 two-mip/channel/offset cases; dropping the offset gave four mismatches. A separate source-built four-thread fixture derived the offset from the lane and wrote each lane's four words to its own output slot. It matched all 320 words on each adapter, and forcing a zero offset caused 12 mismatches on each.
github-bot changed target branch from main to gh-pr/3884/base 2026-12-02 21:05:12 +00:00
github manually merged commit 84e61a5919 into gh-pr/3884/base 2026-12-02 21:05:13 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.