Recompiler: simplify bfm / s_bfm_b64 and lower ffbh_i to FirstbitSHi in direct DXIL #2549
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2559"
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-25T22:57:59Z.
Part of #1269.
Problem
In
crates/xcl/src/gpu/dxil/lower.rs, bitfield mask and signed find-first-bit-high helpers emitted unnecessarily heavy DXIL sequences:bfm(s_bfm_b32,v_bfm_b32) computedselect(w == 0, 0, u32::MAX >> ((32 - w) & 31)) << (b & 31)(8 instructions includingicmpandselect), even thoughw = a & 31is already strictly in0..=31, so((1u32 << w) - 1) << (b & 31)is exact for everywincludingw = 0.s_bfm_b64used the same 12-instructionicmp/select/lshri64expansion even when both operands are compile-time constants, forcingi64arithmetic andFeature::Int64Opsfor constant lane masks.ffbh_i(v_ffbh_i32,s_flbit_i32) manually emulated signed find-first-bit-high withicmp slt 0, bitwise NOT,select, andFirstbitHi(4 instructions), instead of lowering directly to DXIL'sBitCount::FirstbitSHi(dx.op.unaryBits.i32op34).Fix
bfm(lower.rs) to((1 << (a & 31)) - 1) << (b & 31)with direct constant folding whena(or bothaandb) is constant.s_bfm_b64(lower.rs) directly to twoi32constants without touchingi64orFeature::Int64Ops; for dynamic operands, simplify to((1u64 << (al & 63)) - 1) << (bl & 63)with noicmp/select.ffbh_i(lower.rs) directly toself.s.bit_count(BitCount::FirstbitSHi, v).lower::bfm_ffbh_tests::bfm_and_ffbh_i_ir_and_gpu_paritychecking DXIL validation, disassembly (zeroInt64Opsfor constants_bfm_b64,FirstbitSHiop34withouticmp sltforv_ffbh_i32/s_flbit_i32, zeroselectfor dynamicbfm), and wave32 RTX 3070 GPU parity across all edge cases (0,-1,1,-2,0x7FFF_FFFF,0x8000_0000, widths0/1/16/31/32/63/64, offsets0..63).Measured impact
573-program retail direct-DXIL validation sweep (
dxil.dll1.8.2502.11):6d12f58):573/573validated (val_fail=0),51,117,488total DXIL bytes (p50=22,865 us,p95=408,132 us).7bf4853):573/573validated (val_fail=0),51,116,080total DXIL bytes (-1,408 B/-0.003%;p50=19,313 us,p95=376,258 us).Tested
cargo test --lib -p xcl bfm_ffbh): 1 passed, 0 failed..\scripts\test.ps1, NVIDIA GeForce RTX 3070, Windows 11):1424 passed, 0 failed, 46 ignored.dxil.dllvalidation sweep:573/573passed,0failures.cargo build --release -p xcl) and 60 s retail smoke run (see below).Not tested
Regression run
Main (
f087b99):This PR (
7bf4853):AI use
Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-25T23:14:31Z.
Wave64 run (listed as untested; the wave64 GPU tests skipped on the RTX 3070) on an AMD RX 9070 XT, plus an RTX 3060: the new test passes, and nothing else changes in the direct-DXIL GPU suite.
Head
7bf4853applied onmain08db802, debug, Windows 11 Pro 26200,XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4onmainand with the PR, card chosen withXCL_ADAPTER:mainOn both cards, the only result change against
mainis the newbfm_and_ffbh_i_ir_and_gpu_parity(ok), with no new skips. That test translates withwave64: false, so its own GPU run is wave32. On the RX 9070 XT, the rest of the suite's wave64 cases, which skip on a 32-lane GPU, ran with this PR applied and still pass. How many of them containbfmorffbh_iwas not checked. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same onmain.Not tested: Intel, a title.
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 DavidM1911 on 2026-11-25T23:19:15Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 26 ignored.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-25T23:41:17Z.
Tested: current PR head merged onto current
origin/main(clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo targetx86_64-pc-windows-gnurun under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).gpu_suite (cold cache): 166 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. This PR does not change the mad/mac red on RADV.bfm_and_ffbh_i_ir_and_gpu_parityran inside the suite (name matches the filter): passed.Not tested: retail titles (no title data on this lane, counts only).
AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T01:26:44Z.
Independent desktop NVIDIA (Wave32-only Ada) verification of PR #2559 at head
7bf48538afdea8d4bf8e56645a450b5c77b1e405(1commit; exact parent & merge-base:e1d84b7d9153f86a97d2ec5d209d196046fc0bea, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted release tests & build (
7bf48538)cargo test --release -p xcl --lib bfm_and_ffbh_i_ir_and_gpu_parity -- --nocapture(3 consecutive runs)1 passed; 0 failed; 0 ignored; 1324 filtered out× 3 (0.24s,0.21s,0.21s,0skipped — live Wave32 GPU parity on RTX 4060)cargo test --release -p xcl --lib gpu::dxil:: -- --test-threads=4(3 consecutive runs)184 passed; 0 failed; 3 ignored; 1138 filtered out× 3 (3.74s,3.60s,3.60s;183executed +1expected Wave32-only skipdispatch_chain_native_wave64_builds_whole: no wave64)cargo build --release -p xcl1m 07s, exit0,0new warnings)Paired quiet 60 s retail smoke (
title: 29640639)Exact parent & merge-base (
e1d84b7d9153f86a97d2ec5d209d196046fc0bea, cached baseline on the same machine):PR #2559 (
7bf48538afdea8d4bf8e56645a450b5c77b1e405):Runtime log observations (
xcl.log)9222log lines,0[ERROR]/ device-removal / panic lines.19567 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample14011 MB committed by the process; video memory 6115 MB local, 4686 MB non-local.Limits of coverage
bfm/s_bfm_b64simplification andffbh_i->FirstbitSHidirect-DXIL lowering were verified end-to-end on desktop Wave32-only NVIDIA RTX 4060 viabfm_and_ffbh_i_ir_and_gpu_parity(3/3,0skipped) andgpu::dxil::(183executed +1expectedno wave64skip × 3).title: 29640639confirms zero runtime regression rather than re-compiling a coldXCL_DIRECT_DXIL=1shader set (frame-count and commit deltas vs. cached parent reflect single-run startup variance, not this PR).AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T10:00:34Z.
releasing: my merge-check claim for head
7bf48538af.The PR's exact patch is already on
mainas 2820ac6109bf6b2109b6f15fbbecb447b9d2d93c. Both commits have stable patch ID0187a736fba034cd471d889aca77bcb998c53a51; the landed commit credits #2559. There is no remaining change from this head to merge. I stopped before the trial merge and did not run tests for this check.AI use: Codex (GPT-6.2 Sol) verified the commit identity; Codex (GPT-6.2 Astra) independently checked the current source.
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T14:40:40Z.
merge-check claim
head:
7bf48538afImported from ivall/xcl. Originally posted by throny on 2026-11-28T14:53:33Z.
merge-check
base:
b937fbabhead:
7bf48538afmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2140 passed, 1 failed, 48 ignored: exactly the base's result, because the merge changes nothing (26 SKIPPED lines). The one failure is gpu::dxil::msaa_tests::direct_msaa_loads_precede_get_dimensions, which main itself has at
b937fbab(#3093); base alone: 2140 passed, 1 failed, 48 ignored.review: the whole change is already on main: commit
2820ac61is an ancestor ofb937fbab, the PR's diff has the same stable patch id, and a trial merge of this head into main gives main's own tree (no file changes). This agrees with the earlier finding in the thread.performance: nothing to add on main.
verdict: not yet: nothing to merge; already in main through
2820ac61, so this PR can be closed.hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T14:02:52Z.
@Prime1997 this can be closed as the changes are already in main
Verified against current
main(9dfbe3ea): the PR's single commit7bf48538afdea8d4bf8e56645a450b5c77b1e405has the same stable patch id (0187a736fba034cd471d889aca77bcb998c53a51) as2820ac6109bf6b2109b6f15fbbecb447b9d2d93c(Recompiler: simplify direct-DXIL bit masks and signed ffbh), which is already an ancestor ofmain(merged via #2959). Merging this head would change nothing.Checked by saintwolf (OpenCode, Qwen 3.8 27B); agrees with throny's merge-check on the same head.
Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T18:19:52Z.
merge-check claim
head:
7bf48538afImported from ivall/xcl. Originally posted by throny on 2026-11-30T20:10:29Z.
Closing: this change is already on
mainas commit2820ac61(brought in byb0b041fdMerge pull request #2959 from bmjask/stack/308-benchmark-thre). This PR's diff applies in reverse cleanly on currentmain(ff0c364b), so merging it would change nothing. If something here is not onmain, say so and reopen it, or ask and I will.AI use: Claude Code (Claude Opus 5.5) checked this; part of the duplicate sweep on #3041.
Pull request closed