Copy-back by memory class: opt-in switches to leave GPU writes the title does not read on the card #3838
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!3838
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3838"
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?
@x86 on GitHub · 2026-11-30 08:56 UTC · original
x86:pr/unified-memory-classes→main· +457 −4 · 7 files · 3 commits · merged 2026-11-30 14:12 UTCFixes # (none: no issue for this; see Related below)
What it changes
Every title buffer has a host copy; what shaders write into it is hashed, compared and merged back into title memory after the submission, for the title's CPU and for other copies of the same bytes. On an RTX 5090 in the opening, that bridge costs about 11 ms of a 31 ms frame (measured by switching copy-back and refreshes off for timing only, picture broken), and after the existing 1 MiB write-combined rule most of the copy-back that is left is compare passes over small write-combined copies (about 650 a frame), not bytes.
The title declares how each processor reaches each range of its memory, in the protection it passes to
XMemVirtualAlloc/VirtualProtect(GDK graphics memory overview: GPU read-only, write-combined "garlic", coherent "onion", cached non-coherent, no GPU bits). This PR:shadow::title_memory_protection, fed byxmem'snote_gpu_protection, forgotten intitle_memory_freed), and addsVICTORY_UNIFIED_BACK=<classes>to copy shader writes back only for the classes named.VICTORY_WC_NO_BACK_MIN_BYTES(the floor in bytes),VICTORY_WC_PIECES=1|2(write-combined pieces of copies that also cover other memory, such as the title's main pool;2also copies outside the card's memory),VICTORY_WC_NO_BACK_PC=1(copies in the PC's memory).VICTORY_UNIFIED_ALIAS, on underUNIFIED_BACK, for copies underVICTORY_UNIFIED_ALIAS_MAX= 1 MiB). Small write-combined buffers hold data a later pass reads through another copy (a window of 1 MiB or more) that is refreshed from title memory. With the floor alone, the faces' skinning data went stale and vertices of Jason's and Lucia's faces were pulled to one point beside the head.Everything is off by default; with no switch set the layer behaves as before (the only always-on part is recording each range's protection at allocation/protect time).
VICTORY_UNIFIED_STATS=1adds one frame-rate log line with shader writes per class. Details, the reasons for the 1024-byte floor (the exposure the title reads back lies in 64–256 byte copies; a 64-byte floor overexposes the opening) and the limits are indocs/unified-memory-classes.md.The set measured:
How it was tested
cargo testpassed for the crates it touches: yes, where the tests can run on this PC.victory-hle: all pass (423 + 2 + 1).victory-gpu: the new test and the modules touched pass (shadow::68 passed,watch::65 passed, 0 failed). The tests that need a D3D12 device (e.g.ambient::tests::the_passes_build,shadow::exact_tests::*,shadow::land_tests::*) abort the test binary on this Windows 10 machine (test binaries don't load the Agility runtime); they abort identically on41adb551without this PR.cargo clippy -p victory-gpu -p victory-hle --all-targets: no findings in the lines this PR adds.Limits: one scene, one card, one profile; frame generation was not engaged in the measured runs.
gpu-roandnoncoherentare left out of the copy-back in the measured set with no visible fault, but a scene where the title reads GPU results from non-coherent memory would show one. Other scenes and AMD cards are untested, which is why it is opt-in.Checked for overlap
shadow.rs/host.rs), #1927 and #2433 (touch the write-combined code inshadow.rs; may need a rebase against each other)The title declares how each processor reaches each range of its memory: the protection it passes to XMemVirtualAlloc and VirtualProtect (GDK graphics memory overview). GPU read-only pages cannot be written by shaders; write-combined ("garlic") pages are written by the CPU and read by it only uncached; coherent ("onion") pages are made for the CPU to read GPU results; cached non-coherent pages are read by the CPU only after the title's own GPU L2 write-back; and some pages carry no GPU bits. The protection of every range is now kept (shadow::title_memory_protection, fed by xmem's note_gpu_protection, forgotten in title_memory_freed), and VICTORY_UNIFIED_BACK=<classes> (names: unknown, gpu-ro, wc, coherent, noncoherent, cpu-only) copies shader writes back to title memory only for the classes named. Write-combined copies the existing size rule leaves on the card (VICTORY_WC_NO_BACK, _MIN_KB) stay there when wc is kept. Unset, nothing changes. VICTORY_UNIFIED_STATS=1 adds a line to the frame-rate log: shader writes per class, declared, copied back and left on the host side. Co-Authored-By: Claude Opus 5.5 <[email protected]>@Kassadd on GitHub · 2026-11-30 10:02 UTC · original · edited 2026-11-30 10:03 UTC
Measured under Wine, and it is the largest single win of the three optimisations I
tried together.
Environment: RTX 4080 SUPER 16 GB, i9-14900K, 62 GB, CachyOS, NVIDIA 620.73.04,
Proton Experimental
…-20261128(vkd3d-proton71cae0) viaumu-runwith its ownprefix, Series X
1.0.2.1,--res 1440withVICTORY_NATIVE_1440P=0(drawing andshowing at 4K;
1080to1440gives a doubled character). Builtmainat41adb551(the v2026.11.29.05 tree) with #2585, #3756 and this PR, which applied with no
conflict.
The scene matters when comparing with your figures. Yours are Windows, RTX 5090,
Series S, 4K with DLSS Performance, 31.3 ms in the opening and 23.7 ms in the later
scenes. Mine is the open world in play —
--res 1440withVICTORY_NATIVE_1440P=0, i.e. the full 4K scene with no upscaler, Series X, underWine — so my absolute numbers are not comparable and are not offered as such. What is
comparable is the split: how much of the frame goes to
copying backbefore and after.Before and after, same save, same place in the open world, single samples per
figure:
copying backcopiespreparingI cannot attribute all of that to this PR. The three went in together, so what I
can say is narrower: with
VICTORY_UNIFIED_BACK=1among them,copying backfell bytwo thirds and the GPU's share of the frame doubled — the card was idle waiting for
work that, per this PR's argument, the title never reads. That is exactly the
behaviour the doc describes, and it is the change that moved the figure most.
The thing a player notices is not the average but the variance, and that is where
the open world shows it: standing still the frame is about 20 fps, and before these
PRs turning the camera dropped it to 8 — nearly all of it in the copy-back and the
refresh sifting the turn makes. With the three it no longer collapses. On this machine
that is worth more than the mean, because in the world the camera is always moving.
Two notes from the run:
for
VICTORY_MAP_ONCEandVICTORY_COPY_BACK, whileVICTORY_UNIFIED_BACKwasaccepted. Either the doc's names and the code's had drifted apart at the commit I
built, or I misread it — worth a check, since someone following the doc would set a
switch that does nothing.
refreshesis still where the remaining time goes: 8,604 of 8,986 a frame areknown to copy nothing, i.e. the layer asks whether title memory changed and almostalways it has not. #3756 and #3762 make that cheaper to process, but nothing yet
asks less often. If this PR's split is the framework for memory classes, that seems
the next place to point it.
Logs and the exact invocation on request.
@ColorC on GitHub · 2026-11-30 11:53 UTC · original
Isolated Single-Variable A/B Cross-Validation on RTX 5070 Ti (
VICTORY_HW_RT=1, 1440p DLSS Quality + 3x MFG)Tested cleanly on top of our
bench-super-v19-cleanbaseline using a camera-locked 3-scene plan (Noon ~9–10.4k draws, Night ~5.5–6.2k draws, Misty Dawn ~11.7–12.5k draws; same save restored before each run; 0 crashes):Switches tested:
VICTORY_UNIFIED_BACK=wc,coherent,cpu-only,unknown,VICTORY_WC_PIECES=2,VICTORY_WC_NO_BACK_PC=1,VICTORY_WC_NO_BACK_MIN_BYTES=1024cardmeter)preparingms>100 msVisual & Stability Check
Noon,Night,Dawn) side-by-side against baseline: character skinning, face/cap shaders, volumetric fog, wet puddles, foliage, and night streetlamp lighting showed zero regressions or corruption, and 0 crashes across consecutive runs.-5.4 msto-9.7 ms, up to-27%) and huge true per-frame 1% Low (P99) gains (+2.4to+4.9 FPS) on RTX 5070 Ti + 9800X3D. Strong LGTM from this hardware configuration!@Marsietiss on GitHub · 2026-11-30 13:07 UTC · original
Tested a hand port of this on the Mangrove line (RTX 5080 + Ryzen 9 9950X3D, 256 lists in flight, frame generation off, walk-sampled route over three spots, live switch flipped in one launch). It is our own port of the measured set, so it may differ from your code in details.
So the speed is real here too (about -4 ms), but the picture breaks on our tree. Our reading: the set skips copy-back for memory the title reads back on the CPU after the GPU wrote it. Earlier we saw the title read inside a large write-combined pool, and its pieces stay on the card under the byte floor. As far as we can tell from the console's memory rules, only GPU-read-only memory can skip copy-back safely; write-combined and non-coherent memory are still CPU-readable after GPU writes. A variant that skips only GPU-read-only memory was picture-safe here but saved about 0 MB.
Possibly useful: a per-block "title read this after a GPU write" record (we feed ours from a read probe) to exclude those blocks. With it the saving would shrink, but the picture should hold. Happy to test a revision on the 5080.
@NebulaeTUT on GitHub · 2026-11-30 13:31 UTC · original
Test on RTX 3060 Laptop (6 GB): faster here, and by more than on the 5090
I ran the set on a laptop with a 6 GB card.
wcis the class that dominatesin this game, and the saving here is larger than on your 5090, so I am
posting the numbers in case they are useful.
Setup
D3D12Core.dllfrom System32VICTORY_THIN=0 VICTORY_JOIN_PARTS=1on both runs; the set under test added on topshaders+warm --usedbefore each session; neither log has(N being made)The set:
Result (median over frame-rate lines with
draws >= 1000)main,41adb55)The copy-back is what the PR targets and it drops by 42 %, from 23.9 to
13.9 ms. Preparing stays flat, as you found on the 5090. A second run of
the set gave the same copy-back (13.5 and 13.9 ms), so it is not one lucky
run.
wcreally is the class that mattersVICTORY_UNIFIED_STATS=1on this route:wcis 3.17 GB a frame, so takingwcout of the copy-back is what doesthe work. Your 1024-byte floor looks right: I did not try to lower it.
Two things worth reporting
The picture held up on the route I ran (indoor rooms, a street with
NPCs, a vehicle section): no stale faces, no seams, nothing visibly
different from the baseline run.
gpu-roandnoncoherentstayed outof the copy-back the whole time and I saw no fault. That is one route,
not a proof: I did not pass through a scene with reflections or a water
surface, which is where I would expect a stale
noncoherentread toshow.
One hard system freeze. With the set on, the machine locked up: no
BSOD, the crash log stayed empty and the play log simply stops mid-frame;
I had to power-cycle the PC. It did not happen again on the second run
with the same set, so I cannot pin it on this PR. Just before the
freeze the card was reported about 95 % busy, 134.7 ms of card time a
frame, with
wcat 3.17 GB a frame of declared writes. On a 6 GB cardthat could be the card or the driver running out of room rather than the
copy-back logic. I mention it because you asked for reports on cards
other than the 5090, and I would not call this quiet until someone has
run it longer than I have.
Representative frame lines
Baseline (
main), world:With the set, same route:
@Marsietiss on GitHub · 2026-11-30 13:38 UTC · original
Correction to my comment above: please do not count our broken picture against this PR yet. A closer look at our hand port points at a guard we added ourselves, which is not in your code: for copies with writes left we sent only the dwords the title changed, where your PR sends the written page whole (your comment explains why). With our guard a per-frame reset to the same value is never sent, and in our logs the largest indirect mesh dispatch group count climbs from about 300 to 20-30 thousand while the set is on, then falls back within seconds of switching it off. That matches the sparkle, and it is our bug, not yours. We are rebuilding with your whole-page behaviour and will post the result (picture and numbers at 32 and at 256 lists in flight) here.
@Marsietiss on GitHub · 2026-11-30 14:01 UTC · original
Retest done, and the result is the opposite of my first report: with your whole-page behaviour the set is clean here and a clear win. Our broken picture was our own added guard.
RTX 5080 + Ryzen 9 9950X3D, Series S profile, 1080p output with DLSS quality, frame generation off, one launch, live switches, same spot (close NPCs). This is our hand port of the measured set (wc, coherent, cpu-only, unknown; pieces 2; floor 1024).
Caveats: single spot, standing or walking, other processes were compiling during the run, so the ms values are indicative; a matched-draw route run follows. We still read the console's memory rules as allowing the title to read write-combined and non-coherent memory after GPU writes, so we will keep it opt-in on our line until more scenes are checked, but we have not found a scene that shows a problem. Stills of the broken control and the clean run are available; I will attach them when I can upload images. Thanks for this one.
@Marsietiss on GitHub · 2026-11-30 14:05 UTC · original
@Marsietiss on GitHub · 2026-11-30 17:48 UTC · original
Question for the author, from testing the hand port of this at
VICTORY_UNIFIED_BACK=1(default classes, 1024-byte floor) with 256 lists in flight on an RTX 5080.Seen by eye, not yet measured: in a close-up cutscene, some minutes in, a character's face mesh stretches towards one fixed point. Once it has started it stays for the session: switching
unified_backto 0 and the list cap back to 32 live does not heal it. A fresh launch at 32 lists with copy-back of everything shows no stretch in the same scene. The open world looked fine in the same sessions.Our reading (unverified): a write-combined piece above the floor holds skinning or morph output that the title's CPU reads back once and keeps, so it keeps the bytes from before the shader wrote.
VICTORY_UNIFIED_BACK_CLASSESwithoutwcskipping, or a higher floor, to be the safer default?We are running counters now that name the landing route and will post the numbers here.
@Marsietiss on GitHub · 2026-11-30 17:54 UTC · original
Update on my question above, after more runs tonight (all judged by eye in the same close-up scene, RTX 5080, same exe):
unified_back=1unified_back=1So the stretch has only shown on a cold first launch with 256 lists and
unified_back=1together; a warm launch with the same settings looked clean. I have not yet separated 256 fromunified_back=1on a cold launch, so this does not show your change alone is at fault.Counters on the warm run that looked fine: about 8 landed runs per frame (6.5 KB) over bytes a later frame's copies had already been given, nearly all through the resend route.
Our plan for now: start at 32 lists with full copy-back while the pipeline library is cold, and use 256 with
unified_back=1once it is warm. If you have seen cold-launch-only damage, or know why dropped draws would matter for what gets read back, that would help.@Marsietiss on GitHub · 2026-11-30 17:59 UTC · original
@x86 on GitHub · 2026-11-30 19:03 UTC · original
Sorry guys, it looks like my fix for the face bones was not enough. My bad.
@Marsietiss on GitHub · 2026-11-30 19:38 UTC · original
Follow-up to my table above, with one more run that closes this lead on our side. Note: drafted with Claude from my own runs; fork build (hand port of this change), RTX 5080.
New result: the face stretch also happens on a fully warm launch. Pipeline library loaded from disk, no pipelines being made,
VICTORY_UNIFIED_BACK=1with default classes, 256 lists in flight. In a close-up cutscene a spike of the face mesh pulls out from the brow and stays for the session. Switchingunified_backto 0 and the list cap to 32 live does not heal it, same as before. So my earlier reading, that it needs a cold launch with draws being dropped, was wrong. One earlier warm run looked fine for about three minutes; this one did not.What still holds: 32 lists with copy-back of everything, set from launch, has not stretched in any run so far (cold and warm, a few minutes each, by eye).
Where that leaves it for us: copy-back by memory class is off by default in our fork from now on. The declared class is evidently not a full statement of what the title reads back: at least one buffer the title reads (bone or vertex data for faces, by the look of it) sits in a class this leaves on the card, or is reached through an alias the class check does not see. Until someone can name that contract, I am treating "skip the copy-back by class" as a dead lead for correctness and am putting the time into not needing the copy at all (heaps opened in place).
If anyone has the stretch with this switch off, or has it never with it on across long sessions, that would be worth knowing. I can run a specific class mask on request.