GPU: a refresh batch takes the written pages of all its copies in one round of the guard lock #3585
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!3585
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3585"
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?
@neonbyte1 on GitHub · 2026-11-27 19:07 UTC · original
neonbyte1:pr/batched-refresh-take→main· +532 −87 · 4 files · 1 commits · openWhat's wrong
A submission's refreshes are batched per copy (
Batch,crates/victory-gpu/src/host.rs:2399), butBatch::flush(host.rs:2440) then brings each copy up to date on its own:shadow.update(from, to - from)per copy (host.rs:2447) →Shadow::update_tracked(shadow.rs:607) →Tracked::take_split(watch.rs:478). Each take with a written page in its range takes the global guard lock (watch.rs:503), guards the pages' other mappings, makes the pages read-only and drops them from the copy's changed set.The copies only ever read pages recorded as written, so the volume is small (~130 MB a frame here). The cost is the lock: a world frame makes one round of
watch::GUARDSper copy with written pages, 3,229 rounds a frame in our runs. The title's write-fault handler and marked copy-back hold the same lock, so these rounds mostly wait: 7.8 ms a frame inchange checks: … waiting for the guard lock, on the submitting thread, beforeExecuteCommandLists.(The
copies per frameline'sMB checked— 6.3 GB a frame here — is the span asked, not bytes compared:take_splitlooks only at the copy's set of written pages in it.)The fix
Batch::flushworks in three phases:shadow::plan→Tracked::written): for each copy, the written pages in its asked range, read under the copy's own set lock only. A copy with nothing written there stops here. Memory that is not tracked is copied whole, as before.shadow::refresh_planned→watch::take_written): the whole pages of all copies, sorted and deduplicated, in one hold of the guard lock. Each page's other mappings are guarded once, consecutive pages across copies share oneVirtualProtect, then each copy's set drops the pages taken.Shadow::copy_taken, the former tail ofupdate_tracked): per copy, one copy per contiguous run, zeros for unmapped runs, untracked parts whole, snapshot sync where this submission's shaders write.Tracked::take_splitis nowwritten+take_writtenfor one tracker, andShadow::updateisplan+refresh_plannedfor one copy, so there is one take and one refresh path. No switch: the guarantee is the one a single take gives (below), the existing take tests now run throughtake_written, and the change was measured in the title behind a switch first.Why no write is missed. A page leaves a copy's set only under the guard lock, once it is guarded at every mapping (pages that can't be guarded stay changed and are still copied). Copies are read after the take. So a title write before the guard is in the copy; a write after it faults and marks the page again. Writers that don't fault (kernel reads, DirectStorage, remaps, copy-back) mark under the guard lock, so before the page leaves the set (it's in the copy) or after (it's changed again). A page written between the look-up and the take isn't in the plan and stays changed. A page only partly in the asked range is copied in part and stays changed. The window between take and copy is longer than before, but correctness never depended on its length.
The copies line gets
N guard-lock roundsnext to the guard-lock wait (C::TakeRounds, diagnostics only).Run splitting looks up unmapped pages by binary search, removing the O(n²)
unmapped.containsthat #3156 also fixes.Tests
CPU only,
watch.rs:a_batched_take_takes_the_written_pages_of_every_tracker:batched_refreshes_under_concurrent_writes_lose_no_write:taken = whole): both tests fail;GPU, skipped without a device:
host::batch::overlapping_copies_in_one_batch_each_take_the_written_pages(two overlapping copies in one batch, each gets its written pages; a later write is seen by both). The existinga_copy_is_refreshed_once_per_submission_by_the_pages_writtencovers one copy.In the title
RTX 5090, Linux, GE-Proton11-14 Wine with its vkd3d-proton. Stack as listed in #3425, plus overlap and our pending early-release/barrier changes. Prison yard, diag build, two adjacent on/off pairs of the same exe (the change behind a switch there), 420 s each:
Pictures unchanged.
Related
VirtualProtectoutside it. This PR cuts the number of rounds instead; they compose, with a textual overlap intake_split.mainby the dirty bit.None of them batches takes across copies.
Verification
cargo clippy --workspace --all-targets -- -D warnings, with and without--features diagnostics(x86_64-pc-windows-msvc): clean.cargo xtask policy:asset policy: 191 files ok.origin/main.cargo test -p victory-gpu --lib watch::under Wine, with and withoutdiagnostics: 17 passed. Also passes on the default parallel test threads: the round and protection counts the batch test checks are per thread.left: (1, 0)andpage … differs from its copy and is not changed); the second fails the concurrent one.--test-threads=1, filtershost::batch:: shadow:: watch:: host::title_copies:: --skip shadow::run_tests): 31 passed, 0 failed. That ishost::batch2 (both batch tests),host::title_copies2,shadow::tests9 plus 1 othershadow::test, andwatch::tests17.AI-assisted (Claude); measured on my machine, no game data shared.
@pickles976 on GitHub · 2026-11-27 19:43 UTC · original
Offscreen Wine/NVIDIA verification of exact production
af08b8b11f28adeb1e355620cfa7ea20751e8491. Only local test-only changes make bothhost::batchfixtures require a physical NVIDIA DXGI adapter and successful host-copy allocation/mapping instead of returning early.cargo test -p victory-gpu --features diagnostics --lib -- watch::tests:: host::batch:: --nocapture --test-threads=1: 19 passed, 0 failed/ignored, 0.78 s after a fresh intended-worktree 9.08 s build.Coverage distinction: these tests initialize the real RTX 4060 Laptop D3D12 device and inspect persistent host-buffer mappings. They do not dispatch a shader or submit a GPU command list. This is guarding/copy-consistency coverage, not a GPU-execution, loading frame-time, contention, peak-RAM, or title performance measurement. I have not reproduced the separate RTX 5090 frame-time numbers or performed a matched parent benchmark here.
Environment: Linux 6.17, 16 GiB RAM, RTX 4060 Laptop 8 GiB/NVIDIA 590.48.1, Wine 11, NVIDIA masking disabled; diagnostic-relaxed-vtable vkd3d
2576c0b4adfae4a+(not stock certification). Original scope/global safeguards retained. Evidence:.compat-runtime/logs/verify-pr3585-batched-refresh-20261127T194039Z/(console, compilation provenance, result and resource samples). No production edits, title launch, imagery or assets published.AI-assisted verification.
@neonbyte1 on GitHub · 2026-11-27 19:45 UTC · original
@pickles976 thanks for checking the exact head on a second NVIDIA card, and for spelling out the coverage boundary: right, these fixtures exercise the guard/copy consistency with a real device's host mappings, not GPU execution. The frame-time effect is only from our 5090 runs (two adjacent pairs) and is stated as such in the description.
AI-assisted (Claude); no game data shared.
@andrewpozdnakov7-jpg on GitHub · 2026-11-27 19:56 UTC · original
I checked the diagnostics overlap with #3594. The exact heads
af08b8band377cd2dconflict on the counter array length. Tested pair keepsTakeRoundsand the three copy-back counters, deriving the array length from the final counter.On Windows WARP the same two-frame synthetic window printed one guard-lock round per frame and copy-back averages of 1.0 eligible, 0.5 wrote bytes and 1.0 withheld. The next window printed zero for all four figures. The existing synthetic byte checks passed, and the diagnostics suite passed 249 project GPU tests plus the SDK identity check, with one ignored.
Strict GPU Clippy passed for default and all features. The asset policy check passed.
@neonbyte1 and the maintainers can use the tested conflict resolution if both changes are applied. Please retain Git authors on cherry-pick or rebase. If you fold my work into another commit, please include
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.@neonbyte1 on GitHub · 2026-11-27 20:02 UTC · original
@andrewpozdnakov7-jpg thanks, that saves a rebase. I'll keep #3585 independent of #3594 (it's a one-line counter overlap, not a behaviour one); whichever lands second takes your
3cdd467resolution, with your authorship kept. If #3594 merges first I'll rebase #3585 onto it the same way.AI-assisted (Claude); no game data shared.
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.