GPU: copy-back writes only the GPU's bytes and marks only unchanged pages current #1024

Open
github-bot wants to merge 2 commits from github-bot/gh-1024 into main AGit
Owner

@⁠Dufftwt on GitHub · 2026-11-24 15:09 UTC · original
Dufftwt:fix/copy-back-only-gpu-bytes → main · +238 −21 · 3 files · 2 commits · open

Fixes #721, fixes #722.

What's wrong

After a submission, Shadow::copy_back (crates/victory-gpu/src/shadow.rs) brings what shaders wrote back into title memory. It has two problems, both while the title's own threads keep writing the same memory:

  1. It writes back whole 64 KiB pieces (#721). It reads a piece from title memory, puts the GPU's bytes in, and writes the whole piece back. If a title thread writes any other byte of that piece in between, its write is undone. The function's own comment says why that matters: putting older bytes back "broke the title's own records (a fence list read as -1)".
  2. It marks pages current too eagerly (#722). Every synced page is marked current from one write-watch query made after all pieces are done. That query also clears any title write made after the page was read, so the page counts as current while the copy holds older data. Later refreshes skip it, and draws keep reading the old bytes.

What the fix does

  1. The merge loop records the runs of bytes the GPU changed and writes back only those runs. The copy still takes title memory's bytes everywhere, as before.
  2. The runs are stored directly, not through the kernel. A system call per run was far too slow: Vaximous measured 1.3–1.9 s of copy-back per frame in the world on #721, where shaders' scattered writes make thousands of runs per piece. One VirtualQuery per piece (the new host::writable) checks that the runs lie in committed read-write memory. Where they don't, each run still goes through write_mapped, which skips pages it can't write. One watch::writing per piece opens our guarded view blocks first. A block another thread guards again before the stores faults into our handler, which opens it.
  3. After the final query, a synced page is marked current only if title memory, read again, still matches the copy. A page that differs stays stale, and the next refresh copies it.
  4. The guard handler's writable(at) check in watch.rs now calls host::writable(at, 1), the same query.

How it behaves after the fix

Title writes made while copy-back runs are kept, and they reach the host copy at the next refresh. When the title doesn't write meanwhile, the result is the same as before. Copy-back takes about as long as writing whole pieces did, however scattered the GPU's writes are (timings below). The added cost is one 64 KiB read per page the GPU wrote, and one memory query per piece. The copy-back figure in the frame log now counts only the bytes actually written, so it drops.

shortcut: a title thread that unmaps or protects memory between the query and the stores would crash us. The GPU's bytes go back before the title is told the submission is done, so only a title that frees memory the GPU is still writing could do that.

Tests

Three new tests in shadow.rs (copy_back_tests), on write-watched memory and a host copy from host().shared_buffer. They skip without a host GPU. A test-only watch::forget clears the journal for their memory when they free it, so a later test's allocation at the same address starts clean.

  • copy_back_does_not_undo_title_writes_made_while_it_runs: a title thread keeps bumping a word in each of 64 pages while copy_back writes a shader byte back into each. No write may go back to an older value.
  • a_title_write_during_copy_back_reaches_the_copy: once copy-back has finished page 0, the title writes it while 62 pages are still to go. The next refresh must bring that write into the copy.
  • a_read_only_title_page_is_left_alone: the title made one page read-only. Copy-back must not crash on it, and must leave it alone, as write_mapped always did (the kernel's write fails there). The other 63 pages still get the shader's byte.

I ran cargo test -p victory-gpu -- --test-threads=1 on GitHub's windows-latest with Rust 1.98.1 from rust-toolchain.toml (the runner has a hardware D3D12 device as well as WARP):

  • This PR: everything passes (victory-gpu: 53 passed, 1 ignored).
  • The new tests alone on main (ffe310e): both fail.
    • copy_back_does_not_undo_title_writes_made_while_it_runs: title writes undone by the copy-back, left: 64, right: 0, so every one of the 64 pages lost its title write.
    • a_title_write_during_copy_back_reaches_the_copy: in the copy, left: 0, right: 7. The write reached title memory but never reached the copy.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings is clean, with and without --all-features.

Timings. A scratch test (not in this PR) timed one copy_back of 64 pages in which the shaders changed every Nth byte. It ran as a release build on the same runner, 3 rounds each, against this PR without its second commit (one write_mapped per run):

Shader writes Runs per page One write_mapped per run This PR
every 2nd byte 32,768 15.6 s 14–17 ms
every 16th byte 4,096 2.0 s 5.4–5.7 ms
every 256th byte 256 125 ms 4.2–4.3 ms
whole pages 1 10.7–10.9 ms 10.4–11.6 ms

Not tested: a title run with this branch. Vaximous (RTX 4070 Ti, Windows) and xstraok (Wine) saw a crash and a freeze in the world go away with run-only write-back on #721.

Related: #124, #401 and #693 restructure copy_back but keep the whole-piece write; #261 fixes other cases where older bytes went back; #943 changes write_mapped's fallback and #991 merges overlapping write-back ranges, on the same lines. Whichever merges second needs a rebase. Fixes for this were also posted on #721 and #722 as branches, since PRs were closed to non-collaborators: xstraok (plain stores, without a check of the memory), Vaximous, Hiiva (with #722), and Machad3x (with #722; pieces with more than 64 runs are still written whole, which keeps the race in them). Their in-game runs are the evidence that this race matters.

**@⁠Dufftwt** on GitHub · 2026-11-24 15:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024) `Dufftwt:fix/copy-back-only-gpu-bytes` → `main` · +238 −21 · 3 files · 2 commits · open Fixes #721, fixes #722. ## What's wrong After a submission, `Shadow::copy_back` (`crates/victory-gpu/src/shadow.rs`) brings what shaders wrote back into title memory. It has two problems, both while the title's own threads keep writing the same memory: 1. **It writes back whole 64 KiB pieces (#721).** It reads a piece from title memory, puts the GPU's bytes in, and writes the whole piece back. If a title thread writes any other byte of that piece in between, its write is undone. The function's own comment says why that matters: putting older bytes back "broke the title's own records (a fence list read as -1)". 2. **It marks pages current too eagerly (#722).** Every synced page is marked current from one write-watch query made after all pieces are done. That query also clears any title write made after the page was read, so the page counts as current while the copy holds older data. Later refreshes skip it, and draws keep reading the old bytes. ## What the fix does 1. The merge loop records the runs of bytes the GPU changed and writes back only those runs. The copy still takes title memory's bytes everywhere, as before. 2. The runs are stored directly, not through the kernel. A system call per run was far too slow: Vaximous measured 1.3–1.9 s of copy-back per frame in the world on #721, where shaders' scattered writes make thousands of runs per piece. One `VirtualQuery` per piece (the new `host::writable`) checks that the runs lie in committed read-write memory. Where they don't, each run still goes through `write_mapped`, which skips pages it can't write. One `watch::writing` per piece opens our guarded view blocks first. A block another thread guards again before the stores faults into our handler, which opens it. 3. After the final query, a synced page is marked current only if title memory, read again, still matches the copy. A page that differs stays stale, and the next refresh copies it. 4. The guard handler's `writable(at)` check in `watch.rs` now calls `host::writable(at, 1)`, the same query. ## How it behaves after the fix Title writes made while copy-back runs are kept, and they reach the host copy at the next refresh. When the title doesn't write meanwhile, the result is the same as before. Copy-back takes about as long as writing whole pieces did, however scattered the GPU's writes are (timings below). The added cost is one 64 KiB read per page the GPU wrote, and one memory query per piece. The copy-back figure in the frame log now counts only the bytes actually written, so it drops. `shortcut:` a title thread that unmaps or protects memory between the query and the stores would crash us. The GPU's bytes go back before the title is told the submission is done, so only a title that frees memory the GPU is still writing could do that. ## Tests Three new tests in `shadow.rs` (`copy_back_tests`), on write-watched memory and a host copy from `host().shared_buffer`. They skip without a host GPU. A test-only `watch::forget` clears the journal for their memory when they free it, so a later test's allocation at the same address starts clean. - `copy_back_does_not_undo_title_writes_made_while_it_runs`: a title thread keeps bumping a word in each of 64 pages while `copy_back` writes a shader byte back into each. No write may go back to an older value. - `a_title_write_during_copy_back_reaches_the_copy`: once copy-back has finished page 0, the title writes it while 62 pages are still to go. The next refresh must bring that write into the copy. - `a_read_only_title_page_is_left_alone`: the title made one page read-only. Copy-back must not crash on it, and must leave it alone, as `write_mapped` always did (the kernel's write fails there). The other 63 pages still get the shader's byte. I ran `cargo test -p victory-gpu -- --test-threads=1` on GitHub's `windows-latest` with Rust 1.98.1 from `rust-toolchain.toml` (the runner has a hardware D3D12 device as well as WARP): - **This PR:** everything passes (`victory-gpu`: 53 passed, 1 ignored). - **The new tests alone on `main` (`ffe310e`):** both fail. - `copy_back_does_not_undo_title_writes_made_while_it_runs`: `title writes undone by the copy-back`, `left: 64, right: 0`, so every one of the 64 pages lost its title write. - `a_title_write_during_copy_back_reaches_the_copy`: `in the copy`, `left: 0, right: 7`. The write reached title memory but never reached the copy. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` is clean, with and without `--all-features`. **Timings.** A scratch test (not in this PR) timed one `copy_back` of 64 pages in which the shaders changed every Nth byte. It ran as a release build on the same runner, 3 rounds each, against this PR without its second commit (one `write_mapped` per run): | Shader writes | Runs per page | One `write_mapped` per run | This PR | |---|---|---|---| | every 2nd byte | 32,768 | 15.6 s | 14–17 ms | | every 16th byte | 4,096 | 2.0 s | 5.4–5.7 ms | | every 256th byte | 256 | 125 ms | 4.2–4.3 ms | | whole pages | 1 | 10.7–10.9 ms | 10.4–11.6 ms | **Not tested:** a title run with this branch. Vaximous (RTX 4070 Ti, Windows) and xstraok (Wine) saw a crash and a freeze in the world go away with run-only write-back on #721. Related: #124, #401 and #693 restructure `copy_back` but keep the whole-piece write; #261 fixes other cases where older bytes went back; #943 changes `write_mapped`'s fallback and #991 merges overlapping write-back ranges, on the same lines. Whichever merges second needs a rebase. Fixes for this were also posted on #721 and #722 as branches, since PRs were closed to non-collaborators: xstraok (plain stores, without a check of the memory), Vaximous, Hiiva (with #722), and Machad3x (with #722; pieces with more than 64 runs are still written whole, which keeps the race in them). Their in-game runs are the evidence that this race matters.
copy_back read each 64 KiB piece of title memory, put the GPU's bytes in,
and wrote the whole piece back. A title write to any other byte of the
piece in between was undone. It now writes back only the runs of bytes
the GPU changed.

It then marked every synced page current from one write-watch query made
after all pieces. That query also cleared any title write made after a
page was read, so the page counted as current while holding old data. A
page is now marked current only if title memory, read again after the
query, still matches the copy; the others stay stale for the next refresh.

Fixes #721, fixes #722.
Writing each run back through the kernel cost a system call per run, and
shaders' scattered writes make thousands of runs a piece: 1.3-1.9 s of
copy-back a frame in the world. One query per piece now checks that the
runs lie in committed read-write memory, and they are stored directly;
otherwise each still goes through write_mapped. The query is shared with
the guard handler's check.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:17:31 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 15:11 UTC · original

The three copyback tests passed at 67125b3 on an RTX 4090 under Wine/vkd3d-proton 3.2. They covered preserving a concurrent title write, seeing it in the host copy after refresh, and leaving a read-only title page untouched.

We also combined #1024 with #1019 and #322. The existing guest compute test wrote two 56-byte records through an off-element placed UAV. After submission, both GPU-written fields were present in guest memory and all surrounding bytes matched on both ordinary and write-watched allocations. The combined GPU suite had 64 passes, one ignored test and the known Wine empty-library failure.

These runs used stable mappings. They did not measure title copyback time or same-submission visibility through another backing copy.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 15:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7135610126) The three copyback tests passed at 67125b3 on an RTX 4090 under Wine/vkd3d-proton 3.2. They covered preserving a concurrent title write, seeing it in the host copy after refresh, and leaving a read-only title page untouched. We also combined #1024 with #1019 and #322. The existing guest compute test wrote two 56-byte records through an off-element placed UAV. After submission, both GPU-written fields were present in guest memory and all surrounding bytes matched on both ordinary and write-watched allocations. The combined GPU suite had 64 passes, one ignored test and the known Wine empty-library failure. These runs used stable mappings. They did not measure title copyback time or same-submission visibility through another backing copy.
Author
Owner

@⁠Aniseto on GitHub · 2026-11-24 15:22 UTC · original

Ran the three copy-back tests at 67125b3 on native Windows:

Environment: Windows 11 Pro build 26200 x64, Intel Core i5-12400F, 64 GB RAM, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only) driver 32.0.16.2124, Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

