Repository navigation
GPU: a partial refresh of an armed page updates the bytes saved of it - #2377
BastienRodz wants to merge 2 commits into
Conversation
Since cd94d35, a page armed for marked writes keeps its bytes from before the title's first write (Tracked::saved), and copy_back_marked takes what differs from them for the shaders'. A refresh of only part of that page in the same submission (under or beside a range shaders write) leaves the page changed and its saved bytes as they were, while the copy now holds the title's newer bytes there. Copy-back then took the refreshed bytes for the GPU's, putting them back over later title writes, and missed shader writes back to the saved value. Shadow::copy now hands what it copied to Tracked::refreshed, which updates the saved bytes of the pages it covers, as update_busy does for the snapshots of unmarked ranges. Co-Authored-By: Gemini 4 Neon <noreply@google.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AndyLatimer
left a comment
There was a problem hiding this comment.
Tested on NVIDIA hardware, which the description lists as not tested: RTX 3060 Ti (driver 610.88), Windows 11 26200, 81dfeee (base 940d32f).
- The new test without the fix (only the
t.refreshedcall inShadow::copytaken out) fails withleft: [170, 85, 68, 17],right: [170, 102, 0, 17], as in the description. A real D3D12 device runs it here; it doesn't return early. - With the fix it passes.
shadow::andwatch::(11 tests): 10 of 10 runs. cargo test -p victory-gpu --locked: 142 passed, 2 failed, 2 ignored. The 2 failures are the heap-cap tests this card fails onmaintoo (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views, #1744).mainhere: 141 passed, the same 2 failed.cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, default and--all-features: clean.
What I checked, all fine:
- Order.
copy_back_marksruns before the copy-backs of declared ranges (host.rs~988), andcopy_back_markedremoves the page's saved bytes. So the other place where the copy takes title bytes, the*h = *tsync incopy_back_or_not, can't leave saved bytes stale and doesn't need the same call. - Locks.
refreshedtakes theSavedlock whileupdate_busyholdsbefore.copy_back_or_notalready goesbefore→ guards →Saved(throughtaken), and the write handler goes guards →Saved. The PR adds no new order. - A window it also closes, for whole pages.
takeguards a page, drops its saved bytes and releases the guard lock before the copy is made. If the page is armed (an earlier step of the same submission declared it), a title write in that window faults and saves the bytes from before the write, and the copy then has the write. Without this PR, copy-back takes that write for the GPU's and puts it back over a later title write to the same byte. With it, the saved bytes are the copy's. No test for this one, since it's a race.
Nit: the docs of Saved (watch.rs), Tracked::saved and copy_back_marked still say the saved bytes are what the page held at the title's first write. With this PR they are that with later refreshes laid over, i.e. the copy's bytes before the submission. One line in Saved's doc would cover it.
Overlap with other open PRs on these files:
- Merged with #2147, #2239 or #2172 (one at a time): builds, and
shadow::andwatch::pass. - #2169 merges without a conflict but does not build. It folds
Changed's two mutexes into oneChangedState, soself.changed.1inrefreshedis gone (E0609); there it would beself.changed.0.lock()andstate.bytes. It also givescopy_back_markedascratch: &mut Vec<u8>argument, so the new test's two calls need one (E0061). Whichever of the two lands second needs those three lines. - With #2242, #1998 and #1986 the only conflict is that both sides add tests at the end of
shadow.rs'smod tests.
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:
- Updating saved bytes on partial refresh of an armed page cleanly prevents stale copy-back diffs against overwritten title bytes.
cargo test -p victory-gpu shadow::: 5/5 passed on RTX 5090, 5/5 passed on WARP (includingpartial_refresh_under_marked_range_updates_saved_bytes).cargo test -p victory-gpu watch::tests: 6/6 passed.cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.
AI-assisted (Gemini 4 Neon).
…submission Docs of Saved and Tracked::saved: refreshes lay what the copy takes over the bytes saved at the title's first write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @AndyLatimer, that's a thorough check, and good to have it confirmed on a real device. The ordering and lock analysis match my reading. I hadn't thought of the whole-page window between Doc nit addressed in 81e7648: On #2169: agreed, whichever lands second needs |
catminou4
left a comment
There was a problem hiding this comment.
A partial refresh of an armed page updates the saved bytes too (refreshed() under marked ranges). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Closes a copy-back correctness hole in the shadow.rs cluster (#2271/#2272); test included.
What's wrong
Since
cd94d35, marked writes arm pages instead of taking a snapshot. The title's first write to an armed page saves the page's old bytes, andcopy_back_markedcompares the copy against them. A refresh of only part of such a page in the same submission (update_busyunder a written range,update_freebeside a sub-page one) copies the title's newer bytes into the copy but leaves the saved bytes as they were:Tracked::takekeeps a partly covered page changed, andupdate_busyupdates onlyShadow::before, the snapshots of unmarked ranges. Copy-back then takes the refreshed bytes for the GPU's, which puts them back over later title writes, and misses shader writes back to the saved value.What the fix does
Tracked::refreshed(from, bytes)(watch.rs) copies freshly refreshed bytes into the saved bytes of the pages they cover. It returns at once when nothing is saved, the usual case.Shadow::copycalls it after copying. That keepscopy_back_marked's rule ("what differs from the copy's bytes before the submission") for armed pages, asupdate_busyalready does for the snapshots of unmarked ranges.Tests
New
shadow::tests::partial_refresh_under_marked_range_updates_saved_bytes: two pages armed by a range ending 16 bytes into the second, the title writes both pages, part of each is refreshed (under and beside the range), the title then writes again and a shader-side write goes into the copy. Copy-back must keep the later title writes and take the shader's.main(940d32f) it fails:left: [170, 85, 68, 17](stale0x55over the title's0x66, the shader's0x00lost),right: [170, 102, 0, 17].shadow::tests(5) andwatch::tests(6) pass. Run under Wine 10 with vkd3d-proton 3.1 on llvmpipe: the copy needs a host device, and the test returns early without one.Not tested
No title run, and no AMD/NVIDIA GPU. How often the title refreshes part of a page it is also writing through marked views is not measured.
Relation to #2172: that PR widens refreshes of marked view ranges to whole pages, which takes such pages whole and drops their saved bytes. It does not cover a refresh of another range (a constant buffer, say) in the same page, which is what this fixes. The two don't touch the same lines.
Fixes #2375
AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used.
🤖 Generated with Claude Code