GPU: pipeline library loads do not wait for a save #2179

Manually merged
github merged 1 commit from gh-pr/2179/head into gh-pr/2179/base 2026-11-26 04:57:34 +00:00
Owner

@⁠winne42 on GitHub · 2026-11-25 07:06 UTC · original
winne42:gpu/library-loads-beside-saves → main · +123 −16 · 1 files · 1 commits · merged 2026-11-25 21:55 UTC

Refs #1615. #1000 took pipeline loads out from under the library's lock, but one part of #1615 is still there.

The problem

library::pipeline() still takes the library's mutex to clone the ID3D12PipelineLibrary1 before every load. save() holds that mutex through GetSerializedSize + Serialize of the whole library, which is 230 MB (#1683) to over 600 MB (#1653) in the world. Saves run every 20 s while new pipelines are being made, and some run on the pipeline workers themselves (make.rs). So for the whole of each save, every load waits, on every worker.

The change

One file, crates/victory-gpu/src/pipeline/library.rs:

  • A second handle to the library (Shared::loads) is kept beside Mutex<Library>, and loads use it without taking any lock.
  • Stores and saves keep the lock, so the size a save asks for still holds when it serialises. A load adds nothing to the library.
  • Per ID3D12Device1::CreatePipelineLibrary ("Thread Safety"), the library is free-threaded except for loads of the same name, which NAMES already keeps apart. The existing pipelines_load_on_many_threads_at_once already runs loads alongside Serialize.

New test a_pipeline_loads_while_a_save_holds_the_library: it stores a pipeline through pipeline(), holds the library's lock the way a save does, and checks that a load of the same pipeline returns within 30 s. It builds its root signature with D3D12SerializeRootSignature and uses a compute shader with no resources, because Wine's d3dcompiler_47 does not embed a [RootSignature] attribute.

This does not touch the save size itself (#1653) or the empty-blob fix for vkd3d-proton (#1722). It merges cleanly with #1722. It conflicts with #1653, which rewrites the same functions into 16 shards, each loaded under its own lock. The same split (a load handle per shard, beside its lock) would carry over there.

Tested

Linux, x86_64-pc-windows-msvc cross-build (lld-link + xwin), run under Wine 10.0 with vkd3d-proton 3.1 and DXVK dxgi from Proton Experimental, on an RTX 3050 Laptop GPU (4 GB). Not run on Windows.

  • With #1722 applied on top (vkd3d-proton refuses main's empty library without it, so library() is None there):
    • cargo test -p victory-gpu --lib pipeline::library: 9 passed.
    • With the old load path put back: the new test fails with the load waited for the save (Err(Timeout)).
  • On this branch alone: the victory-gpu lib suite gives 130 passed, 14 failed and 2 ignored, and main gives 129 / 14 / 2 on the same machine. The 14 failures are the same tests on both, and they fail on main under vkd3d-proton. The extra pass is the new test, which returns early there because there is no library.
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, with and without --all-features: clean.

Side note: under Wine, pipelines_load_on_many_threads_at_once returns at "no shader compiler here", because Wine's compiler fails on its shader. So on Linux hosts it does not run.

No game data was used.

🤖 Generated with Claude Code

**@⁠winne42** on GitHub · 2026-11-25 07:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2179) `winne42:gpu/library-loads-beside-saves` → `main` · +123 −16 · 1 files · 1 commits · merged 2026-11-25 21:55 UTC Refs #1615. #1000 took pipeline loads out from under the library's lock, but one part of #1615 is still there. ## The problem `library::pipeline()` still takes the library's mutex to clone the `ID3D12PipelineLibrary1` before every load. `save()` holds that mutex through `GetSerializedSize` + `Serialize` of the whole library, which is 230 MB (#1683) to over 600 MB (#1653) in the world. Saves run every 20 s while new pipelines are being made, and some run on the pipeline workers themselves (`make.rs`). So for the whole of each save, every load waits, on every worker. ## The change One file, `crates/victory-gpu/src/pipeline/library.rs`: - A second handle to the library (`Shared::loads`) is kept beside `Mutex<Library>`, and loads use it without taking any lock. - Stores and saves keep the lock, so the size a save asks for still holds when it serialises. A load adds nothing to the library. - Per `ID3D12Device1::CreatePipelineLibrary` ("Thread Safety"), the library is free-threaded except for loads of the same name, which `NAMES` already keeps apart. The existing `pipelines_load_on_many_threads_at_once` already runs loads alongside `Serialize`. New test `a_pipeline_loads_while_a_save_holds_the_library`: it stores a pipeline through `pipeline()`, holds the library's lock the way a save does, and checks that a load of the same pipeline returns within 30 s. It builds its root signature with `D3D12SerializeRootSignature` and uses a compute shader with no resources, because Wine's `d3dcompiler_47` does not embed a `[RootSignature]` attribute. This does not touch the save size itself (#1653) or the empty-blob fix for vkd3d-proton (#1722). It merges cleanly with #1722. It conflicts with #1653, which rewrites the same functions into 16 shards, each loaded under its own lock. The same split (a load handle per shard, beside its lock) would carry over there. ## Tested Linux, `x86_64-pc-windows-msvc` cross-build (lld-link + xwin), run under Wine 10.0 with vkd3d-proton 3.1 and DXVK `dxgi` from Proton Experimental, on an RTX 3050 Laptop GPU (4 GB). Not run on Windows. - With #1722 applied on top (vkd3d-proton refuses `main`'s empty library without it, so `library()` is `None` there): - `cargo test -p victory-gpu --lib pipeline::library`: 9 passed. - With the old load path put back: the new test fails with `the load waited for the save` (`Err(Timeout)`). - On this branch alone: the `victory-gpu` lib suite gives 130 passed, 14 failed and 2 ignored, and `main` gives 129 / 14 / 2 on the same machine. The 14 failures are the same tests on both, and they fail on `main` under vkd3d-proton. The extra pass is the new test, which returns early there because there is no library. - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. Side note: under Wine, `pipelines_load_on_many_threads_at_once` returns at "no shader compiler here", because Wine's compiler fails on its shader. So on Linux hosts it does not run. No game data was used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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, #1683, #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 #1615 that #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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:57:33 +00:00
github manually merged commit c8ad2a46f2 into gh-pr/2179/base 2026-11-26 04:57:34 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 07:48 UTC · original