cargo test -p victory-gpu copy_back
3 passed; 0 failed; 0 ignored      (exit 0)

copy_back_does_not_undo_title_writes_made_while_it_runs, a_title_write_during_copy_back_reaches_the_copy and a_read_only_title_page_is_left_alone pass. The earlier report was on an RTX 4090 under Wine/vkd3d-proton 3.2; this run is native Windows D3D12, so it also covers the native path on a Blackwell part.

Not tested: the title itself (no game data here, and its world can hang the adapter per the README), RDNA2/RDNA4 and Intel GPUs.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; no game data was used.

**@⁠Aniseto** on GitHub · 2026-11-24 15:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7135909275) Ran the three copy-back tests at `67125b3` on native Windows: Environment: Windows 11 Pro build 26200 x64, Intel Core i5-12400F, 64 GB RAM, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only) driver 32.0.16.2124, Rust 1.98.1 (pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5, debug build. ``` cargo test -p victory-gpu copy_back 3 passed; 0 failed; 0 ignored (exit 0) ``` `copy_back_does_not_undo_title_writes_made_while_it_runs`, `a_title_write_during_copy_back_reaches_the_copy` and `a_read_only_title_page_is_left_alone` pass. The earlier report was on an RTX 4090 under Wine/vkd3d-proton 3.2; this run is native Windows D3D12, so it also covers the native path on a Blackwell part. Not tested: the title itself (no game data here, and its world can hang the adapter per the README), RDNA2/RDNA4 and Intel GPUs. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash 1017** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; no game data was used.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:40 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 67125b3: cargo test -p victory-gpu passes, 53 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 15:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7136414773) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 67125b3: `cargo test -p victory-gpu` passes, 53 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠AgneyaK on GitHub · 2026-11-24 16:37 UTC · original

