GPU: load pipeline library entries without the global mutex #1679

Closed
Calvix2k wants to merge 1 commit from upstream-pr/1680 into main
Calvix2k commented 2026-11-24 20:42:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T20:42:29Z.


Summary

Loads from the host pipeline library ran under the one mutex that holds the library, so pipeline workers serialised behind loads that take seconds. CreatePipelineLibrary only requires that loads of the same pipeline name do not overlap.

Reworked on upstream 70564ae (which added the pre-built list):

  • Keep a cloned ID3D12PipelineLibrary1 beside the bookkeeping, so a load does not take the library mutex.
  • Loads take one of 64 locks chosen by pipeline name; different names run in parallel.
  • Stores and saves stay under the library mutex, so the serialised size cannot change under a save.
  • No change to the pre-build/prebuilt state, which is read and written under the same mutex as before.

Based on the original #1680 design by @Vaximous, reduced to the load path for the new library structure.

Validation

  • cargo test -p victory-gpu --locked pipeline::library — 4 passed.
  • Full victory-gpu suite: 77 passed, 1 failed, 1 ignored. The failure is draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view, which fails identically on plain origin/main on this machine (unrelated).
  • clippy --all-targets --all-features -D warnings and cargo xtask policy (174 files) passed.
  • Not measured in the title; the original PR's 3.5 min → 30 s startup measurement was on the old library code.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6591013500 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1680). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T20:42:29Z. --- ## Summary Loads from the host pipeline library ran under the one mutex that holds the library, so pipeline workers serialised behind loads that take seconds. `CreatePipelineLibrary` only requires that loads of the same pipeline name do not overlap. Reworked on upstream 70564ae (which added the pre-built list): - Keep a cloned `ID3D12PipelineLibrary1` beside the bookkeeping, so a load does not take the library mutex. - Loads take one of 64 locks chosen by pipeline name; different names run in parallel. - Stores and saves stay under the library mutex, so the serialised size cannot change under a save. - No change to the pre-build/`prebuilt` state, which is read and written under the same mutex as before. Based on the original #1680 design by @Vaximous, reduced to the load path for the new library structure. ## Validation - `cargo test -p victory-gpu --locked pipeline::library` — 4 passed. - Full `victory-gpu` suite: 77 passed, 1 failed, 1 ignored. The failure is `draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view`, which fails identically on plain `origin/main` on this machine (unrelated). - clippy `--all-targets --all-features -D warnings` and `cargo xtask policy` (174 files) passed. - Not measured in the title; the original PR's 3.5 min → 30 s startup measurement was on the old library code.
catminou4 commented 2026-11-24 22:01:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:42:12Z.

Review: COMMENTED


Static review only: Windows-only code (D3D12/windows_sys/Win32) — nothing compiles or runs on macOS; source review of the diff.

Pipeline library loads take a per-name lock instead of one global lock: unsafe impl Sync for Library (justified by the per-name Mutexes), lock_name() returns a guard, and save_interval/save_files add periodic saves with backoff following measured cost (periodic_saves_back_off_and_follow_their_cost test). Replacing a single global lock with per-name locks is the kind of change that needs the Windows playability runs to shake out deadlocks — statically the guard discipline looks consistent.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047874882 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1680#pullrequestreview-6047874882). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:42:12Z. **Review:** COMMENTED --- Static review only: Windows-only code (D3D12/windows_sys/Win32) — nothing compiles or runs on macOS; source review of the diff. Pipeline library loads take a per-name lock instead of one global lock: unsafe impl Sync for Library (justified by the per-name Mutexes), lock_name() returns a guard, and save_interval/save_files add periodic saves with backoff following measured cost (periodic_saves_back_off_and_follow_their_cost test). Replacing a single global lock with per-name locks is the kind of change that needs the Windows playability runs to shake out deadlocks — statically the guard discipline looks consistent.
BaggyALPHA commented 2026-11-24 22:01:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BaggyALPHA on 2026-11-24T22:01:27Z.

Review: COMMENTED


