victory-gpu: skip redundant guard_ahead when ask_first already ran #460
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/460"
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 readmet3xt-lab/foxhound. Originally posted by kwaadrat on 2026-12-02T12:54:04Z.
When
VICTORY_ASK_FIRST=1andVICTORY_GUARD_FIRST=1(both on by default),ask_firstalready runsguard_ahead(&guarded)on a background thread in parallel withask_once.Previously, after
first.wait(),Host::submitunconditionally calledguard_ahead(&batch.guarded)a second time on the submitting thread, even whenbatch.copy_spanswas not re-run and no flights were awaited (!waited_for_flights && !settled_for_sweep).Change
guarded_fromincrates/victory-gpu/src/host.rs:copy_walk_onceis enabled,asked_first.is_some(),batch.spans_steps == others,guard_first()is true, and!waited_for_flights && !settled_for_sweep, only guard any newly appended entries frombatch.copy_spans_first(own.list())(&batch.guarded[guarded_from..]), skipping the redundant fullguard_aheadcall when nothing new was added.Verification
Measured on Linux (Proton Experimental /
vkd3d-proton, NVIDIA RTX 3060 12 GB, Intel i5-9600KF 6c/6t, Series S profile, 1080p,VICTORY_GUARD_PAGES=1,VICTORY_JOURNAL_SHORT=1,0 being madesteady state):asking the write watch:37.5–65.3 ms/frame->11.6–11.9 ms/framepreparingtotal on submitting thread:125–186 ms/frame->49.2 ms/frameImported from readmet3xt-lab/foxhound. Originally posted by GValdezN on 2026-12-02T16:50:57Z.
Clean approach — capturing
guarded_from = batch.guarded.len()beforecopy_spans_firstand slicingbatch.guarded[guarded_from..]avoids the redundantguard_aheadwithout changing the fallback path. The conditions (guard_first() && !waited_for_flights && !settled_for_sweep) correctly identify whenask_firstalready covered the full set.One thing to verify:
batch.guardedis only appended to between the two hunks (no truncation/reorder), which looks correct from the surrounding code but worth confirming sinceguarded_fromis a positional index.This complements our prefetch + Vec::with_capacity work in #478 — both reduce submit-thread overhead on different phases. No conflict expected.
Imported from readmet3xt-lab/foxhound. Originally posted by kwaadrat on 2026-12-02T20:33:10Z.
Thanks for reviewing! Confirmed in
crates/victory-gpu/src/host.rs:copy_spans_first->copy_spans_first_steps->copy_spans_stepsonly callsself.guarded.push((from, to))(it never clears, truncates, or reordersself.guarded;self.guarded.clear()is only called inBatch::put_backandBatch::copy_spans).guarded_fromandcrate::watch::guard_ahead(&batch.guarded[guarded_from..]),batch.guardedis not touched at all (onlybatch.rangesis updated andask_once/ask_moreare called).So
guarded_fromremains a valid positional slice start for the newly appended entries fromown.list().Imported from readmet3xt-lab/foxhound. Originally posted by tillo88 on 2026-12-02T21:05:57Z.
Replay-bench measurement: no measurable difference on v0.8.3.3
Measured: PR head
ab905fbmerged onto release v0.8.3.3 (same code as main7dbcdcb), 2 measured runs (after a warm-up run that is not counted), against 3 runs of v0.8.3.3 without the PR, same route (~6.5 min).Mean fps: release 36.38, PR 36.43 (+0.1%). That is below the 2-3% we treat as a real change, so: no measurable difference on this route. Only 3 release runs so far, so the release's own spread is not established yet.
Crashes: none in the PR runs and none in the release runs (no host GPU failure, no device lost).
Note: two earlier release runs the same evening, with identical switches, were much slower for most of the route (6-9 fps average); the cause is not known yet and they are left out of the comparison above. No PR run fell into that state.
Config: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, 32 GB, Windows 11; default
play-foxhound.ps1settings (Series X profile, 1440p, DLSS balanced, no frame generation), fullscreen, no frame cap.Measured unattended on a replay bench (same save, recorded controller input); numbers and text prepared with Claude.
Imported from readmet3xt-lab/foxhound. Originally posted by kwaadrat on 2026-12-02T21:16:34Z.
Thanks a lot for running the replay-bench measurement, @tillo88!
That makes total sense on a 9800X3D + native Windows 11 — when
guard_aheadhits already-guarded pages on native NT, the syscall cost is small enough to sit within run-to-run noise. On slower CPUs and especially under Wine/Proton on Linux (whereVirtualProtectcrosses the Wine/kernel boundary), skipping the redundant pass has a much more noticeable impact, while still keeping the Windows hot path slightly leaner with zero regression.Imported from readmet3xt-lab/foxhound. Originally posted by GValdezN on 2026-12-02T21:20:21Z.
Why the replay-bench shows no measurable difference (hypothesis)
The optimization in this PR activates when all five conditions hold together:
copy_walk_once()= trueasked_first.is_some()(the ask_first thread ran)batch.spans_steps == others(steps didn't change)guard_first()= true!waited_for_flights && !settled_for_sweepWhen all are met, before this PR
guard_aheadwas called on the fullbatch.guardedset redundantly (the ask_first thread had already done it). The PR changes it to only guard newly appended entries (guarded[guarded_from..]).But look at what
guard_aheaddoes internally (watch.rs:3679–3694):published()ahead_contains)Most likely explanation: On tillo88's config (RTX 5070 Ti, 1440p, Series X), by the time the submitting thread reaches the second
guard_aheadcall, the ask_first thread has already finished and marked everything as published. Soguard_aheadhits the early return on thepublished()filter — the redundant call is cheap because there's no real work left.On the author's config (RTX 3060, 1080p, Series S), the GPU is slower, there's more CPU pressure, and the ask_first thread likely hasn't finished when the submitting thread reaches the second
guard_ahead— so the pages aren't published yet, the filter doesn't discard them, andguard_aheaddoes real work: materialize, install, hold askings, etc. That's where the 37–65 ms cost comes from.In short: the difference between the two configs isn't that the optimization doesn't work — it's that on faster hardware the redundancy was already "free" because
guard_aheadself-short-circuits when the background thread has already published everything. On slower hardware there's a timing window where both calls do real work.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.