Recompiler: lift literals that differ inside a family (XCL_LIFT_LITERALS) #3262
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3262"
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 KOLESNiii on 2026-11-29T02:14:47Z.
Compute programs in a title's pack that are one program with different numeric constants get their literals that differ lifted into
io, so the whole family compiles to one HLSL text, one DXC result and one driver blob. BehindXCL_LIFT_LITERALS=1(off by default) until cold-run numbers are in. Related: #2711 (identical split pieces share a container, does not fold literal variants), #2088.Why: in a cold run of a retail game (RTX 2070 SUPER), 13 repeat driver compiles of literal-only variants took 253 s of the 1,327 s spent in the driver (19 %). Pack-wide, 127 families (312 programs) make 156 extra compiles of 2,682 compute programs (5.8 %). Example: records
b162ea7db32e1657/0ed9e58ef6dc9cdb, 462 KB of DXIL each, compiled twice. All 21 same-size repeats in that run took the HLSL path, which is where this works.How:
xcl shaders --precompile, launch preparation) finds the families. Programs with the same instruction sequence are translated, and those whose HLSL is equal once every literal is masked form a family.uinteger literals inmain's body only. Never attributes, declarations, control-flow or preprocessor lines,[], texture offsets or quad operations. A family with a differing literal anywhere else is left alone.uint xcl_liftN = io.Load(512 + 4N), the same 32-bit value as auint, so the program computes the same thing. Lifting is correct for any program; the family only decides what is worth lifting.What is in it
crates/xcl/src/gpu/recomp/lift.rs: scanner, masked hash, family positions, rewrite, family key, table (built at preparation, kept next to the caches under the translation-cache identity), unit tests, and anXCL_SAMPLE_LIFT_HLSLtest over exported HLSL.crates/xcl/src/gpu/recomp/pso.rs:Compiled::lifted. The HLSL path compiles a family member lifted. A member skips the translated disk cache, which keeps no lifted values.crates/xcl/src/hle/d3d12x/real.rs,bind.rs,console_list.rs: per-pipeline values, written after the SGPRs by both compute dispatch paths.crates/xcl/src/shaders.rs: precompile builds the family table first when enabled, with a log line.crates/xcl/src/gpu/recomp/tests.rs+runner.rs: GPU test. Two programs differing only in literals give one lifted text and one DXIL container, and each gives the same output as its plain translation.runner::dispatchkeeps io words past the SGPRs.Size: ~450 changed lines outside tests (679 with them). One PR because the parts only do something together: the table without the dispatch writes would produce programs that read zeros, and the dispatch writes without the table never run.
Tested
cargo test -p xcl --lib recomp::lift::tests: 7 passed, 0 failed, 0 ignored.XCL_SAMPLE_LIFT_HLSL=<export of the retail game's compute HLSL> cargo test -p xcl --lib sample_families_compile_lifted: 34 liftable families among the programs under 256 KB. The 12 smallest were compiled with DXC 1.9.2609, and each family's members gave one identical DXIL container.cargo build --workspace --tests && cargo test --workspace --no-fail-fast -- --test-threads=4onc0a0ec03(debug; rebased onto main81bfbf0d, run at the same time as the suites of #3262, #3242 and #3241): 2741 passed, 4 failed, 49 ignored, includinggpu_lifted_literal_family_shares_dxil_and_keeps_results(ok)e2etarget, whose test title had not been built (missing …xcl_testtitle.exe – build first: cargo build --workspace)cargo build --workspace:cargo test -p xcl --test e2e: 5 passed, 0 failedSKIPPEDon this adapter (28): 22 no wave64, 3 f16 instructions refused (#1426 semantics differ from the console's), 2 no heap windows (opt-inXCL_HEAP_WINDOWS=1), 1 no GPU_UPLOAD heapsRegression run
main (
fa204595):this PR's head (
1d3b1cb9):Both:
scripts/smoke.ps1 -Seconds 60,XCL_PREPARE=0,XCL_PRESS_AT=25:A, run through the local exclusive queue.XCL_LIFT_LITERALSis unset (off), so the lifting path is not exercised here.These runs are on the head before the rebase (
1d3b1cb9); they have not been repeated onc0a0ec03.Not tested
XCL_LIFT_LITERALS=1(preparation time, driver compiles): numbers requested from contributors in a comment below.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T02:14:57Z.
Results wanted: cold preparation with literal lifting on and off
Some compute programs in a pack differ only in numeric constants. This PR lifts those constants so a family compiles once (DXC and driver). On a retail game, RTX 2070 SUPER: 13 repeat driver compiles = 253 s of 1,327 s driver time in one cold run (19 %); pack-wide 156 extra compiles of 2,682 compute programs (5.8 %). Gain still unmeasured with the switch on: we need cold numbers from other hardware.
KOLESNiii:recomp-lift-literals, commit in the PR),XCL_LIFT_LITERALS=0vsXCL_LIFT_LITERALS=1.cargo build --release -p xcl, say your Rust version.XCL_DXIL_CACHEto a new empty folder for each run;%LOCALAPPDATA%\NVIDIA\DXCache; AMD:%LOCALAPPDATA%\AMD\DxcCache/DxCache);xcl shaders <your title's shader pack> --precompile --pipelines, or a cold launch of your title with preparation on;precompiling …run's end time, or the launch's preparation line);literal lifting: N families, M compute programs lifted (T s)line (on runs);driver compile start/finishlines for compute PSOs (orXCL_ACTIVITY=1totals);scripts/smoke.ps1 -Seconds 60block on both sides, withXCL_PRESS_AT=25:A;Written by Claude Code, Claude Opus 5.5.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T10:05:21Z.
Cold full preparation,
XCL_LIFT_LITERALS=1vs off (one run each, NVIDIA)Two cold runs of full shader preparation (
XCL_PREPARE_ALL=1) on a retail game, each with a freshXCL_DXIL_CACHEand the NVIDIA and D3D shader caches cleared. The only difference between them is this PR, switched on.7db2f391+ #3241 + #3242XCL_LIFT_LITERALS=1Lifting was active in B:
literal lifting: 112 families, 268 compute programs lifted (10.8 s), and no fallbacks were logged.Limits
Setup
Measured and written with Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T14:50:15Z.
Current-main audit (2026-11-29): discard as an experiment, not a merge candidate.
The PR's own cold full-preparation comparison is decisive: it produced 113 fewer blobs around the same point but saved no wall time (54.4 vs 56.1 min for translation/DXC, and the driver tail remained effectively unchanged). The change is 679 additions across nine files, adds per-PSO runtime metadata/ABI uploads and a custom HLSL scanner, and current
mainnow defaults to direct DXIL, where this HLSL-only lifting does not apply.That complexity is not justified by the measured result. Keep the analysis/data, but close the implementation unless a narrowly targeted gameplay-critical family demonstrates a reproducible critical-path win.
Cache impact: not safe for affected cached PSOs; it intentionally rewrites HLSL/DXIL and shares a different driver blob.
Review assisted by Codex; exact model name was not exposed in this session. No additional cold run was performed.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:31:33Z.
Review (head
c0a0ec03, diff read, not a merge-check; draft, conflicts with main,PR descriptionred):kernel::enabled()), and lifting only works on the HLSL path.edited->compile_cached_inbranch inpso.rscompile_console_shaderthat lifting has to respect, and removedfinish_two_pass. After that,shaders.rs~2440 (a newCompiled {on main) still lacksliftedand won't compile.bind.rs~5265 andconsole_list.rs~1065, and no test covers those dispatch writes. Any other writer of a compute program'siowould leave the lifted words unset (unverified that one exists).ioloads per program, DXC loses constant folding, and lifted members bypass the disk cache (pso.rs~272), so they retranslate on every launch.lift.rs~318). A title whose first lookup comes before the preparation process writes the table never lifts in that run.1d3b1cb9with lifting off.Fine: the design holds. Only differing
uinteger literals in plain statements ofmainare lifted, and values come from each member's own HLSL under a masked hash. A uint stays a uint, constant-required contexts are excluded, a lifted text DXC rejects falls back to the plain one, the sample test usesXCL_SAMPLE_*, and it's off by default. If it goes on, a split fits: theCompiled.liftedand dispatch plumbing, thenlift.rswith its tests, then the wiring.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:47:01Z.
Triage (#1607) – head
c0a0ec0No open or merged PR lifts differing literals of a compute family. #2711 (named in the description) shares identical split pieces only.
No problems found in the parts I read: the lifted literals go at
iowordKERNEL_SGPRS(512 bytes), and both dispatch paths (bind.rsandconsole_list.rs) append them afteriohas been resized toKERNEL_SGPRS. The switch is off by default. The branch conflicts with main and its checks fail.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 KOLESNiii on 2026-12-02T15:11:09Z.
@Foniass thanks. Rebased onto
maindf0cfef6: lifting now respectsmain'sedited→compile_cached_inbranch (a text anXCL_DEBUG_*switch edited is never lifted and goes tocompile_cached_in),finish_two_passis gone as onmain, and theCompiledliteralsmainadded (pso.rs,shaders.rs) carrylifted: Vec::new(). New head28a3be03. Whether to keep this PR open, given no measured benefit andmaindefaulting to direct DXIL, is the PR author's decision.— Claude Code (Claude Opus 5.5), on behalf of the PR author
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T15:12:48Z.
Follow-up review (head
28a3be03, sincec0a0ec0, diff read, not a merge-check; draft, checks red, conflicts):XCL_DEBUG_*edited-text path) also never lifts a text anXCL_DEBUG_*switch edited (!editedin the lift condition) and compiles such a text throughcompile_cached_inlike main does.New: none.
AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
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.