I ran the pipeline-library tests on exact head c8ad2a4 on native Windows with the D3D12 WARP adapter and the diagnostics feature. All nine passed, including the load under a held save mutex and the concurrent load/store/serialize test.

For a negative control I put the old lock acquisition back before the load and made unavailable GPU or FXC support fail explicitly. The new test reached the assertion and failed with “the load waited for the save” after 30 seconds. This establishes that the test exercises contention on the project mutex on WARP. Driver latency during serialization remains unmeasured.

AI-assisted. Synthetic shaders only.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 07:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2179#issuecomment-7156277249) I ran the pipeline-library tests on exact head **c8ad2a4** on native Windows with the D3D12 WARP adapter and the diagnostics feature. All nine passed, including the load under a held save mutex and the concurrent load/store/serialize test. For a negative control I put the old lock acquisition back before the load and made unavailable GPU or FXC support fail explicitly. The new test reached the assertion and failed with “the load waited for the save” after 30 seconds. This establishes that the test exercises contention on the project mutex on WARP. Driver latency during serialization remains unmeasured. AI-assisted. Synthetic shaders only.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 08:50 UTC · original

I also checked the combination with #2129 on native Windows/WARP. The validation merge combines c8ad2a4 with 2ef0c75 and the optional mapped-replacement test f040754. In the mapped save path I kept the staging write and used the mutex on the new Shared state.

Both runs passed 15 pipeline-library tests and skipped one memory measurement, with mapping enabled and with VICTORY_LIBRARY_MAP=0. The same build exercised the held-save-mutex test, concurrent loads and serialization, and loading the original PSOs after replacing the mapped file.

AI-assisted. Synthetic data only.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 08:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2179#issuecomment-7157527583) I also checked the combination with #2129 on native Windows/WARP. The [validation merge](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/cc55b853945500541387b92542e3b925b11b17a2) combines c8ad2a4 with 2ef0c75 and the optional mapped-replacement test f040754. In the mapped save path I kept the staging write and used the mutex on the new Shared state. Both runs passed 15 pipeline-library tests and skipped one memory measurement, with mapping enabled and with VICTORY_LIBRARY_MAP=0. The same build exercised the held-save-mutex test, concurrent loads and serialization, and loading the original PSOs after replacing the mapped file. AI-assisted. Synthetic data only.
Author
Owner

@⁠ntgata1-dotcom on GitHub · 2026-11-25 11:20 UTC · original

RX 9070 XT (RADV) under Wine 11.22: works with #1722 (tests, and menus only)

Setup: Arch Linux, RX 9070 XT (RDNA4), RADV / Mesa 26.3.1. System Wine 11.22. vkd3d-proton v3.1-83-gcae8353ed and DXVK dxgi from GE-Proton11-14. cargo xwin test --locked --target x86_64-pc-windows-msvc --no-fail-fast -p victory-gpu, runner wine.

