GPU: atomic adaptive PSO wait budget and non-blocking pipeline library saves #275
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/275"
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 Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T01:58:50Z.
Summary
Eliminates mid-gameplay 500 ms PSO wait freezes and periodic 20-second pipeline-worker stalls while raising early-warmup capacity:
pipeline/make.rs:FRAME/WAITED_USaccounting with a lock-free packedAtomicU64FrameBudget(reserve + same-frame refund) so concurrent recording threads cannot collectively overshoot the frame wait budget or corrupt newer frames.Condvarto per-Pendingwait_lock/wait_donewakeups.< 60, 8 ms in steady state) with an explicitVICTORY_PSO_WAIT_MS(0..=5000ms) override.pipeline/library.rs:save(false)onto a dedicated low-priority background saver thread reusing its serialization buffer (pre-sized outsidelibrary.lock()).library.lock()strictly forID3D12PipelineLibrary1::Serialize, skips rewritinghost-pipelines.binwhen onlyearly-pipelines.txtchanged, and performs unique-temp atomic write+rename with cleanup on error outside all locks (restoring dirty counters on failure).save(true)synchronous via FIFOSaveAck, and raisesEARLY_MAXfrom8,192to65,536.victory-gpucovering concurrent 8-thread budget reservation/refund/frame isolation,VICTORY_PSO_WAIT_MSparsing/clamping and adaptive defaults, early-list recording/dedup up to 65,536, and atomic-write overwrite + temp-file cleanup on rename error.Verification
cargo clippy --workspace --all-targets— passed (zero new warnings)cargo clippy -p victory --features diagnostics --all-targets— passedcargo test --workspace— passedcargo xtask policy— passed (151 files ok)Imported from Marvisak/VIctory. Originally posted by ifBars on 2026-11-24T02:09:54Z.
I compiled a deterministic CPU-only test against the
FrameBudgetimplementation fromf7730115. A recording thread can read frame 100, get descheduled, then enterreserve(100, ...)after another thread has already reserved frame 101. Becausereserveresets the state on every differing tag, the stale reservation moves the tag back to 100. The next frame-101 caller then gets a second full budget.This interleaving needs no timing-sensitive test:
The current implementation returns
(8000, 8000). The existing test exercises stale refunds. Could we also test stale reservations and havereservereturn zero when the supplied tag precedes the active tag, accounting for the sentinel and wraparound?Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T02:16:13Z.
@ifBars Good catch — thanks for the deterministic repro!
Fixed in
96b2822:FrameBudget::frame_tagnow usesframe % NO_FRAME_TAG(keeping tags strictly in0..NO_FRAME_TAGwithout colliding atNO_FRAME_TAG), andFrameBudget::reservechecksis_newer_tag(tag, cur_tag)via modular half-range distance (0 < diff < NO_FRAME_TAG / 2) before resetting the budget.cur_tag(including across theNO_FRAME_TAGwraparound boundary) now return0without mutating the active frame's packed state.stale_reservation_never_rewinds_active_frame_or_wraparoundcovering thereserve(101) -> reserve(100) / reserve(101)interleaving, partial-budget preservation, andNO_FRAME_TAGwraparound (cargo test -p victory-gpu --lib: 48 passed / 1 ignored,cargo clippy -p victory-gpu --all-targets,cargo xtask policyall passing).Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:25:12Z.
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-gpu/src/pipeline/library.rs,crates/victory-gpu/src/pipeline/make.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-25T07:29:32Z.
A pointer and one observation, since this PR and #2111 change the same accounting in
pipeline/make.rs.What overlaps. On
main,waitreads the frame's waited time before it waits and adds its own only afterwards, so recording threads that wait at the same moment each take the whole budget. Both PRs fix that. #2111 does only that (the waits of a frame end together, and the frame line prints the time draws waited for pipelines); it is onmain940d32fand merges cleanly. Its synthetic test, four threads on pipelines that are never made: the frame stands still 882 ms onmainand 505 ms with the fix.What is only here. The adaptive budget (500 ms for the first 60 frames, 8 ms after),
VICTORY_PSO_WAIT_MS, a wake per pipeline instead of one for all, and the non-blocking library saves. This PR came first (24 Nov). It is ond2a4baeand conflicts withmain. For the library half, #2129 now maps the file and stages the save.One behavioural difference, from reading
96b2822.waitreserves all the budget that is left before it waits, and returns at once when it is granted nothing. So when two recording threads need a pipeline at the same moment, the first holds the whole budget and the second drops its draw immediately, even if its pipeline would be there a millisecond later; it can wait only after the first has refunded. In #2111 both wait until the frame's shared budget ends. I have not measured whether that matters in the title, and neither PR has a title run.Suggestion. After a rebase, the parts unique to this PR sit on top of either accounting, so the two need not compete: this could keep the adaptive budget, the switch and the per-pipeline wake, and take the accounting from whichever the maintainers prefer. If they prefer this PR's accounting, #2111 can close. Either way a test with two threads waiting at once would pin the case above.
Nothing was run for this comment; I read the diff.
AI-assisted (Claude Code).
upstream-sync referenced this pull request2026-11-25 11:05:31 +00:00
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T04:55:11Z.
I checked the 65,536-key warmup limit at
96b2822. When the previous file is already full, the current membership set rejects every unseen key. With a generated full list and 256 new uses, it retained 0 of 256.9d989f5 applies the #3668 ordering to the save snapshot on top of this exact head. It keeps all 256 new keys at the front, fills the remaining slots with earlier keys in their saved order and keeps the 65,536 limit. The nine pipeline library and worker tests passed, including the capacity and save-file tests. Strict library Clippy and the asset policy passed. All-target Clippy flags a missing safety comment in the base's adapter test in
host.rs:267.wbkepler can use the commit when rebasing the warmup and background-save changes.
Please retain the Git authors on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding this change into another commit.AI-assisted with OpenAI Codex.
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.