Repository navigation
Conversation
… own (VICTORY_BACK_OWN_VIEW=1) A marked page's copy-back opened the title's guard (VirtualProtect under the guard lock) and guarded it again after, taking the guard lock three times a page, strictly one page at a time, while the title threads' faults wait for the same lock. View memory is a section (xmem's physical pages): the runtime now tells the GPU side about its sections and views, and with VICTORY_BACK_OWN_VIEW=1 the GPU side maps a view of its own of each whole section. A marked page the title has not written since the copy took it goes back through that view: the title's view keeps its guard, nothing is opened or guarded again, and the guard lock is taken twice a page with no system call under it, to mark the page busy and its other trackers (and those of its other mappings) changed. A title write meanwhile still faults and marks the writer's tracker too, as does a write that did not land: such a page is left for the next refresh. Pages the title wrote before, and private memory, go as before. Off unless asked for. Diagnostics: an "own view" line with the pages written beside the guards, those the title wrote meanwhile, and those in memory with no view of ours.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relation to #3069
This overlaps with #3069 by moe-miau (
VICTORY_COPY_BACK_BESIDE), which uses the same mechanism: a marked page goes back through a second view of its section, so the title's guarded view is never opened. Either this PR or #3069 should be merged, not both. If #3069 is merged, this PR becomes obsolete and I will close it.We wrote this version independently and measured it in game, so I am opening it mainly for the numbers. The differences I can see:
watch.rs, with its own lock, taken before the guard lock). xmem only reports sections and views through three hooks. GPU, HLE: marked pages go back beside the guards (VICTORY_COPY_BACK_BESIDE, opt-in) #3069 writes under xmem's mapping lock through a registered page writer.Problem
After a submission, each marked page goes back into title memory in
Shadow::copy_back_marked.watch::writingopens the guard (VirtualProtectunder the guard lock),host::write_mappedwrites the page, andTracked::takenguards it again. That takes the guard lock three times per page, strictly one page at a time, and the title threads' faults wait for the same lock. In the world, the "back" part of the frame was about 70 ms.Change
With
VICTORY_BACK_OWN_VIEW=1:victory-hlexmem.rs: reports each section it makes for physical pages (title_memory_section), each view it maps of one (title_memory_view), and the section's drop (title_memory_section_gone).victory-gpuwatch.rs: maps one read-write view of each whole section and keeps the title's views of it by address.Tracked::write_besidewrites through that view when the range lies in one known title view:writing, so no tracker takes it.writingdoes) and after it (as its drop does).shadow.rscopy_back_marked: useswrite_besidefor pages with no saved bytes and takes the old path otherwise. Private memory (XMemVirtualAllocpools) has no second view and goes the old way.host.rs:write_mappedreports whether every byte landed.copystat.rs(diagnostics only): an "own view" line with the pages written beside, the ones the title wrote meanwhile, and the pages in memory with no view of ours.The switch is off by default. With the variable unset, no section is mapped and nothing is recorded.
Tested
Windows 11 Pro 26200, RTX 3070 8 GB (driver 610.88), title 1.0.2.1, release +
diagnostics, BVH on,VICTORY_BACK_THREADS=4. 480 s runs in A-B-A order, same shader cache.mainalone cannot be measured on this card: it runs at 0.1 fps because the view heap overflows without #1779. The numbers therefore come from our test stack, an older main plus open NVIDIA PRs (among them #1762, #1779 and #2242/#2280/#2409). On that stack, copy-back compares 32-byte lines instead of whole pages, so the code around it differs frommain'scopy_back_marked; the write-beside part is the same. The variable was the only change between A and B:VICTORY_BACK_OWN_VIEW=1Unit tests (synthetic, no game data):
watch::copy_backs_beside_the_guard_keep_it_and_the_titles_writes: a pagefile section mapped twice as title views. It checks that:PAGE_READONLYwatch::writes_beside_reach_pages_committed_through_the_titles_view: aSEC_RESERVEsection like xmem's. A page committed only through the title's view is written. A page committed nowhere is not written and is left changed.shadow::marked_pages_of_view_memory_go_back_beside_the_guard: goes throughcopy_back_marked. A clean page goes beside and stays guarded. A page the title wrote first goes the old way with both bytes kept.Checks on this branch (
origin/main63bcca4 + this commit), RTX 3070:cargo test -p victory-gpu --release -- --test-threads=1: 247 passed / 2 failed withdiagnostics, 232 passed / 2 failed without. The two 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 --release: 152 passed.cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings: clean with and withoutdiagnostics.cargo xtask policy: ok.Not addressed
AI-assisted.