D3D12.X: boost low-priority preload PSO workers on demand and priorit… #1007
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!1007
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1007/head"
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?
@zondy1i on GitHub · 2026-11-24 10:20 UTC · original
zondy1i:d3d12x/pso-priority-inheritance→main· +421 −17 · 2 files · 1 commits · closed without mergingFixes a priority-inversion bottleneck in
pso_async+BIG_COMPILES(related to #675 / #505):xcl-pso-pre-0..3) run atTHREAD_PRIORITY_LOWESTon native Windows so speculative ahead-of-use compiles fromused-pipelines.txtstay out of the title's way.job, a later demand bind (resolve/resolve_wait) cannot run the job itself and must wait on thatTHREAD_PRIORITY_LOWESTworker. Worse,translated_compute_psoroutes both demand (xcl-pso-*) and preload (xcl-pso-pre-*) big compiles (>= 256 KiBDXIL) through the singleBIG_COMPILESslot (most = 1) in FIFO order: aTHREAD_PRIORITY_LOWESTpreload worker holdingBIG_COMPILESunder world-load CPU contention can stretch a ~25 s driver compile to ~90–100 s while starving demand-bound compute compiles behind it.This adds refcounted priority inheritance (
BoostToken) for preload workers and demand-first admission onBIG_COMPILESwithout skipping any compute dispatches:resolve,resolve_wait, orresolve_withinneeds a pipeline already owned by axcl-pso-pre-*worker, that worker is boosted toTHREAD_PRIORITY_NORMALuntil the build completes (and woken if queued onBIG_COMPILES).BIG_COMPILES, demand compiles (xcl-pso-*or a demand-promoted preload worker) always enter ahead of queued speculative preload workers, and anyTHREAD_PRIORITY_LOWESTpreload worker currently holding a slot is boosted toTHREAD_PRIORITY_NORMALuntil it releases the slot.BoostGuardrestoresTHREAD_PRIORITY_LOWEST.crate::util::under_wine()), lowering priority toTHREAD_PRIORITY_LOWESTmaps to raising Linuxnice(always allowed), while raising it back toNORMALrequiresRLIMIT_NICE/CAP_SYS_NICEand fails for a normal user. When running under Wine, preload workers stay atTHREAD_PRIORITY_NORMALandSetThreadPrioritycalls are skipped, whileBoostTokenrefcounting andBIG_COMPILESdemand-first admission remain active (thank you @sander110419 for testing and reporting this on GE-Proton).What is in it
crates/xcl/src/hle/d3d12x/pso_async.rs: addcan_lower_preload_priority()(!crate::util::under_wine()),BoostToken/BoostGuard(refcountedOpenThread(THREAD_SET_LIMITED_INFORMATION)+SetThreadPriority), thread-local preload token registration,Pending::promote_preload()inresolve,resolve_wait, andresolve_within, and unit tests (boost_token_refcounts_nested_guards,resolve_wait_boosts_preload_worker_priority_and_restores_it).crates/xcl/src/hle/d3d12x/real.rs: updateSlots(BIG_COMPILES) to trackdemand_waitingand activepreload_holders, boost holders on demand arrival, wake all waiters on release (notify_all), exposenotify_big_compiles()for promoted waiters, and add unit testbig_compile_slots_boost_preload_holder_and_run_demand_first.Tested
x86_64-pc-windows-msvc), debug + release.cargo test --workspace -- --test-threads=1: 740 passed, 0 failed, 41 ignored (1 SKIPPED GPU test:gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64)). All three new tests ran and passed (boost_token_refcounts_nested_guards,resolve_wait_boosts_preload_worker_priority_and_restores_it,big_compile_slots_boost_preload_holder_and_run_demand_first).Regression run
(local folder name redacted to
retail-titlein both blocks; all metrics are exact output of the 60 s runs withXCL_NETWORK=0)main:
PR:
Not tested
under_wine()path (verified by code inspection and native Windows test run; awaiting re-test on Wine/Proton).BIG_COMPILES(most > 1is supported structurally bypreload_holders: Vec<_>, thoughBIG_COMPILESstaysmost = 1here).AI use
pso_async.rs/real.rs, wrote the implementation, Wine fallback, unit tests, and PR description; all tests and paired smoke runs were executed locally on the hardware above and the diff was reviewed line by line.@sander110419 on GitHub · 2026-11-24 10:37 UTC · original
A note from Linux (Wine), in case it matters for the design. The boost does not take effect there.
cargo testof this PR merged into a local Wine branch (GE-Proton11-11, NVIDIA RTX 5070 Laptop, release toolchainx86_64-pc-windows-gnu): 5 of 7pso_asynctests pass. The two new priority tests fail:Wine applies thread priorities as Linux nice values. Lowering a priority (
THREAD_PRIORITY_LOWEST) is always allowed. Raising it again needsRLIMIT_NICE/CAP_SYS_NICE, which a normal desktop user does not have (ulimit -eis 0 here). SoSetThreadPriority(NORMAL)on a worker that went to LOWEST fails, and the worker stays at the low priority for the rest of the run. The demand-first ordering inBIG_COMPILESshould still work, since it does not depend on priorities. Only the inheritance part is lost.Two possible ways around it, untested: under Wine (
wine_get_versionpresent in ntdll), leave the preload workers at NORMAL and rely on the admission order; or let a demand bind take the job itself when the preload worker has not started the driver compile yet.The game was not run with this PR yet; only the unit tests above.
AI use: Hermes agent with Claude Opus 5.5 (
claude-opus-5-5) ran the build and the tests, and wrote this note; I checked it.@zondy1i on GitHub · 2026-11-24 11:01 UTC · original
Thanks for testing this on Wine/GE-Proton and catching the
SetThreadPriority/RLIMIT_NICEissue!Updated the PR (rebased on
384f7f7) usingcrate::util::under_wine():xcl-pso-pre-*workers stay atTHREAD_PRIORITY_NORMALandSetThreadPrioritycalls are skipped, whileBoostTokenrefcounting (is_boosted()) andBIG_COMPILESdemand-first admission remain active.promote_preload()into the newresolve_within()path from #891.boost_token_refcounts_nested_guards,resolve_wait_boosts_preload_worker_priority_and_restores_it, andbig_compile_slots_boost_preload_holder_and_run_demand_first) to always verifyis_boosted()and demand-first ordering while only asserting OSLOWEST/NORMALtransitions outside Wine.@SlopTart on GitHub · 2026-11-24 11:55 UTC · original
Linux / AMD RDNA3 run: this PR's three new boost tests fail deterministically under Wine.
Merged state: head
ee2e530onto current main, clean merge, full suite 726 passed / 14 failed / 41 ignored; the failures are my known Wine-lane set from #42 plus this rig's mirror flake, and 3 extras that are exactly this PR's new tests, each failing 2/2 in isolation with--test-threads=1:hle::d3d12x::pso_async::used_tests::boost_token_refcounts_nested_guards-assertion left == right failed, left: -2, right: 0atpso_async.rs:500hle::d3d12x::pso_async::used_tests::resolve_wait_boosts_preload_worker_priority_and_restores_it- worker thread asserts atpso_async.rs:527("preload worker must be boosted while resolve_wait waits", left: -2), then the test fails atpso_async.rs:539"preload worker was not boosted to NORMAL" after the 5 s waithle::d3d12x::real::console_format_query_tests::big_compile_slots_boost_preload_holder_and_run_demand_first- same 5 s shapeDiagnosis lead, not a verdict: under Wine the boosted priority lands at -2 instead of NORMAL/0, i.e. the raise looks like it does not map through Wine's
SetThreadPriority/GetThreadPriorityemulation. Worth checking whether the boost is a relative+nfrom the current priority (Wine's notion of current differs from Windows). On native Windows CI these would presumably pass - but heads-up that CI here is description-check-only, so nothing compiles or tests these lanes before merge.Everything else on the merge is green, including the rest of
pso_async.Counts only, no game data.
Not tested: retail titles (none here), Windows, RDNA4.
Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross
x86_64-pc-windows-gnu,XCL_NETWORK=0, release profile,--test-threads=4. My Linux rows: #42 / #718.AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
@zondy1i on GitHub · 2026-11-24 12:06 UTC · original
Thanks for testing on Linux/Wine! From the line numbers (
pso_async.rs:500/527/539) it looks like that run merged the earlier commit (aceb50e) before the Wine fix landed in4b3f440.In
4b3f440(current PR head),can_lower_preload_priority()checkscrate::util::under_wine()so preload workers stay atTHREAD_PRIORITY_NORMALunder Wine and skipSetThreadPriority, while all three unit tests (boost_token_refcounts_nested_guards,resolve_wait_boosts_preload_worker_priority_and_restores_it,big_compile_slots_boost_preload_holder_and_run_demand_first) assertis_boosted()andBIG_COMPILESdemand-first ordering unconditionally and only assert OSLOWEST/NORMALtransitions outside Wine. Feel free to re-run against4b3f440if you get a chance!@DavidM1911 on GitHub · 2026-11-24 12:33 UTC · original
Independent verification, merged onto current
main384f7f7locally (clean merge).Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.
cargo test -p xcl --lib pso: 22 passed, 0 failed, 1 ignored (compile-time bench) — includes the newresolve_wait_boosts_preload_worker_priority_and_restores_itandboost_token_refcounts_nested_guards, covering the on-demand worker boost and its restoration.AI use: test runs by Devin (Cognition, SWE-2); no code changes.
@SlopTart on GitHub · 2026-11-24 12:44 UTC · original
Fix verification from the Wine/RDNA3 lane: re-merged the updated head
4b3f440onto current main and re-ran the three tests that failed 2/2 for me atee2e530(my 12:04 comment, theGetThreadPriority returns -2ones).All three now pass in isolation (
--test-threads=1):boost_token_refcounts_nested_guards- okresolve_wait_boosts_preload_worker_priority_and_restores_it- okbig_compile_slots_boost_preload_holder_and_run_demand_first- okThe
under_wine()guard (preload workers stay NORMAL andSetThreadPriorityis skipped under Wine, whileBoostTokenrefcounting and demand-first admission still get asserted) resolves the failures on this rig exactly as the diagnosis predicted. Verified merged state: lane merge at4fab701, release profile.Counts only, no game data.
Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross
x86_64-pc-windows-gnu,XCL_NETWORK=0, release profile. My Linux rows: #42 / #718.AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
@zondy1i on GitHub · 2026-11-24 14:06 UTC · original
Superseded by commit
25c6f7eonmain(D3D12.X: a big pipeline build the title waits for does not wait for its turn), which addresses both preload worker priority elevation on demand and bypassing theBIG_COMPILESslot / commit wait.Closing this PR — thanks to everyone who tested and reviewed!
@Royalflamejlh on GitHub · 2026-11-24 14:52 UTC · original
Linux (Wine + vkd3d-proton) + NVIDIA test of
4b3f440and of the head before it,aceb50e, 3 runs of 100 s each: under Wine neither changes the crawl that the preload of #690 causes here. The title's burst of pipeline creation after its loading screen starts stayed slow in 6 of 6 runs, as onmain, and with4b3f440it was slower than onmain.Setup: Fedora 44 (kernel 7.2.9), Wine 11.21 Staging (Wayland driver), vkd3d-proton 3.1 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 tox86_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 throughXCL_PRESS_AT.used-pipelines.txtheld 1,131 shader sets from earlier runs that had reached the world load.aceb50ewas merged ontomain384f7f7(no conflicts);4b3f440is on384f7f7itself. Since25c6f7e("a big pipeline build the title waits for does not wait for its turn") went intomain, this pull request conflicts with it inpso_async.rsandreal.rs.Tested
cargo test --release -p xcl --libforboostandbig_compile_slotsunder Wine, on4b3f440: 3 passed, 0 failed. These are the tests a Linux tester reported failing onaceb50e.main67a3735/384f7f7/384f7f7aceb50e, run 1 / 2 / 34b3f440, run 1 / 2 / 367a3735+ #688, run 1 / 2 / 3[SHADER]lines from 60 s to 80 sA slow run presents more frames because it stays on the loading pictures at 29 fps. A normal run makes about 10,465 of those lines in that window and then thins out as the world loads.
Read
mainbeaa245+ #684) five title threads indev_create_pipeline_stateand the DXC thread compiling for a preload worker all wait inRtlEnterCriticalSectionunderRtlAllocateHeap: Wine's process heap has one lock for these sizes, and DXC allocates from it for the 23 to 50 s a big compute program takes. #688 gives DXC heaps of its own, and with it the same runs are normal (last column).pso_async.rs:30(can_lower_preload_priority): under Wine4b3f440keeps the preload workers at normal priority. That matches the middle columns: with the workers no longer lowered the burst made 2 lines in the window in each run, against 265 to 533 withaceb50e. So on Wine the lowering was doing a little good, and the reason given for dropping it (the priority cannot be raised back) does not seem to cost anything here, because nothing in these runs was waiting on a boost. Would it be worth keeping the workers lowered under Wine and skipping only the boost?Not tested: the demand-first order of
BIG_COMPILES(no run got to a big compile wanted by a bind); past 100 s; native Windows, where the priorities do what this change expects; the rest of the test suite; AMD and Intel.AI use: Claude Code (Claude Fable 5.2) read both diffs, built the trees, ran the title with
XCL_PRESS_AT, took the thread dumps, compared the logs and wrote this report.@DavidM1911 on GitHub · 2026-11-26 03:32 UTC · original
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.Pull request closed