Skip to content

Recompiler: compact cases share code whose branch targets differ - #1448

Open
Pipodi wants to merge 5 commits into
xcl-dev:mainfrom
Pipodi:compact-shared-targets
Open

Pipodi wants to merge 5 commits into
xcl-dev:mainfrom
Pipodi:compact-shared-targets

Conversation

@Pipodi

@Pipodi Pipodi commented Nov 24, 2026 •

Copy link
Copy Markdown

Stacked on #1316 (5328b15, on main afc5ee8); only the top commit (80fac65) belongs here.

#1316's compact form keys a block's case on its text, and the text includes the branch offset (xcl_b ± K). So blocks with the same code but different targets get different cases. The retail title's ActivateRays (95cc13288a27a96e, 19,949 blocks) gets 11,909 cases. Its table is then over MAX_TABLE_WORDS, and the program falls back to the normal form. This PR keys a case on the block's code and branch condition, and treats the target as data:

  • One offset: a case whose blocks all jump by the same offset keeps xcl_b ± K.
  • Several offsets: otherwise, the case starts from 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).
  • A bound on the selects: a case evaluates at most MAX_SELECTS (32) of them. Past that, [branch] if (xcl_b < pivot) splits the list until each leaf has at most 32 (xcl_b is wave-uniform, so the branch is too). Without it, a case that 1,799 blocks share ran 1,799 selects on every visit: @milesah3ad's probe found the dispatch up to 80 % slower than on Recompiler: route compute programs through a compact backend (XCL_COMPACT_CS) #1316 (report); on this GPU I measured 37 % (table below). Cases with 32 or fewer differing targets emit the same text as before.
  • Packing across words: with 2,516 cases (12 bits), the usual packing of two cases to a word still needs 9,975 words. A table that the usual packing puts over MAX_TABLE_WORDS is now packed across words: bits bits from bit xcl_b * bits, two reads, and one word of padding. ActivateRays fits in 7,482 words. Tables under the cap are packed as before.

compact_wanted already counted distinct texts without the branch bytes, so the same programs are routed to the compact backend. One more of them now takes the compact form instead of falling back: ActivateRays. The two others below were already compact. Part of #1269.

What is in it

  • crates/xcl/src/gpu/recomp/compact.rs:
    • cases keyed on code and condition, with per-block targets, and the bounded select list (pick_targets, MAX_SELECTS);
    • packing across words past the cap;
    • compact() takes the packing threshold, so tests can force it.
  • crates/xcl/src/gpu/recomp/tests_compact.rs:
    • Dispatch::of reads the packed table; Dispatch::target follows a case's selects and branches for one block;
    • shared_targets: the same block branches forward from one copy and backward from the other; gpu_compact_shared_targets: one case, one select, results identical to translate in every form this adapter runs;
    • many_targets: 64 copies of one block with different targets. compact_many_targets_take_a_bounded_path (CPU) checks every block reaches its target with at most MAX_SELECTS selects; it fails with the bound removed (checked by passing usize::MAX). gpu_compact_many_targets compares the results with translate;
    • gpu_compact_dense_table: the packed table gives every block the case the usual packing gives it, with results identical to translate, on 5 programs.

