Skip to content

Recompiler: compact form that emits every distinct block text once - #1315

Open
CowboyBingus wants to merge 3 commits into
xcl-dev:mainfrom
CowboyBingus:recomp-compact-form
Open

CowboyBingus wants to merge 3 commits into
xcl-dev:mainfrom
CowboyBingus:recomp-compact-form

Conversation

@CowboyBingus

@CowboyBingus CowboyBingus commented Nov 24, 2026 •

Copy link
Copy Markdown

A compact translation for very large compute programs whose basic blocks repeat: each distinct block text is emitted once, as a case of one dispatch loop, and a static table gives every block's case and branch offset. Part of #1269 and #505 (the 29.75 MB ActivateProbes program, see this comment).

This PR adds the form and its tests; nothing calls it yet. #1316, stacked on this one, routes compute programs to it.

Measured on an RTX 5070 Ti (driver 621.24), indirect_diffuse_lighting:CS_ScreenProbes_ActivateProbes (56c0cd3b82a00c6e, 88,863 instructions), 4 memory windows, split wave64, through XCL's own DXC path and level rule; CreateComputePipelineState with XCL's ABI root signature, no cached blob, from a new exe:

translate translate_compact
HLSL 31,028,146 B 723,453 B
DXIL 29,750,144 B 1,053,264 B
DXC 138.6 s (-O0) 12.5 s
CreateComputePipelineState killed at a 600 s cap 9.7 s

The translate column was measured on 47efa2e plus one local commit outside gpu/ (bc394e3). The 600 s run was the same DXIL (sha256 e45bc693…) on another local tree. The translate_compact column was measured on a local merge (31be310) whose compact.rs differs from this PR's in two comments.

The program has 14,378 basic blocks, and 594 distinct block bodies when branch targets are set aside. compact_wanted takes programs of 20,000 instructions or more whose distinct blocks hold under 30 % of the instructions. By a survey of the retail pack's 2,689 compute-program records (2,682 distinct programs) that applies the same rule, these are 56c0cd3b82a00c6e, 958400d2caf07244 (ActivateProbesTarget) and 95cc13288a27a96e (ActivateRays).

ActivateRays needs a 9,975-word table. The table is capped at 8,192 words: a static array is constant data for the driver, and on this GPU CreateComputePipelineState of this program's compact form with an added 12,288-word static array succeeded, and with 15,360 words failed with E_OUTOFMEMORY. So translate_compact returns an error for ActivateRays, and the caller keeps translate.

Related: #1278 and #1279 change how programs of 4 MB of DXIL or more are scheduled. This PR adds a form for two of them, and the stacked PR routes them to it.

What is in it

  • Recompiler: decode and set up the emitter in prepare(), shared by translate – gpu/recomp/mod.rs, no behaviour change. prepare also takes the HEAP_WINDOWS flag out of mem_windows, as translate did since Recompiler: memory windows from the descriptor heap (no per-access switch) #680, so the compact form gets the same options.
  • Recompiler: compact form that emits every distinct block text once:
    • gpu/recomp/compact.rs (new).
    • gpu/recomp/emit.rs: reset_temps, so temporaries are numbered from t1 for each instruction.
    • Block bodies are the text emit::Em produces for each instruction, as in translate; the A/B tests below compare the results.
    • 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.
  • Tests: A/B tests of translate_compact against translate on the GPU – gpu/recomp/tests_compact.rs.
    • Each test runs the same program through both forms and compares SGPRs, SCC, VGPRs, exports and memory.
    • Each test that uses the compact form asserts it does: the HLSL differs, and the cases, blocks and shared cases are counted.
    • Programs:
    • Also a test that DXC compiles both forms.
    • The test file is 1,220 lines. It is not split from the form because these tests are what shows the form computes what translate does; the runtime code is about 380 lines.

Tested

  • RTX 5070 Ti (driver 621.24), AMD Ryzen 7 9800X3D, Windows 11 (10.0.26300).
  • This PR's head 0d7907b (on main 6e1e2be): cargo build --workspace and cargo build --release succeeded; cargo test -p xcl --lib compact -- --test-threads=4: 25 passed, 0 failed, 0 ignored, with gpu_compact_native_wave64_form SKIPPED (no wave64); cargo test -p xcl --lib pso:: -- --test-threads=4: 16 passed, 0 failed, 1 ignored (compile_time_bench::repeated_pso_shader_compile). The full suite was not run on this head.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 (debug) on an earlier head of this PR, c195f07 (on main 266b845): 976 passed, 1 failed, 42 ignored (lib tests 927 / 1 / 22). The failure is hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory (kernelx.rs:2070), which fails the same way on main 930e8b4. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, gpu_compact_native_wave64_form, and 16 lines of main's lower / lower_dxil tests. SKIPPED (per-lane form refused): 3 lines of lower_dxil's f16 / f32-conversion tests. SKIPPED (no heap windows): heap_window_out_of_memory_falls_back_to_the_switch_form.

