Recompiler: specialize constant-selector v_perm_b32 in direct DXIL #2267

Open
github-bot wants to merge 1 commit from github-bot/gh-2267 into main AGit
Owner

@⁠ramon-victor on GitHub · 2026-11-25 11:53 UTC · original
ramon-victor:opt/dxil-perm-b32-const-sel → main · +155 −0 · 1 files · 1 commits · open

Specializes Lw::perm_b32 (v_perm_b32) in the direct DXIL translator when the byte selector operand sel is 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:

  • Groups output bytes sharing the same source (s0 or s1) and byte-shift delta into a single shift (and omits the byte mask whenever the shift already zeroes the excluded lanes, reducing identity selectors like 0x03020100/0x07060504 to 0 ops and half-packs like 0x05040100 to 3 ops).
  • Coalesces output bytes sharing the same sign-extension selector (8..=11) into a single ashr (or shl 16 + ashr 31 for bit-15 signs).
  • Folds constant zero (12) and 0xFF (>= 13) bytes directly into a single constant operand.

Part of #1269.

What is in it

  • crates/xcl/src/gpu/dxil/prelude.rs: add Lw::perm_b32_const, dispatched from Lw::perm_b32 when self.s.m.const_u64(sel) is Some(k) (dynamic selectors stay on the existing loop), plus perm_b32_const_tests::gpu_direct_perm_b32_const_selector_matches_isa checking 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 onto 1a0bbe3), all 573/573 validate cleanly (0 validator failures):

  • Total emitted DXIL: 42,232,344 B -> 42,221,860 B (-10,484 B)
  • Translation time p95: 302.63 ms -> 284.48 ms

Tested

  • Hardware and toolchain: NVIDIA GeForce RTX 3070 (8 GiB, driver 621.24, wave32), AMD Ryzen 7 5700X, Windows 11 Pro 26300, rustc 1.99.0 (x86_64-pc-windows-msvc), DXC/DXIL 1.8.2502.11 (Windows SDK 10.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 head c665154): 1251 passed; 0 failed; 46 ignored (25 GPU sub-checks skipped on this wave32 adapter: 21 no wave64, 1 no heap windows, 3 per-lane #1426 refusals).
  • cargo build --release -p xcl + direct DXIL validation sweep on 573 sampled retail shader programs: 573/573 translated and dxil.dll-validated (0 failures).

Regression run

xcl-smoke v1
commit: f087b998d0d51a9f11bbfa0761967a63e778edd9
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14467 MB
xcl-smoke v1
commit: c6651548d9b30d1da3929e5cbbe7de1d9c6067ca
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1619 (PresentX 1619)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14475 MB

Not tested

  • Native wave64 GPU hardware (AMD/Intel): RTX 3070 only supports wave32, so native wave64 tests skip on this adapter.
  • Sample-gated tests (XCL_SAMPLE_* env vars unset).

AI use

  • Antigravity (Gemini 4 Neon): implemented perm_b32_const in prelude.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.
**@⁠ramon-victor** on GitHub · 2026-11-25 11:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/2267) `ramon-victor:opt/dxil-perm-b32-const-sel` → `main` · +155 −0 · 1 files · 1 commits · open Specializes `Lw::perm_b32` (`v_perm_b32`) in the direct DXIL translator when the byte selector operand `sel` is 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`: - Groups output bytes sharing the same source (`s0` or `s1`) and byte-shift delta into a single shift (and omits the byte mask whenever the shift already zeroes the excluded lanes, reducing identity selectors like `0x03020100`/`0x07060504` to 0 ops and half-packs like `0x05040100` to 3 ops). - Coalesces output bytes sharing the same sign-extension selector (`8..=11`) into a single `ashr` (or `shl 16` + `ashr 31` for bit-15 signs). - Folds constant zero (`12`) and `0xFF` (`>= 13`) bytes directly into a single constant operand. Part of #1269. **What is in it** - `crates/xcl/src/gpu/dxil/prelude.rs`: add `Lw::perm_b32_const`, dispatched from `Lw::perm_b32` when `self.s.m.const_u64(sel)` is `Some(k)` (dynamic selectors stay on the existing loop), plus `perm_b32_const_tests::gpu_direct_perm_b32_const_selector_matches_isa` checking 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 onto `1a0bbe3`), all 573/573 validate cleanly (`0` validator failures): - Total emitted DXIL: `42,232,344 B -> 42,221,860 B` (`-10,484 B`) - Translation time p95: `302.63 ms -> 284.48 ms` **Tested** - Hardware and toolchain: NVIDIA GeForce RTX 3070 (8 GiB, driver `621.24`, wave32), AMD Ryzen 7 5700X, Windows 11 Pro `26300`, `rustc 1.99.0` (`x86_64-pc-windows-msvc`), DXC/DXIL `1.8.2502.11` (Windows SDK `10.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 head `c665154`): `1251 passed; 0 failed; 46 ignored` (25 GPU sub-checks skipped on this wave32 adapter: 21 `no wave64`, 1 `no heap windows`, 3 per-lane `#1426` refusals). - `cargo build --release -p xcl` + direct DXIL validation sweep on 573 sampled retail shader programs: `573/573` translated and `dxil.dll`-validated (`0` failures). **Regression run** ``` xcl-smoke v1 commit: f087b998d0d51a9f11bbfa0761967a63e778edd9 gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14467 MB ``` ``` xcl-smoke v1 commit: c6651548d9b30d1da3929e5cbbe7de1d9c6067ca gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1619 (PresentX 1619) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14475 MB ``` **Not tested** - Native wave64 GPU hardware (AMD/Intel): RTX 3070 only supports wave32, so native wave64 tests skip on this adapter. - Sample-gated tests (`XCL_SAMPLE_*` env vars unset). **AI use** - Antigravity (Gemini 4 Neon): implemented `perm_b32_const` in `prelude.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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:25:02 +00:00
Author
Owner

@⁠itsSio on GitHub · 2026-11-25 12:09 UTC · original

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 --locked and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture exited 0 on both.

GPU / driver CPU, RAM, toolchain Passed / failed / ignored Runtime SKIPPED
RTX 5080 / 32.0.16.1088 Ryzen 7 9800X3D, 32 GiB; Rust 1.97.0, DXC/DXIL 1.9.2609.5 1251 / 0 / 46 25
RTX 2080 SUPER / 32.0.16.1088 Ryzen 5 5600X, 16 GiB; Rust 1.99.1, DXC/DXIL 1.8.2502.11 1251 / 0 / 46 27

cargo 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 (driver 32.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:

  • OpenCode with OpenAI GPT-6.2 Sol (openai/gpt-6.2-sol): scoped and ran the Windows checks, audited the logs and fixture, and wrote this report. No subagents contributed.
**@⁠itsSio** on GitHub · 2026-11-25 12:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/2267#issuecomment-7162004456) **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 --locked` and `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture` exited 0 on both. | GPU / driver | CPU, RAM, toolchain | Passed / failed / ignored | Runtime `SKIPPED` | | --- | --- | ---: | ---: | | RTX 5080 / `32.0.16.1088` | Ryzen 7 9800X3D, 32 GiB; Rust 1.97.0, DXC/DXIL 1.9.2609.5 | 1251 / 0 / 46 | 25 | | RTX 2080 SUPER / `32.0.16.1088` | Ryzen 5 5600X, 16 GiB; Rust 1.99.1, DXC/DXIL 1.8.2502.11 | 1251 / 0 / 46 | 27 | `cargo 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 (driver `32.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: - OpenCode with OpenAI GPT-6.2 Sol (`openai/gpt-6.2-sol`): scoped and ran the Windows checks, audited the logs and fixture, and wrote this report. No subagents contributed.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 12:52 UTC · original

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; debug cargo test --locked -p xcl --lib -j 2 perm_b32_const_tests -- --test-threads=1 --show-output.

  • Clean exact head: gpu_direct_perm_b32_const_selector_matches_isa passed 1/0/0, no skip. Its KernelOptions is hard-coded to wave64: false, so this is a wave32 execution on the wave64-capable adapter.
  • Local test-only variant: I changed only that fixture's KernelOptions to wave64: true, split: false and its capability check from wave32_supported() to wave64_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.

