Skip to content

GPU: load pipeline library entries without the global mutex - #1680

Closed
Calvix2k wants to merge 1 commit into
Marvisak:mainfrom
Calvix2k:codex/gpu-pipeline-library-locks-1615
Closed

Calvix2k wants to merge 1 commit into
Marvisak:mainfrom
Calvix2k:codex/gpu-pipeline-library-locks-1615

Conversation

@Calvix2k

@Calvix2k Calvix2k commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BaggyALPHA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Calvix2k

Copy link
Copy Markdown
Contributor Author

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.

@Calvix2k
Calvix2k marked this pull request as draft November 24, 2026 22:17
Loads ran under the one mutex that holds the library, so workers serialised behind loads that can take seconds. Keep a cloned `ID3D12PipelineLibrary1` beside the bookkeeping and guard loads with one of 64 locks chosen by pipeline name (`CreatePipelineLibrary` requires only same-name loads not to overlap). Stores and saves stay serialised by the library mutex, so the serialised size cannot change under a save.

Based on the original Marvisak#1680 work; adapted to the pre-build/`prebuilt` state added upstream.
@Calvix2k
Calvix2k force-pushed the codex/gpu-pipeline-library-locks-1615 branch from 2a686eb to 8666a22 Compare November 24, 2026 22:30
@Calvix2k Calvix2k changed the title GPU: pipeline library loads take a lock for their name, not one for all GPU: load pipeline library entries without the global mutex Nov 24, 2026
@Calvix2k
Calvix2k marked this pull request as ready for review November 24, 2026 22:30
Airamek added a commit to Airamek/VIctory that referenced this pull request Nov 24, 2026
Translation speed (compile-storm CPU): Marvisak#1623 inline instruction words
(decode -18..-45%), Marvisak#1834 VALU names without heap vector, Marvisak#1833 live-set
bit walk, Marvisak#1802 relative shift bounds, Marvisak#1824 dx.op declarations once.
Per-draw/per-list CPU: Marvisak#1825 view-stride table once per list, Marvisak#1826
object names only where logged, Marvisak#1800 capped-heap log spam once per 64Ki.
Tooling: Marvisak#1809 list pipeline keys without cache init.
Locking: Marvisak#1680 pipeline library loads without the global mutex.

Held: Marvisak#1819 (2^20->2^14 loop bound) breaks transcendental convergence
tests (sin/cos/exp/sqrt) — accuracy-lowering, rejected per policy.
@Calvix2k

Copy link
Copy Markdown
Contributor Author

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.

@Calvix2k Calvix2k closed this Nov 25, 2026
Airamek added a commit to Airamek/VIctory that referenced this pull request Nov 25, 2026
Upstream moved 70564ae..ccfb029 (GPU pacing, DRED identity, descriptor
cursor, xmem commit reporting, hardware-adapter test gating, input
layouts, many shader lowerings). Resolved 10 files:

- host.rs, pipeline/host.rs (tests), primitive.rs, valu_tests.rs,
  xasync.rs: kept both sides additive tests.
- indirect.rs: took upstream one-group clamp plus
  INDIRECT_ARGUMENT barriers; draw call sites pass the resource.
- pipeline/library.rs: took upstream NAMES-hold plus clone-outside-lock
  loads (supersedes our Marvisak#1680 LOADS); periodic saves stay best-effort.
- emit/host.rs: kept our fence-wait helper; took upstream
  hardware_adapter gating.
- xmem.rs: took upstream OOM reporting; kept our APU allocator-refusal
  crash log on top of it.
- lower.rs: upstream had merged the same Marvisak#1733 helper; dropped our copy.
- pipeline/host.rs: kept our padding-zeroing clean_* over upstream reads.

Kept from our queue: PSV0 strings, op-cache opcode key, huge gating,
Marvisak#1750 wait slices, micro-opts. Verified: workspace green (gpu 151,
shader 254), clippy -D warnings clean, policy 185 files ok.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants