GPU: a marked page's copy-back writes only the bytes the shaders changed, with plain stores #2918

Open
github-bot wants to merge 3 commits from github-bot/gh-2918 into main AGit
Owner

@⁠ZeOs360 on GitHub · 2026-11-25 23:55 UTC · original
ZeOs360:pr/marked-copyback-v8 → main · +612 −45 · 4 files · 3 commits · open

What

After a submission whose shaders marked a page as written through views,
Shadow::copy_back_marked writes the copy's whole 64 KiB page into title
memory when the title had not written the page since the copy took it
(the saved == None arm). The title's threads write those pages too, since
its records share the GPU heap. A title write that lands after that check
and before the write is put back to the copy's older bytes. Where the page
was saved, the merged page is written whole as well, so a title write
between its read and the write is undone the same way. This is the
failure Shadow::copy_back already merges against: its comment records the
copy's bytes going back over a fence list the title then read as -1.

This PR changes the copy-back to:

  • read the page while it is still armed, then ask under the guard lock what
    the title did to it (Tracked::finish, which replaces unarm and
    saved). A title write lands wholly before that (the page changed, its
    bytes from before saved if armed) or after it;
  • write only the runs of bytes the shaders changed, compared against those
    bytes from before, with no runs joined across gaps. A title write
    anywhere else in the page stays, and one made after the read is not undone;
  • keep upstream's rule that only a copy holding the whole page takes it,
    and guard it first and read it again after, so the copy also gets a title
    write that landed meanwhile.

Why plain stores

Exact runs are many and small. In the prologue's intro on 940d32f there
were about 3.3 million runs per frame, about 3.6 bytes each (on current
main, 1,400 to 1,900 runs per marked page, 7 to 10 bytes each). One
ReadProcessMemory per run (about 0.4 µs each, more under load) made the
marked copy-back take 1.1 to 3.5 s per frame for 1 to 11 MB (measured on
940d32f).

The runs are written with plain stores. The first commit does it with
watch::store, a rep movsb routine with unwind data. A destination page
that is not writable faults into the existing write handler:

  • a page we guarded is opened, and the store goes on, as for a title write;
  • any other page (nothing mapped, read-only, one that cannot be read in, or
    a title's own guard page) ends the store. The handler resumes the routine
    at its end, and what is left goes through the kernel (host::write_mapped)
    as before.

The second commit makes exact runs cheaper:

  • watch::store_runs writes all of a page's runs in one call (runs of up
    to 16 bytes a byte at a time, longer ones with rep movsb). A fault ends
    the call, which returns the run it was at; that run and the rest go
    through the kernel.
  • changed_runs compares 64 bytes at once (SSE2) into a mask of the bytes
    that differ, and reads the runs from the mask's runs of set bits: a few
    steps per run, none per byte (tested against the byte-by-byte search).
  • A copy holding the whole page reads it again after the guard anyway, so
    the runs are merged only where it holds the page in part or cannot read
    it again. The page and the list of runs are kept by the thread, not made
    per page.

Cost in the intro's scene, averaged over the frames that copied back more
than 500 marked pages (one run of the game each; the third commit changes
only tests):

on 13f91ca on 219878a
main (whole-page writes) 58 µs 51 µs
this PR, first commit 104 µs
this PR, first two commits 55 µs 64 µs

On the current base exact runs cost about 13 µs a page more than the
whole-page write: about 16 ms a frame at about 1,200 marked pages, on
frames of a second or more. The runs differ from run to run of the game
(1,400 to 1,900 a page), so these single runs are rough.

Relation to other PRs

  • #2242 targets the same race. It joins runs separated by less than 256
    bytes (SPAN_GAP) to keep the kernel writes affordable, which still
    rewrites the unchanged bytes in those gaps. With plain stores, exact runs
    (gap 0) cost about 1.25 times the whole-page write (see the table above),
    so no gap is needed. This PR does not use #2242's code.
  • r4tedx described a plain-store prototype in #2242's thread (fork branch
    perf/copy-back-spans) with the same fallback idea. That work has no PR,
    and this one was written independently.
  • It builds on what main merged since: armed page runs (#2147), saving a
    page before any guard is opened and updating saved bytes on a partial
    refresh (#2239, #2377), and partial and edge pages (#2172).

Tests

  • shadow::tests::marked_copy_back_keeps_a_title_write_made_meanwhile
    writes the page from the title while the copy-back runs, once while the
    page is armed and once after the copy-back asked. With the whole-page
    write, both cases fail, and the title's bytes come back as ff ff ff ff.
    With this change both pass.
  • watch::tests::stores_mark_guarded_pages_and_stop_at_unwritable_ones
    writes short and long runs and covers four destinations: a guarded page
    (opened and marked changed, also from inside rep movsb), a read-only
    page, a decommitted page, and a title guard page, plus empty and reversed
    runs.
  • shadow::tests::changed_runs_are_those_byte_by_byte checks the
    64-byte search against the byte-by-byte one on random data of many
    lengths and densities, and on runs at block edges, in the tail and in
    slices that do not start on 16 bytes.
  • The third commit makes the tests that work on registered copies of
    title memory themselves (eight in shadow, one in host) hold off
    submissions (Host::no_submissions, tests only), as Host::execute
    does around its own copy-back. Another test's submission in parallel
    could refresh their copies or take their marks meanwhile, which is why
    partial_refresh_under_marked_range_updates_saved_bytes sometimes failed
    on main; the longer copy-back of this PR made it and two more fail in
    13 of 30 parallel runs. With the lock: no failure in 40 parallel runs of
    the crate's tests.
  • cargo test -p victory-gpu: 234 passed. cargo clippy --workspace --all-targets -- -D warnings, with and without --all-features: clean.
    cargo xtask policy: ok.
  • Two victory-shader tests fail on my machine with a DXIL validation
    error (rectangles_get_their_fourth_corner,
    elements_sharing_a_row_keep_their_order). This PR does not touch that
    crate, and it is identical to main there.

In game

Machine: RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, Windows 11, Series X
profile, diagnostics builds. My own copy of the title was used; only log
lines, sizes and timings are reported here.

  • On 13f91ca with this PR, the intro's scene ran 493 s (one run
    with the first commit) without the -1 read, against 487 s for one stock
    run. Neither run hit it, so this says nothing either way about the crash;
    it shows the change runs in game.
  • On 940d32f, one of two stock runs hit a title read of address -1 at
    image+0x4f400a9, about 64 frames into the intro's scene. Builds with the
    view-mark fixes ran up to about 332 frames there without it. Those builds
    carried more than this change, so this does not show that this change
    alone removes that crash.
  • On main I make no in-game claim about the -1 read: one run
    cannot show whether it became rarer. The race is still in the code, and
    the test above reproduces it.
  • On every run on this 16 GB machine, CreateCommittedResource for
    shared (CUSTOM, L0) buffers began failing with E_OUTOFMEMORY after 2.5
    to 5 minutes, and the run ended 3.5 to 9.5 minutes in. This happens on
    main as well and is unrelated to this change. After the failures
    began, some runs stopped within a minute with "a host command list did
    not close" (once with E_OUTOFMEMORY as its error). That happened with
    this PR, and also with a build that does not contain it; stock main
    and the first commit alone ran about 6 more minutes, until the title
    stopped. So I take it to follow from the failed allocations, not from
    this change. The cost numbers above come from the first minutes in the
    intro, before a run was stopped by me or by that failure.

AI-assisted: written with Claude Code (Claude Opus 5.5) and reviewed by
Gemini 4 Neon. I read the code and the reviews, and ran the in-game tests
on my machine.

**@⁠ZeOs360** on GitHub · 2026-11-25 23:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2918) `ZeOs360:pr/marked-copyback-v8` → `main` · +612 −45 · 4 files · 3 commits · open ## What After a submission whose shaders marked a page as written through views, `Shadow::copy_back_marked` writes the copy's whole 64 KiB page into title memory when the title had not written the page since the copy took it (the `saved == None` arm). The title's threads write those pages too, since its records share the GPU heap. A title write that lands after that check and before the write is put back to the copy's older bytes. Where the page was saved, the merged page is written whole as well, so a title write between its read and the write is undone the same way. This is the failure `Shadow::copy_back` already merges against: its comment records the copy's bytes going back over a fence list the title then read as -1. This PR changes the copy-back to: - read the page while it is still armed, then ask under the guard lock what the title did to it (`Tracked::finish`, which replaces `unarm` and `saved`). A title write lands wholly before that (the page changed, its bytes from before saved if armed) or after it; - write only the runs of bytes the shaders changed, compared against those bytes from before, with no runs joined across gaps. A title write anywhere else in the page stays, and one made after the read is not undone; - keep upstream's rule that only a copy holding the whole page takes it, and guard it first and read it again after, so the copy also gets a title write that landed meanwhile. ## Why plain stores Exact runs are many and small. In the prologue's intro on 940d32f there were about 3.3 million runs per frame, about 3.6 bytes each (on current `main`, 1,400 to 1,900 runs per marked page, 7 to 10 bytes each). One `ReadProcessMemory` per run (about 0.4 µs each, more under load) made the marked copy-back take 1.1 to 3.5 s per frame for 1 to 11 MB (measured on 940d32f). The runs are written with plain stores. The first commit does it with `watch::store`, a `rep movsb` routine with unwind data. A destination page that is not writable faults into the existing write handler: - a page we guarded is opened, and the store goes on, as for a title write; - any other page (nothing mapped, read-only, one that cannot be read in, or a title's own guard page) ends the store. The handler resumes the routine at its end, and what is left goes through the kernel (`host::write_mapped`) as before. The second commit makes exact runs cheaper: - `watch::store_runs` writes all of a page's runs in one call (runs of up to 16 bytes a byte at a time, longer ones with `rep movsb`). A fault ends the call, which returns the run it was at; that run and the rest go through the kernel. - `changed_runs` compares 64 bytes at once (SSE2) into a mask of the bytes that differ, and reads the runs from the mask's runs of set bits: a few steps per run, none per byte (tested against the byte-by-byte search). - A copy holding the whole page reads it again after the guard anyway, so the runs are merged only where it holds the page in part or cannot read it again. The page and the list of runs are kept by the thread, not made per page. Cost in the intro's scene, averaged over the frames that copied back more than 500 marked pages (one run of the game each; the third commit changes only tests): | | on 13f91ca | on 219878a | |---|---|---| | `main` (whole-page writes) | 58 µs | 51 µs | | this PR, first commit | 104 µs | | | this PR, first two commits | 55 µs | 64 µs | On the current base exact runs cost about 13 µs a page more than the whole-page write: about 16 ms a frame at about 1,200 marked pages, on frames of a second or more. The runs differ from run to run of the game (1,400 to 1,900 a page), so these single runs are rough. ## Relation to other PRs - #2242 targets the same race. It joins runs separated by less than 256 bytes (`SPAN_GAP`) to keep the kernel writes affordable, which still rewrites the unchanged bytes in those gaps. With plain stores, exact runs (gap 0) cost about 1.25 times the whole-page write (see the table above), so no gap is needed. This PR does not use #2242's code. - r4tedx described a plain-store prototype in #2242's thread (fork branch `perf/copy-back-spans`) with the same fallback idea. That work has no PR, and this one was written independently. - It builds on what `main` merged since: armed page runs (#2147), saving a page before any guard is opened and updating saved bytes on a partial refresh (#2239, #2377), and partial and edge pages (#2172). ## Tests - `shadow::tests::marked_copy_back_keeps_a_title_write_made_meanwhile` writes the page from the title while the copy-back runs, once while the page is armed and once after the copy-back asked. With the whole-page write, both cases fail, and the title's bytes come back as `ff ff ff ff`. With this change both pass. - `watch::tests::stores_mark_guarded_pages_and_stop_at_unwritable_ones` writes short and long runs and covers four destinations: a guarded page (opened and marked changed, also from inside `rep movsb`), a read-only page, a decommitted page, and a title guard page, plus empty and reversed runs. - `shadow::tests::changed_runs_are_those_byte_by_byte` checks the 64-byte search against the byte-by-byte one on random data of many lengths and densities, and on runs at block edges, in the tail and in slices that do not start on 16 bytes. - The third commit makes the tests that work on registered copies of title memory themselves (eight in `shadow`, one in `host`) hold off submissions (`Host::no_submissions`, tests only), as `Host::execute` does around its own copy-back. Another test's submission in parallel could refresh their copies or take their marks meanwhile, which is why `partial_refresh_under_marked_range_updates_saved_bytes` sometimes failed on `main`; the longer copy-back of this PR made it and two more fail in 13 of 30 parallel runs. With the lock: no failure in 40 parallel runs of the crate's tests. - `cargo test -p victory-gpu`: 234 passed. `cargo clippy --workspace --all-targets -- -D warnings`, with and without `--all-features`: clean. `cargo xtask policy`: ok. - Two `victory-shader` tests fail on my machine with a DXIL validation error (`rectangles_get_their_fourth_corner`, `elements_sharing_a_row_keep_their_order`). This PR does not touch that crate, and it is identical to `main` there. ## In game Machine: RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, Windows 11, Series X profile, diagnostics builds. My own copy of the title was used; only log lines, sizes and timings are reported here. - On 13f91ca with this PR, the intro's scene ran 493 s (one run with the first commit) without the -1 read, against 487 s for one stock run. Neither run hit it, so this says nothing either way about the crash; it shows the change runs in game. - On 940d32f, one of two stock runs hit a title read of address -1 at image+0x4f400a9, about 64 frames into the intro's scene. Builds with the view-mark fixes ran up to about 332 frames there without it. Those builds carried more than this change, so this does not show that this change alone removes that crash. - On `main` I make no in-game claim about the -1 read: one run cannot show whether it became rarer. The race is still in the code, and the test above reproduces it. - On every run on this 16 GB machine, `CreateCommittedResource` for shared (CUSTOM, L0) buffers began failing with E_OUTOFMEMORY after 2.5 to 5 minutes, and the run ended 3.5 to 9.5 minutes in. This happens on `main` as well and is unrelated to this change. After the failures began, some runs stopped within a minute with "a host command list did not close" (once with E_OUTOFMEMORY as its error). That happened with this PR, and also with a build that does not contain it; stock `main` and the first commit alone ran about 6 more minutes, until the title stopped. So I take it to follow from the failed allocations, not from this change. The cost numbers above come from the first minutes in the intro, before a run was stopped by me or by that failure. AI-assisted: written with Claude Code (Claude Opus 5.5) and reviewed by Gemini 4 Neon. I read the code and the reviews, and ran the in-game tests on my machine.
After a submission whose shaders marked a page as written through views,
copy_back_marked wrote the copy's whole 64 KiB page into title memory
when the title had not written the page since the copy took it. The
title's threads write those pages too (its records share the GPU heap):
a title write landing after that check and before the write was put back
to the copy's older bytes. Where the page was saved, the merged page was
written whole too, so a title write between its read and the write was
undone the same way. Shadow::copy_back already merges for this reason:
its comment records the copy's bytes going back over a fence list the
title then read as -1.

The copy-back now
- reads the page while it is still armed, then asks under the guard lock
  what the title did to it (Tracked::finish, replacing unarm and saved):
  a title write lands wholly before that (the page changed, its bytes from
  before saved if armed) or after it;
- writes only the runs of bytes the shaders changed against those bytes
  from before, so a title write elsewhere in the page stays, and one after
  the read is not undone;
- has a copy holding the whole page take it, guarded and then read again,
  so the copy gets a title write that landed meanwhile.

The runs are written with plain stores (watch::store, `rep movsb`), not
a ReadProcessMemory each: in the world there are millions a frame, a few
bytes each, and a system call apiece cost 1.1 to 3.5 s a frame. A
destination page that is not writable faults into the write handler: a
page we guarded is opened and the store goes on; any other (nothing mapped,
read-only, one that cannot be read in, a title's own guard page) ends the
store, which returns the bytes left, and those and the page's remaining
runs go through the kernel as before. The diagnostics line counts the
runs.

Tests: marked_copy_back_keeps_a_title_write_made_meanwhile writes the
page from the title while the copy-back runs, once while the page is
armed and once after the copy-back asked (both fail with the whole-page
write: the title's bytes come back as ff ff ff ff);
stores_mark_guarded_pages_and_stop_at_unwritable_ones. The tests of armed
runs and busy aliases ask Tracked::finish for the saved bytes; that
unarms the page, so the disarm check arms every page again first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The copy-back of marked pages writes only the runs of bytes the shaders
changed: in the world about 1,500 a page, 7 to 10 bytes each, spread over
most of it. Run by run it cost about 100 µs a page, against 58 µs for
writing the whole page (on 13f91ca). Three things went:

- A call per run: watch::store_runs writes all of a page's runs in one
  call. Runs of up to 16 bytes are copied a byte at a time, longer ones
  with `rep movsb`, whose start costs as much as a short run. A store that
  faults at a page that is not writable ends the call, which returns the
  run it was at; that run and the rest go through the kernel as before.
  The runs are `[usize; 2]`, whose layout is fixed, for the routine.
- A step per byte: changed_runs compares 64 bytes at once (SSE2) into a
  mask of the bytes that differ, and reads the runs from the mask's runs
  of set bits, a few steps per run and none per byte.
- Merging and allocating: a copy holding the whole page reads it again
  after the guard anyway, so the runs are merged into the bytes read only
  where it holds the page in part or cannot read it again; the page's
  bytes and the list of runs are kept by the thread, not made per page.

In the prologue's intro the marked copy-back costs about 64 µs a page,
against about 51 µs for writing whole pages (on 13f91ca: 55 against 58).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Host::execute prepares, runs and copies back under its submission lock.
Tests that register a copy of title memory and then update it or copy
it back themselves did not hold that lock, so a submission of another
test running in parallel could
- bring every registered copy up to date meanwhile (a submission using
  title memory, as the memory tests' do): it took the test's changed
  page, dropped the bytes saved of it and copied the title's bytes over
  the shaders';
- copy back the marked pages of the shared mark bitmaps, taking the
  marks a test had just set.

partial_refresh_under_marked_range_updates_saved_bytes failed that way
now and then on main (a shader byte read back as 0), and the exact-run
copy-back of the commits before, with its longer window, made it and
two more of these tests fail in over two-fifths of parallel runs (13 of
30). The tests that do this now hold the lock while they run
(Host::no_submissions, tests only): no failure in 40 parallel runs of
the crate's tests (nor in 65 more with only the four copy-back tests
holding it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:17:29 +00:00
Author
Owner

@⁠Kajanos on GitHub · 2026-11-26 00:07 UTC · original

Windows 11 / NVIDIA test run, head eed0c767c8 merged onto main 63bcca43c6.

Setup: Windows 11 Home build 26300, RTX 5080, NVIDIA 621.40, rustc 1.98.1 MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100 (dxil.dll from the SDK).

  • cargo test --locked -p victory-gpu: 234 passed, 0 failed, 1 ignored (main: 231).

Not run: the retail title, clippy, and other crates.

AI-assisted (Claude Code)

**@⁠Kajanos** on GitHub · 2026-11-26 00:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2918#issuecomment-7178413537) **Windows 11 / NVIDIA test run**, head `eed0c767c8` merged onto `main` `63bcca43c6`. Setup: Windows 11 Home build 26300, RTX 5080, NVIDIA 621.40, rustc 1.98.1 MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100 (`dxil.dll` from the SDK). - `cargo test --locked -p victory-gpu`: 234 passed, 0 failed, 1 ignored (`main`: 231). Not run: the retail title, clippy, and other crates. AI-assisted (Claude Code)
Author
Owner

@⁠MeMako on GitHub · 2026-11-26 03:30 UTC · original

Independent verification of eed0c76 on AMD Ryzen 9 7950X + AMD Radeon RX 9070 XT (adapter 0, driver 32.0.32029.2010, 32 GB RAM, Windows 11 10.0.26200 x64).

CI checks & tests:

  • cargo clippy -p victory-gpu -p victory --all-targets --locked -- -D warnings (and --all-features): pass
  • cargo test -p victory-gpu --locked: 243 passed, 0 failed (including marked_copy_back_keeps_a_title_write_made_meanwhile, stores_mark_guarded_pages_and_stop_at_unwritable_ones, and changed_runs_are_those_byte_by_byte)

Live title run (release build, warm shader & pipeline cache):
(Note: merged cleanly onto a local RX 9070 XT branch on 842b0cb with a separate-handle workaround equivalent to #2122, DYNAMIC = 1 << 19, #2051, #2472, and a local timing breakdown of copy_back_marks; before/after compared against the exact same branch without #2918.)

Metric (world frames, draws >= 500) Without #2918 (n=50) With #2918 (n=97)
Marked pages / frame (median) 2,444 2,662
Marked bytes written back / frame (median) 97.9 MB (whole pages) 35.5 MB (changed bytes only)
copy_back_marks time (median) 54.9 ms (22.9 µs/page) 81.7 ms (32.2 µs/page, +9.3 µs/page)
Title corruption crashes (read 0xffffffffffffffff) 1 (previous run also hit 1) 0 across 8+ minutes in world

Consistent with your Ryzen 5 5600 measurements (+13 µs/page vs +9.3 µs/page here on a 7950X), and eliminates ~62 MB/frame of whole-page overwrites over unchanged title memory.

No game data, shader names, or screenshots are included, per docs/asset-policy.md. Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.

**@⁠MeMako** on GitHub · 2026-11-26 03:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2918#issuecomment-7181782354) Independent verification of `eed0c76` on AMD Ryzen 9 7950X + AMD Radeon RX 9070 XT (adapter 0, driver `32.0.32029.2010`, 32 GB RAM, Windows 11 `10.0.26200` x64). **CI checks & tests:** - `cargo clippy -p victory-gpu -p victory --all-targets --locked -- -D warnings` (and `--all-features`): pass - `cargo test -p victory-gpu --locked`: 243 passed, 0 failed (including `marked_copy_back_keeps_a_title_write_made_meanwhile`, `stores_mark_guarded_pages_and_stop_at_unwritable_ones`, and `changed_runs_are_those_byte_by_byte`) **Live title run (release build, warm shader & pipeline cache):** *(Note: merged cleanly onto a local RX 9070 XT branch on `842b0cb` with a separate-handle workaround equivalent to #2122, `DYNAMIC = 1 << 19`, #2051, #2472, and a local timing breakdown of `copy_back_marks`; before/after compared against the exact same branch without #2918.)* | Metric (world frames, `draws >= 500`) | Without #2918 (`n=50`) | With #2918 (`n=97`) | |---|---|---| | Marked pages / frame (median) | `2,444` | `2,662` | | Marked bytes written back / frame (median) | `97.9 MB` (whole pages) | **`35.5 MB`** (changed bytes only) | | `copy_back_marks` time (median) | `54.9 ms` (`22.9 µs/page`) | `81.7 ms` (`32.2 µs/page`, `+9.3 µs/page`) | | Title corruption crashes (`read 0xffffffffffffffff`) | `1` (previous run also hit `1`) | **`0`** across 8+ minutes in world | Consistent with your Ryzen 5 5600 measurements (`+13 µs/page` vs `+9.3 µs/page` here on a 7950X), and eliminates ~62 MB/frame of whole-page overwrites over unchanged title memory. No game data, shader names, or screenshots are included, per `docs/asset-policy.md`. Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:31 UTC · original · edited 2026-11-26 07:23 UTC

Automated triage for the maintainers.

Needs work: needs the maintainer's decision (unchanged). Thanks for the comparison. I checked the one factual point that bears on the choice: #2242 currently does not merge with main (conflicts), while this PR merges cleanly. The head is unchanged, and the code in watch.rs and shadow.rs copy_back_marked still reads correctly.

The open questions are for the maintainer:

  • whether a hand-written global_asm! store routine, with SEH unwind data and a vectored handler that moves RIP, is acceptable;
  • if not, whether to fall back to a kernel copy per run, or to keep #2242 after it is rebased.

The measured cost per marked page (1.25x to 1.4x) is lower than what is reported for #2242.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 04:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2918#issuecomment-7182671109) · edited 2026-11-26 07:23 UTC <!-- victory-triage v1 head=eed0c767c8e738fef27694b2961afa78a05d512e verdict=needs-work at=2026-11-26T07:23:39Z --> Automated triage for the maintainers. **Needs work: needs the maintainer's decision (unchanged).** Thanks for the comparison. I checked the one factual point that bears on the choice: #2242 currently does not merge with main (conflicts), while this PR merges cleanly. The head is unchanged, and the code in `watch.rs` and `shadow.rs` `copy_back_marked` still reads correctly. The open questions are for the maintainer: - whether a hand-written `global_asm!` store routine, with SEH unwind data and a vectored handler that moves RIP, is acceptable; - if not, whether to fall back to a kernel copy per run, or to keep #2242 after it is rebased. The measured cost per marked page (1.25x to 1.4x) is lower than what is reported for #2242. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠ZeOs360 on GitHub · 2026-11-26 04:44 UTC · original

To help with the choice the triage asks for, how this PR and #2242 differ:

this PR #2242
what goes back the exact runs the shaders changed runs, joined into one span when less than 256 bytes apart
a title write landing between the read and the write kept, outside the bytes the shaders changed the same, unless it falls in a gap between joined runs (the shortcut its description states)
paths copy_back_marked copy_back_marked, copy_back_page and the snapshot copy_back
how bytes are written plain stores (store_runs); at a page that is not writable they stop, and the rest goes through the kernel copy one kernel copy per span
cost measured in game about 1.25x per marked page (64 against 51 us, RX 7800 XT, one run each) and 1.4x (32.2 against 22.9 us, RX 9070 XT, MeMako's report above) about 2.7x per MB written back with #2280 on top, same tree, and 3.2x alone from a different tree and scene (RTX 5070, r4tedx's reports on #2242)
state merges cleanly needs a rebase (conflicts in shadow.rs)

On the global_asm!: exact runs need one write per run, and a kernel copy costs about 0.4 us each; r4tedx measured exact runs through it at 509 us per page with one changed word per 64 bytes (synthetic, on #2242). Plain stores need a way past a store into a page the title unmapped or protected meanwhile. Here the guard handler opens our own guarded pages as usual; any other write fault between the routine's labels moves RIP to the routine's exit, which returns the run it was at. r4tedx's fork branch perf/copy-back-spans, mentioned on #2242 before this PR, uses the same approach (an inline rep movsb that the handler steps past).

If you'd rather not have the assembly, this can go back to a kernel copy per run (at the cost above), or be closed in favor of #2242 once it is rebased, whichever you prefer. If this PR is the one you keep, I'll bring copy_back_page and the snapshot path over to the same pieces in a follow-up, which covers what #2242 adds.

**@⁠ZeOs360** on GitHub · 2026-11-26 04:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2918#issuecomment-7182857288) To help with the choice the triage asks for, how this PR and #2242 differ: | | this PR | #2242 | |---|---|---| | what goes back | the exact runs the shaders changed | runs, joined into one span when less than 256 bytes apart | | a title write landing between the read and the write | kept, outside the bytes the shaders changed | the same, unless it falls in a gap between joined runs (the shortcut its description states) | | paths | `copy_back_marked` | `copy_back_marked`, `copy_back_page` and the snapshot `copy_back` | | how bytes are written | plain stores (`store_runs`); at a page that is not writable they stop, and the rest goes through the kernel copy | one kernel copy per span | | cost measured in game | about 1.25x per marked page (64 against 51 us, RX 7800 XT, one run each) and 1.4x (32.2 against 22.9 us, RX 9070 XT, MeMako's report above) | about 2.7x per MB written back with #2280 on top, same tree, and 3.2x alone from a different tree and scene (RTX 5070, r4tedx's reports on #2242) | | state | merges cleanly | needs a rebase (conflicts in `shadow.rs`) | On the `global_asm!`: exact runs need one write per run, and a kernel copy costs about 0.4 us each; r4tedx measured exact runs through it at 509 us per page with one changed word per 64 bytes (synthetic, on #2242). Plain stores need a way past a store into a page the title unmapped or protected meanwhile. Here the guard handler opens our own guarded pages as usual; any other write fault between the routine's labels moves RIP to the routine's exit, which returns the run it was at. r4tedx's fork branch `perf/copy-back-spans`, mentioned on #2242 before this PR, uses the same approach (an inline `rep movsb` that the handler steps past). If you'd rather not have the assembly, this can go back to a kernel copy per run (at the cost above), or be closed in favor of #2242 once it is rebased, whichever you prefer. If this PR is the one you keep, I'll bring `copy_back_page` and the snapshot path over to the same pieces in a follow-up, which covers what #2242 adds.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2918/head:github-bot/gh-2918'
git switch 'github-bot/gh-2918'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2918'
git switch 'github-bot/gh-2918'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2918'
git switch 'github-bot/gh-2918'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2918'
git switch 'main'
git merge --squash 'github-bot/gh-2918'
git switch 'main'
git merge --ff-only 'github-bot/gh-2918'
git switch 'main'
git merge 'github-bot/gh-2918'
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!2918
No description provided.