Test report on an RTX 3050 6 GB Laptop (i7-13700H, 16 GB RAM, Windows 11 26300), diag build, title 1.0.2.1, Series X profile. Base tree: main ffe310e + #208 + #223 #233 #320 #439 + #452 + #579 (VICTORY_SKIP_WAVE64=mesh), from #1232. #472, #322 and #1024 merge cleanly onto it.

tree world frames frame preparing copies textures GPU copying back
base 35 4,641 ms 2,915 943 242 931 741
+ #472 + #322 + #1024 60 4,101 ms 2,615 607 180 836 604

So about 12% shorter frames, mostly copies (−36%) and copy-back (−18%). One run each, and the three were
not separated.

On this 16 GB machine much of the rest looks like paging: private bytes reach 22.9 GB and the working set is trimmed to 2-5 GB (numbers in #1232).

AI use: Claude Code (Claude Opus 5.5) merged and built the trees, ran the title on my machine and drafted this note; results are from the runs described.

**@⁠AgneyaK** on GitHub · 2026-11-24 16:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7137947187) Test report on an RTX 3050 6 GB Laptop (i7-13700H, 16 GB RAM, Windows 11 26300), diag build, title 1.0.2.1, Series X profile. Base tree: `main` `ffe310e` + #208 + #223 #233 #320 #439 + #452 + #579 (`VICTORY_SKIP_WAVE64=mesh`), from #1232. #472, #322 and #1024 merge cleanly onto it. | tree | world frames | frame | preparing | copies | textures | GPU | copying back | |---|---|---|---|---|---|---|---| | base | 35 | 4,641 ms | 2,915 | 943 | 242 | 931 | 741 | | + #472 + #322 + #1024 | 60 | **4,101 ms** | 2,615 | **607** | 180 | 836 | **604** | So about 12% shorter frames, mostly copies (−36%) and copy-back (−18%). One run each, and the three were not separated. On this 16 GB machine much of the rest looks like paging: private bytes reach 22.9 GB and the working set is trimmed to 2-5 GB (numbers in #1232). AI use: Claude Code (Claude Opus 5.5) merged and built the trees, ran the title on my machine and drafted this note; results are from the runs described.
Author
Owner

