Repository navigation
GPU: pipelines of different names load from the library at the same time - #1000
Conversation
The pipeline workers held the library's lock while a pipeline loaded. A load is not always a lookup: an AMD driver's library holds about 140 bytes per pipeline, and what the driver's own cache lacks is compiled inside the load, for up to seconds. All eight workers then waited for the one that held the lock. The library is documented as thread-safe but for loads of one pipeline on several threads (ID3D12Device1::CreatePipelineLibrary, "Thread Safety"), so only those exclude each other now: a name is held by one thread at a time, and loads run without the library's lock. Stores and serialising keep it. Measured on an RX 6800 and a Ryzen 9 5900X (sampled stacks, diagnostics build, the same start from a kept pipeline library): - worker CPU while a backlog is made: 1.05 cores -> 7.8; samples blocked on the lock: 481 -> 0 - in the world, two runs each: pipelines still being made 1219-1315 -> 43-54, draws run per frame 3-20 -> 1860-2086, time per frame outside preparing, GPU and copy-back 196-303 ms -> 24-37 ms The frame itself is not shorter on its own: the draws that used to be dropped now run (750-799 -> 1090-1379 ms per frame). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
On an RTX 4090 under Wine/vkd3d-proton 3.2, all five focused library tests passed with f821cb9 plus #844’s null-pointer fix for opening an empty host library. The 96-pipeline fixture exercised the host D3D12 library directly, with concurrent loads of distinct names while other threads stored and serialized. The separate name-gate tests verified that different names can proceed together and callers for the same name take turns. We also integrated #983’s early-pipeline list changes. All seven library tests passed. In a separate test using VIctory’s save API, saving before first use preserved both legacy keys, and the next save promoted the newly used pipeline. The first run of that fixture hit an existing temporary directory after Wine reused a process ID. It passed after switching to a unique directory. These runs verify library behavior on Wine. We did not measure worker backlog, frame time, or title output on the RTX 4090. |
|
Independent NVIDIA/Wine validation of Environment: Linux, RTX 5090 / NVIDIA 620.73.04, Wine 11.22, vkd3d-proton The empty-library fix in #347 is needed on this runtime. With this PR alone, the focused library suite gives 3 passed / 2 failed: both Full workspace unit/integration suite, built with
The GPU crate improves from 52 passed / 1 failed / 1 ignored to 56 passed / 0 failed / 1 ignored. The three added tests pass, as does the empty-library test fixed by #347. No additional failures appeared. The four failures shared with baseline are Limits: no gameplay or performance measurement; no native Windows or genuine Windows WARP run; doctests were not executed under Wine. Some existing tests return early when optional console compilers or the DXIL validator are absent, so the aggregate is the test harness's result, not a claim those optional paths were exercised. No game data was used or attached. AI-assisted testing with Codex. |
pipeline() held the library mutex across LoadPipeline. On AMD a load can compile for seconds (the library keeps ~140 bytes per pipeline), so 650 pipelines kept the eight workers on one core for minutes while title frames waited. The library is free-threaded except for concurrent loads of one name: hold the name instead (also keeps two threads from making the same pipeline), and keep the lock only for stores and serialising. From upstream PR Marvisak#1000 (f821cb9). Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
|
A correction on the in-game rows. A later warm main / branch / branch / main run of this branch together with #999 did not reproduce the smaller backlog: 528 pipelines still being made on main and 748 on the branch (medians), 522 and 811 draws run, and 1,433 and 1,434 ms per frame. Each side had its own shader cache (509 and 456 entries), and draws differ up to 5x between two runs of the same exe, so that comparison does not settle it either way. Please read "pipelines still being made", "draws run" and the frame times in the table as not reproduced. What stands is the lock itself: the workers blocked on it in the sampled stacks, and the test with concurrent loads. |
mercuryVM
left a comment
There was a problem hiding this comment.
Tested f821cb9 on Windows 11, RTX 5070, MSVC: cargo test -p victory-gpu passes (53 passed, 1 ignored), including the three new tests.
The change is right:
- The D3D12 docs say
ID3D12PipelineLibrarysynchronizes itself internally. The one exception is several threads loading the same pipeline, which may change that entry's state in the library. That exception is exactly whatNames::holdcovers. Different names now overlap, while stores andSerializestay under the library mutex. - The
Heldguard'sDroptakes the set's lock, removes the name and callsnotify_all.one_name_is_held_by_one_thread_at_a_timechecks that a panicking holder releases the name. - Cloning the
ID3D12PipelineLibrary1interface out of the lock is a refcount bump. The blob the library was opened from lives in the samestaticand is never dropped, as the comment says.
Nits:
pipelines_load_on_many_threads_at_oncereturns silently when there is no host GPU or noD3DCompile, so on CI it can pass without testing anything. Aneprintln!on those early returns would make that visible.- Two threads asking for one missing name now compile it twice? No: the second waits in
holdand then finds the first one's stored pipeline. This might be worth one line in the doc comment, since it depends on the store happening before_helddrops. It does today, because_heldlives to the end ofpipeline.
AI-assisted (Claude Code).
|
Thanks for the careful check, also of the same-name exception in the docs. Both nits are fair: the test should say when it is skipped (no host GPU or no AI-assisted (Claude Code). |
…ry at the same time Head f821cb9 (TG0000). Conflicts in pipeline/library.rs: our imports (Arc, mpsc for #275's saver thread) with #1000's Condvar; the load takes #1000's form (the interface cloned out of the lock, a hold per name). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Test report from Linux: this is also what starves a warm start under Wine + vkd3d-proton on NVIDIA, and the PR fixes it here. Setup: RTX 5070 Ti (driver 615.78.08), Ryzen 5 9600X (6 workers), Nobara 44, Wine 11.22 Staging, vkd3d-proton from GE-Proton11-14. Tree: r4tedx Before, measured directly. With a timer around the lock and the load in
So the workers ran strictly one at a time for the whole run. The world's first vertex or mesh pipeline arrived after about 570 s in an earlier 600 s run; a cold cache got 234 mesh and 109 vertex pipelines in its first world minute. After. First with the load moved outside the lock by hand (the interface cloned under the lock, as here): 907 loads in 300 s instead of 280, lock wait 0. Then with this PR's code ( Not tested: AMD, native Windows, a library file from a different driver version. (AI-assisted, Claude Code: it found the lock from the logs, added the timers and ran the comparisons on my machine.) Edit: the Wine version was 11.22 Staging, not 11.21 (the system had updated before these runs). |
|
Thanks for measuring it directly under Wine and vkd3d-proton: the time inside |
…ied together Merges Marvisak#72 Marvisak#347 Marvisak#1000 Marvisak#358 Marvisak#352 Marvisak#626 Marvisak#1152 Marvisak#1129 Marvisak#1203 Marvisak#24 Marvisak#642 Marvisak#427 Marvisak#485 Marvisak#550 Marvisak#174 Marvisak#1279 onto main (ffe310e), each head unchanged, no conflicts. One change of mine: three of the PRs each add a `mod tests` at the end of pipeline/host.rs, so the merge defines `tests` three times (E0428). The second and third are named `library_tests` and `blend_tests`; nothing else changes. cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, is clean and cargo test --workspace --locked passes (367 passed, 6 ignored; main has 342 passed, 6 ignored). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…library at the same time
…library at the same time
…library at the same time
A load still took the library's lock to clone the interface, and a save holds that lock while it serialises the whole library (230-600 MB in the world, Marvisak#1683, Marvisak#1653). Saves run every 20 s while pipelines are being made, some on the pipeline workers themselves, so every load waited out each save: the part of Marvisak#1615 that Marvisak#1000 left. The library is kept a second time beside its lock, and loads use that one without locking. A load adds nothing to the library, so the size a save asks for still holds when it serialises; the library is free-threaded but for loads of one name, which NAMES keeps apart. Stores and saves keep the lock. New test: a stored pipeline loads while the lock is held as a save holds it. With the old locking it times out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
library::pipeline()held the pipeline library's mutex while a pipeline loaded. On AMD a load is not always a lookup: the library file holds only about 140 bytes per pipeline, and what the driver's own cache lacks is compiled inside the load, for up to seconds. All eight pipeline workers then ran as one, and the backlog kept recording threads inmake::wait.Loads now run outside the library's lock, and only same-name pipelines exclude each other. Microsoft documents the library as thread-safe with exactly that exception. Stores and serialising keep the lock. One file:
pipeline/library.rs.Measured (RX 6800, Ryzen 9 5900X, Windows 11, diagnostics build, sampled stacks)
Two runs per side, order main / PR / PR / main:
Frames are not shorter on their own. Main looks faster because it drops almost every draw; here they run and their cost shows.
Caveats: the worker rows use a build on top of the copy changes of
TG0000:perf/world-frame-copiesfor main's side (same lock) and the first run under a new exe name for this PR's side; the driver's cache appears to be per exe, and the second PR run had it warm while main's second run did not, so the first run of each is the stricter comparison. The lock is proven by the stacks; thatmake::waitis the unaccounted time rests on frames pinned at exactly 500 ms, the backlog and the A/B, not on a stack inside it.Verification
Rust 1.98.1 MSVC, base
ffe310e:cargo test --workspace --locked345 passed, 0 failed, including a GPU test with 8 threads loading while others store and serialise;cargo clippy --workspace --all-targets --locked -- -D warningsclean with and without--all-features. Not tested: NVIDIA, Intel, Wine.Overlap
library.rs(saves and the wait budget); the ideas are complementary.AI-assisted: written and measured by Claude Opus 5.5. No game data is in this PR.
🤖 Generated with Claude Code