Recompiler: compress per-class branch targets in direct DXIL compact #2356

Closed
github-bot wants to merge 1 commit from github-bot/gh-2356 into main AGit
Owner

@⁠safesearch77 on GitHub · 2026-11-25 16:29 UTC · original
safesearch77:feat/dxil-compact-target-compression → main · +313 −63 · 2 files · 1 commits · closed without merging

Implements #2088 Workstream 2 in the direct-DXIL compact planner (crates/xcl/src/gpu/dxil/compact.rs), porting #1448's per-class bounded branch-target selection so large repeating compute shaders with shared branch targets or varied per-class branch distances fit within the existing MAX_TABLE_WORDS = 8,192 table budget without storing two xcl_steps words per distinct global offset pair.

Part of #2088
Part of #1269

What is in it

  • crates/xcl/src/gpu/dxil/compact.rs:
    • Replaces the global xcl_steps offset-pair table (2 words per globally distinct (t - b, f - b) pair) with per-class sorted (Leg, Leg) transition palettes (Leg::Abs(block) vs Leg::Rel(offset) chosen per leg by intra-class frequency, preferring Abs on ties so singleton classes emit constants without adds).
    • Packs (class | choice << cb) into xcl_blocks alone (pb = 0 bits when every class has a single transition), removing the two xcl_steps global loads from head.
    • Lowers per-class target choices in emit_next using balanced branchless select trees (with a single add per pure-Rel leaf) up to SELECT_LEAF_MAX = 32, splitting larger per-class target lists (many_targets) with a topological binary cond_br + 2-input phi tree so every basic block stays within <= 32 selects and nested dispatch (#2174) preserves its bounded latch fan-in.
    • Keeps large(cfg) >= 20,000, once * 10 < all * 3, and MAX_TABLE_WORDS = 8,192 unchanged, and gates wanted() on both p.words() <= MAX_TABLE_WORDS and p.palette_len() <= MAX_TABLE_WORDS so ordinary programs remain on their current route and total palette IR stays bounded.
  • crates/xcl/src/gpu/dxil/compact_tests.rs:
    • pathological_shared_exits_compress_and_keep_ordinary_programs_plain: verifies a 4,200-block shared-exit program (10,373 table words and rejected on main) compresses to 264 words (326,772 B plain -> 3,692 B compact DXIL) and becomes automatically eligible, while < 20,000-instruction and non-repeating programs stay plain.
    • wanted_rejects_excessive_palette_entries_even_when_block_table_fits: verifies wanted() refuses a program whose p.words() (4,783) fits under MAX_TABLE_WORDS when p.palette_len() (10,201) exceeds MAX_TABLE_WORDS.
    • many_targets_bounds_select_leaves_and_steps_match_cfg: verifies Plan::pack_blocks + Plan::step against Cfg across all reachable blocks on an 80-target class and checks that no lowered basic block exceeds SELECT_LEAF_MAX = 32 selects.
    • gpu_target_compressed_and_many_targets_run_as_plain: checks GPU register parity (sgpr, vgpr across 64 lanes, scc) for shared_exits(60) and many_targets(80) in Nest::Flat and Nest::Fixed(4) against plain DXIL.

Tested

  • Linux host (x86_64-unknown-linux-gnu / cross-check target x86_64-pc-windows-gnu), base 68a284a (rebased onto #2076), head ff97165.
  • cargo check --offline --target x86_64-pc-windows-gnu --workspace --tests: exit 0 (0 errors, 0 warnings in gpu::dxil).
  • Host CPU execution of gpu::dxil::compact_tests (on 06c9f55 base, re-typechecked on 68a284a): 12 passed, 0 failed (4 gpu_* tests cleanly SKIPPED: no GPU).
  • Synthetic DXIL size & planner table measurements (wave64 = true, split = true, mem_windows = 1, 0829441 -> ff97165):
    • shared_exits(1000): 2,379 -> 64 words (-97.3%), forced-compact DXIL 13,044 -> 3,540 B (-72.9%).
    • shared_exits(4200): 10,373 -> 264 words (wanted: false -> true), translate_full DXIL 326,772 -> 3,692 B (-98.9%).
    • multi_cls_outlier(5000) (603 classes, 5,001 pairs): 13,598 -> 1,564 words (wanted: false -> true), translate_full DXIL 394,664 -> 52,580 B (-86.7%).

Not tested

  • Windows D3D12 GPU execution of gpu_target_compressed_and_many_targets_run_as_plain and DXC dxcompiler.dll IDxcValidator validation (developed and typechecked on Linux without a Windows GPU host; opened as Draft until Windows GPU suite and scripts/smoke.ps1 regression runs are attached).
  • Controlled cold NVIDIA CreateComputePipelineState timings and DXIL byte counts on the 76,699-instruction retail compute outlier (XCL_DIRECT_DXIL=1 / XCL_DIRECT_DXIL=all).

AI use

  • Antigravity (Gemini 4 Carbon) implemented per-class branch-target compression and bounded selection trees in compact.rs and tests in compact_tests.rs; reviewed with Claude Opus 5.5.
**@⁠safesearch77** on GitHub · 2026-11-25 16:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/2356) `safesearch77:feat/dxil-compact-target-compression` → `main` · +313 −63 · 2 files · 1 commits · closed without merging Implements #2088 Workstream 2 in the direct-DXIL compact planner (`crates/xcl/src/gpu/dxil/compact.rs`), porting `#1448`'s per-class bounded branch-target selection so large repeating compute shaders with shared branch targets or varied per-class branch distances fit within the existing `MAX_TABLE_WORDS = 8,192` table budget without storing two `xcl_steps` words per distinct global offset pair. Part of #2088 Part of #1269 **What is in it** - `crates/xcl/src/gpu/dxil/compact.rs`: - Replaces the global `xcl_steps` offset-pair table (`2` words per globally distinct `(t - b, f - b)` pair) with per-class sorted `(Leg, Leg)` transition palettes (`Leg::Abs(block)` vs `Leg::Rel(offset)` chosen per leg by intra-class frequency, preferring `Abs` on ties so singleton classes emit constants without `add`s). - Packs `(class | choice << cb)` into `xcl_blocks` alone (`pb = 0` bits when every class has a single transition), removing the two `xcl_steps` global loads from `head`. - Lowers per-class target choices in `emit_next` using balanced branchless `select` trees (with a single `add` per pure-`Rel` leaf) up to `SELECT_LEAF_MAX = 32`, splitting larger per-class target lists (`many_targets`) with a topological binary `cond_br` + 2-input `phi` tree so every basic block stays within `<= 32` `select`s and nested dispatch (`#2174`) preserves its bounded latch fan-in. - Keeps `large(cfg) >= 20,000`, `once * 10 < all * 3`, and `MAX_TABLE_WORDS = 8,192` unchanged, and gates `wanted()` on both `p.words() <= MAX_TABLE_WORDS` and `p.palette_len() <= MAX_TABLE_WORDS` so ordinary programs remain on their current route and total palette IR stays bounded. - `crates/xcl/src/gpu/dxil/compact_tests.rs`: - `pathological_shared_exits_compress_and_keep_ordinary_programs_plain`: verifies a 4,200-block shared-exit program (`10,373` table words and rejected on `main`) compresses to `264` words (`326,772 B` plain -> `3,692 B` compact DXIL) and becomes automatically eligible, while `< 20,000`-instruction and non-repeating programs stay plain. - `wanted_rejects_excessive_palette_entries_even_when_block_table_fits`: verifies `wanted()` refuses a program whose `p.words()` (`4,783`) fits under `MAX_TABLE_WORDS` when `p.palette_len()` (`10,201`) exceeds `MAX_TABLE_WORDS`. - `many_targets_bounds_select_leaves_and_steps_match_cfg`: verifies `Plan::pack_blocks` + `Plan::step` against `Cfg` across all reachable blocks on an 80-target class and checks that no lowered basic block exceeds `SELECT_LEAF_MAX = 32` `select`s. - `gpu_target_compressed_and_many_targets_run_as_plain`: checks GPU register parity (`sgpr`, `vgpr` across 64 lanes, `scc`) for `shared_exits(60)` and `many_targets(80)` in `Nest::Flat` and `Nest::Fixed(4)` against plain DXIL. **Tested** - Linux host (`x86_64-unknown-linux-gnu` / cross-check target `x86_64-pc-windows-gnu`), base `68a284a` (rebased onto #2076), head `ff97165`. - `cargo check --offline --target x86_64-pc-windows-gnu --workspace --tests`: exit 0 (`0` errors, `0` warnings in `gpu::dxil`). - Host CPU execution of `gpu::dxil::compact_tests` (on `06c9f55` base, re-typechecked on `68a284a`): 12 passed, 0 failed (`4` `gpu_*` tests cleanly `SKIPPED: no GPU`). - Synthetic DXIL size & planner table measurements (`wave64 = true, split = true, mem_windows = 1`, `0829441` -> `ff97165`): - `shared_exits(1000)`: `2,379` -> `64` words (`-97.3%`), forced-compact DXIL `13,044` -> `3,540 B` (`-72.9%`). - `shared_exits(4200)`: `10,373` -> `264` words (`wanted`: `false` -> `true`), `translate_full` DXIL `326,772` -> `3,692 B` (`-98.9%`). - `multi_cls_outlier(5000)` (`603` classes, `5,001` pairs): `13,598` -> `1,564` words (`wanted`: `false` -> `true`), `translate_full` DXIL `394,664` -> `52,580 B` (`-86.7%`). **Not tested** - Windows D3D12 GPU execution of `gpu_target_compressed_and_many_targets_run_as_plain` and DXC `dxcompiler.dll` `IDxcValidator` validation (developed and typechecked on Linux without a Windows GPU host; opened as Draft until Windows GPU suite and `scripts/smoke.ps1` regression runs are attached). - Controlled cold NVIDIA `CreateComputePipelineState` timings and DXIL byte counts on the 76,699-instruction retail compute outlier (`XCL_DIRECT_DXIL=1` / `XCL_DIRECT_DXIL=all`). **AI use** - Antigravity (Gemini 4 Carbon) implemented per-class branch-target compression and bounded selection trees in `compact.rs` and tests in `compact_tests.rs`; reviewed with Claude Opus 5.5.
Replaces the global two-word-per-pair xcl_steps offset table in
gpu::dxil::compact with per-class sorted (Leg::Abs, Leg::Rel) palettes
and bounded select/cond_br trees (SELECT_LEAF_MAX = 32), capping both
words() and palette_len() at MAX_TABLE_WORDS and keeping ordinary
programs on their current route (#2088).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:28:46 +00:00
Author
Owner

@⁠bielfreedom on GitHub · 2026-11-25 17:57 UTC · original

AMD Windows driver timing for #2356: on the RX 9070 XT this changes only the two programs main already compacts. One of them builds about 1.5× slower in AMD's driver.

Setup

  • GPU: RX 9070 XT 16 GB (RDNA4, native wave64), AMD driver 32.0.32029.2010.
  • CPU and memory: Ryzen 7 7700 (16 threads), 32 GB RAM, Windows 11, release.
  • Builds:
    • this PR's parent 0829441;
    • this PR at 2707887.
  • Both builds carry a local patch that logs per-program DXIL size, record hash (fnv64) and per-CreateComputePipelineState time.

Method

  • XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=0, XCL_PIPELINE_THREADS=1.
  • XCL_PSO_DISK_CACHE=0 and a fresh exe name per run, because the AMD driver cache is keyed on the exe file name.
  • 3 rounds, interleaved.
  • The machine was in light desktop use, so single builds vary by about ±15 %.

Census (all 2,689 retail compute programs, translation only): 2 programs change, both smaller. ActivateRays (95cc13288a27a96e) stays plain on this adapter, 2,420,640 B, as on main.

program direct DXIL base → PR driver base (3 rounds) driver #2356 (3 rounds) mean
56c0cd3b82a00c6e ActivateProbes 441,040 → 434,072 B (−1.6 %) 17.3 / 16.4 / 21.1 s 15.9 / 17.2 / 19.8 s 18.3 → 17.6 s (−4 %)
958400d2caf07244 ActivateProbesTarget 401,800 → 394,712 B (−1.8 %) 15.5 / 12.6 / 16.3 s 21.0 / 20.3 / 24.9 s 14.8 → 22.1 s (+49 %)
  • All 12 builds succeeded.
  • The driver run's peak private went 4.94–4.96 GB → 4.73–4.74 GB.
  • ActivateProbesTarget was slower in every round. The slowest base round (16.3 s) is below the fastest PR round (20.3 s).

Read / inference

  • On the AMD compiler, the per-class transition palettes cost more for ActivateProbesTarget than the smaller table saves, even though the module is 1.8 % smaller. ActivateProbes is unchanged within noise.
  • On this card nothing gets newly compacted, so the PR's main aim (fitting more programs under the table budget) doesn't show here, and the one measurable change is a slowdown. If the NVIDIA side gains, one option is to keep the global xcl_steps table on 64-lane-wave GPUs, like the #2076 guard did.

Not tested

  • GPU output.
  • XCL_HEAP_WINDOWS=1.
  • A title run.
  • RDNA2 and RDNA3.
  • The PR's own tests on this card.

AI use: Claude Code (Claude Opus 5.5) ran the census and measurements and drafted this. Counts and timings only, no game data.

**@⁠bielfreedom** on GitHub · 2026-11-25 17:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/2356#issuecomment-7170226507) **AMD Windows driver timing for #2356: on the RX 9070 XT this changes only the two programs `main` already compacts. One of them builds about 1.5× slower in AMD's driver.** **Setup** - GPU: RX 9070 XT 16 GB (RDNA4, native wave64), AMD driver 32.0.32029.2010. - CPU and memory: Ryzen 7 7700 (16 threads), 32 GB RAM, Windows 11, release. - Builds: - this PR's parent `0829441`; - this PR at `2707887`. - Both builds carry a local patch that logs per-program DXIL size, record hash (`fnv64`) and per-`CreateComputePipelineState` time. **Method** - `XCL_DIRECT_DXIL=1`, `XCL_HEAP_WINDOWS=0`, `XCL_PIPELINE_THREADS=1`. - `XCL_PSO_DISK_CACHE=0` and a fresh exe name per run, because the AMD driver cache is keyed on the exe file name. - 3 rounds, interleaved. - The machine was in light desktop use, so single builds vary by about ±15 %. **Census** (all 2,689 retail compute programs, translation only): 2 programs change, both smaller. ActivateRays (`95cc13288a27a96e`) stays plain on this adapter, 2,420,640 B, as on `main`. | program | direct DXIL base → PR | driver base (3 rounds) | driver #2356 (3 rounds) | mean | |---|---:|---|---|---:| | `56c0cd3b82a00c6e` ActivateProbes | 441,040 → 434,072 B (−1.6 %) | 17.3 / 16.4 / 21.1 s | 15.9 / 17.2 / 19.8 s | 18.3 → 17.6 s (−4 %) | | `958400d2caf07244` ActivateProbesTarget | 401,800 → 394,712 B (−1.8 %) | 15.5 / 12.6 / 16.3 s | **21.0 / 20.3 / 24.9 s** | **14.8 → 22.1 s (+49 %)** | - All 12 builds succeeded. - The driver run's peak private went 4.94–4.96 GB → 4.73–4.74 GB. - ActivateProbesTarget was slower in every round. The slowest base round (16.3 s) is below the fastest PR round (20.3 s). **Read / inference** - On the AMD compiler, the per-class transition palettes cost more for ActivateProbesTarget than the smaller table saves, even though the module is 1.8 % smaller. ActivateProbes is unchanged within noise. - On this card nothing gets newly compacted, so the PR's main aim (fitting more programs under the table budget) doesn't show here, and the one measurable change is a slowdown. If the NVIDIA side gains, one option is to keep the global `xcl_steps` table on 64-lane-wave GPUs, like the #2076 guard did. **Not tested** - GPU output. - `XCL_HEAP_WINDOWS=1`. - A title run. - RDNA2 and RDNA3. - The PR's own tests on this card. AI use: Claude Code (Claude Opus 5.5) ran the census and measurements and drafted this. Counts and timings only, no game data.
Author
Owner

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

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 143 real failures, deterministic (also fail --test-threads=1, 1064/143):

Every DXC compile of the generated HLSL prelude fails:

dxc: hlsl.hlsl:437:47: error: modifiers must appear before type
uint norm_code_to_f16(uint code, uint w, bool snorm) {
                                              ^
hlsl.hlsl:439:29: error: expected expression
    uint period = w - (uint)snorm;
hlsl.hlsl:440:25: error: expected expression
    bool negative = and(snorm, (code & (1u << (w - 1u))) != 0u);

The parameter name snorm collides with the HLSL snorm texture modifier keyword — rename it (e.g. signed_norm) and the whole suite should recover. Serious breakage, needs a fix before merge.

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-25 18:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/2356#issuecomment-7171257964) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: **143 real failures**, deterministic (also fail `--test-threads=1`, 1064/143): Every DXC compile of the generated HLSL prelude fails: ``` dxc: hlsl.hlsl:437:47: error: modifiers must appear before type uint norm_code_to_f16(uint code, uint w, bool snorm) { ^ hlsl.hlsl:439:29: error: expected expression uint period = w - (uint)snorm; hlsl.hlsl:440:25: error: expected expression bool negative = and(snorm, (code & (1u << (w - 1u))) != 0u); ``` The parameter name `snorm` collides with the HLSL `snorm` texture modifier keyword — rename it (e.g. `signed_norm`) and the whole suite should recover. Serious breakage, needs a fix before merge. — Devin
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 19:06 UTC · original

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 target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).
suite: 145/3 = the three known baseline failures on this lane (fuzz_validate_and_gpu_2 seed 1003, gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_depth_buffer_created_for_unordered_access_is_placed). Targeted run of the two new budget tests: 2 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.

**@⁠SlopTart** on GitHub · 2026-11-25 19:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/2356#issuecomment-7171818142) **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 target `x86_64-pc-windows-gnu` run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29). suite: 145/3 = the three known baseline failures on this lane (`fuzz_validate_and_gpu_2` seed 1003, `gpu_nonfused_mad_and_mac_prevent_fma_contraction`, `gpu_depth_buffer_created_for_unordered_access_is_placed`). Targeted run of the two new budget tests: 2 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.
github-bot closed this pull request 2026-11-26 14:11:26 +00:00
Author
Owner

@⁠bmjask on GitHub · 2026-11-25 20:45 UTC · original · reviewed

No confirmed source-level compact-palette/selection defect found, but this is not merge-ready. Current PR-description checks fail and there is no Windows GPU/DXC-validator/smoke evidence. An RX 9070 XT measurement shows one changed shader regressing from 14.8s to 22.1s driver build time (+49%) despite smaller DXIL; investigate or gate native-wave64 AMD behavior (for example retain xcl_steps) before merge. Do not attribute reported snorm DXC failures without reproduction: discussion identifies that as a separate base/prelude issue.

**@⁠bmjask** on GitHub · 2026-11-25 20:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/2356#pullrequestreview-6064745828) · **reviewed** No confirmed source-level compact-palette/selection defect found, but this is not merge-ready. Current PR-description checks fail and there is no Windows GPU/DXC-validator/smoke evidence. An RX 9070 XT measurement shows one changed shader regressing from 14.8s to 22.1s driver build time (+49%) despite smaller DXIL; investigate or gate native-wave64 AMD behavior (for example retain xcl_steps) before merge. Do not attribute reported snorm DXC failures without reproduction: discussion identifies that as a separate base/prelude issue.
Author
Owner

@⁠safesearch77 on GitHub · 2026-11-26 14:07 UTC · original

Closing this draft: as @⁠bielfreedom and @⁠bmjask measured on RX 9070 XT, compressing per-class branch targets here regresses AMD driver PSO compile time on one of the two affected shaders (14.8s -> 22.1s, +49%), and #2076 / #2257 have since landed cleaner compact-nesting changes on main. Thanks to @⁠bielfreedom, @⁠DavidM1911, @⁠SlopTart, and @⁠bmjask for the testing and review!

**@⁠safesearch77** on GitHub · 2026-11-26 14:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/2356#issuecomment-7194323240) Closing this draft: as @⁠bielfreedom and @⁠bmjask measured on RX 9070 XT, compressing per-class branch targets here regresses AMD driver PSO compile time on one of the two affected shaders (14.8s -> 22.1s, +49%), and #2076 / #2257 have since landed cleaner compact-nesting changes on main. Thanks to @⁠bielfreedom, @⁠DavidM1911, @⁠SlopTart, and @⁠bmjask for the testing and review!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.