GPU: the skipped host copies are counted, and the last tracker of twin mappings opens both #2136
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!2136
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2136"
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?
@r4tedx on GitHub · 2026-11-25 05:49 UTC · original
r4tedx:gpu/skip-unchanged-copies→main· +73 −6 · 2 files · 3 commits · openScope changed with the merge of
main63bcca43(adf58010).mainnow skips a host copy nothing wrote on its own (19533398f,Shadow::clean), and has two of the threewatch.rsalias fixes this PR carried (136e39d09,384b0c0b9). What is left againstmainis two small things:1. The
skippedcounters count againmain'scopies per frameline printsskipped, but nothing onmainincrementsC::SkippedorC::SkippedBytes, so a run onmainalways shows 0 skipped even thoughBatch::addreturns early for every clean copy. This PR counts each early return (diagnosticsonly) and adds the testa_copy_nothing_wrote_is_not_asked_for(host.rs,mod batch), which checks that a clean copy is left out and that a guarded write or a reported write brings back only the page written.2. The last tracker of twin mappings opens both
Tracked::droponmainkeeps mappingaguarded while another mappingbof the same memory still has a tracker. Whenb's tracker then goes, onlybis opened, andastays in the guard set with no holder. That breaks the rule that the guard set never names memory that was freed and allocated again. The fix makesdropalso consider the other mappings of each page it frees, and opens each one that nobody holds on any mapping.openalready does nothing for a page that is not guarded. Test:the_last_tracker_of_twin_mappings_opens_both(watch.rs). The test was not run againstmain.Diff against
main:host.rs+46,watch.rs+33/−6.Checked (synthetic only, no title data)
On
adf58010, Windows 11, WARP, one test thread:cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1: 248 passed, 0 failed, 1 ignored.cargo clippy --locked -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.The earlier preparing-time figures in this PR's history (225.1 → 100.8 ms in the #2134 benchmark, and the in-game counters) measured the skip that
mainnow has. They no longer describe what this PR changes againstmain.AI-assisted.
@yualk on GitHub · 2026-11-25 06:13 UTC · original
Independent locked MSVC
diagcomparison of940d32f69vs937f329a4on Windows / RTX 5070 Ti10de:2c05and WARP1414:008c. An owned productionHost::executecontrol records actual GPU buffer-to-readback copies: cold partial + later full refresh, untouched, watched CPU store, ordered deferred title copy followed by refresh, and rearmed CPU store all return the exact expected words on both pins and both adapters; the independent same-shaped decoy is unchanged. In the untouched arm the two watches drop to zero with two skips.With the exact #2134 workload and the same test-only counters in both trees, 2 warm-up + 5 scored frames/process in A–B–B–A order: RTX paired preparing medians 147.6→51.1 ms and 123.6→46.2 ms; explicit WARP 129.2→55.5 and 133.7→53.4 ms. Median checks 274,094→1,325 in both adapters. At each scored frame the checked-minus-unchanged bytes, requested bytes/count, guard/protect/open counts, snapshot bytes, marked pages/returned bytes, and title-copy count were equal. Same-pin RTX drift was visible, so these are directional synthetic results, not a precise speedup estimate or gameplay FPS. No title, textures, real shader workload or title threads writing concurrently with preparation in this replay.
@r4tedx on GitHub · 2026-11-25 06:35 UTC · original
@catminou4 on whether the tracking covers every write path: the skip reads the same thing the refresh read.
Tracked::unchangedis the size of the very setTracked::taketakes its pages from, kept under that set's lock, so a copy is left out exactly when its refresh would have found no page to copy. A write the trackers do not see (one that neither faults into the guard handler nor is reported throughwriting/title_memory_remapped) was not copied before this change either; this PR neither widens nor narrows that. Memory that is not tracked is never skipped.#1963 is the other direction (what shaders wrote going back into title memory); it does not change which title writes a refresh sees.
Thanks to @yualk for the independent run above: its read-back control (cold, untouched, a watched CPU store, a title copy followed by a refresh, a re-armed store returning the expected words on both builds) is a check I did not have, and its counters match mine (274,094 → 1,325 checks, everything else equal).
Nothing new was run for this comment. The title was not used in these tests.
AI-assisted
@nathanbzrr on GitHub · 2026-11-25 08:40 UTC · original
Verified head
937f329a4987918f38890ff9fe010c40710e6437merged with #2134 (efb35b56) ontomain(940d32f69b) on Windows 11 x64 / AMD Radeon RX 7600:Hardware Benchmark (
world_frame_preparing, 2 trials/config)preparing, ms(T1 / T2)copying back, ms(T1 / T2)change checkschecked, MBchanged (copied), MB940d32f + #2134(RX 7600)940d32f + #2134 + #2136(RX 7600)940d32f + #2134 + #2136 + #2147(RX 7600)940d32f + #2134 + #2136 + #2147(WARP)All 145
victory-gpulib tests pass (--test-threads=1). PR #2136's ownAtomicUsizecount + RAIIDropupdate is sound (Pages::dropupdatesAtomicUsizewithReleasewhileMutexGuardis still held).Pre-Existing
watch.rsAlias Bugs Exposed / Amplified byunchanged()Two live synthetic repros against
940d32f + #2136fail as predicted:Tracked::dropstripsPAGE_READONLYfrom live sibling aliases (watch.rs:255-275): Dropping trackertaover viewasees emptyholders[a]and opensatoPAGE_READWRITE, ignoring live alias trackertboverb. Writes viaastop faulting ->tb.unchanged() == trueandtb.take(b) == [](reprodropping_one_alias_tracker_keeps_live_alias_guardedpanicked).writing(a)vstb.take(b)marksbclean (watch.rs:199-202, 323-335):guard_aliasesignoresprotectfailure whenaisbusy, andtb.take(b)still clearsb->tb.changed(b/PAGE) == falseandtb.unchanged() == truewhileastays unguarded (reprotaking_alias_while_other_mapping_is_busy_keeps_page_changedpanicked).changed_here(watch.rs:480-492) callsopen()(PAGE_READWRITE) beforec.pages().insert(page)(which updatesChanged.2) andc.save(page), leaving a concurrency window where another CPU thread writes without faulting whileunchanged()reads0.(Proposed / uncompiled fix direction:) keep
aguarded inTracked::dropwhenever any alias still has holders; propagateprotectsuccess from aliases toChanged; mark dirty & save beforeopen()inchanged_here.AI-assisted; synthetic tests only, no game files, dumps, or captures used.
@r4tedx on GitHub · 2026-11-25 09:02 UTC · original
@nathanbzrr thank you, all three findings hold. Pushed as
f85763e0on top of937f329(fast-forward, no rebase). Onlycrates/victory-gpu/src/watch.rschanges.Bugs 1 and 2 are already on
main940d32f. #2136'sunchanged()makes them easier to see but did not cause them. On940d32f, with only theunchanged()asserts removed, both of your repros still fail attb.changed(b / PAGE).Tracked::drop: a page is opened only when no tracker holds it on its own mapping or on any other mapping of the same memory. When the last tracker is gone, all the mappings are opened.guard_aliases: it now returns the pages whose other mapping could not be guarded (busy, or protect failed).take()andtaken()leave those pages changed, as they already did for a busy page on the tracker's own mapping.changed(): every tracker, including trackers of the other mappings, is marked and its bytes are saved while the pages are still read-only. Only then are the pages opened. The marking moved into a new helpermark(), which replaceschanged_here. Lock order is unchanged.Both of your repros are now tests (
dropping_one_alias_tracker_keeps_live_alias_guarded, which also checks that both mappings are opened at the end, andtaking_alias_while_other_mapping_is_busy_keeps_page_changed). They fail on937f329and pass onf85763e0. There is no test for the ordering in 3, because a single-threaded test can't hit that race.Verified:
cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1on WARP: 150 passed, 0 failed, 2 ignored.Still open, not new in this PR: alias links are one hop only. A third mapping linked only to
awould not be marked by a write throughb. This assumes the runtime reports every other mapping, which is what it does today.AI-assisted; synthetic tests only, no game files, dumps, or captures used.
@r4tedx on GitHub · 2026-11-25 09:59 UTC · original
In-game counters from one PC: RTX 5070 (driver 616.92), Ryzen 7 7800X3D (max processor state 99 %), Windows 11, diagnostics builds,
VICTORY_LOG=info VICTORY_D3D12_DRED=1. The title was run locally from my own copy. Only counts and timings are given here; no logs or title data are shared.This is not a same-frame A/B:
main940d32f+ #1763 (needed to boot on NVIDIA).f85763e0together with about 25 other PRs, among them #2147f2ca0868, #1819, #2118 and the wave64 stack.The scenes are different moments of the opening. Only the counters this PR controls mean much; the frame times can't be attributed to it.
copies per frame:, a late world frame of each run:main), and watch work and MB checked fall by about 10-50x.AI-assisted
@Marvisak on GitHub · 2026-11-25 10:50 UTC · original · edited 2026-11-25 15:58 UTC
Automated triage for the maintainers.
This pull request no longer merges cleanly into
main(conflicts incrates/victory-gpu/src/host.rs,crates/victory-gpu/src/shadow.rs,crates/victory-gpu/src/watch.rs). It will be reviewed once it is rebased onto the currentmain. The earlier verdict (merge-candidate) was for an older state ofmain.Generated by Claude Code
GPU: a host copy nothing wrote is not asked for at submissionto GPU: the skipped host copies are counted, and the last tracker of twin mappings opens both63bcca43) into gpu/skip-unchanged-copies adf580100d@DenRakEiw on GitHub · 2026-11-25 06:02 UTC · original · approved these changes
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):cargo test -p victory-gpu --lib a_copy_nothing_wrote_is_not_asked_for— passed on RTX 5090cargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean
unchanged()fast-path skipping submission refresh copies when nothing wrote to the tracked range. Looks great.AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 06:33 UTC · original · reviewed
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Host copies nothing wrote not requested at submission — avoids redundant copies; check the dirty-tracking covers all write paths (#1963's write-scope tracking related).
@r4tedx on GitHub · 2026-11-26 10:18 UTC · original
Merged
main63bcca43in asadf58010, pushed as a fast-forward with no rebase or force-push. That answers the needs-rebase triage.Conflicts in
shadow.rs,host.rsandwatch.rswere resolved in favour ofmain.mainalready skips host copies nothing wrote (19533398f), so this PR's own skip andShadow::unchangedare gone. The two alias fixesmainalready has (136e39d09,384b0c0b9) were dropped too. Left againstmain: theskippedcounters, whichmainprints but never increments, andTracked::dropopening both twin mappings once neither has a tracker. Each has a test. I rewrote the title and description to match.Checked on WARP, Windows 11, one test thread: victory-gpu
--features diagnostics --lib248 passed, 0 failed, 1 ignored; clippy-D warningsclean;cargo xtask policy191 files ok. Synthetic tests only, no title data.AI-assisted.
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.