Recompiler: a program's HLSL has only the prelude functions it reaches #2817
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2827"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Alox0099 on 2026-11-26T15:34:53Z.
Every translated program carries
PRELUDEandPRELUDE_MEMwhole – 91 helper functions, about 31 KB – and calls a few of them. The DXIL cache is keyed on the HLSL, so changing any one helper changes the key of every program, and a title then recompiles all of them, whether or not they use that helper. #587 (frexp_mant), #2334 (msad_u8,pk_sad_u16) and #2247 (rla) each did this on the retail pack. A program's HLSL now contains the globals and only the prelude functions it reaches. Changing a helper then recompiles only the programs that use it. DXC drops unreached functions, so the DXIL does not change. Part of #1269 and #2088.What is in it
crates/xcl/src/gpu/recomp/emit.rs:finishputs placeholders where the two preludes go.with_preludesreplaces them with the globals and the functions the program reaches: those named outside the two preludes, and in turn those that the kept functions name. A name counts wherever it appears as a whole word, so a stray match keeps a function it does not need, never the other way round.prelude_itemssplits a prelude into its functions, each with the comment lines above it, and the rest. Unit tests: the split puts the prelude back together exactly and finds every braced block; a program gets the functions it reaches and their dependencies, no others, and the globals; a program that names every function gets the preludes whole.crates/xcl/src/gpu/recomp/tests.rs:gpu_mad_nf_f16_rounds_intermediate_in_binary16adds calls tomad_nf_f16to a translation. RDNA2 has no instruction that emits it, so the test now adds the definitions it needs with the probe (missing_prelude_functions, test only). Its assertions are unchanged.Tested
86e86fc.cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4, run on this commit and on86e86fcalone:86e86fc: 2885 passed, 5 failed, 51 ignored. In that run the lib test binary aborted part-way (misaligned pointer dereferencein windows-core, on threadxcl-pso-ahead-2, STATUS_STACK_BUFFER_OVERRUN), so these counts are the other binaries of that run plus a rerun ofcargo test -p xcl --lib -- --test-threads=4on86e86fc(2741 passed, 0 failed, 31 ignored).test_title_runs_and_game_folder_is_untouched(raytracing AS SRV slot check),test_title_runs_under_the_debug_layer_with_dred,test_title_draws_with_a_root_signature_under_the_debug_layer, andtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs(counted twice by cargo). The 2 more passes are this PR's two tests.eb9a9a7) failed on 8title_texturestests that failed on main's CI at the same time (run 46261846646 on7a649b0); they pass on86e86fc.pso_measurement_compiles_an_exact_synthetic_record("cannot disable the driver cache", no Developer Mode),heap_window_out_of_memory_falls_back_to_the_switch_formandtwo_pass_binds_set_the_shared_view_heap("no heap windows"),mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment("no GPU_UPLOAD heaps")b49be18against the same change on it,3bdd5f2):xcl shaders --recomp: the same report from both (the same programs translated, the same refusals); the whole pass took 544 s on main and 553 s here (one run each, run at the same time).XCL_DUMP_HLSL,XCL_DUMP_EVERY=40: 671 programs, all stages) and compiled withdxc.exe1.8.2502.11 with the same flags: 671 / 671 byte-identical DXIL.dxc.exeat a time: 18.3 s → 17.4 s (5 % less).frexp_mantandpk_sad_u16are now in none (before: all 671), andrlais in 487.-O1, so DXC compiles them at-O3instead: 0.5 s more each, 0.2–1 % smaller DXIL.Regression run
The retail title on the RTX 3070 Ti, after a warm-up run of each build; the two blocks below were run back to back, PR first. main now prepares the whole shader pack before starting the title, which takes longer than the smoke allows here, so both runs set
XCL_PREPARE=0(README) and compile shaders as the title asks for them, as before. Frame counts vary from run to run on this PC: the other measured runs of the same two commits gave 1438 (main) and 1196 (this PR) frames.Not tested
HANDOFF.mdnotes that a prelude change makes every title recompile (e.g. "Prelude changed: titles recompile"). After this PR that holds only for the programs that use the changed function.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by SzczepanGrela on 2026-11-26T15:49:19Z.
RDNA4 / Wine check of the HLSL prelude pruning, including byte comparisons with the current main.
Tested
3bdd5f2fa7bc5566fb633739765bb84882257573, whose parent isb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7.8b957bec6f82495aec940944c6bf47faa02db590, and a separate copy of that main with this PR's two changed source files applied. Both files were unchanged between the parent and current main, so this integration needed no conflict resolution.8293130ebe370b1+(local asserts-disabled build), DXC/DXIL 1.9.2602.17, Rust 1.97.1, releasex86_64-pc-windows-gnu.dxc::compileand the kernel runner's readbacks. No original assertion was changed. Removing those hooks reconstructs the pinned source bytes.Results
gpu::recomp::emit::tests::, at both one and four test threads:Eleven original GPU tests were then run serially in three fresh processes per source copy, alternating source order. Each process: 11 passed, 0 failed, 0 ignored. The set covers frexp f32/f16 sign handling, f64 exponent/mantissa, f32 denorm modes, QSAD/MQSAD, integer multiply/shift/BFE, format packing/saturation, global/LDS atomics, permlane/WQM and the f16 intermediate-rounding probe changed in this PR. Native wave64 ran; the tests that explicitly request wave32 also ran.
gpu_qsad_and_mqsadadditionally exercises its own direct-DXIL controls. No capability skips in any of the 15 top-level processes.From those GPU processes:
The atomic fixture deliberately does not initialize its LDS counter. Its 64
DS_ADD_RTN_U32old values passed an independent consecutive-values check modulo 2^32 in every run; their absolute starting value varies on main too. Lane 63's secondDS_READ2neighbor is outside the LDS area written by the fixture, and its original oracle explicitly excludes that value. Only those 65 raw slots are omitted from cross-run byte equality. The other raw slots and final global memory compare exactly; final atomic add/max values remain 64/163. This does not change or relax the original test assertions.All summaries, skip checks, captured files, source inventories and executable hashes were independently verified.
Build:
cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run. Run the libtest executable under GE-Proton Wine with the emitter-module filter and--nocapture --test-threads=1/4. The GPU matrix uses--exact --nocapture --test-threads=1with these fullgpu::recomp::tests::selectors:Inherited
XCL_*flags are cleared, then explicit RX 9070 selection,XCL_REQUIRE_GPU=wave64,XCL_DIRECT_DXIL=0,XCL_DXC_THREADS=1,XCL_NETWORK=0, the DXC folder and private enabled XCL/vkd3d caches are set. The observation directory contains only these synthetic test artifacts.Not tested
Retail inputs,
scripts/smoke.ps1, full suite, native Windows, other GPUs, every prelude function or shader stage, a changed-helper cache-invalidation experiment, DXC/driver timing, startup time or FPS. The emitter module's RLA reference tests build from the full prelude constant; the eleven translator GPU tests above exercise the changed emission path.AI use
OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the diff, added the local observation hooks, ran the original tests on all three source copies, independently verified the evidence and drafted this report. Publication authorized by the account owner.
Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-26T15:49:39Z.
AMD run with native wave64 (listed as untested), and an RTX 3060 in the same PC: no change from
mainon either card.Tested: pass, head
3bdd5f2applied onmain8b957be, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17,XCL_DIRECT_DXILunset (the HLSL path), card picked withXCL_ADAPTER.cargo test -p xcl --lib -- gpu:: --test-threads=4 --nocapture,mainand this PR one after the other on each card:main708 passed, 2 failed, 6 SKIPPED; this PR 710 passed, 2 failed, 6 SKIPPED. The 2 failures arefuzz_validate_and_gpu_1and_3, the AMD fuzz seeds in #2115, the same onmain. The "no wave64" subcases that skip on NVIDIA run here.main710 passed, 0 failed, 24 SKIPPED; this PR 712 passed, 0 failed, 24 SKIPPED.On both cards the only result changes are the two new tests,
a_program_gets_the_helpers_it_reaches_and_no_othersandthe_preludes_split_into_their_functions_and_back, both ok. The SKIPPED sets are the same as onmain.Not tested: the retail shader pack or a title on AMD,
XCL_DIRECT_DXIL=1, release, Intel.AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T18:34:57Z.
Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2827 at
3bdd5f2fa7bc5566fb633739765bb84882257573(exact parent & merge-baseb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). Measurements and targeted test results only; not a full source review.Setup
7956 MiBreported by D3D12), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200rustc 1.100.0 (0ef1bc386 2026-11-09), DXC1.9.2609.5, release builds, quiet machine (zero concurrent builds/tests during timed runs; noteemit.rschangesXCL_TRANSLATOR_SOURCE_ID, so HLSL-path shaders translated under3bdd5f2fcompiled into a fresh translator namespace)title: 29640639viascripts/smoke.ps1 -Seconds 60(XCL_NETWORK=0, default flags, no input)Targeted RTX 4060 release unit & GPU tests (
3bdd5f2f)cargo test --release -p xcl --lib the_preludes_split_into_their_functions_and_back -- --nocapture: 1 passed, 0 failed, 0 ignored (0.00 s,0SKIPPED).cargo test --release -p xcl --lib a_program_gets_the_helpers_it_reaches_and_no_others -- --nocapture: 1 passed, 0 failed, 0 ignored (0.00 s,0SKIPPED).cargo test --release -p xcl --lib gpu::recomp::: 403 passed, 0 failed, 20 ignored (4.87 s;23SKIPPEDnotices:20no wave64on NVIDIA wave32 RTX 4060 +3pre-existing#1426per-lane-form refusals forV_MUL_F16,V_PK_MUL_F16,V_CVT_F16_F32).Paired 60 s RTX 4060 smoke (exact parent
b49be183vs3bdd5f2f)Both runs completed cleanly at steady 60/2 s pacing with
0device removals and0crashes (3bdd5f2fxcl.log:6,176/6,116 MBpeak/end local VRAM,4,683 MBend non-local VRAM,19,540translated draws /1,024dispatches with0skipped).Exact parent (
b49be183):PR #2827 head (
3bdd5f2f):Limits of coverage
3bdd5f2f(only the 2 new tests individually, all403passing tests ingpu::recomp::, release build, and exact-parent paired 60 s smokes);20wave64 GPU tests skipped on wave32 NVIDIA hardware.RTX 4060) on native Windows 11; no AMD, Intel, or Wine/Linux run on this host.AI use
Ran the targeted release unit/GPU tests, release build, and exact-parent paired quiet 60 s smoke runs with assistance from Google Antigravity (Gemini 4 Neon); all test counts, timings, memory figures, and smoke blocks were extracted directly from
cargo test,xcl.log, andscripts/smoke.ps1outputs.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:01:06Z.
Triage (#1607) – head
a59afc8#1043 solves the same problem differently: it splits
PRELUDE_MEMby hand into blocks chosen by substrings of the body and also prunes the window accessors andFMT_INFO; this PR keeps thePRELUDE/PRELUDE_MEMfunctions reached through a whole-word name graph.No problems found in the diff:
with_preludesruns beforewindowed, but the accessors it inserts call no prelude function, and no code outsideemit.rsinjects calls to prelude helpers into emitted HLSL (the one test that does is adapted viamissing_prelude_functions). Every DXIL cache key changes once.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-03T13:14:22Z.
merge-check
base:
a815de932chead:
a59afc8dc5merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3020 passed, 0 failed, 56 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same list as on main
395405e4; failing: nonereview: read the whole diff (2 files, +166 -3). No blocking finding.
gpu::,XCL_DIRECT_DXIL=0gpu::,XCL_DIRECT_DXIL=1gpu::recomp,XCL_DIRECT_DXIL=0,XCL_HEAP_WINDOWS=1hle::d3d12x::real,XCL_DIRECT_DXIL=0The rows overlap, so the counts do not add up to distinct programs. Five compiles a run were of HLSL that a test had edited after the translation; those were not compared. All tests passed in these runs too. In the first row the HLSL is 4.1 MB instead of 17.2 MB.
2) Nothing that is added after the pruning needs a pruned function:
windowedonly renamesmem.calls and adds the accessors, which use no prelude helper. The linked form (emit::linked_form) takes out those accessors, not the preludes.3) The benefit holds with today's caches (from reading). The
translatedcache is keyed on a hash ofemit.rs, so after a helper edit every program is still translated again. The DXC step is keyed on the HLSL text, so only programs that use the helper are compiled again.4) Not tested: a retail title or its shader pack (none on this machine), AMD.
performance: one rebuild of the HLSL path's DXIL after this lands, as the description says. I did not measure the translation time; the description has 544 s on main and 553 s here for the whole pack, one run each.
verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300, DXC 1.9.2602.17 / Claude Code (Claude Opus 5.5)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.