D3D12.X: compute pipelines not used for a while are released on NVIDIA #2526
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2526
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2526"
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?
@veyn-sudo on GitHub · 2026-11-25 21:37 UTC · original
veyn-sudo:pr/release-unused-shader-code→main· +699 −28 · 7 files · 2 commits · draftStacked on #2422; only the top commit belongs here.
NVIDIA's driver keeps the compiled code of the pipelines in use in a heap of at most 512 MB and removes the device when a submission needs more (#2403). Code counts from a pipeline's first use until it is released, so this releases compute pipelines that are not in use and builds them again at their next bind. Part of #2403.
It is not enough by itself. With the translations of the default path one command allocator's recordings use 289 MB here, and nothing a recording uses can be released: the device was still removed (132 s and 200 s into a run, 134-141 s without). With
XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1the code is about 40 % smaller. CharlyRien has a version of this of their own and reports no removal in 480 s with it and the direct path (#2403).What is in it
hle/d3d12x/shader_code.rs(new): which pipelines count, what recordings hold, what to release.XCL_SHADER_CODE_MBis the code to keep in use (GetCachedBlobsizes): 320 on NVIDIA, no limit elsewhere, 0 for none.pso_async.rs: a build can run again (JobisFnMut); past the limit the compute pipelines bound longest ago are released, none used in the last second. Their next bind builds them itself: a turn in the workers' queue behind first builds took minutes.list_x::record_deferred) hands its pipelines to its segment's allocator too: its segment is reset withoutcl_reset(found by KDenKC).Reset(or the pool knowing that no list is on it and the GPU is done,alloc_pool::when_done, which checks and takes under one lock) gives it back.real/dispatch_chain.rs: all pieces of a split program count, and its recordings let go of them in the same step.when_donetaking under the lock, a split program's recordings and pieces, a dispatch put off to the submit keeping its pipeline with its segment.699 added lines, 58 of them #2422's and 81 the deferred-dispatch fix and its test. I did not find a smaller part that does anything alone: releasing is unsafe without the references, and they do nothing without it. #2417 keeps resolved pipelines alive too; if it goes in, the references here can use it.
Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on0fd22d04: 1441 passed, 0 failed, 47 ignored.SKIPPEDlines: 21 no wave64, 3 f16 forms refused, 1 no heap windows.a_dispatch_with_a_pipeline_still_building_waits_at_the_submitfails; it does onmaine1d84b7too (4 of 12).execute_indirect_reads_the_arguments_written_before_itfailed once with out of memory, not in 8 repeats.XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_DIRECT_SPLIT_INSTRUCTIONS=0: six runs reached the world and were stopped by low memory after 158-170 s, without a removal, the one withXCL_SHADER_CODE_MB=0too. In the two where it was measured at most 116 and 132 MB of code was in use, far under 320. WithXCL_SHADER_CODE_MB=6045 pipelines were released and 121 MB stayed in use.Regression run
main:
this PR:
Not tested
AI use
🤖 Generated with Claude Code
https://claude.ai/code/session_01WStEFektfHt5AEbK6Wupac
xcl nvprofileputs xcl.exe in an NVIDIA profile with a bigger shader heap (#2403) #2590@DavidM1911 on GitHub · 2026-11-25 21:54 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@pvfreis on GitHub · 2026-11-25 21:58 UTC · original
By reading only, at
5b59fe4(not run). Three points before the long direct-path run:XCL_DIRECT_DXIL=1; your run had=0):countsees piece 0 only.dispatch_chain::RECORDINGSkeeps piece 0 and the chain untilReset, so afterlet_go_donea release can free nothing, and the next bind builds a second set.let_go_donechecks, then removes, with no lock across. If another thread records onain between, its references go too; a pass over a second later can free a pipeline still in flight. Checking and removing under one lock closes it.list_x::splitwithout an idle spare makes a listalloc_pooldoes not know:boundgets 0, which is never reset, so they stay inin_recordings(), also after the title releases them. #2333 (a7b93a8) registers the segment and merges cleanly with this.AI use: Claude Code (Claude Opus 5.5) found this; a second Claude Opus 5.5 re-derived it; Claude Fable 5.2 reviewed the text; checked by a person before posting.
@veyn-sudo on GitHub · 2026-11-25 22:11 UTC · original
Thanks, checked against the code: all three are right. 2 is a real race, and I'm fixing it here by checking and removing under one lock. 1 and 3 I'm fixing too; until then please don't read results on
5b59fe4as final, and run it withXCL_DIRECT_SPLIT_INSTRUCTIONS=0. 2 can free a pipeline that is still in flight.AI use: Claude Code (Claude Opus 5.5) wrote this.
@veyn-sudo on GitHub · 2026-11-25 22:36 UTC · original
1 and 2 are fixed in the new head. For 3 I was too quick: #2333 already fixes the split segments, so I'm not duplicating it here, and the two conflict in
dispatch_chain.rs. Until it is in, those pipelines stay: in one run here 62 of 524 bound pipelines were only under allocator 0.AI use: Claude Code (Claude Opus 5.5) wrote this.
@SlopTart on GitHub · 2026-11-25 23:07 UTC · original
Tested: current PR head merged onto current
origin/main(clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo targetx86_64-pc-windows-gnurun under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).gpu_suite (cold cache): 164 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.Targeted run of the compute-pipeline lifetime tests (
a_pipeline_is_forgotten_before_its_address_is_free,an_unused_compute_pipeline_is_released_and_built_again,the_longest_unused_go_first_and_only_as_many_as_it_takes,a_bound_pipeline_lives_until_its_allocator_is_reset,a_chains_recordings_let_go_of_every_piece): 5 passed.Not tested: retail titles (no title data on this lane, counts only).
AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
@KDenKC on GitHub · 2026-11-26 00:22 UTC · original
@veyn-sudo, results for this PR at four budgets on the retail title, using its own count line (you asked @Pipodi for counter runs in #2403; these bracket your NVIDIA default of 320): the removal at world start still comes in every arm, while the count is at or under ~370 MB. Results from one RTX 5090.
Setup
db0e838=main08db802+ #684e56dbc3+ #2333a7b93a85+ #2404809da30+ #25266d19dc0+ #25513567b2e. It includes a local merge resolution: #2333 and #2404 conflict inreal/dispatch_chain.rs, and #2526 conflicts in appended tests. The resolution keeps both sides and was reviewed by a second person before the build. #2551 is in so the title reaches its world within the run: without it, cold whole forms of split programs hold it before world start.--used-only), graphics mostly warm.XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_PSO_TRACE=1 XCL_NETWORK=0plusXCL_SHADER_CODE_MB, 200 s per arm, the same scripted input, no driver profile changes.Results
XCL_SHADER_CODE_MB0x887a0005)In every arm the world's work starts at ~126 s (200–770 draws and 2,000–8,000 dispatches per 2 s, 0–3 presents), and the device is removed 8–12 s later. No GPU-wait timeouts and no skipped draws in any arm; 0–128 skipped dispatches.
Observations
GetCachedBlobsizes, about 1/9 under what the code takes in the heap, and it covers lazily built pipelines. Graphics are counted but never released. Not counted: pipelines built in the call (outsidepso_async), stand-ins, and the driver's own code. (@Jonas-automated measured about 80 MB of the heap going to the driver's background work on a 4090: #2403.) So 340–370 MB counted is roughly 380–415 MB in the heap before those.Possible next steps (not tested):
pso_async(and stand-ins) toward the limit.Not measured: the graphics/compute split of the count at the removal; how many released pipelines were rebuilt; frame times; a second run of each arm (they ran once, in the order 0, 340, 370, 250, under one exe name, so NVIDIA's own cache warmed across arms); any other GPU or driver; the larger shader-heap driver setting.
Thanks to SlopTart for the RADV/Wine lifetime results (#2526), and for your correction on the pool race and split-tail accounting (#2526), which made this head the one to run.
AI use: Claude Code (Claude Opus 5.5) built the tree, ran the arms, measured the logs and wrote this comment.
@DavidM1911 on GitHub · 2026-11-26 01:36 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
@itsSio on GitHub · 2026-11-26 03:24 UTC · original
Independent dual-PC NVIDIA full-workspace test report on clean head
6d19dc04d80f4f502de54d8aa6c1f714fb8c10d7.Tested
32.0.16.1088), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11 Pro build 26200.9974,rustc 1.97.0(stable-x86_64-pc-windows-msvc), DXC1.9.2609.5, debug buildcargo build --workspace: exit 0 (1 warning)cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture: 1428 passed, 0 failed, 46 ignored (shader_code,pso_async::used_tests,dispatch_chain::tests, andfallback_stream_testsall passed)SKIPPED: 26 (wave64-only GPU tests,#1426wave32 f16/cvt refusals, no heap windows,pso_measurementdriver-cache disable0x887A002D)32.0.16.1088), AMD Ryzen 5 5600X, 16 GB RAM, Windows 11 Pro build 26200.8653,rustc 1.99.1(stable-x86_64-pc-windows-msvc), Windows SDK 10.0.26100 DXC1.8.2502.11, debug buildcargo build --workspace: exit 0 (3 warnings)cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture: 1428 passed, 0 failed, 46 ignoredSKIPPED: 29 (same 26 as Machine 1 plus 3 requiringd3d12SDKLayers.dll)Not tested
scripts/smoke.ps1runs--release)AI use
Ran via Samaritan:
@pvfreis on GitHub · 2026-11-26 04:25 UTC · original
@veyn-sudo a data point for "Graphics code counts but stays", and for the graphics share KDenKC raised above: on an RTX 3060, graphics and mesh pipelines fill the same shader-code reserve as compute, at about their blob size.
Tested
--test-threads=4, NVIDIA 32-lane waves only. One run per mode,mainb49be183(this PR's code is not involved).shader_code_limit.rsfrom #2403 with three modes added, each mode in its own process: unique synthetic programs of 500 statements, each used once and kept until the device is removed. Compute gets one dispatch each. Graphics get a unique VS + PS (the 500 statements are in the PS) and one draw covering a 4x4 offscreen target. Mesh gets the 500 statements in a one-thread mesh shader that outputs a full-screen triangle, a small unique PS, and oneDispatchMesheach. Mixed alternates compute and graphics.GetCachedBlobsizes, summed up to the removal (MB = 10^6 bytes):0x887a0005, and no pipeline failed to create. Compute alone matches #2403's 446–449 (the test's "MB" is>> 20).pso_async.rs:1143) is right, and graphics that stay take room from the same reserve: when they hold much of it, releasing compute alone can't keep the sum under it.if n != 0,pso_async.rs:1192-1195), so a run that releases nothing shows no count. Printing the split there also whenn == 0would show in title runs how much of the reserve graphics and mesh hold.(Posted here only; the limit data itself is the #2403 test's.)
Not tested: whether the title's own mix of programs behaves like these synthetic ones; whether the driver's background code and the heap-to-blob overhead apply to graphics the same way, amplification shaders, other GPUs and drivers, a larger reserve from a driver profile, a title run, this PR's code.
AI use: Claude Code. Claude Opus 5.5 wrote the three modes, ran them and wrote this; Claude Fable 5.2 rechecked it.
@KDenKC on GitHub · 2026-11-26 06:06 UTC · original
Source review of head
6d19dc04, no run. I found one gap in how deferred dispatches keep their pipeline alive.list_x::record_deferred(aroundlist_x.rs:2716) records each deferred dispatch on its own segment withbind::dispatch/bind::execute_indirect. Those resolve throughpso_async::resolve_wait, which callsPending::take, whichholds aRef. The segment is then closed, but nothing in that loop callsshader_code::bound/bound_onfor the segment's allocator, the waysplitdoes. So the reference stays in the thread'sHELD:HELD_MAX(4) distinct pipelines in one submission's deferred dispatches, the earlierRefs are popped and dropped right away.Resetdrops them.After that, only
Pending.realholds the pipeline, and it is not inin_recordings(). Onceused() > limit()and 1 s has passed since its lastresolve(note_use), the nextrelease_unusedcan release it while the segment may still be executing. This is the cold path: a pipeline still building atSetPipelineState(stand-in, nothing held), built by the submit. World load is also when the code budget is over and a submission can take more than a second.A
shader_code::bound_on(<the segment's allocator>)after the dispatch inrecord_deferredwould tie the references to the segment. The inlinebind::dispatch/execute_indirectandconsole_list::closetake the sameresolve_waitpath without abound. Those are usually drained by the next bind on the same list, so the deferred loop is the main window.Not tested: we have not run this head. This is from reading the source only.
AI use: Gemini (Antigravity) flagged it in a first-pass review. Claude Code (Claude Opus 5.5) traced the path in the source at
6d19dc04and wrote this.6d19dc04d8to0fd22d04dc@veyn-sudo on GitHub · 2026-11-26 08:42 UTC · original
@KDenKC thanks for both.
The review point was right:
record_deferredresets each segment with the PCResetdirectly, not throughcl_reset, so nothing calledshader_code::boundfor it and the references stayed with the thread. Fixed in0fd22d04:shader_code::bound(seg)after the dispatch ties them to the segment's allocator. The new testa_deferred_dispatch_keeps_its_pipeline_with_its_segmentfails without it ("held by the segment's recording") and passes with it. The head is rebased ontomainb49be183; the suite and both smoke runs are in the description.Your budget runs match what I measured on a 2070 SUPER: in the world the code in use is the working set (~435 MB at the removal, all of it used within the last 2 s), so releasing what is idle cannot keep it under the heap. This PR stays useful for idle code, but on its own it does not prevent the removal at world start.
AI use: Claude Code (Claude Opus 5.5) checked the path, wrote the fix and the test, ran them on my PC and wrote this.
@CryingLaughing on GitHub · 2026-11-26 11:05 UTC · original
Focused RTX 4080 readback on exact head
0fd22d04dc7931066a8560fe178119a2040d0da9with a local test-only overlay onpso_async::used_tests::an_unused_compute_pipeline_is_released_and_built_again.The first one-group compute dispatch wrote
0x13579bdfto a UAV. After allocator reset released the recording reference, idle reclamation cleared the real PSO. The next dispatch rebuilt it (build count 1 → 2) and wrote0x89abcdefto the same UAV. Both values were read back after their submission fences. Different values verify that the command recorded after the rebuild ran on the GPU.Tested
XCL_ADAPTER=4080. Test overlay diff SHA-256ddf8fee788507a89d8481bbe53638f9bd5d042d9270bfe40a193dcd02e1ebfcb.cargo test -p xcl --lib --locked -j 4 --no-run --message-format=json, then the test executable withhle::d3d12x::pso_async::used_tests::an_unused_compute_pipeline_is_released_and_built_again --exact --test-threads=1 --nocapture. 1 passed, 0 failed, 0 ignored, 0 capability skips.The synthetic test forces idle reclamation on a small pipeline. Retail workloads, driver shader-code capacity, and the workspace suite with this overlay remain untested.
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.