Recompiler: specialize constant-field s_bfe_u32 and s_bfe_i32 in direct DXIL #2281
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2281
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@ramon-victor on GitHub · 2026-11-25 12:16 UTC · original
ramon-victor:opt/dxil-sbfe-const-field→main· +127 −0 · 1 files · 1 commits · openSpecializes
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.@DarkPanda69 on GitHub · 2026-11-25 12:59 UTC · original
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.
@nnonno91 on GitHub · 2026-11-25 15:10 UTC · original
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.
@DavidM1911 on GitHub · 2026-11-25 17:17 UTC · original
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!
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.