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
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork#1169
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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
main085ee7c+ #994 (and the #854/#993 below it) + #346 + #500 + #501, with the structure builder on (VICTORY_BVH_BUILDER=1),RELAY=2and the README's speed set. Scene: the barracks after the hand-off.Method
A diagnostic switch,
VICTORY_READ_CENSUS=1(one commit on forkmain: https://github.com/Yorivel/victory-fork/tree/diag/read-census):host::write_mappedwrites copied-back bytes into title memory, each 4 KiB page it wrote getsPAGE_GUARD, and a bit in a page bitmap.ExceptionInformation[0]), or as the layer's when the faulting instruction is insidevictory.exe.host::read, and the nextwrite_mappedof 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".0x80000001.It slows a run badly: one
VirtualProtectper 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:
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.rsdescribes it:So, every frame:
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_SHOTframe).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: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:
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).Same tree, settings and scene as above. Eight consecutive 5-second readings in the barracks, summed:
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: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 inwatch.rsset a whole new protection on title view memory:protect_aliasandprotect_heresetPAGE_READONLY, andopen_heresetsPAGE_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:
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 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 existingVICTORY_BACK_OWN_VIEWfor view memory.Same tree, settings and scene as above, builder on:
VICTORY_BACK_QUIET=1+VICTORY_BACK_OWN_VIEW=1Copies up per frame fell from about 200 MB to 104-108 MB. 0 exceptions.
@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, withVICTORY_BACK_QUIET=1andVICTORY_BACK_OWN_VIEW=1, builder on, six 5-second readings in the barracks: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.