@⁠TG0000 on GitHub · 2026-11-24 16:57 UTC · original

A measured hint on speed, from my own port of this idea (not your build; head 67125b3), RX 6800, Windows 11, one launch, 8 looped world frames of 36 submissions: the write-back with write_runs took about the same time as main's (302 against 292 ms per frame in copy back), because each piece still does a VirtualQuery (about 2 ms in the title's big pools here). With the runs written through a fault-tolerant user-mode copy (the one of #1010, also open) instead, copy back fell to about 79 ms and only the GPU's bytes are written. That also closes the window between the query and the plain stores (host.rs:1400-1410), where a title thread can unmap or protect the memory; that window I only read, I have not reproduced it. QueryWorkingSetEx per page (1 to 2 us here) is another way to avoid the slow query.

The correctness part, writing only what the GPU changed, looks right to me.

AI-assisted (Claude Code).

**@⁠TG0000** on GitHub · 2026-11-24 16:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7138465169) A measured hint on speed, from my own port of this idea (not your build; head 67125b3), RX 6800, Windows 11, one launch, 8 looped world frames of 36 submissions: the write-back with `write_runs` took about the same time as `main`'s (302 against 292 ms per frame in copy back), because each piece still does a `VirtualQuery` (about 2 ms in the title's big pools here). With the runs written through a fault-tolerant user-mode copy (the one of #1010, also open) instead, copy back fell to about 79 ms and only the GPU's bytes are written. That also closes the window between the query and the plain stores (host.rs:1400-1410), where a title thread can unmap or protect the memory; that window I only read, I have not reproduced it. `QueryWorkingSetEx` per page (1 to 2 us here) is another way to avoid the slow query. The correctness part, writing only what the GPU changed, looks right to me. _AI-assisted (Claude Code)._
Author
Owner

@⁠Dufftwt on GitHub · 2026-11-24 16:59 UTC · original

@⁠TG0000 thanks for measuring. 302 against 292 ms is what this PR aims for: only the GPU's bytes are written, at main's speed. The write_mapped per run it replaces took seconds there (1.3–1.9 s per frame in Vaximous's runs on #721).

I agree a fault-tolerant store is the better end state: there's no query, and no window between the query and the stores. It needs the store direction of #1010's copy, though, and #1010 only reads title memory. If #1010 merges first, I'll switch write_runs to its copy in this PR. Otherwise it's a small follow-up on top of both. Did your port add a store routine next to #1010's load, under the same handler?

**@⁠Dufftwt** on GitHub · 2026-11-24 16:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7138511397) @⁠TG0000 thanks for measuring. 302 against 292 ms is what this PR aims for: only the GPU's bytes are written, at `main`'s speed. The `write_mapped` per run it replaces took seconds there (1.3–1.9 s per frame in Vaximous's runs on #721). I agree a fault-tolerant store is the better end state: there's no query, and no window between the query and the stores. It needs the store direction of #1010's copy, though, and #1010 only reads title memory. If #1010 merges first, I'll switch `write_runs` to its copy in this PR. Otherwise it's a small follow-up on top of both. Did your port add a store routine next to #1010's load, under the same handler?
Author
Owner

@⁠TG0000 on GitHub · 2026-11-24 17:31 UTC · original

No new routine: the port called #1010's copy with the title memory as the destination for each run, and fell back to write_mapped for a run that failed. That copy recovers by instruction address, so a fault of the load or of the store fails the call, whichever side it is on. Two things I have not checked for the store direction, so please do not take it as proven: #1010's tests cover the source side only, and after a failed run part of it may already be stored (the fallback then writes it again). A small follow-up on top of both, with tests for a destination that is unmapped, read-only and guarded, sounds right to me.

(302 against 292 ms is the port on this PC; I did not measure the per-run write_mapped it replaces.)

AI-assisted (Claude Code).

**@⁠TG0000** on GitHub · 2026-11-24 17:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7139319098) No new routine: the port called #1010's `copy` with the title memory as the *destination* for each run, and fell back to `write_mapped` for a run that failed. That copy recovers by instruction address, so a fault of the load or of the store fails the call, whichever side it is on. Two things I have not checked for the store direction, so please do not take it as proven: #1010's tests cover the source side only, and after a failed run part of it may already be stored (the fallback then writes it again). A small follow-up on top of both, with tests for a destination that is unmapped, read-only and guarded, sounds right to me. (302 against 292 ms is the port on this PC; I did not measure the per-run `write_mapped` it replaces.) _AI-assisted (Claude Code)._
Author
Owner

@⁠465d6a0eac on GitHub · 2026-11-24 17:49 UTC · original

Thank you for this, @⁠Dufftwt! Many pull requests here are still waiting to be merged, so I've ported this one to 465d6a0eac/AgentRecompVI, a VIctory fork where AI agents review and merge each other's work: https://github.com/465d6a0eac/AgentRecompVI/pull/36. You're credited as the author there. This stays the original.

Test results

  • Windows 11, NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1088, 32-lane waves): together with the rest of this batch, cargo clippy (both variants) and cargo test --workspace pass (429 passed, 0 failed).
  • Copy-back in the world went from 300–450 ms per frame before this batch to 200–300 ms with it (with #1010 and #1025, in a scene that moves).
  • One merge fix: your copy_back_tests module sits next to the tests module #1019 added to shadow.rs.
  • In the world (the first mission's scene), the whole batch took the title from 0.1–0.2 fps (3,300–6,400 ms of GPU time per frame) to 0.8–1.2 fps (190–310 ms). The screen is still black there, and the GPU still hangs after about 3 minutes (one command list over 2 s), so this is not playable yet.
**@⁠465d6a0eac** on GitHub · 2026-11-24 17:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7139762749) Thank you for this, @⁠Dufftwt! Many pull requests here are still waiting to be merged, so I've ported this one to [465d6a0eac/AgentRecompVI](https://github.com/465d6a0eac/AgentRecompVI), a VIctory fork where AI agents review and merge each other's work: https://github.com/465d6a0eac/AgentRecompVI/pull/36. You're credited as the author there. This stays the original. **Test results** - Windows 11, NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1088, 32-lane waves): together with the rest of this batch, `cargo clippy` (both variants) and `cargo test --workspace` pass (429 passed, 0 failed). - Copy-back in the world went from 300–450 ms per frame before this batch to 200–300 ms with it (with #1010 and #1025, in a scene that moves). - One merge fix: your `copy_back_tests` module sits next to the `tests` module #1019 added to `shadow.rs`. - In the world (the first mission's scene), the whole batch took the title from 0.1–0.2 fps (3,300–6,400 ms of GPU time per frame) to 0.8–1.2 fps (190–310 ms). The screen is still black there, and the GPU still hangs after about 3 minutes (one command list over 2 s), so this is not playable yet.
Author
Owner

@⁠aycow on GitHub · 2026-11-24 18:18 UTC · original

I retained Duff's authored 3b2181a byte-run copyback in a #387 test branch. Both concurrent title-write controls passed on native Windows with the GPU crate optimized. In a CPU-only 4 MiB snapshot/copyback fixture, changing one byte per 32 bytes generated 131,072 guarded writes and raised median copyback from 1.37 ms to 718.99 ms. The dense and sparse controls are in the reproduction.

I kept this candidate separate from #387. The later direct-store shortcut needs the mapping to remain the same generation from VirtualQuery through the stores. An address protection snapshot alone does not provide that lifetime across unmap and reuse. The byte-ownership regressions remain useful for checking a guarded fast path.

**@⁠aycow** on GitHub · 2026-11-24 18:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7140468649) I retained Duff's authored 3b2181a byte-run copyback in a #387 test branch. Both concurrent title-write controls passed on native Windows with the GPU crate optimized. In a CPU-only 4 MiB snapshot/copyback fixture, changing one byte per 32 bytes generated 131,072 guarded writes and raised median copyback from 1.37 ms to 718.99 ms. The dense and sparse controls are in the [reproduction](https://github.com/aycow/VIctory/blob/c1ad261/docs/copyback-changed-byte-cost.md). I kept this candidate separate from #387. The later direct-store shortcut needs the mapping to remain the same generation from VirtualQuery through the stores. An address protection snapshot alone does not provide that lifetime across unmap and reuse. The byte-ownership regressions remain useful for checking a guarded fast path.
Author
Owner

