Skip to content

D3D12.X: build console pipelines at their first use (GTA VI: 45+ GB → 17 GB) - #162

Closed
Sr-0w wants to merge 4 commits into
ivall:mainfrom
Sr-0w:lazy-pso
Closed

Sr-0w wants to merge 4 commits into
ivall:mainfrom
Sr-0w:lazy-pso

Conversation

@Sr-0w

@Sr-0w Sr-0w commented Nov 23, 2026

Copy link
Copy Markdown

Problem

The retail GTA VI (GDK) creates ~51 000 distinct pipelines in its first 30 s (measured: a translation-keyed cache found only 33 duplicates). Built at creation, each stays in AMD's driver heap (amdxc64.dll, ~400 KB per pipeline, measured with an NtAllocateVirtualMemory trace): private commit climbed past 45 GB and the system ran out of commit.

While the shader queue was long, title threads without a stand-in waited in their own Create*PipelineState call behind thousands of background DXC jobs (most held by wait_for_memory). The game's watchdog (+0x2215a60) kills the process when a thread stays silent ~30 s.

Change

  • pso_async::submit_lazy: pipelines with console shaders (graphics without HS/DS/GS, compute) get their stand-in at creation and are sent to the workers on their first resolve. resolve_wait (compute) builds a not-yet-sent pipeline on the spot. XCL_LAZY_PSO=0 restores build-at-creation.
  • dxc::urgent: compiles requested from a title thread that waits for them (the sync fallbacks with no stand-in) run immediately on their own xcl-dxc-urgent thread, not behind the pool queue / memory gate (still counted in WORKING).
  • Stand-ins get pc_topology_type (console rect list 19 / 0 were refused with 0x80070057, so the title waited for the full translation instead).

Result (GTA VI 1.0.2.1, AMD GPU, 64 GB)

private commit after 60 s
before 45+ GB, rising until the system runs out
this PR 16.9 GB, flat

No more watchdog kill from starved pipeline creation. (The game then stops on Xbox depth-format issues: separate PR.)

Test plan

  • cargo test --release -p xcl --lib: 534 passed; the 1 failure (gpu_wave64_ps_whole_wave_reductions) also fails on main
  • GTA VI: peak private memory 16.9 GB over 90 s (was 45+ GB); log shows pipelines are built at their first use (n created so far)
  • Another title with many pipelines, to check the first-use build causes no visible hitches (XCL_LAZY_PSO=0 to compare)

🤖 Generated with Claude Code

https://claude.ai/code/session_01XTYmP6vKUQKatSiA2PC95B

…for waiting title threads

GTA VI (retail, GDK) creates ~51 000 distinct pipelines in its first 30 s. Each one built at
creation stays in AMD's driver heap (~400 KB): commit went past 45 GB and the system ran out.
Pipelines with console shaders now get their stand-in at creation and are built the first time
they are bound (pso_async::submit_lazy, sent to the workers on the first `resolve`; compute is
waited for as before). XCL_LAZY_PSO=0 builds them all at creation as before.

A title thread with no stand-in waits in its own call for the translation: its DXC compiles
now run at once on a thread of their own (dxc::urgent) instead of queueing behind thousands of
background jobs held by the memory gate. GTA VI's watchdog killed the game when one of its
threads stayed silent ~30 s. resolve_wait builds a pipeline nobody sent yet on the spot.

Stand-ins also get the PC topology type (pc_topology_type): the console's rect list / none were
refused (0x80070057) and the title waited in the call instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XTYmP6vKUQKatSiA2PC95B
@Krigsexe

Krigsexe commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Heads-up: this repo isn't about any specific retail title. Naming a build version and binary offset in a public PR is a quick way to get the whole repo DMCA'd. Better to keep it generic to D3D12.X pipeline creation. @Sr-0w & @claude

@gefydev

gefydev commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Update 18:16 UTC: main moved to 956a476 while I measured. Its resolve_wait now also builds a pipeline no worker has started, so on the same bench main is at 0.58 / 0.60 / 0.62 s for the last one and 7.35 / 7.39 / 7.36 s for all 200. The main row below is the older db5dc26. The queue wait is no longer a difference between this PR and main; the lazy build is, and points 1 and 2 are about that. This PR conflicts with main now.


I had a smaller change for the same wait ready (a waited-for pipeline moves ahead of the queue) and found this PR in my last duplicate check, so I did not open mine. I tested this one instead.

