shader: lower gfx1013 compute image_gather4_l on a fixed-mip view #2250
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2258"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-25T08:27:17Z.
Part of #2022.
Change
Item E:
image_gather4_lin the compute translator (tools/compute_store_aot.py), as described in the claim comment. Today the compute path refuses every gather. This change lowers one narrow form and keeps the rest refused by name.image_gather4_lon gfx1013, on theR32G32B32A32_FLOATSRV att0thatimage_load_mipalready uses, with a rawu0output. The caller declares the visible mip count of the matching native and desktop views with--gather-mips <count>(Python:gather_mips=), as the pixel tool does for its gfx1030 gathers.pixel_aot.check_gather_sampler(the profile of #1927 and the pixel gathers): normalized coordinates, clamp-to-edge in X and Y, bilinear XY, point mip, zero LOD bias,MIN_LOD0 andMAX_LODat or above the last visible mip.(0,1), (1,1), (1,0), (0,0)order, through fourLoadcalls at the view-relative mip, likegather_2dinpixel_aot.py. The scaled coordinate is clamped to[-1, size]beforefloor(). With clamp-to-edge this selects the same texels and keeps the float-to-int conversion in range.image_gather4,_lz,_b,_cl,_b_cl,_c_l,_c_lz,_l_o); cube, 2D array, 1D and 3D; NSA;unorm,a16,d16,glc; a non-one-hot DMASK; short destination or address ranges; an unverified or misaligned image descriptor; a non-constant or misaligned sampler; a gather under a lane guard; a second gather; a declared view with no gather; gfx1030; a UINT image; a UAV image output; a mip count outside 1 to 16.v_mov_b32of an inline float. LLVM prints a b32 move of0x3f800000asv_mov_b32_e32 v5, 1.0. The move now accepts the inline float spellings that the translator's float ALU already knows (FLOAT_INLINE). Any other decimal spelling is refused as before (Invalid literal move). Without this, an LOD of 1.0 or 2.0 could not be read.--compute-texture-case) now also accepts the existing RGBA32 FLOAT flag, and a new flag that binds thet0SRV withMostDetailedMip = 1. Existing cases are unchanged.Verification
Windows 11 26200, MSVC 19.44,
devpreset, D3D12 debug layer on, DXC from Windows SDK 10.0.26100.0. Tested commitbed536b6onmain67fcebd1.compute_store_aot_gfx1013_gather4_l_hardwarepassed on NVIDIA GeForce RTX 3070 (10de:2484, driver 32.0.16.2101), andcompute_store_aot_gfx1013_gather4_l_warpon WARP 10.0.26100.9818. No capability skips, anddebug_errors=0 debug_warnings=0on every dispatch. Six programs, 320 words each, all equal to an independent CPU model:MostDetailedMip = 1;word=0 expected=3f100002 actual=3f000002;word=64 expected=3f101002 actual=3f100002;MostDetailedMip = 1program run on the full view: 256 mismatches,word=0 expected=3f200000 actual=3f100000;word=0 expected=c5c5c5c5 actual=3f100002.main1949b265, the fixture stops atUnsupported compute instruction: v_mov_b32_e32 v5, 1.0, and the LOD 0 program atUnsupported compute instruction: image_gather4_l .... I also removed each guard of the lowering in turn: 18 mutants, each turned the check red.python tests/compute_gather4_l_check.py --binary llvm-mc-15 llvm-objcopy-15 --llvm libLLVM-15.so.1. I ran the same mode locally with LLVM 15.0.7: the clang 15 integrated assembler stood in forllvm-mc, withllvm-objcopyandLLVM-C.dllfrom the same release. All six programs assemble for gfx1013. LLVM's disassembly equals the fixture text line for line, the decoded text lowers to the same HLSL, and the synthetic container CLI with--gather-mips 3matches the text lowering.ctest --preset dev --no-tests=error -j 1 -R "compute_" -V: everycompute_store_aot_*test passed (152 of 152). The 10 other failures in that run need targets I had not built (d3d12x_compute_list_check.exe, the startup compute request client,cpu_shim_startup.exe), and each stopped on the missing file.-R "^offscreen_": 4/4. The CPU modes ofcompute_store_check,compute_load_format_check,compute_mimg_float_store_check,compute_mimg_float_store_d16_check,compute_image_atomics_gfx1013_check,compute_mimg_msaa_check,compute_mimg_image_uav_load_checkandcompute_desc_numeric_checkpass. So dodocs_links_check,bidi_controls_checkandgit diff --check.releasepreset. Also not run: AMD and Intel GPUs, a real application dispatch, and Xbox hardware.Evidence and follow-up
The six gfx1013 programs are written for this test, built from text in the test file, and MIT. No game files. Each builds U and V as
0.1875 × id − 0.15for an 8×8 group, from the dispatch-thread ID with integer and binary32 ALU forms the translator already lowers. So the footprints cover both clamped edges, and every scaled coordinate stays at least 1/64 texel away from a tap boundary at each mip used (the model asserts this). Texels are distinct normal binary32 values for every mip, row, column and channel.Semantics:
llvm.amdgcn.image.gather4.l.2dand the assembler syntax.(0,1), (1,1), (1,0), (0,0)order, andLoadandGetDimensionstake view-relative mips.Assumptions: the caller binds matching native and desktop views and declares their mip count. Coordinates must select the same half-texel footprint under native texture-coordinate precision and desktop float arithmetic. Coordinates within 1/256 texel of a tap boundary, NaN payloads and denormal texels are not tested. As the issue says, this is not application coverage until it is used in a real dispatch.
docs/experiments.mddocuments the profile, the refusals and the commands. The test is registered in CMake (compute_store_aot_gfx1013_gather4_l_{hardware,warp}) and in the Ubuntu LLVM 15 job.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T08:30:51Z.
Review: COMMENTED
Review of head
bed536b6dbb39af3aa7fa9ba3a9795c23f6e98ba(comment only, no approval).Scope read:
tools/compute_store_aot.py(gather lowering,GATHER_HLSL,gather_mipsvalidation, float inlinev_mov_b32),tests/compute_gather4_l_check.py,tests/compute_check.cpp, CMake/CI wiring,docs/experiments.md.Commands executed locally (Linux, worktree at the PR head):
git diff --stat origin/main...HEAD: 7 files, +510/-12.python3 tests/compute_gather4_l_check.py:translation controls passed(this mode runs the translation controls only; the llvm-mc and WARP readback modes were not available locally).python3 tests/docs_links_check.py: self-test passed, 18 files, 429 links.python3 tests/bidi_controls_check.py: no bidirectional controls in 1536 files.git diff --check origin/main...HEAD: clean.git checkout -- .:< gather_mipschanged to<= gather_mips: killed (Expected rejection: known integer LOD inside the view).0u: killed by the translation controls.-1.0fchanged to-4.0f: survives, but this is an equivalent mutant. After+1and theclamp(.., 0, edge)the selected texels are the same. Not a test gap.Findings
--draw). On Linux only the string-level controls run. The PR therefore depends on the Windows CI jobs (Assemble and translate gfx1013 fixtures,Build and test on Windows), which were still pending when I looked. Please wait for those to be green before Ready.-0.5foffset and the "keep coordinates off tap boundaries" caveat are documented indocs/experiments.md. It would help to also say in thelower()docstring that this is a caller guarantee and is not checked in the translator.isfiniteearly return is appended after all other staged steps, so any earlier staged step with a side effect would still run. Today staged steps are pure loads, so this is fine. A short comment would protect it from later changes.Checked and fine: the gather mask is one-hot only and other
image_gather4*forms are refused by name. The sampler goes through the sharedpixel_aot.check_gather_sampler. The LOD must be a known integral float inside the view.gather_mipsis validated as an int from 1 to 16 and requires exactly one gather. The result order (0,1), (1,1), (1,0), (0,0) matchesgather_2dinpixel_aot.py. Title and body are neutral. The PR is mergeable.AI-assisted; commands listed were executed locally.