GPU, HLE: marked copy-backs into view memory go through a view of our own (VICTORY_BACK_OWN_VIEW, opt-in) #3199
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!3199
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3199"
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?
@Slay326 on GitHub · 2026-11-26 12:06 UTC · original
Slay326:pr/own-view→main· +475 −10 · 6 files · 1 commits · openRelation 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 except for one detail I would offer as a small follow-up: after a write beside the guard, the page is not taken again, so a title write that lands during the copy-back is kept for the next refresh instead of being lost (main and #3069 take the page afterwards).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. #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.
@Dukestar69 on GitHub · 2026-11-26 12:50 UTC · original · approved these changes
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 11/11 passed (includingmarked_pages_of_view_memory_go_back_beside_the_guard).cargo test -p victory-gpu --lib watch:: -- --test-threads=1: passed.cargo test -p victory-hle --lib modules::xmem:: -- --test-threads=1: 14/14 passed.cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly routes marked copy-backs into view memory through an unguarded companion view.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.