Skip to content

Recompiler: nest the compact dispatch of big programs by default - #2025

Open
Pipodi wants to merge 9 commits into
xcl-dev:mainfrom
Pipodi:nest-default
Open

Pipodi wants to merge 9 commits into
xcl-dev:mainfrom
Pipodi:nest-default

Conversation

@Pipodi

@Pipodi Pipodi commented Nov 25, 2026 •

Copy link
Copy Markdown

Stacked on #2018 (908c454, on #1692 2046259, #1448 80fac65 and #1316 5328b15); only the top commit (eee2b86) belongs here.

With XCL_COMPACT_NEST unset, the compact form now uses auto from #2018: groups of 32 cases for a program of 512 cases or more, the flat switch below. XCL_COMPACT_NEST=0 keeps the flat form, and a power of two nests every program. An invalid value warns and keeps auto, the way XCL_COMPACT_CS keeps its default. Part of #1269.

Why: the flat switch over ActivateRays' 2,516 cases took 168 s and 8.1 GB in a cold NVIDIA driver build, against 36 s and 1.5 GB nested (RTX 4090, measurements). Testers measured the same programs with a fixed group size:

  • AMD Windows (RX 9060 XT, RX 9070): all three built in 9–60 s nested, where the flat form took minutes or did not finish.
  • RADV (RX 9070 XT): the flat form ran out of memory, the nested one built in 202 s. The ~700-case programs built 9 % faster and 28 % slower nested; the README says so.

What is in it

  • crates/xcl/src/gpu/recomp/compact.rs: nest_of reads the value (unset or invalid: Auto), nest_from_env keeps it once; test an_unset_nest_is_auto.
  • crates/xcl/src/gpu/recomp/pso.rs: comment only. Unset now names compact cache entries _c_na, as auto does. The translator sources change, so the cache's identity changes anyway.
  • crates/xcl/src/gpu/recomp/tests_compact.rs: a doc line. With XCL_SAMPLE_BIG_CS set, gpu_compact_sample_big_cs now runs the default (nested) form of a big sample.
  • README.md: what the default does, and XCL_COMPACT_NEST.

Tested

  • RTX 4090 (driver 617.42), i9-13900K, 32 GB, Windows 11 Pro 26300, rustc 1.100.0.
  • eee2b86 (on main afc5ee8 through the stack), debug: cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 gave 1300 passed, 0 failed, 46 ignored, in 23 result blocks. Its patch is the same as at f698c22 (and at 06489ea except the README context, kept as main has it before this PR's bullet); only the base moved.
  • SKIPPED (29): 22 GPU cases for no wave64; 3 lower_dxil per-lane f16/f32 cases (refused by the per-lane form, as on main); 3 cases that need the D3D12 debug layer / SDK layers, which this machine does not have; heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • Fails without the change: with unset read as flat again, an_unset_nest_is_auto fails.

Regression run

The retail title, 60 s, XCL_PRESS_AT=16:A (the title takes A at its title screen 16 s in and loads for the rest of the run), no other variables (the default shader cache, warm from earlier runs). Both runs on this machine, with nothing else running.

main 06c9f55:

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1213 (PresentX 1213)
presents per 2 s (last 3): 0 2 7
device removals: 0
crashes: 0
peak commit: 25341 MB

This PR, head eee2b86:

xcl-smoke v1
commit: eee2b862a16c8cbab65daf7f9492f8f2320a84c7
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1310 (PresentX 1310)
presents per 2 s (last 3): 0 0 3
device removals: 0
crashes: 0
peak commit: 25875 MB

The PR's run got 108.0 % of main's frames and 102.1 % of its peak commit.

Not tested

  • A title run that reaches the compact form: in 60 s the title does not reach ActivateRays, so the smoke pair checks only that the rest still works. In a 300 s run of Recompiler: compact dispatch can switch in two levels (XCL_COMPACT_NEST) #1692 with groups of 32, the title built ActivateRays nested in 36 s; with the flat form it had not finished the build by the end of the run.
  • auto itself (as opposed to a fixed group size) on AMD, RADV and Intel; programs under 698 cases in the driver. @philip-roy-jones is measuring the threshold on an RX 580 (claim).

AI use

🤖 Generated with Claude Code

@nnonno91

Copy link
Copy Markdown

Tested

Independent GPU and translated-cache check on 06489ea27c0f657263a948f244ca80373bd0f8fa. Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, AMD Radeon(TM) Graphics (32.0.21042.62, native wave64), and GeForce RTX 5090 (32.0.16.1742, split wave64). Rust 1.100.0 x64 MSVC, DXC/DXIL 1.8.2502.11, unoptimized dev/test profiles with debug info off.

  • cargo build --workspace --locked passed.
  • cargo test --locked -p xcl --lib gpu::recomp::compact::tests -- --test-threads=1 --nocapture passed 7 tests on AMD, and the same command with the filter shader_cache_tests passed 16. Zero failed, ignored, or skipped.
  • cargo test --locked -p xcl --test compact_default_gpu_probe -- --exact default_compact_mode_and_cache_on_gpu --test-threads=1 --nocapture passed in all five settings on each adapter (1 passed, 0 failed, 0 ignored, 0 skipped per process). The temporary probe used synthetic 511- and 512-case FSPX compute shaders through console_hlsl, console_to_dxil_in, and D3D12 dispatch. XCL_COMPACT_CS=1 forced these fixtures onto the compact backend. All 64 output words for each shader matched the CPU sum in every setting on both GPUs.
XCL_COMPACT_NEST 511 cases 512 cases Translated-cache suffix
Unset, auto, or invalid Flat 16 groups of 32 _c_na
0 Flat Flat _c
32 16 groups 16 groups _c_n32

On each adapter, the unset run populated a fresh cache. Explicit auto and an invalid string both reused those entries in separate cached-only processes, with one hit and zero compiler calls per shader. The invalid string emitted the fallback warning. The flat and fixed modes created their own translated-cache entries without replacing the automatic ones. HLSL and DXIL matched byte for byte between the default and the corresponding explicit control at each boundary.

Not tested

Real titles, automatic selection of the compact backend, controlled compile timings, gameplay performance, RADV, or the full workspace test suite.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) prepared and ran the temporary probe, checked the output, and drafted this report.