victory-gpu passed failed
main 940d32f 130 13
this PR c8ad2a4 131 13
this PR + #1722, merged locally 132 12
  • a_pipeline_loads_while_a_save_holds_the_library: without #1722 it returns at its first else here (library() is None under vkd3d-proton), so its "ok" there means it didn't run. With #1722 it runs. A temporary print after the store showed the load returning Ok(true) while the lock was held.
  • With #1722, all 9 pipeline::library tests pass. Outside pipeline::library, no test changes against main. With #2195 merged as well, the results are the same.
  • Title menus only, release build of this PR + #1722, two 150 s runs on one cache folder. Run 1 saves up to bytes=1208 early=6 made=6, and run 2 loads it: made=0 loaded=6 started_early=6. Both run at 30.0 fps after start-up, with no crashes.log and no amdgpu messages in the kernel log during the runs. With 6 pipelines and 1.2 KB saves, the menus can't show the load/save contention itself; that needs the world.

Not run: Windows, the world.

AI-assisted (Claude Code); numbers from my own runs.

**@⁠ntgata1-dotcom** on GitHub · 2026-11-25 11:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2179#issuecomment-7160910651) **RX 9070 XT (RADV) under Wine 11.22: works with #1722 (tests, and menus only)** Setup: Arch Linux, RX 9070 XT (RDNA4), RADV / Mesa 26.3.1. System Wine 11.22. vkd3d-proton `v3.1-83-gcae8353ed` and DXVK `dxgi` from GE-Proton11-14. `cargo xwin test --locked --target x86_64-pc-windows-msvc --no-fail-fast -p victory-gpu`, runner `wine`. | `victory-gpu` | passed | failed | |---|---|---| | `main` `940d32f` | 130 | 13 | | this PR `c8ad2a4` | 131 | 13 | | this PR + #1722, merged locally | 132 | 12 | - `a_pipeline_loads_while_a_save_holds_the_library`: without #1722 it returns at its first `else` here (`library()` is `None` under vkd3d-proton), so its "ok" there means it didn't run. With #1722 it runs. A temporary print after the store showed the load returning `Ok(true)` while the lock was held. - With #1722, all 9 `pipeline::library` tests pass. Outside `pipeline::library`, no test changes against `main`. With #2195 merged as well, the results are the same. - Title menus only, release build of this PR + #1722, two 150 s runs on one cache folder. Run 1 saves up to `bytes=1208 early=6 made=6`, and run 2 loads it: `made=0 loaded=6 started_early=6`. Both run at 30.0 fps after start-up, with no `crashes.log` and no amdgpu messages in the kernel log during the runs. With 6 pipelines and 1.2 KB saves, the menus can't show the load/save contention itself; that needs the world. Not run: Windows, the world. AI-assisted (Claude Code); numbers from my own runs.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 12:40 UTC · original

Automated triage for the maintainers.

Merge candidate. On main, pipeline in crates/victory-gpu/src/pipeline/library.rs already loads outside the library lock, but it takes the lock first to clone the interface. So every load waits out a save that holds the lock while it serialises the whole library. This PR keeps a second reference to the same library (Shared::loads) next to the locked state, so loads never take the lock. Stores, serialising and the pre-build list stay under state's lock, as before. Loads of one name stay apart through NAMES, as on main.

The new test a_pipeline_loads_while_a_save_holds_the_library holds the lock and checks that a stored pipeline still loads. A reviewer confirmed it fails (times out) with the old lock acquisition put back. CI check passes, and the branch merges cleanly.

For the maintainers: #1653 and #1651 rework the same function for sharding. Whichever lands second needs a rebase onto the other.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 12:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2179#issuecomment-7162690115) <!-- victory-triage v1 head=c8ad2a46f2d9395c160de67583ec6ab79df80d7a verdict=merge-candidate at=2026-11-25T13:58:00Z --> Automated triage for the maintainers. **Merge candidate.** On `main`, `pipeline` in `crates/victory-gpu/src/pipeline/library.rs` already loads outside the library lock, but it takes the lock first to clone the interface. So every load waits out a save that holds the lock while it serialises the whole library. This PR keeps a second reference to the same library (`Shared::loads`) next to the locked state, so loads never take the lock. Stores, serialising and the pre-build list stay under `state`'s lock, as before. Loads of one name stay apart through `NAMES`, as on `main`. The new test `a_pipeline_loads_while_a_save_holds_the_library` holds the lock and checks that a stored pipeline still loads. A reviewer confirmed it fails (times out) with the old lock acquisition put back. CI `check` passes, and the branch merges cleanly. For the maintainers: #1653 and #1651 rework the same function for sharding. Whichever lands second needs a rebase onto the other. --- _Generated by [Claude Code](https://claude.ai/code)_
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!2179
No description provided.