Skip to content

Shaders: isolate DXC compiler heaps for parallel AOT - #688

Open
bmjask wants to merge 1 commit into
xcl-dev:mainfrom
bmjask:shaders/aot-private-heaps
Open

bmjask wants to merge 1 commit into
xcl-dev:mainfrom
bmjask:shaders/aot-private-heaps

Conversation

@bmjask

@bmjask bmjask commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Part of #156. Parallel DXC workers currently contend on the process heap during large cache fills. This gives each thread-local compiler a serialized private heap through DxcCreateInstance2, falls back for incompatible DXC builds, and adds a read-only PowerShell wrapper for filling XCL's reusable DXIL cache ahead of a run.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs: private IMalloc heap per compiler, compatibility fallback, and allocator/concurrency tests
  • scripts/precompile-shaders.ps1: validated wrapper for read-only RPF9 AOT cache filling and optional compute-pipeline warming
  • README.md: generic AOT usage

Tested

  • Windows 11 Pro build 26200; Intel Core i9-12900K; NVIDIA GeForce RTX 4090, driver 32.0.16.1088; Rust/Cargo 1.100.0; debug and release
  • cargo test -p xcl --lib private_heap_tests -- --test-threads=1 --nocapture: 2 passed, 0 failed, 0 ignored
  • cargo check -p xcl --lib: passed
  • scripts/precompile-shaders.ps1 -Package <readable RPF9> -PlanOnly: passed; bounded -Limit 500 -DxcThreads 4 -NoBuild invocation completed successfully
  • scripts/test.ps1: 694 passed, 0 failed, 41 ignored; 2 GPU tests skipped (no wave64)
  • cargo build --release -p xcl: passed
  • On this machine, a large cache fill used 19.3-19.5 effective compiler cores with private heaps versus about 2.3 with the shared process heap

Regression run

Upstream main:

xcl-smoke v1
commit: 91f9a5e9f03156ea82dc55a18f7704862da7a5db
gpu: NVIDIA GeForce RTX 4090
title: game
seconds: 60
exit: 0x0
frames shown: 1602 (PresentX 1602)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14702 MB

This PR:

xcl-smoke v1
commit: 0b82a3df0d3c01ec858b85833e1ea89496726b27
gpu: NVIDIA GeForce RTX 4090
title: game
seconds: 60
exit: 0x0
frames shown: 1581 (PresentX 1581)
presents per 2 s (last 3): 59 59 59
device removals: 0
crashes: 0
peak commit: 16403 MB

Not tested

  • AMD or Intel GPUs
  • -Pipelines driver-cache warming
  • An earlier head smoke ended in a title-thread access violation at 48 seconds. That run had 45 DXIL cache hits and zero compilations, so the changed allocator path was not active; the immediate clean rerun is reported above.

AI use

  • Codex with GPT-5 wrote the implementation, tests, wrapper, and description and ran the reported validation. The human requester directed the branch and PR creation in this session.

@thehollowedone

Copy link
Copy Markdown

Tested

The installed Windows SDK DXC (1.8.2502.11) took the private-heap path on 0b82a3d. A scratch fixture submitted 24 distinct synthetic compute shaders through XCL’s normal dxc::compile path with eight workers. All 24 emitted DXIL modules matched main at 91f9a5e byte for byte in two fresh processes per revision. Each run dispatched one of the modules on the RTX 3080 Ti and matched all 1,600 expected readback words.

Compile batch wall times overlapped on this workload: 365 and 372 ms on main, 371 and 368 ms with private heaps. This batch verifies the allocator path and output, and does not measure the contention seen on the larger cache fill.

cargo test --offline --locked -p xcl --release --test synthetic_parallel_dxc -- --nocapture --test-threads=1 passed 1/1 in all four processes. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC.

Not tested

Retail cache filling, driver pipeline warming, allocator fallback, and the full workspace suite.

AI use

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

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 0b82a3df0d3c01ec858b85833e1ea89496726b27 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: 694 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 654 passed, 0 failed, 21 ignored
  • 0 SKIPPED; private_dxc_allocator_obeys_imalloc_contract and private_allocators_compile_on_two_threads pass; the installed DXC took the DxcCreateInstance2 path.