**@⁠luckyteagirl** on GitHub · 2026-11-25 12:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/2267#issuecomment-7162966539) 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`; debug `cargo test --locked -p xcl --lib -j 2 perm_b32_const_tests -- --test-threads=1 --show-output`. - **Clean exact head:** `gpu_direct_perm_b32_const_selector_matches_isa` passed **1/0/0**, no skip. Its `KernelOptions` is hard-coded to `wave64: false`, so this is a wave32 execution on the wave64-capable adapter. - **Local test-only variant:** I changed only that fixture's `KernelOptions` to `wave64: true, split: false` and its capability check from `wave32_supported()` to `wave64_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.
Author
Owner

@⁠nnonno91 on GitHub · 2026-11-25 15:14 UTC · original

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

  • Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Radeon integrated graphics (32.0.21042.62), RTX 5090 (32.0.16.1742), Rust 1.100.0 x64 MSVC, Windows SDK DXC/DXIL 1.8.2502.11. Unoptimized test profile.
  • Clean PR head, 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.
  • Temporary fixture-only variant, 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.

**@⁠nnonno91** on GitHub · 2026-11-25 15:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/2267#issuecomment-7166518115) 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** - Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Radeon integrated graphics (32.0.21042.62), RTX 5090 (32.0.16.1742), Rust 1.100.0 x64 MSVC, Windows SDK DXC/DXIL 1.8.2502.11. Unoptimized test profile. - Clean PR head, `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. - Temporary fixture-only variant, `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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 17:05 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!

**@⁠DavidM1911** on GitHub · 2026-11-25 17:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/2267#issuecomment-7168978039) 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!
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 18:41 UTC · original

Diff review, CI, and both AMD and NVIDIA checks passed on c665154, but recent origin/main merges turned this branch CONFLICTING/DIRTY. Please rebase onto origin/main so it becomes mergeable again.

**@⁠raylitebull** on GitHub · 2026-11-25 18:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/2267#issuecomment-7171249533) Diff review, CI, and both AMD and NVIDIA checks passed on `c665154`, but recent `origin/main` merges turned this branch `CONFLICTING/DIRTY`. Please rebase onto `origin/main` so it becomes mergeable again.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/gpu/dxil/prelude.rs
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.
git fetch -u origin '+refs/pull/2267/head:github-bot/gh-2267'
git switch 'github-bot/gh-2267'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2267'
git switch 'github-bot/gh-2267'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2267'
git switch 'github-bot/gh-2267'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2267'
git switch 'main'
git merge --squash 'github-bot/gh-2267'
git switch 'main'
git merge --ff-only 'github-bot/gh-2267'
git switch 'main'
git merge 'github-bot/gh-2267'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.