Skip to content

D3D12.X: pipelines an earlier run used are built ahead of their first use - #690

Merged
theaustinayers merged 1 commit into
xcl-dev:mainfrom
theaustinayers:pso-preload
Nov 24, 2026
Merged

theaustinayers merged 1 commit into
xcl-dev:mainfrom
theaustinayers:pso-preload

Conversation

@theaustinayers

Copy link
Copy Markdown
Collaborator

A lazy pipeline (#162) is built at its first use: until then a graphics one draws nothing and a compute one is waited for on the title's thread. A retail title's first frames of its world use hundreds of pipelines for the first time at once. This keeps which pipelines a title used and builds those ahead of their first use in the next run, while the title loads.

I searched the open PRs first: #628 orders the worker pool's queue, #533 / #267 bound the waits, #214 / #567 the compile concurrency; none builds a pipeline before its first use. This works with any of them.

What is in it

  • crates/xcl/src/hle/d3d12x/pso_async.rs: mod used – the shader-set keys of pipelines a run used, appended to used-pipelines.txt beside the DXIL cache and read at the start of the next run; preload – two to four workers at the lowest thread priority, apart from the ones a bind sends to, that build a lazy pipeline as soon as it is made when an earlier run used one of its shaders (whoever takes the job first builds it, so a bind is never held up by them). submit_lazy takes the key; resolve / resolve_wait note the first use. XCL_PSO_PRELOAD=0 turns it off. Pipelines no run used stay lazy as before.
  • crates/xcl/src/hle/d3d12x/real.rs: shaders_key (a hash of the pipeline's shader blobs in their order), passed from go_background.
  • crates/xcl/src/hle/d3d12x/bind.rs: the three submit_lazy calls of an existing test get the new argument.
  • Tests: the_keys_of_a_file_are_read_and_other_lines_passed_over, a_pipeline_an_earlier_run_used_is_built_ahead_of_its_first_use (built with no bind when an earlier run used it, still pending when none did, and a first use is kept), a_key_follows_the_shaders_and_their_order_and_is_never_zero.

Tested

  • RTX 5090 (driver 621.14), Ryzen 9 9950X3D, 128 GB, Windows 11 build 26300, rustc 1.100.0.
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4 on 2e36ce0: 695 passed, 0 failed, 41 ignored. The head commit 7296a8b differs from it in a doc comment and the commit message only; on it I reran cargo test --release -p xcl --lib -- used_tests shaders_key_tests: 3 passed.
  • SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • A retail title, release build, with a used-pipelines.txt of 1197 shader sets from earlier runs: 512 pipelines were built ahead within 5.2 s of the start (the log line is printed at powers of two), in the smoke run below and in a 200 s run into the title's world.
  • What it buys depends on what happens to a pipeline that is not ready. On main a compute pipeline is waited for, and the title's world still ends at its watchdog with this PR as without it (102 s without, 106 s with: no difference I can claim). On a build of mine that skips a dispatch instead of waiting (bounded waits, as D3D12.X: bound compute pipeline waits so slow compiles do not trip wa… #533 does), the title's first world frames skipped ~2 170 dispatches without this and 94 – 150 with it, in runs on this machine.

Regression run

Both runs had the same scripted input (XCL_PRESS_AT, A at 20 s and so on), so they leave the title's first menu and go on into its loading, where its pipelines are made.

main:
```
xcl-smoke v1
commit: 91f9a5e
gpu: NVIDIA GeForce RTX 5090
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1311 (PresentX 1311)
presents per 2 s (last 3): 2 2 0
device removals: 0
crashes: 0
peak commit: 22607 MB


this PR:
```
xcl-smoke v1
commit: 7296a8bd42a2e96c22c1a7dbb1f39b252cf4e589
gpu: NVIDIA GeForce RTX 5090
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1339 (PresentX 1339)
presents per 2 s (last 3): 3 10 0
device removals: 0
crashes: 0
peak commit: 23008 MB

Not tested

  • A first run with no used-pipelines.txt: nothing is built ahead then (covered by the unit test's pipeline that no run used, not by a title run with the file removed).
  • The memory of the pipelines built ahead over a long session: the file only grows (1197 keys after ~20 runs to the start of the title's world); the smoke runs show 23.0 GB peak commit against 22.6 GB on main.
  • AMD and Intel GPUs; other titles.

AI use

  • Claude Code, Claude Fable 5.2: wrote the change, the tests and this description, and ran the builds, tests and runs above on the hardware named.

… use

A lazy pipeline is built at its first use: until then a graphics one
draws nothing and a compute one is waited for on the title's thread. A
retail title's first frames of its world use hundreds of pipelines for
the first time at once.

The pipelines a title uses are now kept by a hash of their shaders
(used-pipelines.txt beside the DXIL cache), and a lazy pipeline of
shaders an earlier run used is sent to workers of its own when it is
made: two to four threads at the lowest priority, apart from the ones a
bind sends to, so a pipeline that is bound is not held up by the ones
made ahead. XCL_PSO_PRELOAD=0 turns it off. Pipelines no run used stay
lazy, as before (the memory of ~51 000 built pipelines was the reason
for making them lazy).

Measured on an RTX 5090 with a build that skips a dispatch instead of
waiting for its pipeline: ~2 170 dispatches skipped in the title's first
world frames without this, 94 - 150 with it.

Assisted-by: Claude Code (Claude Fable 5.2)
@thehollowedone

Copy link
Copy Markdown

Tested

On 7296a8b, I checked the real D3D12 pipeline hook in three fresh processes using an isolated synthetic cache. A scratch extension to gpu_compute_e2e observed the stand-in and translated-pipeline count before the first call to resolve_wait.

  • Cold cache: the pipeline stayed pending before first use. First use built it and wrote one key to used-pipelines.txt.
  • Second process: the preload worker built the pipeline before first use. The translated-pipeline count increased by one and XCL logged the completed ahead-of-use build.
  • XCL_PSO_PRELOAD=0: with the same saved key, the pipeline stayed pending before first use and no ahead-of-use build completed. The startup line still said the recorded shader sets are built ahead. The stand-in state and completion log distinguished the disabled behavior.

Each dispatch matched all 1,536 readback words. The focused test passed 1/1 in each process with the D3D12 debug layer enabled and no errors or runtime skips. Runtime code was stock.

Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, DXC 1.8.2502.11, Rust 1.99.1 MSVC, debug. cargo test --offline --locked -p xcl --test gpu_compute_e2e console_wave64_compute_through_the_pso_hook_dispatch_and_read_back -- --exact --nocapture --test-threads=1.

Not tested

Graphics pipeline preload, contention with a large history, and retail loading.

AI use

Codex with GPT-6.2 Sol adapted the scratch fixture, ran the tests, and drafted the report.

@theaustinayers
theaustinayers merged commit a8db4b0 into xcl-dev:main Nov 24, 2026
2 checks passed
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 7296a8bd42a2e96c22c1a7dbb1f39b252cf4e589 on AMD RDNA4. I merged it onto current main 91f9a5e locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 695 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 655 passed, 0 failed, 21 ignored
  • 0 SKIPPED; a_pipeline_an_earlier_run_used_is_built_ahead_of_its_first_use passes.

Review: The set written this run starts as the file's set, so only keys that are new append a line: used-pipelines.txt grows by distinct shader sets, not by every run. Under cfg(test) the file is neither read nor written. A small thing: keys are never removed, so after a title update its stale keys stay in the file (they only cost a lookup, since a key with no lazy pipeline builds nothing). I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@crosettiremi

crosettiremi commented Nov 24, 2026 •

Copy link
Copy Markdown

Independent Windows 11 / RX 7900 XT result on retail 1.0.2.1, with DXC 1.9.2602.17. I tested the preload change at 7296a8b on a local combined build with bounded graphics and compute waits, first-use tracking on those paths, and a sparse-buffer release fix. The prior-use file started with 180 shader sets. I had seeded 177 from earlier traces before the preceding run.

The log recorded 128 pipelines built ahead of first use by 6.643 s. The account picker held 60 presents per two seconds and accepted A at 37.004 s. The game displayed the loading artwork and began streaming. It later hit the known world-loading watchdog at 154.691 s (0xc0000005 at title+0x23cf683), with no device removal. The submission thread logged 14 two-second Wait64BitValueX timeouts. Peak process commit was 40,842 MB.

This verifies preloading on AMD. The build and warmed cache do not isolate its effect on frame rate or time to the watchdog. The combined workspace passed 722 tests with 41 ignored.

Upstream change tested: 7296a8b. Workspace command: cargo test --workspace --locked --offline -- --test-threads=4. Codex (GPT-6) ran the checks and summarized the local logs.

burber added a commit to burber/xcl that referenced this pull request Nov 24, 2026
…uns, sparse and write-watch fixes)

Conflict in pso_async.rs: xcl-dev#690's key / used fields and xcl-dev#533's timed_out kept side by side;
the bounded waits (resolve_within, resolve_compute_within) record a pipeline's use too, so
xcl-dev#690 builds those ahead next run; the older tests pass the new key argument (0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
JustDownTV added a commit to JustDownTV/xcl that referenced this pull request Nov 24, 2026
upstream xcl-dev#690 added a key argument to submit_lazy (pipelines an earlier run
used are built ahead); the wait-budget and compute-pool tests carried on
perso pass 0, no key.
@crosettiremi

Copy link
Copy Markdown

Follow-up to my earlier AMD test. I repeated a Series S-profile run on the RX 7900 XT with the exact same release executable, saved profile and A press at 37 s. The second launch used the complete application caches written by the first. Both builds had #690 enabled, so this measures repeat-launch behavior on the integration stack.

The 512th pipeline finished preloading at 9.883 s on the repeat, compared with 16.952 s on the first run. The repeat accepted driver blobs on 282 successful compute pipeline creations. It still encountered 21 successful cold creations and two cold creations that returned E_OUTOFMEMORY.

The two failed compute compilations were serialized. ScreenProbes ActivateProbes (22,909,544 bytes of DXIL) took 91.119 s and ActivateRays (13,015,316 bytes) took 54.018 s. Both were started by a preload worker. Peak process commit was 68,701 MB. The repeat recorded 2,215 presents and zero device removals before a title access violation in world loading at 174.409 s. The trace establishes driver memory pressure; it does not establish the cause of the title exception.

The local integration workspace reported 737 passed, 0 failed and 41 ignored. One counted pass printed a skip for the missing xgameruntime.dll debug-layer fixture. The same binary was used for both game runs. Codex (GPT-6) ran the tests and prepared this report.

JustDownTV added a commit to JustDownTV/xcl that referenced this pull request Nov 24, 2026
A lazy compute pipeline was built at its first bind, on the binding thread
(waited for: a skipped dispatch leaves output the title reads). With the
retail game's stall watchdog parked, an RTX 5070 Ti run went past its first
cinematic's start and then stood still for over three minutes: twelve new
compute pipelines bound one after another, each built on that thread in
turn by the NVIDIA driver in 6 - 38 s.

Compute pipelines now go to the workers that build ahead (xcl-dev#690's preload,
lowest priority) as soon as the title makes them, so they are built in
parallel before most first binds; a bind that finds one not started still
builds it itself. Those workers are compile_threads / 2 (2 - 6) while this
is on. XCL_EAGER_COMPUTE=0: built at first use, as before. Off in tests,
which decide which thread builds what.
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 24, 2026
…l#490, ivall#347)

The fork keeps its own pso_async (short waits, all compute pipelines built ahead); ivall#690 upstream is its used-pipelines part.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 24, 2026
The page opened with the title and a paragraph; what a reader looks for
first (which games, how to build, where to ask) was a scroll away, and
the environment switches a user needs were spread over the text or only
in HANDOFF.md.

- a centred header: tagline, badges (Discord, CI, licence, platform),
  and links to the page's sections
- how XCL works as three rows (native code, console libraries, shaders)
- "Switches for a run": the eight variables a user is most likely to
  set, each checked against the code on main
- the Pipelines row names what main has since ivall#634 / ivall#636 / ivall#690

No statement about what works was changed. The test count (ivall#485) and a
Contributing section (ivall#453) are left to their open pull requests.

Assisted-by: Claude Code (Claude Fable 5.2)
@WarmMilkCodes

Copy link
Copy Markdown
Contributor

Title: Pipeline preload (#690): committed memory climbs ~1.4 GB/s on AMD RDNA2 until Windows runs out (retail title from #505)

Hardware: AMD Radeon RX 6600 XT (8 GB, RDNA2), Ryzen 5 5500, 32 GB RAM, page file on a second drive (commit limit 130 GB), Windows 11, DXC 1.8.2502.11.

Build: a local test branch: main with #690 and #713, plus #533 and two local changes that bound pipeline waits (no changes to pso_async's preload code). #762 was in some of the runs; #688 in one (taken out after). The leak follows XCL_PSO_PRELOAD in every run, with or without those.

What happens

Once used-pipelines.txt holds a few hundred entries, a run logs 512 pipelines built ahead of their first use about 11 s in. From then on, the process's committed memory grows at about 1.4 GB/s until the commit limit is reached. Committed memory, sampled every 2 s with \Memory\Committed Bytes:

Time Committed Free RAM
23:12:54 57.4 GB 0.1 GB
23:13:29 100.0 GB 0.2 GB
23:14:31 127.7 GB 0.2 GB
23:15:06 131.2 GB 0.8 GB

The title sat at its account picker the whole time. XCL's log is nearly silent after ~100 s, with no pipeline builds or uploads logged while memory climbs. The desktop stopped drawing (blank icon boxes, error dialogs) until a reboot. Two other runs with the same list ended at ~130 s with memory allocation of 4920320 bytes failed and exit 0xc0000409, with no crash dump.

With XCL_PSO_PRELOAD=0, the same build:

  • At the same account picker for ~3 min: committed memory flat at 25.0–25.1 GB.
  • A full run: 25 GB → 35 GB over 8 min of world streaming, reaching 578 s and 14 700 frames. No leak; the run ended on an unrelated title crash.

When it started: an earlier run with a short list (32 pipelines built ahead) had no leak (294 s, past the world loading screen). The leak appeared once the list reached 512+ (605 shader sets at the last run).

Not checked yet:

  • Whether the memory is held in the driver (pipelines built ahead and kept) or in XCL.
  • Whether a smaller preload list, or one preload thread, still leaks.
  • NVIDIA, or a fresh used-pipelines.txt.

JustDownTV added a commit to JustDownTV/xcl that referenced this pull request Nov 24, 2026
upstream xcl-dev#690 added a key argument to submit_lazy (pipelines an earlier run
used are built ahead); the wait-budget and compute-pool tests carried on
perso pass 0, no key.

(cherry picked from commit a3536a8)
JustDownTV added a commit to JustDownTV/xcl that referenced this pull request Nov 24, 2026
A lazy compute pipeline was built at its first bind, on the binding thread
(waited for: a skipped dispatch leaves output the title reads). With the
retail game's stall watchdog parked, an RTX 5070 Ti run went past its first
cinematic's start and then stood still for over three minutes: twelve new
compute pipelines bound one after another, each built on that thread in
turn by the NVIDIA driver in 6 - 38 s.

Compute pipelines now go to the workers that build ahead (ivall#690's preload,
lowest priority) as soon as the title makes them, so they are built in
parallel before most first binds; a bind that finds one not started still
builds it itself. Those workers are compile_threads / 2 (2 - 6) while this
is on. XCL_EAGER_COMPUTE=0: built at first use, as before. Off in tests,
which decide which thread builds what.

(cherry picked from commit f06d4f6)
isaacwingate added a commit to isaacwingate/xcl that referenced this pull request Nov 24, 2026
A lazy compute pipeline was built at its first bind, on the title's
thread: the bind has to wait for it (a skipped dispatch corrupts what it
computes), and the driver takes seconds for a big one. Preloading (xcl-dev#690)
covered only the shaders an earlier run used, so every compute pipeline
new to a run was still compiled in the middle of a frame.

Every compute pipeline now goes to the preload workers when the title
makes it, after the ones of an earlier run (a second, lower line of the
same queue). Graphics pipelines stay lazy: a retail title makes ~58 000
pipelines and only 2 734 of them have a compute shader, so building
these costs little. A bind that comes first still builds or waits as
before, and each build is kept on disk for later runs (driver_cache).

Measured on the retail title of xcl-dev#505 (RTX 5080, driver 32.0.16.2124,
XCL_NETWORK=0, 240 s), counting resolve_wait calls that found their
pipeline not built: without this, 16 compute binds built theirs on a
title thread, 3 - 23 s each and 92.7 s in all, on five threads within
10 s, and the title's hang watchdog ended the run at 125 s. With it, one
bind waited 2 ms; the run went on until XboxBvhBuilder refused an
acceleration structure above 2^40 (xcl-dev#585) at 137 s.

Part of xcl-dev#505.

XCL_PRELOAD_COMPUTE=0 turns off this build-ahead alone: the driver keeps
each compute pipeline built (an AMD GPU under Wine measured 7 - 10 GB more
host memory), and XCL_PSO_PRELOAD=0 would also turn off xcl-dev#690's preload
of the pipelines an earlier run used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CalvyPZ pushed a commit to CalvyPZ/xcl that referenced this pull request Nov 24, 2026
XCL_PSO_PRELOAD=graphics keeps remembered graphics pipelines eligible for
preloading while compute pipelines retain their ordinary first-bind build
and wait. Unset, 1, 0 and unrecognized values retain their existing behavior.
The existing queues, workers and exact-once job ownership are unchanged.

Extend xcl-dev#690 with an opt-in admission policy, not a default or dispatch change.
The CPU scheduling regression runs five policy values in fresh processes and
checks actual remembered graphics/compute submission and real-value selection.

Assisted-by: OpenAI Codex (GPT-6; exact model variant unavailable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants