Recompiler: specialize constant-field s_bfe_u32 and s_bfe_i32 in direct DXIL #2271
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2281"
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 ivall/xcl. Originally posted by ramon-victor on 2026-11-25T12:16:45Z.
Specializes
Lw::sbfe_u(s_bfe_u32) andLw::sbfe_i(s_bfe_i32) in the direct DXIL translator when the packed offset/width operandc(offset = c & 31,width = (c >> 16) & 0x7F) is a compile-time constant.While constant-folding in
Lw::bin/Lw::selalready collapses the mask/width predicates for constantc, specializing directly:s_bfe_*before optimization.& ((1 << width) - 1)mask ins_bfe_u32(and theshl+ashrsign-extension pair ins_bfe_i32) wheneverwidth >= 32 - off, since the right shift already clears/sign-extends the topoffbits.1 <= width < 32 - off) ins_bfe_i32with 2 shifts (shl(v, 32 - off - width)thenashr(..., 32 - width)) instead of 3 shifts (ashr+shl+ashr).Scalar BFE uses a 7-bit width (
0..=127wherewidth >= 32extracts all remaining bits), so this remains exact without using DXILUbfe/Ibfe(which mask width to 5 bits).Part of #1269.
What is in it
crates/xcl/src/gpu/dxil/lower.rs:Lw::sbfe_uandLw::sbfe_i(dynamiccstays on the existing general lowering).sbfe_const_tests::sbfe_const_algebra_matches_reference_exhaustivelyverifying every(off, width)pair in0..32 x 0..128against the reference ISA semantics, andsbfe_const_tests::gpu_direct_sbfe_const_field_validates_and_matches_isachecking DXIL validation, disassembly (0 selects), and GPU execution across 10 edge-case(off, width)pairs for bothS_BFE_U32andS_BFE_I32.On a seeded 600-program sample (
xcl shaders <archive> --direct --sample 600 --seed 3 --max-bytes 40000 --validate --threads 8, 573 programs within the cap), all 573/573 validate cleanly (0validator failures):41,323,736 B -> 41,322,584 B(-1,152 B)Tested
621.24, wave32), AMD Ryzen 7 5700X, Windows 11 Pro26300,rustc 1.99.0(x86_64-pc-windows-msvc), DXC/DXIL1.8.2502.11(Windows SDK10.0.26100.0).cargo test -p xcl --lib gpu::dxil::lower::sbfe_const_tests(debug):2 passed; 0 failed(exhaustive 4,096(off, width)algebraic proof + 20-op GPU execution check on RTX 3070)..\scripts\test.ps1(debug, full workspace):1252 passed; 0 failed; 46 ignored(25 GPU sub-checks skipped on this wave32 adapter: 21no wave64, 1no heap windows, 3 per-lane#1426refusals).cargo build --release -p xcl+ direct DXIL validation sweep on 573 sampled retail shader programs:573/573translated anddxil.dll-validated (0failures).Regression run
Not tested
XCL_SAMPLE_*env vars unset).AI use
Lw::sbfe_uandLw::sbfe_i, added exhaustive algebraic and GPU ISA tests inlower.rs, and ran the full workspace test suite, 573-shader validation benchmark, and 60 s smoke regression run.Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-25T12:59:47Z.
The AMD native wave64 run listed as untested, plus an RTX 3060: the new test passes on both.
Head
8373646applied onmain1a0bbe3, debug, Windows 11 Pro 26200,cargo test -p xcl --lib -- gpu:: --test-threads=4:gpu_direct_sbfe_const_field_validates_and_matches_isaok. 631 passed, 2 failed, 22 ignored, 6 SKIPPED, the same asmainplus the new test; the 2 failures are the AMD fuzz seeds tracked in #2115.Not tested: a title with
XCL_DIRECT_DXIL=1.AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-25T15:10:32Z.
Independent Windows test of
837364677f87988b5081e7ad0e9b61fd4f28644f. Signed and unsigned constant bit-field results matched the reference on Radeon integrated graphics and RTX 5090.Tested
cargo test --locked -p xcl --lib sbfe_const_tests -- --nocapture --test-threads=1once per explicitly selected adapter. Each run reported 2 passed, 0 failed, 0 ignored, and no logged skips.Not tested
Dynamic fields on GPU, the parent revision, retail titles, or the full workspace suite. The fixture changes were temporary.
AI use
OpenAI Codex (GPT-6.2 Sol) prepared and ran the tests, verified the results, and wrote this report.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T17:17:29Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:44:18Z.
Triage (#1607) – head
8373646No open or merged PR makes the same change. Main's
Lw::sbfe_u/sbfe_iingpu/dxil/lower.rsalways emit the generic select-based sequence. The constant-field branches give the same results as main's generic code, includingoff + width >= 32andwidth >= 32. Note:sbfe_const_algebra_matches_reference_exhaustivelytests a copy of the formula written into the test, notsbfe_u/sbfe_ithemselves. Only the GPU test runs the real lowering. The PR conflicts with main.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.