Skip to content

Recompiler: compact dispatch can switch in two levels (XCL_COMPACT_NEST) - #1692

Draft
Pipodi wants to merge 6 commits into
xcl-dev:mainfrom
Pipodi:compact-nest
Draft

Pipodi wants to merge 6 commits into
xcl-dev:mainfrom
Pipodi:compact-nest

Conversation

@Pipodi

@Pipodi Pipodi commented Nov 24, 2026 •

Copy link
Copy Markdown

Stacked on #1448 (57d7574, itself on #1316 964f5ed); only the top commit (9c09c8f) belongs here.

The compact form's dispatch loop is one switch over every case. All cases fall through to one merge block, which has a predecessor per case and a phi operand per predecessor for each of the ~147 loop-carried registers. On ActivateRays (2,516 cases), that is 436,656 merge operands. The NVIDIA driver's time and memory follow them: about 165 s and 8.2 GB for one cold pipeline build (#1269 result).

XCL_COMPACT_NEST=<P> (a power of two up to 65536; off when unset or 0) switches on case >> log2(P) first. Each group of P cases has its own inner switch and ends in xcl_nb = min(xcl_nb, <blocks>u). The min stops DXC from folding the groups' exits back into one merge. Without it, the 147 × 2,910 merge comes back. This PR adds the switch, off by default. Turning it on above a case count is a separate PR, after measurements on more programs and GPUs. Part of #1269.

What is in it

  • crates/xcl/src/gpu/recomp/compact.rs:
    • compact_with takes the group size, and compact() reads it from XCL_COMPACT_NEST once.
    • An invalid value logs a warning and leaves the nest off.
    • With the nest off, the HLSL is the flat form as before (the selector expression is only factored out).
  • crates/xcl/src/gpu/recomp/pso.rs: the translated-shader disk cache names a nested compact entry _c_n<P> instead of _c, so a warm flat entry is never loaded for a nested run, or the other way round. Names with the nest off are unchanged.
  • Tests:
    • compact::tests::nested_dispatch_groups_the_cases: P = 2, 4, 8, 16, with ceil(cases/P) inner switches, every case once, one min per group, and the flat text with P = 0.
    • The parsing of the size.
    • The cache file name.
    • tests_compact::gpu_compact_nested_dispatch: the GPU A/B against translate with P = 2 and 4, on the synthetic programs (now with Recompiler: compact cases share code whose branch targets differ #1448's many_targets, whose case has the [branch] if tree of selects), in every form the adapter runs.
    • compact_sample_big_cs_nested_dxil on the existing XCL_SAMPLE_BIG_CS hook: DXC only, nested DXIL under 80 % of the flat compact form's.
    • The tests' reader of the compact HLSL (Dispatch::of) reads the nested form too. With XCL_COMPACT_NEST set for the whole run, the compact tests now check the nested form instead of stopping at the flat switch line (@einfachama found 15 of them doing that).

Tested

  • RTX 4090 (driver 617.42), i9-13900K, 32 GB, Windows 11 Pro 26300, rustc 1.100.0.
  • 9c09c8f (on main 266b845 through Recompiler: route compute programs through a compact backend (XCL_COMPACT_CS) #1316 964f5ed and Recompiler: compact cases share code whose branch targets differ #1448 57d7574), debug: cargo build --workspace && cargo test --workspace -- --test-threads=4 gave 990 passed, 0 failed, 42 ignored, in 20 result blocks.
  • cargo test -p xcl --lib compact -- --test-threads=4 with XCL_COMPACT_NEST unset, =32 and =2: 33 passed, 0 failed, 0 ignored each (SKIPPED gpu_compact_native_wave64_form: no wave64).
  • SKIPPED: gpu_compact_native_wave64_form, gpu_wave32_program_in_wave64_hardware, gpu_geometry_wave32_prefix_count_over_a_mask and 16 lower / lower_dxil GPU cases (no wave64); 3 lower_dxil per-lane f16/f32 cases (refused by the per-lane form, from main); heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows); pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache: Windows Developer Mode is required).
  • Fails without the change: with compact_with made to ignore the group size, nested_dispatch_groups_the_cases and gpu_compact_nested_dispatch fail. The GPU test fails on its HLSL-shape assert; its results would be equal either way.
  • Release, xcl shaders <record> --precompile --only cs, a new XCL_DXIL_CACHE per run, on records of three compute programs from the retail title:
program DXIL, nest off DXIL, XCL_COMPACT_NEST=32 ratio DXC, off / 32
ActivateRays 2,848,780 B (the same hash as #1448 at b370923) 1,037,876 B 36 % 22.0 / 9.8 s
second program 942,812 B 602,444 B 64 % 12.0 / 9.2 s
third program 847,392 B 539,260 B 64 % 22.1 / 20.2 s

Regression run

The retail title, 60 s, XCL_PRESS_AT=16:A, a new empty XCL_DXIL_CACHE per run, XCL_COMPACT_NEST unset (this PR's default). The main block is the one made tonight for #1448's regression run (same commit of main, title and settings).

main 689f2db:

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1239 (PresentX 1239)
presents per 2 s (last 3): 1 11 26
device removals: 0
crashes: 0
peak commit: 25409 MB

This PR, head 9c09c8f:

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

The PR's run got 89.6 % of main's frames and 60.3 % of its peak commit. Neither log has a compact backend line.

Not tested

  • The nested form in a title run by me: the smoke runs above have it off, so they check only that the change breaks nothing.
  • AMD timing and Intel. On NVIDIA Linux, @0naku measured it (45 s against 350 s). On an RTX 3050 8 GB, @brothernog built ActivateRays in the heap form in 31.8 s against 312 s flat. On Linux / RADV (RX 9070 XT), @St5sz2Jk found the nested form slower in the driver: 244 s and a 45.5 GB peak, against 70 s for the flat form with @0naku's switch-tree patch. On an RTX 4060 8 GB, @einfachama built ActivateRays nested in a title run in 24.9 s from cold. On AMD and RTX 5090, @nnonno91 ran the GPU tests, including the packed table.
  • The nested form with a packed (dense) table runs on the GPU only on @nnonno91's AMD and RTX 5090; here it is checked for HLSL shape.
  • Results on the retail programs are compared only through the synthetic programs: their own dispatch does not finish within the test runner's 10 s with zero inputs.
  • Recompiler: share scalar operands in compact compute cases #1548 (9c26337, stacked on Recompiler: compact cases share code whose branch targets differ #1448's old head 42b2f11): it builds the dispatch from the decoded instructions, not from the HLSL (@t4l03's correction). Both PRs change compact.rs and pso.rs and conflict there (git merge-tree of 9c26337 and 7123faa), so whichever merges second has to reconcile the dispatch emission and the cache names. The two have not been run together.

AI use

  • Claude Code.
    • A Claude Sonnet 5.5 subagent wrote the code, the tests and the commit message. It also ran the suite, the sample tests and the smoke run.
    • A Claude Fable 5.2 subagent planned the merge-phi measurement.
    • Claude Opus 5.5 (the main session) set the design, ran the DXIL size checks, did the rebase onto Recompiler: compact cases share code whose branch targets differ #1448's new head, made the tests read the nested form, ran the suite and the smoke run on this head, read the diff and wrote this description. A second Opus 5.5 agent reviewed the diff.

🤖 Generated with Claude Code

https://claude.ai/code/session_013qV4hiM5Sx9hBkPpgAarKX

@Pipodi
Pipodi marked this pull request as ready for review November 24, 2026 19:21
@nnonno91

Copy link
Copy Markdown

Independent Windows GPU check of commit 00f10eeceb4b58738610a2138c4361d5f5a69582. Nested dispatch with a densely packed table matched the reference on both AMD and NVIDIA.

Tested

  • Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, AMD Radeon(TM) Graphics (32.0.21042.62), and NVIDIA GeForce RTX 5090 (32.0.16.1742). Rust 1.100.0 MSVC, Windows SDK DXC 1.8.2502.11, debug/test profiles.
  • On the unmodified PR head with XCL_ADAPTER=AMD Radeon and the default compact settings, cargo build --workspace --locked succeeded. cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output reported 888 passed, 0 failed, 42 ignored. One of the reported passes logged an explicit skip, heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows.
  • For the targeted check, I temporarily extended tests_compact.rs and ran cargo test --locked -p xcl --lib -- gpu_compact_dense_nested_dispatch --test-threads=1 --nocapture once per adapter. Each run reported 2 passed, 0 failed, 0 ignored and no skips. Both used wave32, plus native wave64 on AMD or split wave64 on NVIDIA.
  • I adapted the four fixtures from gpu_compact_nested_dispatch to call compact_with with heavy=0, dense_above=0 and groups of 2 or 4. The generated HLSL used both word-spanning extraction and nested switches. Its table data matched the flat dense form (nest=0). Each adapter ran 32 nested kernel configurations across the default and unstructured translation options, matching 4,235,392 result bytes against translate and the flat dense form. The fixture tables contained 28 word-straddling entries across program/form pairs.
  • I also applied the same settings to the existing gpu_compact_compute_dispatch fixture. All four nested compute configurations per adapter matched a CPU calculation for all 256 thread stores and preserved 16 sentinel dwords. Both GPU controls matched the same calculation. The worktree was restored after the targeted checks.

Not tested

Retail output, cold compile timing, Intel, or Linux. The combined check forced the packing and grouping through compact_with.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) adapted and ran the temporary tests, verified the logs, and wrote this report.

@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

@nnonno91 thanks. Your report covers one of the PR's Not tested points: the nested form with a packed table. You ran it on the GPU and it matched the flat dense form on AMD and NVIDIA, in wave32 and in native wave64 on AMD. That's a check the 4090 here can't make (no wave64). The other points are still open: retail programs on the GPU, AMD timing, and the merge order with #1548.

AI use: Claude Code (Claude Opus 5.5) wrote this reply.

@brothernog

brothernog commented Nov 24, 2026 •

Copy link
Copy Markdown

Tested 00f10ee on an RTX 3050 8 GB (desktop, Ryzen 7 5800XT) (NVIDIA 610.88, Windows 11 build 26300, DXC 1.9.2602.17, release), with a retail program. This covers part of the Not tested point "retail programs on the GPU", on a smaller card than the 4090.

ActivateRays (95cc13288a27a96e), translated as the runtime does with XCL_COMPACT_CS=1 XCL_HEAP_WINDOWS=1 and the translation cache off. Then a cold CreateComputePipelineState with the runtime's root signature and samplers, one PSO per process, one run each:

Form DXIL DXC Driver (cold) Driver peak commit Accepted
flat (XCL_COMPACT_NEST unset) 2,560,316 B 39.6 s 312.0 s 3,962 MB yes
XCL_COMPACT_NEST=32 906,364 B 19.0 s 31.8 s 850 MB yes
  • On this card the nested form is about 10× faster in the driver (on the 4090 it was about 4.4×), and it uses about 4.7× less commit.
  • "Peak commit" is the process's PeakPagefileUsage from K32GetProcessMemoryInfo, read right after the PSO call (66 MB before it). It may count differently from your 8.2 GB / 1.5 GB figures.
  • The sizes differ from yours because of heap windows (XCL_HEAP_WINDOWS=1); the nested-to-flat ratio is close (0.35 here, 0.36 on the 4090).

Not tested: main (kole's 8 GB run ran out of commit in DXC), other values of P, and a title run.

This comment was AI-assisted.

@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

@brothernog thanks, that's the first run of #1692 on a retail program on a small card. In the heap form, the driver went from 312 s to 31.8 s and its peak from 3,962 to 850 MB, and both pipelines were accepted. That is about 10× here against 4.4× on the 4090, so the small cards gain the most. On the 4090, the grid in #1269 (7142472413) puts the driver's time at about merge operands^0.8 × blocks. Yours looks steeper than that on this card. I'll use your table as the 8 GB data point when PR 2 (on by default above a case count) is measured.

Note: #1692 is now in conflict with main through #1316 (#1524 changed console_translation in pso.rs). I'll rebase it after #1316's next head.

AI use: Claude Code (Claude Opus 5.5) wrote this reply.

@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

Rebased onto #1448's new head 42b2f11 (on #1316 f207df1, on main 85e3826). The new head is 7123faa. The commit's patch is the same as 00f10ee's, so the tests and measurements made at 00f10ee (@0naku, @nnonno91, @brothernog) cover the same code.

  • On the RTX 4090, the whole suite gave 905 passed, 0 failed, 42 ignored.
  • The smoke run against main 85e3826 reached 102.7 % of main's frames and 99.3 % of its peak commit, with no crash or device removal.

The description has the new counts and both blocks.

AI use: Claude Code (Claude Opus 5.5) rebased and wrote this comment. A Claude Sonnet 5.5 subagent ran the suite and the smoke runs.

@t4l03

t4l03 commented Nov 24, 2026

Copy link
Copy Markdown

@Pipodi a clarification for the compatibility note in the description: #1548 at 9c26337 collects operands from decoded instructions, groups the block bodies, and only then emits the dispatch switch. Reading the emitted switch was part of the earlier HLSL prototype. I checked the two public heads (9c26337 and 7123faa) with git merge-tree; they do conflict in compact.rs and pso.rs. Whichever lands second will need to reconcile dispatch emission and cache names. We have no measurements with both options enabled yet.

AI use

Codex (gpt-6.2-sol) checked the source and merge tree and drafted this note.

@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

@t4l03 thank you, you're right. #1548's own commits on top of #1448 (c934db6, 8891798, 9c26337) build the dispatch from the decoded instructions and don't parse the HLSL. I've corrected the line in the description. It now says that the two PRs conflict in compact.rs and pso.rs (I see the same with git merge-tree of 9c26337 and 7123faa), that whichever merges second reconciles the dispatch emission and the cache names, and that they haven't been run together.

AI use: Claude Code (Claude Opus 5.5) checked the merge tree and #1548's commits, and wrote this comment.

CowboyBingus and others added 4 commits November 24, 2026 13:14
…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>
@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
@einfachama

Copy link
Copy Markdown
Contributor

Test report for #1692 with XCL_COMPACT_NEST=32 and heap windows, in title runs of my retail title on an 8 GB NVIDIA card. It covers the "Not tested" item "a title run" for both big programs.

  • 15ec6daefb19a780: builds in the driver in 24.9 s from cold, where the other forms I tried on this card did not finish.
  • 56c0cd3b82a00c6e: builds in 10.5 s.
  • Both: loaded from their driver blobs in later runs.
  • The title: in 5 runs it still does not present again after its world load starts. With kernelx: Sleep does not count the time a bind waits for a pipeline build #1288 holding its watchdog, it is now held by first-time builds of other big compute programs, one after another.

Setup

The two programs, nested, in the title

15ec6daefb19a780 (record 95cc13288a27a96e) 56c0cd3b82a00c6e (code hash d122faa48eb0afdc)
compact line, run 1 128.2 s: 76699 instructions, 2280459 B HLSL 128.8 s: 88863 instructions, 737038 B HLSL
DXIL 904 932 B 561 008 B
DXC (compact line to driver start, less the wait at the huge-compile gate) ~13 s ~10 s
driver, run 1 (cold, on a preload worker) 24 934 ms (after 7 270 ms at the gate) 10 488 ms
blob kept; runs 2–5 load it in 8 ms (run 2) at ~5 s kept; 5 ms (run 2)

The title: 5 runs

run 1 run 2 run 3 run 4 run 5
last 2 s window with a present 112 s 100 s 102 s 94 s 96 s
presents after it (to 420 s) 0 0 0 0 0
compute waits ≥ 250 ms: n / total / longest 147 / 550 s / 22 s 40 / 628 s / 82 s 41 / 596 s / 90 s 49 / 582 s / 43 s 20 / 593 s / 40 s
compute builds after 94 s (from blobs) 261 (32) 252 (87) 119 (31) 59 (0) 10 (0)
of these ≥ 500 KB DXIL, compiled (driver s) 16 (280 s) 19 (387 s) 18 (317 s) 13 (225 s) 10 (148 s)
≥ 500 KB programs from blobs before 94 s 1 18 40 63 77
longest single build (DXIL, driver) 370 KB, 7.2 s 1 394 KB, 40.6 s 1 555 KB, 44.8 s 1 054 KB, 21.4 s 1 074 KB, 19.9 s
peak commit / lowest available physical memory 30.8 GB / 1.02 GB 32.6 GB / 0.54 GB 32.2 GB / 0.25 GB 30.9 GB / 0.55 GB 30.3 GB / 0.88 GB
  • All 5 ran to the 420 s limit (exit 0). The title's watchdog did not fire (kernelx: Sleep does not count the time a bind waits for a pipeline build #1288).
  • What holds it now, in the thread dumps at 260 s and 340 s:
  • Over the runs:
    • Each run loads more big programs from earlier runs' blobs before the stall (1 → 77).
    • The small programs leave the stall (261 → 10 compute builds after 94 s).
    • The time spent waiting does not shrink: run 5 spends ~300 s on 10 new programs of 733–1 074 KB.

Not tested

AI use

  • Claude Code (Claude Opus 5.5) merged the stack, resolved the conflicts, added the local log line, ran the tests and the runs, counted the results from the logs and thread dumps, and wrote this report. Claude Fable 5.2 (in the Claude app) planned the tests and reviewed the report. I checked it before posting.

@St5sz2Jk

Copy link
Copy Markdown

Test report for #1692 7123faa on Linux / RADV (RDNA4), with XCL_COMPACT_NEST=32. It covers part of the Not tested item "AMD, Intel and dxil-spirv". ActivateRays builds in the title, but RADV takes 244 s and the process peaks at 45.5 GB, against 70 s for the flat form with @0naku's switch-tree patch on the same card.

Tested

ActivateRays (95cc13288a27a96e)

this PR, NEST=32 flat form + switch tree (my earlier run)
DXIL 1,036,712 B 2,848,780 B
dxil-spirv, native CLI 0.6 s, 0.17 GB, 3.7 MB of SPIR-V, spirv-val passes at default limits 14.8 s, 0.46 GB
RADV in the title (driver compile finish) 244.0 s (after 23.9 s waiting for the gate) 69.8 s
process memory 12.7 GB → 45.5 GB peak while it built 36.7 GB at the end of that run
  • The nesting problem is gone in this form, and dxil-spirv's default structurizer handles it without the switch tree. The cost moves into RADV: dxil-spirv finishes in under a second, so the 244 s are the driver's.
  • @0naku measured this form at 45 s on NVIDIA Linux (7142130114). So on RADV the two-level form is the slower option, at least at P = 32.

The rest of the run

  • 2,154 s with 2,332 driver compiles. There were no driver faults, and Mesa rejected no SPIR-V (MESA_SPIRV_FAIL_DUMP_PATH stayed empty).
  • It ended on the title's watchdog (+0x23cf683) with 56,524 pipelines queued and none compiling (window overlay at about 1,840 s). That is the scheduling stall described in [OFFICIAL] Looking for PRs with shaders optimization #1269, not something this PR causes.

Not tested: other P values; NEST with the switch tree; a cold driver cache for the other programs; repeat runs; RDNA2/3.

AI use: Claude Code (Claude Opus 5.5) built the trees and vkd3d-proton, ran the offline conversion, read the logs and wrote this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Pipodi and others added 2 commits November 24, 2026 23:41
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>
Claude-Session: https://claude.ai/code/session_013qV4hiM5Sx9hBkPpgAarKX
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>
Claude-Session: https://claude.ai/code/session_013qV4hiM5Sx9hBkPpgAarKX
@Pipodi
Pipodi marked this pull request as ready for review November 24, 2026 23:20
@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

New head 9c09c8f, rebased onto #1448's new head 57d7574, which bounds the select list. The nested emission itself is unchanged. Two test changes are in the same commit:

  • @einfachama's finding: with XCL_COMPACT_NEST set for the whole run, 15 compact tests stopped at the flat switch line. The tests' HLSL reader (Dispatch::of) now reads the nested form too. With the variable unset, =32 and =2, cargo test -p xcl --lib compact gives 33 passed, 0 failed each, so setting it now runs those tests on the nested form.
  • gpu_compact_nested_dispatch now also runs Recompiler: compact cases share code whose branch targets differ #1448's many_targets. Without it, the nested dispatch combined with the select tree was only compared with translate when the variable was set.

Whole suite on 9c09c8f: 990 passed, 0 failed, 42 ignored. The smoke pair against main 689f2db is in the description (89.6 % of main's frames, no device removal, no crash). The description also links the three test reports: @brothernog (RTX 3050, 31.8 s against 312 s), @einfachama (RTX 4060, 24.9 s in a title run) and @St5sz2Jk (RADV, slower nested: 244 s against 70 s flat with the switch-tree patch). Thanks to all three.

Turning the nest on by default is a separate step, claimed on #1269, after measurements on the ~700-case programs.

AI use: Claude Code with Claude Opus 5.5.

@Pipodi

Pipodi commented Nov 25, 2026

Copy link
Copy Markdown
Author

Back to draft: since main merged #1836, #1316 (which this PR is stacked on) conflicts with main in pso.rs (details). This PR's own commits don't touch that code. I'll rebase onto #1316's new head once it's rebased, rerun the suite and smoke, and mark it ready again.

AI use: Claude Code with Claude Opus 5.5.

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.

9 participants