@raylitebull

Copy link
Copy Markdown
Member

Independent AMD RDNA2 + NVIDIA RTX 5090 checks on \

@ettehn

ettehn commented Nov 25, 2026

Copy link
Copy Markdown

Independent cold-compile timings on RTX 5070 Ti Laptop

Tested 06489ea27c0f657263a948f244ca80373bd0f8fa in release on Windows 11 26200.9974, RTX 5070 Ti Laptop (driver 621.24), Ryzen 9 8945HX, DXC 1.8.2502.11 and Rust 1.97.1. Used xcl shaders <pack> --measure-pso <record> --repeat 1 --windows 4, with XCL_COMPACT_CS=1, XCL_HEAP_WINDOWS=1 and XCL_PSO_DISK_CACHE=0. Each run used a fresh process and the tool disabled the implicit driver caches. Reversed the order for the flat, 32 and 64 repeats. All 21 PSO builds succeeded.

Seconds for DXC plus D3D12 PSO creation, excluding archive lookup and HLSL emission:

Record Flat Groups of 16 Groups of 32 Groups of 64
ActivateProbes 56c0cd3b82a00c6e 14.07–14.31 13.68 12.33–12.37 10.94–11.23
ActivateProbesTarget 958400d2caf07244 22.22–22.51 20.82 19.71–19.88 17.88–18.02
ActivateRays 95cc13288a27a96e 42.12–42.70 28.68 27.23–27.25 26.10–26.82

For ActivateRays, flat → 32 reduced DXC from 20.29–20.95 s to 7.78–7.81 s and driver creation from 21.75–21.83 s to 19.42–19.47 s. For ActivateProbes, 32 improved the combined time even though driver creation alone rose from 6.48–6.56 s to 7.40–7.42 s. Groups of 64 were slightly faster overall on this adapter and emitted 6–7% larger DXIL than groups of 32. This is one adapter and one driver version.

The compact unit-test filter and gpu_compact_nested_dispatch passed (8 total, zero failed, ignored or skipped). The retail PSOs were created but never dispatched. Retail output parity and title behavior remain untested in this run.

AI use: OpenAI Codex (GPT-6.2 Sol) assisted with benchmark setup and verification.

@ettehn

ettehn commented Nov 25, 2026

Copy link
Copy Markdown

Follow-up experiment: group nested cases by similar register writes

