GPU: map the pipeline library's file instead of reading it into memory #2129
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2129
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2129"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@0xkn0wh3r3 on GitHub · 2026-11-25 05:44 UTC · original
0xkn0wh3r3:gpu/mapped-pipeline-library→main· +683 −53 · 1 files · 3 commits · openThe problem
The host pipeline library is read into memory at start and kept for the whole run: D3D12 reads the bytes a library was made from for as long as it lives. Each save then builds a second full-size copy to write out. Measured on fxceless/victory-fork, the library was 1,352 MB, all of it in the process's own memory.
The fix
Blob::Mapped). Only the pages D3D12 touches are in memory, and Windows can drop them without writing anything.host-pipelines.bin.tmp-*, and the early and pre-build lists' files) left by runs that ended during a save. A file is removed only if its process ID is not running: "no such process" (error 87) or exited. Denied access counts as running.host-pipelines.nextfirst and is renamed from there over the library, the step a start also takes. If a system refuses to replace a mapped file, the new library waits there and takes over at the next start; the pending file is always the newest library saved.VICTORY_LIBRARY_MAP=0restores the old behaviour. Its buffer (and the fallback when a staging file can't be mapped) is #2007's falliblezeroed, so a save without memory is still left for later instead of aborting, with #2007's warning.Ported from fxceless/victory-fork (commit
578d459): the mapping only, re-applied on top of upstream's concurrent loads, unique staging files and pre-build list.Testing
the_library_file_is_mapped_and_replaced: a save replaces a mapped library while the old mapping still reads the old bytes; the next start reads the new one; a failed serialisation leaves the library as it was and no staging file behind.a_replaced_library_file_still_reads_from_the_disk: an 8 MiB file written past the system cache still reads correctly page by page after being replaced. It fails with the file closed: page 16 reads zeros here.the_next_start_reads_the_library_saved_last: with the library held, saves wait as the pending file (a newer one replacing an older); released, the next save replaces the library and leaves no pending file.a_mapped_library_file_cannot_be_written_meanwhile: while mapped, opening the file to write or truncate fails with a sharing violation; reading it and a save's rename over it work.staging_names_give_their_process,staging_files_of_ended_runs_are_removed: staging files whose process ended are removed (no such process, or exited with a handle held). Those of this process, of a running process, of PID 4 and other files are kept.pipelines_load_on_many_threads_at_oncenow opens its library from a mapped file.library_file_memory, ignored measurement, release): for a 256 MiB library file, reading it into memory adds 256.5 MiB of private memory; mapping it and reading every page adds 0.5 MiB.a_mapped_library_file_cannot_be_written_meanwhilestaging_files_of_ended_runs_are_removedcargo test -p victory-gpu --libon an RTX 5070 Ti, with mapping on and withVICTORY_LIBRARY_MAP=0: all pass except the two tests that already fail onmainfrom the NVIDIA heap cap (#1835).cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.Not covered / Related
zeroedfor its buffer fallback and needs no buffer when mapping works. #2179 (merged) loads without the library's lock; the mapped bytes stay with the locked library, which is never dropped.Rebased onto
f3578e3Re-expressed on top of #2007 and #2179: this branch's own fallible buffer and its test (
a_save_buffer_the_host_cannot_give_is_an_error) are dropped in favour of #2007'szeroedanda_save_buffer_the_host_cannot_give_is_refused; a save without memory logs #2007's "saved later" warning. Saves keep #2179's lock split (loads lock nothing).cargo test -p victory-gpu --lib: all pass but the two that fail onmainhere (NVIDIA heap cap); clippy clean with and without--features diagnostics.@r4tedx on GitHub · 2026-11-25 05:52 UTC · original
I opened #2132 for the same change four minutes after this one, without having seen it; I'm closing mine in favour of this PR, which also takes the save-time copy away. Three things from that work that may be useful here, from synthetic tests on Windows 11 (no GPU, no title):
std::fs::renameover it all fail (the rename withERROR_ACCESS_DENIED, 5). So your choice ofFile::open's default sharing (read, write and delete) is what makes the rename work. Its price is that any other process may also write the mapped file in place while D3D12 reads it, and nothing here would notice. I went the other way in #2132 (read-only sharing and a new numbered file per save) for that reason. Whether an in-place writer is realistic here is a judgment call; I mention it because the fork's device loss came from exactly this file changing under the mapping.host-pipelines.bin.tmp-*later. Killing a hung run is routine, so they pile up. In #2132 a load removes those whose process is no longer running (OpenProcess; only "no such process", error 87, counts as ended).Vecand 0.5 MiB mapped (PrivateUsagebefore and after the load).AI-assisted (Claude Code). No game data was used.
@Dathinel on GitHub · 2026-11-25 06:11 UTC · original · edited 2026-11-25 06:19 UTC
A pending save can replace a newer successful save at the next load. I reproduced this on Windows at
fe997c5with one process, a temporary directory, and one-byte payloads passed throughwrite_library:host-pipelines.binopen for reading withFILE_SHARE_READonly.host-pipelines.nextcontains B.host-pipelines.bindirectly returns C.Blob::of(dir). Expected C, got B.replace_libraryleaves the previous pending file when the later rename to the canonical path succeeds.Blob::ofthen promotes that pending file before reading. This sequence would make a useful regression test for whichever ordering scheme you choose. It checks the cache bytes on reopen; no driver, game data, or concurrent writers were involved. AI-assisted.Follow-up on
2ef0c75. The same regression still reopens generation 2 after generation 3 was saved. Optional fix and regression test: publish each completed save to the pending name first, then try to promote it. The patch applies cleanly to your updated head. With it, the pipeline-library tests passed on Windows (15 passed, one memory measurement ignored), including both a still-held and a released canonical file.One tradeoff I verified: if the pending file itself is held without delete sharing, the new save returns an error and preserves the previous successful save. The old code reported success in that case but reopened the previous pending bytes anyway. These checks used one process; cross-process ordering and crash durability remain untested.
@0xkn0wh3r3 on GitHub · 2026-11-25 06:13 UTC · original
Thanks, all three were useful. I've pushed 2ef0c75 for them:
a_mapped_library_file_cannot_be_written_meanwhile.*.tmp-<pid>-<n>files of the library, early list and pre-build list whose process has ended. As in #2132, only "no such process" (87) counts as ended whenOpenProcessfails, and denied access counts as running. One addition: a process that has exited while another process still holds its handle (GetExitCodeProcessis no longerSTILL_ACTIVE) also counts as ended. Tests:staging_names_give_their_processandstaging_files_of_ended_runs_are_removed. The second checks a process ID with no process, an exited process with a handle held, a running process, PID 4, this process and an unrelated file.library_file_memory. It gives the same here: 256.5 MiB private when read into memory, 0.5 MiB mapped, for a 256 MiB file. It is now in the description.Each new check was mutation-tested (the table is in the description).
cargo test -p victory-gpu --libpasses with mapping on and withVICTORY_LIBRARY_MAP=0, except the two NVIDIA #1835 failures. Clippy is clean with and withoutdiagnostics.@andrewpozdnakov7-jpg on GitHub · 2026-11-25 07:53 UTC · original
I ran the pipeline-library tests at 2ef0c75 on native Windows with D3D12 WARP. The suite returned 14 passed and one ignored measurement.
I also extended the concurrent load test so it replaces the canonical file while the original library still owns its mapped view. A freshly opened library must load the newly added compute PSO, and the threads must still load the original PSOs from the old mapping. The extended suite passed with mapping enabled. When I deliberately republished the previous snapshot, the added assertion failed at the load of the new PSO with HRESULT 0x80070057.
Optional regression test on your exact head. If you fold the test into your commit, please retain this trailer.
Co-authored-by: andrewpozdnakov7-jpg [email protected]
AI-assisted. Synthetic shaders only.
@Marvisak on GitHub · 2026-11-25 10:48 UTC · original · edited 2026-11-26 01:21 UTC
Automated triage for the maintainers.
Merge candidate (unchanged). The push since the last triage (
3294cf6to7577fdb) rebases onto currentmainand now merges cleanly, including the earlier textual conflict with #2007. Incrates/victory-gpu/src/pipeline/library.rs, the branch's own fallible buffer is dropped in favour ofmain'szeroed(anOutOfMemoryerror still leaves the save for later, with #2007's warning).write_atomicallyand the newwrite_libraryboth keepmain'sWRITINGlock and uniquestagingnames.main'sconcurrent_write_atomically_never_fails_or_truncatestest is kept. The rest is as reviewed before:replace_libraryrenames each save throughhost-pipelines.next.remove_abandonedremoves staging files only for ended processes. It queries processes and spawns none.Optional, as before: the module doc and the share-mode comment cite run figures and the fork, which would sit better in the PR description.
CI: passing (
check).Recommending a look, not approving.
Generated by Claude Code
@Slay326 on GitHub · 2026-11-25 14:13 UTC · original
Measured on an RTX 3070 with a 3,843 MB library (27,160 pipelines): read whole it is one 3,665 MB private allocation for the run, and
saverewrote all of it six times in 130 s withmade=0(only the early list had changed), each time with a second copy in memory: process commit swung between 37.6 and 42.1 GB. With both PRs merged, process commit at start is 10.3 GB instead of 15.6 GB, and no save rewrites the library in a 480 s run.AI-assisted.
@0xkn0wh3r3 on GitHub · 2026-11-25 18:37 UTC · original
Thanks. Both points are fixed in 3294cf6.
host-pipelines.nextfirst, then from there over the library, which is the same step a start takes inBlob::of. So a pending file is either the newest save or absent. A save that can't replace the library leaves its bytes in.next, and the next save replaces them. If.nextitself is held open, that save fails and the previous library is what the next start reads.the_next_start_reads_the_library_saved_lastcovers your sequence, with the library both held and released, plus a held.nextfailing the save. It fails on 2ef0c75.staging_files_of_ended_runs_are_removedno longer starts any. A PID no process can have stands in for an ended run, and this process and PID 4 stand in for running ones. The cost is that the "exited but its handle still held" branch is no longer tested. Covering it would take one short-livedcmd /c exit 0child, if you'd rather keep that.@andrewpozdnakov7-jpg, thanks for the concurrent-replacement test. I'd rather keep it as your own commit. If the maintainer wants it in, it can go in as it is. @Slay326, thanks for the commit-charge numbers: 15.6 → 10.3 GB at start with no full rewrites is the effect I was after.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.