GPU: serialize pipeline library saves and use unique temp files #164
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/164"
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?
Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-24T22:06:07Z.
Problem
save()staged the pipeline library to a fixedhost-pipelines.tmppath and releasedlibrary.saving.write()before callingreplace_library().write_atomically()stagedearly-pipelines.txtto a fixed.tmppath with no lock.save(true)can race on the same temp file or leave stale temp files on rename error.Fix
SAVE_IOwithout holdinglibrary.saving.write()across renames..tmp-<pid>-<seq>staging paths viaunique_tmp()for bothsave()andwrite_atomically().replace_library()andwrite_atomically().Verification
write_atomicallyandSAVE_IO+replace_libraryverifying integrity and zero leftover.tmp-*files.cargo clippy --workspace --all-targets --locked -- -D warningscargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo test -p victory-gpu pipeline::library::tests --locked(6/6 passed)cargo test -p xtask --locked(4/4 passed)Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-24T22:58:52Z.
I reproduced a save-retry problem on this head (
baf1154) and current main (2119b0e). When an early-list rename fails, or both host-library rename destinations fail,save(true)can clear the dirty state before publication succeeds. After removing the filesystem obstruction, a secondsave(true)can return without writing the previously pending data. The same problem is present on #211.An independent retry patch on this head passed eight source-built cases. These cover real rename failures, retrying the early list independently after successful host publication, injected serialize and staging failures, successful fallback, and Stores or early notes arriving during publication. The patch acknowledges the serialized Store count only after a successful rename and subtracts that snapshot so new Stores stay pending. It also restores the early-list dirty flag if its write fails.
The repro uses real filesystem operations with a simulated D3D12 library. Native D3D12 and concurrent processes sharing the same cache were outside this run. This retry behavior can be tested independently of the startup ordering change in #211.
Imported from fxceless/victory-fork. Originally posted by Headache3318 on 2026-11-25T09:24:15Z.
Independent verification: PR #535 does not exist on this repo (redirects to issue #535). Verified PR #164 (GPU: serialize pipeline library saves and use unique temp files) instead, which matches the description of fixing a race in the pipeline library cache. Build: success. PR-specific tests: 6/6 passed including the 2 new concurrent safety tests (concurrent_write_atomically_never_fails_or_leaves_temp_files, concurrent_save_io_and_replace_library_never_collide_or_leak_tmp). Full workspace tests timed out after 480s (expected for cross-compilation through Wine). No merge conflicts. Machine: Arch Linux, kernel 7.3.5-arch1-1, 3x RTX 4090 driver 620.73.04, Proton, AI-assisted.
Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-25T09:44:40Z.
Thank you — this reproduced exactly as you described, and the fix follows the shape of your patch.
What was wrong.
save()cleared both dirty flags before either write landed: it stored0into the library'saddedcount beforereplace_library()renamed the serialised bytes into place, and it cleared the early list'schangedflag beforewrite_atomically()wrote that list. A failed rename therefore left the retry with nothing to do. Both destinations have to fail for the library to be lost, but the early list is one write and fails on its own — including when the library write fails first and the list is never attempted.What changed (
crates/victory-gpu/src/pipeline/library.rs). The publication step is nowpublish():added.fetch_sub(snapshot, Relaxed)only afterreplace_library()returnsOk(()), so stores that arrive while the library is being serialised stay pending for the next save.serialise()failure restores the early-list flag too; that path used to drop the pending early list as well.Tests — three, new, all with real filesystem operations against a simulated library, as in your repro:
a_save_whose_rename_fails_keeps_its_stores_and_early_list_pending— both rename destinations held by a folder (ERROR_ACCESS_DENIED), then released: the retry writes both files.a_save_acknowledges_only_the_stores_it_serialised— a store arriving between the snapshot and the publication stays pending.an_early_list_that_cannot_be_written_stays_pending_after_the_library_is_published— the library lands, the list does not, and only the list stays dirty.Each was checked against the bug: acknowledging the stores before the rename, clearing every store instead of the snapshot, and dropping the early-list restore each fail the test named for it. The probes are recorded in the test file so the next editor has them.
Gate, on this head rebased onto
9376fd60:pipeline::library::tests9 passed;cargo test -p victory-gpu149 passed, 3 ignored;cargo test -p xtask4 passed. Both clippy passes are red in this workspace for three pre-existing diagnostics that are identical onmainat9376fd60(placed_filler_twinsnever used,sort_unstable_by_keyindraw.rs,depth_writtennever read) —main's own CI Clippy job failed at that commit. This branch adds none of them; I left them alone rather than widen the diff.Not covered, the same as your run: native D3D12 and concurrent processes sharing one cache. No local title files here, so it is the same simulated-library shape you used.
Rebased onto
9376fd60and force-pushed with lease.Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-25T13:49:16Z.
Your repro is addressed on
f3230ff5, and I want to be precise about which of your requirements each part answers, because the ordering is the whole fix.publish()now does, in this order:replace_library— the rename, or the fallback that leaves the new file beside the old one.Ok:added.fetch_sub(snapshot), wheresnapshotis the count taken before serialisation began. That is your "acknowledge the serialized Store count only after a successful rename".snapshot, so they survive the subtraction and the next save writes them.changedis set back totrue.So the failure path leaves the store count untouched and the early list dirty, and the next
save(true)writes the data instead of returning early. That is the bug you described atbaf1154.Tests, one per requirement — none of these existed before:
a_save_acknowledges_only_the_stores_it_serialiseda_save_whose_rename_fails_keeps_its_stores_and_early_list_pendingan_early_list_that_cannot_be_written_stays_pending_after_the_library_is_publishedProbe: acknowledge the stores before checking the rename result — the shape of the original bug — and all three fail, the first with
the store that arrived during the save is still pending(count-3, i.e. an underflow past zero, which is what acknowledges-what-never-wrote looks like). Restored byte-identical afterwards.cargo test -p victory-gpu --lib pipeline::library: 9 passed, 0 failed.Two things I did not cover, so they are not read as covered: native D3D12 — the tests use a simulated library, as you noted — and two processes sharing one cache directory. Both are outside what this repo can run here. If you have a machine where the obstruction is real (a mapped file the system refuses to replace), that is the run that would settle
replace_library's fallback path rather than its error path.Imported from fxceless/victory-fork. Originally posted by Headache3318 on 2026-11-30T12:41:22Z.
Independent verification at head
f3230ff5(AI-assisted, Hermes Agent; Arch Linux, kernel 7.3.6-arch1-2, 3x RTX 4090 driver 620.73.04 — the tests cross-compilex86_64-pc-windows-msvcwithcargo-xwinand run under wine; no game data, no native D3D12).The three new tests and the full library suite pass on a second host.
cargo xwin test -p victory-gpu --lib pipeline::library --target x86_64-pc-windows-msvcatf3230ff5ce8c: 9 passed / 0 failed (exit 0), including all three you list pinning the repro —a_save_acknowledges_only_the_stores_it_serialised,a_save_whose_rename_fails_keeps_its_stores_and_early_list_pending,an_early_list_that_cannot_be_written_stays_pending_after_the_library_is_published— plus the two concurrency tests from my earlier check on the previous head. Your mapping of requirements to tests holds as far as these runs can see.On the obstruction run you asked for: on Linux/wine the rename obstruction fires without needing a mapped file (the destination held by a directory fails the rename as
EISDIR), so the error path is now confirmed on a second host too — but that means this box cannot tell which errno its test branch took, and the fallback path (the new file left beside the old one) still has no second-host run from here. Agree it needs a native run to settle.One host note, not caused by this PR: run natively on Linux, the same command fails to compile with three errors (
crate::texture,crate::host,host_resourceconfigured out —list.rs:1809,list.rs:1815,resource.rs:619). The unmodified base9376fd6fails with the identical three, so it is pre-existing cfg gating on main of that era; this PR touches onlypipeline/library.rs, so the Windows-target run above is the right way to exercise it here.Mergeability — needs author action:
main's history has been rewritten since this branch was based. There is no merge base between the PR (at its base9376fd6) and current main368967f(git merge-basereturns nothing; GitHub shows CONFLICTING), so a plain rebase cannot work. Simulated the fresh port:git cherry-pick cf0de55 f3230ff5onto368967fconflicts in exactly one file,crates/victory-gpu/src/pipeline/library.rs— main has since moved that file — everything else applies clean. Resolving that one file should carry the fix over intact.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.