On the same 06489ea Windows / RTX 5070 Ti Laptop setup as above, I kept groups of 32 and prototyped a stable sort of compact cases by the set of directly assigned SGPRs/VGPRs. The block-to-case table was remapped; block order and branch targets were kept. This was a local experiment using emitted assignments as a heuristic.

  • ActivateRays (95cc13288a27a96e), -O1, two independent cache-off runs per arm in original/reordered/reordered/original order. Driver PSO time 19.17–19.45 → 15.44–15.48 s, DXC 7.71–7.73 → 7.18–7.22 s. DXIL 919,948 → 827,732 B; the SDK DXC disassembly has 79,432 → 58,442 phi incoming operands.
  • ActivateProbes (56c0cd3b82a00c6e), one build per arm at each level. At -O3, driver time 7.54 → 5.78 s, but DXC 5.00 → 18.53 s. At -O1, DXC still grew 4.79 → 18.36 s. This is an end-to-end compile regression for this record.
  • ActivateProbesTarget (958400d2caf07244), one build per arm per level. At -O3, DXC + driver 19.53 → 20.41 s. At -O1, 19.35 → 20.21 s.

The existing synthetic GPU test gpu_compact_nested_dispatch passed with the reordered cases (1 passed, no skip). Retail PSOs were only built. This is evidence for investigating a targeted optimization for the largest switches; I would keep the current default grouping while the reason for the DXC regression and retail output parity are unresolved.

AI use: OpenAI Codex (GPT-6.2 Sol) assisted with prototyping and verification.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main (crates/xcl/src/gpu/recomp/pso.rs) — needs a rebase before it can be tested.

@Diskuss

Diskuss commented Nov 25, 2026

Copy link
Copy Markdown