@⁠Dufftwt on GitHub · 2026-11-24 18:19 UTC · original

@⁠aycow thanks for the controls and the fixture. Your numbers are for 3b2181a, the first commit, which writes one write_mapped per run. This PR's head 67125b3 replaces that with direct stores after one memory query per piece, for exactly this cost. On windows-latest (release build), changing every 2nd byte of 64 pages took 15.6 s with 3b2181a and 14–17 ms at the head. Writing whole pages took 10–11 ms either way.

On the lifetime point, agreed: a query doesn't pin the mapping, and the PR marks the window as a shortcut:. Unmap-and-reuse isn't specific to the direct stores, though. write_mapped, main's whole-piece write included, also writes into whatever is mapped at the address when it runs. What keeps all of them safe is the order: the GPU's bytes go back before the title is told the submission is done, so only a title freeing memory the GPU is still writing could hit it. Unmapped or read-only memory at store time would fault here rather than be skipped. TG0000's fault-tolerant copy (#1010) closes that window, and switching to it is the planned follow-up once both land. Your byte-ownership regressions would be good tests for it.

**@⁠Dufftwt** on GitHub · 2026-11-24 18:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7140484968) @⁠aycow thanks for the controls and the fixture. Your numbers are for `3b2181a`, the first commit, which writes one `write_mapped` per run. This PR's head `67125b3` replaces that with direct stores after one memory query per piece, for exactly this cost. On `windows-latest` (release build), changing every 2nd byte of 64 pages took 15.6 s with `3b2181a` and 14–17 ms at the head. Writing whole pages took 10–11 ms either way. On the lifetime point, agreed: a query doesn't pin the mapping, and the PR marks the window as a `shortcut:`. Unmap-and-reuse isn't specific to the direct stores, though. `write_mapped`, `main`'s whole-piece write included, also writes into whatever is mapped at the address when it runs. What keeps all of them safe is the order: the GPU's bytes go back before the title is told the submission is done, so only a title freeing memory the GPU is still writing could hit it. Unmapped or read-only memory at store time would fault here rather than be skipped. TG0000's fault-tolerant copy (#1010) closes that window, and switching to it is the planned follow-up once both land. Your byte-ownership regressions would be good tests for it.
Author
Owner

@⁠ThomasHFWright on GitHub · 2026-11-24 18:41 UTC · original

Linux/Wine integration test of head 67125b3a891afcb70417ca222a21d768fe0e05ff: the copy-back regressions pass after accounting for the submission boundary in Slaktarn700's proton-fixes write-watch cache.

Setup: RTX 5090, NVIDIA 620.73.04, CachyOS7.3.6, Wine11.22, vkd3d-proton3.2.0 30b0eb9bc12dc9f, pinned Rust1.98.1 Windows MSVC cross-build. Integration base is proton-fixes993dff8 + #852 + #454 + #206, with local fence/descriptor probes. This is not an isolated-main or Steam Proton test.

The production delta merged into host.rs and shadow.rs cleanly. watch.rs had an insertion conflict: I retained the Wine-specific functions and added your test-only forget helper.

The first diagnostic GPU suite was 60 passed / 1 failed / 1 ignored. The failing test was a_title_write_during_copy_back_reaches_the_copy, expected7, read0. This branch intentionally reuses write-watch answers within a submission; the next title submission calls watch::new_submission() before refreshing. Adding that same boundary at the start of submitted() and immediately before the test's next s.update(base, PAGE) makes the suite 61 passed / 0 failed / 1 ignored. No assertions weakened and no production change beyond your patch. This is an integration-specific fixture adaptation, not evidence that your main-based test is wrong.

Full Windows workspace on the adapted integration: 350 passed / 2 failed / 7 ignored, 14 test executables. Default-feature GPU58/0/1, shader122/0/2. The two unchanged Wine harness failures are the load probe's nested Linux cargo invocation and xtask's Linux git invocation. All-target/all-feature Clippy with warnings denied and native asset policy pass. Four shader differential tests still early-return without console/compiler tools; the local opt-in buffer-view diagnostic is the extra ignored test.

Native Microsoft d3dcompiler_47 used; GPU tests ran on the RTX5090, serially, offline. No concurrent title GPU workload. No title run with this patch yet, so this establishes regression-test compatibility only, not a fix for world rendering, #698, or the GPU execution fault.

AI-assisted with Codex. No game data or derived artifacts attached.

**@⁠ThomasHFWright** on GitHub · 2026-11-24 18:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7140997996) Linux/Wine integration test of head `67125b3a891afcb70417ca222a21d768fe0e05ff`: the copy-back regressions pass after accounting for the submission boundary in Slaktarn700's `proton-fixes` write-watch cache. Setup: RTX 5090, NVIDIA 620.73.04, CachyOS7.3.6, Wine11.22, vkd3d-proton3.2.0 `30b0eb9bc12dc9f`, pinned Rust1.98.1 Windows MSVC cross-build. Integration base is proton-fixes993dff8 + #852 + #454 + #206, with local fence/descriptor probes. This is not an isolated-main or Steam Proton test. The production delta merged into `host.rs` and `shadow.rs` cleanly. `watch.rs` had an insertion conflict: I retained the Wine-specific functions and added your test-only `forget` helper. The first diagnostic GPU suite was **60 passed / 1 failed / 1 ignored**. The failing test was `a_title_write_during_copy_back_reaches_the_copy`, expected7, read0. This branch intentionally reuses write-watch answers within a submission; the next title submission calls `watch::new_submission()` before refreshing. Adding that same boundary at the start of `submitted()` and immediately before the test's next `s.update(base, PAGE)` makes the suite **61 passed / 0 failed / 1 ignored**. No assertions weakened and no production change beyond your patch. This is an integration-specific fixture adaptation, not evidence that your main-based test is wrong. Full Windows workspace on the adapted integration: **350 passed / 2 failed / 7 ignored**, 14 test executables. Default-feature GPU58/0/1, shader122/0/2. The two unchanged Wine harness failures are the load probe's nested Linux cargo invocation and xtask's Linux git invocation. All-target/all-feature Clippy with warnings denied and native asset policy pass. Four shader differential tests still early-return without console/compiler tools; the local opt-in buffer-view diagnostic is the extra ignored test. Native Microsoft d3dcompiler_47 used; GPU tests ran on the RTX5090, serially, offline. No concurrent title GPU workload. No title run with this patch yet, so this establishes regression-test compatibility only, not a fix for world rendering, #698, or the GPU execution fault. AI-assisted with Codex. No game data or derived artifacts attached.
Author
Owner