Regression run
scripts/smoke.ps1 -Game <game folder> -Seconds 60 -Title retail (release builds, menus, no input):

main:

xcl-smoke v1
commit: 6e1e2befc7430126b1e7b98b5c3fe93813c866b6
gpu: NVIDIA GeForce RTX 5070 Ti
title: retail
seconds: 60
exit: 0x0
frames shown: 1538 (PresentX 1538)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17225 MB

this PR:

xcl-smoke v1
commit: 0d7907b385de6670b1a471ee015c32464da7ae10
gpu: NVIDIA GeForce RTX 5070 Ti
title: retail
seconds: 60
exit: 0x0
frames shown: 1591 (PresentX 1591)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17294 MB

Not tested

  • AMD, wave64 hardware (the native wave64 case skips here: no wave64), Linux / Wine.
  • A GPU A/B run of the full 88,863-instruction program: its translate form did not finish in the driver within 600 s on this GPU.
  • This PR alone in a title run (nothing calls the form yet).
  • The compact form with Recompiler: memory windows from the descriptor heap (no per-access switch) #680's heap windows (XCL_HEAP_WINDOWS=1): the A/B tests use the switch form.

AI use

  • Claude Code (Claude Opus 5.5) wrote the code, the tests and this description, and ran the measurements; I ran the tests and runs on my machine and checked the results.

🤖 Generated with Claude Code

@DarkPanda69

DarkPanda69 commented Nov 24, 2026 •

Copy link
Copy Markdown

AMD run with 64-lane waves, where gpu_compact_native_wave64_form runs instead of skipping. Updated for head 0d7907b (earlier runs on c195f07, 7118972, d58677a, 732f2ff, a45ac0c and a940184, same result).

Tested: pass, head 0d7907b applied on main 6ea813a, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.

cargo test -p xcl --lib -- gpu:: --test-threads=4 (now the wider gpu:: filter, which also runs the direct DXIL tests):

  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010, waves 32..64: 604 passed, 2 failed, 22 ignored. The 2 failures are the AMD fuzz seeds 722 and 1599 tracked in 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, which fail the same way on main without this PR. All 17 gpu_compact_* tests ok, gpu_compact_native_wave64_form and gpu_compact_against_the_pc_block_fallback included.
  • NVIDIA RTX 3060, driver 32.0.16.1088, waves 32 only: 606 passed, 0 failed, 22 ignored. gpu_compact_native_wave64_form SKIPPED (no wave64); the other gpu_compact_* tests ok.
  • The other SKIPPED lines (direct DXIL per-lane form refused, and no wave64 on the 3060) are the same on main without this PR.

gpu_dxil_wide_parity was not rerun for this head (3 passed, 0 SKIPPED on both GPUs at c195f07).

Not tested: the whole workspace suite; #1316 on top of this; a title; compile time of the big program.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@ASThome00

Copy link
Copy Markdown

Test report for this PR on an adapter with native 64-lane waves, which covers the test listed as skipped above.

Commit: 711897240007a7c906bd31b1bb571a15907f1269 (this PR's head, on main 930e8b4), debug build.

Hardware: AMD Radeon(TM) Graphics (integrated, Ryzen 9 7900X3D; driver 31.0.24002.92) and NVIDIA RTX 5070 Ti (driver 32.0.16.2124), 64 GB RAM, Windows 11 26300, Rust 1.100.0, DXC 1.9.2602.17.

Tested

  • XCL_ADAPTER=radeon cargo test -p xcl --lib compact -- --test-threads=4: 19 passed, 0 failed, 0 ignored, none SKIPPED. gpu_compact_native_wave64_form ran and passed; the "wave64 native" variants (also unstructured and with 4 windows) report result bytes identical to translate.
  • XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 769 passed, 1 failed, 41 ignored. SKIPPED (no mesh shaders): gpu_geometry_mode_es_gs_strip, gpu_mesh_mode_two_passes.
    • The failure is gpu::recomp::tests::gpu_s_round_mode_controls_f16_rounding_across_modes (tests.rs:6838, lane 1 (0xbf800800) RNE: left 15360, right 48128). It fails the same way on main 930e8b4 on this adapter (2 of 2 runs), so it is not from this PR.
  • Same command on the RTX 5070 Ti: 770 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, gpu_compact_native_wave64_form.

Not tested

AI use: Claude Code (Claude Fable 5.2) ran the tests and wrote this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, 21 ignored.

Thanks!

@thaqiart139-alt

thaqiart139-alt commented Nov 24, 2026 •

Copy link
Copy Markdown

Edited: rerun on the current head a45ac0c (rebased onto main c160d86). The first run was on 7118972, against main 930e8b4, with the same result: all pass on both GPUs.

Test report for this PR's head a45ac0c on AMD RDNA2 with native 64-lane waves (the description's "native wave64 case skips here"), and on a 32-lane NVIDIA card.

