Repository navigation
Conversation
After a submission, a page shaders wrote goes back into title memory. For marked pages (views) and pages written at computed addresses that was the whole page: read title memory, compare, then write the copy's 64 KiB over it. The title's threads write the same pages meanwhile (its GPU heap holds CPU records next to what shaders write), and a write that landed after the read was undone by the copy's older bytes. The page was then taken with those bytes, so the copy kept them for good, and a later copy-back of the page put them back over the title's again. Now only the runs of bytes the shaders changed are written (runs less than 256 bytes apart as one span, with the title's bytes between them as read: a kernel copy per run cost over 1 ms per page). The page is armed while it is read, so a title write that lands during the read saves the bytes from before it and the shaders' bytes are told apart from the title's. After the copy-back the page is taken first and the copy reads it again, so a title write before the guard is back is in the copy and one after it faults. The snapshot path writes only the bytes the GPU changed as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-gpu --lib shadow::— 5 passed, 0 failedcargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean run-based copy-back writing only bytes actually changed by the GPU without clobbering concurrent CPU writes. Looks great.
AI-assisted (Gemini 4 Neon).
catminou4
left a comment
There was a problem hiding this comment.
Copy-backs put back only the bytes the GPU changed: differing computes changed runs word-at-a-time, SPAN_GAP=256 merges nearby runs. 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. Notable perf fix (whole-page copy-back cost >1 ms/page in-world) and avoids clobbering concurrent title writes — the motivation is well documented.
|
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head AI-assisted (Claude Code); no game data. |
|
Independent run of the base commit's behaviour on Windows 10 19045 / RX 7800 XT, as part of testing #2280 (which is stacked on this): |
The marked-page copy-back (shaders write through views of a copy) read the page after disarming it, wrote each whole piece when anything in it changed, and took the page with bytes read before the title's writes. Arm the page while it is read (a title write then keeps its bytes from before), write only the differing runs with the span merging the other copy-back already uses, and take the page then read it again when the copy-back ends. Ported from Marvisak/VIctory#2242 (wbkepler, GPL-3.0-or-later). Test: a_marked_copy_back_puts_back_only_the_bytes_the_gpu_changed (fails on the whole-piece write).
|
In-game numbers for spans against one kernel write per run. They come from a fork and not from this branch, so they say something about the idea and nothing about this PR's code. The fork (fxceless/victory-gta6) has the per-run write (after #2009) in its snapshot copy-back since its
On a newer fork tree (more PRs, 925-954 pieces a frame), same executable and switches: 54.3 ms with 4096 and 50.8 ms with 256 (45 and 35 report lines, one launch each, so equal within noise). The smaller gap, as in this PR, cost nothing extra here, and it keeps the race window smaller. Per-run writes were about 0.9 ms a piece, close to the "over 1 ms per page" in this PR's description. The same idea is open for the fork with a gap of 64 (fxceless/victory-fork#857, measured under Wine). Setup: RTX 3070 Ti Laptop 8 GB (driver 596.36), i7-12700H, 16 GB RAM, Windows 11, diagnostics build, Series X profile. One machine, one run per row. The per-run and spans rows come from the same executable, but each spans run differs by one more switch, so this is not a strict A/B. AI-assisted (Claude Code). No game data. |
What's wrong
After a submission, each 64 KiB page that shaders marked as written (through views,
copy_back_marked) or wrote at computed addresses (copy_back_page) goes back into title memory. Both paths read title memory, compared it with the host copy and then wrote the copy's whole page over title memory. The title's threads keep writing the same pages meanwhile: its GPU heap holds CPU-side records next to buffers that shaders write. Two races follow:changed) and before itswrite_mappedis overwritten by the copy's older bytes. A write during the read itself looks like a shader's byte (title memory differs from the copy) and is reverted too.takenwith the bytes the copy-back had, so a title write between the read and the guard coming back is lost from the copy for good. The next copy-back of that page sees the copy differ from title memory and puts the stale bytes back over the title's record. This can happen much later.The snapshot path (
copy_back) merged correctly byte by byte, but it also wrote the merged 64 KiB piece from a buffer it read earlier, so it had race 1 as well.On the host below, the title crashed with an access violation about 155 s into the world. It read an address computed from a per-object index, and that address lies deep in an unmapped gap of the address space. Reconstructing the address from the title's own minidump fits an index that held the float 1.0 in place of an index, with the array it points into in physical-page memory that a host copy guards (read-only pages). The world copies back about 700 marked pages every 5 s. I did not catch the bad write in the act, so this cause is inferred, not proven.
The fix (
crates/victory-gpu/src/shadow.rs)differing+write_runs). Runs less than 256 bytes apart go out as one span, and the bytes between them hold title memory as the copy-back read it. A kernel copy per run cost over 1 ms per page in the world, where shaders change many scattered words of a page. Title bytes farther than that from the shaders' bytes are never written.copy_back_markedandcopy_back_pageshareput_back. It arms the page while it reads title memory, so a title write that lands during the read saves the page's bytes from before (the existing guard save). The shaders' bytes can then still be told apart from the title's, and the page is unarmed before our own write.take_and_read). A title write before the guard is back is in the copy. A write after it faults and marks the page changed. The copy never takes the page with bytes read earlier.copy_back(snapshot path) writes only the bytes the GPU changed, through the same helpers, and takes and re-reads its whole pages the same way.Cost: one more 64 KiB read per page that goes back, and one kernel copy per span instead of one per page.
Shortcut: inside a span, a title write that lands between the copy-back's read and its write is still undone. That window is microseconds, and the write has to fall within 256 bytes of bytes the shaders changed.
Tests
New test
shadow::tests::a_copy_back_puts_back_only_the_bytes_the_gpu_changed. A test-only hook makes a title write right after the copy-back has read the page, on a page marked through views and on a page written at computed addresses. The test checks that the shader's byte and the title's byte both end up in title memory, and that the copy holds the title's byte. With the previous whole-page write, the title's byte would be reverted at that point.The existing shadow tests (
marked_pages_go_back_by_the_bytes_the_gpu_changed,title_writes_under_a_busy_range_are_copied,snapshots_cover_the_declared_ranges_and_writes_go_back_once) still pass unchanged.Gate on Windows 11, NVIDIA RTX 5090:
cargo clippy -p victory-gpu --all-targets -- -D warningsandcargo clippy -p victory --features diagnostics --all-targets -- -D warnings: clean.cargo test -p victory-gpu: 142 passed, 2 failed. The two failures are unrelated to this change:descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_viewsboth assert the view heap's size or layout, and this host caps shader-visible view heaps at 1M descriptors.cargo xtask policy: ok.Live
Windows 11, NVIDIA RTX 5090, a private integration build plus this fix (an earlier revision that wrote each run separately, without the 256-byte spans):
DEVICE_HUNGafter about 210–220 s from start.That run alone does not prove the crash is gone.
🤖 Generated with Claude Code