Machine: Ryzen 5 1600 (6C/12T), 16 GB RAM, ~13.5 GB commit free, GTX 1650 4 GB (driver 32.0.16.2124, 32-lane waves), Windows 11 26300, DXC from SDK 10.0.26100. No retail title was run here. PR head 73c8e74 on db5dc26, debug build.

Tests: cargo test --workspace: 535 lib tests pass, 0 fail, 2 SKIPPED (no wave64). The other suites pass. e2e passes after cargo build --workspace; my first run failed only because I had not built the test title.

Synthetic bench: 200 pipelines, each one DXC compile of a different CS, no cache, no driver PSO, 11 DXC threads. 3 runs each.

wait for the last one all 200
main db5dc26, submit 7.33 / 7.25 / 7.24 s 7.38 / 7.36 / 7.38 s
this PR, submit 0.35 / 0.34 / 0.31 s 7.35 / 7.36 / 7.38 s
this PR, submit_lazy, 1 title thread, all used – 45.2 / 45.5 / 45.5 s
this PR, submit_lazy, 4 title threads, all used – 11.9 / 11.9 / 11.9 s

The main runs and this PR's were not interleaved with each other (minutes apart on the same machine). The wait behind the queue is gone. Two things I noticed:

  1. counts() still counts every unfinished Pending, so lazy pipelines that were never used count as building (measured: 200 of 200 before any use). present::show_compiling treats queued > 0 as active, so from reading the code the window title would say "compiling shaders: … N pipelines queued" for the whole run, and report.json background_pipelines would include them. Counting only those that were sent (queued) or whose job is already taken would fix it.

  2. When pipelines are used right after they are bound, they are built one at a time per title thread. resolve at bind sends the pipeline, but the draw / dispatch that follows takes the job back in resolve_wait if no worker got it first, so the worker pool seems to stay mostly idle (45 s against 7.4 s above). It is the worst case (every pipeline used, bind then use at once, no other work between them) and it does not count what you save by never building the rest, so it may well be the right trade for a title that creates ~51 000. It is the first-use hitch your last test-plan item asks about. Each waiting thread also skips wait_for_memory, so the gate's limit does not hold for them.

My version's tests (queue order, waiting twice, a blocked worker) are yours if useful; I can send them as a patch.

@ryosen0

ryosen0 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested pull/162/head (lazy-pso, commit 73c8e74) on this title, Windows 11 host, RTX 3060 Ti (wave32), XCL_NETWORK=0:

The null-write crash is unchanged — game_scarlett_master.exe+0x2215c35 (write at address 0x0), identical registers to the non-lazy run:

rax=0x140004380 rbx=0x0 rcx=0x4189374bc6a7f0 rbp=0x0 r8=0x7ffea000
on the stack: game_scarlett_master.exe+0x71b9a20, game_scarlett_master.exe+0x2215eca

Differences with lazy-pso:

  • crash surfaces earlier, ~50 s (vs ~93 s build-at-creation);
  • translated_pipelines: 3 (most now deferred to first use), failed_pipelines: 641, presents: 2, unique shaders 4,536 — same ballpark;
  • the failed PSOs still log PSO stream rejected (0x80070057), the fallback version too.

Two conclusions this rules in/out:

  1. The crash is not the ~30 s watchdog at +0x2215a60 — +0x2215c35 is a different site (+0x1d5 away), and lazy building changed the timing without moving the crash. So it's a genuine null-deref, not a thread-silence kill.
  2. The title dereferences the result of a rejected console-shader pipeline (rbx=0, rbp=0, static rax=0x140004380) regardless of when that pipeline was built. The 0x80070057 rejections — topology type 3, 2 render targets, DSV format 118, HS false, GS false — look like the upstream cause; this matches the AS/MS subobject suspicion in HANDOFF. PR D3D12.X: Xbox D16S8 depth formats and depth buffers that are also UAVs #163 (D16S8 depth formats) is likely relevant since DSV format 118 (D16S8) is in that rejected stream.

