feat: image_gather4 compare, bias and clamp forms in the RDNA 2 interpreter and HLSL — 1,303/1,490 #343
No reviewers
Labels
No labels
accessibility
bloqué : binaire console
bug
chargeur
console-dll
cpu
documentation
duplicate
enhancement
good first issue
gpu
help wanted
invalid
performance
question
runtime-gdk
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LooperSalty--AnyXboxX!343
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-343"
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?
@KainanP on GitHub · 2026-11-26 10:02 UTC · original
KainanP:feat/mimg-gather-compare→main· +691 −22 · 18 files · 5 commits · merged 2026-11-26 15:57 UTCChange
The reference interpreter and the HLSL recompiler now run 18 MIMG gather encodings that until now raised
Untranslated/Untranslatable:GatherCmp)image_gather4_c,_c_lz,_c_l,_c_o,_c_lz_o,_c_l_oz_ref <func> texel.R, not filtered, in gather order(x0, y1), (x1, y1), (x1, y0), (x0, y0);func= S# DEPTH_COMPARE_FUNCimage_gather4_c_cl,_c_b,_c_b_cl,_c_cl_o,_c_b_o,_c_b_cl_oimage_gather4_cl,_b,_b_cl,_cl_o,_b_o,_b_cl_oimage_gather4[_o]: the dmask component after DST_SELWhy this family and not image load/store. On
origin/main(c4c93bd),image_load,image_load_mip,image_store,image_store_mipandimage_get_resinfoalready run (rdna2_exec_image.py, the 6 formats ofrdna2_image.py), and the_pck/_pck_sgnopcodes are not in the LLVM-generated table, so they cannot move the count;image_atomic_*is in #309. The remaining well-documented MIMG family that fits the existing one-level 2D image model is the gather family above. (The DS*_src2_*ops were also considered and dropped: the RDNA 2 ISA no longer documents them.){ offset } { bias } { z-compare } { s, t } { lod or clamp }, consecutive VGPRs or NSA. The counts equal LLVM'sgetAddrSizeMIMGOp(port inrdna2_operands_mimg.py), checked for the 18 names in a test.BASE_LEVEL = LAST_LEVEL = 0, as everywhere inrdna2_image.py). The LOD only selects the mip level, so bias, clamp and lod cannot change the result;image_gather4_lalready relies on this. A gather does not filter, so the S# filters do not matter either.z_refand of the texel) flush to zero,-0 == +0, a NaN is unordered (NOT_EQUALtrue, the other ordered functions false;NEVER/ALWAYSconstant). No float compare runs on the GPU, so the result does not depend on the driver's denormal mode._ooffsets are those ofimage_gather4, reused (bilinear_axis,clamp_index,fetch_texelin the interpreter;ImageBilinearAxis,ImageClamp,ImageFetch,ImageGather4in HLSL).Refused by name (rule 3), interpreter and HLSL for instruction fields, interpreter for descriptors:
dmaskother than0x1with compare (the compared component is R); anydmaskthat is not one bit; T#DST_SEL_Xother than R with compare; T#BC_SWIZZLE≠ 0 and S#TRUNC_COORD= 1 (not modelled); plus everythingrdna2_image.pyalready refuses (dimension other than 2D,r128/tfe/lwe/a16/d16, mip levels, formats, anisotropic filtering, half-border clamp modes, non-standard border colours). The neighboursimage_sample_b,image_gather4h,image_get_lodstay refused (a test keeps them named).New files:
emu/rdna2_exec_gather.py(interpreter, refusal rules shared with HLSL) andemu/rdna2_hlsl_gather.py(HLSL, integer compare, no 64-bit types). One import and one branch inrdna2_exec.py(step andexecutable) andrdna2_hlsl.py; the gather helpers are added to the helper lists ofrdna2_hlsl.py,rdna2_hlsl_wave64.pyandrdna2_hlsl_graphics.py(so a pixel shader using them compiles).rdna2_image.py,rdna2_exec_image.pyandrdna2_hlsl_image.pyare not touched (no conflict with #309).Coverage: interpreter 1,285 → 1,303 of 1,490 encodings (README 86% → 87%, from
rdna2_exec.coverage()); test count 1600+ → 1700+ (1,711 collected). Same change in the 9 READMEs.Verification
Branch on main
c4c93bd. Runtime unchanged against main; the GPU runner is the one built from main'sruntime/.New parity file plus
test_rdna2_exec_gather.pyand the existing image tests (test_rdna2_image.py,test_rdna2_image_ops.py,test_rdna2_image_formats_lod.py) on the other two adapters:Mutation check: making the HLSL
GatherKeykeep denormals (no flush) makes 3 of the 4 GPU parity cases fail on the RTX 4060 Laptop, so the special values reach the compare.Oracle and test data
test_gathers_match_the_interpreterruns all 18 gathers in one program, each through its own S# (8 samplers: the 8 compare functions, with wrap / mirror / clamp / mirror-once / border addressing, the 3 standard border colours, one unnormalized), on a 32_32_32_32_FLOAT texture whose R holds±0, denormals, the smallest normal,±inf, quiet NaNs with payload and quarter steps, and an 8_8_8_8_UNORM texture for the non-compare forms; per-lanes/tinside and outside [0, 1], per-lane offsets (including negative), per-lanez_ref(same special values) and garbage lod/bias/clamp dwords; consecutive and NSA addresses. Four cases: wave32 and wave64, all lanes and a partial EXEC (0xB5E30F71;0x8F0F00F37E1CA55A) with the result registers prefilled per lane.tests/test_rdna2_exec_gather.py(arithmetic in the comments): each compare function on a 2x2 depth grid, every compare form against its footprint with and without offset and with a NaN lod, every non-compare form equal toimage_gather4, denormal flush and-0, NaN reference and NaN/inf texels, border texels, NSA layout order,vdataoverlapping the addresses, and every refusal (with the HLSL refusal for instruction fields). None of these values is a hardware measurement.emu.rdna2_exec_gatherdoes not exist), and each of the 18 encodings raisesinstruction non traduite.Sources (labelled per
docs/research/rdna2-sources.md; printed page numbers of the archived PDFhttp://web.archive.org/web/20230214072857id_/https://developer.amd.com/wp-content/resources/RDNA2_Shader_ISA_November2020.pdf, SHA-25622aec03f…4795, checked):x y, gather4_cl addsclamp; table 44 (p. 73):_Bone bias dword,_CLclamp,_Cone z-comp dword,_Oone offset dword. §8.2.5 (p. 73): "{ offset } { bias } { z-compare } { derivative } { body }", offsets X=[5:0], Y=[13:8]. Table 45 (p. 74-75): T# base/last level, dst_sel, BC swizzle at bits 123:121. Table 46 (p. 76): S# depth compare func 0-7 at bits 14:12, trunc coord at bit 27, min/max LOD "in resource view space (0.0 = T#.base_level)".srcReferenceValue {ComparisonFunction} texel.R", "Denorms are flushed to zero going into the comparison". The gather order is the one already cited forimage_gather4.MIMGInstructions.td/AMDGPU::getAddrSizeMIMGOp, as ported inrdna2_operands_mimg.py: one address dword each forc,b,oand forcl/l.Assumptions left open (measurement questions for an RDNA 2 card)
image_gather4_b/_cl/_c_b_clalways read level 0 whatever the bias / clamp (negative, huge, NaN)?image_gather4_cflush a denormalz_refas well as denormal texels (D3D says "going into the comparison")?z_refor texel, doesNOT_EQUALreturn 1.0 and the ordered functions 0.0 (asimage_sample_calready assumes)?texel.R) or the DST_SEL_X component? Refused when they differ until measured.dmaskother than0x1onimage_gather4_clegal, and which component does it compare? Refused until measured.Checklist
E_NOTIMPL), never a fake success. (Unmodelled cases raiseUntranslated/Untranslatablenaming the instruction and the field.)test_readme_sync.pychecks it).Made with AI assistance: Claude Code with Claude Opus 5.5, for KainanP.
🤖 Generated with Claude Code
The 18 MIMG encodings image_gather4_c, _c_lz, _c_l, _cl, _b, _b_cl, _c_cl, _c_b, _c_b_cl and their _o forms now run in the reference interpreter and translate to HLSL (1,285 -> 1,303 of 1,490). New modules emu/rdna2_exec_gather.py and emu/rdna2_hlsl_gather.py; one import and one branch per dispatcher, the existing image modules are untouched. - Addresses: { offset } { bias } { z-compare } { s, t } { lod or clamp } (ISA section 8.2.5 and tables 43-44, p. 72-73), consecutive or NSA; the counts match LLVM's getAddrSizeMIMGOp (port in rdna2_operands_mimg.py). - On the supported one-level 2D view (BASE_LEVEL = LAST_LEVEL = 0) the LOD only picks the mip level, so bias, clamp and lod do not change the result, as already for image_gather4_l (S# min/max LOD are "in resource view space (0.0 = T#.base_level)", table 46, p. 76). - Without compare: the dmask component after DST_SEL, as image_gather4. - With compare: the 4 results 1.0/0.0 of `z_ref <func> texel.R`, not filtered, in gather order (Microsoft Learn, gather4_c (sm5 - asm)); denormals flushed to zero before the compare (same page), NaN unordered (NOT_EQUAL true). Compared on integers in both the interpreter and the HLSL, so no float compare runs on the GPU. - Refused by name: dmask other than 0x1 or DST_SEL_X other than R with compare, T# BC_SWIZZLE != 0, S# TRUNC_COORD, plus what rdna2_image.py already refuses. README: 1,303 of 1,490 (87%), 1700+ tests, in the 9 languages. Tests: tests/test_rdna2_exec_gather.py (values by hand) and tests/test_rdna2_hlsl_gather.py (all 18 ops, 8 samplers / compare functions, wave32 and wave64, full and partial EXEC, GPU parity). Co-Authored-By: Claude Opus 5.5 <[email protected]>@LooperSalty on GitHub · 2026-11-26 11:08 UTC · original
Merge conflict with
mainafter #302 (VOP3P packed f16) landed. Files in conflict:PrototypeScarlett/emu/rdna2_hlsl.py,rdna2_hlsl_graphics.py,rdna2_hlsl_wave64.py. Auto-merged without conflict:README.mdand the 8docs/i18n/README.*.mdfiles.Resolution: merge
maininto the branch, keep both sides of the overlapping f16 handling in the three HLSL files (the #302 VOP3P opcodes and this PR'simage_gather4changes must both survive), reruntests/test_rdna2_hlsl*and therdna2_opsverifier, then push. No README counter change is expected from the conflict itself.🤖 Generated with Claude Code
@KainanP on GitHub · 2026-11-26 11:26 UTC · original
Merged
maininto the branch (merge commitde05bc4, no rebase).Kept both sides in
rdna2_exec.py,rdna2_hlsl.py,rdna2_hlsl_graphics.pyandrdna2_hlsl_wave64.py: #302'srdna2_exec_pkf16/rdna2_hlsl_pkf16imports, dispatch and HELPERS, plus this PR'srdna2_exec_gather/rdna2_hlsl_gatherimport, branch and HELPERS.README: one change. #302 moved
rdna2_exec.coverage()onmainto 1,312, so on the merged tree it is now 1,330 of 1,490 (89%) instead of the 1,303 (87%) this PR claimed. I updated that in the 9 READMEs. The test count stays 1700+ (1,720 collected).Tests on the merged tree:
tests/test_rdna2_hlsl*95 passed. Full suite: 1705 passed, 15 skipped. The skips are Rust/TomBox builds that aren't present locally.test_rdna2_hlsl_gather.py,test_rdna2_exec_gather.pyandtest_rdna2_hlsl_pkf16.py50/50 passed on each.tools/rdna2_mnemonics.py --verifier: 38,999 encodings, 0 wrong lengths. Regeneratingrdna2_ops.pyleaves it unchanged.AI use: Claude Code (Claude Opus 5.5).
@KainanP on GitHub · 2026-11-26 12:48 UTC · original
Merged
main(#351) into the branch with a merge commit (938071c), no rebase.rdna2_exec.coverage()on the merged tree; the French and Russian READMEs now write1 330with a space, like the1 490next to it.689b74cregeneratescrates/anyxboxx-report/data/rdna2-coverage.txt(MIMG 39 → 57) sotest_built_in_gpu_table_is_up_to_datepasses.pytest -n auto) 1854 passed, 1 skipped;test_rdna2_hlsl_gather.py5 passed on WARP and on Intel UHD; ruff clean; mnemonic verifier OK. CI green.#275 regenerates the same table (VOP1/VOP3 rows), so the second of the two to merge needs a one-line merge there.
AI use: Claude Code (Claude Opus 5.5).