GPU: pipelines of different names load from the library at the same time #1000

Manually merged
github merged 1 commit from gh-pr/1000/head into gh-pr/1000/base 2026-11-26 04:16:37 +00:00
Owner

@⁠TG0000 on GitHub · 2026-11-24 14:48 UTC · original
TG0000:perf/parallel-pipeline-loads → main · +230 −7 · 1 files · 1 commits · merged 2026-11-25 00:09 UTC

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 in make::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:

main this PR
Worker CPU while a backlog is made 1.05 cores 7.8 cores
Worker samples blocked on the lock 481 0
Pipelines still being made, in the world 1,315 / 1,219 54 / 43
Draws run per frame 3 / 20 1,860 / 2,086
Time per frame outside preparing, GPU and copy-back 303 / 196 ms 37 / 24 ms
Total time per frame 799 / 750 ms 1,090 / 1,379 ms

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-copies for 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; that make::wait is 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 --locked 345 passed, 0 failed, including a GPU test with 8 threads loading while others store and serialise; cargo clippy --workspace --all-targets --locked -- -D warnings clean with and without --all-features. Not tested: NVIDIA, Intel, Wine.

Overlap

  • #275 conflicts in library.rs (saves and the wait budget); the ideas are complementary.
  • #72, #347, #352 and #640 edit the same area and merge cleanly. #546 changes the order pipelines are made in.

AI-assisted: written and measured by Claude Opus 5.5. No game data is in this PR.

🤖 Generated with Claude Code

**@⁠TG0000** on GitHub · 2026-11-24 14:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1000) `TG0000:perf/parallel-pipeline-loads` → `main` · +230 −7 · 1 files · 1 commits · merged 2026-11-25 00:09 UTC ## 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 in `make::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](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12device1-createpipelinelibrary). 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: | | main | this PR | |---|---|---| | Worker CPU while a backlog is made | 1.05 cores | 7.8 cores | | Worker samples blocked on the lock | 481 | 0 | | Pipelines still being made, in the world | 1,315 / 1,219 | 54 / 43 | | Draws run per frame | 3 / 20 | 1,860 / 2,086 | | Time per frame outside preparing, GPU and copy-back | 303 / 196 ms | 37 / 24 ms | | **Total time per frame** | **799 / 750 ms** | **1,090 / 1,379 ms** | **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-copies` for 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; that `make::wait` is 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 --locked` 345 passed, 0 failed, including a GPU test with 8 threads loading while others store and serialise; `cargo clippy --workspace --all-targets --locked -- -D warnings` clean with and without `--all-features`. Not tested: NVIDIA, Intel, Wine. ## Overlap - #275 conflicts in `library.rs` (saves and the wait budget); the ideas are complementary. - #72, #347, #352 and #640 edit the same area and merge cleanly. #546 changes the order pipelines are made in. AI-assisted: written and measured by Claude Opus 5.5. No game data is in this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:16:35 +00:00
github manually merged commit f821cb9d75 into gh-pr/1000/base 2026-11-26 04:16:37 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 15:02 UTC · original

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.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 15:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1000#issuecomment-7135368116) 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.
Author
Owner

@⁠ThomasHFWright on GitHub · 2026-11-24 15:07 UTC · original

Independent NVIDIA/Wine validation of f821cb9d7550180d7fb1bd8f7318174e3a680041, based on ffe310e. This covers compatibility/correctness of the tests, not the performance improvement measured on AMD.

Environment: Linux, RTX 5090 / NVIDIA 620.73.04, Wine 11.22, vkd3d-proton 30b0eb9bc12dc9f, DXVK dxgi, Rust 1.98.1, x86_64-pc-windows-msvc. An app-local native d3dcompiler_47.dll from an existing Winetricks cache was supplied identically to both full-suite configurations so the synthetic HLSL fixtures could compile. All executions were offline under Xvfb.

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 a_rejected_blob_gives_an_empty_library and pipelines_load_on_many_threads_at_once fail opening the empty library. Applying #347 (197c7acf) makes all five library tests pass. In that focused run I changed the no-device/no-compiler returns into assertions and printed the compiled shader count: all 96 synthetic shaders compiled, so the concurrency test actually ran. That test-only instrumentation was removed before the full suite.

Full workspace unit/integration suite, built with cargo test --workspace --all-features --locked --offline --target x86_64-pc-windows-msvc --no-run, then all 14 generated test executables run under Wine with --nocapture --test-threads=1:

Configuration Passed Failed Ignored
Unmodified ffe310e 341 5 6
ffe310e + #1000 + #347 345 4 6

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 modules::net::tests::only_loopback_is_reachable (missing Wine Winsock export), loads_binds_and_calls_probe (nested Linux Cargo from a Windows process), emit::tests::stub_pipeline_is_created (checksum-rejection expectation differs under vkd3d-proton), and policy::tests::repository_passes_policy (Windows xtask cannot launch host Git). cargo test -p xtask separately passes all four tests natively on Linux, and asset policy passes. Windows-target GPU Clippy with all targets/features and -D warnings also passes.

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.