Tested

  • RTX 4090 (driver 617.42), i9-13900K, 32 GB, Windows 11 Pro 26300, rustc 1.100.0, DXC 1.9.2602.17.
  • 80fac65 (on Recompiler: route compute programs through a compact backend (XCL_COMPACT_CS) #1316 5328b15, on main afc5ee8), debug: cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 gave 1292 passed, 0 failed, 46 ignored, in 23 result blocks. The commit's patch is the same as at 7fadd08 and 57d7574; only the base moved. The measurements below were taken at 57d7574 and not rerun.
  • 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).
  • The probe (@milesah3ad's crates/xcl/examples/cmp1448.rs from a8eebfd, copied in locally, not part of this PR), release, --rounds 3600 --vary 1 --dispatch 30, median of 30 dispatches:
#1316 964f5ed this PR without the bound this PR (bound 32) bound 64
switch (--heap 0) 9.84 ms 13.52 ms 10.39 ms 10.36 ms
heap windows (--heap 1) 12.63 ms 13.41 ms 12.52 ms 12.04 ms
longest select run / [branch] if – 1,799 / 0 32 / 56 64 / 28
DXIL select / br i1 42 / 44 1,833 / 36 1,833 / 92 1,833 / 64

DXC keeps the branches. With --vary 0 (all copies share targets), the HLSL and DXIL are byte-identical with and without the bound; dispatch #1316 9.92 ms, this PR 9.88 ms.

  • xcl shaders <records> --precompile --only cs, then the same with --pipelines (release), on records of the retail title's three screen-probe programs. Each run had a fresh XCL_DXIL_CACHE and a new exe path, so the NVIDIA driver cache missed (each log: pipelines made on the GPU 1, refused 0, loaded from the driver cache 0):
program blocks cases (#1316) table words DXC DXIL driver peak private
ActivateRays 19,949 2,516 (11,909, falls back) 7,482, across words 20–24 s 2.89 MB 175, 190, 215, 233 s, made 8.08 GB
ActivateProbes 21,038 751 (906) 7,013 11.6 s 0.94 MB 12.6 s, made 1.41 GB
ActivateProbesTarget 20,972 698 (851) 6,991 22.2 s 0.85 MB 9.9 s, made 1.18 GB
  • ActivateRays's driver time and the bound: interleaved with the runs above, the same build without the bound (2.85 MB) took 162, 162, 164 and 201 s, and bound 64 took 200, 202 and 216 s. The means are 172 s (no bound), 203 s (32) and 206 s (64); the spread of each overlaps the others, so with 3–4 runs each I can't separate them. Bound 64 gives no gain in driver time and only a small one in the probe with heap windows (12.04 against 12.52 ms), so the PR keeps 32.
  • The case and table-word counts come from local builds that logged them, and the Recompiler: route compute programs through a compact backend (XCL_COMPACT_CS) #1316 counts from 490ccbb, as in the earlier revision of this description.

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. Both runs on this machine, back to back, 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 80fac65:

xcl-smoke v1
commit: 80fac657868d5ce22390f044ce91d8c6f197a318
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1365 (PresentX 1365)
presents per 2 s (last 3): 16 25 44
device removals: 0
crashes: 0
peak commit: 25946 MB

The PR's run got 112.5 % of main's frames and 102.4 % of its peak commit.

Not tested

  • Whether the compact form of the retail programs gives the same results as translate on the GPU; only the small programs above were compared. translate's form of ActivateProbes (28.7 MB DXIL) was still in the driver after 33 minutes, so that comparison has no reference to run against.
  • A title run that reaches this code: 60 s of the title does not reach ActivateRays (in earlier runs neither log had a compact backend line), so the smoke pair is a regression check of the rest only.
  • A driver refusal of the compact form is not retried in the normal form (Recompiler: route compute programs through a compact backend (XCL_COMPACT_CS) #1316 retries only a DXC refusal).
  • AMD: not tested by me. On an RX 9070 XT, @Nmopqr333 found that the AMD driver does not finish ActivateRays in this form (87 GB of private memory in about 150 s). @DTsordas reports the same driver needs over 55 GB for it as 3.3 MB of direct DXIL too.
  • Intel, wave64 hardware, Linux / vkd3d-proton. On Linux, @vitor127wt's run hit their 240 s timeout in the driver.
  • 160–230 s and 8 GB is still a long first build for one program. Recompiler: compact dispatch can switch in two levels (XCL_COMPACT_NEST) #1692 (stacked on this) nests the dispatch; there ActivateRays is 1.04 MB and built in 39 s in a title run on this GPU.

AI use

  • Claude Code. Claude Opus 5.5 (the main session) wrote the change, the bound, the tests and this description, ran the suite, the probe and the driver timings, and did the rebases onto Recompiler: route compute programs through a compact backend (XCL_COMPACT_CS) #1316's eb1f131 and 5328b15. A second agent of the same model reviewed the change before the bound, and another reviewed 7fadd08 with the bound and the packing across words: nothing blocking (it noted that the tests do not reach a select tree deeper than one split). Subagents on Claude Sonnet 5.5 ran the smoke pairs (this one included) and did earlier rebases.

🤖 Generated with Claude Code

@nnonno91

Copy link
Copy Markdown

AMD native-wave64 test report for 6c7bb05

Tested clean head 6c7bb05baa6f3bcb278f156e3473d377e42163b7 on the Ryzen 7 9800X3D’s integrated Radeon graphics. The shared-branch-target and dense-table tests produced byte-for-byte identical results to the standard translator in native wave64 and wave32, with structured and unstructured control flow. The dense-table test covered 28 entries that cross a word boundary.

Tested

  • AMD Radeon(TM) Graphics (driver 32.0.21042.62), GeForce RTX 5090 (driver 617.42), Ryzen 7 9800X3D, Windows 11 25H2 (26200.9974), Rust 1.100.0 MSVC, DXC 1.8.2502.11, debug/test profiles.
  • With XCL_ADAPTER selecting AMD, cargo build --workspace --locked and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output passed with 775 passed, 0 failed, 41 ignored, and no reported hardware skips. The synthetic end-to-end title passed.
  • cargo test --locked -p xcl --lib gpu_compact_ -- --nocapture --test-threads=1 reported 18 passed, 0 failed, 0 ignored on each adapter. I set XCL_REQUIRE_GPU=wave64 on the AMD run. The NVIDIA run exercised split wave64 and reported one hardware skip, gpu_compact_native_wave64_form, which Cargo included in its pass count.

Not tested

  • The optional XCL_SAMPLE_BIG_CS fixture, retail shader equivalence, retail-title smoke runs, and performance. The checks above used the project’s synthetic test programs.

AI use

  • OpenAI Codex (GPT-6, exact model variant unavailable) ran the tests and prepared this report.

@t4l03

t4l03 commented Nov 24, 2026

Copy link
Copy Markdown

Thanks for posting the exact stack. I tested the ActivateRays output from clean head 6c7bb05baa6f3bcb278f156e3473d377e42163b7 on the RTX 4070 Ti. This adds a lower-memory-budget data point for the four-switch-window form.

Tested

  • Windows 11 build 26300, Ryzen 7 7800X3D, RTX 4070 Ti driver 617.14, DXC/validator 1.9.2609.5.
  • An external release extractor called this head's translate_compact on the retail record with four switch windows and the original compute interface and static samplers. It emitted 2,516 cases and 2,275,162 B HLSL. An independent count found 10,096 target overrides. DXC cs_6_6 -HV 2021 -O1 took 18.64 s and emitted 2,848,780 B DXIL, which passed validation.
  • Two serial runs of that DXIL through the same standalone XCL compute ABI probe, each with an empty XCL cache and a distinct helper executable name. NVIDIA's global cache stayed enabled. Both crossed the harness's 6 GiB process-commit cap and were stopped, at 103.32 s / 6.116 GiB and 81.88 s / 6.101 GiB. Neither wrote a blob.

Not tested

  • Completion with a higher memory limit, game dispatch or device removal in the title. The harness stopped the two builds before the driver returned a pipeline. I’m preparing matched window-lowering comparisons against this exact output.

AI use

Codex via T3 Code (gpt-6.2-sol) pinned the head, wrote the external extractor, ran these checks and wrote the report. No game data or generated shaders attached.

@t4l03

t4l03 commented Nov 24, 2026 •

Copy link
Copy Markdown

Immediate-operand sharing follow-up on exact #1448 input

I used the ActivateRays HLSL emitted by 6c7bb05baa6f3bcb278f156e3473d377e42163b7 as input to a local prototype. Sharing case templates that differ at supported unsigned literal positions reduced the case count from 2,516 to 1,214. Decode-and-substitute matched all 19,949 input block bodies and their target expressions. The additional parameter arrays and repacked dispatch table take 11,078 routing words, up from 7,482. The emitted prototype retained 12-bit case IDs. Using 11 bits would bring the projected total to 10,455 words.

RTX 4070 Ti driver 617.14, Windows 11 26300, Ryzen 7 7800X3D, DXC/validator 1.9.2609.5, -O1. Same standalone compute ABI probe and static samplers, separate empty XCL caches and executable names. NVIDIA global DXCache stayed enabled.

Four-window form DXIL PSO wall time Peak process commit
#1448 + switches 2,848,780 B stopped at cap twice 6.116 / 6.101 GiB
#1448 + #680 heap 2,560,312 B 81.49 / 78.11 s 4.340 / 4.338 GiB
Immediate sharing + switches 1,802,576 B 68.40 / 61.10 s 3.384 / 3.379 GiB
Immediate sharing + #680 heap 1,548,804 B 26.79 / 25.47 s 1.428 / 1.427 GiB

The immediate-sharing variants passed DXIL validation and each successful run saved a driver blob. The combined form uses the accessor block emitted by the local #1448 + #680 stack and the immediate-sharing dispatcher. Compared with heap windows alone it cut mean wall time and peak commit by about 67% each. The exact baseline and combined form each hit the 6 GiB process cap in a separate one-run check on the 7800X3D's AMD iGPU, with no blob.

I also tried grouping existing overrides by absolute target without adding tables. The mapping still matched all 10,096 overrides, and the code emitted 5,208 selects. DXIL grew to 2,868,640 B and the first NVIDIA run hit the 6 GiB cap, so I set that form aside.

This is a local compilation and pipeline-creation result. Compatibility of the extra static data, runtime heap binding, and retail dispatch output are still open.

AI use: GLM-5.3 via T3 Code built and tested the local HLSL adapter. Codex via T3 Code (gpt-6.2-sol) verified the artifacts, ran the capped PSO checks and wrote this report. The prototype stays local.

@vitor127wt

Copy link
Copy Markdown

Linux / Wine test of ActivateRays at 6c7bb05

I tested clean head 6c7bb05baa6f3bcb278f156e3473d377e42163b7 in a Windows MSVC release cross-build. The isolated Series 1.0.2.1 CS_ScreenProbes_ActivateRays record (15ec6daefb19a780 in XCL) took the compact route with XCL_COMPACT_CS=auto. Translation and DXC took 12.0 s with 1 compiled and 0 errors. The outputs were 2,275,162 B HLSL and 2,848,780 B DXIL, the same sizes reported in the exact-head Windows test. Windows comparison

Cold PSO with precompiled DXIL Result Peak RSS
Default structurizer 240 s timeout, exit 124 584.2 MiB
Legacy structurizer 240 s timeout, exit 124 583.5 MiB

I ran xcl shaders <isolated folder> --precompile --only cs --windows 4 --split 1 and then the same command with --pipelines in a fresh process for each mode. One DXC worker and one PSO worker, XCL PSO and vkd3d-proton and NVIDIA disk caches disabled, and an 8 GiB cgroup with no swap. The PSO runs used VKD3D_CONFIG=pipeline_library_log and VKD3D_CONFIG=legacy_structurizer,pipeline_library_log. Both logged an empty pipeline cache and shader hash cc7047005a5c7dca. The cached DXIL SHA-256 was unchanged.

RTX 5070 Ti (16 GB), NVIDIA Linux driver 620.73.04, Ryzen 7 9700X, CachyOS x86-64 kernel 7.3.5-2-cachyos, Wine 11.22, vkd3d-proton ec20719452e916b with dxil-spirv 7c04863, Windows DXC 1.9.2609.5. This is one offline PSO attempt per mode, without shader dispatch or a title run. Earlier Wine result for the same shader with #1316 and #1321

AI use — Codex (GPT-6 family, exact variant unavailable) cross-built the exact head, ran the measurements, and drafted this report.

@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

@t4l03 thanks, that is a bigger lever than the one I was measuring. On an RTX 4090, a build of the same ActivateRays input that drops all 10,096 overrides (wrong output, a ceiling only) cuts the DXIL by only 6 % (2,848,780 → 2,672,544 B, DXC 21–25 s → 14 s). Together with your grouping result, the overrides look like a small part of the cost; sharing immediates goes at the case count itself. The driver timing of that ceiling build is not run yet.

Two points before anyone writes it:

  • The table cap. 10,455 routing words is over the compact form's MAX_TABLE_WORDS = 8,192 (compact.rs:27-31). The comment there says CreateComputePipelineState took 12,288 words on an RTX 5070 Ti and failed with E_OUTOFMEMORY at 15,360, for a single array. It is not known whether the limit is per array or for all static data together, which decides whether your parameter arrays fit.
  • Who writes it. Do you plan to open this as a PR stacked on Recompiler: compact cases share code whose branch targets differ #1448? If not, I can write it on top of Recompiler: compact cases share code whose branch targets differ #1448, with a GPU test per substituted operand kind, after you say so; I'd rather not have two versions.

AI use: Claude Code (Claude Opus 5.5) wrote this comment; the 4090 numbers come from its own DXC runs on 98191af, a local build of #1448 with the overrides removed.

@t4l03

t4l03 commented Nov 24, 2026 •

Copy link
Copy Markdown

Thanks for checking the override cost and raising the table limit. I’m taking the immediate-sharing follow-up for now, so please hold off on a parallel implementation. I’m starting with the routing-data budget and GPU equivalence before deciding what is ready to stack on #1448.

The measured layout used 11,078 routing words in four arrays: 7,482 case words and 2,660, 624 and 312 parameter words. The 10,455-word figure was a projection using narrower case IDs.

For provenance, Codex (gpt-6.2-sol) planned and reviewed the experiments and ran the GPU pipeline benchmarks. GLM-5.3 wrote the local HLSL prototype. Any further implementation from my side will be written with GPT and will credit the prototype as prior work.

11-bit follow-up: Codex (gpt-6.2-sol) wrote and ran a scratch repacker on the combined heap variant. All 19,949 case IDs matched independently after repacking. The 10,455-word layout passed DXIL validation and built twice on the same RTX 4070 Ti, in 23.94 / 23.71 s at 1.425 GiB peak process commit in both runs. Both saved a 1,252,974-byte driver blob. The same isolated XCL cache setup was used, with NVIDIA global DXCache enabled. This removes 623 routing words from the measured 12-bit form. The total still exceeds 8,192 words, and retail dispatch correctness is still open.

@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

@t4l03 understood, it's yours; I've stopped my side of it. When you have a branch, I can run its GPU equivalence tests and a --pipelines timing of ActivateRays on an RTX 4090 with driver 617.42, in both window forms.

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

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

Verified head 6c7bb05baa6f3bcb278f156e3473d377e42163b7 on Windows 11 / NVIDIA RTX 5080 (Blackwell, split-wave64):

  • cargo test -p xcl --lib -- gpu::recomp --test-threads=4: 213 passed, 0 failed, 18 ignored (0 new compiler warnings).

Clean pass on RTX 5080.

@t4l03

t4l03 commented Nov 24, 2026 •

Copy link
Copy Markdown

@Pipodi the GPT-written Rust follow-up is available in #1548. The version tested here was stacked on your then-current #1448 head. Set XCL_COMPACT_IMMEDIATES=1 to try it with the usual xcl shaders … --precompile --only cs --pipelines command. XCL_COMPACT_CS still controls eligibility and the translated cache has a separate _ci entry.

On ActivateRays it emits 2,281 cases (was 2,516), with 7,482 dispatch words and 708 operand words. An independent decode check matched all 19,949 emitted block bodies and branch mappings. The synthetic GPU equivalence test passed on RTX 4070 Ti and AMD iGPU with native or split wave64 as available: cargo test --locked -p xcl --lib gpu_compact_immediates_match_translate -- --nocapture.

On the 4070 Ti (617.14), the new output with #680's heap accessors built twice in 64.76 / 63.26 s at 3.509 / 3.492 GiB. The matching #1448 + #680 control was 81.49 / 78.11 s at 4.340 / 4.338 GiB. The new switch form still hit the 6 GiB process cap in one run. These were standalone PSOs with separate XCL caches and NVIDIA global DXCache enabled. The 4090 comparison you offered would be useful, particularly the switch form. The heap arm needs #680 on top of this stack.

AI use: Codex (gpt-6.2-sol) wrote and tested the Rust implementation and wrote this report. The earlier GLM-5.3 HLSL prototype motivated the work.

@kesku

kesku commented Nov 24, 2026

Copy link
Copy Markdown

This gets ActivateRays (95cc13288a27a96e) compiling on my 5080 now!!

With #1316 the table needed 9,975 words and fell back to the old translator. With 6c7bb05 it builds to 2.85 MB of DXIL, the driver accepts it, and the next run no longer waits on that pipeline.

Tested on b7aa9f3 with #1316 and local storage/scheduling changes. Driver 621.01, DXC 1.9.2602.17 :)

@imnicho

imnicho commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Test report at 6c7bb05 from a small machine (4 cores, 16 GB RAM): 15ec6daefb19a780 takes the compact form, its pipeline is built inside a title run, and the process no longer runs out of commit. This is the follow-up to my report on #1316 (#1316 (comment)), where that program's fallback ended every run.

Tested

#1316 at 5e312d5 (the earlier report) this PR at 6c7bb05
15ec6daefb19a780 (76,699 instructions) refused (9,975-word table), translated as before compact form, 2,269,990 B of HLSL
DXC for it – about 40 s (translated at 21.3 s of the run, its DXIL in the cache at 61 s)
its pipeline – 2,560,316 B of DXIL, 175.8 s in the driver, done at 238.8 s of the run
process commit to the cap: 50.2 GB at 100 s 28.8 to 29.6 GB from 120 s to the end
end of the run 0xc0000409 at 125.8 s, before the world's set-up running at the 900 s limit; world set-up at 108.2 s, 0 dispatches skipped
  • d122faa48eb0afdc (88,863 instructions) also takes the compact form here, at 733,609 B of HLSL.
  • The 175.8 s are with the title's other builds beside it on four cores, so they say little about the driver alone.
  • After both programs the title was still waiting for other pipelines (25 builds of 10 s or more in this run) and presented no frame of the world, so I cannot say anything about the output of either compact program in the title.

Not tested

AI use

  • Claude Code with Claude Fable 5.2 ran the build and the run on the machine named and wrote this report.

@t4l03

t4l03 commented Nov 24, 2026 •

Copy link
Copy Markdown

Quick status on the test branch after the repository transfer: GitHub’s API still shows the test branch on the fork, but Git fetches of both the fork and xcl-dev/xcl currently return HTTP 403 with a repository-disabled message. The branch may be unavailable to clone for now. The release CLI check and both 60-second smoke runs are complete. I’m keeping the patch ready while Git access and draft PR creation are blocked.

@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

@t4l03 the 4090 run of 235a71f. Your switch form was the one you asked about; it gets 1.4 GB smaller here, but not faster.

Tested: RTX 4090 24 GB, driver 617.42, 32 GB RAM, Windows 11 Pro (26300), release build. Tree: 235a71f merged locally with #680's final head deb4b92 (local 5e48c35; I resolved two conflicts in recomp/mod.rs by hand: both test modules kept, and the heap-window normalisation of Options at the top of prepare). xcl shaders <pack> --precompile --only cs --pipelines on ActivateRays (95cc13288a27a96e) alone, a new XCL cache per arm. NVIDIA's global DXCache is on: an arm whose DXIL was built before on this machine comes back from it in about 1 s, so the controls are my earlier cold runs. One run per arm.

Arm HLSL DXIL DXC + driver Peak private
XCL_COMPACT_IMMEDIATES=1 + XCL_HEAP_WINDOWS=1 2.19 MB 2.38 MB 113.5 s 3.55 GB
#1448 6c7bb05 + #680 95f34c1, heap (earlier cold run) 2.27 MB 2.56 MB 127.1 s (20.5 + 106.6) 4.37 GB
XCL_COMPACT_IMMEDIATES=1, switch form 2.19 MB 2.67 MB 194.6 s 6.81 GB
#1448 6c7bb05, switch form (earlier cold runs) 2.28 MB 2.85 MB 170–199 s 8.2 GB
  • Both immediate-sharing arms logged (immediate sharing) and made the pipeline, with 0 refused. DXC took about 20 s in each.
  • Heap form: about 11 % less total time and 19 % less peak memory. With one sample, the time difference is within what I saw between runs before (170–199 s for the same switch-form DXIL).
  • Switch form: 17 % less peak memory, and the time is inside the earlier range. It did not hit a cap here; the process passed 6 GiB, so a 6 GiB limit would have stopped it.
  • cargo test --release -p xcl --lib gpu_compact_immediates_match_translate -- --test-threads=4 on this tree: 1 passed, 0 failed, not skipped.

Not tested: repeat runs (needed before the time difference means anything), the full suite on this tree, a title run, AMD.

{"campaign": 1269, "task": "M5", "class": "nv-win", "gpu": "RTX 4090", "driver": "617.42", "commit": "235a71f", "local_patches": ["merge of #680 deb4b92 (local 5e48c35)"], "scenario": "ActivateRays 95cc13288a27a96e, xcl shaders --precompile --only cs --pipelines, cold", "runs": 1, "measurements": [{"what": "imm_heap_total_s", "value": 113.5, "unit": "s"}, {"what": "imm_heap_peak_gb", "value": 3.55, "unit": "GB"}, {"what": "imm_heap_dxil_mb", "value": 2.38, "unit": "MB"}, {"what": "imm_switch_total_s", "value": 194.6, "unit": "s"}, {"what": "imm_switch_peak_gb", "value": 6.81, "unit": "GB"}, {"what": "imm_switch_dxil_mb", "value": 2.67, "unit": "MB"}]}

AI use: Claude Code (Claude Opus 5.5) ran the builds and measurements and wrote this report.

@t4l03

t4l03 commented Nov 24, 2026

Copy link
Copy Markdown

Thanks for running both forms. The switch result is a useful cross-check: it completed above our 6 GiB cap, used less commit than your earlier control, and stayed within its timing range. I’ve added the 4090 result to the draft with the historical-control caveat. Git access has recovered and the tested fork SHA still matches.

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

@Pipodi
Pipodi force-pushed the compact-shared-targets branch from 4cbb6b6 to b370923 Compare November 24, 2026 18:55
@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

@DavidM1911 thanks. #1316 was rebased onto main c160d86, and #1448 is now rebased onto it: head b370923 (on #1316 5749171), no conflicts. The suite passed on the same files: 884 passed, 0 failed, 42 ignored, on the RTX 4090. A new smoke pair against c160d86 is running, and the description gets updated with it.

AI use: Claude Code (Claude Opus 5.5) did the rebase and wrote this reply.

@t4l03

t4l03 commented Nov 24, 2026

Copy link
Copy Markdown

@Pipodi #1316 is now mergeable at 5749171. I’ll rebase #1548 and rerun its GPU tests and smoke check once #1448 is restacked, so the 3060 Ti retest can also use your updated head.

@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

@t4l03 it is restacked: #1448's head is b370923, on #1316 5749171. Nothing in #1448's own commit changed from 4cbb6b6, so #1548 should rebase onto it without trouble.

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

@Pipodi
Pipodi force-pushed the compact-shared-targets branch from 57d7574 to 7fadd08 Compare November 25, 2026 06:46
@Pipodi
Pipodi marked this pull request as ready for review November 25, 2026 06:51
@itsSio

itsSio commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Tested

Independent check requested in #1269, on clean PR head 7fadd08829e3713cdef26829e81356920b9866e4, no local patches or merge. Both systems: Windows 11 Pro 26200, x64 MSVC, unoptimized dev/test with debug info off. cargo build --workspace --locked succeeded on both. cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture completed all 21 test result blocks on each:

GPU / driver CPU, RAM, toolchain Passed / failed / ignored Runtime SKIPPED
RTX 5080 / 32.0.16.1088 Ryzen 7 9800X3D, 32 GiB; Rust 1.97.0, DXC/DXIL 1.9.2609.5 1183 / 0 / 46 26
RTX 2080 SUPER / 32.0.16.1088 Ryzen 5 5600X, 16 GiB; Rust 1.99.1, DXC/DXIL 1.8.2502.11 1183 / 0 / 46 28

Both logged 21 native-wave64 skips, three per-lane f16/f32 refusals, unavailable driver-cache control and unavailable heap windows. The RTX 2080 SUPER also skipped two D3D12 debug-layer tests (test_title_draws_with_a_root_signature_under_the_debug_layer, uploads_start_from_each_subresources_state).

cargo test -p xcl --lib --locked gpu::recomp::tests_compact -- --test-threads=1 --nocapture: 21 / 0 / 0 on the Radeon RDNA2 iGPU (32.0.21043.5001, same Ryzen 7 system) with no runtime skips; 21 / 0 / 0 on the RTX 2080 SUPER with one native-wave64 skip. The shared-branch-target check matched the reference output. The RTX 2080 SUPER results were recovered from the two completed on-disk logs because the runner did not return a terminal response.

Not tested

Retail smoke or samples, full AMD workspace, RADV, Intel, or compile and execution performance.

AI use

Ran via Samaritan:

  • OpenCode with OpenAI GPT-6.2 Sol (openai/gpt-6.2-sol): ran the checks, recovered and verified the logs, and wrote this report.

CowboyBingus and others added 5 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>
@Pipodi
Pipodi force-pushed the compact-shared-targets branch from 7fadd08 to 80fac65 Compare November 25, 2026 14:00
@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.