Skip to content

Recompiler: share scalar operands in compact compute cases - #1548

Open
t4l03 wants to merge 8 commits into
xcl-dev:mainfrom
t4l03:recomp-compact-immediates
Open

t4l03 wants to merge 8 commits into
xcl-dev:mainfrom
t4l03:recomp-compact-immediates

Conversation

@t4l03

@t4l03 t4l03 commented Nov 24, 2026 •

Copy link
Copy Markdown

Stacked on #1448 (through #1315 and #1316). Only the three commits after 57d7574 belong to this PR.

Part of #1269. Compact compute shaders can have repeated bodies with different scalar literals or embedded program-counter values. With XCL_COMPACT_IMMEDIATES=1, eligible bodies can share a case while preserving their original operands and branch targets.

What is in it

  • Share eligible decoded scalar operands and program-counter values under the existing 8,192-word limit for dispatch and operand tables together.
  • Add an opt-in compute route and separate translated cache entries. Keep the existing default and standard compact fallback.
  • Test literal and PC equivalence on the GPU, the routing-data budget, and translated-cache separation.

Tested

  • Windows 11 build 26300, Ryzen 7 7800X3D, RTX 4070 Ti driver 617.14, integrated Radeon driver 32.0.21042.62, Rust 1.100.0, DXC 1.9.2609.5.

  • cargo test --workspace --locked --offline -j 4 --no-fail-fast -- --test-threads=4 --show-output on the RTX 4070 Ti, debug: Cargo reported 988 passed, 0 failed, 42 ignored. The harness logged 24 skipped tests or subcases: 19 without native wave64, three per-lane opcode refusals, one with heap windows unavailable, and one PSO measurement requiring Windows Developer Mode.

  • cargo test --locked --offline -p xcl --lib -j 4 gpu_compact -- --nocapture on the integrated Radeon: 21 passed, 0 failed, 0 ignored, zero skips. This includes GPU readback comparisons for operand sharing and the upstream many-target case.

  • Before the metadata-only rewrite, the release CLI exported and precompiled ActivateRays in both modes with compact compute, Direct DXIL and four descriptor-heap windows enabled (--split 0). Both selected compact HLSL and produced separate _ci.bin and _c.bin entries in the same cache. The case count fell from 2,516 to 2,281; the 7,482-word block table plus the 708-word literal table stayed under the 8,192-word limit. The longest target-select leaf was 32 in both forms, preserving Recompiler: compact cases share code whose branch targets differ #1448's bound.

  • Earlier standalone ActivateRays PSO from the first immediate-sharing revision on this 4070 Ti with Recompiler: memory windows from the descriptor heap (no per-access switch) #680's heap accessors: 64.76 / 63.26 s and 3.509 / 3.492 GiB. The matching Recompiler: compact cases share code whose branch targets differ #1448 heap control took 81.49 / 78.11 s and 4.340 / 4.338 GiB. The switch-window experiment hit the 6 GiB process cap. Separate XCL caches, NVIDIA global DXCache enabled.

  • Independent RTX 4090 (617.42) testing completed both forms on the first immediate-sharing revision with Recompiler: memory windows from the descriptor heap (no per-access switch) #680 applied locally. Switch windows used 6.81 GB versus about 8.2 GB in the earlier control. The 194.6 s result was inside the earlier range. The heap arm used 3.55 GB and took 113.5 s, one run with historical controls. Report.

Regression run

scripts/smoke.ps1 -Game <title folder> -Seconds 60, release, default routing.

main:

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 4070 Ti
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 660 (PresentX 660)
presents per 2 s (last 3): 46 49 47
device removals: 0
crashes: 0
peak commit: 15614 MB

this PR:

xcl-smoke v1
commit: b391e9cca9af3d095e61d998bee7003581724010
gpu: NVIDIA GeForce RTX 4070 Ti
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 564 (PresentX 565)
presents per 2 s (last 3): 31 28 22
device removals: 0
crashes: 0
peak commit: 15985 MB

Not tested

AI use

Codex (gpt-6.2-sol) wrote the Rust implementation and tests, rebased onto 57d7574, ran validation, and drafted this report. GLM-5.3 wrote a separate local HLSL research prototype that motivated this implementation. That prototype and its generated shader artifacts are outside this PR.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

@t4l03

t4l03 commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Thanks, @DavidM1911. I verified that the head at the time contains main at c160d86 and merges cleanly. GitHub also reports the PR as mergeable. You can fetch the current PR head with git fetch https://github.com/xcl-dev/xcl.git refs/pull/1548/head and test FETCH_HEAD in a clean checkout. If the conflict still reproduces, could you share the two SHAs you used?

