GPU heaps in host memory: residency, CPU readback and wait-release data from a PS5 relinker #1640

Open
opened 2026-11-26 05:00:14 +00:00 by github-bot · 1 comment
Owner

@⁠Astronaut10 on GitHub · 2026-11-24 18:31 UTC · original

Data from AnyPS5 (PS5 titles on Linux/Vulkan; part of XCL's recompiler was ported from it), which uses the same memory model: the GPU reads title memory in place from host memory. Measured on Astro Bot, RX 9070 XT at PCIe 3.0 x16; PCIe 4/5 hosts pay less per byte.

1. Write-combined graphics memory is not only upload data. kernelx.rs puts the title's PAGE_GRAPHICS_* heaps in the coherent window, as upload heaps. On the console that memory also holds geometry the GPU reads every frame. In ours:

  • Host-memory traffic was 49 of 106 ms of GPU time in one scene, 24 of 68 in another.
  • VRAM copies of just the vertex and index ranges, checked against the write watch (239–271 MiB), cut draw GPU time 39.6 → 29.0 and 33.8 → 16.3 ms. Ranges rewritten every frame stayed in host memory, which cut uploads 9x.
  • Unpruned copies (+3.4 GiB) pushed textures out of VRAM and the frame rate collapsed to 0.1 fps.

Palmwave measured the same on the retail title (one pass 431 ms in host memory, 0.45 ms in VRAM). With 15–21 GB already in use on 16 GB cards, moving whole heaps to VRAM may not fit; a budgeted copy of the ranges the GPU reads often and the CPU rarely writes got most of the gain for us.

2. CPU reads of GPU writes in the sparse windows. The CPU's view is not updated there. A first-touch census (protect the pages the GPU wrote, count the CPU's first touch) found ~96 % of the GPU's stores into title memory overwritten before any CPU read. The same mechanism becomes copy-back on first touch: exact at little cost, and it shows which memory needs the coherent window.

3. Waits whose producer is not submitted yet (#1452). Our frame replay tool hit the same class. Every one turned out to be signalled by GPU work submitted later. Releasing them on a timer let them go 0–2 frames before their producer, and only 73–76 % of output pixels matched; releasing only when nothing else could run needed no releases at all and raised that to 92 %. A timer release can also explain wrong images.

AI-assisted (Claude Code); numbers from our own runs, no XCL or the retail title data.

**@⁠Astronaut10** on GitHub · 2026-11-24 18:31 UTC · [original](https://github.com/xcl-dev/xcl/issues/1640) Data from AnyPS5 (PS5 titles on Linux/Vulkan; part of XCL's recompiler was ported from it), which uses the same memory model: the GPU reads title memory in place from host memory. Measured on Astro Bot, RX 9070 XT at PCIe 3.0 x16; PCIe 4/5 hosts pay less per byte. **1. Write-combined graphics memory is not only upload data.** `kernelx.rs` puts the title's `PAGE_GRAPHICS_*` heaps in the coherent window, as upload heaps. On the console that memory also holds geometry the GPU reads every frame. In ours: - Host-memory traffic was 49 of 106 ms of GPU time in one scene, 24 of 68 in another. - VRAM copies of just the vertex and index ranges, checked against the write watch (239–271 MiB), cut draw GPU time 39.6 → 29.0 and 33.8 → 16.3 ms. Ranges rewritten every frame stayed in host memory, which cut uploads 9x. - Unpruned copies (+3.4 GiB) pushed textures out of VRAM and the frame rate collapsed to 0.1 fps. Palmwave measured the same on the retail title (one pass 431 ms in host memory, 0.45 ms in VRAM). With 15–21 GB already in use on 16 GB cards, moving whole heaps to VRAM may not fit; a budgeted copy of the ranges the GPU reads often and the CPU rarely writes got most of the gain for us. **2. CPU reads of GPU writes in the sparse windows.** The CPU's view is not updated there. A first-touch census (protect the pages the GPU wrote, count the CPU's first touch) found ~96 % of the GPU's stores into title memory overwritten before any CPU read. The same mechanism becomes copy-back on first touch: exact at little cost, and it shows which memory needs the coherent window. **3. Waits whose producer is not submitted yet (#1452).** Our frame replay tool hit the same class. Every one turned out to be signalled by GPU work submitted later. Releasing them on a timer let them go 0–2 frames before their producer, and only 73–76 % of output pixels matched; releasing only when nothing else could run needed no releases at all and raised that to 92 %. A timer release can also explain wrong images. AI-assisted (Claude Code); numbers from our own runs, no XCL or the retail title data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:00:14 +00:00
Author
Owner

@⁠CharlyRien on GitHub · 2026-11-24 22:36 UTC · original · edited 2026-11-24 22:37 UTC

A data point on what makes the host-memory heap expensive for compute, from offline benchmarks and a retail title on an RTX 3090 (driver 616.56, Windows 11): for loads, the multiplier is the globallycoherent qualifier on a view of the imported heap, much more than host memory by itself.

Micro-benchmark (one buffer, 1 024 dependent loads per thread, GPU timestamps; ns per load per wave)

memory behind the view view ns
video memory heap view, globallycoherent 177
video memory heap view, plain 72
host memory imported with OpenExistingHeapFromAddress heap view, globallycoherent, same address 5 875
same same, 64 independent groups 374 ms in total: the loads are serialized GPU-wide
same heap view, plain, same address 73
same heap view, plain, stride 64 B 1 175 (one bus read per new line, then cached)
same SRV 76

One captured world-load dispatch of the title, replayed offline with its real inputs (32x32x2 groups of 4x4x4, loops reading a constant buffer in the committed window): 7 369 ms as the runtime does it, 9.95 ms with the same views not globallycoherent (byte-identical output), 12.7 ms with the windows in video memory.

So for data the dispatch only reads, dropping the qualifier (#1850) gets what a copy in video memory gets, without the copy. A copy still pays where the qualifier has to stay: with #1850's rule the programs that use an atomic keep it and carry about 5 s of GPU time per world frame here; with the committed window copied to video memory (#1329 forced on Windows) the same frame is about 0.35 s. Details in #1850.

About point 1 above: the 431 ms against 0.45 ms pass has the same shape as ours. It may be worth checking whether its views were globallycoherent (before #1850 every compute memory window is), because then most of that cost is the qualifier and not the bus.

About point 3 (timer releases): on the copy path we see about twenty GPU queue.Wait … did not complete within 5000 ms releases per world frame, every queue waiting on the others, and the 3D scene comes out flat grey. Whether the two are linked is not established yet; that is what I am looking at now.

Setup (edited in)

  • Tree for the title figures: main 9e3831e merged locally with #1288, #1448, #684, #889, #1323, #929 and #640, plus local diagnostics (GPU timestamp queries around each operation, a device-removal watcher); the 5 s figure adds the HLSL-path part of #1850, the 0.35 s figure adds #1326, #1327 and #1329 with XCL_UMA_SHADOW=1.
  • The micro-benchmark and the replay are a local test harness on the same tree: it builds the windows as the runtime does (VirtualAlloc, OpenExistingHeapFromAddress, placed buffers, views taken from the descriptor heap with XCL_HEAP_WINDOWS=1) and times dispatches with timestamp queries, median of 3.
  • Run: release, XCL_HEAP_WINDOWS=1 XCL_NETWORK=0 XCL_ACTIVITY=1, warm DXIL and driver caches, scripted A presses, 230 – 300 s per run, no XCL_PSO_WAIT_MS unless a row says so.
  • Local switches, not for upstream: compute programs of 4 MB of DXIL or more are not handed to the driver (three of them; no draw or dispatch was skipped in the runs without XCL_PSO_WAIT_MS); the title's own stall watchdog is neutralised so that long stalls can be observed.
  • Windows: TdrDelay and TdrDdiDelay set to 30 s. With the default 2 s the driver resets the device during the multi-second dispatches (System event 4101) and nothing can be timed.
  • RTX 3090 24 GB (driver 616.56, 32-lane waves so the split wave64 form), Ryzen 9 5950X, 32 GB RAM + 32 GB page file, Windows 11 22631, DXC 1.9.2602.17.

Not tested: AMD or Intel GPUs, other drivers, stores and atomics through each kind of view (being measured).

AI use: Claude Code (Claude Fable 5.2) wrote the harness, ran the measurements and drafted this.

**@⁠CharlyRien** on GitHub · 2026-11-24 22:36 UTC · [original](https://github.com/xcl-dev/xcl/issues/1640#issuecomment-7146425626) · edited 2026-11-24 22:37 UTC A data point on what makes the host-memory heap expensive for compute, from offline benchmarks and a retail title on an RTX 3090 (driver 616.56, Windows 11): for loads, the multiplier is the `globallycoherent` qualifier on a view of the imported heap, much more than host memory by itself. **Micro-benchmark** (one buffer, 1 024 dependent loads per thread, GPU timestamps; ns per load per wave) | memory behind the view | view | ns | |---|---|---| | video memory | heap view, `globallycoherent` | 177 | | video memory | heap view, plain | 72 | | host memory imported with `OpenExistingHeapFromAddress` | heap view, `globallycoherent`, same address | **5 875** | | same | same, 64 independent groups | 374 ms in total: the loads are serialized GPU-wide | | same | heap view, plain, same address | 73 | | same | heap view, plain, stride 64 B | 1 175 (one bus read per new line, then cached) | | same | SRV | 76 | **One captured world-load dispatch of the title, replayed offline with its real inputs** (32x32x2 groups of 4x4x4, loops reading a constant buffer in the committed window): 7 369 ms as the runtime does it, 9.95 ms with the same views not `globallycoherent` (byte-identical output), 12.7 ms with the windows in video memory. So for data the dispatch only reads, dropping the qualifier (#1850) gets what a copy in video memory gets, without the copy. A copy still pays where the qualifier has to stay: with #1850's rule the programs that use an atomic keep it and carry about 5 s of GPU time per world frame here; with the committed window copied to video memory (#1329 forced on Windows) the same frame is about 0.35 s. Details in https://git.gtahub.st/github/xcl-dev--xcl/pulls/1850. About point 1 above: the 431 ms against 0.45 ms pass has the same shape as ours. It may be worth checking whether its views were `globallycoherent` (before #1850 every compute memory window is), because then most of that cost is the qualifier and not the bus. About point 3 (timer releases): on the copy path we see about twenty `GPU queue.Wait … did not complete within 5000 ms` releases per world frame, every queue waiting on the others, and the 3D scene comes out flat grey. Whether the two are linked is not established yet; that is what I am looking at now. **Setup** (edited in) - Tree for the title figures: `main` `9e3831e` merged locally with #1288, #1448, #684, #889, #1323, #929 and #640, plus local diagnostics (GPU timestamp queries around each operation, a device-removal watcher); the 5 s figure adds the HLSL-path part of #1850, the 0.35 s figure adds #1326, #1327 and #1329 with `XCL_UMA_SHADOW=1`. - The micro-benchmark and the replay are a local test harness on the same tree: it builds the windows as the runtime does (`VirtualAlloc`, `OpenExistingHeapFromAddress`, placed buffers, views taken from the descriptor heap with `XCL_HEAP_WINDOWS=1`) and times dispatches with timestamp queries, median of 3. - Run: release, `XCL_HEAP_WINDOWS=1 XCL_NETWORK=0 XCL_ACTIVITY=1`, warm DXIL and driver caches, scripted A presses, 230 – 300 s per run, no `XCL_PSO_WAIT_MS` unless a row says so. - Local switches, not for upstream: compute programs of 4 MB of DXIL or more are not handed to the driver (three of them; no draw or dispatch was skipped in the runs without `XCL_PSO_WAIT_MS`); the title's own stall watchdog is neutralised so that long stalls can be observed. - Windows: `TdrDelay` and `TdrDdiDelay` set to 30 s. With the default 2 s the driver resets the device during the multi-second dispatches (System event 4101) and nothing can be timed. - RTX 3090 24 GB (driver 616.56, 32-lane waves so the split wave64 form), Ryzen 9 5950X, 32 GB RAM + 32 GB page file, Windows 11 22631, DXC 1.9.2602.17. **Not tested**: AMD or Intel GPUs, other drivers, stores and atomics through each kind of view (being measured). **AI use**: Claude Code (Claude Fable 5.2) wrote the harness, ran the measurements and drafted this.
This discussion has been locked. Commenting is limited to contributors.
No description provided.