Skip to content

Direct DXIL compact: two-level nested dispatch for large class counts - #2174

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
certified-retart:dxil/compact-nested-dispatch
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
certified-retart:dxil/compact-nested-dispatch

Conversation

@certified-retart

Copy link
Copy Markdown
Contributor

Implements two-level nested dispatch for the direct DXIL compact emitter (#2088 workstream 3, part of #1269), staying orthogonal to table-compression work (#2076).

Instead of one flat switch(class) fanning out to every distinct block class and merging all of them back into a single high-fan-in latch, large compact programs now dispatch through an outer switch(class >> shift) into per-group inner switch(class) blocks (with a direct br for a singleton tail group) and merge each group through its own group latch. Each group latch performs the loop-exit check (next >= n ? exit : latch) directly rather than forwarding with an empty unconditional branch; empty group latches were observed to collapse back into near-flat NVIDIA compile times during driver CFG simplification, while per-group exit checks preserve the bounded two-level merge fan-in during SSA promotion without adding extra runtime instructions.

Controlled by XCL_DIRECT_COMPACT_NEST:

  • Unset / auto (default): nests programs with >= 512 distinct classes into groups of 32 (AUTO_NEST_MIN_CLASSES = 512, AUTO_NEST_GROUP_SIZE = 32); keeps a flat switch below 512 classes.
  • 0 / off: forces a flat single-level switch.
  • Power of two in 2..=65536: fixes the inner group size whenever classes > P. Invalid values fall back to auto.

What is in it

  • crates/xcl/src/gpu/dxil/compact.rs: Nest policy enum (Flat, Auto, Fixed(usize)), nest_mode() / parse_nest(), emit_with_nest() emitting two-level switch(class >> shift) -> per-group inner switch(class) -> per-group exit/merge latches (cond_br(next >= n, exit, latch)), with epilogue loads placed in exit.
  • crates/xcl/src/gpu/dxil/kernel.rs: compact_nest_tag() for cache identity and #[cfg(test)] translate_full_nested() threading explicit Nest policies without mutating process env vars.
  • crates/xcl/src/gpu/recomp/pso.rs: folds non-default XCL_DIRECT_COMPACT_NEST tags into the direct-DXIL translated cache identity.
  • crates/xcl/src/gpu/dxil/compact_tests.rs: unit tests for env parsing and group-size resolution (parse_nest_and_group_size_policy), CFG/IR structure test inspecting Module switch fan-out and block predecessor fan-in including a singleton tail group (nested_compact_ir_structure_bounds_switch_fanout_and_merge_fanin), and real-GPU equivalence tests (gpu_nested_compact_matches_plain_and_flat) covering Flat, Fixed(2), Fixed(4), Fixed(8), non-multiple-of-P class counts, and nested loop-budget exhaustion against the plain form.

Controlled cold NVIDIA PSO timings (RTX 5070 12 GB)

  • Hardware/OS: NVIDIA GeForce RTX 5070 12 GB (driver 610.74, 32-lane waves / split wave64), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, Agility SDK v614, DXC 1.9.2602.17.
  • Setup: debug test binary copied to a fresh executable path per run so NVIDIA's implicit shader cache (keyed by exe path, D3D12.X: XCL_BACKGROUND_COMPILES=0 stops the driver's second compiles #1552; ShaderCacheControl(DISABLE) unavailable without Developer Mode) was cold on every first CreateComputePipelineState call, verified by a second call returning in 0.0-0.1 ms. XCL caches were not used. Four root UAV memory windows (mem_windows = 4, no XCL_HEAP_WINDOWS), XCL_DIRECT_COMPACT=1.
  • Measured on the two wanted=true compact compute programs in the retail shader pack plus one forced 1,022-class compute program (hashes of record names, base cbc296a + this PR's compact logic):
Record hash wanted RDNA2 insts Blocks Classes flat (=0) DXIL / cold PSO auto (groups of 32) DXIL / cold PSO fixed 16 DXIL / cold PSO
fd88efc2287f6d8d true 78,920 14,377 617 484,508 B / 7,385.0 ms 484,916 B (+408 B) / 6,026.1 ms (-18.4%) 485,472 B / 5,979.4 ms (-19.0%)
0964b31d760351d6 true 78,524 14,346 590 442,740 B / 6,905.8 ms 443,056 B (+316 B) / 5,032.7 ms (-27.1%) 443,596 B / 4,974.5 ms (-28.0%)
574ab0316665188f false (forced) 21,071 1,155 1,022 1,561,184 B / 119,463.3 ms 1,562,056 B (+872 B) / 101,054.1 ms (-15.4%) 1,562,960 B / 102,289.5 ms (-14.4%)

Every run's second CreateComputePipelineState call completed in 0.0-0.1 ms, confirming the first call was a cold driver compile.

Tested

  • NVIDIA GeForce RTX 5070 12 GB (driver 610.74), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0, DXC 1.9.2602.17, Agility SDK v614.
  • df45043, debug: cargo test -p xcl --lib compact_tests -- --nocapture -> 8 passed, 0 failed, 0 ignored, 0 skipped (including gpu_nested_compact_matches_plain_and_flat, nested_compact_ir_structure_bounds_switch_fanout_and_merge_fanin, and parse_nest_and_group_size_policy).
  • df45043, debug: cargo test --workspace -- --test-threads=4 -> 1,157 passed, 0 failed, 46 ignored across 21 result blocks, with 25 SKIPPED lines (20 native wave64 on wave32 GPU, 3 pre-existing per-lane f16/f32 refusals, 1 pso_measurement_compiles_an_exact_synthetic_record due to Developer Mode off, 1 heap_window_out_of_memory_falls_back_to_the_switch_form due to no heap windows).

Regression run

60 s retail title run, release build (cargo build --release -p xcl), fresh XCL_DXIL_CACHE, default environment (note: origin/main cbc296a..568e7db changed only README.md and assets/readme/*.svg).

main cbc296a:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 5070
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1682 (PresentX 1682)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15030 MB

This PR, head df45043:

xcl-smoke v1
commit: df450437987e300567610ab91902f1999fd3e9e4
gpu: NVIDIA GeForce RTX 5070
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1665 (PresentX 1665)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14136 MB

99.0 % of main's frames, 94.1 % of main's peak commit, sustained 60 60 60 presents, 0 device removals, 0 crashes.

Not tested

  • Live title run with XCL_DIRECT_DXIL=1 reaching the 590/617-class compact compute shaders (the default smoke run above uses the HLSL path, so it verifies zero regression on the default path; direct compact execution equivalence is verified by the GPU tests in compact_tests.rs).
  • GPU execution-time microbenchmark of nested vs flat compact on the 590/617-class retail programs (only cold PSO build times were measured on those records; dispatch-loop instruction count per block step adds one lshr + second switch branch and keeps the same single next >= n check per step).
  • AMD, Intel, Linux/vkd3d-proton, native 64-lane hardware, and XCL_HEAP_WINDOWS=1 combined with nested direct compact.
  • Composition with Recompiler: direct compact form stores a branch's target in the entry #2076's 2,643-class compact program (95cc13288a27a96e / ef65b99fa3f04179), which exceeds main's 8,192-word table limit until target compression lands.

AI use

  • Gemini wrote the implementation, tests, benchmark harness, and this description, and ran the workspace tests, cold NVIDIA PSO benchmarks, and smoke run on local hardware.

Adds two-level nested dispatch (outer switch on class >> shift, per-group inner switches, and per-group exit/merge latches) to the direct DXIL compact emitter (xcl-dev#2088 workstream 3, part of xcl-dev#1269). Controlled by XCL_DIRECT_COMPACT_NEST (default/auto: groups of 32 for >= 512 classes; 0/off: flat; power of two in 2..=65536: fixed group size) and folded into the direct DXIL translated cache identity.
@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Related work: Pipodi's #1692 → #2018 → #2025 do the same two-level nesting for the HLSL compact dispatch (gpu/recomp/compact.rs). #2018 nests programs of 512 cases or more under XCL_COMPACT_NEST=auto, and #2025 makes it the default. This PR does it for the direct DXIL compact emitter at the same 512 threshold, under XCL_DIRECT_COMPACT_NEST. The two don't overlap in code: git merge-tree of df45043 with #2025's f698c22 is clean. A maintainer may still want one variable, threshold and group-size policy for both paths, and linking the threads would help whoever measures them. Each path's compile-time gain was measured separately.

AI-assisted (Claude Code); source read and git merge-tree only.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@DarkPanda69

Copy link
Copy Markdown

Tested: gpu_nested_compact_matches_plain_and_flat passes on AMD with native 64-lane waves and on an RTX 3060 (split wave64).

Head df45043 applied on main 568e7db, debug, cargo test -p xcl --lib -- gpu:: --test-threads=4 with XCL_ADAPTER set to each card.
Not tested: a live title with XCL_DIRECT_DXIL=1 reaching the 590/617-class programs.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@bielfreedom

Copy link
Copy Markdown

AMD RDNA4 timing for #2174: the two programs it nests on the RX 9070 XT build 4.9× faster and with less than half the memory. ActivateProbes went from 70.6 s to 14.4 s, ActivateProbesTarget from 59.3 s to 12.3 s, and peak private from 11.3 to 5.0 GB. It complements @DarkPanda69's GPU test run on the same card.

Setup

  • GPU: RX 9070 XT 16 GB (RDNA4, native wave64), AMD driver 32.0.32029.2010.
  • CPU and memory: Ryzen 7 7700, 32 GB RAM, Windows 11, release.
  • Builds:
    • this PR's base 568e7db;
    • this PR at df45043.
  • 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_DIRECT_COMPACT_NEST unset (auto), 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.
  • 2 rounds, interleaved.
  • Census of all 2,689 retail compute programs on both builds: only two programs change on this adapter. They are the two that main already compacts.
program direct DXIL base → PR driver, base (r1 / r2) driver, #2174 (r1 / r2) faster
56c0cd3b82a00c6e ActivateProbes 446,812 → 447,224 B 71.4 / 69.8 s 14.4 / 14.4 s 4.9×
958400d2caf07244 ActivateProbesTarget 406,644 → 406,944 B 59.6 / 58.9 s 12.3 / 12.3 s 4.8×
process peak private (both built in turn) 11.27 GB 5.03 GB

All 8 builds succeeded, with 0 refused.

ActivateRays (95cc13288a27a96e): still not buildable on this card, but slower to blow up. On AMD, main and #2076's current head keep this program plain because of the 8,192-word table limit. To see whether nesting rescues its 2,643-case compact form here, I merged this PR with #2076's earlier head f1b313f, whose larger table applied on every GPU. The merge was clean.

form of ActivateRays DXIL AMD driver
plain (main) 3,916,120 B 24 GB after about 205 s, killed (#2076 data)
compact, flat switch (#2076 f1b313f) 1,249,504 B 24 GB after 31 s, killed
compact, nested (#2076 f1b313f + this PR) 1,251,660 B 24 GB after 76–77 s, killed (2 of 2 rounds)

So on the AMD compiler nesting cuts the memory growth rate of this program by about 2.5×, but that isn't enough. A program of about 600 cases builds within about 5 GB; one of 2,643 cases still passes 24 GB.

Read / inference

  • On RDNA4 the AMD compiler gains more from the bounded merge fan-in than the NVIDIA numbers in the description suggest: about 5× faster and about 2.2× less memory on both affected programs. For the default (auto, 512 or more classes) this looks like a clear win on AMD Windows.
  • For ActivateRays on AMD, a smaller group size or a third level might be worth a try with XCL_DIRECT_COMPACT_NEST=8 or 16 on the f1b313f combination. I can run that if useful.

Not tested

  • GPU output (covered by DarkPanda69's test run).
  • Other XCL_DIRECT_COMPACT_NEST values.
  • A title run.
  • RDNA2 and RDNA3.

AI use: Claude Code (Claude Opus 5.5) ran the census and measurements and drafted this. The account owner is away; counts and timings only, no game data.

@bielfreedom

Copy link
Copy Markdown

Follow-up on ActivateRays with smaller groups: same combination (#2076 f1b313f + this PR), same card and method, XCL_DIRECT_COMPACT_NEST set explicitly, 1 run each.

group size direct DXIL AMD driver
flat (no nest) 1,249,504 B 24 GB after 31 s, killed
32 (auto) 1,251,660 B 24 GB after 76–77 s, killed
16 1,253,864 B 24 GB after 121 s, killed
8 1,257,952 B 24 GB after 264 s, killed
  • Each halving of the group roughly halves the rate at which the AMD compiler's memory grows on this program.
  • Even at 8, the build passes 24 GB without finishing.
  • On RDNA4 the 2,643-case form seems to need more than a smaller inner switch: a third level, or splitting the program (Recompiler: split large direct compute pipelines at CFG edges #2080's chain), would be the next things to try. I didn't test either.

AI use: Claude Code (Claude Opus 5.5) ran this and wrote it. Account owner away; counts and timings only.

@itsSio

itsSio commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Tested

Independent clean-head Windows verification of df450437987e300567610ab91902f1999fd3e9e4; no local merge or patches. Both PCs ran cargo build --workspace --locked and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture (all exit 0). Unoptimized MSVC dev/test profiles, debug info off, no XCL_SAMPLE_* variables and no shader-backend overrides for the workspace suite.

GPU and driver System and toolchain Passed / failed / ignored Runtime SKIPPED events
GeForce RTX 5080, 32.0.16.1088 Windows 11 Pro 26200, Ryzen 7 9800X3D, 32 GiB, Rust 1.97.0, DXC 1.9.2609.5 1157 / 0 / 46 25
GeForce RTX 2080 SUPER 8 GB, 32.0.16.1088 Windows 11 Pro 26200, Ryzen 5 5600X, 16 GiB, Rust 1.99.1, DXC 1.8.2502.11 1157 / 0 / 46 27

Both NVIDIA runs logged 20 skips for no native wave64, three per-lane refusals (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32), one no-heap-windows skip (heap_window_out_of_memory_falls_back_to_the_switch_form) and one driver-cache-disable skip (pso_measurement_compiles_an_exact_synthetic_record, 0x887A002D). The RTX 2080 SUPER run also logged two D3D12-debug-layer skips (test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state).

cargo test -p xcl --lib --locked gpu::dxil::compact_tests -- --test-threads=1 --nocapture returned 8 passed / 0 failed / 0 ignored / 0 skipped separately on the RTX 5080, RTX 2080 SUPER, and 9800X3D Radeon RDNA2 iGPU (XCL_ADAPTER=radeon, driver 32.0.21043.5001). gpu_nested_compact_matches_plain_and_flat ran on each, covering split wave64 on NVIDIA and native wave64 on Radeon, including the singleton tail and loop-budget exit.

Not tested: Full AMD workspace suite, release builds, retail smoke, retail shader inputs, or cold compile and warm GPU timing. No performance improvement is inferred from these checks.

AI use

Ran via Samaritan:

  • OpenCode with OpenAI GPT-6.2 Sol: checked for overlap, ran the tests on both Windows PCs, checked the result and skip counts, and wrote this report.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent native Windows RDNA2 check on exact head df450437987e300567610ab91902f1999fd3e9e4 (base 568e7db7729c8fa6c8f0f4b32d798faaf11462bb), clean detached worktree.

Environment: Windows 11 build 26200; Ryzen 9 5980HX; AMD Radeon RX 6800M (native wave64), 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, matching XCL_DXC_DIR.

cargo test --locked -p xcl --lib -j 2 compact_tests -- --test-threads=1 --show-output: 8 passed, 0 failed, 0 ignored, no explicit skips. The focused gpu_nested_compact_matches_plain_and_flat also passed alone 1/0/0. Its checked-in GPU fixture compares plain, flat, and nested group sizes 2/4/8 on a repeated-block program, 4/8 on a 17-class program with a singleton tail, and a nested loop-budget exit. This adds native wave64 RDNA2 execution to the existing NVIDIA and RDNA4 reports.

Scope: Focused debug tests using synthetic programs with one memory window. I did not measure cold RX 6800M driver PSO times, run the 590/617-class retail programs, run a full suite, or launch a title with direct compact mode. The pass establishes the tested kernel equivalence, not the stated compile-time benefit on this GPU.

AI use: OpenAI Codex inspected the GPU fixture, ran the focused and eight-test filters, verified no skips and the exact clean revision, and prepared this report.

@PHeitor1

Copy link
Copy Markdown

Blackwell run on a newer driver (621.24; the RTX 50 runs I saw in this thread are on 610.74 and 610.88): no new failure against main, no hang.

Tested

  • RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300, rustc 1.100.0 MSVC, DXC 1.9.2602.17, debug, Developer Mode off, no XCL_SAMPLE_*. Exact head df45043, clean tree; cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4:
default XCL_DIRECT_DXIL=1
main 568e7db (its base) 1150 passed, 4 failed, 46 ignored 1148 passed, 6 failed, 46 ignored
this PR df45043 1153 passed, 4 failed, 46 ignored 1151 passed, 6 failed, 46 ignored

git merge-tree of this head with #2080 (8eefdef) conflicts; with #1919 (5835139) it is clean.

Not tested: a shader pack, a title, cold build times, GPU time, release, other XCL_DIRECT_COMPACT_NEST values set from the environment.

Run and written with Claude Code (Claude Opus 5.5).

@ClosetPie107

Copy link
Copy Markdown

Linux / AMD RDNA4 (RADV) test report on exact head df45043 (clean detached worktree).

Environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1, native wave64), Ryzen 5 9600X, 30 GiB RAM, CachyOS
  • Proton Experimental (experimental-11.0-20261112), vkd3d-proton v3.1 (#257 + dxil-spirv 53aac418), DXVK v3.1.1-209, DXC 1.9.2609.5, x86_64-pc-windows-gnu cross-compile

Unit & GPU tests (debug test binary, XCL_ADAPTER=9070 XCL_REQUIRE_GPU=wave64, --test-threads=1 --nocapture)

  • Default (gpu::dxil::compact_tests): 8 passed, 0 failed, 0 ignored, 0 skipped (2.14 s)
  • XCL_DIRECT_DXIL=1 (gpu::dxil::compact_tests): 8 passed, 0 failed, 0 ignored, 0 skipped (2.09 s), including gpu_nested_compact_matches_plain_and_flat on native wave64 RADV.

Cold RADV PSO timings (release xcl.exe shaders <dir> --precompile --only cs --pipelines --direct, XCL_DIRECT_DXIL=1 XCL_DIRECT_COMPACT=1, MESA_SHADER_CACHE_DISABLE=true, VKD3D_SHADER_CACHE_PATH=0, fresh XCL_DXIL_CACHE, MemoryMax=22G, MemorySwapMax=0):

Record Classes nest=0 (flat) nest=auto (32) nest=16
ActivateProbes (9083c094) 599 9.8 s compile (10.4 s wall) / 2.31 GiB peak 7.4 s (-24.5%) (7.6 s wall) / 2.18 GiB 8.0 s (8.2 s wall) / 2.23 GiB
ActivateProbesTarget (534f271f) 573 8.3 s compile (8.4 s wall) / 1.79 GiB peak 6.3 s (-24.1%) (6.5 s wall) / 1.74 GiB 6.7 s (6.8 s wall) / 1.73 GiB
ActivateRays (d60186e6, forced) 2,643 OOM (>22 GiB) at 75.4 s OOM (>22 GiB) at 8.8 s OOM (>22 GiB) at 9.5 s

Both ActivateProbes and ActivateProbesTarget reported pipelines made on the GPU 1, refused 0, pipelines loaded from the driver cache 0.

Not tested: full workspace suite, retail title run, warm GPU runtime.

AI use: T3 Code / Antigravity (Gemini 4 Neon) built and ran these tests on this machine and drafted this report.

anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
Brings main to full parity with upstream/main (cdb0891), including:
- World rendering & gameplay: xcl-dev#1991, xcl-dev#1988, xcl-dev#1984, xcl-dev#2028, xcl-dev#2078
- Memory / VRAM / PSO: xcl-dev#1985, xcl-dev#2157, xcl-dev#2178, xcl-dev#2195, xcl-dev#2176, xcl-dev#1996, xcl-dev#1914
- Direct DXIL & shaders: xcl-dev#2120, xcl-dev#2174, xcl-dev#2194, xcl-dev#2207, xcl-dev#1951, xcl-dev#1973, xcl-dev#2156, xcl-dev#2064
- Preserves local Linux/Wine customizations: docs/linux.md, scripts/linux/*,
  in-process Wine XAsync (xgameruntime/api.rs), loader watchdog bypass, and
  Wine MEM_WRITE_WATCH bypass on coherent UMA windows (gpu/uma.rs).

Assisted-by: Antigravity (Gemini 4)
raylitebull pushed a commit that referenced this pull request Nov 25, 2026
This takes out e964ad2, which kept the table limit of 8,192 words on a
GPU with 64-lane waves. It was added after a run on an RX 9070 XT at
cbc296a, where neither form of the program it let in built within
24 GB and the compact form reached that sooner. Since #2174 the compact
form nests its dispatch by default, and on the same card model with
64 GB that program's nested compact form built in 159 to 203 s at about
34 GB with heap memory windows, where its plain form, which the guard
kept, passed 48 GB (komglebissarov on #2088, 1 run per form). With the
default switch windows both forms passed 48 GB, so that path does not
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 25, 2026
This takes out e964ad2, which kept the table limit of 8,192 words on a
GPU with 64-lane waves. It was added after a run on an RX 9070 XT at
cbc296a, where neither form of the program it let in built within
24 GB and the compact form reached that sooner. Since xcl-dev#2174 the compact
form nests its dispatch by default. On RX 9070 XTs with heap memory
windows that program's nested compact form built in 138 to 203 s, at
17.6 GB on a 32 GB machine and 33.9 GB on a 64 GB one, where the plain
form the guard kept passed 24 and 48 GB (bielfreedom on xcl-dev#2375,
komglebissarov on xcl-dev#2088). With the default switch windows neither form
built within 24 GB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants