Files
VIctory-NVIDIA/docs/unified-memory-classes.md
2026-11-30 21:17:36 +13:00

81 lines
4.5 KiB
Markdown

# Copy-back by memory class
On the console the CPU and the GPU share one memory. Here every title buffer has a host copy, and what
shaders write into a copy is compared after the submission and merged back into title memory, where
the title's CPU and other copies of the same bytes read it. These switches let the layer skip that for
memory the title will not read back. All are off unless set.
## The classes
The title declares how each processor reaches each range of its memory, in the protection it passes to
`XMemVirtualAlloc` and `VirtualProtect` (GDK, graphics memory overview). The layer now keeps that
protection per range (`shadow::title_memory_protection`, fed by `xmem`):
| Class | Protection | What the GDK says |
|---|---|---|
| `gpu-ro` | `PAGE_GRAPHICS_READONLY` / `EXECUTE` / `EXECUTE_READ` | shaders cannot write it |
| `wc` | `PAGE_WRITECOMBINE` with a GPU-writable bit ("garlic") | the CPU writes it; reads are uncached, which titles avoid |
| `coherent` | `PAGE_GRAPHICS_COHERENT` ("onion") | made for the CPU to read GPU results |
| `noncoherent` | CPU cached, GPU writable, not coherent (`0x2004`) | the CPU reads GPU writes only after the title's own GPU L2 write-back |
| `cpu-only` | no GPU bits | the GPU reaches it only through another mapping of the pages |
| `unknown` | no protection recorded | not the title's XMem memory |
In GTA VI: about 1.3 GB coherent, 3 GB write-combined, 4 GB non-coherent, and the 16 GB page pool
(`cpu-only` view with a GPU twin).
## Switches
| Switch | Effect |
|---|---|
| `VICTORY_UNIFIED_BACK=<classes>` | copy shader writes back only for the classes named (comma list of the names above). Unset or `all`: as before |
| `VICTORY_WC_NO_BACK_MIN_BYTES=<n>` | the write-combined floor (`VICTORY_WC_NO_BACK`) in bytes; takes precedence over `_MIN_KB` |
| `VICTORY_WC_PIECES=1` / `2` | with `UNIFIED_BACK`: the floor takes the write-combined pieces of copies that also cover other memory; `2` also copies outside the card's memory |
| `VICTORY_WC_NO_BACK_PC=1` | the floor also takes copies in the PC's memory |
| `VICTORY_UNIFIED_ALIAS=0` | turn off the shared-range rule below (on by default under `UNIFIED_BACK`) |
| `VICTORY_UNIFIED_ALIAS_MAX=<bytes>` | copies the shared-range rule looks at: smaller than this (1 MiB) |
| `VICTORY_UNIFIED_STATS=1` | a frame-rate log line with shader writes per class: declared, copied back, left on the host side, copied back as shared |
The set measured below:
```
VICTORY_UNIFIED_BACK=wc,coherent,cpu-only,unknown
VICTORY_WC_PIECES=2
VICTORY_WC_NO_BACK_PC=1
VICTORY_WC_NO_BACK_MIN_BYTES=1024
```
(with `VICTORY_WC_NO_BACK=1`, as the launchers set it).
## Why the floor and the shared-range rule
- **The time is in passes, not bytes.** After the existing 1 MiB write-combined rule, most of what is
left is compare passes over small write-combined copies (about 650 a frame in the opening), each a
pass of its own, about 15 µs of frame each. The byte floor leaves them on the card.
- **Exposure.** What the title reads back from write-combined memory lies in copies of 64 to 256 bytes:
a floor of 64 bytes overexposes the opening; 256 or 1024 keeps it right.
- **Data read through another copy.** Small write-combined buffers also hold data that a later pass
reads through another host copy of the same bytes, a window of 1 MiB or more, which is refreshed from
title memory. Left on the card, that data never reaches it: with the floor alone, the faces' skinning
data went stale and vertices of the characters' faces were pulled to one point beside the head. So a
piece the class rule would leave on the card is copied back when another copy holds any of it, for
copies under 1 MiB.
## Measurements
RTX 5090, Ryzen 9 9950X3D, Windows 10 with the Agility runtime, Series S profile, 4K output with DLSS
Performance, frame generation off; the opening (cutscene, then the scenes after it), 330 s runs
alternating with unswitched ones; median frame time over the frame-rate lines.
| | Opening | Later scenes |
|---|---|---|
| Unswitched (4 runs) | 31.3 ms | 23.7 ms |
| The set above (2 runs) | 28.9 ms | 22.4 ms |
About 8 % less frame time early and 5 % later. The picture was checked at full resolution against
unswitched runs over the whole opening.
Limits: one scene, one card, one profile; frame generation was not engaged in the runs. The classes
`gpu-ro` and `noncoherent` were left out of the copy-back 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.