Repository navigation
gfx2hlsl: lower compute image_gather4_lz_o with signed 6-bit NSA offsets - #3884
Conversation
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>
R0Y00
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
Summary
Adds
op_image_gather4_lz_oto the Python compute translator (tools/startup/gfx2hlsl.py) to unblock the highest-weight compute image refusal class (image_gather4_lz_oacross 2D shadow/sampling compute shaders).tools/startup/gfx2hlsl.py): Extendsgather_2d_setupwithnsa=Trueto parse bracketed[vOFF, vU, vV]operands (verifying single distinct VGPRs per entry), unpacks the two signed 6-bit offsetssx = asint(vOFF << 26) >> 26andsy = asint(vOFF << 18) >> 26matching the native C++ lowering (src/gfx1013_direct_compute.inl), and emitstex.Gather{Red,Green,Blue,Alpha}(smp, float2(u, v), int2(sx, sy))forcs_6_0.raw_code[pc]) to refuse unprintedLWE,R128,TFE,A16/D16, and bit-14 flags alongsideunorm/d16modifiers, non-NSA addresses, non-one-hotdmask, non-2D dimensions, duplicate address registers, and unsupported gather samplers.tests/startup_compute_gather_lz_offset_check.py,CMakeLists.txt,.github/workflows/windows.yml): Covers all four one-hot channels, boundary offsets (31,-32), overlappingdst/address registers,image_gather4_lzregression, refusal controls, real DXC compilation (--compile), GPU dispatch (--dispatchwithdropped_offsetmutation control), and--cachedry-run.Verification
python -B tests/startup_compute_gather_lz_offset_check.py(controls,--llvm-mc,--compile, and--dispatchGPU verification — pass; reverting the raw MIMG bit guard fails the negative control)python -B tests/startup_compute_gather_lz_check.py— passpython -B tests/startup_gfx2hlsl_compute_check.py— passpython -B tests/docs_links_check.py,tests/bidi_controls_check.py,tests/script_state_check.py, andtests/form_coverage_check.py— pass