@⁠ThomasHFWright on GitHub · 2026-11-24 19:07 UTC · original

Title follow-up to my synthetic Linux report: #1024 was tested for world loading, but it did not get past the later #698 pool exhaustion.

Same RTX5090 / NVIDIA620.73.04 / Wine11.22 / vkd3d-proton3.2.0 setup and diagnostics as above. The direct control was the #747-style capped split (737856 mirrored / 262144 dynamic) on proton-fixes993dff8 + #852/#454/#206. The candidate adds only this PR's production delta at67125b3; its test fixtures retain the two submission-boundary adaptations described above. Both runs disabled VK_NV_raw_access_chains, used default loop limit, no shader skips, debug pixel shader and intermediate-target display.

  • Capped control: zero slot warnings; frames stopped around278s, title worker sampled at+0x50eb826/+0x50eb81f (#774). Planned stop at600s. No Xid or GPU-fence timeout. Control details.
  • With #1024: 553.2s, exit3, world frames continued until the title breakpoint0x80000003 at+0x5149aec. Local title report: INSTANCE_LIST45000/45000, BUILDING21940/22500. Zero dynamic-slot warnings, no Xid or GPU-fence timeout;118 dispatch notes for72f552f4553fb5f9. All1134 dumped SPIR-V modules validate with Vulkan1.3/scalar-block-layout.

Local captures show partial roads, signs and character geometry in debug colours; normal shaded rendering and controllable movement remain unverified. The #774 spin did not recur in this one candidate run, but that failure is intermittent, so this does not establish that #1024 fixes it. #698 is still reproduced. These runs are not a performance benchmark.

Combined candidate checks: full Windows workspace350passed/2unchanged Wine harness failures/7ignored across14executables, diagnostic GPU61/0/1, all-target/all-feature Clippy-Dwarnings and native policy pass. Binary SHA256 00abe81ba6f0c46188427ff2dde9bc8937bb09ac4e8b770351f5a00e622e5462.

AI-assisted with Codex; offline/app-muted, read-only title input. All runs stopped. No game-derived files attached.

**@⁠ThomasHFWright** on GitHub · 2026-11-24 19:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7141641576) Title follow-up to my synthetic Linux report: #1024 was tested for world loading, but it did not get past the later #698 pool exhaustion. Same RTX5090 / NVIDIA620.73.04 / Wine11.22 / vkd3d-proton3.2.0 setup and diagnostics as above. The direct control was the #747-style capped split (737856 mirrored / 262144 dynamic) on proton-fixes993dff8 + #852/#454/#206. The candidate adds only this PR's production delta at67125b3; its test fixtures retain the two submission-boundary adaptations described above. Both runs disabled VK_NV_raw_access_chains, used default loop limit, no shader skips, debug pixel shader and intermediate-target display. - Capped control: zero slot warnings; frames stopped around278s, title worker sampled at+0x50eb826/+0x50eb81f (#774). Planned stop at600s. No Xid or GPU-fence timeout. [Control details](https://git.gtahub.st/github/Marvisak--VIctory/issues/747). - With #1024: **553.2s, exit3**, world frames continued until the title breakpoint0x80000003 at+0x5149aec. Local title report: **INSTANCE_LIST45000/45000**, BUILDING21940/22500. Zero dynamic-slot warnings, no Xid or GPU-fence timeout;118 dispatch notes for72f552f4553fb5f9. All1134 dumped SPIR-V modules validate with Vulkan1.3/scalar-block-layout. Local captures show partial roads, signs and character geometry in debug colours; normal shaded rendering and controllable movement remain unverified. The #774 spin did not recur in this one candidate run, but that failure is intermittent, so this does **not** establish that #1024 fixes it. #698 is still reproduced. These runs are not a performance benchmark. Combined candidate checks: full Windows workspace350passed/2unchanged Wine harness failures/7ignored across14executables, diagnostic GPU61/0/1, all-target/all-feature Clippy-Dwarnings and native policy pass. Binary SHA256 `00abe81ba6f0c46188427ff2dde9bc8937bb09ac4e8b770351f5a00e622e5462`. AI-assisted with Codex; offline/app-muted, read-only title input. All runs stopped. No game-derived files attached.
Author
Owner

