Recompiler: specialize constant-selector v_perm_b32 in direct DXIL #2257
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2267"
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-25T11:53:53Z.
Specializes
Lw::perm_b32(v_perm_b32) in the direct DXIL translator when the byte selector operandselis a compile-time constant, avoiding the ~125-instruction dynamic per-byte select tree emitted for arbitrary runtime selectors.For constant selectors (the standard RDNA2 idiom for packing, unpacking, byte-swapping, and sign-extending),
perm_b32_const:s0ors1) and byte-shift delta into a single shift (and omits the byte mask whenever the shift already zeroes the excluded lanes, reducing identity selectors like0x03020100/0x07060504to 0 ops and half-packs like0x05040100to 3 ops).8..=11) into a singleashr(orshl 16+ashr 31for bit-15 signs).12) and0xFF(>= 13) bytes directly into a single constant operand.Part of #1269.
What is in it
crates/xcl/src/gpu/dxil/prelude.rs: addLw::perm_b32_const, dispatched fromLw::perm_b32whenself.s.m.const_u64(sel)isSome(k)(dynamic selectors stay on the existing loop), plusperm_b32_const_tests::gpu_direct_perm_b32_const_selector_matches_isachecking DXIL validation, disassembly (select-tree elimination), and GPU execution across 10 selector patterns covering all selector classes (0..=3,4..=7,8..=11,12,13,255).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, measured before rebasing onto1a0bbe3), all 573/573 validate cleanly (0validator failures):42,232,344 B -> 42,221,860 B(-10,484 B)302.63 ms -> 284.48 msTested
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 perm_b32_const_tests(debug):1 passed; 0 failed(validates DXIL, verifies select-tree elimination, and verifies 10 selector patterns × 8 inputs on the RTX 3070)..\scripts\test.ps1(debug, full workspace on headc665154):1251 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
perm_b32_constinprelude.rs, added DXIL disassembly and GPU ISA parity tests, and ran the full workspace test suite, 573-shader validation benchmark, and 60 s smoke regression run.Imported from ivall/xcl. Originally posted by itsSio on 2026-11-25T12:09:53Z.
Tested
Independent Windows verification at clean
c6651548d9b30d1da3929e5cbbe7de1d9c6067ca. Both PCs used Windows 11 Pro build 26200, x64 MSVC, and unoptimized dev/test profiles with debug info off.cargo build --workspace --lockedandcargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocaptureexited 0 on both.SKIPPED32.0.16.108832.0.16.1088cargo test -p xcl --lib --locked perm_b32_const_tests -- --test-threads=1 --nocapture: 1 passed / 0 failed / 0 ignored, no runtime skips, on each RTX card and the Radeon RDNA2 iGPU (driver32.0.21043.5001, same Ryzen 7 system and toolchain). The fixture validated DXIL, checked the generated select count, and compared 10 selectors ? 8 inputs against the CPU reference. The GPU fixture uses wave32 on all three adapters.Not tested
Native or split wave64 for this fixture, full AMD workspace, Intel, title samples, and performance.
AI use
Ran via Samaritan:
openai/gpt-6.2-sol): scoped and ran the Windows checks, audited the logs and fixture, and wrote this report. No subagents contributed.Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-25T12:52:03Z.
Independent RX 6800M check of PR head
c6651548d9b30d1da3929e5cbbe7de1d9c6067ca, including a local test-only native-wave64 variant of its new GPU fixture.Environment: Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver
30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5.XCL_ADAPTER=6800M,XCL_REQUIRE_GPU=wave64,XCL_DIRECT_DXIL=1; debugcargo test --locked -p xcl --lib -j 2 perm_b32_const_tests -- --test-threads=1 --show-output.gpu_direct_perm_b32_const_selector_matches_isapassed 1/0/0, no skip. ItsKernelOptionsis hard-coded towave64: false, so this is a wave32 execution on the wave64-capable adapter.KernelOptionstowave64: true, split: falseand its capability check fromwave32_supported()towave64_supported()(with matching skip text). The same selector/input fixture passed 1/0/0, no skip, on native wave64. This validates the PR's unchanged production lowering on the RX 6800M in native-wave64 mode. The two test-only edits were not committed; I restored the clean PR head afterward.The fixture checks 10 selector patterns across 8 input pairs and validates/disassembles the generated DXIL. I did not run the full workspace suite, a retail-title smoke, split-wave64, or a performance benchmark on this head. The local wave64 result is not an exact-head test-binary result; it uses the exact-head production code with the fixture mode changed as described.
AI use: OpenAI Codex (GPT-6; exact variant not exposed in this session) ran the native Windows tests, made and restored the local fixture-only change, checked the logs, and drafted this report. No game data was used.
Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-25T15:14:12Z.
Independent Windows test of
c6651548d9b30d1da3929e5cbbe7de1d9c6067ca. Constant-selector byte permutations matched the ISA reference on both adapters, including the upper half of split wave64 on RTX 5090.Tested
cargo test --locked -p xcl --lib perm_b32 -- --nocapture --test-threads=1. The wave32 fixture reported 1 passed, 0 failed, 0 ignored, and no logged skips on each adapter.cargo test --locked -p xcl --lib gpu_direct_perm_b32_const_selector_matches_isa -- --nocapture --test-threads=1. Enabled all 64 execution lanes and checked 10 selector patterns against eight inputs in each half of the wave, with reversed input order in the upper half. The logs confirmed native wave64 on the Radeon and split wave64 on the RTX 5090. Both reported 1 passed, 0 failed, 0 ignored, and no logged skips. DXIL validation and the select-count assertion also passed. Restored the clean checkout afterward.Not tested
Parent revision, performance, retail titles, or the full workspace suite.
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:05:04Z.
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 raylitebull on 2026-11-25T18:41:04Z.
Diff review, CI, and both AMD and NVIDIA checks passed on
c665154, but recentorigin/mainmerges turned this branchCONFLICTING/DIRTY. Please rebase ontoorigin/mainso it becomes mergeable again.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:42:26Z.
Triage (#1607) – head
c665154#3503 (main commit
6ff86e30, "specialize const v_perm_b32 (#2267)") merged the sameperm_b32_constand the same constant-selector branch inperm_b32, line for line. Your GPU testgpu_direct_perm_b32_const_selector_matches_isais not on main. It could go in as a small test-only PR.Recommendation: close (superseded by #3503 / main commit
6ff86e3).AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:51:21Z.
Closing as superseded: this change is already on
main(6ff86e30).6ff86e30(rebases #2212 and #2267) has perm_b32_const in dxil/prelude.rs line for line and the const_u64 call site; only the PR's GPU test perm_b32_const_tests is not on main (test-only remainder)Two independent checks found this: Foniass's close list on #1607 and ours against current
main. If something here is still missing onmain, say so and reopen it, or ask and I will.AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.
Pull request closed