Skip to content

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

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
Holastor:dxil/compute-image-ops
Dec 2, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
Holastor:dxil/compute-image-ops

Conversation

@Holastor

@Holastor Holastor commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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, R0Y00#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 <noreply@anthropic.com>
@Holastor
Holastor marked this pull request as draft December 2, 2026 19:35

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I checked the two failing jobs on b30c04a3. The Python job hit the shared standin_exports: d3d12_xs entries 84 != 83 mismatch corrected by #3885. 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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

@Holastor
Holastor marked this pull request as ready for review December 2, 2026 21:00
@R0Y00
R0Y00 merged commit 70d2679 into R0Y00:main Dec 2, 2026
5 checks passed
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.

2 participants