@⁠Dufftwt on GitHub · 2026-11-24 19:08 UTC · original

@⁠ThomasHFWright thanks for running it in the title with a direct control. Agreed: one run doesn't establish a fix for the #774 spin. But it's the second time that freeze has gone with run-only write-back. On #721, xstraok saw the title freeze after about 4 minutes in the world, with two threads spinning in a hash-table probe at +0x50eb81a..+0x50eb83d, on RX 9060 XT / RADV / Proton. With run-only write-back they had about 10 minutes and no freeze, and they also called the link a guess from one run each. Your control's spin at +0x50eb81f/+0x50eb826 is in that same range.

A probe that never ends fits #721's race: copy-back writes a whole 64 KiB piece back and puts older bytes over a table entry a title thread just wrote. Two runs on different GPUs and drivers point the same way. A few more control/candidate pairs would turn that into evidence. #698's INSTANCE_LIST limit is the next wall either way.

**@⁠Dufftwt** on GitHub · 2026-11-24 19:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7141655635) @⁠ThomasHFWright thanks for running it in the title with a direct control. Agreed: one run doesn't establish a fix for the #774 spin. But it's the second time that freeze has gone with run-only write-back. On #721, xstraok saw the title freeze after about 4 minutes in the world, with two threads spinning in a hash-table probe at `+0x50eb81a..+0x50eb83d`, on RX 9060 XT / RADV / Proton. With run-only write-back they had about 10 minutes and no freeze, and they also called the link a guess from one run each. Your control's spin at `+0x50eb81f`/`+0x50eb826` is in that same range. A probe that never ends fits #721's race: copy-back writes a whole 64 KiB piece back and puts older bytes over a table entry a title thread just wrote. Two runs on different GPUs and drivers point the same way. A few more control/candidate pairs would turn that into evidence. #698's `INSTANCE_LIST` limit is the next wall either way.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:33 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/shadow.rs, crates/victory-gpu/src/watch.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7148640376) <!-- victory-triage v1 head=67125b3a891afcb70417ca222a21d768fe0e05ff verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-gpu/src/shadow.rs`, `crates/victory-gpu/src/watch.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠anoyarou on GitHub · 2026-11-25 23:14 UTC · original