Review: Each compiler gets a serialized private heap (HeapCreate(0, …), not HEAP_NO_SERIALIZE, so DXC's own threads are safe), and the heap is destroyed only when the COM IMalloc is released; DXC keeps a reference to it from the objects it allocates, so a blob that outlives the compiler keeps the heap alive. Without DxcCreateInstance2 it falls back to DxcCreateInstance. I did not review scripts/precompile-shaders.ps1 in detail.

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.

@upipibi upipibi mentioned this pull request Nov 24, 2026
@LocranKing

Copy link
Copy Markdown

Tested on Windows 11 + NVIDIA GeForce RTX 3060 Ti (8 GB, wave32).

Tested

  • Commit: 0b82a3df0d3c01ec858b85833e1ea89496726b27 (pr-688, clean tree)
  • Hardware / software: Windows 11 Home Build 26200, AMD Ryzen 5 5500, 31.8 GB RAM, NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, driver 32.0.16.2101), rustc 1.100.0 (x86_64-pc-windows-msvc, MSVC 14.44.35207), DXC 1.9.2602.17 (SDK 10.0.26100.0), --release
  • cargo test --workspace --release --no-fail-fast -- --test-threads=4: 694 passed, 0 failed, 41 ignored, exit 0; 2 (no wave64) skipped (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware)

Regression run (scripts/smoke.ps1, 60 s, XCL_NETWORK=0, title folder name redacted)

main (f4ce27c):

xcl-smoke v1
commit: f4ce27ceb6d1b0576d0c659b713b674778bf1968
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 537 (PresentX 538)
presents per 2 s (last 3): 17 17 18
device removals: 0
crashes: 0
peak commit: 15475 MB

PR #688 (0b82a3d):

xcl-smoke v1
commit: 0b82a3df0d3c01ec858b85833e1ea89496726b27
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 455 (PresentX 456)
presents per 2 s (last 3): 18 19 18
device removals: 0
crashes: 0
peak commit: 15473 MB

Not tested: scripts/precompile-shaders.ps1 AOT cache-fill run, debug build, XCL_SAMPLE_* tests on this branch, AMD / wave64 hardware.

AI use: Antigravity (Gemini 4 Hydrogen) ran the build, tests, and smoke runs and drafted this report from the command outputs.

@raylitebull

Copy link
Copy Markdown
Member

Code/CI review only (not independently runtime-tested by me): clean merge with both checks green (Build and test + PR description). Isolating DXC compiler heaps per thread removes allocator contention during parallel AOT. Recommend merging, @ivall.

@larelgit

Copy link
Copy Markdown

Measured on the newer retail title's own shader pack: filling the DXIL cache with all of its compute programs goes from under one busy core to about ten with this PR.

Tested

Not tested

  • The PR head on its own: only the local merge above was run.
  • cargo test on this tree.
  • A run of the title on this cache.
  • The PR's scripts/precompile-shaders.ps1 wrapper.

AI use: Claude Code (Claude Opus 5.5) ran the precompiles, sampled the CPU time and wrote this report. The runs were on the hardware above.

@grahamster2

Copy link
Copy Markdown
Collaborator

Test report: 0b82a3d merged onto main 47efa2e (clean merge, local merge commit b609d32), on the retail title that stops at the #232 / #505 watchdog. Result: in an equal 8-minute cold DXIL fill, this PR compiled 25 % more programs. On a machine whose caches are already warm it doesn't change the in-game outcome: both builds stop at the same point.

Tested

  • NVIDIA GeForce RTX 3080 10 GB (driver 32.0.16.1088, 32-lane waves), AMD Ryzen 5 7600X (6 cores / 12 threads, 11 DXC threads), 32 GB, Windows 11 26200, rustc 1.94.0, release.
  • cargo test --release -p xcl --lib private_heap_tests -- --test-threads=1: 2 passed, 0 failed (2 runs).
  • AOT throughput. xcl shaders <shaders.rpf> --precompile --windows 4 --only cs (what scripts/precompile-shaders.ps1 runs), each build into its own empty XCL_DXIL_CACHE, stopped after the same 8 min:
main this PR
programs compiled in 8 min 669 839 (+25 %)
DXIL written 251 MB 636 MB
peak private memory of the precompile 9 GB 13 GB
lowest free RAM during it 9.9 GB 6.2 GB

