Repository navigation
Conversation
…ESIDE) After a submission, each 64 KiB page that shaders marked as written goes back into title memory: its guards are opened, the kernel copies the page in, and the page is guarded again. With VICTORY_COPY_BACK_BESIDE=1, a page that a view of physical pages shows is written through a view of our own of the whole section instead, which no guard covers: the title's views stay guarded and show the new bytes (the same pages), with no protection calls, no first-write faults and no kernel write. The write runs under the mapping lock, so no view there changes meanwhile. The page and its other mappings are marked changed in their trackers before (armed ones save their bytes) and after the write, as around a kernel write. Other memory goes back as before. The idea is avatarmanz/VIctory-7900XTX's landing beside the guards (commits 66afb2b, 0d5e4c8, 2c982ee, GPL-3.0-or-later); this is a new, smaller implementation on main, not their code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dukestar69
left a comment
There was a problem hiding this comment.
Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):
- Diff review: Opt-in
VICTORY_COPY_BACK_BESIDEwrites marked pages back through separate physical-page views without disarming/rearming title write-watch guards, preserving guard protection while still marking trackers. cargo test -p victory-gpu watch::tests -- --test-threads=1: 16 passed, 0 failed (includinga_write_beside_keeps_the_guards_and_marks_the_trackers).cargo test -p victory-gpu shadow::tests -- --test-threads=1(RTX 5090): 9 passed, 0 failed.cargo test -p victory-hle xmem::tests -- --test-threads=1: 13 passed, 0 failed (includingwrites_beside_land_through_guarded_views).cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
kotekompotek
left a comment
There was a problem hiding this comment.
Verified both halves: Section::whole lazily maps an unguarded full-section view (unmapped on Drop); write_beside resolves at->whole offset under the physical() lock (checked_add bound) so no remap mid-write; write_through marks pages+aliases changed with save before the write and again after (a tracker taking the page mid-way reads it), matching the writing-window semantics without opening any guard; fallback to writing+write_mapped preserved; opt-in env. Both tests use real sections+VirtualProtect and discriminate.
fuzeofficlal
left a comment
There was a problem hiding this comment.
Tested locally on Windows 11 x64 (rustc 1.98.1, RTX 5090 + WARP):
cargo clippy -p victory-gpu -p victory-hle --all-targets --locked -- -D warnings(default and--all-features): clean.- RTX 5090 (default and
VICTORY_COPY_BACK_BESIDE=1):victory-gpuwatch::tests(16 passed),shadow::tests(9 passed);victory-hlexmem::tests(13 passed). - WARP (
--features diagnostics,VICTORY_D3D12_WARP=1,VICTORY_COPY_BACK_BESIDE=1):watch::tests(16 passed),shadow::tests(9 passed). cargo xtask policy: 191 files ok.- Verified lock ordering (
PHYSICAL -> GUARDSmatchesxmem::map/xmem::unmap, noGUARDS -> PHYSICALpath) and confirmed with a standalone Windows 11SEC_RESERVEprobe that committing a new page viaVirtualAlloc(MEM_COMMIT)on aMapViewOfFile3title view afterSection::whole()was already mapped immediately makes that pageMEM_COMMIT | PAGE_READWRITEin the cachedwholeview without faulting.
One concurrency gap in crates/victory-gpu/src/watch.rs (write_through) should be tightened before merge:
-
Missing
g.busytracking across the unlockedcopy_nonoverlappingwindow (watch.rs:102-111):
Unlikewriting()(watch.rs:806),write_throughreleasesGUARDSaftermark_with_aliases(..., true), copiesbyteswithout(first, last)ing.busy, and then re-acquiresGUARDSformark_with_aliases(..., false). Because the pages remain ing.protectedand are not marked busy, a concurrentTracked::take()/take_split()/taken()on the page or an alias (which the doc comment onwrite_besideanticipates, and which becomes reachable alongside parallel copy-back like #2914) succeeds during the copy:Shadow::update_trackedcan read torn mid-copy bytes viacopy_mappedwhilecopy_nonoverlappingis writing the same physical page; andwatch.rs:517callsself.changed.taken(page), which dropssaved.bytes[page]on an armed tracker—breaking the invariant guarded bywatch::tests::a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes. Whenwrite_throughthen runsmark_with_aliases(..., false), the page is re-marked changed withsaved == None, causing a subsequentShadow::copy_back_markedto drop GPU writes on that page (MarkedKept).
Pushing
(first, last)intog.busyunder the firstguards()lock and removing it (via a small drop guard) under the secondguards()lock closes both races cleanly with minimal overhead.
Minor non-blocking polish:
crates/victory-gpu/src/watch.rs:103: handlebytes.is_empty()early and useat.saturating_add(bytes.len()).div_ceil(PAGE)to matchwriting()(watch.rs:804) and avoid marking a page on an empty unaligned write or overflowing nearusize::MAX.crates/victory-gpu/src/shadow.rs:522:writtencan beOption<&[u8]>((&*host)/title.as_slice()) directly, avoiding the raw pointer round-trip and extraunsafefrom_raw_partsblock.
|
Automated triage for the maintainers. Verdict: merge candidate. With What I checked against main:
CI: Generated by Claude Code |
What
After a submission, every 64 KiB page shaders marked as written goes back into title memory in
Shadow::copy_back_marked. Each page opens its guards (watch::writing), gets copied in by the kernel (host::write_mapped), then is guarded again (Tracked::taken). On the stack below that is about 2,250 pages a frame, 45 ms of a 60 ms copy-back: two protection changes per page, first-write faults on the newly writable page, and a kernel copy.With
VICTORY_COPY_BACK_BESIDE=1, a page that a view of physical pages shows is written through a view of our own of the whole section instead (xmem::write_beside, whichvictory_gpu::use_page_writerregisters). No guard covers that view. The title's views stay guarded and show the new bytes, since they are the same pages. No protection calls, no first-write faults, no kernel write.PHYSICAL), so no view there is mapped, unmapped or freed while it happens. The lock order PHYSICAL → GUARDS is the onemap/unmapalready use, when they calltitle_memory_remapped/title_memory_aliased.alias_of) are marked changed in every tracker holding them. The first mark comes before the write: armed trackers save their bytes. The second comes after it, for a tracker that took the page in between.changed()now shares that marking throughmark_with_aliases. The copy's own tracker is unarmed first and taken afterwards, as before.The switch is off by default: nothing changes unless it is set.
The idea comes from avatarmanz/VIctory-7900XTX's landing beside the guards (66afb2b, 0d5e4c8, 2c982ee; GPL-3.0-or-later). This is a new, smaller implementation on
main, not their code. It has no dword merge or worker pool. It works alongside #2914, which spreads the same loop over threads.Measured
RTX 4070 SUPER, Windows 11. Local stack: main + #2464 + #2098 + #2626 + #2628 + #2711 + #2851 + #2705 + #2925 + #2958, with
VICTORY_CARD_COPIES=1andVICTORY_WAVE32_APPROX=1. Prologue cell, medians of the 5 s reports from 540 to 900 s of a 15-minute run (about 62 reports each):Tests
watch::tests::a_write_beside_keeps_the_guards_and_marks_the_trackers: three views of one section, two of them title mappings with trackers (one armed). A write beside leaves both mappingsPAGE_READONLY, shows in both and marks both trackers. The armed one keeps the bytes from before. A writer that cannot write marks nothing.xmem::tests::writes_beside_land_through_guarded_views: a write lands through a read-only title view and shows at the page's other mapping. A range past a view, or private memory, is not written.cargo test -p victory-gpu --lib --locked: 230 passed. The 2 failures are the known heap-size pair on NVIDIA (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views), which fail onmaintoo.cargo test -p victory-hle --lib --locked: 153 passed.cargo clippy --workspace --all-targets --locked -- -D warningsandcargo xtask policyare clean.AI-assisted (Claude Code). Runs done on my machine.
🤖 Generated with Claude Code