Shaders: startup preparation builds a split program's whole, not its chain #3442
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3442"
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-29T17:34:48Z.
Startup preparation compiled every split compute program's whole DXIL twice, and its pieces, although the runtime only uses the first of those builds.
Why
Where a cold full preparation's compute driver work goes (retail game, RTX 2070 SUPER). All 2,730 compute translations of the title's direct-DXIL cache, banded by the size of the whole program's DXIL. Driver time is weighted as size^1.6, the exponent fitted to 1,340 cold compiles on this card (size^1.5 to size^1.7). On
main, startup preparation builds every split program three ways: whole (ABI root), every piece, and the whole again under the chain root.Script and data:
bands.pyover the translated cache, with the per-band results for size^1.5, ^1.6 and ^1.7; more context in https://github.com/xcl-dev/xcl/issues/2088#issuecomment-7262349510.The mandatory path (
Pipelines::prepare_compiled_compute:xcl run's startup preparation and its workers, also the PSO corpus and milestones) built, for every program that direct translation split into a dispatch chain:.pso),.chain.pso),.chain.pso).Since
ec80c071the runtime first loads the ABI whole blob (CachedWholeintranslated_compute_pso_once). When that blob loads, it builds no chain, so 2. and 3. were never used. A chain's own whole is still built lazily by the runtime if a chain ever needs it. In a cold full preparation of a retail game, size-weighted, the chain-root wholes are ~40 % of the compute driver work and the pieces ~12 %: ~52 % in all (see Why below).Now the whole is built first, and the chain only when the runtime would not find the whole (
chain_needed): when the whole was refused or overXCL_PIPELINE_MAX_KB, or its driver blob is not on disk. In that case the pieces are built as before, and the record counts as prepared once they are. The chain-root whole is not tried then, because it is the same DXIL under another root and would fail the same way. The non-mandatory--pipelinespath (make_selected) is unchanged.What is in it
crates/xcl/src/shaders.rs:prepare_compiled_computebuilds the whole first;chain_neededmakes the decision;whole_blob_pathgives the blob path the runtime loads;a_split_programs_chain_is_prepared_only_without_its_whole(the decision);startup_preparation_builds_a_split_programs_whole_and_no_chain(GPU). With the whole kept, preparation writes exactly the whole.pso, for direct and indirect prewarm alike. With the whole over the cap, it writes exactly the pieces'.chain.pso.crates/xcl/tests/gpu_compute_e2e.rs:a_preparation_worker_also_builds_a_split_programs_whole_form(#2794) asserted the old behaviour, the worker's piece blobs besides the whole. It is replaced by @andrewDoing'sa_preparation_worker_keeps_a_split_programs_abi_whole, which:.pso;CachedWhole) is tested from a prepared blob.README.md: one sentence on what startup preparation builds for split programs.Tested
NVIDIA GeForce RTX 2070 SUPER 8 GB (driver 621.40), AMD Ryzen 5 3600XT, Windows 11 Home build 26300, rustc 1.100.1, debug.
cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4on30122062(debug): 2739 passed, 0 failed, 49 ignored (41 test binaries).SKIPPEDon this adapter (28), the same kinds as on the earlier head: no wave64 (most of them), f16/f32 per-lane forms refused, no heap windows (opt-inXCL_HEAP_WINDOWS=1), no GPU_UPLOAD heaps.cargo test -p xcl --test gpu_compute_e2e -- --test-threads=1on30122062: 9 passed, 0 failed, 0 ignored; 1 SKIPPED (heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows). @andrewDoing'sa_preparation_worker_keeps_a_split_programs_abi_wholepassed.cargo test -p xcl --lib shaders::pipeline_cap_tests:: -- --test-threads=1: 7 passed, 0 failed, 0 ignored, no SKIPPED.The new GPU test fails without the fix (main's
prepare_compiled_computebody put back). It finds the whole.pso, two piece.chain.psofiles and the chain-root whole.chain.pso, where it expects only the whole.pso.Cold mandatory preparation (
xcl shaders <pack> --precompile --only cs --pipelines --records <6 records>withXCL_PRECOMPILE_PARENTset, the pathxcl run's preparation workers take) of 6 records of a retail game, each side into a new, emptyXCL_DXIL_CACHE, release builds. Records: 5 split programs (each a ~1.39 MB whole and 18 pieces) and 1 unsplit program as a control.0fe06eb0.pso, 95.chain.psof1574257.pso, 0.chain.psoOn main, each split program got the whole, 18 pieces and the whole again (5 × 19 = 95
.chain.pso). Here each record gets one.pso. The wall times are not cold times: the NVIDIA driver's own shader cache was on and already held these programs from an earlier full preparation (6 wholes in 60 s is well under 6 × ~34 s cold). The claim rests on the counts (101 → 6 driver builds, 33.1 → 11.2 MB of blobs) and on the cold cost of an avoided whole below.What one avoided chain-root whole costs, measured on main with the driver's shader caches turned off (
xcl shaders --measure-pso 2e1d03fbed9d95eb --repeat 1,ShaderCacheControl, one compile at a time): 33.9 s for a 1,387,508-byte whole. Under 12-way preparation, the pieces plus the chain-root whole finished a median of 428 s after the ABI whole, for programs of ≥ 1 MiB.Regression run
main (
0fe06eb0):this PR's head (
30122062):Both:
scripts/smoke.ps1 -Seconds 60,XCL_PREPARE=0,XCL_PRESS_AT=25:A, release builds, run through the local exclusive queue. With preparation off, these runs check that nothing else breaks; they do not run the changed preparation path.Note: #3219 (test-only) asserts the old set of files that preparation writes. Whichever of the two merges second needs its test updated.
Not tested
XCL_PREPARE=0), and a warmxcl runafter a full preparation, which would showcompute split: 0 programs splitfor the prepared records. A full preparation takes hours here.AI use
shaders.rs, and this description. The investigation that found the double build was Claude Code, Claude Opus 5.5 as well.a_preparation_worker_keeps_a_split_programs_abi_whole: written by @andrewDoing with OpenAI Codex (GPT-6.2 Sol). Taken in unchanged and co-authored in the commit.🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T17:36:54Z.
Test results wanted. This PR should cut the driver work of a cold shader preparation. Each split compute program now gets one driver compile, not 2 + its pieces. I can only measure it on one NVIDIA card here, and the NVIDIA driver's own shader cache makes a "cold" run less cold than it looks. Runs on other GPUs, especially AMD and Intel, would help most.
What to run (on your own game dump; the same title, settings and machine for both sides):
mainand this PR's head (cargo build --release -p xcl), and note both commits.XCL_DXIL_CACHEfolder, so preparation is cold for XCL. Use a new folder per side; there is no need to delete your existing cache: Let preparation finish, then play a minute or so.What to report for each side:
xcl.logof the cold run: theShader preparation: compute pipelines done in N sline;<XCL_DXIL_CACHE>\driverby kind:*.psothat are not*chain.pso,*.chain.pso,*.indirect-chain.pso. This counts them in PowerShell:xcl.logof the warm run: the lastcompute split: N programs split, ...line, if there is one;Expected: the PR's side writes fewer
.chain.psofiles and finishes preparation sooner, and the warm runs look the same on both sides. A cold preparation can take a long time; if you stop one early, say when.Please post one comment and edit it if you rerun (see CONTRIBUTING, "Reviews and test reports").
Written with Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T17:47:54Z.
The stock integration test
a_preparation_worker_also_builds_a_split_programs_whole_formfails onf1574257because it still requires chain files. The worker succeeded and left one ABI.pso, with one fresh GPU pipeline creation and zero refusals. The exact-key assertions in #3219 also fail when applied on top, since they expect the old startup artifact set.I put a one-file test update on our fork. It checks the exact single ABI
.psofrom a genuinely split DXIL program, runs the startup worker again with zero fresh GPU pipeline creations, then opens the cache in another runtime process. The runtime selects the ABI root and dispatches correctly, including all 32 expected output lanes and the untouched guard values. The worker uses the runtime’s memory-window count. An earlier one-window probe could not hit the four-window runtime key. Integration-test commitOn RTX 5070 (616.92), Ryzen 7 5700X3D, Windows 11 26300.10075, Rust 1.100.0 MSVC and DXC 1.8.2502.11, the complete
gpu_compute_e2etarget reported 9 passed, zero failed, and one explicit skip for opt-in heap windows. The three focused worker and offline-cache tests passed with zero skips. The revised worker test failed as intended on main0fe06eb0, where the same synthetic fixture made and saved seven fresh pipelines. The run covers native GPU cache behavior on this fixture. Retail preparation time and gameplay remain unmeasured.Codex with GPT-6.2 Sol implemented the integration test update and ran the checks.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T20:55:05Z.
Thanks @andrewDoing, that's a better test than mine.
f1574257was fixed in178241b7, which only changed that test's counts to expect the whole and no pieces. On178241b7(RTX 2070 SUPER, driver 621.40):cargo test --workspace --no-fail-fast -- --test-threads=4gave 2739 passed, 0 failed, 49 ignored, with 28 SKIPPED (22 no wave64).a_preparation_worker_keeps_a_split_programs_abi_wholereplaces it, unchanged, at30122062. It's squashed into the PR's one commit with you as co-author, and the description credits your Codex (GPT-6.2 Sol) use. The runtime dispatch from the prepared blob is the evidence this PR was missing for "steady state unchanged".gpu_compute_e2etarget, the whole suite and the smoke run on30122062are queued here. I'll update the description with those counts when they're done.AI use: Claude Code (Claude Opus 5.5) drafted this reply.
Imported from ivall/xcl. Originally posted by dudenudem on 2026-11-29T21:25:57Z.
Test report: split-program preparation A/B on Linux/Wine + vkd3d-proton (AMD) — extra data point, not a merge check
Setup. Our tree is a Linux/Wine stack (main
0fe06eb0+ your cache work1bd9cee1+ a port of #3455), so the driver is vkd3d-proton 3.1.0 on RADV, not amdxc64. A = our maine9e608fc(pre-port); B =ff221653, the clean cherry-pick of178241b7(author preserved) plus one test of ours. AMD Radeon RX 7900 XTX (RADV NAVI31, Mesa 26.3.1), Vulkan 1.4.363, Wine GE-Proton11-14, rustc 1.96.1, DXC 1.9.0.1. Six records (5 split + 1 unsplit control),XCL_SPLIT_WAVE64=1, one pipeline thread, WARP, a freshXCL_DXIL_CACHEand a fresh vkd3d pipeline cache per side,--precompile --only cs --pipelines --records..pso.chain.pso.indirect-chain.psoe9e608fcff221653B matches your claim: one ABI
.psoper record when the whole fits, no chain-root whole, no pieces. A is cut short by the driver: on this stack, building the split-protocol piece DXIL faults vkd3d-proton at0x110, so its 5 partial.chain.psoare not the full set it would write on a working driver. That also means B avoids a driver crash A hits here — a side effect worth knowing, though it says nothing about Windows drivers.What we could not complete on this driver: the over-cap branch (pieces instead of the whole; the decision test covers the policy), and the runtime fallback execution. Your "not tested" item — a runtime that rejects the whole blob — we took seriously: we extended
recorded_split_selects_cached_whole_or_pieces(hle/d3d12x/real.rs) so a miss/stale selection runs the registered chain plan and asserts its memory result equals the whole program's. It compiles and is skipped with a reason unlessXCL_SAMPLE_RUNTIME_COMPUTEis set; running it needs a driver where the split-protocol piece DXIL builds. Simple DXC pieces with the chain root signature do build on WARP (split_compute_program_prebuilds_and_caches_chain_pieces), so the failure is specific to that piece DXIL, not the root signature.How our tree differs from main (mostly orthogonal to this PR): it is the curated Linux stack with a ported HLE layer; translator deltas (watertight BVH, a barrier proof that lowers proven-uniform CS barriers, CLAMP/OMOD/DX9 multiply, #3455 cherry-picked as
9791e7db); a bounded preparation with persisted refusal hashes and HLSL routing for records that fault the driver; and your cache architecture (#3445-#3450) merged, so both sides share the receipt-v2 identity model. Preparation completion differences on this machine should be read against that, not against this PR.Not tested here: the Windows suite (per the queue's rule a Wine run is an extra data point, not a merge check), NVIDIA/Intel, a full retail preparation, and the GPU over-cap path.
AI use: omp harness with nanogpt/deepseek/deepseek-v4.1-flash-1017; subagents ran the builds and the A/B on the machine above. No game data is included.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T21:42:52Z.
Test report: full startup shader preparation, cold cache, with #3442 + the #3263 stack + the #3269 stack together
One run of a build that combines these three PRs. It shows what they do together; it does not say how much each one contributes.
Build:
a96b183c, local merge of 4465c886 (main3b6a91ed+ #3318 #3321 #3323 #3325 #3328 #3330 #3332 #3336 #3364 #3377 + #3241 + #3242) with:4511c6e5;e13ccd7f, #326116f2f5c1, #3263e618b742);a343eafc, #3268527a8b26, #32694a8217a7).cargo build --release -p xcl. Also set:XCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=1(stands in for #2428, which does not merge onto this set).This PR in the build:
4511c6e5(cherry-picked; the head is now30122062, which differs).Run: retail game,
XCL_PREPARE_ALL=1(all 26,503 records),XCL_RUN_SECONDS=180(ends 180 s after the title starts),XCL_ACTIVITY=1. Cold XCL cache:XCL_DXIL_CACHEpointed at a new, empty folder, so no translation, DXC output or driver blob was reused.Compared with: the same retail game and settings on 4465c886 alone (the base above, without the three PRs and without the heap switches), run earlier today with a warm cache: it started with 48,305 translations, 44,556 DXIL files and 13,051 driver blobs, and reused about half of its driver blobs.
Graph. Progress of every full preparation run on this PC. This build is the solid blue line, the base the dashed pink one; in the lower panel blue reaches 100 % at ~1.4 h, pink at ~3.4 h. Data and script: CSVs +
plot.py.Not tested / limits
30122062) and #3269 (nowe01151a2, with #3268 now64f666c0) have changed since, so this report is for the commits listed above.Hardware: NVIDIA GeForce RTX 2070 SUPER 8 GB (driver 621.40), AMD Ryzen 5 3600XT, 32 GB, Windows 11 Home build 26300, rustc 1.100.1.
Tool and model: Claude Code (Claude Opus 5.5): two sessions on this machine ran the queued runs; this one extracted the numbers from their logs and wrote this report.
Imported from ivall/xcl. Originally posted by johnbf8x on 2026-11-29T22:23:46Z.
merge-check
base:
1bd9cee1e5head:
301220626amerge: clean (git merge --no-commit --no-ff onto origin/main in a detached worktree; the merged tree was tested uncommitted)
build: cargo build --workspace -> ok; cargo build --release -p xcl -> ok (the PR merged and main alike)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 (XCL_DXC_DIR = DXC 1.9.2609) -> main and PR the same: 137 passed, 2 failed, 20 ignored outside the lib; the lib binary ends abnormally on both (0x80004005, "sparse upload preparation still failed after bounded retries – the title is stopped before its GPU submission"), so no lib total. The lib in parts on both: hle::d3d12x::list_x alone on 1 thread 113 passed, 0 failed; the rest on 4 threads ends at the same place after 1696 ok on main and PR alike. The PR's own tests run directly: cargo test -p xcl --lib shaders::pipeline_cap_tests:: -- --test-threads=1 -> 7 passed, 0 failed, 0 ignored; cargo test -p xcl --test gpu_compute_e2e a_preparation_worker_keeps_a_split_programs_abi_whole -- --exact -> 1 passed. SKIPPED: 28 on both (22 no wave64, 3 f16/f32 per-lane forms refused, 2 no heap windows, 1 no D3D12 debug layer); failing: e2e test_title_draws_with_a_root_signature_under_the_debug_layer and test_title_runs_under_the_debug_layer_with_dred (no D3D12 debug layer on this PC), and the lib abort; all fail on base too
review: none blocking, after reading the whole diff (shaders.rs, gpu_compute_e2e.rs, README.md). chain_needed() is only consulted on the mandatory path (prepare_compiled_compute); make_selected (--pipelines without a parent) is unchanged. A whole that was refused or over XCL_PIPELINE_MAX_KB still gets its pieces, as before, and the chain-root whole is no longer retried in that case. Not covered here: an indirect dispatch (ExecuteIndirect) of a split program from a prepared whole blob in a title (the new e2e test dispatches it directly), AMD/wave64, a full cold startup preparation
performance: mandatory preparation (xcl shaders shaders.rpf --precompile --only cs --pipelines --records, XCL_PRECOMPILE_PARENT set, a new empty XCL_DXIL_CACHE per run) of the 31 programs that 33 of 60 pipeline keys from earlier runs matched: main 130 driver builds (31 .pso + 99 .chain.pso, 33.8 MB) in 3 runs; PR 31 builds (31 .pso, 0 .chain.pso, 12.1 MB) in 2 runs; 0 refused, 0 failed writes on both. Times (not cold: the NVIDIA driver's shader cache warmed run by run): main 130.8, 103.3, 71.3 s; PR 51.3, 17.3 s, each below the main run before it. Smoke (60 s, XCL_PREPARE=0, so the changed path does not run): PR 937 frames against main 809 (116 %), peak commit 15410 against 14713 MB (105 %), 0 device removals and 0 crashes on both
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 3070 Ti 8 GB (driver 621.40), Intel Core i7-12700K, Windows 10 Pro 19045, rustc 1.100.0 / Claude Code, Claude Opus 5.5
Regression run
Both from scripts/smoke.ps1 -Seconds 60, each from its own copy of one warm DXIL cache and its own data root, with
XCL_LAZY_PSO=1, XCL_LAZY_COMPUTE=1, XCL_HEAP_WINDOWS=1 and XCL_PRESS_AT=25:A. The PR's block names main's commit with
"(uncommitted changes)": it is the PR test-merged onto main, not the PR's head commit, so it cannot stand in for the
author's own block.
main (
1bd9cee1):PR #3442 merged onto
1bd9cee1:Found on the way (not this PR)
scripts/smoke.ps1on main: it setsXCL_NETWORK,XCL_RUN_SECONDSandXCL_ACTIVITY(lines 60-62) after$psi.EnvironmentVariables['XCL_PREPARE'](line 57). That first read copies the environment into theProcessStartInfo, so XCL gets none of the three. Here the title never ended itself (one run went 928 s until its
window was closed) and logged no
activity (2 s)lines. The two runs above set the three variables before callingsmoke.ps1. Seen on Windows PowerShell 5.1.
stop_for_unresolved_wait, "the title is stopped") on main1bd9cee1on thisPC, so
cargo test --workspacegives no lib total here.Imported from ivall/xcl. Originally posted by PrMeiliv on 2026-11-29T23:16:31Z.
Test report: cold mandatory compute preparation, used-only set of a retail game, A/B on the same main (not a merge-check)
Setup
0fe06eb0+ #2590 (xcl nvprofileCLI command only, unrelated to this path)148031ea. Its code is identical to the current head30122062(git diff 148031ea 30122062is empty; only the commit message changed)Command, per side, the path
xcl run's preparation workers take:xcl shaders <game>\shaders.rpf --precompile --only cs --pipelines --used-onlyXCL_PRECOMPILE_PARENTset,XCL_DEVICE_TYPE=anaconda,XCL_PIPELINE_THREADS=8(the log says8 driver compiles at once)XCL_DXIL_CACHEholding only the same copiedused-*lists (selection: 1277 of 2496 keys matched shader-package records,281 split programs earlier runs dispatched indirectly get direct and indirect pieces/whole, 1149 shaders compiled, 0 already cached)%LOCALAPPDATA%\NVIDIA\DXCachewas emptied before each side (A: 17 files in use could not be deleted; B: not checked)Results
0fe06eb0*.chain.pso*.chain.psoMy script counted
*.chain.psoonly; the remaining 5051 blobs on A are the wholes plus*.indirect-chain.pso, which I did not count separately (the folders were deleted after counting).The gain is larger on current main than on an older base. A first run against main
7a649b0e(before the merges up to0fe06eb0, which add the indirect pieces and wholes to this path) gave 2296 s and 5581 blobs (4446*.chain.pso) for the base, against B's 988 s (−57 %). That pair differs by more than this PR, so the table above is the clean comparison.Not tested
xcl runitself (theShader preparation: compute pipelines done in N sline) and the warm run'scompute split:line. I ran the worker command on its own.AI use: Claude Code (Claude Opus 5.5) wrote the A/B scripts, read the logs and wrote this report. The runs were done on the PC above. Posted at the user's request.
Imported from ivall/xcl. Originally posted by ArtuArtaza on 2026-11-29T23:20:01Z.
Test report: cold mandatory compute preparation A/B on AMD (RX 6700 XT, RDNA2, Windows), a 40-record sample of a retail game (not a merge-check)
Short version: no change at default settings, about half the compute driver time with
XCL_PSO_DISK_CACHE=1. This is the preparation workers' path on a sample, not the fullxcl runprotocol of the "Test results wanted" comment.Setup
0fe06eb0, B =30122062(this PR's head). On current main: A =b38197ae, B =b38197aewith this PR's commit cherry-picked (no conflicts).xcl shaders shaders.rpf --precompile --only cs --pipelines --records <file>withXCL_PRECOMPILE_PARENT,XCL_PIPELINE_THREADS=1,XCL_DXC_THREADS=2,XCL_DEVICE_TYPE=lockhart. One process, one driver compile at a time.XCL_DXIL_CACHEfor every run, and every run used its own copy of the exe under another file name, because AMD's driver shader cache (%LOCALAPPDATA%\AMD\DxcCache) is per exe name. Each of the eight runs below is confirmed cold by the new cache files the driver created for it. (One attempt is not in the table: AMD's key does not tell apart names of the same length that differ only near the end, so two renamed exes reused older caches and finished in seconds. The run tag is now at the start of the name.)Result (one run each)
0fe06eb0persistence disabled 188)0fe06eb0persistence disabled 188)0fe06eb0XCL_PSO_DISK_CACHE=1.pso, 148.chain.pso0fe06eb0XCL_PSO_DISK_CACHE=1.psob38197aepersistence disabled 188)b38197aepersistence disabled 188)b38197aeXCL_PSO_DISK_CACHE=1.pso, 148.chain.psob38197aeXCL_PSO_DISK_CACHE=1.psodriver_cache::enabled), sowhole_blob_pathgivesNone,on_diskis false andchain_neededis always true.XCL_PSO_DISK_CACHE=1it does what the description says: 40 pipelines instead of 188 (−79 %), and 52 % less time on both bases (424 s against 889 s, 500 s against 1040 s).driver_cache::note_vendorsays. A second process with the same exe name took all 40 of B's blobs from disk (pipelines loaded from the driver cache 40, no fresh creation) once the verified list was set aside, so the driver does accept them across processes.Not tested
CachedWholetakes these blobs in a game on AMD.A question from reading the code (not measured): at default settings on AMD the runtime has no blob on disk, so
CachedWholemisses and the runtime builds the chain. If that is right, on AMD the pieces are the part of preparation the runtime uses and the two whole builds are the part it does not. Would it make sense for preparation to follow the same rule there, or to say in the README that the PR needsXCL_PSO_DISK_CACHE=1on AMD?AI use: Claude Code (Claude Fable 5.2) built both sides, ran the measurement, wrote this report and posted it from my account at my request.