Independent warm-cache A/B on Windows, RTX 3080 12 GiB, driver 621.24. Both builds used the same diagnostics stack (#1604, #211 and #1702), startup input and Series S profile. Each run received a fresh copy of the same VIctory library and 690-entry early list, plus the same test profile. All four runs accepted the library. The baseline and this PR had identical local timers around the app's load lock, the D3D12 load call, and fallback pipeline creation.

Trial order Time to 500 successful library loads, baseline / this PR Cumulative app load-lock wait at 512 completed requests, baseline / this PR
Baseline then this PR 19.32 s / 9.36 s 103.68 s / 0.84 s
This PR then baseline 7.46 s / 6.37 s 9.65 s / 0.001 s

Both builds had 510 cache hits by the 512-request sample in both trials. The lock values are elapsed time summed across workers. The driver cache was left intact across runs, so the speedup magnitude is sensitive to run conditions. The app-side lock reduction and improved startup load throughput held in both orders.

In the longer pair, by 1,024 completed requests each build had 540 hits and 484 fallback creation calls. Those calls accumulated 171.87 s / 195.83 s of worker elapsed time, respectively. This points to native creation as a useful separate target after the warm-library burst. These measurements cover startup and worker activity.

AI-assisted (Codex). Aggregate results only.

<!-- greyfinch-sync:Marvisak/VIctory:review:6048102217 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1680#pullrequestreview-6048102217). Originally posted by [BaggyALPHA](https://github.com/BaggyALPHA) on 2026-11-24T22:01:27Z. **Review:** COMMENTED --- Independent warm-cache A/B on Windows, RTX 3080 12 GiB, driver 621.24. Both builds used the same diagnostics stack (#1604, #211 and #1702), startup input and Series S profile. Each run received a fresh copy of the same VIctory library and 690-entry early list, plus the same test profile. All four runs accepted the library. The baseline and this PR had identical local timers around the app's load lock, the D3D12 load call, and fallback pipeline creation. | Trial order | Time to 500 successful library loads, baseline / this PR | Cumulative app load-lock wait at 512 completed requests, baseline / this PR | | --- | ---: | ---: | | Baseline then this PR | 19.32 s / 9.36 s | 103.68 s / 0.84 s | | This PR then baseline | 7.46 s / 6.37 s | 9.65 s / 0.001 s | Both builds had 510 cache hits by the 512-request sample in both trials. The lock values are elapsed time summed across workers. The driver cache was left intact across runs, so the speedup magnitude is sensitive to run conditions. The app-side lock reduction and improved startup load throughput held in both orders. In the longer pair, by 1,024 completed requests each build had 540 hits and 484 fallback creation calls. Those calls accumulated 171.87 s / 195.83 s of worker elapsed time, respectively. This points to native creation as a useful separate target after the warm-library burst. These measurements cover startup and worker activity. AI-assisted (Codex). Aggregate results only.
upstream-sync changed title from [PR #1680] GPU: pipeline library loads take a lock for their name, not one for all to [PR #1680] GPU: load pipeline library entries without the global mutex 2026-11-24 23:04:57 +00:00
Calvix2k commented 2026-11-24 23:05:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T22:17:24Z.


Marking draft: upstream 70564ae rebuilt the library around the pre-built pipeline list (prebuilt, prebuilt_changed, save tagging), which overlaps every hunk of the lock/save split here. It needs a rework against the new state rather than a mechanical conflict resolution. The concurrency issue itself is still real (upstream still has one Mutex<Library>), so I will redo it on the new base.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146045810 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1680#issuecomment-7146045810). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T22:17:24Z. --- Marking draft: upstream 70564ae rebuilt the library around the pre-built pipeline list (prebuilt, prebuilt_changed, save tagging), which overlaps every hunk of the lock/save split here. It needs a rework against the new state rather than a mechanical conflict resolution. The concurrency issue itself is still real (upstream still has one `Mutex<Library>`), so I will redo it on the new base.
upstream-sync closed this pull request 2026-11-25 01:07:01 +00:00
Calvix2k commented 2026-11-25 01:08:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T00:46:56Z.


Superseded by main: origin/main (4118f33) now holds a pipeline's name with NAMES.hold(name) around load/store and keeps the library in OnceLock<Option<Mutex>>, so loads of different names run in parallel while loads/stores of one name are serialised, and saves take the library mutex. That is the same outcome this PR's 64-stripe lock and STORES RwLock produced, with the new pre-build support on top. Closing this in favour of the code already on main; nothing from the PR is lost.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148868936 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1680#issuecomment-7148868936). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T00:46:56Z. --- Superseded by main: origin/main (4118f33) now holds a pipeline's name with NAMES.hold(name) around load/store and keeps the library in OnceLock<Option<Mutex<Library>>>, so loads of different names run in parallel while loads/stores of one name are serialised, and saves take the library mutex. That is the same outcome this PR's 64-stripe lock and STORES RwLock produced, with the new pre-build support on top. Closing this in favour of the code already on main; nothing from the PR is lost.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1679
No description provided.