AI use

Codex (gpt-6.2-sol) checked the Git refs and merge tree and drafted this reply.

@t4l03

t4l03 commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Update for the RTX 3060 Ti retest: main advanced from c160d86 to 85e3826, and the head at the time conflicts. @CowboyBingus @Pipodi, I reproduced the same gpu/recomp/pso.rs conflict starting at #1316 (5749171). The export added by #1524 calls the five-argument console_translation from shaders.rs, and #1316 changes that function's signature and return type for compact routing. I'll restack #1548 and rerun its tests and smoke pair once #1448 has the updated base.

AI use

Codex (gpt-6.2-sol) checked the merge trees and drafted this update.

@t4l03
t4l03 force-pushed the recomp-compact-immediates branch from ccfd4c6 to 9c26337 Compare November 24, 2026 20:28
@t4l03

t4l03 commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

@DavidM1911 the retest head was stacked on #1448 42b2f11. I verified a clean merge against main 4178e88, and GitHub reports the PR as mergeable. git fetch https://github.com/xcl-dev/xcl.git refs/pull/1548/head will fetch the new head for your RTX 3060 Ti retest. The description has the fresh suite and smoke results.

AI use

Codex (gpt-6.2-sol) rebased, validated, and drafted this update.

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
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
@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown

@t4l03 heads-up: #1448 has a new head, 57d7574. It is #1448's old commit plus a bound on the per-case select list (MAX_SELECTS = 32, split by [branch] if (xcl_b < pivot), in pick_targets in compact.rs), rebased onto #1316 964f5ed. #1448 is now ready for review. This PR's three commits no longer merge onto it without conflicts (checked with git merge-tree), so it needs a rebase onto 57d7574 when you get to it. The bound only changes cases with more than 32 differing targets.

AI use: Claude Code with Claude Opus 5.5.

Factor up to two decoded literal values out of repeated compact bodies. Keep lookup records sorted by block and count their storage and the dispatch table against the existing word limit. Retain standard compact routing and exercise the opt-in API against the standard translator on the GPU.

Prior experiment: a local HLSL prototype written with GLM-5.3 motivated this independent Rust implementation.

Assisted-by: Codex (gpt-6.2-sol)
Treat the exact low dword of S_GETPC_B64 as an eligible runtime parameter. Test distinct PCs in two shared blocks against the standard translator, including the first block's saved PC and the final pair.

Assisted-by: Codex (gpt-6.2-sol)
Route eligible compute shaders through immediate sharing when explicitly requested and keep the translated cache separate from the normal and compact forms. Preserve standard compact fallback on translation errors.

Assisted-by: Codex (gpt-6.2-sol)
@t4l03
t4l03 force-pushed the recomp-compact-immediates branch from 9c26337 to 2f9d88f Compare November 24, 2026 23:08
@t4l03
t4l03 marked this pull request as ready for review November 24, 2026 23:08
@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 2f9d88f (on its base 266b845).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::dxil::fuzz_tests: 983 passed, 0 failed, 42 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_compact_native_wave64_form, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: literal_family_sharing_stays_within_the_table_budget, equal_blocks_share_one_case, compact_is_wanted_for_large_repetitive_programs, gpu_compact_matches_translate, the_switch_reads_auto_0_and_1, only_compute_goes_to_the_compact_backend, translated_compact_and_normal_forms_are_kept_apart, a_refused_compact_form_is_compiled_in_the_normal_form, the_compact_routing_goes_before_direct_dxil, compact_and_normal_forms_compile, gpu_compact_execz_nest, gpu_compact_backward_loops, compact_many_targets_take_a_bounded_path, gpu_compact_many_targets, gpu_compact_immediates_match_translate, gpu_compact_shared_targets, gpu_compact_dense_table, gpu_compact_repeated_blocks, gpu_compact_far_jumps, gpu_compact_v_mul_lo_u32, gpu_compact_buffer_load_format_x, gpu_compact_native_wave64_form, gpu_compact_compute_dispatch, gpu_compact_memory_windows, gpu_compact_memory_windows_loop, gpu_compact_programs_with_four_windows, gpu_compact_exchange_repeated, gpu_compact_buffer_load_format_x_repeated, gpu_compact_endpgm_before_last_block, gpu_compact_against_the_pc_block_fallback, gpu_compact_sample_big_cs.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 988 passed, 0 failed, 42 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 62265d3 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651) and the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

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