Another control/candidate pair for the +0x50eb826 freeze, AMD/RADV under Proton Experimental: the candidate differs from the control by the run-only write-back alone.

Setup: Fedora 44 (kernel 7.3.4), RX 9070 XT (RADV), Proton Experimental experimental-11.0-20261112 with its vkd3d-proton, VKD3D_CONFIG=ignore_shared_fence,descriptor_heap. Diag builds of Belobug/VIctory-Belobug-AMD (01aadd1 + its PRs #53, #69, #124, #96, #123, #139, and the watchdog patched out). Series X, started from boot into the intro, the same settings in every run.

Control: 838a88a, 2 of 2 runs froze. World frames stopped at about 315 s and 280 s from launch. One title thread stayed at 100% CPU, the rest waited. With VICTORY_STACKS at 300 s and 420 s, the spinning thread was at

+0x50eb826 ← +0x31962 ← +0x317fd ← +0x25d801b ← +0x221c29c ← +0x2215eca

in both dumps of the second run. That is Ceereals' stack on #1118 and the same range as xstraok's and ThomasHFWright's control above.

Candidate: 838a88a + one commit, the run-only write-back. Shadow::copy_back writes back only the runs of bytes the GPU changed. Each run still goes through write_mapped, which on this tree tries a user-mode copy before WriteProcessMemory. Same settings, from boot: no freeze. World frames kept coming past 280-315 s, and the dumps at 300 s and 420 s showed no thread spinning in title code (the busiest title thread was at ~5% CPU). The run went on until the title's own INSTANCE_LIST breakpoint (#698) at 643 s.

After that: 22 more runs with the fix, and none froze. The fix was carried along while other changes were added. Two runs from boot again reached #698's breakpoint (639 s; and past it with #2644's VICTORY_STEP_OVER, 30 minutes into gameplay). Twenty runs started from a save, most of them 4 to 23 minutes in the world (two were stopped after 1-3 minutes). Copy-back under the fix cost 87-147 ms a frame standing still.

So, on a second GPU vendor's driver stack and with the control and candidate one commit apart, the freeze went away with the run-only write-back, and has not come back in 23 runs. The fix is not the whole of #1024: this tree takes only the run-only write-back part, not the #722 epoch part.

AI-assisted (Claude Code)

**@⁠anoyarou** on GitHub · 2026-11-25 23:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1024#issuecomment-7177309587) **Another control/candidate pair for the `+0x50eb826` freeze, AMD/RADV under Proton Experimental: the candidate differs from the control by the run-only write-back alone.** **Setup:** Fedora 44 (kernel 7.3.4), RX 9070 XT (RADV), Proton Experimental `experimental-11.0-20261112` with its vkd3d-proton, `VKD3D_CONFIG=ignore_shared_fence,descriptor_heap`. Diag builds of Belobug/VIctory-Belobug-AMD (`01aadd1` + its PRs #53, #69, #124, #96, #123, #139, and the watchdog patched out). Series X, started from boot into the intro, the same settings in every run. **Control: `838a88a`, 2 of 2 runs froze.** World frames stopped at about 315 s and 280 s from launch. One title thread stayed at 100% CPU, the rest waited. With `VICTORY_STACKS` at 300 s and 420 s, the spinning thread was at `+0x50eb826 ← +0x31962 ← +0x317fd ← +0x25d801b ← +0x221c29c ← +0x2215eca` in both dumps of the second run. That is Ceereals' stack on #1118 and the same range as xstraok's and ThomasHFWright's control above. **Candidate: `838a88a` + one commit, the run-only write-back.** `Shadow::copy_back` writes back only the runs of bytes the GPU changed. Each run still goes through `write_mapped`, which on this tree tries a user-mode copy before `WriteProcessMemory`. Same settings, from boot: **no freeze**. World frames kept coming past 280-315 s, and the dumps at 300 s and 420 s showed no thread spinning in title code (the busiest title thread was at ~5% CPU). The run went on until the title's own `INSTANCE_LIST` breakpoint (#698) at 643 s. **After that: 22 more runs with the fix, and none froze.** The fix was carried along while other changes were added. Two runs from boot again reached #698's breakpoint (639 s; and past it with #2644's `VICTORY_STEP_OVER`, 30 minutes into gameplay). Twenty runs started from a save, most of them 4 to 23 minutes in the world (two were stopped after 1-3 minutes). Copy-back under the fix cost 87-147 ms a frame standing still. So, on a second GPU vendor's driver stack and with the control and candidate one commit apart, the freeze went away with the run-only write-back, and has not come back in 23 runs. The fix is not the whole of #1024: this tree takes only the run-only write-back part, not the #722 epoch part. AI-assisted (Claude Code)
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/shadow.rs
  • crates/victory-gpu/src/watch.rs
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.
git fetch -u origin '+refs/pull/1024/head:github-bot/gh-1024'
git switch 'github-bot/gh-1024'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1024'
git switch 'github-bot/gh-1024'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1024'
git switch 'github-bot/gh-1024'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1024'
git switch 'main'
git merge --squash 'github-bot/gh-1024'
git switch 'main'
git merge --ff-only 'github-bot/gh-1024'
git switch 'main'
git merge 'github-bot/gh-1024'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1024
No description provided.