shader: lower explicit-LOD 2D image_gather4_l in gfx2hlsl #2307
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2315"
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 Vladimir-Human on 2026-11-25T11:58:38Z.
Refs #1802
Lower gfx1013 explicit-LOD 2D non-comparison
image_gather4_lacross pixel and compute stages intools/startup/gfx2hlsl.py.Semantics and design
AMDGPUMIMG0x44,dim:SQ_RSRC_IMG_2D):image_gather4_ltakes four destination VGPRs, three contiguous address VGPRs (u, v, lod), an 8-register image descriptor, a 4-register constant sampler, and a one-hot componentdmask(0x1/0x2/0x4/0x8).Stage.gather_2d_setup): shares 2D gather setup withop_image_gather4_lz, validates constant sampler words viapixel_aot.check_gather_sampler(CLAMP_LAST_TEXELin X/Y, normalized coordinates, zeroMIN_LOD, point mip filter, zero bias, non-anisotropic XY), and keepsMIP_POINT_PRECLAMP(word 2 bit 28; Mesagfx10-rsrc.jsonSQ_IMG_SAMP_WORD2) refused for_l. Compute stages enforceself.fixed_table_image(ops[2], name)(8-word fixed-table unmodified descriptor checks).gather_2d_lod): D3D12 SM 5.1/6.0Gather*only reads view mip zero (D3D11.3 functional spec §22.4.2), sogather_2d_lodchecksuvandlodfiniteness bitwise, queries view levels viaGetDimensions, clampslodto[0, MAX_LOD](sampler word 1 bits23:12,u4.8) and rounds (floor(lod + 0.5f)) within[0, levels - 1], and loads the four(0,1), (1,1), (1,0), (0,0)taps clamped to mip bounds. Non-finite inputs return zero without corrupting surrounding lanes/words._c_l,_b,_l_o, non-2D dims, non-one-hotdmask,a16,d16,tfe,unorm,r128,lwe, NSA addresses, out-of-bounds register ranges, non-constant/invalid samplers, and modified/unaligned/aliasedcsimage descriptors.Verification (rebased commit
85f7cda9on209938b0). .\tools\dev.ps1; cmake --preset release; cmake --build --preset release --target offscreen_checkctest --preset release --no-tests=error -j 1 -R "^startup_(compute_gather_l|compute_gather_lz|image_gather_lz|image_gather_c_lz|image_sample_l|compute_image_store_d16)(_warp|_hardware)?$" -V): 16/16 passed (0 skipped), includingstartup_compute_gather_l,startup_compute_gather_l_warp, andstartup_compute_gather_l_hardware:Microsoft Basic Render Driver(1414:008c, driver10.0.26100.9818, Windows Build26300.9974(26H2),debug_layer=enabled,debug_errors=0 debug_warnings=0) — 13 positive compute cases (mip0_red..sampler_max_lod_0), 2 NaN cases, 4-lane dynamic LOD (cs_6_0), 6 compute mutants (dropped_gather,wrong_component,forced_mip_zero,wrong_first_mip,wrong_tap_order,ignored_max_lod), 2 pixel draws (DXC ps_6_0+FXC ps_5_1 /WX), and 1 pixel mutant (forced_mip_zero) all passed (compared_words=320 mismatches=0, mutants failed as predicted).NVIDIA GeForce RTX 4070 SUPER(10de:2783, driver32.0.16.2114, Windows Build26300.9974(26H2),debug_layer=enabled,debug_errors=0 debug_warnings=0) — identical full suite passed (0debug errors/warnings, all mutants failed as predicted).ctest --preset release --no-tests=error -j 1 -R "^startup_gfx2hlsl_compute"): 13/13 passed (0 skipped).tests/docs_links_check.py,tests/bidi_controls_check.py,tests/startup_tools_lint_check.py,tests/startup_translator_check.py,tests/startup_compute_gather_l_check.py,tests/startup_image_gather_lz_check.py,tests/startup_compute_gather_lz_check.py,tests/startup_image_sample_l_check.py,tests/startup_compute_image_store_d16_check.py,tests/startup_image_gather_c_lz_check.py,tests/startup_gfx2hlsl_refusals_check.py,tests/startup_gfx2hlsl_handler_arity_check.py,tests/startup_gfx2hlsl_compute_check.py,tests/startup_compute_translate_check.py,tests/startup_gfx2hlsl_b64_shift_check.py,tests/compute_gather4_l_check.py,tests/form_coverage_check.py,tests/shader_census_check.py): all passed.llvm-mc-15is not installed on Windows, so--llvm-mcassembly round-trip was not executed locally (cross-checked viatools/disasm_rdna2.pyand wired into.github/workflows/windows.ymlpixel-binary).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:00:42Z.
Review: COMMENTED
Review of head
85f7cda962acbb215ceeb7a3299de337edcbc5a0(comment only, no approval).Summary: No P1. Two P2 and two nits. The lowering looks right. Tap order
(0,1),(1,1),(1,0),(0,0)matches D3D Gather. The_lopcode is refused for MIP_POINT_PRECLAMP. Non-finite inputs return zero. The mip is clamped to the view levels. CI Windows jobs were still pending when I looked.Commands run locally (Linux, in a worktree at the head SHA):
git diff --stat origin/main...HEAD: 7 files, +532/-12python3 -B tests/startup_compute_gather_l_check.py: "image_gather4_l compute and pixel controls passed"python3 -B tests/startup_image_gather_lz_check.py: passedpython3 -B tests/startup_compute_gather_lz_check.py: passedpython3 tests/docs_links_check.py: 448 links okpython3 tests/bidi_controls_check.py: no bidi controlsgit diff --check origin/main...HEAD: cleanMutations (each reverted with
git checkout -- .):gfx2hlsl.pygather_2d_setup): killed by the Linux test.(0,1)to(1,1),floor(lod+0.5)tofloor(lod), and removing the lod non-finite guard: all three SURVIVE on Linux. The Linux run has no--dispatch, so only string and refusal checks run. The--dispatchlist does have cases for each (frac_lod_down/up,nan_lod, tap compare viareference()), so they should die on Windows. I did not run the Windows pipeline. I am relying on the pending CI jobs "Build and test on Windows" and "Assemble and translate gfx1013 fixtures", and I did not see them finish.Findings
tools/startup/gfx2hlsl.py(gather_2d_lodhelper): the mip is chosen by round-to-nearestfloor(lod + 0.5), matching the point-mip-filter rule. That is a D3D-spec-based choice and is not measured on console hardware.docs/experiments.mddoes not say so. Please state it as unmeasured, as the siblinggather_2d_profile_wordsdocstring does.tests/startup_compute_gather_l_check.py: the Linux-only path is string-based for the rounding, tap order and non-finite guard. Those behaviors are only protected when--dispatchruns (WARP/hardware CTest). Make sure a Windows WARP run passes before moving to Ready.tools/startup/gfx2hlsl.py:uses_gather_2d_lod = Falseis set on the class and again in both__init__methods. One place is enough.tests/startup_image_gather_lz_check.py: the comment says_lis lowered "by their own tests". Namestartup_compute_gather_l_check.pyfor clarity.Clean-room: the description cites public ISA and spec sources only. Title is neutral. The PR is mergeable.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:43:09Z.
Review: COMMENTED
Review of head
86ad18d189139549fed727c639d68640dd9211a7(PR #2315).Scope read:
tools/startup/gfx2hlsl.py(gather_2d_setup,op_image_gather4_lzrefactor,op_image_gather4_l,gather_2d_lodhelper emit),tests/startup_compute_gather_l_check.py, CMake/CI wiring, docs.Commands executed locally
git diff --stat origin/main...HEAD: 7 files, +532/-12.git diff --check origin/main...HEAD: clean.python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 452 links.python3 tests/bidi_controls_check.py: self-test passed, 1616 files, no bidi controls.python3 tests/startup_compute_gather_l_check.py: "image_gather4_l compute and pixel controls passed".python3 tests/startup_image_gather_lz_check.py: passed (the_lzrefactor intogather_2d_setupkeeps its behaviour).x2w_pipe.py win2025 2315 --regex 'startup_(compute|image)_gather' --skip-release-> 12/12 passed, includingstartup_compute_gather_l,startup_compute_gather_l_warp,startup_compute_gather_l_hardware, and the existing_lz/_c_lzsiblings (no regression). Release preset not run.gh pr checks): Windows build/test and Linux Python checks pass; "Assemble and translate gfx1013 fixtures" was still pending when I looked. PR is mergeable, title is neutral.Mutation check (Linux)
floor(lod+0.5)->floor(lod)) and swapped one gather tap in the emitted HLSL. The Linux-only run of the check still passed in both cases. The Linux run only translates and string-checks the source. The numeric proof is the Windows WARP/hardware readback. I did not re-run these mutants on Win2025, so I can't say the readback kills them.Findings
tests/startup_compute_gather_l_check.py): the GPU readback (--dispatch) covers the compute stage only. The pixel stage is checked at translate level only, although both use the samegather_2d_lodhelper. A pixel--drawreadback case would close that gap. Not blocking, since the helper is shared.tools/startup/gfx2hlsl.py,gather_2d_setup):MIP_POINT_PRECLAMPis refused by OR-ing bit 28 into the profile words just for the_lpath. A short comment on why this is refused for_land not for_lzwould help the next reader. The PR body already cites the source.Semantics: address count (3 for u, v, lod), one-hot dmask, tap order (0,1), (1,1), (1,0), (0,0), NaN/Inf lanes returning zero, MAX_LOD clamp (u4.8) and clamping to view levels all match the PR description and the intended gather behaviour.
AI-assisted; commands listed were executed locally.