Tested on AMD Radeon RX 9070 XT (RDNA4) at f698c22623c5ef846da3d0449679921c39a1d7a9 (bare head, not merged with main; it is 3 commits behind main 568e7db). Covers the whole compact stack (#1448, #1692, #2018) per the #1269 request.

Windows 11 Pro 26300.9974, Ryzen 7 5700X3D, 32 GB, driver 32.0.32015.7029, Rust 1.100.0 msvc, DXC 1.9.2602.17, debug build, D3D12 debug layer installed.

Tested

  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1189 passed, 2 failed, 46 ignored. No DXGI_ERROR_DEVICE_REMOVED.
  • Failures: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and _3 (panic at fuzz_tests.rs:1171, e.g. seed 722 res[30] = 0x1, CPU 0x7fffffff). These are the same two failures as on main 568e7db (1152 passed / 2 failed / 46 ignored, known AMD issue DXIL fuzz tests: fuzz_validate_and_gpu_1 fails on AMD (seed 722 and others, RDNA2-4), so the default suite is red there #2115); nothing new fails. Passed count is +37 vs main from the stack's added tests; ignored is unchanged.
  • SKIPPED lines (8):
    • f16_programs_on_the_gpu x4 (f16 arithmetic and f16 packed, wave32 and wave64, per-lane form): refused, unsupported V_MUL_F16 / V_PK_MUL_F16 VOP3 modifiers (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics)
    • f32_programs_on_the_gpu x2 (f32 conversions, wave32 and wave64): refused, unsupported V_CVT_F16_F32
    • shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode required, 0x887A002D)
    • heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows

Not tested: no smoke: our only title (The Matrix Awakens) stops before shader compile on main at CreateCommandSignature E_INVALIDARG (#1887), so a smoke on this stack alone would only show that crash. Release build not tested.

Report written by Claude Code (Claude Sonnet 5.5) from a real run on this machine.

@upipibi

upipibi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

NVIDIA test report for f698c22 (base 6e1e2be), as asked in #1269; it covers the stack from #1316 through #2018. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, the PR head as it is.

  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1190 passed, 1 failed, 46 ignored.
    • The one failure is test_title_runs_and_game_folder_is_untouched, because my build step ran only cargo build --workspace --tests, so xcl_testtitle.exe and testgame_mw.dll, built from the repository's tests/testtitle, were missing (the panic says "build first: cargo build --workspace"). So the end-to-end test did not run here. With a full build (cargo build --workspace && cargo build --workspace --tests), cargo test -p xcl --test e2e gives 3 passed, 0 failed at f698c22, and 3 passed, 0 failed on main 568e7db. So nothing failed on this head here.
    • SKIPPED: 26, mostly no wave64 (the wave64 parity and lower_dxil GPU cases). The others are per-lane form: refused, no heap windows, cannot disable the driver cache, and Developer Mode off (0x887A002D).
  • No xcl-smoke block: I have no title.

AI-assisted (Claude Code). Synthetic tests only.

@itsSio

itsSio commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Tested

Independent Windows GPU check at clean PR head f698c22623c5ef846da3d0449679921c39a1d7a9 (no local merge or patches), following the #1269 request. Both machines ran cargo build --workspace --locked (exit 0) and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture (exit 0). Unoptimized MSVC dev/test profiles, debug info off, default XCL shader options, no XCL_SAMPLE_* variables.

GPU and driver System and toolchain Passed / failed / ignored 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 1191 / 0 / 46 26
GeForce RTX 2080 SUPER, 32.0.16.1088 Windows 11 Pro 26200, Ryzen 5 5600X, 16 GiB, Rust 1.99.1, DXC 1.8.2502.11 1191 / 0 / 46 28

Both NVIDIA runs logged 21 native-wave64 skips (including gpu_compact_native_wave64_form), three per-lane cases refused (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32), no heap windows (heap_window_out_of_memory_falls_back_to_the_switch_form), and no driver-cache disable support (pso_measurement_compiles_an_exact_synthetic_record, 0x887A002D). The RTX 2080 SUPER also lacked the D3D12 debug layer for test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state. Runtime skips are reported separately from Rust's ignored count.

On the 9800X3D's Radeon RDNA2 iGPU (driver 32.0.21043.5001), XCL_ADAPTER=radeon cargo test -p xcl --lib --locked gpu::recomp::tests_compact -- --test-threads=1 --nocapture gave 25 passed / 0 failed / 0 ignored, no runtime skips, including native-wave64 compact and nested-vs-flat dispatch coverage.

Not tested: Full workspace on AMD, retail smoke, game shader samples, or compile-time performance. No speedup is inferred from suite duration.

AI use

Ran via Samaritan:

  • OpenCode with OpenAI GPT-6.2 Sol: scoped the check, ran both Windows builds and GPU tests, checked counts and skips, and drafted the report.
  • OpenCode with Claude Opus 5.5: independently checked campaign overlap, the current PR-head request, and maintainer feedback.

@moombathepilot

Copy link
Copy Markdown

Tested — RX 7800 XT on Windows

Clean PR head f698c22623c5ef846da3d0449679921c39a1d7a9. Ryzen 7 5700X3D, RX 7800 XT (driver 32.0.32029.2010), Windows 11, Rust 1.100.0 MSVC, DXC 1.9.2602.17.

  • cargo build --locked --workspace passed. cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output: 1,190 passed, 1 failed, 46 ignored across 21 result blocks.
  • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 failed on seed 722 (res[30] = 0x1, CPU 0x7fffffff). The same mismatch reproduced on parent 5040ea1ef4807af4732dcbfaed1789226c39c4e0 (Recompiler: XCL_COMPACT_NEST=auto nests programs of 512 cases or more #2018), consistent with DXIL fuzz tests: fuzz_validate_and_gpu_1 fails on AMD (seed 722 and others, RDNA2-4), so the default suite is red there #2115. The first run also hit console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk (DXIL not compiled yet). That test passed on the full rerun and in isolation on the parent.
  • Runtime skips (10): four per-lane f16 arithmetic/packed cases (V_MUL_F16, V_PK_MUL_F16), two per-lane f32 conversion cases (V_CVT_F16_F32), pso_measurement_compiles_an_exact_synthetic_record (driver-cache disable unavailable, 0x887A002D), test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state (D3D12 debug layer unavailable), and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows). The PLS junction subcase also logged mklink /J unavailable.

Retail startup smoke

Release build, scripts/smoke.ps1 -Seconds 60 with a fresh XCL data root and DXIL cache, networking off, no injected input.

xcl-smoke v1
commit: f698c22623c5ef846da3d0449679921c39a1d7a9
gpu: AMD Radeon RX 7800 XT
title: 817b32af
seconds: 60
exit: 0x0
frames shown: 918 (PresentX 918)
presents per 2 s (last 3): 49 60 60
device removals: 0
crashes: 0
peak commit: 15757 MB

Not tested

World loading, retail shader compile-time performance, or a paired startup comparison.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) ran the builds, tests and smoke, compared the failing tests against the parent, and drafted this report.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@Rednaxeh

Copy link
Copy Markdown
Contributor

RX 7800 XT (RDNA3, wave64), in the title: the compact nested form builds ActivateRays on the AMD driver in 57 s where main cannot build it at all. The title still does not render its world within 900 s on this card: it keeps asking for new 1 MB compute programs that the driver builds at 30–40 s each.

Covers the in-title part that @moombathepilot's report on this card leaves out (world loading, compile times). Head f698c22 merged locally onto main 568e7db (clean merge, 7573f49), release. Ryzen 7 7800X3D, 32 GB RAM, driver 32.0.32029.2010, Windows 11 26300, Rust 1.100.0, DXC 1.9.2602.17. The newer retail title of #505, offline, defaults (HLSL path), XCL_PSO_TRACE=1 XCL_ACTIVITY=1, A at the start screen.

ActivateRays and ActivateProbes (the two programs compact_wanted takes here)

Three runs: 300 s cold, 300 s warm, 900 s warm

  • No device removal, no crash, no refused program, 0 draws / 0 dispatches skipped. Frames: 1445 / 1483 / 1513 (menus at 30 fps, loading, then a black window from ~82 s to the end in each run).
  • Warm runs get every big program of the earlier runs from the blob cache (418 supplied in the 900 s run), but each run asks for programs no earlier run created: 82 new records in the second run, 25 of them over 256 KB (19 MB of DXIL). In the 900 s run, after 120 s, the driver builds 1.0–1.4 MB compute programs at 30–41 s each, 3–4 a minute through the single huge-compile slot (gated (waited 54–197 s)), 155 compiles over 256 KB in all (111 MB); at 600 s a title thread waits in resolve_wait for one of them at SetPipelineState. Commit 32–35 GB, spikes to 49.8 GB at 782 s.
  • 168 distinct compute records over 256 KB seen across today's runs on this card; the comment in real.rs expects ~600 of the ~1 MB ray-tracing resolve programs.

So on RDNA3 this stack removes the one program that main could never build, and the remaining cost is the AMD driver's 30–40 s per 1 MB program times the number of programs the title asks for, one slot at a time. A world picture would need several more warm runs, more huge-compile slots (XCL_HUGE_PSO_CONCURRENCY, 3 GB of commit headroom each on a 32 GB machine), or a way to fill the blob cache ahead that works on AMD (xcl shaders --pipelines does not: AMD keys its driver cache by application).

Not tested

  • The suite on this head (moombathepilot's run above is on the same card), XCL_COMPACT_NEST=0, the direct backend with this stack, NVIDIA.

AI use: Claude Code (Claude Fable 5.1) read the logs and wrote this; the runs were mine.

@ClosetPie107

Copy link
Copy Markdown

Linux / AMD RDNA4 (RADV) test report on exact head f698c22 (clean detached worktree), covering XCL_COMPACT_NEST unset (auto) on RADV from Not tested.

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, capped at MemoryMax=14G, MemorySwapMax=0)

  • gpu::recomp::compact: 9 passed, 0 failed, 0 ignored, 0 skipped (0.36 s).
  • gpu::recomp::tests_compact: gpu_compact_against_the_pc_block_fallback hit the 14 GiB cgroup OOM cap on RADV/dxil-spirv (killed cleanly; previously triggered an uncapped OOM).
  • gpu::recomp::tests_compact --skip gpu_compact_against_the_pc_block_fallback: 24 passed, 0 failed, 0 ignored, 0 skipped (8.00 s).

Cold RADV PSO builds with XCL_COMPACT_NEST unset (auto) (release xcl.exe shaders <dir> --precompile --only cs --pipelines, MESA_SHADER_CACHE_DISABLE=true, VKD3D_SHADER_CACHE_PATH=0, fresh XCL_DXIL_CACHE, MemoryMax=14G, MemorySwapMax=0):

  • ActivateProbes (9083c094, 88,863 insts, 752 KB HLSL): 21.2 s compile (22.0 s wall), 4.23 GiB peak (pipelines made on the GPU 1, refused 0, driver cache 0) — down from 252 s flat on #1316.
  • ActivateProbesTarget (534f271f, 88,445 insts, 692 KB HLSL): 15.4 s compile (15.5 s wall), 2.90 GiB peak (pipelines made on the GPU 1, refused 0, driver cache 0) — down from 176 s flat on #1316.

Not tested: full workspace suite, retail title run, ActivateRays, programs under 512 cases.

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

@Pipodi
Pipodi marked this pull request as draft November 25, 2026 11:20
CowboyBingus and others added 6 commits November 25, 2026 05:40
…nslate

No behaviour change: the decoding, block leaders and emitter set-up at the
start of translate() move into prepare(), so a second form of the program
(the compact form) is built from exactly the same decoded program and
emitter state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DXC inlines every helper of a cs_6_x target, so a retail compute shader
with thousands of equal blocks (ActivateProbes 56c0cd3b82a00c6e: 88,863
instructions, 3,281 buffer_load_format_x) becomes 29.75 MB of DXIL that
the driver needs minutes for. translate_compact() cuts the program into
blocks (leaders, plus every instruction whose HLSL exceeds 600 B on its
own), emits each instruction with emit::Em as translate() does,
temporaries numbered from t1 per instruction, and shares equal block
texts as cases of one dispatch loop. Branches go to a block at an offset
from their own (part of the text), so a static table only holds every
block's case, packed. The table is capped at 8,192 words: on an RTX 5070
Ti, CreateComputePipelineState of this program's compact form with an
added 12,288-word static array succeeded; with 15,360 words it failed
with E_OUTOFMEMORY. Back edges spend the loop budget (65,536 per lane);
once it is spent the program ends, where the structured form leaves the
loop and runs what follows. compact_wanted() picks programs of
20,000+ instructions whose distinct blocks hold under 30 % of them.
Not called yet.

Measured on 56c0cd3b82a00c6e (4 memory windows, split wave64, RTX 5070
Ti, a local merge, 31be310): 723,453 B HLSL, DXIL
1,053,264 B in 12.5 s, CreateComputePipelineState 9.7 s from a new exe
with no cached blob.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests_compact translates each program with translate and with
compact::translate_compact and runs both on the same inputs. The kernel
programs assert byte-identical SGPRs, SCC, VGPRs of all lanes, exports
and the split form's upper-half SGPRs, plus flat memory or the first
64 KiB of each memory window; the compute dispatch compares memory.

Programs: nested execz regions, divergent and scalar backward loops,
one block repeated at five addresses, far jumps (s_getpc_b64, add or
sub, s_setpc_b64) forward and backward, v_mul_lo_u32,
buffer_load_format_x in twelve formats and repeated as a block of its
own, a cross-lane block (ballot, readfirstlane, readlane) repeated
under four exec masks, s_endpgm before the last block, a loop through
four memory windows with loads, stores and per-lane atomics, a
compute dispatch, and 200 forward jumps that xcl-dev#1307's bound sends to
pc blocks in translate (gpu_compact_against_the_pc_block_fallback). The kernel programs run in each form forms() lists
for the adapter (wave64 split or native, wave32; with branches also
unstructured), and in the wave64 forms with mem_windows: 4; the
compute dispatch runs in wave64 (split where the adapter needs it) and
wave32.

Every program here except one has a branch, and the tests assert that
translate_compact gives it the compact form: they read its dispatch
loop back from the HLSL. translate_compact keeps translate's form for a
program without branches, so the two straight-line programs start with
a branch to the next instruction. For the repeated blocks, the
exchange block, the buffer loads, the window loop, the far jumps and
s_endpgm they also assert the shape: fewer cases than blocks, one case
for the four copies of the exchange block and one for the block after
the load, the load a case of its own, the far jumps' block offsets,
two program ends before the last block. The exception is the
memory-window program of gpu_memory_windows_above_4_gib (no branch):
it gets translate's form from both, so its test compares translate
with itself; the window loop runs the compact form through the
windows.

The atomics in the memory-window programs add to a dword per lane. On
an RTX 5070 Ti (split wave64, 4 windows), with all 64 lanes adding to
one dword, 40 runs of the same DXIL returned two different lane 0
values (5 and 35 runs): the split halves' atomics land in either
order.

gpu_compact_sample_big_cs (XCL_SAMPLE_BIG_CS=<code file>) runs a retail
program both ways. A program translate_compact refuses (e.g. its table
limit) is SKIPPED; when the driver cannot create translate's pipeline
(e.g. E_OUTOFMEMORY), the A/B comparison is SKIPPED and the compact
form must still compile and run.

Needs the compact backend (compact.rs and `pub mod compact`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…PACT_CS)

The switch XCL_COMPACT_CS: unset / auto = the programs compact_wanted
picks, 0 = none, 1 = every compute program; another value logs a warning
and acts as auto.
`translate_routed` gives a compute program to translate_compact where the
switch says so and uses `translate` when that returns an error or an
incomplete translation. The PSO path (console_translation, both FSPX and
FSSM), `xcl shaders` statistics and precompile, and the shader dump's
recompile use it.

The on-disk translation cache names an entry of a program routed to the
compact backend `..._c.bin`, so a compact and a normal translation of one
program never share a file; the file name of a normal entry is unchanged.
compact.rs is added to the translator sources that identify compatible
cache entries (this commit changes that identity, so existing entries are
translated again once). One INFO line per compute program routed to the
compact backend, the first time: instructions and HLSL bytes, or why it
fell back.

When dxc::compile_cached fails on a compute program's compact-form HLSL, the
program is compiled in the normal form (or taken from the normal form's
translation-cache entry when that is on disk), and the result is kept under
the normal entry, never the `_c` one; one WARN line is logged before that.
A cached-only attempt is not retried: its DXIL is not refused, only not made
yet. A refusal is not remembered between runs. A driver
(CreateComputePipelineState) rejection of a compact pipeline is not retried in
the normal form.

With XCL_DIRECT_DXIL (xcl-dev#1426) on, a compute program XCL_COMPACT_CS routes to
the compact form goes to the HLSL path's compact form first, not to the direct
translator; if DXC refuses that HLSL, the retry in the normal form goes to the
direct translator first, then to translate. Every other compute program goes
to the direct translator as before, and to the HLSL path when that falls back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The compact form keyed a block's case on its text with the branch offset
in it, so blocks with the same code but different targets were separate
cases. ActivateRays (95cc13288a27a96e) has 19,949 blocks and got 11,909
cases. Its table was over MAX_TABLE_WORDS, so the program fell back to the
normal form.

A case is now keyed on the block's code and branch condition, and the
target is data. A case whose blocks all jump by one offset keeps
`xcl_b +/- K`. Otherwise it takes the offset most of its blocks jump by
and sets each other block's target with
`xcl_t = select(xcl_b == k, target, xcl_t)`. ActivateRays has 2,516 cases.
At 12 bits, the usual packing (two cases to a word) still needs 9,975
words, so a table over MAX_TABLE_WORDS is now packed across words: bits
from bit `xcl_b * bits`, two reads, one word of padding. ActivateRays fits
in 7,482 words.

A case evaluates at most MAX_SELECTS (32) of those selects. Past that, the
list is split by `[branch] if (xcl_b < pivot)` until each leaf has at most
32. `xcl_b` is wave-uniform, so the branch is too. Without the bound, a
case that 1,799 blocks share runs 1,799 selects on every visit: on
milesah3ad's probe (a8eebfd, 3,600 rounds, targets that differ per copy)
a dispatch took 13.5 ms against 9.8 ms on the parent, and 10.4 ms with the
bound. DXC keeps the branches (92 conditional branches in the DXIL against
36). Cases with 32 or fewer differing targets emit the same text as
before.

Which programs take the compact form does change: ActivateRays had 11,909
cases and a 9,975-word table, so it fell back to the normal form, and it now
takes the compact form through the across-word table. ActivateProbes and
ActivateProbesTarget were compact before and keep the usual packing.

Measured on an RTX 4090 (driver 617.42), release, a fresh DXIL cache and
a new exe path per run (so the driver's cache missed):
- ActivateRays: DXC 20-24 s, 2.89 MB DXIL. The driver made it in 175,
  190, 215 and 233 s (peak private 8.1 GB). The same build without the
  bound: 2.85 MB, 162, 162, 164 and 201 s, interleaved with those runs.
  K = 64 took 200-216 s, no better.
- ActivateProbes: 751 cases (906 before), 0.94 MB DXIL, driver 12.6 s.
- ActivateProbesTarget: 698 cases (851 before), 0.85 MB DXIL, driver 9.9 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The compact form's dispatch loop is one switch over every case, so the
merge block after it has one predecessor per case and a phi operand per
predecessor for each of the ~147 loop-carried registers. On one retail
compute program (ActivateRays, RTX 4090) that is 436,656 merge operands,
2,848,780 B of DXIL, a cold driver build of about 165 s and a peak of
8.2 GB.

XCL_COMPACT_NEST=<P> (a power of two; off when unset or 0) switches on
`case >> log2(P)` first, and each group has its own inner switch and ends
in `xcl_nb = min(xcl_nb, <blocks>u)`. The min is what stops DXC from
folding the group merges back into one (without it the 147 x 2,910
operand merge returns). Measured with a throwaway build of the same
emission, P = 32: merge operands 436,656 -> 93,531, DXIL 2,848,780 ->
1,037,876 B, cold driver build about 165 s -> 38 s, peak 8.2 -> 1.5 GB
(issue xcl-dev#1269, comment 7141317244).

Off by default: with the variable unset the HLSL is the flat form as
before (the selector expression is only factored out). `compact_with`
takes the group size so tests do not depend on the environment; an
invalid value logs a warning and leaves the nest off.

The translated-shader disk cache names a compact entry `_c`, and now
`_c_n<P>` when the nest is on, so a warm flat entry is not loaded for a
nested run or the other way round; names with the nest off are unchanged.
P is limited to 2^16: a shift of 32 or more is masked to 0 by HLSL.

Tests: the HLSL shape on a synthetic program (ceil(cases/P) inner
switches, every case once, one min per group, the off text is flat); the
parsing of the size and the cache file name; a GPU A/B against
`translate` with the nest on (results are compared there, on synthetic
programs); and, on XCL_SAMPLE_BIG_CS, DXC only: nested DXIL under 80 % of
the flat compact form's. Measured 36 % (ActivateRays), 64 % and 64 % on
two other programs; folded back it would be about 100 %. The samples' own
dispatch does not finish in the runner's 10 s with zero inputs, so their
results are not compared.

The tests' reader of the compact HLSL (`Dispatch::of`) reads the nested
form too, so the compact tests pass with XCL_COMPACT_NEST set and then
check the nested form (in a run with it set to 32, a tester found 15 of
them stopping at the flat switch line before).

Stacked on xcl-dev#1448.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pipodi and others added 3 commits November 25, 2026 14:52
A GPU A/B of the nested and flat compact forms is not possible on a
retail program: run as a kernel with zero or random inputs, the retail
programs tried so far do not finish or remove the device, flat or nested,
on NVIDIA and on AMD (xcl-dev#1269).

nested_matches_flat checks the HLSL instead. The text before and after the
dispatch is the same; the case number is the flat switch's expression of
the table; case k is in group k >> log2(P), with the flat case's address
and text; and every group ends in min(xcl_nb, n) with the loop's own n,
which changes only an xcl_nb that ends the loop either way.
nested_dispatch_runs_the_flat_cases runs the check on the synthetic
programs, groups of 1 to 32, both table packings, and checks that it finds
a case moved to another group, a changed case text and a changed bound.
compact_sample_big_cs_nested_runs_the_flat_cases runs it on
XCL_SAMPLE_BIG_CS in groups of 16, 32 and 64. It passed on three retail
programs (703, 659 and 2,438 cases with the test's options).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
XCL_COMPACT_NEST=<P> nests every compact program or none. A cold driver
build of the nested form was much faster for the biggest programs
measured, so `auto` decides per program: groups of 32 cases from 512
cases (distinct block texts) on, one switch below. 512 is below the
smallest program measured (698 cases); nothing under it was timed. The
case count is known only once the blocks are emitted, so compact_at
resolves the setting there; unset and 0 stay flat, and a size still
nests every program.

Measured on an RTX 4090 (driver 617.42), release, a fresh DXIL cache and
a new exe path per run, compute programs of the retail title:
- 751 cases: 11.6 s flat, 5.9 s nested; 698 cases: 9.5 s, 4.8 s;
  2,516 cases: 168 s and 8.1 GB flat, 36 s and 1.5 GB nested.
- Groups of 16, 32 and 64 took 36.8, 36.1 and 37.2 s on the last.
Testers on AMD Windows built the three with groups of 64 where the flat
form did not finish. On RADV the two ~700-case programs built 9 % faster
and 28 % slower nested, a cost of `auto` there, and the 2,516-case one
only nested.

The translated-shader cache names an `auto` entry `_c_na`, as the group
size follows from the program.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With XCL_COMPACT_NEST unset, the compact form now uses `auto`: groups of
32 cases for a program of 512 cases or more, the flat switch below.
XCL_COMPACT_NEST=0 keeps the flat form for every program, a power of
two nests every program in groups of that size, and an invalid value
warns and keeps `auto`.

The flat switch over the 2,516 cases of the biggest compute program of
the retail title gives one merge block with ~147 phi operands per case.
A cold NVIDIA driver build of it took 168 s and 8.1 GB, nested 36 s and
1.5 GB (RTX 4090). Testers on xcl-dev#1269 measured it with a fixed group
size of 32 or 64:
- AMD Windows (RX 9060 XT, RX 9070): with the nest, it and the two
  ~700-case programs built in 9-60 s, where the flat form took minutes
  or did not finish;
- RADV (RX 9070 XT): the flat form ran out of memory at 94 GB, the
  nested one built in 202 s; the two ~700-case programs built 9 %
  faster and 28 % slower nested.

The value is read through nest_of, so the unset case has a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Pipodi
Pipodi marked this pull request as ready for review November 25, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.