Back reads: per-buffer diagnostics of the memory bridge, copy-back, refreshes and waits (VICTORY_BACK_READS, diagnostics builds only) #2960
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!2960
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2960"
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?
@AS-AI-DEV on GitHub · 2026-11-29 19:02 UTC · original
AS-AI-DEV:back-reads→main· +1544 −0 · 7 files · 2 commits · openRelated: #2415 (cutting memory-bridging cost),
docs/unified-memory-audit.md(3.6, U0: "a read watch";VICTORY_READ_WATCHis named intexback.rsbut was never built). Needs #2048, or any fix for the diagnostics build, to compile: 829188e's and f889bb0's--features diagnosticsbuild fail on their own (copystat.rsmb,Host::submit's shadowedtiming()).What it changes
Scope: a diagnostic tool only; it changes nothing in how the game runs. Every line it adds to the layer is behind
#[cfg(all(windows, feature = "diagnostics"))], so release builds compile none of it (their code is the same as without this PR). In a diagnostics build it is off unless one of its switches is set, and when on it only counts and logs: it never changes what the title reads or writes, never changes a protection, and makes no copy. The one thing it does to memory is take a sample of stored pages out of the working set, which Windows brings back by itself at the next touch (a soft fault). Its cost when on is in "How it was tested". A change based on what it finds would be a separate PR.A diagnostic for the memory bridge, for everyone working on it. Diagnostics builds only: the module and every hook are
#[cfg(all(windows, feature = "diagnostics"))], so release builds do not change.The layer lands and merges what shaders wrote back into title memory, and refreshes title memory up to its copies, whether or not anything needs the bytes. Per frame and per host copy, this counts what happens to each stored 64 KiB page until its next store: which of the layer's own readers take it, whether the title writes it, and, on a sample, whether anything touched it at all. The look changes no protection: the stored pages are taken out of the working set (
VirtualUnlockof unlocked pages) and Windows is asked later which came back (QueryWorkingSetEx); a touched page costs one soft fault.It complements
VICTORY_LAND_READS(land/reads.rs): that one makes landed pages no-access and counts the faults, which is exact about reads and writes but changes protections, costs a fault per page, and gives totals only. This one is passive and gives the table by buffer, which says where to work first.Ported from Dathinel/victory-4gb's
backreads.rs, adapted to this tree: stores are hooked where this tree makes them (crate::land's pieces,shadow::put_changedfor merges), and the copy being worked for is a scope on the thread. Added, each its own switch, off unless set:VICTORY_BACK_READS=1|2|alt2also looks at one stored page in 8;alt20 s each way, so the looks' cost showsVICTORY_BACK_READS_KIND=1VICTORY_BACK_READS_TIME=1Host::submit, the frame line's "the submitting thread", on whichever thread runs it); the table ranked by thatVICTORY_BACK_READS_WRITES=1VICTORY_REFRESH_WATCH=1VICTORY_BACK_READS_SCENE=1VICTORY_BACK_READS_WAITS=1crate::hostalready blames on a range of title memory go to the copy that holds it, the rest to a row of their own; with the submitting thread's shareVICTORY_BACK_READS_SPLIT_MB=<n>nMB counted by region (a title's big GPU pool is one buffer)VICTORY_BACK_READS_CSV=<file>How to read it, and what it cannot tell, is in
docs/back-reads.md.How it was tested
f889bb0+ #2048's two compile fixes + this.VICTORY_ASYNC_SUBMIT=0needsVICTORY_THIN=0too; that run ended in a device loss, as that configuration has before here without this).VICTORY_CARD_STEPS=0): 22.8 ms counted against the frame line's 24.0 ms "waiting for flights", 70 % of it on two small buffers.SPLIT_MB=8, no row left for a copy over 8 MB.VICTORY_BACK_READS=altand a release build were also run: the release build is unchanged, the game ran normally under both.cargo testpassed for the crates it touches: no new failures;victory-gpu's failures onf889bb0are the same with and without this (every_switch_of_the_translator_is_in_the_key:VICTORY_SCALAR_SPLITSnot read any more; the menu and xmem tests that fail only in the full parallel run). The module only counts and has no tests of its own.cargo clippy -p victory-gpu --all-targets --features diagnostics: nothing in the files and lines this adds (the warnings left are elsewhere).cargo xtask policy: nothing from this (the one finding isheap_sites/frame_users.rs, as onf889bb0). Switches read throughasked_for!where they are on/off.Checked for overlap
VICTORY_LAND_READS(in the tree, complementary, see above); no open PR adds a per-buffer read or refresh watch.@akimfomin on GitHub · 2026-11-29 19:53 UTC · original
Thanks for adding per-buffer evidence. We’re evaluating the read-back path for native 2560×1440 on Ada, with Series X, RT enabled, DLSS and FG off. Your observation that one 174 MB buffer accounts for half the stored bytes stood out. Which counters or negative controls would you use to separate truly redundant transfers from CPU-visible partial writes and from time waiting for GPU completion? Have you identified a public synthetic workload where omitting a transfer remained byte-exact? We’d like to validate the invariants before trying a change in-game.
@AS-AI-DEV on GitHub · 2026-11-29 20:14 UTC · original · edited 2026-11-29 21:20 UTC
Thanks, good questions. What the tool can and cannot separate, as it stands:
Redundant vs. partial CPU writes vs. needed, per stored 64 KiB page until its next store:
VICTORY_BACK_READS=2): nothing touched the page at all. This is the candidate for "the transfer was redundant".VICTORY_BACK_READS_WRITES=1, by write faults on guarded memory (never the layer's: its stores open the guard first) and by the journal on write-watched memory (the first asking after the layer's store is that store itself, so this is a lower bound). A page in this bucket was overwritten, but possibly only in part: the tool does not tell a partial write from a whole one, so this bucket alone does not prove the transfer redundant.Negative controls / cross-checks I would use:
VICTORY_LAND_READS=1(already in the tree) on the same scene: it makes landed pages no-access and counts the faults by whose code, exact about reads vs. writes. Its "other code read" should not exceed this tool's something else bucket, and its untouched should match its "landed again untouched".VICTORY_BACK_READS=alt: looks on 20 s, off 20 s, so the looks' own cost (one soft fault per touched page) shows in the frame log.Time waiting for GPU completion is not measured by this tool. It times the CPU work of merges/landings, refreshes and the look for title bytes under flights (
VICTORY_BACK_READS_TIME, split by thread on my local branch at the time, since added to this PR). Waits for flights are in the existing frame line ("waiting for flights") and the card meter.One finding from today that may matter for your evaluation: on this tree (
VICTORY_RELAY=1) the landings run on the relay thread, not on the submitting thread. In a walking run (Series X, 2560x1440, DLSS performance, frame generation 2x, ray tracing off; RTX 5060 Ti, Ryzen 7 5800X), the bridge's CPU time on the submitting thread was ~14.6 ms a frame: refreshes 11.5 ms and the look for title bytes under flights 3.1 ms, while landings/merges there were 0.0 ms (9.5 ms on other threads). So omitting redundant landings would mostly save helper CPU and memory bandwidth, not the frame. Also, the 174 MB buffer is one buffer covering most of a 185 MB GPU pool the title reserves at device start; split by region (VICTORY_BACK_READS_SPLIT_MB=8, on my local branch at the time, since added to this PR), its first 8 MB holds most of its refresh cost.A byte-exact synthetic workload: I have not found or built one. Two candidates in the tree:
host/membench.rs(synthetic frames through the title's own calls, added in the v2026.11.29.02 hotfix) could get a mode that leaves out a class of landing and compares the title-memory bytes the next frame reads against a run that lands everything; and the captured-frame replay (diagnostics builds) could compare render targets with and without a transfer. Neither is done; I would be glad to compare notes if you start one.@AS-AI-DEV on GitHub · 2026-11-29 20:20 UTC · original · edited 2026-11-29 21:20 UTC
A correction to my comment above: where it said "on our branch" (now "on my local branch at the time"), that meant my local working tree, not this pull request's branch, which was unclear. Two things it mentions are not in this PR:
VICTORY_BACK_READS_SPLIT_MB=<n>(copies bigger thannMB counted by region).Everything else in it (the buckets,
VICTORY_BACK_READS_WRITES,alt, theVICTORY_LAND_READScross-check, the limits) matches what this PR contains. If those two would help your evaluation, I can add them here as a separate commit.@AS-AI-DEV on GitHub · 2026-11-29 21:08 UTC · original
Reopened with a second commit (
a1d988f) that adds what was missing above, now checked, plus the waits you asked about:VICTORY_BACK_READS_TIME): time spent preparing submissions (Host::submit, the frame line's "the submitting thread") is counted apart from the helpers', on whichever thread runs it. The earlier version told the thread by its name and would have shown 0 with async submission off; this one does not.VICTORY_BACK_READS_WAITS): the waitscrate::hostalready blames on a range of title memory go to the copy that holds it (no copy is made by looking), the rest to a row of their own, with the submitting thread's share. So a row now tells copying from waiting, the third part of your question.VICTORY_BACK_READS_SPLIT_MB=<n>).How it was checked, walking runs of a diagnostics build (details in the PR text and
docs/back-reads.md):VICTORY_CARD_STEPS=0), 22.8 ms of waits counted against the frame line's 24.0 ms "waiting for flights", 70 % of them on two small buffers; as the route plays normally here, the submissions hardly wait (2.3 ms a frame, presents and synchronous submissions only);The run with
VICTORY_THIN=0andVICTORY_ASYNC_SUBMIT=0ended in a device loss; that configuration has lost the device here before without this module, but say if you see it with it.Back reads: who touches what comes back from the card, per buffer (VICTORY_BACK_READS)to Back reads: per-buffer diagnostics of the memory bridge, copy-back, refreshes and waits (VICTORY_BACK_READS, diagnostics builds only)@AS-AI-DEV on GitHub · 2026-11-29 21:15 UTC · original · edited 2026-11-29 21:20 UTC
@akimfomin thank you for the review and the questions: they shaped the second commit. The waits per buffer (
VICTORY_BACK_READS_WAITS) answer the third part of your question (copying vs. waiting for the card), and the submitting thread is now told apart correctly with async submission on or off.The title and description now say the scope plainly: this is a diagnostic tool only. Release builds compile none of it, diagnostics builds run it only when its switches are set, and it never changes what the title reads or writes. The doc (
docs/back-reads.md) has how to read it, what it costs when on, and how it was checked.If you try it on your setup (GPU-limited, ray tracing on), the waits and the per-buffer table are where it should differ most from mine, and I would be glad to see what it shows.
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.Merge
Merge the changes and update on Forgejo.