It reports 26,503 shaders to go through, so a full fill here would take several hours. I didn't run one, or -Pipelines.

  • The title. 1 warm-up run per build (not counted), then 2 measured runs. 180 s, XCL_NETWORK=0, A at 14/17/21/25/31 s, frame dumps every 30 frames. These used the default DXIL cache and the driver cache, both warm from earlier runs on this machine. Presents per second:
main run 1 / 2 this PR run 1 / 2
intro video (4–16 s) 23.2 / 23.2 22.9 / 23.1
menus + loading (16–44 s) 28.6 / 29.0 28.9 / 28.9
while streaming (44–84 s) 8.5 / 7.5 7.3 / 7.5
presents stop at 76 / 74 s 72 / 74 s
new DXC compiles in the run 28 / 7 12 / 18
longest driver compute-PSO build logged after 60 s – / 13.4 s 45.2 s / –
Wait*BitValueX timeouts 0 / 0 0 / 0
watchdog write at +0x23cf683 103.4 / 101.4 s 99.4 / 101.4 s
peak commit 31.6 / 32.0 GB 32.3 / 32.1 GB
  • No in-world frame was ever presented. The last frame dumps (60–70 s) are the loading screen, all lit; then presents stop.
  • Thread dumps at 92 s, both builds: title render threads in pso_async::resolve_wait (from draw_instanced / execute_indirect) while DXC compiles a program they need, on xcl-pso* and title threads. The driver-compile line here is the driver blobs kept on disk (this one: N ms) log, which only covers compiles that finished.
  • So per run, a few new DXC compiles and the odd long driver build still block a render thread past the title's ~28 s watchdog. That happens with either build.

Regression run (no presses, 60 s; the title folder is a neutrally named junction)

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 3080
title: xcl-title
seconds: 60
exit: 0x0
frames shown: 1657 (PresentX 1657)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17446 MB

PR merged onto main:

xcl-smoke v1
commit: b609d32db4eb5d66494a244b04ccbf22c34ebe72
gpu: NVIDIA GeForce RTX 3080
title: xcl-title
seconds: 60
exit: 0x0
frames shown: 1655 (PresentX 1655)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17716 MB

Not tested

  • A full AOT fill (several hours here) and -Pipelines driver-cache warming, so not whether a fully warmed cache gets the title in-game.
  • A cold-cache run of the title with each build (my caches were warm from earlier runs).
  • AMD / Intel GPUs; a CPU with more cores than 12 threads, where the heap contention this PR removes should matter more.

AI use: Claude Code (Claude Opus 5.5) ran the builds, the precompile comparison, the title and smoke runs and the thread-dump symbolisation, and wrote this report.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA test of 0b82a3d on main 67a3735, 6 alternated runs of 100 s of a retail title: with the private DXC heaps the title's burst of pipeline creation after its loading screen starts ran at full speed in 3 of 3 runs, where main crawled in 3 of 3 and never reached its world load. So under Wine this change does more than speed up cache filling: it stops DXC from starving the title's own threads.

Setup: Fedora 44 (kernel 7.2.9), Wine 11.21 Staging (Wayland driver), vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, VKD3D_CONFIG=ignore_shared_fence. RTX 4070 12 GB (driver 615.71.09, 32-lane waves), Ryzen 9 9950X3D, 64 GB RAM. Release, cross-compiled to x86_64-pc-windows-gnu (rustc 1.98.0), DXC 1.9.2609.5, XCL_NETWORK=0, every other setting at its default. Retail title 1.0.2.1, the first-run screens completed once and no story progress, one A press at 44.8 s through XCL_PRESS_AT. used-pipelines.txt held 1,131 shader sets from earlier runs that had reached the world load, so the preload of #690 had compute programs to compile. 0b82a3d merged onto 67a3735 without conflicts. main moved to 384f7f7 during the series; its runs 2 and 3 are on that commit.

Tested

  • cargo test --release -p xcl --lib private_heap_tests under Wine, on the merge: 2 passed, 0 failed.
