Copy-back: the title's CPU touches ~0.1-0.3% of what is copied back; the rest is re-read only by the layer's next refresh (read census, RTX 4090) #1169

Open
opened 2026-11-26 03:58:48 +00:00 by github-bot · 4 comments
Owner

@⁠Yorivel on GitHub · 2026-11-25 22:33 UTC · original

AI-assisted (Claude Code). Numbers and log lines only, no game data.

Measured: the title's CPU touches about 0.1-0.3% of what the copy-back writes into title memory. Nearly all the rest is read again only by the layer's own next refresh.

This puts a number on README item (3), "what shaders wrote left on the card until the title's processor reads it … being studied, nothing built". On this machine the copy-back and what follows it are the largest part of a frame.

Setup

RTX 4090 (32-lane waves), driver 621.40, i9-14900K, 64 GB, Windows 11, Series X profile, diagnostics build. Tree: fork main 085ee7c + #994 (and the #854/#993 below it) + #346 + #500 + #501, with the structure builder on (VICTORY_BVH_BUILDER=1), RELAY=2 and the README's speed set. Scene: the barracks after the hand-off.

Method

A diagnostic switch, VICTORY_READ_CENSUS=1 (one commit on fork main: https://github.com/Yorivel/victory-fork/tree/diag/read-census):

  • After host::write_mapped writes copied-back bytes into title memory, each 4 KiB page it wrote gets PAGE_GUARD, and a bit in a page bitmap.
  • A vectored handler, registered first, takes guard hits on those pages. It clears the bit, counts the page once, and lets the access go on. The page is counted as title read or title write (ExceptionInformation[0]), or as the layer's when the faulting instruction is inside victory.exe.
  • The layer's kernel accesses (host::read, and the next write_mapped of the same page) would fail on a guard rather than fault, so they take the guard off first. They count as the layer's, or as "copied back again untouched".
  • A second bitmap of every page the census ever guarded absorbs guard hits in the short window between a bit and its guard. Without it the first version crashed the title with an unhandled 0x80000001.

It slows a run badly: one VirtualProtect per page, so 0.3 fps here. The ratios are what it measures, not the frame time.

Numbers

Six consecutive 5-second readings in the barracks, per second:

copied-back pages guarded touched first by the title (read / write) touched first by the layer
20.7 MB 0.00 / 0.01 MB 13.8 MB
31.1 MB 0.02 / 0.00 MB 24.9 MB
57.9 MB 0.01 / 0.01 MB 61.4 MB
25.4 MB 0.04 / 0.00 MB 33.6 MB
45.9 MB 0.04 / 0.05 MB 36.9 MB
24.3 MB 0.05 / 0.01 MB 31.3 MB

During loading the readings were the same: 70.9 MB guarded against 0.09 / 0.02 MB touched by the title. The run's copy-back was about 106 MB a frame at 0.3 fps, which is about 32 MB/s and agrees with the guarded rate. Zero pages were copied back again untouched: the layer touches nearly every page before the next copy-back of it.

The "title" share is an upper bound. The most frequent "title" reader address, 0x7ffea07dc78b, is in a system DLL, which the layer's own threads also call.

What it means

The layer's own touch is the refresh after the copy-back. shadow.rs describes it:

Our write shows as a title write at the copy's next refresh, which copies those pages once more (some dozens of MB a frame).

So, every frame:

  1. shaders write;
  2. the layer snapshots, compares, and copies the changes back into title memory;
  3. that write shows as a title write, and the layer copies the same bytes up again;
  4. the title's processor almost never looks at them.

Builder on against builder off in the same scene, without the census: 214 ms against 161 ms a frame. Of the 53 ms difference, about 38 ms is preparing and 44 ms copying back (85-88 MB against 58), and only 12 ms is the builder's own card time (from a VICTORY_SHOT frame).

The numbers point to the console's model: leave what shaders wrote on the card, and fetch a page only when the title's processor touches it. A guard or no-access fault per page would do the fetch, as the census's handler already does the counting. That would take out steps 2 and 3 for over 99% of the bytes.

I'm starting a prototype of that, with the fetch on fault, on top of the census code. Pointers to anything in the flights/relay design that rules it out are welcome before I get far.

**@⁠Yorivel** on GitHub · 2026-11-25 22:33 UTC · [original](https://github.com/fxceless/victory-fork/issues/1169) *AI-assisted (Claude Code). Numbers and log lines only, no game data.* **Measured: the title's CPU touches about 0.1-0.3% of what the copy-back writes into title memory. Nearly all the rest is read again only by the layer's own next refresh.** This puts a number on README item (3), *"what shaders wrote left on the card until the title's processor reads it … being studied, nothing built"*. On this machine the copy-back and what follows it are the largest part of a frame. ## Setup RTX 4090 (32-lane waves), driver 621.40, i9-14900K, 64 GB, Windows 11, Series X profile, diagnostics build. Tree: fork `main` `085ee7c` + #994 (and the #854/#993 below it) + #346 + #500 + #501, with the structure builder on (`VICTORY_BVH_BUILDER=1`), `RELAY=2` and the README's speed set. Scene: the barracks after the hand-off. ## Method A diagnostic switch, `VICTORY_READ_CENSUS=1` (one commit on fork `main`: https://github.com/Yorivel/victory-fork/tree/diag/read-census): - After `host::write_mapped` writes copied-back bytes into title memory, each 4 KiB page it wrote gets `PAGE_GUARD`, and a bit in a page bitmap. - A vectored handler, registered first, takes guard hits on those pages. It clears the bit, counts the page once, and lets the access go on. The page is counted as **title read** or **title write** (`ExceptionInformation[0]`), or as **the layer's** when the faulting instruction is inside `victory.exe`. - The layer's kernel accesses (`host::read`, and the next `write_mapped` of the same page) would fail on a guard rather than fault, so they take the guard off first. They count as the layer's, or as "copied back again untouched". - A second bitmap of every page the census ever guarded absorbs guard hits in the short window between a bit and its guard. Without it the first version crashed the title with an unhandled `0x80000001`. It slows a run badly: one `VirtualProtect` per page, so 0.3 fps here. The ratios are what it measures, not the frame time. ## Numbers Six consecutive 5-second readings in the barracks, per second: | copied-back pages guarded | touched first by the title (read / write) | touched first by the layer | |---|---|---| | 20.7 MB | 0.00 / 0.01 MB | 13.8 MB | | 31.1 MB | 0.02 / 0.00 MB | 24.9 MB | | 57.9 MB | 0.01 / 0.01 MB | 61.4 MB | | 25.4 MB | 0.04 / 0.00 MB | 33.6 MB | | 45.9 MB | 0.04 / 0.05 MB | 36.9 MB | | 24.3 MB | 0.05 / 0.01 MB | 31.3 MB | During loading the readings were the same: 70.9 MB guarded against 0.09 / 0.02 MB touched by the title. The run's copy-back was about 106 MB a frame at 0.3 fps, which is about 32 MB/s and agrees with the guarded rate. Zero pages were copied back again untouched: the layer touches nearly every page before the next copy-back of it. The "title" share is an upper bound. The most frequent "title" reader address, `0x7ffea07dc78b`, is in a system DLL, which the layer's own threads also call. ## What it means The layer's own touch is the refresh after the copy-back. `shadow.rs` describes it: > Our write shows as a title write at the copy's next refresh, which copies those pages once more (some dozens of MB a frame). So, every frame: 1. shaders write; 2. the layer snapshots, compares, and copies the changes back into title memory; 3. that write shows as a title write, and the layer copies the same bytes up again; 4. the title's processor almost never looks at them. Builder on against builder off in the same scene, without the census: 214 ms against 161 ms a frame. Of the 53 ms difference, about 38 ms is preparing and 44 ms copying back (85-88 MB against 58), and only 12 ms is the builder's own card time (from a `VICTORY_SHOT` frame). The numbers point to the console's model: leave what shaders wrote on the card, and fetch a page only when the title's processor touches it. A guard or no-access fault per page would do the fetch, as the census's handler already does the counting. That would take out steps 2 and 3 for over 99% of the bytes. I'm starting a prototype of that, with the fetch on fault, on top of the census code. Pointers to anything in the flights/relay design that rules it out are welcome before I get far.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:48 +00:00
Author
Owner

@⁠Yorivel on GitHub · 2026-11-25 22:42 UTC · original

AI-assisted (Claude Code). Numbers only, no game data.

Follow-up: about 92% of the layer's re-reads are the same copy reading back its own output. Other copies and textures account for well under 1%.

The first post counted every access of the layer's as one kind. That left a real question open: a write-back is also how another host copy, or a texture, of the same title memory learns what shaders wrote. Those re-reads would be needed, not waste. Census v2 tells them apart:

  • Each copy-back tags its thread with the copy's id, and the guarded pages record that copy as their owner.
  • Each read path tags its thread too: a copy's refresh (Shadow::copy, copy_changed), a copy-back merge (copy_back_with, relay_merge, card_merge, card_merge_relay), and a texture refresh (with_title, refresh_timed, refresh_unlocked).
  • A guard hit by a tagged thread counts as the layer's even when the faulting instruction is in a system DLL. In v1 such a hit could count as the title's.

Same tree, settings and scene as above. Eight consecutive 5-second readings in the barracks, summed:

the layer's touches of copied-back pages share
the same copy (its refresh, or its next merge) ~92%
another copy ~0.3%
textures ~0.05%
untagged read paths ~8%

0 exceptions. The title's own touches stay at 0.00-0.05 MB/s read and 0.00-0.05 MB/s written, against 5-52 MB/s of copied-back pages guarded.

So the round trip is almost entirely a copy re-reading what it already holds. Leaving shaders' output on the card and fetching a page only when the title's processor touches it would remove about 90% of it with no forwarding between host copies. If every untagged read turned out to be another copy, the other-copy cases could still go card to card. The untagged reads are the builder's record scan, descriptor reads and the like, so most of them probably aren't.

The v2 tags are in the census branch (https://github.com/Yorivel/victory-fork/tree/diag/read-census).

**@⁠Yorivel** on GitHub · 2026-11-25 22:42 UTC · [original](https://github.com/fxceless/victory-fork/issues/1169#issuecomment-7176691045) *AI-assisted (Claude Code). Numbers only, no game data.* **Follow-up: about 92% of the layer's re-reads are the same copy reading back its own output. Other copies and textures account for well under 1%.** The first post counted every access of the layer's as one kind. That left a real question open: a write-back is also how *another* host copy, or a texture, of the same title memory learns what shaders wrote. Those re-reads would be needed, not waste. Census v2 tells them apart: - Each copy-back tags its thread with the copy's id, and the guarded pages record that copy as their owner. - Each read path tags its thread too: a copy's refresh (`Shadow::copy`, `copy_changed`), a copy-back merge (`copy_back_with`, `relay_merge`, `card_merge`, `card_merge_relay`), and a texture refresh (`with_title`, `refresh_timed`, `refresh_unlocked`). - A guard hit by a tagged thread counts as the layer's even when the faulting instruction is in a system DLL. In v1 such a hit could count as the title's. Same tree, settings and scene as above. Eight consecutive 5-second readings in the barracks, summed: | the layer's touches of copied-back pages | share | |---|---| | the same copy (its refresh, or its next merge) | ~92% | | another copy | ~0.3% | | textures | ~0.05% | | untagged read paths | ~8% | 0 exceptions. The title's own touches stay at 0.00-0.05 MB/s read and 0.00-0.05 MB/s written, against 5-52 MB/s of copied-back pages guarded. So the round trip is almost entirely a copy re-reading what it already holds. Leaving shaders' output on the card and fetching a page only when the title's processor touches it would remove about 90% of it with no forwarding between host copies. If every untagged read turned out to be another copy, the other-copy cases could still go card to card. The untagged reads are the builder's record scan, descriptor reads and the like, so most of them probably aren't. The v2 tags are in the census branch (https://github.com/Yorivel/victory-fork/tree/diag/read-census).
Author
Owner

@⁠Yorivel on GitHub · 2026-11-25 22:56 UTC · original

AI-assisted (Claude Code).

A correction to the numbers above: for view memory, the title's share is a lower bound, not a measurement.

The census marks a page with PAGE_GUARD. The write guards in watch.rs set a whole new protection on title view memory: protect_alias and protect_here set PAGE_READONLY, and open_here sets PAGE_READWRITE. Each of those calls drops the census's guard bit. Once the layer re-protects a copied-back view page, a later title read of it no longer faults, and the census never sees it.

So:

  • Private memory (the title's heaps; write-watched, never re-protected) is measured as posted.
  • View memory (the page pool): the title-read counts can be too low.

The split of the layer's own touches in the follow-up (same copy about 92%) is not affected, since those were counted before any re-protection.

A first prototype that leaves copied-back private memory pending until touched, VICTORY_LAZY_BACK, crashes the title within 65-100 s: pointers of all ones are read. A control run of the same build without the switch is clean for 4 minutes. So something reads that memory that neither the overlay on the layer's kernel reads nor the guard catches. I'll post what it is once found. Until then, please read the 0.1-0.3% as "how much the title touched before the layer did", not as how much it needs.

**@⁠Yorivel** on GitHub · 2026-11-25 22:56 UTC · [original](https://github.com/fxceless/victory-fork/issues/1169#issuecomment-7176971521) *AI-assisted (Claude Code).* **A correction to the numbers above: for view memory, the title's share is a lower bound, not a measurement.** The census marks a page with `PAGE_GUARD`. The write guards in `watch.rs` set a whole new protection on title view memory: `protect_alias` and `protect_here` set `PAGE_READONLY`, and `open_here` sets `PAGE_READWRITE`. Each of those calls drops the census's guard bit. Once the layer re-protects a copied-back view page, a later title read of it no longer faults, and the census never sees it. So: - **Private memory** (the title's heaps; write-watched, never re-protected) is measured as posted. - **View memory** (the page pool): the title-read counts can be too low. The split of the layer's own touches in the follow-up (same copy about 92%) is not affected, since those were counted before any re-protection. A first prototype that leaves copied-back private memory pending until touched, `VICTORY_LAZY_BACK`, crashes the title within 65-100 s: pointers of all ones are read. A control run of the same build without the switch is clean for 4 minutes. So something reads that memory that neither the overlay on the layer's kernel reads nor the guard catches. I'll post what it is once found. Until then, please read the 0.1-0.3% as "how much the title touched before the layer did", not as how much it needs.
Author
Owner

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

AI-assisted (Claude Code). Numbers only.

Where this led: with the structure builder on, the barracks now run as fast as they did with the builder off (RTX 4090).

The lazy copy-back prototype went nowhere: it crashed in every run. Guards on private pages vanish without a hit; an audit found 13 such pages in one run. A much simpler change removes the same waste with no guards: write the copy-back as before, but don't let the write read as the title's. That's VICTORY_BACK_QUIET (PR #1188) for private memory, alongside the existing VICTORY_BACK_OWN_VIEW for view memory.

Same tree, settings and scene as above, builder on:

ms a frame
#994 stack alone 214-224
+ #346 (named windows declared only when marked) 192-203
+ VICTORY_BACK_QUIET=1 + VICTORY_BACK_OWN_VIEW=1 164-168
(builder off, for scale) 161

Copies up per frame fell from about 200 MB to 104-108 MB. 0 exceptions.

**@⁠Yorivel** on GitHub · 2026-11-25 23:14 UTC · [original](https://github.com/fxceless/victory-fork/issues/1169#issuecomment-7177302200) *AI-assisted (Claude Code). Numbers only.* **Where this led: with the structure builder on, the barracks now run as fast as they did with the builder off (RTX 4090).** The lazy copy-back prototype went nowhere: it crashed in every run. Guards on private pages vanish without a hit; an audit found 13 such pages in one run. A much simpler change removes the same waste with no guards: write the copy-back as before, but don't let the write read as the title's. That's `VICTORY_BACK_QUIET` (PR #1188) for private memory, alongside the existing `VICTORY_BACK_OWN_VIEW` for view memory. Same tree, settings and scene as above, builder on: | | ms a frame | |---|---| | #994 stack alone | 214-224 | | + #346 (named windows declared only when marked) | 192-203 | | + `VICTORY_BACK_QUIET=1` + `VICTORY_BACK_OWN_VIEW=1` | **164-168** | | (builder off, for scale) | 161 | Copies up per frame fell from about 200 MB to 104-108 MB. 0 exceptions.
Author
Owner

@⁠Yorivel on GitHub · 2026-11-25 23:30 UTC · original

AI-assisted (Claude Code). Numbers only.

One more measurement, to save someone the work: a per-page dirty mask written by shaders would not pay much here.

Before writing one, I counted, in the relay's merges (Shadow::relay_merge), what is looked at against what actually changed. For each stretch, every 4 KiB page of it counts as looked at, and a page counts as changed when the fetched bytes differ from the snapshot. Same tree and scene as above, with VICTORY_BACK_QUIET=1 and VICTORY_BACK_OWN_VIEW=1, builder on, six 5-second readings in the barracks:

per second
looked at 150-157 MB in about 37,700 pages
pages that changed about 22,300 (91-95 MB)
changed spans 92-96 MB

About 60% of what the merges look at did change. A mask would skip the other ~40%: roughly 10 MB a frame of compares at 6 fps, a few milliseconds. What is left of the copy-back is real shader output that the layer can't prove the title won't read. The census says the title touches under 1% of it, but knowing which 1% is what the lazy prototype couldn't do safely.

That run settled at 157-161 ms a frame (6.2-6.4 fps), 0 exceptions.

**@⁠Yorivel** on GitHub · 2026-11-25 23:30 UTC · [original](https://github.com/fxceless/victory-fork/issues/1169#issuecomment-7177649283) *AI-assisted (Claude Code). Numbers only.* **One more measurement, to save someone the work: a per-page dirty mask written by shaders would not pay much here.** Before writing one, I counted, in the relay's merges (`Shadow::relay_merge`), what is looked at against what actually changed. For each stretch, every 4 KiB page of it counts as looked at, and a page counts as changed when the fetched bytes differ from the snapshot. Same tree and scene as above, with `VICTORY_BACK_QUIET=1` and `VICTORY_BACK_OWN_VIEW=1`, builder on, six 5-second readings in the barracks: | per second | | |---|---| | looked at | 150-157 MB in about 37,700 pages | | pages that changed | about 22,300 (91-95 MB) | | changed spans | 92-96 MB | About 60% of what the merges look at did change. A mask would skip the other ~40%: roughly 10 MB a frame of compares at 6 fps, a few milliseconds. What is left of the copy-back is real shader output that the layer can't prove the title won't read. The census says the title touches under 1% of it, but knowing *which* 1% is what the lazy prototype couldn't do safely. That run settled at 157-161 ms a frame (6.2-6.4 fps), 0 exceptions.
This discussion has been locked. Commenting is limited to contributors.
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/fxceless--victory-fork#1169
No description provided.