GPU: the Xbox's shared CPU/GPU memory on PC GPUs: simulated in video memory on discrete cards, title memory itself on unified ones #3100

Open
0xkn0wh3r3 wants to merge 24 commits from upstream-pr/3102 into main
0xkn0wh3r3 commented 2026-11-26 08:03:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T08:03:08Z.


Goal: give titles the Xbox Series' shared memory model on a PC whose GPU has its own video memory.

On the console, the CPU and GPU share one pool of memory. A title builds vertex data, constants and command data at an address, hands the GPU that address, and reads back what shaders wrote at that same address, with nothing copied. Titles are written around that.

A PC with a discrete GPU has two pools: system memory next to the CPU, and video memory on the card, joined by PCI Express. Each processor is fast in its own pool and slow in the other: on an RTX 5070 Ti, the GPU reads system memory at ~23 GB/s and video memory at ~720 GB/s.

This PR simulates the console's single pool on such a GPU:

  • Title memory stays the one source of truth, at the title's own addresses.
  • The host GPU works on an image of it in video memory, kept coherent in both directions at every submission.
  • The title still sees one memory, and its shaders read at video-memory speed.

Where the host really has one pool (an APU or integrated GPU), no simulation is needed: the GPU uses title memory itself, exactly as on the console.

Everything here is my own work: new code, plus my open PRs, which this replaces (#2120, #2130, #2222, #2870, #2912, #2921, #2929, #2945). It depends on no one else's PR.

How the shared pool is simulated

What the console guarantees Discrete GPU (video memory) Unified host (APU, integrated GPU)
The GPU reads what the CPU just wrote, at the same address Pages the title wrote since the last submission (write watch, guards) are copied into the video-memory image before the submission, straight through the BAR into GPU upload heaps Same memory: nothing to copy
The CPU reads what the GPU just wrote, at the same address Pages shaders wrote (write marks, or snapshots of declared ranges) go back into title memory after the submission, through a system-memory mirror that catches up only where the CPU reads Same memory: nothing to copy back
The GPU reads its data at memory speed The image is in video memory: the benchmark's GPU time drops from 44 ms to 11 (2 with snapshots) Already at memory speed
One copy of the data Two: title memory and its image in video memory, sized under the DXGI video memory budget One: title memory itself (opened as a GPU heap)
The title frees, protects and remaps its memory at will Unchanged Buffers held in place are let go first (pins), then the change goes through

Why simulate instead of sharing literally on a discrete GPU? The GPU can read title memory itself across the bus (VICTORY_IN_PLACE=1). Measured, that takes 43.7 ms per submission, against 29.7–36.7 ms for the simulated pool in video memory: shaders reading across PCI Express cost more than keeping the image coherent. So literal sharing is only the default where the pool really is shared.

What each host gets by default

No environment variable is needed. The switches only override.

Host Default
Discrete GPU reporting GPU upload heaps (Resizable BAR on, with driver and D3D12 runtime support), NVIDIA Copies of all title buffers, and of title memory outside buffers, in video memory
Same, AMD or Intel Copies of read-only buffers in video memory. Copies of buffers shaders write, and of title memory outside buffers, stay in system memory: on an RX 9070 XT and an RX 7900 XTX their mirrors cost more than they saved
Discrete GPU without GPU upload heaps (Resizable BAR off, older runtime) Unchanged from main: copies in system memory
GPU sharing memory with the CPU (APU, integrated GPU), self-test passes No copies: title memory in place
Same, self-test fails (e.g. a translation layer that gives the GPU new memory) Copies, with a log line saying why
Mac through D3DMetal Copies: it reports a discrete GPU (UMA=false) and opens no heaps from title memory

The startup log names the outcome: host GPU memory: ..., plus a line when in place turns on or is refused.

Overrides:

  • VICTORY_GPU_UPLOAD=0: every copy in system memory.
  • VICTORY_GPU_UPLOAD_WRITES=0|1: written buffers' copies in system memory, or in video memory on any GPU.
  • VICTORY_IN_PLACE=0|1: in place off, or on wherever the GPU can open title memory as a heap.

The diagnostics ranking (from #2929) needs a --features diagnostics build plus VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1.

Results

Synthetic: shadow::bench::compute_heavy_submissions_by_copy_placement runs one submission of 200 compute dispatches in 8 lists over 320 MiB of title buffers, through the real copy paths (shadow::find, Shadow::refresh, Shadow::gpu_writes, HostList, Host::execute). Each placement runs in its own process, and the test checks that title memory ends up byte-identical in all of them. Ryzen 9 7900X, Windows 11. Each number is the median of three runs, each the median of 5 submissions, ms per submission.

host writes found by title writes main (copies in system memory) this PR, default
RTX 5070 Ti write marks none 58.1 29.0 (copies in video memory) −50%
RTX 5070 Ti write marks 16 MiB per submission 60.3 32.6 −46%
RTX 5070 Ti snapshots none 71.8 37.1 −48%
RTX 5070 Ti snapshots 16 MiB per submission 74.1 39.2 −47%
integrated Radeon (7900X) write marks none 58.9 40.6 (title memory in place) −31%
integrated Radeon write marks 16 MiB per submission 59.8 41.1 −31%
integrated Radeon snapshots none 70.1 40.5 −42%
integrated Radeon snapshots 16 MiB per submission 71.1 40.9 −42%
  • 5070 Ti: the GPU's time drops from 44 ms to 11 with write marks, and to 2 with snapshots. Copy-back grows by 4-5 ms, from bringing written pages back to their mirrors. With snapshots, preparing grows by about 2 ms: the declared ranges come back to the mirrors whole before the snapshots (see the review fixes below).
  • Integrated Radeon: refreshes (up to 14 ms), snapshots and copy-backs (15-17 ms) disappear, and no copies are made (320 MiB of memory saved). Opening the heaps costs 127 ms once, against 25-30 ms to allocate copies. The first submission then takes 40 ms instead of 111-134, so the first use costs about the same either way, and every later submission is 18-30 ms shorter. Video-memory placements buy nothing there: it is the same memory.
  • Title memory outside any buffer (the same benchmark with VICTORY_TEST_BENCH_LOOSE=1, 5070 Ti): 30.6-44.4 ms with its 4 MiB windows' copies in video memory, against 66.3-103.1 ms in system memory (−54 to −57%). The GPU's time falls from about 50 ms to 10 (2 with snapshots).
  • 5070 Ti with VICTORY_IN_PLACE=1: 43.6-43.8 ms. That beats copies in system memory but loses to copies in video memory, so in place stays off on discrete GPUs.
  • In a title on an RX 7900 XTX (zed6000's run, intro cutscene, medians of 36 frame lines): no gain. The base takes 415 ms a frame and this PR's default 431 ms. With VICTORY_GPU_UPLOAD_WRITES=1 the GPU's time falls from 151 to 138 ms, but copying back grows from 58 to 78 ms, for 438 ms. No dropped draws, new warnings or device removals. That is the second AMD card where written copies in video memory don't pay, so they stay NVIDIA-only.

docs/gpu-memory.md has the full tables, every placement on both GPUs.

What changes

Detecting the host (from #2912)

  • crate::unified::detect runs at host creation: ARCHITECTURE1.UMA / CacheCoherentUMA, GPUUploadHeapSupported and the DXGI budgets. It costs about 0.3 ms and logs one line (host GPU memory: ...), which also goes into the GPU failure text.

Copies in video memory on discrete GPUs (from #2120, #2130, #2222, #2870)

  • Copies of read-only title buffers go in GPU upload heaps.
  • Copies of written buffers go in video memory with a system-memory mirror that catches up lazily.
  • Copies of title memory outside any buffer (its 4 MiB windows) are placed as written buffers' copies: shaders may write any of it.
  • Upload-heap copies take a share of the VRAM budget, and render targets are demoted last.
  • On by default where the host has GPU upload heaps. Written copies only on NVIDIA: on an RX 9070 XT and an RX 7900 XTX the mirrors cost more than they saved. VICTORY_GPU_UPLOAD=0 and VICTORY_GPU_UPLOAD_WRITES=0|1 override.

Title memory in place on unified hosts (new, crate::in_place)

  • Each title buffer of at least 64 KiB becomes a heap over its own pages (OpenExistingHeapFromAddress1), with one buffer placed at its start.
  • Shadow gains an in-place kind whose data is title memory itself. Refresh, snapshot and copy-back do nothing for it.
  • On by default where the host reports UMA and title memory passes unified::self_test. The self-test runs once, only on unified hosts: it has the GPU copy into and out of memory allocated like the title's pools, and checks that both sides see the other's writes. That guards against layers that have the API but hand the GPU new memory, such as vkd3d-proton without VK_EXT_external_memory_host.
  • VICTORY_IN_PLACE=1 turns it on wherever heaps open; =0 turns it off.

Freeing memory held in place (from #2921, now with its caller)

  • While a heap lives, Windows refuses VirtualFree, VirtualProtect and UnmapViewOfFile* with error 87.
  • The HLE wraps those calls, and xmem's own unmapping, in title_memory_change. That releases the buffers held over the range first, then retries for up to 100 ms while lists still holding them are reset.
  • Each placed buffer holds its heap through private data, so the heap's registration lasts as long as anything is placed in it. vkd3d-proton destroyed heaps early; pickles976 reported it on #2945.

Withholding still works with in place

  • What programs using title memory write is withheld from title memory when they miss (memory::withholding). A buffer in place cannot withhold anything, so:
    • Declared write to a buffer in place: the buffer gets a copy from its next use on. That submission saves the range beforehand and puts it back if the writes are withheld.
    • Page table made: buffers shaders may write move to copies before the table names them. Only buffers made without unordered access stay in place.
  • Other copies of pages held in place can't guard them, so they're refreshed at each use and always see what the GPU wrote.

Mirrors stay consistent (review fixes, from r4tedx's findings on this PR)

  • A failed GPU copy back loses nothing. Host::copy_now reports whether it saw its fence reached on a live device, and doesn't reuse its allocator until it has. When it didn't (no copier, a failed call, a removed device), bring_back reads the pages through the CPU's mapping of video memory. That's slow, but the mirror still gets the shaders' writes. Written copies made after that stay in system memory. Before this, the stale bits were cleared anyway, and the copy-back pushed the mirror's old bytes into title memory and video memory.
  • Snapshots bring back their declared ranges whole, not only the pages refreshes left stale. A byte an earlier shader wrote through an undeclared view is in video memory with no stale bit. A snapshot without it took it for this submission's write and put it over the title's byte.
  • VICTORY_COPIES_IN_VIDEO_MEMORY (diagnostics) now places copies as the video-memory placements do: written ones with their mirrors, within the upload budget. Mirrors, the marks bitmap and other shared buffers stay in system memory.
  • These apply to buffers' copies and to loose windows alike.

Diagnostics (from #2929)

  • The frame-rate line ranks host copies by the GPU time they're bound to and what video memory would save (VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1). Buffers in place aren't ranked.

Limits

  • My measurements are synthetic. The only run in a title so far is zed6000's on an RX 7900 XTX (no gain, above). None has run on NVIDIA or on a unified host.
  • A title write that lands while its page is being copied back, after the copy-back read it, can miss the copy until the title writes the page again. Main has the same window (r4tedx's finding 4); it isn't fixed here.
  • A title that reads memory at computed addresses (page tables) keeps in place only for buffers made without unordered access, starting with its first such submission. If a page-table program writes one of those, the write reaches title memory and is not withheld.
  • While a heap still lives (a list or descriptor slot holds its buffer), a copy over the same pages is refreshed at every use. Results withheld into that copy are therefore dropped at the next submission rather than at the end of the frame.
  • In place is untested on vkd3d-proton and D3DMetal. The self-test decides the default there.
  • The written-pages bitmap stays in system memory (#2175 / #2465 by wbkepler move it). With copies in video memory, marking takes about 9 of the 11 GPU ms in the benchmark.
  • Copies of single views off their buffer's elements (shadow::exact, ~2 KB each, in shared buffers) stay in system memory.
  • Window copies are never freed, so memory allocated again at the same address reuses its window's copy. That copy is current only where the runtime reported the remap (as on main). The benchmark caught this when it reused addresses between modes.

Tests

  • New:
    • shadow::tests::a_title_buffer_in_place_needs_no_copies
    • the_title_frees_memory_a_buffer_is_in_place_over
    • a_buffer_in_place_holds_its_heap_and_pin
    • page_tables_move_written_buffers_to_copies
    • host::withholding::a_program_using_title_memory_moves_a_buffer_in_place_to_a_copy
    • in_place::tests::the_switch_decides_and_unset_follows_the_host
    • in_place::tests::a_host_that_never_opens_heaps_is_not_asked_again
    • shadow::tests::loose_memory_is_in_video_memory_with_a_mirror
    • a_failed_copy_back_from_video_memory_loses_no_shader_writes (a buffer's copy, marked and declared, and a loose window's)
    • an_earlier_undeclared_shader_write_does_not_reach_title_memory_late (a buffer's copy and a loose window's)
    • with_copies_in_video_memory_the_cpu_sides_stay_in_system_memory (diagnostics)
    • The first two fail without their fixes.
  • Plus the tests carried over from the replaced PRs.
  • In-place tests rerun themselves in a child process with VICTORY_IN_PLACE=1; elsewhere tests keep the copies, so the copy machinery stays tested on unified hosts.
  • RTX 5070 Ti: victory-gpu 271 passed, 2 failed (289 passed with diagnostics). dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views fail the same way on clean main on this machine.
  • Integrated Radeon (VICTORY_TEST_ADAPTER=radeon): 273 of 273 (291 of 291 with diagnostics).
  • victory-hle: 154 passed. Workspace clippy is clean, with and without victory-gpu/diagnostics.
  • #2112 (desplmfao): opt-in title memory in place on any host, with a 1 MiB floor. The in-place code here is written separately and differs: it is on by default only on unified hosts behind the self-test, opens one heap per buffer, pins heaps so the title can still free that memory, and handles withholding.
  • #2734 (sirrus98), #2705 (MrEjecutor) and #2993 (r4tedx): other video-memory placements for host copies.
  • #2175 / #2465 (wbkepler): the written-pages bitmaps in video memory.
  • #2371 / #1630: adapter choice. On a laptop whose default adapter is the integrated GPU, in place turns on there.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6622199834 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T08:03:08Z. --- **Goal: give titles the Xbox Series' shared memory model on a PC whose GPU has its own video memory.** On the console, the CPU and GPU share one pool of memory. A title builds vertex data, constants and command data at an address, hands the GPU that address, and reads back what shaders wrote at that same address, with nothing copied. Titles are written around that. A PC with a discrete GPU has two pools: system memory next to the CPU, and video memory on the card, joined by PCI Express. Each processor is fast in its own pool and slow in the other: on an RTX 5070 Ti, the GPU reads system memory at ~23 GB/s and video memory at ~720 GB/s. This PR simulates the console's single pool on such a GPU: - Title memory stays the one source of truth, at the title's own addresses. - The host GPU works on an image of it in video memory, kept coherent in both directions at every submission. - The title still sees one memory, and its shaders read at video-memory speed. Where the host really has one pool (an APU or integrated GPU), no simulation is needed: the GPU uses title memory itself, exactly as on the console. Everything here is my own work: new code, plus my open PRs, which this replaces (#2120, #2130, #2222, #2870, #2912, #2921, #2929, #2945). It depends on no one else's PR. ### How the shared pool is simulated | What the console guarantees | Discrete GPU (video memory) | Unified host (APU, integrated GPU) | |---|---|---| | The GPU reads what the CPU just wrote, at the same address | Pages the title wrote since the last submission (write watch, guards) are copied into the video-memory image before the submission, straight through the BAR into GPU upload heaps | Same memory: nothing to copy | | The CPU reads what the GPU just wrote, at the same address | Pages shaders wrote (write marks, or snapshots of declared ranges) go back into title memory after the submission, through a system-memory mirror that catches up only where the CPU reads | Same memory: nothing to copy back | | The GPU reads its data at memory speed | The image is in video memory: the benchmark's GPU time drops from 44 ms to 11 (2 with snapshots) | Already at memory speed | | One copy of the data | Two: title memory and its image in video memory, sized under the DXGI video memory budget | One: title memory itself (opened as a GPU heap) | | The title frees, protects and remaps its memory at will | Unchanged | Buffers held in place are let go first (pins), then the change goes through | Why simulate instead of sharing literally on a discrete GPU? The GPU can read title memory itself across the bus (`VICTORY_IN_PLACE=1`). Measured, that takes 43.7 ms per submission, against 29.7–36.7 ms for the simulated pool in video memory: shaders reading across PCI Express cost more than keeping the image coherent. So literal sharing is only the default where the pool really is shared. ### What each host gets by default No environment variable is needed. The switches only override. | Host | Default | |---|---| | Discrete GPU reporting GPU upload heaps (Resizable BAR on, with driver and D3D12 runtime support), NVIDIA | Copies of all title buffers, and of title memory outside buffers, in video memory | | Same, AMD or Intel | Copies of read-only buffers in video memory. Copies of buffers shaders write, and of title memory outside buffers, stay in system memory: on an RX 9070 XT and an RX 7900 XTX their mirrors cost more than they saved | | Discrete GPU without GPU upload heaps (Resizable BAR off, older runtime) | Unchanged from main: copies in system memory | | GPU sharing memory with the CPU (APU, integrated GPU), self-test passes | No copies: title memory in place | | Same, self-test fails (e.g. a translation layer that gives the GPU new memory) | Copies, with a log line saying why | | Mac through D3DMetal | Copies: it reports a discrete GPU (UMA=false) and opens no heaps from title memory | The startup log names the outcome: `host GPU memory: ...`, plus a line when in place turns on or is refused. Overrides: - `VICTORY_GPU_UPLOAD=0`: every copy in system memory. - `VICTORY_GPU_UPLOAD_WRITES=0|1`: written buffers' copies in system memory, or in video memory on any GPU. - `VICTORY_IN_PLACE=0|1`: in place off, or on wherever the GPU can open title memory as a heap. The diagnostics ranking (from #2929) needs a `--features diagnostics` build plus `VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1`. ### Results Synthetic: `shadow::bench::compute_heavy_submissions_by_copy_placement` runs one submission of 200 compute dispatches in 8 lists over 320 MiB of title buffers, through the real copy paths (`shadow::find`, `Shadow::refresh`, `Shadow::gpu_writes`, `HostList`, `Host::execute`). Each placement runs in its own process, and the test checks that title memory ends up byte-identical in all of them. Ryzen 9 7900X, Windows 11. Each number is the median of three runs, each the median of 5 submissions, ms per submission. | host | writes found by | title writes | main (copies in system memory) | this PR, default | | |---|---|---|---|---|---| | RTX 5070 Ti | write marks | none | 58.1 | 29.0 (copies in video memory) | **−50%** | | RTX 5070 Ti | write marks | 16 MiB per submission | 60.3 | 32.6 | **−46%** | | RTX 5070 Ti | snapshots | none | 71.8 | 37.1 | **−48%** | | RTX 5070 Ti | snapshots | 16 MiB per submission | 74.1 | 39.2 | **−47%** | | integrated Radeon (7900X) | write marks | none | 58.9 | 40.6 (title memory in place) | **−31%** | | integrated Radeon | write marks | 16 MiB per submission | 59.8 | 41.1 | **−31%** | | integrated Radeon | snapshots | none | 70.1 | 40.5 | **−42%** | | integrated Radeon | snapshots | 16 MiB per submission | 71.1 | 40.9 | **−42%** | - **5070 Ti:** the GPU's time drops from 44 ms to 11 with write marks, and to 2 with snapshots. Copy-back grows by 4-5 ms, from bringing written pages back to their mirrors. With snapshots, preparing grows by about 2 ms: the declared ranges come back to the mirrors whole before the snapshots (see the review fixes below). - **Integrated Radeon:** refreshes (up to 14 ms), snapshots and copy-backs (15-17 ms) disappear, and no copies are made (320 MiB of memory saved). Opening the heaps costs 127 ms once, against 25-30 ms to allocate copies. The first submission then takes 40 ms instead of 111-134, so the first use costs about the same either way, and every later submission is 18-30 ms shorter. Video-memory placements buy nothing there: it is the same memory. - **Title memory outside any buffer** (the same benchmark with `VICTORY_TEST_BENCH_LOOSE=1`, 5070 Ti): 30.6-44.4 ms with its 4 MiB windows' copies in video memory, against 66.3-103.1 ms in system memory (−54 to −57%). The GPU's time falls from about 50 ms to 10 (2 with snapshots). - **5070 Ti with `VICTORY_IN_PLACE=1`:** 43.6-43.8 ms. That beats copies in system memory but loses to copies in video memory, so in place stays off on discrete GPUs. - **In a title on an RX 7900 XTX** ([zed6000's run](https://github.com/Marvisak/VIctory/pull/3102#issuecomment-7199931278), intro cutscene, medians of 36 frame lines): no gain. The base takes 415 ms a frame and this PR's default 431 ms. With `VICTORY_GPU_UPLOAD_WRITES=1` the GPU's time falls from 151 to 138 ms, but copying back grows from 58 to 78 ms, for 438 ms. No dropped draws, new warnings or device removals. That is the second AMD card where written copies in video memory don't pay, so they stay NVIDIA-only. `docs/gpu-memory.md` has the full tables, every placement on both GPUs. ### What changes **Detecting the host** (from #2912) - `crate::unified::detect` runs at host creation: `ARCHITECTURE1.UMA` / `CacheCoherentUMA`, `GPUUploadHeapSupported` and the DXGI budgets. It costs about 0.3 ms and logs one line (`host GPU memory: ...`), which also goes into the GPU failure text. **Copies in video memory on discrete GPUs** (from #2120, #2130, #2222, #2870) - Copies of read-only title buffers go in GPU upload heaps. - Copies of written buffers go in video memory with a system-memory mirror that catches up lazily. - Copies of title memory outside any buffer (its 4 MiB windows) are placed as written buffers' copies: shaders may write any of it. - Upload-heap copies take a share of the VRAM budget, and render targets are demoted last. - On by default where the host has GPU upload heaps. Written copies only on NVIDIA: on an RX 9070 XT and an RX 7900 XTX the mirrors cost more than they saved. `VICTORY_GPU_UPLOAD=0` and `VICTORY_GPU_UPLOAD_WRITES=0|1` override. **Title memory in place on unified hosts** (new, `crate::in_place`) - Each title buffer of at least 64 KiB becomes a heap over its own pages (`OpenExistingHeapFromAddress1`), with one buffer placed at its start. - `Shadow` gains an in-place kind whose `data` is title memory itself. Refresh, snapshot and copy-back do nothing for it. - On by default where the host reports UMA and title memory passes `unified::self_test`. The self-test runs once, only on unified hosts: it has the GPU copy into and out of memory allocated like the title's pools, and checks that both sides see the other's writes. That guards against layers that have the API but hand the GPU new memory, such as vkd3d-proton without `VK_EXT_external_memory_host`. - `VICTORY_IN_PLACE=1` turns it on wherever heaps open; `=0` turns it off. **Freeing memory held in place** (from #2921, now with its caller) - While a heap lives, Windows refuses `VirtualFree`, `VirtualProtect` and `UnmapViewOfFile*` with error 87. - The HLE wraps those calls, and xmem's own unmapping, in `title_memory_change`. That releases the buffers held over the range first, then retries for up to 100 ms while lists still holding them are reset. - Each placed buffer holds its heap through private data, so the heap's registration lasts as long as anything is placed in it. vkd3d-proton destroyed heaps early; pickles976 reported it on #2945. **Withholding still works with in place** - What programs using title memory write is withheld from title memory when they miss (`memory::withholding`). A buffer in place cannot withhold anything, so: - **Declared write to a buffer in place:** the buffer gets a copy from its next use on. That submission saves the range beforehand and puts it back if the writes are withheld. - **Page table made:** buffers shaders may write move to copies before the table names them. Only buffers made without unordered access stay in place. - Other copies of pages held in place can't guard them, so they're refreshed at each use and always see what the GPU wrote. **Mirrors stay consistent** (review fixes, from r4tedx's findings on this PR) - **A failed GPU copy back loses nothing.** `Host::copy_now` reports whether it saw its fence reached on a live device, and doesn't reuse its allocator until it has. When it didn't (no copier, a failed call, a removed device), `bring_back` reads the pages through the CPU's mapping of video memory. That's slow, but the mirror still gets the shaders' writes. Written copies made after that stay in system memory. Before this, the stale bits were cleared anyway, and the copy-back pushed the mirror's old bytes into title memory and video memory. - **Snapshots bring back their declared ranges whole**, not only the pages refreshes left stale. A byte an earlier shader wrote through an undeclared view is in video memory with no stale bit. A snapshot without it took it for this submission's write and put it over the title's byte. - **`VICTORY_COPIES_IN_VIDEO_MEMORY` (diagnostics)** now places copies as the video-memory placements do: written ones with their mirrors, within the upload budget. Mirrors, the marks bitmap and other shared buffers stay in system memory. - These apply to buffers' copies and to loose windows alike. **Diagnostics** (from #2929) - The frame-rate line ranks host copies by the GPU time they're bound to and what video memory would save (`VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1`). Buffers in place aren't ranked. ### Limits - My measurements are synthetic. The only run in a title so far is zed6000's on an RX 7900 XTX (no gain, above). None has run on NVIDIA or on a unified host. - A title write that lands while its page is being copied back, after the copy-back read it, can miss the copy until the title writes the page again. Main has the same window (r4tedx's finding 4); it isn't fixed here. - A title that reads memory at computed addresses (page tables) keeps in place only for buffers made without unordered access, starting with its first such submission. If a page-table program writes one of those, the write reaches title memory and is not withheld. - While a heap still lives (a list or descriptor slot holds its buffer), a copy over the same pages is refreshed at every use. Results withheld into that copy are therefore dropped at the next submission rather than at the end of the frame. - In place is untested on vkd3d-proton and D3DMetal. The self-test decides the default there. - The written-pages bitmap stays in system memory (#2175 / #2465 by wbkepler move it). With copies in video memory, marking takes about 9 of the 11 GPU ms in the benchmark. - Copies of single views off their buffer's elements (`shadow::exact`, ~2 KB each, in shared buffers) stay in system memory. - Window copies are never freed, so memory allocated again at the same address reuses its window's copy. That copy is current only where the runtime reported the remap (as on main). The benchmark caught this when it reused addresses between modes. ### Tests - New: - `shadow::tests::a_title_buffer_in_place_needs_no_copies` - `the_title_frees_memory_a_buffer_is_in_place_over` - `a_buffer_in_place_holds_its_heap_and_pin` - `page_tables_move_written_buffers_to_copies` - `host::withholding::a_program_using_title_memory_moves_a_buffer_in_place_to_a_copy` - `in_place::tests::the_switch_decides_and_unset_follows_the_host` - `in_place::tests::a_host_that_never_opens_heaps_is_not_asked_again` - `shadow::tests::loose_memory_is_in_video_memory_with_a_mirror` - `a_failed_copy_back_from_video_memory_loses_no_shader_writes` (a buffer's copy, marked and declared, and a loose window's) - `an_earlier_undeclared_shader_write_does_not_reach_title_memory_late` (a buffer's copy and a loose window's) - `with_copies_in_video_memory_the_cpu_sides_stay_in_system_memory` (diagnostics) - The first two fail without their fixes. - Plus the tests carried over from the replaced PRs. - In-place tests rerun themselves in a child process with `VICTORY_IN_PLACE=1`; elsewhere tests keep the copies, so the copy machinery stays tested on unified hosts. - **RTX 5070 Ti:** victory-gpu 271 passed, 2 failed (289 passed with `diagnostics`). `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views` fail the same way on clean main on this machine. - **Integrated Radeon** (`VICTORY_TEST_ADAPTER=radeon`): 273 of 273 (291 of 291 with `diagnostics`). - victory-hle: 154 passed. Workspace clippy is clean, with and without `victory-gpu/diagnostics`. ### Related - #2112 (desplmfao): opt-in title memory in place on any host, with a 1 MiB floor. The in-place code here is written separately and differs: it is on by default only on unified hosts behind the self-test, opens one heap per buffer, pins heaps so the title can still free that memory, and handles withholding. - #2734 (sirrus98), #2705 (MrEjecutor) and #2993 (r4tedx): other video-memory placements for host copies. - #2175 / #2465 (wbkepler): the written-pages bitmaps in video memory. - #2371 / #1630: adapter choice. On a laptop whose default adapter is the integrated GPU, in place turns on there.
Dukestar69 commented 2026-11-26 08:08:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T08:08:40Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • cargo test -p victory-gpu shadow::tests -- --test-threads=1 (RTX 5090 & WARP): 24 passed, 0 failed on both (including all new video-memory mirror and in-place tests).
  • cargo test -p victory-gpu draw::tests -- --test-threads=1 (RTX 5090): 20 passed, 0 failed.
  • cargo test -p victory-hle memoryapi & xmem: all tests passed.
  • cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 199 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6070463987 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102#pullrequestreview-6070463987). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T08:08:40Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP): - `cargo test -p victory-gpu shadow::tests -- --test-threads=1` (RTX 5090 & WARP): 24 passed, 0 failed on both (including all new video-memory mirror and in-place tests). - `cargo test -p victory-gpu draw::tests -- --test-threads=1` (RTX 5090): 20 passed, 0 failed. - `cargo test -p victory-hle memoryapi` & `xmem`: all tests passed. - `cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 199 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Ahmet-Dedeler commented 2026-11-26 09:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Ahmet-Dedeler on 2026-11-26T08:04:52Z.


A data point for the Mac side, since Apple Silicon is the obvious unified host: through Apple's D3DMetal (CrossOver 26.3, D3DMetal 4.0b3, M5 Max) this path won't turn on, and it can't as written.

  • The adapter calls itself "AMD Compatibility Mode", with ~53 GB "dedicated" and UMA=false, so unified::detect won't see a unified host even though it is one.
  • Forcing it wouldn't help either. OpenExistingHeapFromAddress returns E_NOTIMPL, OpenExistingHeapFromAddress1 E_FAIL, and OpenExistingHeapFromFileMapping (SEC_COMMIT and SEC_RESERVE) E_NOTIMPL. So the self-test should fail cleanly and fall back to copies, which is the right outcome.

What does work there is the reverse direction: let D3DMetal allocate a mapped write-back buffer, then use mach_vm_remap (copy=FALSE, fixed + overwrite) to put that buffer's pages at the title's own address. The title and the GPU then share the pages. It's written up with a standalone probe in pragyaangaur/VIctory-macOS#204, and pragyaangaur/VIctory-macOS#207 (merged there, VICTORY_ALIAS_BUFFERS=1) implements it behind a startup probe. It only covers buffers: Metal textures have their own swizzled storage, so textures keep their copies.

So if in_place had a seam where the "open the title's pages as a heap + place a buffer" step can be swapped for "make a host buffer + alias it over the title's pages", the shadow side of this PR (the in-place kind with no refresh, snapshot or copy-back, the pinning, the withholding rules) looks like it would carry over to the Mac as is. I haven't tried this PR on the Mac myself.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186161905 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102#issuecomment-7186161905). Originally posted by [Ahmet-Dedeler](https://github.com/Ahmet-Dedeler) on 2026-11-26T08:04:52Z. --- A data point for the Mac side, since Apple Silicon is the obvious unified host: through Apple's D3DMetal (CrossOver 26.3, D3DMetal 4.0b3, M5 Max) this path won't turn on, and it can't as written. - The adapter calls itself "AMD Compatibility Mode", with ~53 GB "dedicated" and `UMA=false`, so `unified::detect` won't see a unified host even though it is one. - Forcing it wouldn't help either. `OpenExistingHeapFromAddress` returns E_NOTIMPL, `OpenExistingHeapFromAddress1` E_FAIL, and `OpenExistingHeapFromFileMapping` (SEC_COMMIT and SEC_RESERVE) E_NOTIMPL. So the self-test should fail cleanly and fall back to copies, which is the right outcome. What does work there is the reverse direction: let D3DMetal allocate a mapped write-back buffer, then use `mach_vm_remap` (copy=FALSE, fixed + overwrite) to put that buffer's pages at the title's own address. The title and the GPU then share the pages. It's written up with a standalone probe in pragyaangaur/VIctory-macOS#204, and pragyaangaur/VIctory-macOS#207 (merged there, `VICTORY_ALIAS_BUFFERS=1`) implements it behind a startup probe. It only covers buffers: Metal textures have their own swizzled storage, so textures keep their copies. So if `in_place` had a seam where the "open the title's pages as a heap + place a buffer" step can be swapped for "make a host buffer + alias it over the title's pages", the shadow side of this PR (the in-place kind with no refresh, snapshot or copy-back, the pinning, the withholding rules) looks like it would carry over to the Mac as is. I haven't tried this PR on the Mac myself.
Marvisak commented 2026-11-26 09:06:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T08:24:37Z.


Automated triage for the maintainers.

Needs work, and needs the maintainer's decision. This merges cleanly, but it is 5,425 added lines in 20 files, folding in eight earlier PRs, and some of it is beyond what triage can pass:

  • Long design document: docs/gpu-memory.md (529 lines of rationale, charts and measurement tables) goes against the repo's rule that docs stay short. Please cut it to a few lines on the switches (VICTORY_GPU_UPLOAD, VICTORY_GPU_UPLOAD_WRITES, VICTORY_IN_PLACE) and keep the measurements in the PR description.
  • Tests spawn processes: several tests rerun the test binary through std::process::Command::new(std::env::current_exe()) with environment switches (shadow.rs, in_place.rs, shadow/bench.rs). Spawning processes needs the maintainer's decision.
  • New HLE overrides: crates/victory-hle/src/modules/memoryapi.rs now intercepts VirtualFree, VirtualProtect, UnmapViewOfFile and their variants, retrying for up to 100 ms while the GPU side lets go of pinned heaps. That changes runtime behaviour for every title memory change, and it is only exercised synthetically ("No title has been run on either host").
  • Size: detection (unified.rs), video-memory copies (budget.rs, heat.rs, shadow.rs), in place (in_place.rs, pinned.rs) and the HLE wrappers can each be reviewed and reverted on their own. Splitting them would make each reviewable. The PR is the replacement for #2120, #2130, #2222, #2870, #2912, #2921, #2929 and #2945, so those can be closed in its favour once a direction is chosen.

CI (check) was still running when this was written. What would change the verdict: the doc trimmed, the maintainer's call on the child-process tests and the memoryapi overrides, and ideally a split into reviewable pieces.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186558995 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102#issuecomment-7186558995). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T08:24:37Z. --- <!-- victory-triage v1 head=63ab7631a503e8846bdb52a2cebf19df8e62fc02 verdict=needs-work at=2026-11-26T08:18:11Z --> Automated triage for the maintainers. **Needs work, and needs the maintainer's decision.** This merges cleanly, but it is 5,425 added lines in 20 files, folding in eight earlier PRs, and some of it is beyond what triage can pass: - **Long design document:** `docs/gpu-memory.md` (529 lines of rationale, charts and measurement tables) goes against the repo's rule that docs stay short. Please cut it to a few lines on the switches (`VICTORY_GPU_UPLOAD`, `VICTORY_GPU_UPLOAD_WRITES`, `VICTORY_IN_PLACE`) and keep the measurements in the PR description. - **Tests spawn processes:** several tests rerun the test binary through `std::process::Command::new(std::env::current_exe())` with environment switches (`shadow.rs`, `in_place.rs`, `shadow/bench.rs`). Spawning processes needs the maintainer's decision. - **New HLE overrides:** `crates/victory-hle/src/modules/memoryapi.rs` now intercepts `VirtualFree`, `VirtualProtect`, `UnmapViewOfFile` and their variants, retrying for up to 100 ms while the GPU side lets go of pinned heaps. That changes runtime behaviour for every title memory change, and it is only exercised synthetically ("No title has been run on either host"). - **Size:** detection (`unified.rs`), video-memory copies (`budget.rs`, `heat.rs`, `shadow.rs`), in place (`in_place.rs`, `pinned.rs`) and the HLE wrappers can each be reviewed and reverted on their own. Splitting them would make each reviewable. The PR is the replacement for #2120, #2130, #2222, #2870, #2912, #2921, #2929 and #2945, so those can be closed in its favour once a direction is chosen. CI (`check`) was still running when this was written. What would change the verdict: the doc trimmed, the maintainer's call on the child-process tests and the `memoryapi` overrides, and ideally a split into reviewable pieces. --- _Generated by [Claude Code](https://claude.ai/code)_
r4tedx commented 2026-11-26 09:06:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-26T09:02:04Z.


Note: these tests ran at 63ab7631. The head has since moved to aab00070 (one commit: title memory outside buffers is in video memory where written copies are). That commit doesn't change copy_now, bring_back or copy_back_marked, but it does touch where copies are placed, so finding 3 may read differently there. I haven't re-run the tests on it yet.

Thanks for pulling #2120, #2130, #2222 and the rest into one PR. The lazy mirror and the in-place path for unified hosts are nice, and keeping read-only copies in a single buffer saves the RAM that #2993 spends. I read #3102 against #2993, which covers the same ground, and wrote synthetic tests for the places where the two differ. Below are only the findings those tests reproduce on #3102's own code, at 63ab7631.

How the tests run. All of them are in one file, crates/victory-gpu/src/shadow/tests/repro_3102.rs, on the branch r4tedx/VIctory:repro/3102-findings (commit 47bd0cf3). That branch is one commit on top of #3102's 63ab7631, with tests only and no fixes.

  • They use your helpers (mirrored_buffer, gpu_store, gpu_bytes, mark_entry).

  • Each runs in a child process with the switches your own mirror tests set: VICTORY_GPU_UPLOAD=1 and VICTORY_GPU_UPLOAD_WRITES=1. That is the default on NVIDIA.

  • They ran on WARP with --features diagnostics --test-threads 1. WARP reports GPU upload heaps, so no test returns early. Each one asserts and prints adapter "Microsoft Basic Render Driver" vendor 0x1414: gpu_upload true gpu_upload_writes true.

  • I added two hooks, both #[cfg(test)], so they are compiled out of every other build:

    • in Host::copy_now, a switch that makes the copy not run;
    • in Shadow::copy_back_marked, a closure that runs just before taken.

    Nothing else in the production code changed.

Command: VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib repro_3102 -- --test-threads 1


1. A failed bring-back loses a marked shader write on every side, and can write stale mirror bytes into title memory

Where:

  • host.rs:4127-4189. copy_now returns (). With no copier it returns silently (:4164). Errors from Reset, Close, Signal or SetEventOnCompletion are only logged (:4187). The result of WaitForSingleObject is ignored (:4182).
  • shadow.rs:1376. bring_back clears the stale bits before it calls copy_now (:1385).
  • shadow.rs:695 and :705. copy_back_marked compares the mirror with title memory, then always pushes the mirror into video memory.

What goes wrong. When the copy that brings the shaders' writes back doesn't run:

  • Marked page. The mirror lacks the shader's write. The compare finds nothing, and the push writes the mirror's old bytes over the shader's write in video memory too. The write is gone from title memory, the mirror and video memory.
  • Marked page whose mirror was stale. This is the usual state after a refresh, which writes video memory only. The stale bit has already been cleared, so the compare runs against whatever the mirror last held. Those bytes go into title memory. Here that was 65,273 of 65,536 bytes of the page; every byte the shader didn't write became the mirror's old zeros.
  • Declared unmarked range. The write stays in video memory only. Title memory and the mirror don't get it, and the cleared stale bit means no later read brings it back.

Tests:

  • e_a_failed_bring_back_keeps_the_shaders_writes (mirror current)
  • e_a_failed_bring_back_keeps_the_shaders_writes_stale_mirror

Each test runs one submission. Its shaders write 0x5a into a marked page and into a declared range, and the GPU copies after the submission do not run.

Output
assertion `left == right` failed: (title, mirror, video memory) at the marked page and the declared range: the shader's byte should survive a failed bring-back (pattern byte there 0x08; stale pages after [])
  left: ((8, 8, 8), (33, 33, 90))
 right: ((90, 90, 90), (90, 90, 90))

[stale mirror]
REPRO-3102 (e) current false: ... stale pages after [], title bytes off the pattern elsewhere: page 0 65273 page 1 0
assertion `left == right` failed: (title, mirror, video memory) at the marked page and the declared range: the shader's byte should survive a failed bring-back (pattern byte there 0x08; stale pages after [])
  left: ((0, 0, 0), (33, 33, 90))
 right: ((90, 90, 90), (90, 90, 90))

How #2993 handles it (d2c20e28, from fuzeofficlal's review there):

  • copy_now returns whether it saw the list end.
  • The allocator is reset only after the last list was seen to end.
  • If the signal fails after the list ran, the copier is retired. If the event fails, the fence is read instead.
  • When a bring-back fails, the bytes are read through the mapping before the copy-backs, and no further copies are admitted to video memory.
  • Without a copier, none is admitted at all.
  • Test: a_failed_gpu_copy_of_shaders_writes_loses_none_of_them.

You're welcome to take any of it. For a lazy mirror, the smallest change would be to clear the stale bits only after copy_now reports success, and to skip the copy-back's compare and push for pages whose pull failed.

2. An old unmarked GPU write reaches title memory late, over a title write

Where:

  • shadow.rs:1275-1277: the shortcut, under which writes outside declared ranges and marked pages stay in video memory.
  • shadow.rs:1304-1329: snapshots_ahead brings back stale pages only.
  • shadow.rs:483: keep_before takes the snapshot from the mirror.
  • host.rs:1649: pull(&snapshots) after the submission brings back whole pages.
  • shadow.rs:620: the merge.

What goes wrong. An earlier shader writes a byte through a view no list declares or marks, as a shader without write marks does. The byte lands in video memory only and sets no stale bit. Later, the title writes that byte while a submission declares the page unmarked and its shader writes another byte there. The snapshot comes from the mirror, which lacks the old byte. The pull after the submission brings the old byte in, so the merge takes it for this submission's write and puts it over the title's byte. On main, and on #3102 with VICTORY_GPU_UPLOAD_WRITES=0, the snapshot already holds the old byte, so the title's byte stays.

Tests:

  • h_an_old_unmarked_write_does_not_reach_title_memory_late_with_mirrors fails.
  • The control, h_..._in_system_memory (VICTORY_GPU_UPLOAD_WRITES=0), passes.
Output
REPRO-3102 (h) mirrors false: title (p+10, p+20) = (0x77, 0xbb)      <- control passes
REPRO-3102 (h) mirrors true: title (p+10, p+20) = (0xaa, 0xbb)
assertion `left == right` failed: mirrors true: title memory at p+10 keeps the title's byte (0x77, not the old shader's 0xaa), p+20 gets this submission's 0xbb
  left: (170, 187)
 right: (119, 187)

How #2993 handles it (477c6c6f): Shadow::writing brings the range back from video memory before taking the snapshot, wherever no snapshot covers it yet. Tests: an_old_unmarked_write_does_not_reach_title_memory_late_at_2 and _at_0. With a lazy mirror, the equivalent is for snapshots_ahead to pull the whole declared range, not only its stale pages, before the snapshot. That costs one GPU copy per unmarked range.

3. With VICTORY_COPIES_IN_VIDEO_MEMORY set as well (diagnostics), the CPU sides go to GPU upload heaps

Where: host.rs:4208. The diagnostics override in shared_mapped_buffer applies to every shared_buffer. That includes:

  • the mirrors (shadow.rs:1541);
  • the written copies the switch or the budget keeps in system memory (None => mirror, shadow.rs:1555);
  • the marks bitmap (shadow.rs:1090).

What goes wrong:

  • These buffers land in GPU upload heaps outside UPLOAD_POOL's budget.
  • freshen copies video memory into video memory.
  • The CPU reads mirrors and copy-backs through the BAR.

It affects diagnostics builds only.

Tests:

  • f_with_both_switches_the_cpu_sides_stay_in_system_memory_mirror
  • f_with_both_switches_the_cpu_sides_stay_in_system_memory_kept_copy (_WRITES=0, the same branch a copy the budget refuses takes)
Output
assertion `left == right` failed: mirrors true: the CPU side of the copy and the marks bitmap are in system memory (heap type 5 is a GPU upload heap)
  left: ((5, 0), (5, 0))
 right: ((4, 3), (4, 3))
[kept copy, _WRITES=0: same output with "mirrors false"]

(heap type, CPU page property): 5 = GPU_UPLOAD, 4/3 = CUSTOM/WRITE_BACK.

How #2993 handles it (d2c20e28): while its switch is on, Host::system_buffer always makes CPU sides in the CUSTOM write-back L0 heap, and the diagnostics override no longer applies to them. Test: with_both_switches_the_cpu_sides_stay_in_system_memory.

4. A title write during a marked copy-back misses the copy (main's window, now on both sides)

Where: shadow.rs:676-708. The copy-back reads title memory, merges, writes title memory, pushes the mirror, and then calls taken (:708). Nothing re-reads title memory after the page is guarded again. copy_back_or_not (:620-638) has the same order.

What goes wrong. A title write to the page after the copy-back's read and before taken reaches neither the mirror nor video memory. taken then counts the page as current, so the next refresh copies 0 bytes, and the GPU keeps the old byte.

Tests:

  • c_a_title_write_during_a_copy_back_reaches_video_memory_with_mirrors fails.
  • With _WRITES=0, c_..._in_system_memory fails the same way. So this is main's existing window, not something #3102 adds. With mirrors it covers both sides.
Output
REPRO-3102 (c) mirrors true: at p+100 video 0x64 mirror 0x64; the next refresh copied 0 bytes; video after it 0x64
assertion `left == right` failed: mirrors true: the GPU side (now, the mirror, after the next refresh, which copied 0 bytes) has the title's write at p+100 (pattern 0x64)
  left: (100, 100, 100)
 right: (119, 119, 119)
[_WRITES=0: same values]

How #2993 handles it (80aac1c3): after taking the page, settle reads title memory into the system side once more, and only then writes video memory. Test: a_title_write_during_a_copy_back_reaches_video_memory. It is lower priority than 1–3 because main has the same window.

Not confirmed

  • #2051's queued refresh. I expected a refresh through #2051's copy_queued to write the mirror alone. #3102 doesn't contain #2051, so I couldn't test that directly.
    • #3102's own refreshes reach video memory. d_refreshes_of_mirrored_copies_reach_video_memory passes: it checks the first refresh, a title write, and a write under a busy range, read back by GPU copy.
    • What I can show is that the tests wouldn't catch it. d_a_write_of_the_mirror_alone_is_seen_by_read_host_not_the_gpu writes the mirror by hand, as copy_queued writes self.data. read_host then reports 0xc1, while the GPU side still has 0x28.
    • If #2051 lands second, a check through gpu_bytes, or a debug_assert!(self.vram.is_none()) in copy_queued, would catch it.
  • I haven't tested the budget, residency or in-place points from my notes: 2 GiB admitted without a reading, no ceiling near full, copies at HIGH residency, and an in-place free while a list or a descriptor slot holds the buffer. They are design questions more than reproduced bugs.

#3102 and #2993 overlap: two designs for the same feature, and only one can merge. Which one is the maintainer's call. Whichever lands, we'd be glad to help port the fixes and tests above onto it.

The title was not used in these tests.

AI-assisted

<!-- greyfinch-sync:Marvisak/VIctory:comment:7187328528 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102#issuecomment-7187328528). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-26T09:02:04Z. --- > Note: these tests ran at `63ab7631`. The head has since moved to `aab00070` (one commit: title memory outside buffers is in video memory where written copies are). That commit doesn't change `copy_now`, `bring_back` or `copy_back_marked`, but it does touch where copies are placed, so finding 3 may read differently there. I haven't re-run the tests on it yet. Thanks for pulling #2120, #2130, #2222 and the rest into one PR. The lazy mirror and the in-place path for unified hosts are nice, and keeping read-only copies in a single buffer saves the RAM that #2993 spends. I read #3102 against #2993, which covers the same ground, and wrote synthetic tests for the places where the two differ. Below are only the findings those tests reproduce on #3102's own code, at `63ab7631`. **How the tests run.** All of them are in one file, [`crates/victory-gpu/src/shadow/tests/repro_3102.rs`](https://github.com/r4tedx/VIctory/blob/47bd0cf3c78d5a3b97b68a008f767e826b939707/crates/victory-gpu/src/shadow/tests/repro_3102.rs), on the branch [`r4tedx/VIctory:repro/3102-findings`](https://github.com/r4tedx/VIctory/tree/repro/3102-findings) (commit `47bd0cf3`). That branch is one commit on top of #3102's `63ab7631`, with tests only and no fixes. - They use your helpers (`mirrored_buffer`, `gpu_store`, `gpu_bytes`, `mark_entry`). - Each runs in a child process with the switches your own mirror tests set: `VICTORY_GPU_UPLOAD=1` and `VICTORY_GPU_UPLOAD_WRITES=1`. That is the default on NVIDIA. - They ran on WARP with `--features diagnostics --test-threads 1`. WARP reports GPU upload heaps, so no test returns early. Each one asserts and prints `adapter "Microsoft Basic Render Driver" vendor 0x1414: gpu_upload true gpu_upload_writes true`. - I added two hooks, both `#[cfg(test)]`, so they are compiled out of every other build: - in `Host::copy_now`, a switch that makes the copy not run; - in `Shadow::copy_back_marked`, a closure that runs just before `taken`. Nothing else in the production code changed. Command: `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib repro_3102 -- --test-threads 1` --- ### 1. A failed bring-back loses a marked shader write on every side, and can write stale mirror bytes into title memory **Where:** - `host.rs:4127-4189`. `copy_now` returns `()`. With no copier it returns silently (`:4164`). Errors from `Reset`, `Close`, `Signal` or `SetEventOnCompletion` are only logged (`:4187`). The result of `WaitForSingleObject` is ignored (`:4182`). - `shadow.rs:1376`. `bring_back` clears the stale bits before it calls `copy_now` (`:1385`). - `shadow.rs:695` and `:705`. `copy_back_marked` compares the mirror with title memory, then always `push`es the mirror into video memory. **What goes wrong.** When the copy that brings the shaders' writes back doesn't run: - *Marked page.* The mirror lacks the shader's write. The compare finds nothing, and the `push` writes the mirror's old bytes over the shader's write **in video memory too**. The write is gone from title memory, the mirror and video memory. - *Marked page whose mirror was stale.* This is the usual state after a refresh, which writes video memory only. The stale bit has already been cleared, so the compare runs against whatever the mirror last held. Those bytes go into title memory. Here that was **65,273 of 65,536 bytes** of the page; every byte the shader didn't write became the mirror's old zeros. - *Declared unmarked range.* The write stays in video memory only. Title memory and the mirror don't get it, and the cleared stale bit means no later read brings it back. **Tests:** - `e_a_failed_bring_back_keeps_the_shaders_writes` (mirror current) - `e_a_failed_bring_back_keeps_the_shaders_writes_stale_mirror` Each test runs one submission. Its shaders write `0x5a` into a marked page and into a declared range, and the GPU copies after the submission do not run. <details><summary>Output</summary> ``` assertion `left == right` failed: (title, mirror, video memory) at the marked page and the declared range: the shader's byte should survive a failed bring-back (pattern byte there 0x08; stale pages after []) left: ((8, 8, 8), (33, 33, 90)) right: ((90, 90, 90), (90, 90, 90)) [stale mirror] REPRO-3102 (e) current false: ... stale pages after [], title bytes off the pattern elsewhere: page 0 65273 page 1 0 assertion `left == right` failed: (title, mirror, video memory) at the marked page and the declared range: the shader's byte should survive a failed bring-back (pattern byte there 0x08; stale pages after []) left: ((0, 0, 0), (33, 33, 90)) right: ((90, 90, 90), (90, 90, 90)) ``` </details> **How #2993 handles it** (d2c20e28, from fuzeofficlal's review there): - `copy_now` returns whether it saw the list end. - The allocator is reset only after the last list was seen to end. - If the signal fails after the list ran, the copier is retired. If the event fails, the fence is read instead. - When a bring-back fails, the bytes are read through the mapping before the copy-backs, and no further copies are admitted to video memory. - Without a copier, none is admitted at all. - Test: `a_failed_gpu_copy_of_shaders_writes_loses_none_of_them`. You're welcome to take any of it. For a lazy mirror, the smallest change would be to clear the stale bits only after `copy_now` reports success, and to skip the copy-back's compare and `push` for pages whose pull failed. ### 2. An old unmarked GPU write reaches title memory late, over a title write **Where:** - `shadow.rs:1275-1277`: the shortcut, under which writes outside declared ranges and marked pages stay in video memory. - `shadow.rs:1304-1329`: `snapshots_ahead` brings back stale pages only. - `shadow.rs:483`: `keep_before` takes the snapshot from the mirror. - `host.rs:1649`: `pull(&snapshots)` after the submission brings back whole pages. - `shadow.rs:620`: the merge. **What goes wrong.** An earlier shader writes a byte through a view no list declares or marks, as a shader without write marks does. The byte lands in video memory only and sets no stale bit. Later, the title writes that byte while a submission declares the page unmarked and its shader writes another byte there. The snapshot comes from the mirror, which lacks the old byte. The pull after the submission brings the old byte in, so the merge takes it for this submission's write and puts it over the title's byte. On main, and on #3102 with `VICTORY_GPU_UPLOAD_WRITES=0`, the snapshot already holds the old byte, so the title's byte stays. **Tests:** - `h_an_old_unmarked_write_does_not_reach_title_memory_late_with_mirrors` fails. - The control, `h_..._in_system_memory` (`VICTORY_GPU_UPLOAD_WRITES=0`), passes. <details><summary>Output</summary> ``` REPRO-3102 (h) mirrors false: title (p+10, p+20) = (0x77, 0xbb) <- control passes REPRO-3102 (h) mirrors true: title (p+10, p+20) = (0xaa, 0xbb) assertion `left == right` failed: mirrors true: title memory at p+10 keeps the title's byte (0x77, not the old shader's 0xaa), p+20 gets this submission's 0xbb left: (170, 187) right: (119, 187) ``` </details> **How #2993 handles it** (477c6c6f): `Shadow::writing` brings the range back from video memory before taking the snapshot, wherever no snapshot covers it yet. Tests: `an_old_unmarked_write_does_not_reach_title_memory_late_at_2` and `_at_0`. With a lazy mirror, the equivalent is for `snapshots_ahead` to pull the whole declared range, not only its stale pages, before the snapshot. That costs one GPU copy per unmarked range. ### 3. With `VICTORY_COPIES_IN_VIDEO_MEMORY` set as well (diagnostics), the CPU sides go to GPU upload heaps **Where:** `host.rs:4208`. The diagnostics override in `shared_mapped_buffer` applies to every `shared_buffer`. That includes: - the mirrors (`shadow.rs:1541`); - the written copies the switch or the budget keeps in system memory (`None => mirror`, `shadow.rs:1555`); - the marks bitmap (`shadow.rs:1090`). **What goes wrong:** - These buffers land in GPU upload heaps outside `UPLOAD_POOL`'s budget. - `freshen` copies video memory into video memory. - The CPU reads mirrors and copy-backs through the BAR. It affects diagnostics builds only. **Tests:** - `f_with_both_switches_the_cpu_sides_stay_in_system_memory_mirror` - `f_with_both_switches_the_cpu_sides_stay_in_system_memory_kept_copy` (`_WRITES=0`, the same branch a copy the budget refuses takes) <details><summary>Output</summary> ``` assertion `left == right` failed: mirrors true: the CPU side of the copy and the marks bitmap are in system memory (heap type 5 is a GPU upload heap) left: ((5, 0), (5, 0)) right: ((4, 3), (4, 3)) [kept copy, _WRITES=0: same output with "mirrors false"] ``` (heap type, CPU page property): 5 = `GPU_UPLOAD`, 4/3 = `CUSTOM`/`WRITE_BACK`. </details> **How #2993 handles it** (d2c20e28): while its switch is on, `Host::system_buffer` always makes CPU sides in the CUSTOM write-back L0 heap, and the diagnostics override no longer applies to them. Test: `with_both_switches_the_cpu_sides_stay_in_system_memory`. ### 4. A title write during a marked copy-back misses the copy (main's window, now on both sides) **Where:** `shadow.rs:676-708`. The copy-back reads title memory, merges, writes title memory, `push`es the mirror, and then calls `taken` (`:708`). Nothing re-reads title memory after the page is guarded again. `copy_back_or_not` (`:620-638`) has the same order. **What goes wrong.** A title write to the page after the copy-back's read and before `taken` reaches neither the mirror nor video memory. `taken` then counts the page as current, so the next refresh copies 0 bytes, and the GPU keeps the old byte. **Tests:** - `c_a_title_write_during_a_copy_back_reaches_video_memory_with_mirrors` fails. - With `_WRITES=0`, `c_..._in_system_memory` **fails the same way**. So this is main's existing window, not something #3102 adds. With mirrors it covers both sides. <details><summary>Output</summary> ``` REPRO-3102 (c) mirrors true: at p+100 video 0x64 mirror 0x64; the next refresh copied 0 bytes; video after it 0x64 assertion `left == right` failed: mirrors true: the GPU side (now, the mirror, after the next refresh, which copied 0 bytes) has the title's write at p+100 (pattern 0x64) left: (100, 100, 100) right: (119, 119, 119) [_WRITES=0: same values] ``` </details> **How #2993 handles it** (80aac1c3): after taking the page, `settle` reads title memory into the system side once more, and only then writes video memory. Test: `a_title_write_during_a_copy_back_reaches_video_memory`. It is lower priority than 1–3 because main has the same window. ### Not confirmed - **#2051's queued refresh.** I expected a refresh through #2051's `copy_queued` to write the mirror alone. #3102 doesn't contain #2051, so I couldn't test that directly. - #3102's own refreshes reach video memory. `d_refreshes_of_mirrored_copies_reach_video_memory` passes: it checks the first refresh, a title write, and a write under a busy range, read back by GPU copy. - What I can show is that the tests wouldn't catch it. `d_a_write_of_the_mirror_alone_is_seen_by_read_host_not_the_gpu` writes the mirror by hand, as `copy_queued` writes `self.data`. `read_host` then reports `0xc1`, while the GPU side still has `0x28`. - If #2051 lands second, a check through `gpu_bytes`, or a `debug_assert!(self.vram.is_none())` in `copy_queued`, would catch it. - I haven't tested the budget, residency or in-place points from my notes: 2 GiB admitted without a reading, no ceiling near full, copies at HIGH residency, and an in-place free while a list or a descriptor slot holds the buffer. They are design questions more than reproduced bugs. --- #3102 and #2993 overlap: two designs for the same feature, and only one can merge. Which one is the maintainer's call. Whichever lands, we'd be glad to help port the fixes and tests above onto it. The title was not used in these tests. AI-assisted
r4tedx commented 2026-11-26 10:05:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-26T09:09:26Z.


Follow-up: I re-ran the tests from my earlier comment on the new head, aab00070 ("title memory outside buffers is in video memory where written copies are").

The tests are rebased onto it at r4tedx/VIctory:repro/3102-findings-2 (head 5ae42265, tests only). That commit lets loose 4 MiB windows be mirrored, so I added loose-window variants of (e), (h) and (f) (copy_of(loose, ..)). The setup is unchanged: WARP, --features diagnostics --test-threads 1, VICTORY_GPU_UPLOAD=1 VICTORY_GPU_UPLOAD_WRITES=1 in a child process, and every test prints gpu_upload_writes true. Your shadow:: tests pass with the two test-only hooks in place: 26 passed, 3 ignored.

finding buffer copy at aab00070 loose window at aab00070
1. failed bring-back still fails, same output new case: fails the same way
2. old unmarked write via snapshot still fails, same output; control (_WRITES=0) passes new case: fails the same way; control passes
3. both switches (diagnostics) still fails, same output the window's mirror is in a GPU upload heap too
4. title write before taken still fails, with and without mirrors (main's window) not tested

The new cases come from the loose windows: until 63ab7631 their copies were in system memory with no mirror, so findings 1 and 2 couldn't apply to them. Now loose goes through copy_buffer(len, false) (shadow.rs:1610), so they get the same mirror and the same paths. The window in the test (0x400000 bytes) has write marks, and its results match a buffer's exactly.

Output at aab00070
1. e_a_failed_bring_back_keeps_the_shaders_writes, e_loose_... (mirror current):
   left: ((8, 8, 8), (33, 33, 90))   right: ((90, 90, 90), (90, 90, 90))
   ..._stale_mirror, e_loose_..._stale_mirror:
   left: ((0, 0, 0), (33, 33, 90))   right: ((90, 90, 90), (90, 90, 90))
   title bytes off the pattern elsewhere: page 0 65273 page 1 0
   (title, mirror, video memory) for the marked page, then the declared range; the shader wrote 0x5a = 90

2. h_an_old_unmarked_write_..._with_mirrors, h_loose_..._with_mirrors:
   left: (170, 187)   right: (119, 187)      title (p+10, p+20) = (0xaa, 0xbb), expected (0x77, 0xbb)
   h_..._in_system_memory, h_loose_..._in_system_memory: ok

3. f_with_both_switches_..._mirror, _kept_copy, f_loose_..._mirror:
   left: ((5, 0), (5, 0))   right: ((4, 3), (4, 3))   (heap type 5 = GPU_UPLOAD; 4/3 = CUSTOM/WRITE_BACK)

4. c_a_title_write_during_a_copy_back_..._with_mirrors and _in_system_memory:
   left: (100, 100, 100)   right: (119, 119, 119)   the next refresh copied 0 bytes

The d_ checks are unchanged: d_refreshes_of_mirrored_copies_reach_video_memory passes, and the mirror-only write stand-in still shows read_host 0xc1 against 0x28 on the GPU side.

The title was not used in these tests.

AI-assisted

<!-- greyfinch-sync:Marvisak/VIctory:comment:7187509663 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102#issuecomment-7187509663). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-26T09:09:26Z. --- Follow-up: I re-ran the tests from my earlier comment on the new head, `aab00070` ("title memory outside buffers is in video memory where written copies are"). The tests are rebased onto it at [`r4tedx/VIctory:repro/3102-findings-2`](https://github.com/r4tedx/VIctory/tree/repro/3102-findings-2) (head `5ae42265`, tests only). That commit lets loose 4 MiB windows be mirrored, so I added loose-window variants of (e), (h) and (f) (`copy_of(loose, ..)`). The setup is unchanged: WARP, `--features diagnostics --test-threads 1`, `VICTORY_GPU_UPLOAD=1 VICTORY_GPU_UPLOAD_WRITES=1` in a child process, and every test prints `gpu_upload_writes true`. Your `shadow::` tests pass with the two test-only hooks in place: 26 passed, 3 ignored. | finding | buffer copy at `aab00070` | loose window at `aab00070` | |---|---|---| | 1. failed bring-back | still fails, same output | **new case:** fails the same way | | 2. old unmarked write via snapshot | still fails, same output; control (`_WRITES=0`) passes | **new case:** fails the same way; control passes | | 3. both switches (diagnostics) | still fails, same output | the window's mirror is in a GPU upload heap too | | 4. title write before `taken` | still fails, with and without mirrors (main's window) | not tested | The new cases come from the loose windows: until `63ab7631` their copies were in system memory with no mirror, so findings 1 and 2 couldn't apply to them. Now `loose` goes through `copy_buffer(len, false)` (`shadow.rs:1610`), so they get the same mirror and the same paths. The window in the test (`0x400000` bytes) has write marks, and its results match a buffer's exactly. <details><summary>Output at aab00070</summary> ``` 1. e_a_failed_bring_back_keeps_the_shaders_writes, e_loose_... (mirror current): left: ((8, 8, 8), (33, 33, 90)) right: ((90, 90, 90), (90, 90, 90)) ..._stale_mirror, e_loose_..._stale_mirror: left: ((0, 0, 0), (33, 33, 90)) right: ((90, 90, 90), (90, 90, 90)) title bytes off the pattern elsewhere: page 0 65273 page 1 0 (title, mirror, video memory) for the marked page, then the declared range; the shader wrote 0x5a = 90 2. h_an_old_unmarked_write_..._with_mirrors, h_loose_..._with_mirrors: left: (170, 187) right: (119, 187) title (p+10, p+20) = (0xaa, 0xbb), expected (0x77, 0xbb) h_..._in_system_memory, h_loose_..._in_system_memory: ok 3. f_with_both_switches_..._mirror, _kept_copy, f_loose_..._mirror: left: ((5, 0), (5, 0)) right: ((4, 3), (4, 3)) (heap type 5 = GPU_UPLOAD; 4/3 = CUSTOM/WRITE_BACK) 4. c_a_title_write_during_a_copy_back_..._with_mirrors and _in_system_memory: left: (100, 100, 100) right: (119, 119, 119) the next refresh copied 0 bytes ``` </details> The `d_` checks are unchanged: `d_refreshes_of_mirrored_copies_reach_video_memory` passes, and the mirror-only write stand-in still shows `read_host` 0xc1 against 0x28 on the GPU side. The title was not used in these tests. AI-assisted
0xKaji commented 2026-11-26 14:01:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-26T13:49:29Z.


Tested on Linux (Wine 11.22 + DXVK + vkd3d-proton, RTX 3060 8 GiB with 8 GiB Resizable BAR, 16 GiB system RAM, GTA VI --console series-s):

  1. DXVK vendor spoofing disables written in VRAM by default: DXVK reports the RTX 3060 as vendor=0x1002 (AMD), so host copies of title buffers in GPU upload heaps logs:
    supported=true vendor=0x1002 read_only=true written=false
    leaving ~3.9 GB of written host copies in system memory with ~4.0 GiB of local VRAM unused.

  2. VICTORY_GPU_UPLOAD_WRITES=1 uses VRAM, but system-memory mirrors still OOM 16 GiB hosts: Forcing VICTORY_GPU_UPLOAD_WRITES=1 cleanly moves ~1.93 GiB into VRAM (local rose from 3,469 to 5,399 MB of 7,445 MB budget, nvidia-smi peak 5,902 MiB), confirming GPU_UPLOAD works under vkd3d-proton. However, because written buffers keep a full system-memory mirror, GPU system memory only dropped from 4,054 to 3,987 MB and process RSS stayed at 14,360 MiB (OOM exit=137 at 87s).

  3. VICTORY_IN_PLACE=1 fallback on page-table activation: With VICTORY_IN_PLACE=1, once title-memory page tables activate, 189 written buffers move back to copies (host copies: 4181 (4018.9 MB), 15,206 MiB RSS → OOM at 88s). By comparison, #2112 avoids those copies/mirrors and reaches frame=1716 without OOM under the same 16 GiB setup.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7193887915 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102#issuecomment-7193887915). Originally posted by [0xKaji](https://github.com/0xKaji) on 2026-11-26T13:49:29Z. --- Tested on Linux (Wine 11.22 + DXVK + vkd3d-proton, RTX 3060 8 GiB with 8 GiB Resizable BAR, 16 GiB system RAM, GTA VI `--console series-s`): 1. **DXVK vendor spoofing disables `written` in VRAM by default:** DXVK reports the RTX 3060 as `vendor=0x1002` (AMD), so `host copies of title buffers in GPU upload heaps` logs: `supported=true vendor=0x1002 read_only=true written=false` leaving ~3.9 GB of written host copies in system memory with ~4.0 GiB of local VRAM unused. 2. **`VICTORY_GPU_UPLOAD_WRITES=1` uses VRAM, but system-memory mirrors still OOM 16 GiB hosts:** Forcing `VICTORY_GPU_UPLOAD_WRITES=1` cleanly moves ~1.93 GiB into VRAM (`local` rose from `3,469` to `5,399 MB` of `7,445 MB` budget, `nvidia-smi` peak `5,902 MiB`), confirming `GPU_UPLOAD` works under vkd3d-proton. However, because written buffers keep a full system-memory mirror, GPU system memory only dropped from `4,054` to `3,987 MB` and process RSS stayed at `14,360 MiB` (OOM `exit=137` at 87s). 3. **`VICTORY_IN_PLACE=1` fallback on page-table activation:** With `VICTORY_IN_PLACE=1`, once title-memory page tables activate, 189 written buffers move back to copies (`host copies: 4181 (4018.9 MB)`, `15,206 MiB` RSS → OOM at 88s). By comparison, `#2112` avoids those copies/mirrors and reaches `frame=1716` without OOM under the same 16 GiB setup.
potatoe0100 commented 2026-11-26 15:02:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by potatoe0100 on 2026-11-26T14:06:53Z.


Benchmark on a narrower link than the 5070 Ti, since NVIDIA gets all copies in video memory by default: RTX 4060 8 GB (Ada, PCIe 4.0 x8, Resizable BAR on, driver 621.14), i5-13600KF, 32 GB, Windows 11 Pro 26300. Head 669f428, cargo test --release -p victory-gpu --lib --locked compute_heavy -- --ignored --nocapture. Each figure is the median of 3 runs (each the median of 5 submissions), in ms per submission. Synthetic only, no game files.

copies writes found by title writes total prepare GPU copy-back
system memory (main) write marks none 160.8 0.0 143.6 19.7
read-only copies in video memory write marks none 71.2 0.0 52.7 19.7
all copies in video memory (NVIDIA default) write marks none 106.5 0.0 78.5 28.7
system memory (main) snapshots none 161.7 18.4 120.2 21.5
read-only copies in video memory snapshots none 70.0 19.6 25.3 21.8
all copies in video memory (NVIDIA default) snapshots none 53.2 18.8 5.5 28.8
title memory in place write marks none 122.0 0.0 121.8 0.1
title memory in place snapshots none 115.4 0.0 115.2 0.1

The "16 MiB per submission" rows track their "none" rows within a few ms. VICTORY_TEST_BENCH_LOOSE=1: system memory 159.2 / 144.0, all copies in video memory 99.5 / 52.4 (write marks / snapshots). Read-only copies in video memory give nothing there, and in place is skipped ("title memory does not open in place here").

What differs from the 5070 Ti numbers:

  • Every video-memory placement still beats main by a wide margin here (−34% to −67%), so the PR helps this card a lot.
  • With write marks, the NVIDIA default (all copies in video memory) is 50% slower than read-only copies only (106.5 vs 71.2 ms). GPU time goes from 52.7 to 78.5 ms and copy-back from 19.7 to 28.7. On the 5070 Ti the two were about even (31.0 vs 31.7 ms in docs/gpu-memory.md). My guess is the system-memory written-pages bitmap that the description mentions (marking about 9 of 11 GPU ms there): over an x8 link, the marks from written copies seem to cost more than video memory saves. #2175 / #2465 would test that.
  • With snapshots, all copies in video memory is the best placement here as well (53.2 ms).
  • Unlike the 7900X's iGPU case, VICTORY_IN_PLACE=1 opened on this discrete card. It sits between system memory and video memory, as on the 5070 Ti.

So on x8 cards the NVIDIA default may want "written copies only with snapshots", or a link-width check. I haven't checked where the link width could be read from D3D12/DXGI. "Making buffers" was 94-110 ms with copies in video memory, against 17-19 in system memory, once per run.

AI-assisted (Claude)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7194296926 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102#issuecomment-7194296926). Originally posted by [potatoe0100](https://github.com/potatoe0100) on 2026-11-26T14:06:53Z. --- Benchmark on a narrower link than the 5070 Ti, since NVIDIA gets all copies in video memory by default: **RTX 4060 8 GB** (Ada, **PCIe 4.0 x8**, Resizable BAR on, driver 621.14), i5-13600KF, 32 GB, Windows 11 Pro 26300. Head `669f428`, `cargo test --release -p victory-gpu --lib --locked compute_heavy -- --ignored --nocapture`. Each figure is the median of 3 runs (each the median of 5 submissions), in ms per submission. Synthetic only, no game files. | copies | writes found by | title writes | total | prepare | GPU | copy-back | |---|---|---|---|---|---|---| | system memory (main) | write marks | none | 160.8 | 0.0 | 143.6 | 19.7 | | read-only copies in video memory | write marks | none | **71.2** | 0.0 | 52.7 | 19.7 | | all copies in video memory (NVIDIA default) | write marks | none | 106.5 | 0.0 | 78.5 | 28.7 | | system memory (main) | snapshots | none | 161.7 | 18.4 | 120.2 | 21.5 | | read-only copies in video memory | snapshots | none | 70.0 | 19.6 | 25.3 | 21.8 | | all copies in video memory (NVIDIA default) | snapshots | none | **53.2** | 18.8 | 5.5 | 28.8 | | title memory in place | write marks | none | 122.0 | 0.0 | 121.8 | 0.1 | | title memory in place | snapshots | none | 115.4 | 0.0 | 115.2 | 0.1 | The "16 MiB per submission" rows track their "none" rows within a few ms. `VICTORY_TEST_BENCH_LOOSE=1`: system memory 159.2 / 144.0, all copies in video memory 99.5 / 52.4 (write marks / snapshots). Read-only copies in video memory give nothing there, and in place is skipped ("title memory does not open in place here"). What differs from the 5070 Ti numbers: - Every video-memory placement still beats `main` by a wide margin here (−34% to −67%), so the PR helps this card a lot. - **With write marks, the NVIDIA default (all copies in video memory) is 50% slower than read-only copies only** (106.5 vs 71.2 ms). GPU time goes from 52.7 to 78.5 ms and copy-back from 19.7 to 28.7. On the 5070 Ti the two were about even (31.0 vs 31.7 ms in `docs/gpu-memory.md`). My guess is the system-memory written-pages bitmap that the description mentions (marking about 9 of 11 GPU ms there): over an x8 link, the marks from written copies seem to cost more than video memory saves. #2175 / #2465 would test that. - With snapshots, all copies in video memory is the best placement here as well (53.2 ms). - Unlike the 7900X's iGPU case, `VICTORY_IN_PLACE=1` opened on this discrete card. It sits between system memory and video memory, as on the 5070 Ti. So on x8 cards the NVIDIA default may want "written copies only with snapshots", or a link-width check. I haven't checked where the link width could be read from D3D12/DXGI. "Making buffers" was 94-110 ms with copies in video memory, against 17-19 in system memory, once per run. AI-assisted (Claude)
latentdev commented 2026-11-26 15:02:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by latentdev on 2026-11-26T14:27:13Z.


In the title on an RTX 4090: no gain while the views' bitmap is in system memory, then GPU time −65 %

The description notes that no title has been run yet, so here is one: aab0007 in the title on an NVIDIA card. In short, the written-pages bitmap your Limits section mentions decides the result here. While it stays in system memory, this PR changes almost nothing. Once it moves to video memory, this PR cuts GPU time by about two thirds.

Setup

  • RTX 4090 (Resizable BAR on; your startup line reports GPU upload heaps supported), driver 621.24.
  • Ryzen 9 7950X3D, 31 GB RAM, Windows 11 26300.
  • Retail 1.0.2.1, Series X profile, diag build, warm shader cache.
  • Scene: the opening cutscene, then the first gameplay.
  • Tree: main 63bcca4 plus what this card needs to draw a lit world: #1630, #1832, #2332, #2178, #2121, #439, #2214, with the structure builder held back.
  • Numbers are medians of the frame-rate lines over the world.
build ms/frame GPU ms preparing ms copy-back ms samples
tree 5,537 4,627 93 80 141
tree + this PR 4,423 4,078 126 94 36
tree + views' bitmap in video memory 745 528 ¹ 105 92 35
tree + bitmap in video memory + this PR + #2821 600–680 141–178 ¹ 133–137 96–102 77 / 40

¹ The 528 and the 178 were measured with VICTORY_GPU_TIMING=1, which runs each list on its own. On this build that adds about a quarter: 178 with it, 141 without.

Why this PR alone barely moves it.

  • Every marked write and every read mark is a load plus an atomic OR on the views' bitmap. That bitmap is a shared_buffer in system memory, so each of them crosses the bus.
  • On this tree that is most of the GPU's time:
    • deferred_tiled:CS_ResetTilesMask (a7eeed0646be1ab7, the clear #2958 measured at 20–41 ms on a 4070 SUPER) took about 1 s per dispatch;
    • full-screen passes took about 100 ms each.
  • #2121's page-read marks add to that traffic here, so a tree without them may show less.

What moved it. I ported wbkepler's #2465 approach onto current main's two bitmaps, read marks included:

  • the bitmap is a DEFAULT-heap UAV buffer;
  • one closed list runs after each submission's lists and copies it into a read-back buffer, then clears it from zeros;
  • the CPU reads and clears the read-back copy as it did the bitmap.

That alone took the GPU from 4.6 s to about 0.5 s per frame. Copies of title buffers in video memory then matter: this PR took it to about 0.15 s.

Same build, this PR's switch only. VICTORY_GPU_UPLOAD=0 gave a median of 1,016 ms on the GPU, against 141–178 ms with the default. That =0 run ended early (9 samples), so treat it as a rough figure.

No device removal attributable to this PR. Several runs ended in 0x887A0005 with empty breadcrumbs. A memory monitor alongside showed the PC out of memory at that moment (commit 50.2 of a 50.5 GB limit, 0.7 GB RAM free). That happened with VICTORY_GPU_UPLOAD=0 too, so it is this 31 GB machine and this tree, not the placement.

Happy to rerun a newer head the same way.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7194842353 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102#issuecomment-7194842353). Originally posted by [latentdev](https://github.com/latentdev) on 2026-11-26T14:27:13Z. --- ### In the title on an RTX 4090: no gain while the views' bitmap is in system memory, then GPU time −65 % The description notes that no title has been run yet, so here is one: aab0007 in the title on an NVIDIA card. In short, the written-pages bitmap your Limits section mentions decides the result here. While it stays in system memory, this PR changes almost nothing. Once it moves to video memory, this PR cuts GPU time by about two thirds. **Setup** - RTX 4090 (Resizable BAR on; your startup line reports GPU upload heaps supported), driver 621.24. - Ryzen 9 7950X3D, 31 GB RAM, Windows 11 26300. - Retail 1.0.2.1, Series X profile, diag build, warm shader cache. - Scene: the opening cutscene, then the first gameplay. - Tree: `main` 63bcca4 plus what this card needs to draw a lit world: #1630, #1832, #2332, #2178, #2121, #439, #2214, with the structure builder held back. - Numbers are medians of the frame-rate lines over the world. | build | ms/frame | GPU ms | preparing ms | copy-back ms | samples | |---|---:|---:|---:|---:|---:| | tree | 5,537 | 4,627 | 93 | 80 | 141 | | tree + this PR | 4,423 | 4,078 | 126 | 94 | 36 | | tree + views' bitmap in video memory | 745 | 528 ¹ | 105 | 92 | 35 | | tree + bitmap in video memory + this PR + #2821 | 600–680 | 141–178 ¹ | 133–137 | 96–102 | 77 / 40 | ¹ The 528 and the 178 were measured with `VICTORY_GPU_TIMING=1`, which runs each list on its own. On this build that adds about a quarter: 178 with it, 141 without. **Why this PR alone barely moves it.** - Every marked write and every read mark is a load plus an atomic OR on the views' bitmap. That bitmap is a `shared_buffer` in system memory, so each of them crosses the bus. - On this tree that is most of the GPU's time: - `deferred_tiled:CS_ResetTilesMask` (`a7eeed0646be1ab7`, the clear #2958 measured at 20–41 ms on a 4070 SUPER) took about 1 s per dispatch; - full-screen passes took about 100 ms each. - #2121's page-read marks add to that traffic here, so a tree without them may show less. **What moved it.** I ported wbkepler's #2465 approach onto current main's two bitmaps, read marks included: - the bitmap is a `DEFAULT`-heap UAV buffer; - one closed list runs after each submission's lists and copies it into a read-back buffer, then clears it from zeros; - the CPU reads and clears the read-back copy as it did the bitmap. That alone took the GPU from 4.6 s to about 0.5 s per frame. Copies of title buffers in video memory then matter: this PR took it to about 0.15 s. **Same build, this PR's switch only.** `VICTORY_GPU_UPLOAD=0` gave a median of 1,016 ms on the GPU, against 141–178 ms with the default. That `=0` run ended early (9 samples), so treat it as a rough figure. **No device removal attributable to this PR.** Several runs ended in `0x887A0005` with empty breadcrumbs. A memory monitor alongside showed the PC out of memory at that moment (commit 50.2 of a 50.5 GB limit, 0.7 GB RAM free). That happened with `VICTORY_GPU_UPLOAD=0` too, so it is this 31 GB machine and this tree, not the placement. Happy to rerun a newer head the same way.
0xkn0wh3r3 commented 2026-11-26 17:58:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T17:58:44Z.


Thanks for the careful repros. Findings 1–3 are fixed in 669f428a, with new tests of our own that cover buffers' copies and loose windows:

  1. Failed bring-back. copy_now now returns whether it saw its fence reached on a live device. It doesn't reuse the allocator until the earlier fence is reached. When a copy fails, bring_back reads the pages through the CPU's mapping of video memory, so the mirror still gets the shaders' writes and the copy-back compares against them. Written copies made after a failure stay in system memory. Test: a_failed_copy_back_from_video_memory_loses_no_shader_writes (a marked page, a declared range and a loose window, with the mirrors stale).
  2. Old unmarked write. snapshots_ahead brings the declared ranges back whole, not only their stale pages. On the 5070 Ti bench that costs about 2 ms per submission in the snapshot rows, which are still −47% against main. Test: an_earlier_undeclared_shader_write_does_not_reach_title_memory_late.
  3. Diagnostics switch. VICTORY_COPIES_IN_VIDEO_MEMORY no longer overrides shared buffers. It now places read-only and written copies in video memory the way the placements do, with written copies keeping their mirrors, so mirrors, the marks bitmap and kept copies stay in CUSTOM write-back memory. Test: with_copies_in_video_memory_the_cpu_sides_stay_in_system_memory.

Finding 4 is main's existing window, so I've listed it under Limits rather than fixing it here.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7199913405 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102#issuecomment-7199913405). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T17:58:44Z. --- Thanks for the careful repros. Findings 1–3 are fixed in 669f428a, with new tests of our own that cover buffers' copies and loose windows: 1. **Failed bring-back.** `copy_now` now returns whether it saw its fence reached on a live device. It doesn't reuse the allocator until the earlier fence is reached. When a copy fails, `bring_back` reads the pages through the CPU's mapping of video memory, so the mirror still gets the shaders' writes and the copy-back compares against them. Written copies made after a failure stay in system memory. Test: `a_failed_copy_back_from_video_memory_loses_no_shader_writes` (a marked page, a declared range and a loose window, with the mirrors stale). 2. **Old unmarked write.** `snapshots_ahead` brings the declared ranges back whole, not only their stale pages. On the 5070 Ti bench that costs about 2 ms per submission in the snapshot rows, which are still −47% against main. Test: `an_earlier_undeclared_shader_write_does_not_reach_title_memory_late`. 3. **Diagnostics switch.** `VICTORY_COPIES_IN_VIDEO_MEMORY` no longer overrides shared buffers. It now places read-only and written copies in video memory the way the placements do, with written copies keeping their mirrors, so mirrors, the marks bitmap and kept copies stay in CUSTOM write-back memory. Test: `with_copies_in_video_memory_the_cpu_sides_stay_in_system_memory`. Finding 4 is main's existing window, so I've listed it under Limits rather than fixing it here.
zed6000 commented 2026-11-26 17:59:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by zed6000 on 2026-11-26T17:59:42Z.


In the title on AMD (RX 7900 XTX): no gain in the intro, by default or with written copies in video memory.

Setup: RX 7900 XTX 24 GB (RDNA3, Resizable BAR; the startup line reports supported=true vendor=0x1002), driver 32.0.32029.2010, Ryzen 9 7900X3D, 95 GB, Windows 11 26200. Base: main 63bcca4 + the #1247 shader stack + #2703, which leave 0 dropped draws in this scene. This PR at 669f428 merged onto that base (clean). Diag build, Series X profile, warm caches, VICTORY_KEYS into the intro cutscene. Medians of 36 frame-rate lines under 10 fps (about 3 minutes), the same method as my copy-PR table on #400.

build fps ms/frame preparing (copies) on the GPU copying back video memory at the end
base 2.4 415 199 (94 ms, 480 MB) 151 58
+ this PR, default (read_only=true written=false) 2.3 431 201 (95 ms, 486 MB) 154 61 12.8 GB
+ this PR, VICTORY_GPU_UPLOAD_WRITES=1 (written=true) 2.3 438 199 (86 ms, 467 MB) 138 78 18.4 GB
  • With written copies in video memory the GPU saves about 13 ms a frame, but copying back grows by about 19 ms, so the frame is a little slower. That matches your RX 9070 XT note, and the AMD default of written=false looks right for this card.
  • No dropped draws, no new warnings, no device removal in either run. The black-frame warnings at boot are the same as on the base.
  • On this tree the GPU's 150 ms is spread over thousands of commands (heaviest pipeline 8.5 ms/frame; see #400). So it is not dominated by the bitmap traffic latentdev measured on the 4090 tree, which may be why the placement changes little here.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7199931278 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102#issuecomment-7199931278). Originally posted by [zed6000](https://github.com/zed6000) on 2026-11-26T17:59:42Z. --- **In the title on AMD (RX 7900 XTX): no gain in the intro, by default or with written copies in video memory.** **Setup:** RX 7900 XTX 24 GB (RDNA3, Resizable BAR; the startup line reports `supported=true vendor=0x1002`), driver 32.0.32029.2010, Ryzen 9 7900X3D, 95 GB, Windows 11 26200. Base: `main` `63bcca4` + the #1247 shader stack + #2703, which leave **0 dropped draws** in this scene. This PR at `669f428` merged onto that base (clean). Diag build, Series X profile, warm caches, `VICTORY_KEYS` into the intro cutscene. Medians of 36 frame-rate lines under 10 fps (about 3 minutes), the same method as my copy-PR table on #400. | build | fps | ms/frame | preparing (copies) | on the GPU | copying back | video memory at the end | |---|---:|---:|---|---:|---:|---:| | base | 2.4 | 415 | 199 (94 ms, 480 MB) | 151 | 58 | | | + this PR, default (`read_only=true written=false`) | 2.3 | 431 | 201 (95 ms, 486 MB) | 154 | 61 | 12.8 GB | | + this PR, `VICTORY_GPU_UPLOAD_WRITES=1` (`written=true`) | 2.3 | 438 | 199 (86 ms, 467 MB) | **138** | **78** | 18.4 GB | - With written copies in video memory the GPU saves about 13 ms a frame, but copying back grows by about 19 ms, so the frame is a little slower. That matches your RX 9070 XT note, and the AMD default of `written=false` looks right for this card. - No dropped draws, no new warnings, no device removal in either run. The black-frame warnings at boot are the same as on the base. - On this tree the GPU's 150 ms is spread over thousands of commands (heaviest pipeline 8.5 ms/frame; see #400). So it is not dominated by the bitmap traffic latentdev measured on the 4090 tree, which may be why the placement changes little here.
0xkn0wh3r3 commented 2026-11-26 18:41:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T18:41:59Z.


Thanks for running this in the title. It's the first run of #3102 outside synthetic tests. The RX 7900 XTX result matches the RX 9070 XT: written copies in video memory save GPU time, but the mirrors' copy-back costs more, so they stay NVIDIA-only by default. I've added your numbers to the description's results and limits.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7200754026 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3102#issuecomment-7200754026). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T18:41:59Z. --- Thanks for running this in the title. It's the first run of #3102 outside synthetic tests. The RX 7900 XTX result matches the RX 9070 XT: written copies in video memory save GPU time, but the mirrors' copy-back costs more, so they stay NVIDIA-only by default. I've added your numbers to the description's results and limits.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3102:upstream-pr/3102'
git switch 'upstream-pr/3102'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3102'
git switch 'upstream-pr/3102'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3102'
git switch 'upstream-pr/3102'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3102'
git switch 'main'
git merge --squash 'upstream-pr/3102'
git switch 'main'
git merge --ff-only 'upstream-pr/3102'
git switch 'main'
git merge 'upstream-pr/3102'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3100
No description provided.