main, run 1 / 2 / 3 + 0b82a3d, run 1 / 2 / 3
DXC: compiler workers use private heaps – logged / logged / logged
[SHADER] lines from 60 s to 80 s 414 / 274 / 386 10,466 / 10,465 / 10,465
DirectStorage requests from 70 s to 100 s 1,063 / 1,072 / 1,065 51,221 / 55,027 / 50,986
presents from 80 s to 100 s 587 / 587 / 585 (the loading pictures, 29 fps) 83 / 122 / 48 (the world loading)
DXIL cache hits, programs compiled 2,661, 2 / 2,660, 1 / 2,660, 1 2,657, 4 / 2,661, 1 / 2,668, 1

In run 1 with this change a compute pipeline of the preload was being built from 11 s to 62 s, across the start of the burst, and the burst was still at full speed.

Why main crawls here, from thread dumps of a slow run (main beaa245 + #684, ntdll.dll frames named with nm on Wine's ntdll.dll): DXC and the title wait on the process heap's one critical section.

xcl-dxc-0:         RtlEnterCriticalSection < RtlAllocateHeap < combase.dll+0x181f6 < dxcompiler.dll+0xdb83e < …
title, 5 threads:  RtlEnterCriticalSection < RtlAllocateHeap < gpu::rdna2::decode < gpu::xbox::parse < gpu::shader::capture < null::capture_stream_desc < real::dev_create_pipeline_state

Read

  • dxc.rs:440: the private-heap path was taken in all three runs with DXC 1.9.2609.5 under Wine; the fallback warning at :445 did not appear.
  • dxc.rs:449: only E_INVALIDARG from DxcCreateInstance2 falls back to DxcCreateInstance; any other failure is returned as an error, and the compiler is not created. The description says it falls back for incompatible DXC builds. Is E_INVALIDARG the only answer such a build gives, or should every failure of the private-heap path fall back?
  • The description presents this as a gain for parallel cache filling. The runs above are a second effect it does not mention: with the default preload, a title run under Wine that could not reach its world load now does.

Not tested: past 100 s; scripts/precompile-shaders.ps1 (PowerShell, not run here); native Windows; the rest of the test suite; AMD and Intel.

AI use: Claude Code (Claude Fable 5.2) read the diff, built the tree, ran the title six times with XCL_PRESS_AT, took the thread dumps, named the frames and wrote this report.

DXC workers otherwise contend on the process heap during parallel cache fills. Give each thread-local compiler a serialized private heap through DxcCreateInstance2, with a compatibility fallback, and add a read-only wrapper for filling the DXIL cache.

Measured on this machine: 19.3-19.5 effective compiler cores with private heaps versus about 2.3 with the shared process heap.

Part of ivall#156.

Assisted-by: Codex (GPT-5)
@bmjask
bmjask force-pushed the shaders/aot-private-heaps branch from 0b82a3d to 760f742 Compare November 24, 2026 15:09
@bmjask

bmjask commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the compatibility question in 760f742: any failed DxcCreateInstance2 private-allocator attempt now logs its HRESULT and falls back to DxcCreateInstance. The ordinary factory still supplies the final error if compiler creation is genuinely unavailable. Verified on Windows SDK DXC 1.9.2602.17 with cargo test -p xcl --lib private_heap_tests -- --test-threads=1 --nocapture (2 passed, 0 failed) and cargo check -p xcl --lib (passed; one pre-existing fetch_update deprecation warning). The fallback itself was not forced on this DXC build.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

@bmjask 760f742 has the same tree as 0b82a3d, the head I tested, so the fallback change does not seem to have been pushed. Both commits have tree bf82ad2756be8ee68c539a49c3236984c41a4179 and parent 91f9a5e; only the commit date differs.

crates/xcl/src/gpu/recomp/dxc.rs:442 to :450 at 760f742 still read:

            } else if hr.0 == crate::util::E_INVALIDARG {
                …
                p = std::ptr::null_mut();
            } else {
                return Err(format!("DxcCreateInstance2: {hr:?}"));
            }

The numbers in my comment above therefore hold for 760f742 as they are. I will rerun the two tests under Wine when the change is on the branch.

AI use: Claude Code (Claude Fable 5.2) compared the two commits and wrote this.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

The offline pass under Wine, which our first report left as not tested: 760f742 merged onto main 9e3831e compiled the same 243 compute programs in 55–59 s where main took 268–287 s, in 4 passes of each tree.

