Repository navigation
Conversation
Batch title_memory_aliased across xmem::map with an early return when unaliased, coalesce VirtualProtect(PAGE_READWRITE) runs in open_runs with per-page fallback across unmapped holes, unify Tracked's changed/saved state into one lock via begin_copy_back, reuse a caller-owned 64 KiB scratch buffer across copy_back_marks/copy_back_page, and batch Tracked::taken per contiguous Shadow run. Assisted-by: T3 Code (Antigravity, gemini-4-neon)
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-gpu --lib watch::— 8 passed, 0 failedcargo clippy -p victory-gpu -p victory-hle --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean batching of watch GUARDS locks, VirtualProtect runs, and shadow copy-back. Looks great.
AI-assisted (Gemini 4 Neon).
…tory #2169) Port of Marvisak/VIctory#2169 by RVZO6 (GPL-3.0-or-later), adapted to our tree (armed runs from #2147, withheld ranges from #1998): - watch.rs: one lock per tracker (`ChangedState`: changed pages, armed runs, saved bytes) so a copy-back disarms, takes saved bytes and checks the page once; `title_memory_aliased_batch` links a whole map() under one GUARDS lock with a zero-lock early return; `open_runs` coalesces VirtualProtect(PAGE_READWRITE) per contiguous run, falling back per page; `Tracked::taken` sorts and dedups its pages. - xmem.rs: one batched `title_memory_aliased_batch` per `map()`, not one call per page. - shadow.rs: one 64 KiB scratch buffer reused across copy-back loops, and `taken` queued per contiguous Shadow run instead of per page; unchanged guarded pages are left alone so a racing title write is not cleared. - New tests: batched aliasing fault propagation, open_runs across unmapped holes, and batched copy-back (scratch reuse, racing write). Assisted-by: T3 Code (Antigravity, gemini-4-neon)
|
Audited head Baseline tests pass (
(Proposed / uncompiled fix direction:) re-guard each written page immediately in one AI-assisted; synthetic tests only, no game files, dumps, or captures used. |
|
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head AI-assisted (Claude Code); no game data. |
…and snapshot before opening Addresses all three review findings on Marvisak#2169: - Replace deferred t.taken(&batch) in Shadow::copy_back_marks with Writing::finish_taken, which removes the busy range, notifies other holders/aliases, re-guards the written full page and its aliases, and clears it from tracked.changed under one GUARDS lock immediately after write_mapped (also used in copy_back_page). Previously opened unchanged pages stay in changed.pages so concurrent CPU writes are never lost. - Propagate read-only guards transitively across chained aliases in title_memory_aliased_batch via a worklist over g.alias_of (handling both forward and reverse chains in one GUARDS lock). - In watch::changed, mark/snapshot armed holders before removing read-only guards on [first, last) or aliases, and use a 16-entry stack buffer in open_runs, open_range, and changed to avoid heap allocation on the VEH fault path. - Add regression tests covering concurrent CPU writes immediately after page 0 copy-back, unchanged previously-opened pages, and forward/reverse chained aliases in title_memory_aliased_batch. Assisted-by: T3 Code (Antigravity, gemini-4-neon)
…and snapshot before opening Addresses all three review findings on Marvisak#2169: - Replace deferred t.taken(&batch) in Shadow::copy_back_marks with Writing::finish_taken, which removes the busy range, notifies other holders/aliases, re-guards the written full page and its aliases, and clears it from tracked.changed under one GUARDS lock immediately after write_mapped (also used in copy_back_page). Previously opened unchanged pages stay in changed.pages so concurrent CPU writes are never lost. - Propagate read-only guards transitively across chained aliases in title_memory_aliased_batch via a worklist over g.alias_of (handling both forward and reverse chains in one GUARDS lock). - In watch::changed, mark/snapshot armed holders before removing read-only guards on [first, last) or aliases, and use a 16-entry stack buffer in open_runs, open_range, and changed to avoid heap allocation on the VEH fault path. - Add regression tests covering concurrent CPU writes immediately after page 0 copy-back, unchanged previously-opened pages, and forward/reverse chained aliases in title_memory_aliased_batch. Assisted-by: T3 Code (Antigravity, gemini-4-neon)
|
Thanks @nathanbzrr for the thorough RX 7600 repros — all three findings are fixed in
Verified on fork AI-assisted: T3 Code (Antigravity, gemini-4-neon) |
On CPU-heavy frames and physical/tiled memory mappings, write-watch maintenance and marked-page copy-back incur avoidable global lock churn, per-page
VirtualProtectsyscalls, and per-page 64 KiB scratch allocations:xmem::mapcallstitle_memory_aliasedin a loop per 64 KiB page — locking globalGUARDSeven whenshownis empty (the common unaliased case) and callingprotect(&mut g, &[page])one page at a time.Tracked::drop,changed, andchanged_herecallVirtualProtect(..., PAGE, PAGE_READWRITE, ...)one page at a time instead of coalescing contiguous runs.Shadow::copy_back_markedacquiresTracked's mutexes three times per page (unarm,saved,changed), allocates a freshvec per page, and locksGUARDS+ callsVirtualProtectper page viat.taken(&[page / PAGE]).The change
crates/victory-gpu/src/watch.rs&crates/victory-gpu/src/lib.rs:title_memory_aliased_batch(with zero-lock early return when no entry has aliases;title_memory_aliaseddelegates when!others.is_empty()), linking aliases under oneGUARDSlock and callingprotect(&mut g, &to_protect)once (sorting & deduping inprotect).open()withopen_runs(), coalescing consecutive pages into oneVirtualProtect(PAGE_READWRITE)per run with per-page fallback across unmapped holes or distinct reservations.Changed's two mutexes into oneMutex<ChangedState>, addingTracked::begin_copy_back(page)(single lock for disarm + take saved bytes + changed check) andChanged::mark(page, save).crates/victory-hle/src/modules/xmem.rs: calltitle_memory_aliased_batchonce permap()instead of per page.crates/victory-gpu/src/shadow.rs&crates/victory-gpu/src/memory.rs:page_scratch) acrosscopy_back_marksandmemory::bind'scopy_back_pageloop.t.taken(&batch)per contiguousShadowrun incopy_back_marks, queuing only written or previously opened pages so unchanged guarded pages keep their guard and never clear a concurrent CPU write arriving afterbegin_copy_back.VirtualProtect/ twin-section tests:watch::tests::title_memory_aliased_empty_and_batch_propagate_faults,watch::tests::open_runs_coalesces_and_falls_back_across_unmapped_holes, andshadow::tests::batched_copy_back_reuses_scratch_batches_taken_and_rearms.Not a duplicate of
#2147changesSaved::armedfrom aBTreeSet<usize>to page runs (Tracked::arm/unarm); it does not batchtitle_memory_aliased, coalesceVirtualProtectinopen_runs, unifybegin_copy_back, reuse copy-back scratch buffers, or batchTracked::taken. If#2147merges first, this rebases cleanly onto itsarmedruns representation.#2136skips requesting unchanged host copies at submission and is orthogonal to marked-page copy-back and watch batching.Tested
windows-latestMSVC + Windows WARP SM 6.6 CI on fork integration stack (Run 45562558052):cargo clippy --workspace --all-targets --locked -- -D warnings: clean.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.cargo test --workspace --locked: 712 passed, 0 failed, 10 ignored, includingvictory-gpu152 passed, 0 failed, 2 ignored,victory-hle143 passed, 0 failed (all 10modules::xmem::tests::*), andxtask(6 passed, 0 failed,repository_passes_policy).c5a9547:cargo clippy(default &--all-features)-D warningsclean; Wine-10.0 passedwatch/shadow(13 passed, 0 failed) andxmem(10 passed, 0 failed).Not run: the title; any hardware GPU (CI ran on Windows WARP only). The title was not used in these tests.
AI-assisted: T3 Code (Antigravity, gemini-4-neon)