Watch: unmapped view blocks are parked, not asked about at every check #812
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!812
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-812"
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?
@Peppacodes on GitHub · 2026-11-25 08:32 UTC · original
Peppacodes:vf/view-guard-parking→main· +398 −9 · 4 files · 1 commits · openThe guards' walk over a view range asks Windows (
VirtualQuery, throughuncommitted_end) about every block it noted absent, at every check. In the first room ~86,000-96,000 such blocks lie in the ranges host copies cover, nearly all of them 64 KiB placeholders, each its own region, so each question covers one block: ~88,000 questions a frame.Why this matters
main(9376fd6), and 20 ms on an integration branch of310c6eb.The fix (
crates/victory-gpu/src/watch.rs, behindVICTORY_VIEW_SET, on by default;VICTORY_VIEW_SET=0is the walk exactly as before)VirtualAlloc(MEM_COMMIT)into one fails. On title memory the only such call isxmem::map, which already callstitle_memory_remapped. So a block found uncommitted inside a placeholder is parked: it is not asked about again until it is remapped.VirtualQuerycannot tell a placeholder from an ordinary no-access reservation (same state, type and protection).QueryVirtualMemoryInformation(MemoryRegionInfo)can: flag bit 8 (placeholder reservation) is set on fresh, split and unmapped-to placeholders, and never on ordinary reservations. A one-time check on a placeholder of our own keeps the walk wherever the flag is not filled (Wine may not fill it).VICTORY_PARK_EPOCH).XMemVirtualAllocnow announces its commits (victory_gpu::title_memory_committed), so a commit through the runtime is seen at once. A commit nobody announces is seen within an epoch; the walk saw it at the next check.cleandoes (the walk,protect_here,open_here, remaps).protect_aliasnever marks a block clean, so the alias guards from8dd30abare untouched.known_viewalso answers yes for a range already known to be view memory, so a range whose first block was written asks no failing write-watch question (follows #670).How it was found. Per frame there were ~10,500 view checks, ~5,200 of which walked ~87,000 blocks that were not clean, while only ~280 guard faults a frame marked blocks as newly written. The blocks that stayed not clean were the unmapped ones. #685 (open) also walks only the blocks that are not clean, through an interval map, but unmapped blocks are not clean, so it still asks about each one at every check. Here a not-clean set alone left the guards at 19.7 ms; parking took them to 7-8 ms.
Tested on
main(9376fd6) plus this commit, on Windows 11 with an RTX 5080 (driver 621.24), a Ryzen 7 5700X3D and 32 GB:One five-minute game run each way, first room, 1080p (median of the last 20 frame lines):
VICTORY_VIEW_SET0(main as it is)1On
mainthe frame here is set by the copy-back thread (~160 ms, ~107 of it waiting for fetches of card copies' pieces), so the saved time does not show in the frame yet.The same change on an integration branch of
310c6eb(with #220, #144 and other open PRs), before the alias guards came in: 123.1 / 155.0 / 127.9 ms a frame over three runs with guards at 7.0-8.2 ms, against 135.8 and 144.7 ms for the walk with guards at 20 ms. Frames swing ~15 % between identical runs on this machine, so the guards line is the measure.Dead ends measured on the way: an answer per submission for the uncommitted regions (238.6 ms a frame, because each block is its own region) and a look at every parked block once per 32 submissions (200.9 ms, ~200,000 questions a frame).
cargo test -p victory-gpu --features diagnostics --lib watch::: 13 passed, withVICTORY_VIEW_SETunset and with=0(the four alias tests included). New testparked_blocks_come_back_when_committedcovers announced and unannounced commits.writes_in_partly_committed_view_blocks_are_reportednow steps the epoch for its unannounced commit, andunmapped_blocks_are_reported_once_until_mappedchecks that its placeholder blocks are parked and not looked at again.cargo test -p victory-hle --lib xmem: 12 passed.cargo clippy --workspace --all-targets --locked -- -D warnings, with and without--all-features: the only errors are three already onmain, none in a file this touches (an unusedplaced_filler_twinsinresource.rs, an unreaddepth_writteninindirect.rs,clippy::unnecessary_sort_byindraw.rs). With those three allowed: clean.cargo test --workspace --locked: 541 passed, 0 failed, 10 ignored.The game runs were of this change before two small edits: the one-time placeholder check, and a binary search for the views in
title_memory_remapped. The tests and clippy ran on this commit.Not checked: Wine.
AI-assisted (Claude Code).
@MamaLeVrai on GitHub · 2026-11-25 09:54 UTC · original
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head
e277b98intomain9376fd6in a throwaway tree (no conflict).cargo clippy --workspace --all-targets --locked -- -D warningsfails, with the same two errors asmainitself on this machine (function placed_filler_twins is never used,field depth_written is never read,victory-gpu): this PR adds none and removes none.cargo test --workspace --locked: 541 passed, 0 failed, 10 ignored, two runs (mainalone: 540 passed). The title was not run, so this says nothing about in-game effect. No game data.AI-assisted (Claude Code); no game data.
@Ym1r1710 on GitHub · 2026-11-25 21:29 UTC · original
Heads up, found a problem with this one in my tree. When the title maps one physical page at several addresses, a write through one view opens all of them, and the check of the first view guards them all again. protect_alias (and the batched run version if you also have #1059) then does g.unclean.remove(&block) for the other views' blocks too, so when those views get checked there is nothing left to look at and their host copies keep the bytes from before the write.
watch::tests::a_write_is_reported_at_every_checked_view fails with this PR applied. Leaving the block in the unclean set there (just insert into protected, no remove; guard_unclean already takes it out once it reports it) makes the test pass again. Ran it in game on an RTX 5080 after the change, two runs to world+800, picture fine and frame time unchanged.
@grosterr on GitHub · 2026-11-25 23:03 UTC · original
Two notes from the #770 stack, which carries this PR, on an RTX 3060 12 GB:
Main's
VICTORY_ABSENT_ONCE(44bff61) goes after the same cost as this PR. Main's README for run 279 counts ~690,000 questions to Windows in 20 seconds about view blocks already known to be unmapped. With 100 ms notes, 40–50 % of the answers come from the notes, and no frame gain is shown yet. This PR's parking stops asking about such blocks in a placeholder at all until the runtime tells of a mapping there. With both in one tree, main's testa_block_noted_uncommitted_is_asked_about_again_only_when_its_note_is_oldfails: it maps a block into a placeholder "without a word" and expects the next asking to find it, but here the block is parked. WithVICTORY_VIEW_SET=0the test passes. I made its expectation depend onview_set()(details in #770). If main takes this PR,ABSENT_ONCEmay matter only whereVIEW_SETis off (Wine, where placeholders are not told apart).On Ym1r1710's alias problem: at this PR's head (
e277b98) and in the #770 stack (d034ac1),protect_aliasonly inserts intoprotected(andviewed) and does not touchunclean, anda_write_is_reported_at_every_checked_viewpasses in our tree. #1059 itself has nounclean(it is based on main without this PR), so theg.unclean.remove(&block)inprotect_aliaswas probably added when the two were merged together in that tree. Anyone merging this PR with #1059 should keepprotect_aliasas it is here and run that test.AI-assisted (Claude Code); checked by me.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.