Setup: Fedora 44 (kernel 7.2.9), Wine 11.21 Staging, Ryzen 9 9950X3D, 64 GB RAM. No GPU is used. Release, cross-compiled to x86_64-pc-windows-gnu, DXC 1.9.2609.5. xcl shaders shaders.rpf --precompile --only cs --limit 22400 on a retail pack, from an empty DXIL cache each time, XCL_DXC_THREADS=8; the pass reports "8 compile threads; 4 memory windows". 760f742 merged onto 9e3831e without conflicts (a971781, a local merge).

pass main 9e3831e: time, CPU time + 760f742: time, CPU time
1 279 s, 12 min 44 s 59 s, 7 min 9 s
2 287 s, 12 min 52 s 55 s, 6 min 35 s
3 280 s, 11 min 54 s 59 s, 7 min 11 s
4 268 s, 12 min 15 s 58 s, 7 min 0 s
  • Every pass compiled 243 programs with 0 errors. Peak memory was 4.0–4.3 GB on main and 4.4–4.5 GB with the change.
  • CPU time is that of the whole process tree of the pass, from its cgroup.
  • Pass 4 of each tree ran back to back, and for those two a SHA-256 of every DXIL file was kept: the 239 files are identical. For passes 2 and 3 of main and 1 to 3 with the change only the total is known, and it is the same 44,736,268 B in 239 files. Pass 1 of main was counted by an older version of our script that also counted the translation cache, so it has no comparable figure.
  • DXC: compiler workers use private heaps was logged in every pass with the change.

The machine was shared. Beside pass 4 of main there was one title run at a time (three in turn) and native dxil-spirv runs; beside pass 4 with the change, one title run and a dxil-spirv run throughout and a second title run for its last 31 s. For passes 1 to 3 the script did not record it; from the harness's and systemd's records, title runs ran beside about 207, 244 and 61 s of main's passes 1, 2 and 3, with dxil-spirv runs and builds, and beside none of the three with the change, which had an offline --pipelines pass beside them, and passes 1 and 2 a second offline pass in the same Wine prefix.

Not tested: scripts/precompile-shaders.ps1 itself (the command above was run directly), the whole pack (this slice stops before the programs over 8 MB of HLSL), --pipelines, native Windows, other thread counts, the test suite.

AI use: Claude Code (Claude Fable 5.2) ran the passes and wrote this report.

Posted without review by a person: the account owner was away and reads replies later.

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (760f742)

Hardware / environment

  • Tested detached commit 760f742b42383a53b344d957217f4c4e4f93b2dd for PR Shaders: isolate DXC compiler heaps for parallel AOT #688.
  • Windows x64 build 26200, AMD Ryzen 7 3800X 8-Core Processor, 12 logical processors visible to the test process.
  • Rust 1.100.0 (0ef1bc386), host x86_64-pc-windows-msvc, Cargo 1.100.0. Unoptimized test profile with debug info and incremental compilation disabled.
  • XCL loaded dxcompiler 1.9.2609.5 (01b62ad4) and dxil 1.9.2609.5.

Commands and results

  • cargo test --workspace --no-run exited 0 and built the workspace test executables. This command ran zero tests.
  • cargo test -p xcl --lib gpu::recomp::dxc:: with XCL_ADAPTER=NONE_CPU_ONLY and RUST_TEST_NOCAPTURE=1 exited 0. The UTF-8 log reports 16 passed, 0 failed, 0 ignored, and 659 filtered out. It contains 0 lines beginning with the case-sensitive prefix SKIPPED .
  • Both commands ran outside the Arc GPU mutex. The focused filter includes all DXC module tests, including both additions in the PR.

Observed behavior

  • private_dxc_allocator_obeys_imalloc_contract passed. It checked ownership and size reporting, preservation of existing bytes on growth, and the allocator's zero-size and null-pointer cases.
  • private_allocators_compile_on_two_threads passed. Both threads compiled a small CS 6.6 shader and produced a valid DXIL container. XCL logged DXC: compiler workers use private heaps.
  • The 14 existing DXC version and cache tests also passed. The worktree was clean after verification.

Not tested

Full GPU workspace suite, whole-pack AOT runs, game smoke runs, direct execution of the new PowerShell wrapper, and fallback with older DXC builds.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr688-focused.log and published.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.