shader: lower compute s_bitreplicate_b64_b32 lane masks #1575
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1582"
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 Asimmimx on 2026-11-24T14:35:44Z.
Change
Refs #1546. This lowers
s_bitreplicate_b64_b32lane-pattern masks in the compute translator (tools/compute_store_aot.py). It also adds one minimal consumer that makes such a mask observable: a lane select throughv_cndmask_b32_e64.Lowering rules
s_bitreplicate_b64_b32 s[d:d+1], imm:D.u64[2i] = D.u64[2i+1] = S0.u32[i], per the RDNA 2 ISA, the same as the existingpixel_aothelper. With an inline or 32-bit literal source, both halves become known scalar words: the low half replicates bits 0–15 and the high half bits 16–31.Unverified lane mask source.Invalid lane mask destination.v_cndmask_b32_e64 vD, a, b, sM(wave32 spelling):D = mask[lane] ? b : a. It lowers to(((0xMASKu >> (tid.x % Xu)) & 1u) != 0u ? b : a), and the result is data only.Unverified lane mask.a/boperands, or a destination past v255, are refused withUnverified ALU operand.Lane mask select requires a one-dimensional group of at most 32 threadsrather than guessed.The change adds two new
elifbranches before thes_lshl_b32branch. It touches no shared table or comment.Fixture (
tests/compute_lane_mask_check.py, new; it imports the helpers oftests/compute_store_check.py, which is unchanged)0x0fff0fffin both halves.0x33fc033f, high0xc3f00fcc.buffer_store_dwordx4stores four words:m.lo[lane] ? 0x600d : gidn.lo[lane] ? gid : 0xbeefn.hi[lane] ? gid : 0xffffffff0xc3f00fccThe draw must also reject the following, each at its first differing word:
Controls
controlsmode pins the exact HLSL, checks the masks -1, 0, 0xffff and 0xffff0000, and runs about 30 refusals.Unsupported compute instruction: …for:s[8:9]mask;vcc_loorexec_loas the mask;-v/|v|/clamp;s_mov_b32 exec_lo, s8;s_and_saveexec_b32 s20, s8.Unsupported store address.Registration and docs
compute_store_aot_lane_mask_${adapter}, registered aftercompute_store_aot_mimg_store_packed.docs/experiments.mdsubsection "Lane-pattern masks from s_bitreplicate_b64_b32", after the per-lane guards section.Verification
Commit
6c0e5380(main) plus this change,devpreset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11.1002:73ff), driver 32.0.21045.29003, debug layer enabledThese also pass with the change: the
compute_store_checktranslator controls,drawanddraw-guard-readon WARP,tests/docs_links_check.py,tests/bidi_controls_check.py,tests/form_coverage_check.pyandgit diff --check.Open points
Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:27:27Z.
Review: COMMENTED
Reviewed at commit
285cbc6c724442601f27b6f92c96c173358c6f33.Findings
tools/compute_store_aot.py:s_bitreplicate_b64_b32 s[d:d+1], immvalidates even alignment,high == dst + 1 <= 105, non-pending destination pair, and 32-bit integer inline/literal source, then folds both 32-bit halves intoscalar.v_cndmask_b32_e64 vD, src0, src1, sMenforces a 1D group of at most 32 threads (dims[1:] == (1, 1)anddims[0] <= 32) sotid.x % dims[0]matches the wave lane at either wave size, checks thatsMholds a statically known 32-bit integer word, and lowersD = mask[lane] ? src1 : src0.tests/compute_lane_mask_check.pyandCMakeLists.txt: negative controls cover non-immediate sources, invalid/pending destinations, unknown/pending/unsupported masks, source modifiers/clamp, out-of-range VGPRs, store-address rejection, and >32 / multi-dimensional groups; D3D12 WARP dispatches verify 320 readback words across 32- and 16-thread groups along with wrong-reference and mutated-HLSL rejection.Verification
python3 -B tests/docs_links_check.py-> passed (16 Markdown files, 344 links).python3 -B tests/bidi_controls_check.py-> passed (1253 tracked files).python3 -B tests/compute_lane_mask_check.py controls-> passed.--preset dev):ctest --preset dev(41 direct downstreamcompute_*_warptests, includingcompute_store_aot_lane_mask_warp) -> 41/41 passed (61.07s/4.49sforcompute_store_aot_lane_mask_warp)./O2(--preset release): same 41-test suite -> 41/41 passed (58.32s/4.78sforcompute_store_aot_lane_mask_warp).No blocking issues found.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:35:07Z.
Review: COMMENTED
Audit at
head_sha:285cbc6c724442601f27b6f92c96c173358c6f33(this follows my earlier comment on the same head and adds the semantic audit and the mutation results it lacked).Verdict: 0 P1, 0 P2.
Scope
CMakeLists.txt(oneadd_test, test only),docs/experiments.md,tests/compute_lane_mask_check.py(new),tools/compute_store_aot.py(+29). Nosrc/, nogfx2hlsl, no.github/.git merge-treeagainst currentmain(68969ed8): no conflicts.RDNA 2 semantics
s_bitreplicate_b64_b32 s[d:d+1], imm:D.u64[2i] = D.u64[2i+1] = S0.u32[i]for i in 0..31. The lowering computessum(((src >> (bit // 2)) & 1) << bit for bit in range(64))and stores the two halves as known words. Sign extension of a negative immediate is safe because only bits 0..31 are read. Destination must be even,high == dst + 1, at mosts105, and not pending; only decimal/hex immediates in[-2^31, 2^32)are accepted, so an SGPR source or a float inline constant is refused.v_cndmask_b32_e64 vD, src0, src1, sM:D = mask[lane] ? src1 : src0. It is accepted only for a one-dimensional group of at most 32 threads, where the group is one wave at wave32 and the lane istid.x % dims[0]. The single-SGPR mask operand is wave32 syntax:llvm-mc-19 -mcpu=gfx1013 -mattr=-wavefrontsize32,+wavefrontsize64rejects all three fixturev_cndmask_b32_e64 ..., sNlines (3 errors), so a wave64 program cannot reach this branch with the same text. The mask SGPR must hold a statically known word; source modifiers,clamp,vcc, ranges are not matched.llvm-mc-19 -mcpu=gfx1030 -mattr=+wavefrontsize32assembless_bitreplicate_b64_b32 s[8:9], 0x3f3f3f3f(ff 3b 88 be ...), the second constant, and the threev_cndmask_b32_e64forms (-1, literal and SGPR sources).Verified
Limits: Linux x86-64 only. No Windows/D3D12/DXC:
compute_store_aot_lane_mask_*(draw: 320 readback words, wrong references, mutated HLSL) was not run for this head.python3 -B tests/compute_lane_mask_check.py controls-> exit 0.python3 -B tests/docs_links_check.py-> 16 files, 344 links OK.git diff --check HEAD^ HEADclean.bit // 2->bit // 3(exact-textAssertionError); select arms swapped (AssertionError); lane taken astid.xwithout the modulo (AssertionError); group limit 32 -> 64 (Expected a rejection: Lane mask select requires a one-dimensional group of at most 32 threads); odd destination allowed (AssertionError: Unverified lane mask); negative immediate refused (ValueError: Unverified lane mask source).git checkout -- .;git status --shortclean.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:55:24Z.
Review: COMMENTED
Independent verification at
head_sha:285cbc6c724442601f27b6f92c96c173358c6f33.Verdict: 0 P1, 0 P2.
Scope & Semantics
CMakeLists.txt(test-onlyadd_test),docs/experiments.md,tests/compute_lane_mask_check.py,tools/compute_store_aot.py. Clean-room verified; nosrc/,gfx2hlsl, or.github/changes.s_bitreplicate_b64_b32 s[d:d+1], immandv_cndmask_b32_e64 vD, src0, src1, sM):s_bitreplicate_b64_b32replicates each source bitiin0..31toD[2i]andD[2i+1], enforces even-aligned contiguous SGPR pair<= s105, non-pending destination, and 32-bit integer immediate source (-(1 << 31) <= val <= 0xffffffff).v_cndmask_b32_e64lowersD = mask[lane] ? src1 : src0to(((0x{mask:08x}u >> (tid.x % {dims[0]}u)) & 1u) != 0u ? {src1} : {src0}), restricting to 1D groups of at most 32 threads (single wave wherelane == local.xat either wave32 or wave64), statically known non-pending SGPR mask, and valid ALU operands.Commands Executed
git diff --check origin/main...HEAD— PASSpython3 tests/docs_links_check.py— PASS (16 Markdown files, 344 links)python3 tests/bidi_controls_check.py— PASS (1253 files)python3 -B tests/compute_lane_mask_check.py controls— PASSllvm-mc-19 -triple=amdgcn-- -mcpu=gfx1013 -mattr=+wavefrontsize32 -show-encodingonLANE_MASK— PASScmake --build --preset dev+ctest --preset dev(42/42 passed, includingcompute_store_aot_lane_mask_warp) — PASScmake --build --preset release(/O2) +ctest --preset release(42/42 passed, includingcompute_store_aot_lane_mask_warp) — PASStools/compute_store_aot.py(reverted viagit checkout -- .):words[1]andwords[0]inv_cndmask_b32_e64ternary -> caught bycompute_lane_mask_check.py controls.bit // 2tobit // 3ins_bitreplicate_b64_b32-> caught bycompute_lane_mask_check.py controls.AI-assisted; commands listed were executed locally.