Happy to re-run any candidate fix (AS/MS numbering, or #163) on this title and report register-level diffs — fast turnaround on our side.

gbuyssens added a commit to gbuyssens/xcl that referenced this pull request Nov 23, 2026
…urgent compiles for waiting title threads

Conflict in pso_async.rs: ivall#162's version kept - it already holds upstream's
build-in-the-bind behaviour (resolve_wait takes the job) and adds the lazy queue.
gbuyssens added a commit to gbuyssens/xcl that referenced this pull request Nov 23, 2026
…urgent compiles for waiting title threads

Conflict in pso_async.rs: ivall#162's version kept - it already holds upstream's
build-in-the-bind behaviour (resolve_wait takes the job) and adds the lazy queue.
Sr-0w and others added 2 commits November 23, 2026 20:00
# Conflicts:
#	crates/xcl/src/hle/d3d12x/pso_async.rs
With GTA VI's compute pipelines built at their first dispatch the device was removed ~20 s in
(an invalid call, nothing from the debug layer before it); with graphics ones only it runs at
30 fps. Compute pipelines are far fewer and their first bind waits for them anyway.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XTYmP6vKUQKatSiA2PC95B
@Sr-0w

Sr-0w commented Nov 23, 2026

Copy link
Copy Markdown
Author

Update after 956a476 ("Retail game reaches 30 fps"):

  • Merged main into this branch. pso_async now keeps your job / complete structure and only adds the first-use part (queued, submit_lazy, send).
  • Compute pipelines are no longer deferred. On top of 956a476, building GTA VI's compute pipelines at their first dispatch got the device removed ~20 s in (0x887a0001, nothing from the debug layer before it). I bisected my 4 PRs on top of main and only this deferral did it. With graphics deferral only, it runs at 30 fps like main.
  • The memory win is no longer measurable on main. Private commit during the first minute: main 13 → 18 → 30 → 38 → 39 GB, this branch 15 → 19 → 27 → 38 → 44 GB. Both then hit the same spike (up to 162 GB on main here, 64 GB RAM): with XCL_TRACE_ALLOC (Crash diagnostics: thread dump at the unhandled exception; XCL_TRACE_ALLOC commit tracer #164) it is amdxc64.dll compiling pipelines plus XCL's translation of big compute shaders (translate / emit, called from dev_create_compute_pso on a title thread). That matches the 1 MB ray-tracing programs in HANDOFF.

Converting to draft: as it stands, this does not earn its complexity on current main. The dxc::urgent part (compiles for a title thread that waits, run ahead of the queue) may still be worth taking on its own. Tell me if you want it split out.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XTYmP6vKUQKatSiA2PC95B

@Sr-0w

Sr-0w commented Nov 23, 2026

Copy link
Copy Markdown
Author

Found the cause of the device removal I attributed to deferring compute pipelines: invalid UAV descriptors on depth buffers whose UAV flag #163 drops, used by a dispatch. #163 now writes a null view for them. With that, deferring compute pipelines too works (XCL_LAZY_COMPUTE=1 locally): private memory stays around 20 GB at 35 s, vs 60+ GB and rising without it. The game then gets further (it creates those shadow-map UAVs) and stops at ~35 s on a memset to a null pointer in title code (+0x5ebea33, a 256 KB R32_FLOAT buffer whose allocation returned null). I am investigating that before proposing compute deferral again.

🤖 Generated with Claude Code

@gw1337x

gw1337x commented Nov 23, 2026

Copy link
Copy Markdown

Setup: AMD Radeon RX 7800 XT (RDNA3, 16 GB), driver 32.0.32015.7029, 32 GB RAM, Windows 11 Pro 26200, GTA VI retail, XCL_NETWORK=0, release build.
Test branch: main 956a476 + #170 (incl. #163 @ 634c423) + #162 @ 641f551 + #168 @ 070a737 + xg.rs of #169 + #176 + #164.

Data point for compute deferral, with the view-format fixes I posted on #163 and #168 in place: deferring compute pipelines works on this machine and it is what makes the difference with 32 GB of RAM.

XCL_TRACE_ALLOC (#164): without compute deferral, amdxc64.dll grows 4.7 → 23 → 48 GB (15 / 30 / 45 s), all under translated_compute_pso → CreateComputePipelineState. Private commit of the game process reaches 76–90 GB, the working set drops to ~0 (paging), and the game's watchdog (+0x2215c35) fires at 50–54 s. A warm translation cache made no difference. XCL_DXC_THREADS=4 made no difference either.

at 30 s build-at-creation compute deferred too
process private commit 48–57 GB 35 GB
amdxc64.dll (tracer, cumulative) 23 GB 7.5 GB

(I restored the compute branch of 73c8e74 behind XCL_LAZY_COMPUTE=1.)

Related: dxc::wait_for_memory checks ullAvailPageFile, which on a system-managed page file keeps growing (the commit limit went 84.8 → 113 GB during a run), so the gate never held anything back while physical memory was exhausted.

Next stop with deferral on: DEVICE_HUNG (0x887a0006) at ~26 s. In a debug-layer run of the same build, the last error before it stopped was IASetIndexBuffer: pDesc->BufferLocation 0x...2480 does not belong to any existing Resource or Heap (title memory outside the GPU windows, I think).

🤖 Generated with Claude Code

@RemingtonWilcox

Copy link
Copy Markdown
Contributor

Tested 641f551 (main 956a476 + this PR) on an RTX 3090 (driver 616.92), Windows 11 26300, Ryzen 9 5950X.
cargo test --workspace --no-fail-fast -- --test-threads=2: 569 passed, 0 failed, 39 ignored, identical to main. The PR adds no tests and I have no title, so this only covers regressions in the synthetic suite (GPU tests included): none.

AI-assisted test report (Claude); tests run locally as stated; the diff was read in full before running.

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

I tested disposal, concurrent first use and build failure at the scheduler boundary on PR head 641f55143864349fa3a5dd02557512af8fe0e43d and main 956a476bf738a098f39df4f4c8acef682e43030f (Windows x64 MSVC, Rust 1.99.0). These were synthetic closures. The surrounding D3D12.X tests ran on the RTX 5070 Ti workstation.

Check main, eager submit PR head, lazy submit
Release the stand-in before its first bind Job ran Job dropped without running
First graphics bind during a gated build Returned stand-in Returned stand-in
Two waiting callers, then successful completion Both got the real result, one build Same
Two waiting callers, then a build returning zero Both got the stand-in, one build Same

Repeated binding after failure continued to return the stand-in. The first draw can still block while a build is in flight: crates/xcl/src/hle/d3d12x/bind.rs:291 calls resolve_wait before drawing. A nonblocking graphics bind alone therefore gives no bound on first-draw latency.

The PR adds no tests. The affected module plus two reviewer tests gave 56 pass / 0 fail on the PR head and 55 pass / 1 fail on main; the eager-disposal negative control accounts for the difference. The fixtures cover two concurrent waiters and an ordinary failed build. Driver compilation time, frame-time distribution, process memory and retail execution were outside this test. AI-assisted review.

Built at creation, GTA VI's thousands of compute pipelines took 60+ GB of commit in AMD's driver
within a minute and the game never left its loading screen (no dispatch at all in 80 s). The
device removal this deferral once caused was not the deferral: invalid UAVs of depth buffers
(fixed in ivall#163) used by the dispatches it let the game reach. With both, GTA VI reaches its
title screen and menus. `XCL_LAZY_COMPUTE=0` builds them at creation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SKtJseucqXR6iuAE6HBtiA
@Sr-0w
Sr-0w marked this pull request as ready for review November 23, 2026 20:42
@Sr-0w

Sr-0w commented Nov 23, 2026

Copy link
Copy Markdown
Author

Compute pipelines are deferred again, now by default (XCL_LAZY_COMPUTE=0 turns it off). The device removal this deferral caused earlier came from invalid depth-buffer UAVs, which #163 now fixes. Without the deferral, GTA VI makes no dispatch in 80 s and reaches 96 GB of commit. With it, it stays around 20–40 GB and gets to its title screen and menus. Screenshots are in #203. Marked ready for review.

🤖 Generated with Claude Code

@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Main now creates console pipelines at their first use by default (956a476 + 38b05b7: pso_async::lazy, XCL_LAZY_PSO=0 turns it off). A graphics pipeline is translated and sent to the workers at its first resolve, and a compute pipeline is built at its first bind. With that, and the page-based placement of GPU-owned textures in 38b05b7, the retail game reaches its first menu at ~19 GB of commit. This branch now conflicts with main. Could you check against current main whether anything here is still needed, for example the disposal and concurrent-first-use behaviour Kalmarv tested?

@Sr-0w

Sr-0w commented Nov 23, 2026

Copy link
Copy Markdown
Author

Checked against current main (7a033c8): main already builds console pipelines at first use, graphics at first resolve and compute at first bind. With it, the retail game gets past its title screen and into its world without this branch. The only thing left here is dropping a deferred build whose stand-in is released before its first bind (the disposal case Kalmarv tested). It saves some wasted compiles but isn't needed for correctness, and I haven't measured a difference from it. Closing. I can reopen a small PR for that part alone if you want it.

🤖 Generated with Claude Code

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.

8 participants