shader: lower compute s_bfe_u32 and s_bfe_i32 #1948
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1955"
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 henriazz10 on 2026-11-24T22:07:06Z.
Change
Refs #721. This is the
s_bfe_u32/s_bfe_i32slice claimed in https://github.com/R0Y00/Xbox2Windows/issues/721#issuecomment-7143412663. It touches onlytools/compute_store_aot.py,tests/compute_store_check.py,CMakeLists.txtanddocs/experiments.md.s_bfe_u32 sD, S0, S1ands_bfe_i32 sD, S0, S1(SOP2) on known 32-bit scalar words (alu_word,hlsl_word,ALU_EXPRESSION_LIMIT), withoffset = S1[4:0]andwidth = S1[22:16]per the RDNA2 ISA (0whenwidth == 0,(S0 << (32 - offset - width)) >> (32 - width)whenoffset + width <= 32, andS0 >> offsetwhenoffset + width > 32; logical fors_bfe_u32, arithmetic fors_bfe_i32).SCCis unread.s_bfe_u32/s_bfe_i32) only when referenced in the lowered body sowidth == 0returns0uinstead of shifting by32and all shift counts stay in0..31.s30,s12,s23befores_waitcnt lgkmcnt(0));s105(s106) or pending load destination (s23);0x1ffffffff);s_bfe_u64,s_bfe_i64);v0,1.0,exec_lo) and unsupported suffixes/modifiers (_e64,clamp,-s4,abs(s4));SCCconsumers (s_cbranch_scc0 0), use as a store address or lane-guard compare operand, and expressions exceedingALU_EXPRESSION_LIMIT.Verification
Commit
314bad99, rebased onto32595645. The draws,controls()and the LLVM 15 round trip were re-run on314bad99. Windows 11, DXC 10.0.26100.0, Python 3.12 (pe-env), debug layer enabled.offscreen_checkwas built frommain; this PR does not change it.groups=1 compared_words=320 mismatches=0,debug_errors=0 debug_warnings=0groups=1 compared_words=320 mismatches=0,debug_errors=0 debug_warnings=0Doc/repo checks:
tests/docs_links_check.py: exit 0 (Checked 18 Markdown files and 376 links.).tests/bidi_controls_check.py: exit 0 (Checked 1330 tracked source, script and build/CI files: no bidirectional controls.).git diff --check HEAD~1: exit 0.LLVM 15 round trip in Docker:
binary_exit=0.bfe_binary()decodes the assembledBFEfixture back to the sames_bfe_u32/s_bfe_i32lines and requires the same translation.Negative control. With
tools/compute_store_aot.pyfromorigin/main,bfe_controls()fails withValueError: Unsupported compute instruction: s_bfe_u32 s16, s4, 0x80008.Evidence
The
BFEfixture is source-built in LLVM 15 spelling for one 64-thread group (wave_size=32, 4 words per thread, 256 words written and words256..319left atSENTINEL). It covers mid-word extraction with MSB 1 (0x8000f5a3, offset 8, width 8) under boths_bfe_u32ands_bfe_i32,width == 0with ignored bits set inS1[31:23]andS1[15:5](0xff80ffe8,0xff80ffe0),offset + width == 32(0x100010),offset + width > 32(0x140014), negative inline constant-1withoffset = 0, width = 32(0x200000), and chaineds_bfeoutput. All 320 words are compared against an independent Python model (bfe_model).bfe_controls). Checks exacts_bfe_u32/s_bfe_i32helper emission (and per-helper omission when unused), the exactStore4expression, and all rejection cases listed above.s_bfe_i32treated as unsigned: word 1;width == 0not returning0: word 3;offset + width > 32not sign-extending: word 2;width == 0ureturningsrcinstead of0u;s_bfe_i32using unsigned right shift ((src >> offset)).Checklist
docs/experiments.md).AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T23:57:50Z.
Review: COMMENTED
Review of head
742306417b7d149c9b384a5903967c4b0151a0a7.Diff read in full (CMakeLists.txt, docs/experiments.md, tests/compute_store_check.py, tools/compute_store_aot.py). CMakeLists.txt only registers
compute_store_aot_bfe_<adapter>. The semantics follow the RDNA 2 ISA pseudocode (width 0 returns 0, offset+width > 32 shifts only, shift counts stay in 0..31). Spec-derived and independent of any other source; no clean-room concern.P1: 0. P2: 0.
Commands executed (Linux):
git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflictspython3 tests/docs_links_check.py: PASS (18 files, 391 links)python3 tests/bidi_controls_check.py: PASS (1407 files)git diff --check origin/main...HEAD: PASSpython3 -B tests/compute_store_check.py <mode>:controls()incl. newbfe_controls()PASSgh pr checks 1955: Linux checks, gfx1013 fixtures, Windows build and test all passWindows Server 2025 (
x2w_pipe.py win2025 1955): Debug (--preset dev) 72/72 pass; Release /O2 (--preset release) 72/72 pass; includescompute_store_aot_bfe_warp.Mutations on the code under test (reverted with
git checkout -- .):"s_bfe_i32"lowering mapped tos_bfe_u32(...): KILLED bybfe_controls()(helper and exact-HLSL assertion).width == 0ureturningsrc, andoffset + width <= 32uchanged to<: not exercised by the Linux controls (they check emission and signature only); these are covered by the on-devicedraw-bfecomparison, which I did not re-run with the mutation.127uchanged to63u: survives. No fixture setsS1[22]. Minor, not blocking.Note (not blocking): the Linux controls assert only the helper signature lines, so helper-body regressions are caught on the device run only.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:35:17Z.
Review: COMMENTED
Review of head
314bad99f5(s_bfe_u32 / s_bfe_i32 lowering).Result: 0 P1, 0 P2. Clean-room: the change is original code, a spec-derived model and a source-built fixture. CMakeLists.txt only registers
compute_store_aot_bfe_${adapter}.Semantics read: width 0 returns 0,
offset + width <= 32uses shift-left then shift-right (logical for u32, arithmetic for i32), and the overflow case usessrc >> offset. Every shift count stays in 0..31. Helpers are emitted only when referenced. The Python model is independent of the HLSL helper.Commands executed locally:
git merge-tree --write-tree --name-only origin/main HEAD: no conflicts. PR is MERGEABLE.gh pr checks 1955: Linux, Windows and gfx1013 fixtures pass.python3 -B tests/compute_store_check.py <mode>: controls() including bfe_controls() pass.python3 tests/docs_links_check.py: PASS (18 files, 394 links).python3 tests/bidi_controls_check.py: PASS.git diff --check origin/main...HEAD: clean.x2w_pipe.py win2025 1955 --wait 900: Debug (--preset dev) passed, Release /O2 (--preset release) passed.compute_store_aot_bfe_warpran and passed.Mutations (all killed by
bfe_controls()):s_bfe_i32table entry changed to calls_bfe_u32: exact-HLSL assertion fails.s_bfe_i32helper emission suppressed, so thes_bfe_i32helper was missing: the per-helper emission assertion fails.The device-side mutations (width 0 returns src, unsigned shift in i32) are part of
bfe_drawand passed on Win2025.AI-assisted; commands listed were executed locally.