**@⁠ThomasHFWright** on GitHub · 2026-11-24 15:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/1000#issuecomment-7135492577) Independent NVIDIA/Wine validation of `f821cb9d7550180d7fb1bd8f7318174e3a680041`, based on `ffe310e`. This covers compatibility/correctness of the tests, not the performance improvement measured on AMD. Environment: Linux, RTX 5090 / NVIDIA 620.73.04, Wine 11.22, vkd3d-proton `30b0eb9bc12dc9f`, DXVK dxgi, Rust 1.98.1, `x86_64-pc-windows-msvc`. An app-local native `d3dcompiler_47.dll` from an existing Winetricks cache was supplied identically to both full-suite configurations so the synthetic HLSL fixtures could compile. All executions were offline under Xvfb. **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 `a_rejected_blob_gives_an_empty_library` and `pipelines_load_on_many_threads_at_once` fail opening the empty library. Applying #347 (`197c7acf`) makes all five library tests pass. In that focused run I changed the no-device/no-compiler returns into assertions and printed the compiled shader count: all 96 synthetic shaders compiled, so the concurrency test actually ran. That test-only instrumentation was removed before the full suite. Full workspace unit/integration suite, built with `cargo test --workspace --all-features --locked --offline --target x86_64-pc-windows-msvc --no-run`, then all 14 generated test executables run under Wine with `--nocapture --test-threads=1`: | Configuration | Passed | Failed | Ignored | | --- | ---: | ---: | ---: | | Unmodified `ffe310e` | 341 | 5 | 6 | | `ffe310e` + #1000 + #347 | 345 | 4 | 6 | 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 `modules::net::tests::only_loopback_is_reachable` (missing Wine Winsock export), `loads_binds_and_calls_probe` (nested Linux Cargo from a Windows process), `emit::tests::stub_pipeline_is_created` (checksum-rejection expectation differs under vkd3d-proton), and `policy::tests::repository_passes_policy` (Windows `xtask` cannot launch host Git). `cargo test -p xtask` separately passes all four tests natively on Linux, and asset policy passes. Windows-target GPU Clippy with all targets/features and `-D warnings` also passes. 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.
Author
Owner

@⁠TG0000 on GitHub · 2026-11-24 15:07 UTC · original

Thanks for both runs. So on vkd3d-proton the library tests need #347 or #844 (opening an empty host library); that failure is in code this PR does not change, so I leave it to those PRs.

**@⁠TG0000** on GitHub · 2026-11-24 15:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/1000#issuecomment-7135506698) Thanks for both runs. So on vkd3d-proton the library tests need #347 or #844 (opening an empty host library); that failure is in code this PR does not change, so I leave it to those PRs.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:12 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at f821cb9: cargo test -p victory-gpu passes, 53 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 15:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1000#issuecomment-7135647945) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at f821cb9: `cargo test -p victory-gpu` passes, 53 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠TG0000 on GitHub · 2026-11-24 15:15 UTC · original

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.

**@⁠TG0000** on GitHub · 2026-11-24 15:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/1000#issuecomment-7135725921) 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.
Author
Owner

@⁠TG0000 on GitHub · 2026-11-24 16:30 UTC · original

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 D3DCompile), and the order "stored before _held drops" deserves a line in the comment. I will add them with the next change this branch needs, so that your test run stays valid for the current head.

AI-assisted (Claude Code).

**@⁠TG0000** on GitHub · 2026-11-24 16:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1000#issuecomment-7137783976) 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 `D3DCompile`), and the order "stored before `_held` drops" deserves a line in the comment. I will add them with the next change this branch needs, so that your test run stays valid for the current head. _AI-assisted (Claude Code)._
Author
Owner

@⁠TG0000 on GitHub · 2026-11-24 18:00 UTC · original

Thanks for measuring it directly under Wine and vkd3d-proton: the time inside LoadPipeline and the wait for the lock are the part I could not measure here (Windows, RX 6800 only).

**@⁠TG0000** on GitHub · 2026-11-24 18:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1000#issuecomment-7140023893) Thanks for measuring it directly under Wine and vkd3d-proton: the time inside `LoadPipeline` and the wait for the lock are the part I could not measure here (Windows, RX 6800 only).
Author
Owner

@⁠Mumogg on GitHub · 2026-11-24 17:57 UTC · original · edited 2026-11-24 19:08 UTC

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 integration/testers update 9 (94e0ea5) plus small local changes; diagnostics build; 1.0.2.1, network off. Same warm cache directory for every run (1,167 pipelines listed for an early start, library file 270 kB, so about 190 bytes per pipeline: vkd3d-proton compiles inside the load as well).

Before, measured directly. With a timer around the lock and the load in library::pipeline(), one 300 s warm run:

loads completed 280 (all found in the library)
time inside LoadPipeline, summed 298 s of the 300 s run
time waiting for the library's lock, summed over workers 1,149 s
longest single load / longest wait for the lock 12.3 s / 45.6 s

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 (f821cb9, merged into that tree; the only conflict was the use std::sync line): all 1,620 early pipelines were loaded 101 s after start (host pipelines all made made=0 loaded=1621 started_early=1620), no device removal, no error from the library in three runs with concurrent loads. That last run also had a two-level queue (see my note on #546), so the 101 s is not this PR alone.

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).

**@⁠Mumogg** on GitHub · 2026-11-24 17:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/1000#issuecomment-7139945626) · edited 2026-11-24 19:08 UTC 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 `integration/testers` update 9 (`94e0ea5`) plus small local changes; diagnostics build; 1.0.2.1, network off. Same warm cache directory for every run (1,167 pipelines listed for an early start, library file 270 kB, so about 190 bytes per pipeline: vkd3d-proton compiles inside the load as well). **Before, measured directly.** With a timer around the lock and the load in `library::pipeline()`, one 300 s warm run: | | | |---|---| | loads completed | 280 (all found in the library) | | time inside `LoadPipeline`, summed | 298 s of the 300 s run | | time waiting for the library's lock, summed over workers | 1,149 s | | longest single load / longest wait for the lock | 12.3 s / 45.6 s | 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 (`f821cb9`, merged into that tree; the only conflict was the `use std::sync` line): all 1,620 early pipelines were loaded 101 s after start (`host pipelines all made made=0 loaded=1621 started_early=1620`), no device removal, no error from the library in three runs with concurrent loads. That last run also had a two-level queue (see my note on #546), so the 101 s is not this PR alone. 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).*
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1000
No description provided.