Skip to content

Preserve newer guest writes across gaps and overlapping page snapshots - #2

Open
MichaelSmithAI wants to merge 5 commits into
wbkepler:gpu/snapshot-pagesfrom
MichaelSmithAI:fix/paged-snapshot-preservation
Open

MichaelSmithAI wants to merge 5 commits into
wbkepler:gpu/snapshot-pagesfrom
MichaelSmithAI:fix/paged-snapshot-preservation

Conversation

@MichaelSmithAI

Copy link
Copy Markdown

This ports the snapshot-preservation logic and regression cases from Maraco91’s #261 to the per-page storage in #497, and adds a case for two disjoint ranges within one 64 KiB page.

On 5ff3a35, a later write declaration can cover an earlier gap inside one page. Its refreshed bytes can then look like shader writes. A second copyback over an overlapping range can likewise mistake a byte taken from guest memory during the first copyback for a new shader write. In both tests the guest wrote 2 and copyback replaced it with 1.

The change records the current bytes of newly declared intervals in the existing page buffers. After copyback merges a range, later overlapping ranges compare against those merged bytes. The existing check for a fully covered declaration stays in front of the range calculations. For a newly covered interval the implementation copies and sorts the span list. Its effect on title frame time has not been measured.

Verification

On an RTX 4090 under Wine with vkd3d-proton, the original Marvisak#497 branch passed the cross-page gap test and failed the same-page gap and overlapping-range tests. With the patch all five snapshot tests passed, including both original Marvisak#497 tests. The controls use a D3D12 shared buffer and simulate shader writes in its mapped memory. A separate run repeated all five passes and their completion markers. Asset policy passed.

Run cargo test --locked -p victory-gpu --lib shadow:: -- --nocapture --test-threads=1. This work used no game files. The performance measurements in Marvisak#497 belong to its original author.

AI-assisted implementation and verification.

wbkepler and others added 4 commits November 24, 2026 04:43
A copy of view memory (physical-page views, which cannot be
write-watched) guards each 64 KiB block it took read-only. A block that
is not mapped (a placeholder between views of a GPU heap) cannot be made
read-only, so it never became clean: every asking reported it written
again, and the copy read it through the per-page fallback, whose
failing kernel reads cost hundreds of ms per world frame.

Note such blocks absent (only after VirtualProtect fails and the block is
not committed). An absent block is not reported again until
title_memory_remapped, which the runtime calls after mapping or
unmapping views, clears it. The copy keeps the zeros it took.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before a submission runs, the bytes of each range its shaders write are
kept to tell afterwards what the GPU changed. They were one buffer per
copy, grown to the bounding range of every range the submission
declared: each growth took a buffer from a pool of eight (a fresh one,
page faults and all, when none was free and big enough) and copied the
whole old snapshot into it.

Keep them per title page instead, in 64 KiB buffers from a pool of up to
4,096, each page's part grown as ranges in it are declared (newly covered
bytes taken from the copy as it is then, as before). A range inside one
already taken returns at once. Copy-back compares page by page as it did
by 64 KiB piece, with its scratch page from the same pool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants