Proposal (Linux): unify title memory by placing it in VRAM at the title's own addresses #95

Open
opened 2026-11-26 03:32:06 +00:00 by github-bot · 1 comment
Owner

@⁠Fran-co-F on GitHub · 2026-11-26 03:20 UTC · original

Your docs/findings.md puts it well: every large cost is noticing, moving and waiting, because CPU and GPU no longer share memory. On Linux the two can share it again, and I think the layer could drop most of that work there.

Idea. The in-place mode (OpenExistingHeapFromAddress1 on title memory, as in upstream #2112 / DexNom VICTORY_INPLACE) skips copies, refreshes and copy-back for what it covers. Today vkd3d-proton backs that call with host memory (VK_EXT_external_memory_host), so shaders read it over PCIe. Under Wine, vkd3d-proton can instead allocate DEVICE_LOCAL | HOST_VISIBLE memory (ReBAR), copy the bytes in, and map it at the same virtual address with VK_EXT_map_memory_placed. The title keeps its pointers, shaders read VRAM, and there is nothing to notice or move. Windows has no equivalent: D3D12 can't choose where a heap's CPU mapping lives.

What I measured (RX 9070 XT, RADV / Mesa 26.3.1, Wine 11.17, vkd3d-proton master, kernel 7.3):

  • This fork runs on Linux at about the same speed as your Windows numbers: 50–56 ms a frame (18–20 fps) in the prologue street scene with your play.ps1 settings. That needs a wineserver with mapped views in a tree (CachyOS/wine-cachyos#50). Stock Wine spends seconds per frame there. In the log, "preparing" is the wall at 43–55 ms, as in your findings.
  • Prototype on DexNom (patched Wine win32u/ntdll + vkd3d-proton): about 3,400 in-place heaps / 861 MiB mapped in VRAM at the title's addresses in the real game. GPU time went back to the copy-based level (110–130 ms in that scene), against 700–1,000 ms with in place over PCIe.
  • The kernel side of the page pool works: one VRAM allocation exported as dma-buf can be mmapped with MAP_FIXED at chosen addresses, with non-zero offsets, the same 64 KiB at several addresses, and the aliases stay coherent. Unmapping one view leaves the others intact. Tested natively; under Wine still to do.
  • Hard constraint: the CPU reads VRAM through the BAR at about 10 MB/s (RAM: 38 GB/s; writes: 11.7 GB/s). Anything the CPU reads must stay in RAM, or the gain turns into a loss.

What blocked a clear win so far:

  1. Windows and title buffers overlap ("4848 MB of windows lie over 3436 MB of title memory"). Mapping per request leaves partial overlaps that can't share one VRAM block. Those fall back to CPU copies that now read VRAM, which is worse than before. The fix is to place whole 32 MiB-aligned blocks of each private arena, so every window and buffer inside reuses the same block.
  2. Most of the per-frame copy volume is view memory (the page pool), which in-place turns down today. It needs one VRAM block per section with views mapped at their offsets (shown possible above). The layer's own CPU paths (copies, hashes, compares, write watch) must skip ranges that live in VRAM.

Expected effect here. From your boat-scene breakdown (55 ms frame: preparing thread 48 ms, of which about 30 ms is refreshes, card steps, write-watch queries, card copies and title bytes under shader writes; card about 41 ms including hash passes): removing the sync work should make the frame GPU-bound. That is about 41 ms right away, and roughly 30–35 ms once the card no longer hashes copies. These are estimates, not measurements.

Limits. Linux only, AMD with ReBAR. NVIDIA needs VK_EXT_map_memory_placed in its driver, which I haven't checked. It needs small patches in Wine and vkd3d-proton (opt-in through environment variables) and changes in the layer's view handling.

I'm continuing on the 32 MiB blocks and then the page pool. I can share the Wine and vkd3d-proton patches and the test programs if anyone wants to try this in parallel. Feedback on whether this layer's view and guard machinery could skip VRAM-backed ranges would help a lot.

**@⁠Fran-co-F** on GitHub · 2026-11-26 03:20 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/95) Your `docs/findings.md` puts it well: every large cost is noticing, moving and waiting, because CPU and GPU no longer share memory. On Linux the two can share it again, and I think the layer could drop most of that work there. **Idea.** The in-place mode (`OpenExistingHeapFromAddress1` on title memory, as in upstream #2112 / DexNom `VICTORY_INPLACE`) skips copies, refreshes and copy-back for what it covers. Today vkd3d-proton backs that call with host memory (`VK_EXT_external_memory_host`), so shaders read it over PCIe. Under Wine, vkd3d-proton can instead allocate `DEVICE_LOCAL | HOST_VISIBLE` memory (ReBAR), copy the bytes in, and map it **at the same virtual address** with `VK_EXT_map_memory_placed`. The title keeps its pointers, shaders read VRAM, and there is nothing to notice or move. Windows has no equivalent: D3D12 can't choose where a heap's CPU mapping lives. **What I measured (RX 9070 XT, RADV / Mesa 26.3.1, Wine 11.17, vkd3d-proton master, kernel 7.3):** - **This fork runs on Linux at about the same speed as your Windows numbers:** 50–56 ms a frame (18–20 fps) in the prologue street scene with your `play.ps1` settings. That needs a `wineserver` with mapped views in a tree ([CachyOS/wine-cachyos#50](https://github.com/CachyOS/wine-cachyos/pull/50)). Stock Wine spends seconds per frame there. In the log, "preparing" is the wall at 43–55 ms, as in your findings. - **Prototype on DexNom** (patched Wine `win32u`/`ntdll` + vkd3d-proton): about 3,400 in-place heaps / 861 MiB mapped in VRAM at the title's addresses in the real game. GPU time went back to the copy-based level (110–130 ms in that scene), against 700–1,000 ms with in place over PCIe. - **The kernel side of the page pool works:** one VRAM allocation exported as dma-buf can be `mmap`ped with `MAP_FIXED` at chosen addresses, **with non-zero offsets, the same 64 KiB at several addresses**, and the aliases stay coherent. Unmapping one view leaves the others intact. Tested natively; under Wine still to do. - **Hard constraint:** the CPU *reads* VRAM through the BAR at about **10 MB/s** (RAM: 38 GB/s; writes: 11.7 GB/s). Anything the CPU reads must stay in RAM, or the gain turns into a loss. **What blocked a clear win so far:** 1. Windows and title buffers overlap ("4848 MB of windows lie over 3436 MB of title memory"). Mapping per request leaves partial overlaps that can't share one VRAM block. Those fall back to CPU copies that now *read VRAM*, which is worse than before. The fix is to place whole 32 MiB-aligned blocks of each private arena, so every window and buffer inside reuses the same block. 2. Most of the per-frame copy volume is **view memory** (the page pool), which in-place turns down today. It needs one VRAM block per section with views mapped at their offsets (shown possible above). The layer's own CPU paths (copies, hashes, compares, write watch) must skip ranges that live in VRAM. **Expected effect here.** From your boat-scene breakdown (55 ms frame: preparing thread 48 ms, of which about 30 ms is refreshes, card steps, write-watch queries, card copies and title bytes under shader writes; card about 41 ms including hash passes): removing the sync work should make the frame GPU-bound. That is about 41 ms right away, and roughly 30–35 ms once the card no longer hashes copies. These are estimates, not measurements. **Limits.** Linux only, AMD with ReBAR. NVIDIA needs `VK_EXT_map_memory_placed` in its driver, which I haven't checked. It needs small patches in Wine and vkd3d-proton (opt-in through environment variables) and changes in the layer's view handling. I'm continuing on the 32 MiB blocks and then the page pool. I can share the Wine and vkd3d-proton patches and the test programs if anyone wants to try this in parallel. Feedback on whether this layer's view and guard machinery could skip VRAM-backed ranges would help a lot.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:32:06 +00:00
Author
Owner

@⁠Fran-co-F on GitHub · 2026-11-26 13:30 UTC · original

First measured gain on this fork: 51–55 ms → 45–46 ms, with only private write-combined memory in VRAM plus VICTORY_PORT_CBV=1 (RX 9070 XT, Linux)

Setup: a9400a6 + #166, local patches for the in-place filter, Wine 11.17 (patched win32u/ntdll, view-tree wineserver), vkd3d-proton ec20719 (patched to place in-place heaps in VRAM in 32 MiB blocks), RADV 26.3.1, Series X profile, VICTORY_RELAY=2, VICTORY_PORT_CONSTANTS off. VICTORY_INPLACE=2. Same save and scene, 160 s runs, medians over about 110 s of world frames. The control uses the same Wine, prefix and binary with in place off.

frame copies copying back
control (1 run) 51 ms 26 ms 27 ms
control + PORT_CBV (2 runs) 53, 58 ms 28, 29 ms 26, 26 ms
VRAM, no PORT_CBV (1 run) 62 ms (worse) 50 ms 10 ms
VRAM + PORT_CBV (2 runs) 45, 46 ms 21, 21 ms 12, 13 ms

What it took, in order:

  1. Do not move everything. Placing cacheable title memory in VRAM made frames much slower and the run ended in the title's watchdog (that was on DexNom). The filter now takes only allocations the title declares write-combined / non-cacheable (about 1 GiB); the cacheable ones stay on the copy path.
  2. The layer's own CPU reads matter too. With only VRAM on, "copies and fills" on the submitting thread went from 4.5 to 26 ms and the card-step fills fell from ~4,200 to 3 a frame. My reading is that those fills moved to the CPU and read VRAM; I did not measure that directly.
  3. VICTORY_PORT_CBV=1 removes that cost here: about 1,000 tables' constant buffers a frame (1.9 MB) are read by the card in place, and "copies and fills" is back to 2.5–2.9 ms.

Limits: one machine, one scene, one or two runs per row, picture checked only by eye (one of the two VRAM runs looked slightly worse while loading; the counters of dropped draws did not differ). View memory (the page pool) is not covered; it is still copied.

AI-assisted (Claude Code and Gemini).

**@⁠Fran-co-F** on GitHub · 2026-11-26 13:30 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/95#issuecomment-7193457552) **First measured gain on this fork: 51–55 ms → 45–46 ms, with only private write-combined memory in VRAM plus `VICTORY_PORT_CBV=1` (RX 9070 XT, Linux)** Setup: `a9400a6` + #166, local patches for the in-place filter, Wine 11.17 (patched `win32u`/`ntdll`, view-tree wineserver), vkd3d-proton `ec20719` (patched to place in-place heaps in VRAM in 32 MiB blocks), RADV 26.3.1, Series X profile, `VICTORY_RELAY=2`, `VICTORY_PORT_CONSTANTS` off. `VICTORY_INPLACE=2`. Same save and scene, 160 s runs, medians over about 110 s of world frames. The control uses the same Wine, prefix and binary with in place off. | | frame | copies | copying back | |---|---|---|---| | control (1 run) | 51 ms | 26 ms | 27 ms | | control + `PORT_CBV` (2 runs) | 53, 58 ms | 28, 29 ms | 26, 26 ms | | VRAM, no `PORT_CBV` (1 run) | **62 ms (worse)** | 50 ms | 10 ms | | VRAM + `PORT_CBV` (2 runs) | **45, 46 ms** | 21, 21 ms | 12, 13 ms | What it took, in order: 1. **Do not move everything.** Placing cacheable title memory in VRAM made frames much slower and the run ended in the title's watchdog (that was on DexNom). The filter now takes only allocations the title declares write-combined / non-cacheable (about 1 GiB); the cacheable ones stay on the copy path. 2. **The layer's own CPU reads matter too.** With only VRAM on, "copies and fills" on the submitting thread went from 4.5 to 26 ms and the card-step fills fell from ~4,200 to 3 a frame. My reading is that those fills moved to the CPU and read VRAM; I did not measure that directly. 3. **`VICTORY_PORT_CBV=1` removes that cost here:** about 1,000 tables' constant buffers a frame (1.9 MB) are read by the card in place, and "copies and fills" is back to 2.5–2.9 ms. Limits: one machine, one scene, one or two runs per row, picture checked only by eye (one of the two VRAM runs looked slightly worse while loading; the counters of dropped draws did not differ). View memory (the page pool) is not covered; it is still copied. AI-assisted (Claude Code and Gemini).
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/avatarmanz--VIctory-7900XTX#95
No description provided.