Tested

  • GPUs: AMD Radeon(TM) Graphics, the RDNA2 iGPU of a Ryzen 7 7800X3D (native wave64, driver 32.0.21045.29003), and NVIDIA GeForce RTX 5070 (driver 32.0.16.2101). Ryzen 7 7800X3D, 32 GB, Windows 11 Home build 26300, Rust 1.100.0, debug, DXC 1.9.2602.17 (Windows SDK 10.0.26100.0). Adapter chosen with XCL_ADAPTER=radeon / nvidia; the SKIPPED lists below show which GPU each run used.
  • cargo test --workspace -- --test-threads=4, this PR against its base:
main c160d86 this PR a45ac0c
RTX 5070 858 passed, 0 failed, 42 ignored 877 passed, 0 failed, 42 ignored
Radeon iGPU 858 passed, 0 failed, 42 ignored 877 passed, 0 failed, 42 ignored
  • All 16 tests in tests_compact.rs pass on the iGPU, gpu_compact_native_wave64_form included (it runs there; on the RTX 5070 it is SKIPPED: no wave64). gpu_compact_sample_big_cs returns at once without XCL_SAMPLE_BIG_CS, so 15 of them ran.
  • hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory, the one failure in the description, passes on both GPUs here, on c160d86 and on a45ac0c.
  • SKIPPED, the same on c160d86:
    • RTX 5070: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware and gpu_compact_native_wave64_form (no wave64); heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
    • iGPU: gpu::dxil::graphics::tests::emitted_ms_primitive_attribute_reaches_the_pixel_shader, gpu::dxil::graphics::tests::emitted_ms_ps_draw_a_triangle, gpu_geometry_mode_es_gs_strip and gpu_mesh_mode_two_passes (no mesh shaders); heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

Not tested

  • The giant retail programs, a title run, DXC or driver timings, other AMD generations, Linux / Wine.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report.

@CowboyBingus

Copy link
Copy Markdown
Author

Rebased onto main 9e3831e (after #680); the head is now 732f2ff. Two conflicts, both in gpu/recomp/mod.rs: #680's HEAP_WINDOWS handling at the start of translate now sits in prepare(), which translate and translate_compact share; and the module list keeps both mod heap_window_tests and mod tests_compact. Suite, smoke and description are updated for the new head.

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

@CowboyBingus

Copy link
Copy Markdown
Author

Rebased onto main c160d86 (after #1426); the head is now a45ac0c. No conflicts in this PR's commits. Suite, smoke and description are updated for the new head.

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

@CowboyBingus
CowboyBingus force-pushed the recomp-compact-form branch 2 times, most recently from 8174658 to c195f07 Compare November 24, 2026 21:20
@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 25, 2026
The third-largest compute program of a retail pack repeats itself as the
two largest do (13,890 blocks of 2,643 kinds), but its branches go to
6,530 different pairs of offsets. As an index into a table of pairs its
tables were about 24,000 words, over the limit, and it kept the plain
form: 3.9 MB of DXIL.

In it, as in the other large programs, a block's second successor is
the next block or the same as its first. When every conditional branch
of a program falls through to the next block, a table entry now holds
the taken successor itself if that makes the tables smaller: 11,287
words here, in one table. The limit goes from 8,192 to 12,288 words,
the size xcl-dev#1315 measured an RTX 5070 Ti accepting in the HLSL form, and
the program takes the form.

Part of xcl-dev#1269.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
CowboyBingus and others added 3 commits November 24, 2026 22:01
…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>
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 25, 2026
The third-largest compute program of a retail pack repeats itself as the
two largest do (13,890 blocks of 2,643 kinds), but its branches go to
6,530 different pairs of offsets. As an index into a table of pairs its
tables were about 24,000 words, over the limit, and it kept the plain
form: 3.9 MB of DXIL.

In it, as in the other large programs, a block's second successor is
the next block or the same as its first. When every conditional branch
of a program falls through to the next block, a table entry now holds
the taken successor itself if that makes the tables smaller: 11,287
words here, in one table. The limit goes from 8,192 to 12,288 words,
the size xcl-dev#1315 measured an RTX 5070 Ti accepting in the HLSL form, and
the program takes the form.

Part of xcl-dev#1269.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

6 participants