GPU: host copies of title buffers in video memory, under a DXGI budget (opt-in) #2993

Open
github-bot wants to merge 4 commits from github-bot/gh-2993 into main AGit
Owner

@⁠r4tedx on GitHub · 2026-11-26 02:38 UTC · original
r4tedx:mem/vram-copies-main → main · +1977 −49 · 7 files · 4 commits · open

What it changes

Off by default. Without the switch, no code path changes.

  • Where shaders read. With VICTORY_VRAM_COPIES=1, the host copy of a title buffer made without unordered access gets a second buffer in video memory: a GPU upload heap, which the CPU maps through the PCI BAR. It is used only when D3D12_OPTIONS16.GPUUploadHeapSupported is set (Resizable BAR). Shaders, views, root descriptors and page tables use that buffer. With =2, copies of buffers that shaders may write get one too. Loose windows and the copies of single views stay in system memory.

  • The CPU's side stays in system memory, always. The system memory buffer that main has today is kept for every copy. The CPU reads only that buffer (snapshots, page compares, copy-backs). Every CPU write into the copy goes there first and then into video memory:

    • refreshes, including those under a range a submitted list declared;
    • the zeros of unmapped pages;
    • copy-back merges.
  • The CPU never reads video memory. The BAR mapping is a vram::WriteOnly, a type with only a write method and private fields, so no code outside vram.rs can read through it. A CPU read of a BAR runs at about 50 MB/s (#2120's table).

  • Shader writes come back through main's page marks. After a submission's GPU work, and before any copy-back reads a copy, one GPU copy brings into the system memory side:

    • the ranges its lists declared unmarked (snapshot ranges), withheld ones too. Main compares these whole, so they come back whole;
    • the pages marked in either written-pages bitmap, held-back ones too.

    Ranges declared marked (views that mark their writes, root UAVs of marked copies) do not come back whole. The CPU reads nothing in them but their marked pages. Pages written at computed addresses (memory.rs) are brought back the same way before their copy-back. The copy-backs then run main's code unchanged: compare, write the changed bytes into title memory, take the page again. The system memory side then matches the GPU side wherever shaders wrote, withheld writes included.

  • The order of a copy-back. The order is: bring back, merge and write, take the page again, read the page from title memory once more, then write video memory. A title write that lands after the page went back and before its guard is back is in that last read. A write after the guard faults and marks the page changed. If video memory were written before the read, it would miss such a write for good, because the page counts as current. For copies in system memory, nothing changes.

  • Admission through the DXGI budget. QueryVideoMemoryInfo (local segment) is asked at most every 250 ms. Bytes taken since the last reading count as used. A copy goes to video memory only when:

    • copies there stay within the cap: a quarter of the budget (VICTORY_VRAM_COPIES_MB sets it by hand), and never more than what the rest of the process leaves under 85 % of the budget. The cap shrinks as textures, render targets and depth buffers fill the card;
    • use stays under 85 % of the budget;
    • use has not passed 85 % since it was last under 75 %. Near a full budget, room a texture gives back is soon taken again;
    • there is a reading at all.

    Admission and charge happen under one lock. A copy's bytes go back when D3D12 destroys its buffer (ID3DDestructionNotifier), because lists and heap slots can hold the buffer after the copy is gone.

  • Copies yield to textures past the budget. Each buffer in video memory gets D3D12_RESIDENCY_PRIORITY_LOW. Copies are made early, before most textures; in the title run they took 1.2 GB at 54 % of the budget, and textures then took the card to 95 %. Past the budget, the system moves our copies to system memory first. Shaders then read them across the bus, as they read a system copy. The title's textures (normal), render targets and depth buffers (high on play/main) stay. The buffer and its GPU address do not change.

  • Past the cap, a copy stays in system memory. It is a plain copy on main's path, with main's tests. It loses no writes, because nothing about it differs from main.

Files: vram.rs (new: switch, WriteOnly, budget, buffer creation, the line under diagnostics); shadow.rs (the video memory side, put/settle, pull_written/pull; device-removed reports say when the nearest copy's GPU side is in video memory); host.rs (mapped_buffer, copy_now, memory_info, the bring-back before copy_back_marks); memory.rs (the bring-back before computed-address copy-backs); resource.rs (read-only buffers registered as such).

Switches

switch effect
VICTORY_VRAM_COPIES=1 copies of buffers made without unordered access go to video memory
VICTORY_VRAM_COPIES=2 copies of every title buffer do
VICTORY_VRAM_COPIES_MB=N cap of N MB in place of a quarter of the budget

Unset or 0: off. With --features diagnostics, a line per stats interval reports:

host copies in video memory: N of read-only buffers (MB), N of written ones (MB), MB in all (cap now MB; card MB of MB[, past 85 %: admitting none]); refused for the budget N (MB); shaders' writes brought back MB/frame in N GPU copies/frame (declared ranges, marked pages, computed-address pages MB/frame)

"cap now" is the cap after the margin. The three parts are counted before runs of one copy that meet are joined, so they can add up to more than the total.

Limits

  • Twice the memory for each copy in video memory. The system memory side is kept in full. The extra RAM was accepted for this design: it keeps the CPU off the BAR and makes falling back free.
  • Refreshes write twice. One write goes to system memory and one to the BAR, about 22.7 GB/s on a 5070 Ti per #2120. A lazy CPU side, as in #2130's mirror, would avoid the second write but adds stale-page tracking on every CPU read. That is left for a later change, if a title run shows refresh time matters.
  • One GPU copy per submission that wrote copies in video memory. It costs a fixed ~0.05 ms (copy_now's signal and wait; #2130 measured 1 page in 0.048 ms and 64 pages in 0.232 ms) plus the bytes.
  • Admission only. Nothing is moved out of video memory when the budget shrinks later. Placement is decided once, when the copy is made. Past the budget, the low residency priority lets the system demote copies before textures (not measured on hardware yet).
  • Undeclared, unmarked shader writes stay on the GPU side, as they stay in the copy on main, until a refresh of their page.
  • Not built on #2051. #2051 (refreshes on several threads) is not on main. Its queued refresh copies must call Shadow::copy, or write through put, to reach video memory. A refresh that wrote only the system memory side was the bug the rebase onto #2130 found.

Tests (WARP, --features diagnostics)

Each test below re-runs itself in a child process with VICTORY_VRAM_COPIES set, because the switch is read once per process. It asserts the class it expects, so it cannot pass by skipping. The parent checks that the child ran 1 test.

The software adapter here does report GPUUploadHeapSupported, so the tests use real GPU upload heaps. For hosts without them, and with VICTORY_TEST_VRAM_STAND_IN=1, the tests use a write-combined CUSTOM heap that the CPU maps in their place, so the same code runs either way. W0 prints which heap it used.

  • copies_in_video_memory_are_made_charged_and_given_back (W0): a read-only buffer's copy is VramRead and a written one's is VramWritten. Their GPU sides are in the video memory heap and the CPU side is in system memory. Both are charged. A clone of a buffer, as heap slots hold, keeps its bytes charged. The bytes go back when the clone goes.

  • copies_past_the_cap_stay_in_system_memory_and_lose_no_writes (#693, Belobug #105): with a faked 64 MiB budget, 4 copies of 4 MiB go to video memory and the fifth stays in system memory. With faked use near the budget, a sixth stays too, and 2 refusals are counted. A submission's shaders then write into two copies in video memory and two in system memory, one marked and one declared (snapshot) of each. All four writes reach title memory.

  • refreshes_of_copies_in_video_memory_reach_video_memory: what the GPU reads matches the title's bytes after the first refresh, after a title write, and under a range a list declared as written by shaders.

  • shader_writes_into_copies_in_video_memory_come_back: a read-only buffer's copy is written by shaders anyway, through a view that writes. A marked page and a declared range go back by the bytes the GPU changed, brought back by a GPU copy (counted). A title write in the marked page during the submission stays, and is in both sides afterwards.

  • a_title_write_during_a_copy_back_reaches_video_memory (the order): a test hook writes title memory between a marked page's copy-back write and the page being taken again. The page is then current, so no refresh brings the write. Video memory has it.

  • copies_go_to_video_memory_within_the_cap_and_the_budget (no GPU): the admission rule, including #693's numbers (19,042 MB of a 10,570 MB budget: not even one page).

  • a_copy_in_video_memory_takes_no_more_dynamic_slots_than_one_in_system_memory (draw.rs): one copy is admitted (VramRead), the next is refused (System). Over 8 submissions each list takes the same dynamic slots for root views of either: read and written, at two addresses, one view per copy and kind. The copy in video memory keeps the buffer and GPU address it was made with.

  • marked_ranges_of_copies_in_video_memory_come_back_by_their_marked_pages: a range declared marked comes back as its one marked page (64 KiB of 256), and an unmarked range comes back whole, once. Both are counted by why.

  • the_cap_shrinks_as_the_card_fills_and_copies_wait_near_a_full_budget (no GPU): the title run's numbers. The cap is a quarter of the budget at first. With 9,800 MB used by others, under 118 MB is left. At the run's end (11,063 of 11,668 MB) nothing is admitted. At 80 % still nothing, after passing 85 %. Under 75 % copies are admitted again.

Results on this head (1cf4dac8, on main 63bcca43; VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1):

  • With VICTORY_VRAM_COPIES unset: 255 passed / 0 failed / 1 ignored (main 63bcca43 in the same worktree: 246 / 0 / 1). The new tests set the switch in their child processes.
  • Clippy --all-targets -D warnings is clean with and without --all-features.
  • With VICTORY_VRAM_COPIES=2 set for the whole suite, 9 of main's in-process tests fail (bindless::tests::heap_views_are_current, heap_views_follow_writes_through_another_mapping, draw::tests::root_views_reach_their_copy_and_read_zeros_past_it, five shadow::tests on marks and snapshots, and #2377's new partial_refresh_under_marked_range_updates_saved_bytes). They write the GPU side through write_host and then call copy-back directly, without the post-submission bring-back (pull_written) the real path runs, so they read zeros. Eight fail the same way before the rebase. If wanted, these tests can skip, or call pull_written, when the process-wide switch is set.
  • The rebase met two of main's changes: Shadow::update_free became update_tracked (#2172), so the video memory write after zeroing unmapped pages moved into its unmapped loop; and Shadow::copy now calls Tracked::refreshed (#2377), kept, followed by the video memory write.

Earlier, on the pre-rebase branch (mem/vram-copies 72338fe6, main 13f91cae): 207 / 0 / 1, and the play/main port (82c8382b): 289 / 0 / 10.

  • An existing test fails now and then in the full suite, on main as well. memory::tests::a_submission_that_missed_leaves_the_copies_at_once ("the written page counts as changed at once") failed:

    • in 3 of 5 suite runs on this branch, one of them with the five new child-process tests skipped;
    • in 1 of 3 suite runs on main 13f91cae, in the same worktree and conditions (descriptor::host::tests::a_slot_rewritten_while_its_view_is_prepared_views_the_new_record failed in another).

    It passed 3 of 3 run alone. Another test's submission can refresh the shared copy between its read_host and its clean() check, so it is a race in the test, not something this PR changes.

What a title run should show

Compare the same save and camera, VICTORY_GPU_TIMING=1, with --features diagnostics, in three runs: off, =1, and =2. Expected:

  • GPU ms/frame drops with =1 (vertex, index and constant data) and more with =2 (heaps the shaders write).
    • #2120's synthetic read: 31x faster on a 5070 Ti.
    • The #2130 title run on a 5090 (wbkepler): GPU 316-332 → 100-103 ms.
  • VRAM MB: the host copies in video memory line gives MB held and the cap. The video memory: line stays under the budget.
  • No device removal.
  • Copy-back ms rises a little (one GPU copy per writing submission). Preparing ms rises by the second write of refreshed bytes.

Game results

Local runs on an RTX 5070 (12 GB, Windows 11), the same open-world save, about 10 minutes of world each, diagnostics builds. The title's own data was used in these runs; only counts and timings from the logs are given here. The play builds also carry other open PRs and our own fixes not yet upstream (a dynamic descriptor pool fix, bounded list memory and others), so these numbers show this change against the same build without it, not main as is. All arms below: 0 device removals.

Against the same build with the switch off (DP1 → VC2; play/main-vram 82c8382b, VICTORY_VRAM_COPIES off vs =2, batched clamps off in both):

off =2
median frame time, difference (95 % CI) −64 .. −127 ms
mean frame time 910 ms 817 ms
GPU / preparing / copy-back ms per frame 316 / 295 / 121 216 / 268 / 130
drops per frame: no host pipeline / indirect 565 / 472 417 / 205

Copies in video memory: 1,231 MB (203 read-only + 1,028 written). The 85 % stop held the card at 90 % of the budget ("past 85 %: admitting none"). Shaders' writes brought back: 81 MB/frame in 20 GPU copies, marked pages only.

Against #2130's GPU upload heaps, on one build (N2U → N2P; play/main-next-2 deeb5939, which carries both; N2U: VICTORY_GPU_UPLOAD=1 + _WRITES=1, this switch off; N2P: VICTORY_VRAM_COPIES=2, the upload heaps off):

upload heaps (#2130) =2 (this PR)
median frame time, difference (95 % CI) −50 .. −96 ms
mean / p50 / p95 frame time 838 / 762 / 1,399 ms 746 / 692 / 930 ms
GPU / preparing / copy-back ms per frame 126 / 283 / 133 123 / 268 / 133
drops per frame: no host pipeline / indirect 389 / 108 382 / 99

The GPU time is about the same either way. The difference is in fewer long frames: the 95th percentile falls from 1,399 to 930 ms.

Against the same build without any GPU placement (BM1 → N2P): median −7 .. −36 ms (95 % CI); GPU 227 → 123 ms per frame; preparing 227 → 268 ms. Preparing eats most of the GPU gain. Part of it is the second write of refreshed bytes and the bring-backs listed under Limits.

Earlier runs of this change (VB and VC, before the fix) were cut short by the memory guard, because of a host upload-buffer growth unrelated to this change (fixed separately since), and their pool drops confounded the frame times. They are left out here.

Credit

  • 0xkn0wh3r3, #2120 and #2130: copies in GPU upload heaps, read-only buffers registered by their flags, the destruction-callback charge, copy_now (ported, co-author on the commit), and the child-process test pattern.
  • #2222 (0xkn0wh3r3): the idea of sizing the copies by the DXGI budget and charging bytes between readings. The budget code here is our own.
  • wbkepler, #693: the over-budget evidence (an RTX 5070: 19 GB of a 10.5 GB budget, then a TDR).
  • Belobug #105: the copies past a cap that lost their writes.

Overlap

This PR overlaps #2120, #2130 and #2222 (0xkn0wh3r3) directly:

  • Its read-only half does what #2120 does.
  • Its written half does what #2130 does, with a different system memory side: always current and always kept, against #2130's lazy mirror.
  • Its admission covers what #2222's upload pool does for copies.

#2222's residency priorities and render-target demotion are not here. If the maintainer prefers 0xkn0wh3r3's PRs, the parts of this one that stand on their own are:

  • the write-only mapping type;
  • every CPU write going through one path to video memory;
  • the ordering rule and its test;
  • the WARP stand-in heap with the child-process tests.

They can go there as suggested commits. #2389 (desplmfao, texture levels on demand) is separate and makes room for these copies on 12 GB cards.

The tests above are synthetic and do not use the title. The game results use local title data, as stated in their section.

AI-assisted

🤖 Generated with Claude Code

**@⁠r4tedx** on GitHub · 2026-11-26 02:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2993) `r4tedx:mem/vram-copies-main` → `main` · +1977 −49 · 7 files · 4 commits · open ### What it changes Off by default. Without the switch, no code path changes. - **Where shaders read.** With `VICTORY_VRAM_COPIES=1`, the host copy of a title buffer made without unordered access gets a second buffer in video memory: a GPU upload heap, which the CPU maps through the PCI BAR. It is used only when `D3D12_OPTIONS16.GPUUploadHeapSupported` is set (Resizable BAR). Shaders, views, root descriptors and page tables use that buffer. With `=2`, copies of buffers that shaders may write get one too. Loose windows and the copies of single views stay in system memory. - **The CPU's side stays in system memory, always.** The system memory buffer that main has today is kept for every copy. The CPU reads only that buffer (snapshots, page compares, copy-backs). Every CPU write into the copy goes there first and then into video memory: - refreshes, including those under a range a submitted list declared; - the zeros of unmapped pages; - copy-back merges. - **The CPU never reads video memory.** The BAR mapping is a `vram::WriteOnly`, a type with only a `write` method and private fields, so no code outside `vram.rs` can read through it. A CPU read of a BAR runs at about 50 MB/s (#2120's table). - **Shader writes come back through main's page marks.** After a submission's GPU work, and before any copy-back reads a copy, one GPU copy brings into the system memory side: - the ranges its lists declared unmarked (snapshot ranges), withheld ones too. Main compares these whole, so they come back whole; - the pages marked in either written-pages bitmap, held-back ones too. Ranges declared marked (views that mark their writes, root UAVs of marked copies) do not come back whole. The CPU reads nothing in them but their marked pages. Pages written at computed addresses (`memory.rs`) are brought back the same way before their copy-back. The copy-backs then run main's code unchanged: compare, write the changed bytes into title memory, take the page again. The system memory side then matches the GPU side wherever shaders wrote, withheld writes included. - **The order of a copy-back.** The order is: bring back, merge and write, take the page again, read the page from title memory once more, then write video memory. A title write that lands after the page went back and before its guard is back is in that last read. A write after the guard faults and marks the page changed. If video memory were written before the read, it would miss such a write for good, because the page counts as current. For copies in system memory, nothing changes. - **Admission through the DXGI budget.** `QueryVideoMemoryInfo` (local segment) is asked at most every 250 ms. Bytes taken since the last reading count as used. A copy goes to video memory only when: - copies there stay within the cap: a quarter of the budget (`VICTORY_VRAM_COPIES_MB` sets it by hand), and never more than what the rest of the process leaves under 85 % of the budget. The cap shrinks as textures, render targets and depth buffers fill the card; - use stays under 85 % of the budget; - use has not passed 85 % since it was last under 75 %. Near a full budget, room a texture gives back is soon taken again; - there is a reading at all. Admission and charge happen under one lock. A copy's bytes go back when D3D12 destroys its buffer (`ID3DDestructionNotifier`), because lists and heap slots can hold the buffer after the copy is gone. - **Copies yield to textures past the budget.** Each buffer in video memory gets `D3D12_RESIDENCY_PRIORITY_LOW`. Copies are made early, before most textures; in the title run they took 1.2 GB at 54 % of the budget, and textures then took the card to 95 %. Past the budget, the system moves our copies to system memory first. Shaders then read them across the bus, as they read a system copy. The title's textures (normal), render targets and depth buffers (high on play/main) stay. The buffer and its GPU address do not change. - **Past the cap, a copy stays in system memory.** It is a plain copy on main's path, with main's tests. It loses no writes, because nothing about it differs from main. Files: `vram.rs` (new: switch, `WriteOnly`, budget, buffer creation, the line under `diagnostics`); `shadow.rs` (the video memory side, `put`/`settle`, `pull_written`/`pull`; device-removed reports say when the nearest copy's GPU side is in video memory); `host.rs` (`mapped_buffer`, `copy_now`, `memory_info`, the bring-back before `copy_back_marks`); `memory.rs` (the bring-back before computed-address copy-backs); `resource.rs` (read-only buffers registered as such). ### Switches | switch | effect | |---|---| | `VICTORY_VRAM_COPIES=1` | copies of buffers made without unordered access go to video memory | | `VICTORY_VRAM_COPIES=2` | copies of every title buffer do | | `VICTORY_VRAM_COPIES_MB=N` | cap of N MB in place of a quarter of the budget | Unset or `0`: off. With `--features diagnostics`, a line per stats interval reports: `host copies in video memory: N of read-only buffers (MB), N of written ones (MB), MB in all (cap now MB; card MB of MB[, past 85 %: admitting none]); refused for the budget N (MB); shaders' writes brought back MB/frame in N GPU copies/frame (declared ranges, marked pages, computed-address pages MB/frame)` "cap now" is the cap after the margin. The three parts are counted before runs of one copy that meet are joined, so they can add up to more than the total. ### Limits - **Twice the memory for each copy in video memory.** The system memory side is kept in full. The extra RAM was accepted for this design: it keeps the CPU off the BAR and makes falling back free. - **Refreshes write twice.** One write goes to system memory and one to the BAR, about 22.7 GB/s on a 5070 Ti per #2120. A lazy CPU side, as in #2130's mirror, would avoid the second write but adds stale-page tracking on every CPU read. That is left for a later change, if a title run shows refresh time matters. - **One GPU copy per submission that wrote copies in video memory.** It costs a fixed ~0.05 ms (`copy_now`'s signal and wait; #2130 measured 1 page in 0.048 ms and 64 pages in 0.232 ms) plus the bytes. - **Admission only.** Nothing is moved out of video memory when the budget shrinks later. Placement is decided once, when the copy is made. Past the budget, the low residency priority lets the system demote copies before textures (not measured on hardware yet). - **Undeclared, unmarked shader writes stay on the GPU side**, as they stay in the copy on main, until a refresh of their page. - **Not built on #2051.** #2051 (refreshes on several threads) is not on main. Its queued refresh copies must call `Shadow::copy`, or write through `put`, to reach video memory. A refresh that wrote only the system memory side was the bug the rebase onto #2130 found. ### Tests (WARP, `--features diagnostics`) Each test below re-runs itself in a child process with `VICTORY_VRAM_COPIES` set, because the switch is read once per process. It asserts the class it expects, so it cannot pass by skipping. The parent checks that the child ran 1 test. The software adapter here does report `GPUUploadHeapSupported`, so the tests use real GPU upload heaps. For hosts without them, and with `VICTORY_TEST_VRAM_STAND_IN=1`, the tests use a write-combined CUSTOM heap that the CPU maps in their place, so the same code runs either way. W0 prints which heap it used. - `copies_in_video_memory_are_made_charged_and_given_back` (W0): a read-only buffer's copy is `VramRead` and a written one's is `VramWritten`. Their GPU sides are in the video memory heap and the CPU side is in system memory. Both are charged. A clone of a buffer, as heap slots hold, keeps its bytes charged. The bytes go back when the clone goes. - `copies_past_the_cap_stay_in_system_memory_and_lose_no_writes` (#693, Belobug #105): with a faked 64 MiB budget, 4 copies of 4 MiB go to video memory and the fifth stays in system memory. With faked use near the budget, a sixth stays too, and 2 refusals are counted. A submission's shaders then write into two copies in video memory and two in system memory, one marked and one declared (snapshot) of each. All four writes reach title memory. - `refreshes_of_copies_in_video_memory_reach_video_memory`: what the GPU reads matches the title's bytes after the first refresh, after a title write, and under a range a list declared as written by shaders. - `shader_writes_into_copies_in_video_memory_come_back`: a read-only buffer's copy is written by shaders anyway, through a view that writes. A marked page and a declared range go back by the bytes the GPU changed, brought back by a GPU copy (counted). A title write in the marked page during the submission stays, and is in both sides afterwards. - `a_title_write_during_a_copy_back_reaches_video_memory` (the order): a test hook writes title memory between a marked page's copy-back write and the page being taken again. The page is then current, so no refresh brings the write. Video memory has it. - `copies_go_to_video_memory_within_the_cap_and_the_budget` (no GPU): the admission rule, including #693's numbers (19,042 MB of a 10,570 MB budget: not even one page). - `a_copy_in_video_memory_takes_no_more_dynamic_slots_than_one_in_system_memory` (`draw.rs`): one copy is admitted (`VramRead`), the next is refused (System). Over 8 submissions each list takes the same dynamic slots for root views of either: read and written, at two addresses, one view per copy and kind. The copy in video memory keeps the buffer and GPU address it was made with. - `marked_ranges_of_copies_in_video_memory_come_back_by_their_marked_pages`: a range declared marked comes back as its one marked page (64 KiB of 256), and an unmarked range comes back whole, once. Both are counted by why. - `the_cap_shrinks_as_the_card_fills_and_copies_wait_near_a_full_budget` (no GPU): the title run's numbers. The cap is a quarter of the budget at first. With 9,800 MB used by others, under 118 MB is left. At the run's end (11,063 of 11,668 MB) nothing is admitted. At 80 % still nothing, after passing 85 %. Under 75 % copies are admitted again. Results on this head (1cf4dac8, on `main` 63bcca43; `VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1`): - With `VICTORY_VRAM_COPIES` unset: 255 passed / 0 failed / 1 ignored (`main` 63bcca43 in the same worktree: 246 / 0 / 1). The new tests set the switch in their child processes. - Clippy `--all-targets -D warnings` is clean with and without `--all-features`. - With `VICTORY_VRAM_COPIES=2` set for the whole suite, 9 of main's in-process tests fail (`bindless::tests::heap_views_are_current`, `heap_views_follow_writes_through_another_mapping`, `draw::tests::root_views_reach_their_copy_and_read_zeros_past_it`, five `shadow::tests` on marks and snapshots, and #2377's new `partial_refresh_under_marked_range_updates_saved_bytes`). They write the GPU side through `write_host` and then call copy-back directly, without the post-submission bring-back (`pull_written`) the real path runs, so they read zeros. Eight fail the same way before the rebase. If wanted, these tests can skip, or call `pull_written`, when the process-wide switch is set. - The rebase met two of main's changes: `Shadow::update_free` became `update_tracked` (#2172), so the video memory write after zeroing unmapped pages moved into its unmapped loop; and `Shadow::copy` now calls `Tracked::refreshed` (#2377), kept, followed by the video memory write. Earlier, on the pre-rebase branch (mem/vram-copies 72338fe6, `main` 13f91cae): 207 / 0 / 1, and the play/main port (82c8382b): 289 / 0 / 10. - An existing test fails now and then in the full suite, on main as well. `memory::tests::a_submission_that_missed_leaves_the_copies_at_once` ("the written page counts as changed at once") failed: - in 3 of 5 suite runs on this branch, one of them with the five new child-process tests skipped; - in 1 of 3 suite runs on main 13f91cae, in the same worktree and conditions (`descriptor::host::tests::a_slot_rewritten_while_its_view_is_prepared_views_the_new_record` failed in another). It passed 3 of 3 run alone. Another test's submission can refresh the shared copy between its `read_host` and its `clean()` check, so it is a race in the test, not something this PR changes. ### What a title run should show Compare the same save and camera, `VICTORY_GPU_TIMING=1`, with `--features diagnostics`, in three runs: off, `=1`, and `=2`. Expected: - **GPU ms/frame** drops with `=1` (vertex, index and constant data) and more with `=2` (heaps the shaders write). - #2120's synthetic read: 31x faster on a 5070 Ti. - The #2130 title run on a 5090 (wbkepler): GPU 316-332 → 100-103 ms. - **VRAM MB:** the `host copies in video memory` line gives MB held and the cap. The `video memory:` line stays under the budget. - **No device removal.** - **Copy-back ms** rises a little (one GPU copy per writing submission). **Preparing ms** rises by the second write of refreshed bytes. ### Game results Local runs on an RTX 5070 (12 GB, Windows 11), the same open-world save, about 10 minutes of world each, diagnostics builds. **The title's own data was used in these runs; only counts and timings from the logs are given here.** The play builds also carry other open PRs and our own fixes not yet upstream (a dynamic descriptor pool fix, bounded list memory and others), so these numbers show this change against the same build without it, not `main` as is. All arms below: 0 device removals. **Against the same build with the switch off** (DP1 → VC2; play/main-vram 82c8382b, `VICTORY_VRAM_COPIES` off vs `=2`, batched clamps off in both): | | off | `=2` | |---|---:|---:| | median frame time, difference (95 % CI) | | −64 .. −127 ms | | mean frame time | 910 ms | 817 ms | | GPU / preparing / copy-back ms per frame | 316 / 295 / 121 | 216 / 268 / 130 | | drops per frame: no host pipeline / indirect | 565 / 472 | 417 / 205 | Copies in video memory: 1,231 MB (203 read-only + 1,028 written). The 85 % stop held the card at 90 % of the budget ("past 85 %: admitting none"). Shaders' writes brought back: 81 MB/frame in 20 GPU copies, marked pages only. **Against #2130's GPU upload heaps, on one build** (N2U → N2P; play/main-next-2 deeb5939, which carries both; N2U: `VICTORY_GPU_UPLOAD=1` + `_WRITES=1`, this switch off; N2P: `VICTORY_VRAM_COPIES=2`, the upload heaps off): | | upload heaps (#2130) | `=2` (this PR) | |---|---:|---:| | median frame time, difference (95 % CI) | | −50 .. −96 ms | | mean / p50 / p95 frame time | 838 / 762 / 1,399 ms | 746 / 692 / 930 ms | | GPU / preparing / copy-back ms per frame | 126 / 283 / 133 | 123 / 268 / 133 | | drops per frame: no host pipeline / indirect | 389 / 108 | 382 / 99 | The GPU time is about the same either way. The difference is in fewer long frames: the 95th percentile falls from 1,399 to 930 ms. **Against the same build without any GPU placement** (BM1 → N2P): median −7 .. −36 ms (95 % CI); GPU 227 → 123 ms per frame; preparing 227 → 268 ms. Preparing eats most of the GPU gain. Part of it is the second write of refreshed bytes and the bring-backs listed under Limits. Earlier runs of this change (VB and VC, before the fix) were cut short by the memory guard, because of a host upload-buffer growth unrelated to this change (fixed separately since), and their pool drops confounded the frame times. They are left out here. ### Credit - 0xkn0wh3r3, #2120 and #2130: copies in GPU upload heaps, read-only buffers registered by their flags, the destruction-callback charge, `copy_now` (ported, co-author on the commit), and the child-process test pattern. - #2222 (0xkn0wh3r3): the idea of sizing the copies by the DXGI budget and charging bytes between readings. The budget code here is our own. - wbkepler, #693: the over-budget evidence (an RTX 5070: 19 GB of a 10.5 GB budget, then a TDR). - Belobug #105: the copies past a cap that lost their writes. ### Overlap This PR overlaps #2120, #2130 and #2222 (0xkn0wh3r3) directly: - Its read-only half does what #2120 does. - Its written half does what #2130 does, with a different system memory side: always current and always kept, against #2130's lazy mirror. - Its admission covers what #2222's upload pool does for copies. #2222's residency priorities and render-target demotion are not here. If the maintainer prefers 0xkn0wh3r3's PRs, the parts of this one that stand on their own are: - the write-only mapping type; - every CPU write going through one path to video memory; - the ordering rule and its test; - the WARP stand-in heap with the child-process tests. They can go there as suggested commits. #2389 (desplmfao, texture levels on demand) is separate and makes room for these copies on 12 GB cards. The tests above are synthetic and do not use the title. The game results use local title data, as stated in their section. AI-assisted 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With VICTORY_VRAM_COPIES=1, the copy of a title buffer made without
unordered access gets a GPU side in a GPU upload heap (resizable BAR,
D3D12_OPTIONS16.GPUUploadHeapSupported); with =2, so do copies of buffers
shaders may write. Shaders use the video memory buffer. The system memory
buffer stays the copy's CPU side: every CPU write into the copy (refreshes,
the zeros of unmapped pages, copy-back merges) goes there and then into
video memory through a write-only mapping, which has no way to be read
(the CPU reads a BAR at ~50 MB/s).

What shaders wrote comes back before the CPU reads it: after a
submission ran, the ranges its lists declared and the pages marked in the
written-pages bitmaps (withheld ones too) are copied by the GPU into the
system memory side, in one list; pages written at computed addresses
likewise, before their copy-back. The copy-backs then compare as for any
copy. When a copy-back takes a page again, the system memory side reads
it from title memory once more before its bytes go to video memory, so a
title write that lands while the page goes back reaches video memory.

Admission: copies in video memory hold at most a quarter of the budget
DXGI gives the process (VICTORY_VRAM_COPIES_MB sets the cap by hand), and
none is made where use would pass nine tenths of the budget, or without
a reading. Their bytes go back when D3D12 destroys the buffer. A copy
refused stays in system memory, on main's path.

Tests run on the software adapter with a write-combined stand-in heap when
it has no GPU upload heaps, each in a child process with the switch set.

Ideas, the GPU copy and the child-process test pattern from #2120 and

Co-Authored-By: 0xkn0wh3r3 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The first title runs of the switch (RTX 5070, 12 GB) showed three things.

The budget. Copies were admitted at 54 % of the budget, before the
world's textures loaded, and the textures then took the card to 95 %.
Admission now leaves a margin: use stays under 85 % of the budget, and
the cap (a quarter of the budget, or VICTORY_VRAM_COPIES_MB) is never
more than what the rest of the process leaves under 85 %, so it shrinks
as the card fills. Once use passes 85 %, nothing is admitted until it is
back under 75 %. Each buffer in video memory gets
D3D12_RESIDENCY_PRIORITY_LOW: past the budget the system moves these
copies to system memory before the title's textures and targets, with
the same buffer and GPU address.

The bring-back. Ranges declared written and marked came back whole after
each submission, though the CPU reads nothing of them but their marked
pages, which come back anyway. Now only unmarked ranges (main compares
them whole) and marked pages come back. The diagnostics line splits the
bytes by why: declared ranges, marked pages, computed-address pages.

Descriptor slots. A copy in video memory costs a list no more dynamic
slots than one in system memory. Its buffer and GPU address are fixed at
creation. Root-view slots are keyed by copy and kind, fresh tables by
the title's descriptor words, and page-table view pairs by copy. A test
now checks this over 8 submissions. The run's slot shortage followed
more draws and twice the host textures under =2, not the copies' views.

Tests: a copy in video memory takes the same slots as a system copy over
8 submissions, and keeps its address; marked ranges come back by their
marked pages and unmarked ones whole, once; the margin, the 75 % latch
and the shrinking cap with the run's numbers; #693 and Belobug #105 as
before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:19:37 +00:00
From the review of #2993 (fuzeofficlal):

- A GPU copy that brings shaders' writes back reports whether its end
  was seen (`Host::copy_now`). Its allocator is reset only after its last
  list was seen to end. If the signal fails after the list was executed,
  the copier is not used again. If the event fails, the fence is read
  instead. A removed device ends the run, as after a submission. When the
  bring-back's copy fails, the bytes are read through the mapping before
  the copy-backs, so none of the shaders' writes is lost and no stale
  side is read. From then on, no copy is admitted to video memory.
  Without a copier, none is admitted at all.
- With `VICTORY_VRAM_COPIES` on, host copies (their system memory sides,
  copies the budget refused, loose windows, copies of single views) are
  made in system memory always (`Host::system_buffer`). Diagnostics'
  `VICTORY_COPIES_IN_VIDEO_MEMORY` no longer puts them in GPU upload
  heaps outside the budget.
- A reading kept up to 250 ms is taken again when a copy would take use
  past 75 % on it. The 85 % margin is documented as approximate.

Tests run in-process with `VICTORY_VRAM_COPIES` set for the whole suite
(9 failed at `=2`) now see what a submission's end does. `write_host`
brings back what it writes, as `pull_written` does, and `write_gpu`
writes the GPU side alone, inside a submission. `read_host` reads what
shaders see: the GPU side, where undeclared, unmarked writes through
heap views stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A range declared unmarked is snapshotted at submission, and its
copy-back takes what differs from the snapshot for this submission's
shader writes. On main the copy is one buffer, so the snapshot holds
whatever earlier shaders wrote there through views no list declared or
marked (a shader without write marks). With a video memory side, the
snapshot came from the system memory side, which lacks such a write.
The copy-back then put that write into title memory, late, over a title
write made meanwhile. Main never does that.

`Shadow::writing` now brings the range back from video memory first,
where no snapshot covers it yet: one GPU copy per such range of a copy
in video memory, counted as "before snapshots" on the diagnostics line.
Ranges declared marked, and copies in system memory, are not affected.

Test: an_old_unmarked_write_does_not_reach_title_memory_late_at_2 and
_at_0. The title's byte survives in both. With the bring-back off, the
`=2` test fails (title memory gets the old shader byte).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠pickles976 on GitHub · 2026-11-26 02:46 UTC · original

Independent Wine/vkd3d-proton 3.2.0 run on the RTX 4060 Laptop GPU (8 GiB), driver 590.48.1, exact head 1cf4dac8, vendor masking disabled: copies_in_video_memory_are_made_charged_and_given_back passed 1/1 and explicitly printed GPU upload heaps used: true (not the CUSTOM stand-in), so the native GPU-upload path is available on this stack. Three other child-process fixtures each passed 1/1: cap refusal preserves system-memory fallback and writes; marked/declared shader writes come back; a title write in the copy-back/re-guard window reaches video memory. No title run or frame-time/budget-residency result. On this 16 GiB RAM/8 GiB VRAM machine this is not a loading RAM fix: the full system-memory CPU copy remains and enabling the option adds VRAM use. Recommend comparing off vs =1 first with a guarded, same-save title trial only after a separate loading-RAM fix clears our 2,048 MiB available safety floor; record admitted MB, video-memory budget, preparing/copy-back/GPU ms and device removals before considering =2. Logs .compat-runtime/logs/verify-pr2993-wine-rtx4060-{vram-copy-availability,copies_past_the_cap_stay_in_system_memory_and_lose_no_writes,shader_writes_into_copies_in_video_memory_come_back,a_title_write_during_a_copy_back_reaches_video_memory}.log.

**@⁠pickles976** on GitHub · 2026-11-26 02:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2993#issuecomment-7181112281) Independent Wine/vkd3d-proton 3.2.0 run on the **RTX 4060 Laptop GPU (8 GiB)**, driver 590.48.1, exact head 1cf4dac8, vendor masking disabled: `copies_in_video_memory_are_made_charged_and_given_back` passed 1/1 and explicitly printed `GPU upload heaps used: true` (not the CUSTOM stand-in), so the native GPU-upload path *is* available on this stack. Three other child-process fixtures each passed 1/1: cap refusal preserves system-memory fallback and writes; marked/declared shader writes come back; a title write in the copy-back/re-guard window reaches video memory. No title run or frame-time/budget-residency result. On this 16 GiB RAM/8 GiB VRAM machine this is not a loading RAM fix: the full system-memory CPU copy remains and enabling the option adds VRAM use. Recommend comparing off vs `=1` first with a guarded, same-save title trial **only after** a separate loading-RAM fix clears our 2,048 MiB available safety floor; record admitted MB, video-memory budget, preparing/copy-back/GPU ms and device removals before considering `=2`. Logs `.compat-runtime/logs/verify-pr2993-wine-rtx4060-{vram-copy-availability,copies_past_the_cap_stay_in_system_memory_and_lose_no_writes,shader_writes_into_copies_in_video_memory_come_back,a_title_write_during_a_copy_back_reaches_video_memory}.log`.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-26 04:42 UTC · original

Thanks @⁠fuzeofficlal for the careful read. All three points hold against 1cf4dac8, and they're fixed in d2c20e28 on this branch. It also has a fix for the tests that failed with VICTORY_VRAM_COPIES set for the whole suite, and, in 477c6c6f, a correctness fix we found ourselves (both below).

P1: a failed bring-back copy

You're right on every count. copy_now returned nothing, logged the errors, ignored WaitForSingleObject, and reset the allocator on the next call even when Signal had failed after ExecuteCommandLists.

  • Host::copy_now (host.rs:3736) now returns whether the copy's end was seen.
    • A failure while recording (allocator or list Reset, Close) executes nothing, so the copier stays usable.
    • After ExecuteCommandLists, a failed Signal means the end can't be seen. The copier is then marked broken (host.rs:3800) and never used again, so its allocator is never reset under a list that may still be running.
    • Copier::wait (host.rs:3855) checks the wait's result. If SetEventOnCompletion or the wait fails, it reads the fence instead, for up to 10 s. A fence of u64::MAX (removed device) doesn't count as the end.
    • A removed device ends the run through fail (host.rs:3796), as after a submission, so it isn't hidden.
  • On a failed bring-back, bring_back (shadow.rs:1280) reads the runs through the mapping into the system memory side (WriteOnly::read_back, vram.rs:103). That happens before the copy-backs, so nothing they read is stale and no write is lost. vram::stop (vram.rs:123) then stops admitting copies. Without a copier, vram::make admits none at all (vram.rs:361).
  • Where I differ from the suggestion: a copy already in video memory can't drop its video memory side, because its GPU address is in views, root descriptors and page tables. And keeping the dirty state would only defer the loss while no copier works. So for those copies the fallback is the slow read through the mapping (~50 MB/s), counted in vram::READ_BACK, and only after a failure. The ordering of a copy-back is unchanged: bring back, merge and write, take the page, read it again, write video memory.
  • Test: shadow::tests::a_failed_gpu_copy_of_shaders_writes_loses_none_of_them runs a submission whose shaders write a marked page and a declared range, with a test hook (host::COPY_FAILS) failing the bring-back's copy:
    • Its event first: the fence is read, nothing is read back, and the copier still works.
    • Then its signal: the bytes are read back through the mapping, title memory and the system memory side have both writes, copy_now refuses from then on, and the next copy made stays in system memory.

P2a: both switches

Confirmed: with diagnostics' VICTORY_COPIES_IN_VIDEO_MEMORY set, shared_buffer made home in a GPU upload heap, so a copy the budget refused stayed in video memory too.

  • New Host::system_buffer (host.rs:3662) takes the system memory heap main's copies use (CUSTOM, write-back, L0). shared_buffer uses it unless main's switch is on.
  • With VICTORY_VRAM_COPIES on, every host copy buffer is made there (copy_buffer, shadow.rs:1305): system memory sides, copies the budget refused, loose windows and copies of single views. Video memory is then reached only through vram::make and its budget.
  • Test: shadow::tests::with_both_switches_the_cpu_sides_stay_in_system_memory runs a child with both switches. It asserts main's switch is on there, and that both a copy in video memory's system memory side and a refused copy are in a write-back CUSTOM heap. The child-process tests now clear main's switch unless they name it (in_child_with, vram.rs:517).

P2b: the cached reading

Agreed. Within the 250 ms, the reading sees only our own charges.

  • The module docs now call the 85 % margin approximate within that interval (vram.rs:22).
  • When a copy would take use past 75 % of the budget on a kept reading, DXGI is asked again before admission (vram.rs:373). A copy is made once per title buffer, so this costs one QueryVideoMemoryInfo per copy made near the line. Far from the line, the kept reading is still used.
  • Test: vram::tests::a_kept_reading_near_the_line_is_taken_again, with a faked DXGI answer, kept as DXGI's is:
    • at 70 % a copy is admitted;
    • after others take 200 MB, the next copy is still admitted on the kept reading (the approximation, as documented);
    • after a new reading at 76 %, one more is admitted;
    • with 90 % behind the kept reading, the next copy asks again and is refused.

Tests run with the switch set for the whole suite

With VICTORY_VRAM_COPIES=2 set for the whole suite, 9 of main's in-process tests failed on 1cf4dac8. All 9 were the harness; no shader read a wrong byte.

  • Six skipped the submission's bring-back. They wrote the GPU side with write_host, then called the copy-backs directly, without the pull_written a submission runs:

    • shadow::tests::marked_pages_go_back_by_the_bytes_the_gpu_changed
    • marks_of_shaders_using_title_memory_are_held_back
    • partial_refresh_under_marked_range_updates_saved_bytes
    • snapshots_cover_the_declared_ranges_and_writes_go_back_once
    • title_writes_under_a_busy_range_are_copied
    • what_a_frame_withholds_leaves_the_copies_at_its_end
  • Three read the wrong side. These went through real submissions:

    • bindless::tests::heap_views_are_current
    • heap_views_follow_writes_through_another_mapping
    • draw::tests::root_views_reach_their_copy_and_read_zeros_past_it

    Their raw-HLSL shaders write the output through a heap or table view that no list declares and nothing marks. As bindless::refresh's shortcut says, those writes stay in the copy, which is now its GPU side. read_host read the system memory side. Their output buffers are made without unordered access, so they go to video memory even at =1.

The fix is in the helpers, not the tests:

  • read_host (shadow.rs:177) reads what shaders see: the GPU side, by a GPU copy, for a copy in video memory. read_system reads the system memory side.
  • write_host (shadow.rs:210) writes as a submission that has ended: the GPU side, then its bytes back, as pull_written does.
  • write_gpu (shadow.rs:229) writes the GPU side alone, for writes inside a submission. The new video memory tests use it, so they still check the real bring-back.

Every production copy-back already ran after its bring-back (host.rs pull_written before copy_back_marks and copy_back/keep_writes; memory.rs pull before copy_back_page).

A snapshot holds the GPU side (found while checking the above)

While checking which CPU reads of a copy could differ from main, we found one that did. A range declared unmarked is snapshotted at submission, and its copy-back takes whatever differs from the snapshot for this submission's shader writes. On main the copy is one buffer, so the snapshot already holds anything earlier shaders wrote there through a view that no list declared or marked (a shader translated without write marks).

With a video memory side, the snapshot came from the system memory side, which lacks such a write. The copy-back then put that old write into title memory, late, over a title write made in between. Main never does that.

Shadow::writing (shadow.rs:468) now brings the range back from video memory before snapshotting it, where no snapshot covers it yet. This is one GPU copy per such range, counted as "before snapshots" on the diagnostics line. Ranges declared marked, and copies in system memory, are unchanged.

We considered keeping such copies in system memory at admission instead. But a write can only go unmarked through a shader without write marks, and that is known per draw, not when the copy is made. Copies without mark bits would need 2^22 pages of copies first.

The test is shadow::tests::an_old_unmarked_write_does_not_reach_title_memory_late_at_2, with _at_0 as the baseline. A shader write lands on the GPU side, undeclared. Then the title writes the same byte while a later submission declares the range unmarked and writes another byte of it. The title's byte survives at =2, as at 0. With the new bring-back switched off, the =2 test fails: title memory gets the old shader byte (0xaa) in place of the title's (0x77).

Results

WARP, VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads 1:

VICTORY_VRAM_COPIES 1cf4dac8 d2c20e28 477c6c6f
unset 255 / 0 / 1 258 / 0 / 1 260 / 0 / 1
=1 not run 258 / 0 / 1 260 / 0 / 1
=2 246 / 9 / 1 258 / 0 / 1 260 / 0 / 1

The 5 added are the tests above. Clippy -p victory-gpu --all-targets -D warnings is clean with and without --all-features.

Not done: no hardware run. The failure paths are exercised only through the test hook, not by a real failed Signal.

Other notes on this PR

  • @⁠kotekompotek, thanks for the review. On the synchronous wait in memory::bind's pull: in our two title runs with =2 (about 10 minutes each, RTX 5070), the computed-address bring-back was 0.00 MB/frame in every diagnostics line (103 and 106 lines). All bring-backs were marked pages: 79 and 87 MB/frame, in about 20 GPU copies a frame. So that wait didn't cost anything there. The marked-page bring-backs are the likelier cost in preparing.
  • @⁠pickles976, thanks for the vkd3d-proton run. You're right that this is no fix for loading RAM: keeping the system memory side is by design (see Limits). On =1: in an earlier title run it made no measurable difference to frame time, with 203 MB of read-only copies admitted. The gain we measured is at =2. The game results in the description are local title runs, counts and timings only.

The tests above don't use the title. The two notes just above refer to the local title runs reported in the description.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-26 04:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2993#issuecomment-7182834858) Thanks @⁠fuzeofficlal for the careful read. All three points hold against `1cf4dac8`, and they're fixed in `d2c20e28` on this branch. It also has a fix for the tests that failed with `VICTORY_VRAM_COPIES` set for the whole suite, and, in `477c6c6f`, a correctness fix we found ourselves (both below). ### P1: a failed bring-back copy You're right on every count. `copy_now` returned nothing, logged the errors, ignored `WaitForSingleObject`, and reset the allocator on the next call even when `Signal` had failed after `ExecuteCommandLists`. - `Host::copy_now` (`host.rs:3736`) now returns whether the copy's end was seen. - A failure while recording (allocator or list `Reset`, `Close`) executes nothing, so the copier stays usable. - After `ExecuteCommandLists`, a failed `Signal` means the end can't be seen. The copier is then marked broken (`host.rs:3800`) and never used again, so its allocator is never reset under a list that may still be running. - `Copier::wait` (`host.rs:3855`) checks the wait's result. If `SetEventOnCompletion` or the wait fails, it reads the fence instead, for up to 10 s. A fence of `u64::MAX` (removed device) doesn't count as the end. - A removed device ends the run through `fail` (`host.rs:3796`), as after a submission, so it isn't hidden. - On a failed bring-back, `bring_back` (`shadow.rs:1280`) reads the runs through the mapping into the system memory side (`WriteOnly::read_back`, `vram.rs:103`). That happens before the copy-backs, so nothing they read is stale and no write is lost. `vram::stop` (`vram.rs:123`) then stops admitting copies. Without a copier, `vram::make` admits none at all (`vram.rs:361`). - Where I differ from the suggestion: a copy already in video memory can't drop its video memory side, because its GPU address is in views, root descriptors and page tables. And keeping the dirty state would only defer the loss while no copier works. So for those copies the fallback is the slow read through the mapping (~50 MB/s), counted in `vram::READ_BACK`, and only after a failure. The ordering of a copy-back is unchanged: bring back, merge and write, take the page, read it again, write video memory. - Test: `shadow::tests::a_failed_gpu_copy_of_shaders_writes_loses_none_of_them` runs a submission whose shaders write a marked page and a declared range, with a test hook (`host::COPY_FAILS`) failing the bring-back's copy: - Its event first: the fence is read, nothing is read back, and the copier still works. - Then its signal: the bytes are read back through the mapping, title memory and the system memory side have both writes, `copy_now` refuses from then on, and the next copy made stays in system memory. ### P2a: both switches Confirmed: with diagnostics' `VICTORY_COPIES_IN_VIDEO_MEMORY` set, `shared_buffer` made `home` in a GPU upload heap, so a copy the budget refused stayed in video memory too. - New `Host::system_buffer` (`host.rs:3662`) takes the system memory heap main's copies use (CUSTOM, write-back, L0). `shared_buffer` uses it unless main's switch is on. - With `VICTORY_VRAM_COPIES` on, every host copy buffer is made there (`copy_buffer`, `shadow.rs:1305`): system memory sides, copies the budget refused, loose windows and copies of single views. Video memory is then reached only through `vram::make` and its budget. - Test: `shadow::tests::with_both_switches_the_cpu_sides_stay_in_system_memory` runs a child with both switches. It asserts main's switch is on there, and that both a copy in video memory's system memory side and a refused copy are in a write-back CUSTOM heap. The child-process tests now clear main's switch unless they name it (`in_child_with`, `vram.rs:517`). ### P2b: the cached reading Agreed. Within the 250 ms, the reading sees only our own charges. - The module docs now call the 85 % margin approximate within that interval (`vram.rs:22`). - When a copy would take use past 75 % of the budget on a kept reading, DXGI is asked again before admission (`vram.rs:373`). A copy is made once per title buffer, so this costs one `QueryVideoMemoryInfo` per copy made near the line. Far from the line, the kept reading is still used. - Test: `vram::tests::a_kept_reading_near_the_line_is_taken_again`, with a faked DXGI answer, kept as DXGI's is: - at 70 % a copy is admitted; - after others take 200 MB, the next copy is still admitted on the kept reading (the approximation, as documented); - after a new reading at 76 %, one more is admitted; - with 90 % behind the kept reading, the next copy asks again and is refused. ### Tests run with the switch set for the whole suite With `VICTORY_VRAM_COPIES=2` set for the whole suite, 9 of main's in-process tests failed on `1cf4dac8`. All 9 were the harness; no shader read a wrong byte. - **Six skipped the submission's bring-back.** They wrote the GPU side with `write_host`, then called the copy-backs directly, without the `pull_written` a submission runs: - `shadow::tests::marked_pages_go_back_by_the_bytes_the_gpu_changed` - `marks_of_shaders_using_title_memory_are_held_back` - `partial_refresh_under_marked_range_updates_saved_bytes` - `snapshots_cover_the_declared_ranges_and_writes_go_back_once` - `title_writes_under_a_busy_range_are_copied` - `what_a_frame_withholds_leaves_the_copies_at_its_end` - **Three read the wrong side.** These went through real submissions: - `bindless::tests::heap_views_are_current` - `heap_views_follow_writes_through_another_mapping` - `draw::tests::root_views_reach_their_copy_and_read_zeros_past_it` Their raw-HLSL shaders write the output through a heap or table view that no list declares and nothing marks. As `bindless::refresh`'s shortcut says, those writes stay in the copy, which is now its GPU side. `read_host` read the system memory side. Their output buffers are made without unordered access, so they go to video memory even at `=1`. The fix is in the helpers, not the tests: - `read_host` (`shadow.rs:177`) reads what shaders see: the GPU side, by a GPU copy, for a copy in video memory. `read_system` reads the system memory side. - `write_host` (`shadow.rs:210`) writes as a submission that has ended: the GPU side, then its bytes back, as `pull_written` does. - `write_gpu` (`shadow.rs:229`) writes the GPU side alone, for writes inside a submission. The new video memory tests use it, so they still check the real bring-back. Every production copy-back already ran after its bring-back (`host.rs` `pull_written` before `copy_back_marks` and `copy_back`/`keep_writes`; `memory.rs` `pull` before `copy_back_page`). ### A snapshot holds the GPU side (found while checking the above) While checking which CPU reads of a copy could differ from main, we found one that did. A range declared unmarked is snapshotted at submission, and its copy-back takes whatever differs from the snapshot for this submission's shader writes. On main the copy is one buffer, so the snapshot already holds anything earlier shaders wrote there through a view that no list declared or marked (a shader translated without write marks). With a video memory side, the snapshot came from the system memory side, which lacks such a write. The copy-back then put that old write into title memory, late, over a title write made in between. Main never does that. `Shadow::writing` (`shadow.rs:468`) now brings the range back from video memory before snapshotting it, where no snapshot covers it yet. This is one GPU copy per such range, counted as "before snapshots" on the diagnostics line. Ranges declared marked, and copies in system memory, are unchanged. We considered keeping such copies in system memory at admission instead. But a write can only go unmarked through a shader without write marks, and that is known per draw, not when the copy is made. Copies without mark bits would need 2^22 pages of copies first. The test is `shadow::tests::an_old_unmarked_write_does_not_reach_title_memory_late_at_2`, with `_at_0` as the baseline. A shader write lands on the GPU side, undeclared. Then the title writes the same byte while a later submission declares the range unmarked and writes another byte of it. The title's byte survives at `=2`, as at `0`. With the new bring-back switched off, the `=2` test fails: title memory gets the old shader byte (0xaa) in place of the title's (0x77). ### Results WARP, `VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads 1`: | `VICTORY_VRAM_COPIES` | `1cf4dac8` | `d2c20e28` | `477c6c6f` | |---|---|---|---| | unset | 255 / 0 / 1 | 258 / 0 / 1 | 260 / 0 / 1 | | `=1` | not run | 258 / 0 / 1 | 260 / 0 / 1 | | `=2` | 246 / 9 / 1 | 258 / 0 / 1 | 260 / 0 / 1 | The 5 added are the tests above. Clippy `-p victory-gpu --all-targets -D warnings` is clean with and without `--all-features`. Not done: no hardware run. The failure paths are exercised only through the test hook, not by a real failed `Signal`. ### Other notes on this PR - @⁠kotekompotek, thanks for the review. On the synchronous wait in `memory::bind`'s `pull`: in our two title runs with `=2` (about 10 minutes each, RTX 5070), the computed-address bring-back was 0.00 MB/frame in every diagnostics line (103 and 106 lines). All bring-backs were marked pages: 79 and 87 MB/frame, in about 20 GPU copies a frame. So that wait didn't cost anything there. The marked-page bring-backs are the likelier cost in preparing. - @⁠pickles976, thanks for the vkd3d-proton run. You're right that this is no fix for loading RAM: keeping the system memory side is by design (see Limits). On `=1`: in an earlier title run it made no measurable difference to frame time, with 203 MB of read-only copies admitted. The gain we measured is at `=2`. The game results in the description are local title runs, counts and timings only. The tests above don't use the title. The two notes just above refer to the local title runs reported in the description. AI-assisted
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:34 UTC · original · edited 2026-11-26 07:19 UTC

Automated triage for the maintainers.

Thanks for the reply. The head is unchanged since our last comment and the reply agrees with the open points: the maintainer's choice between this design and #2120/#2130/#2222, and a hardware run of the current head on main alone (off vs =2). The verdict stays needs work; needs the maintainer's decision until those are settled.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2993#issuecomment-7183603861) · edited 2026-11-26 07:19 UTC <!-- victory-triage v1 head=477c6c6fab2c799b8f4555361783c53706080364 verdict=needs-work at=2026-11-26T07:19:35Z --> Automated triage for the maintainers. Thanks for the reply. The head is unchanged since our last comment and the reply agrees with the open points: the maintainer's choice between this design and #2120/#2130/#2222, and a hardware run of the current head on `main` alone (off vs `=2`). The verdict stays **needs work; needs the maintainer's decision** until those are settled. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠r4tedx on GitHub · 2026-11-26 05:36 UTC · original

Thanks for the triage.

  1. Design. We'd welcome the maintainer's call between this and #2120/#2130/#2222. The main differences:

    • this keeps the system memory side current, through one CPU write path, so the CPU never reads video memory;
    • it admits copies by a DXGI margin, with residency demotion;
    • it brings shader writes back by marked pages.

    If this design is preferred, we'll split it as described:

    • (a) the write-only mapping and the vram module, opt-in;
    • (b) the single CPU write path;
    • (c) copy-back ordering and the bring-back, with their tests.

    If #2130's design is preferred, we're happy to offer the pieces that still apply there instead.

  2. A hardware run of the current head on main alone, off vs =2. Agreed, that's the right test. On our RTX 5070 it isn't possible yet: upstream main on its own (781e846d, with 219878a0) currently ends this title's load in a device removal. We haven't attributed that yet and will post what we find. The d2c20e28 and 477c6c6f changes have been tested on WARP only so far. The frame times in the description come from builds carrying other unmerged PRs, as it says.

Local title data was used for the runs mentioned here; only their outcome is given.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-26 05:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2993#issuecomment-7183640629) Thanks for the triage. 1. **Design.** We'd welcome the maintainer's call between this and #2120/#2130/#2222. The main differences: - this keeps the system memory side current, through one CPU write path, so the CPU never reads video memory; - it admits copies by a DXGI margin, with residency demotion; - it brings shader writes back by marked pages. If this design is preferred, we'll split it as described: - (a) the write-only mapping and the `vram` module, opt-in; - (b) the single CPU write path; - (c) copy-back ordering and the bring-back, with their tests. If #2130's design is preferred, we're happy to offer the pieces that still apply there instead. 2. **A hardware run of the current head on `main` alone, off vs `=2`.** Agreed, that's the right test. On our RTX 5070 it isn't possible yet: upstream `main` on its own (781e846d, with 219878a0) currently ends this title's load in a device removal. We haven't attributed that yet and will post what we find. The `d2c20e28` and `477c6c6f` changes have been tested on WARP only so far. The frame times in the description come from builds carrying other unmerged PRs, as it says. Local title data was used for the runs mentioned here; only their outcome is given. AI-assisted
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 02:47 UTC · original · approved these changes

LGTM — verified the data-flow invariants end to end.

What I checked:

  • Direction discipline: every CPU write path (refresh, unmapped zero-fill, copy-back merges via settle) goes sysmem side then put→BAR; write_host goes BAR-only (it's the "what shaders see" side); shader writes return via pull/pull_written → copy_now (src=buffer, dst=home). No path reads the BAR — WriteOnly makes it unrepresentable, not just undocumented.
  • Ordering: pull_written before copy_back_marks (bitmaps preserved for it); settle re-reads title memory after re-taking the guard — the BEFORE_TAKEN test hook writes between the copy-back write and the re-take and asserts the byte survives in VRAM, which is the exact race the ordering exists for.
  • Admission: limit = min(cap, 85%·budget − others), admits adds 75% hysteresis, charged covers the window between DXGI readings, and the size|class destruction-callback packing is safe (low 16 bits free on 64KiB multiples).
  • Merge logic in bring_back: overlapping/adjacent runs per copy join correctly; a marked page inside a declared range dedupes to the union.
  • Off-by-default: level 0 → wanted→System → vram=None everywhere; IN_VRAM early-out means the pull paths cost one relaxed load when disabled.
  • Tests are discriminating: slot-parity across 8 submissions, class assertions per level, the budget table mirrors #693's actual numbers, and gpu_bytes checks real GPU-side contents after each write path.

One note, non-blocking: pull inside memory::bind runs a synchronous fence wait per call while enabled — fine as designed (it's gated opt-in and the copies are what make it worthwhile), just worth watching in the diagnostics line (PULLED_BY[Computed]) on real runs.

**@⁠kotekompotek** on GitHub · 2026-11-26 02:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2993#pullrequestreview-6067882902) · **approved these changes** LGTM — verified the data-flow invariants end to end. What I checked: - **Direction discipline**: every CPU write path (refresh, unmapped zero-fill, copy-back merges via `settle`) goes sysmem side then `put`→BAR; `write_host` goes BAR-only (it's the "what shaders see" side); shader writes return via `pull`/`pull_written` → `copy_now` (src=buffer, dst=home). No path reads the BAR — `WriteOnly` makes it unrepresentable, not just undocumented. - **Ordering**: `pull_written` before `copy_back_marks` (bitmaps preserved for it); `settle` re-reads title memory after re-taking the guard — the `BEFORE_TAKEN` test hook writes between the copy-back write and the re-take and asserts the byte survives in VRAM, which is the exact race the ordering exists for. - **Admission**: `limit` = min(cap, 85%·budget − others), `admits` adds 75% hysteresis, `charged` covers the window between DXGI readings, and the `size|class` destruction-callback packing is safe (low 16 bits free on 64KiB multiples). - **Merge logic in `bring_back`**: overlapping/adjacent runs per copy join correctly; a marked page inside a declared range dedupes to the union. - **Off-by-default**: level 0 → `wanted`→System → `vram=None` everywhere; `IN_VRAM` early-out means the pull paths cost one relaxed load when disabled. - Tests are discriminating: slot-parity across 8 submissions, class assertions per level, the budget table mirrors #693's actual numbers, and `gpu_bytes` checks real GPU-side contents after each write path. One note, non-blocking: `pull` inside `memory::bind` runs a synchronous fence wait per call while enabled — fine as designed (it's gated opt-in and the copies are what make it worthwhile), just worth watching in the diagnostics line (`PULLED_BY[Computed]`) on real runs.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 02:58 UTC · original · requested changes

Code review on 1cf4dac8 (static/source inspection; no runtime GPU execution):

  • P1 — Failed VRAM readback swallows errors and risks resetting an in-flight copy allocator (crates/victory-gpu/src/host.rs:3750-3775, crates/victory-gpu/src/shadow.rs:1200-1208):
    • If copier initialization fails (host.rs:3750), copy_buffers returns early without copying.
    • At host.rs:3765-3774, ExecuteCommandLists runs before Signal and SetEventOnCompletion, errors are only logged and discarded, and WaitForSingleObject's return value is ignored.
    • Because pull_vram (shadow.rs:1202-1203) returns normally, callers proceed to read the stale system-memory mirror and clear shader-write dirty tracking (host.rs:1414-1434, memory.rs:684-697). Worse, if Signal or SetEventOnCompletion fails after ExecuteCommandLists, the submitted copy list may still be in flight when the next call invokes c.allocator.Reset() at host.rs:3759.
    • Suggest propagating/checking confirmed fence completion before clearing dirty state or reusing the copy allocator, and falling back to system-memory copies if the copier cannot be initialized.
  • P2 — Dual VRAM switches can bypass the new budget in diagnostics builds (crates/victory-gpu/src/shadow.rs:1284-1299, crates/victory-gpu/src/host.rs:3645-3658):
    • home is allocated via host.shared_buffer(size), which switches to D3D12_HEAP_TYPE_GPU_UPLOAD whenever VICTORY_COPIES_IN_VIDEO_MEMORY is set. With both flags enabled, the "system memory side" mirror already occupies VRAM outside vram::make, and a budget refusal (None => (home, None)) still leaves the buffer in VRAM. Giving home an explicit system-memory L0 heap path avoids this bypass.
  • P2 — 250 ms cached DXGI usage can overshoot the 85% ceiling (crates/victory-gpu/src/vram.rs:204-226, 310-325):
    • reading() adds only last.charged (newly admitted copies) during MAX_AGE = 250ms and does not observe concurrent texture/render-target VRAM allocations in the same window. Either refresh when other allocations consume headroom or document the 85% margin as approximate within the cache interval.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 02:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2993#pullrequestreview-6067954996) · **requested changes** Code review on `1cf4dac8` (static/source inspection; no runtime GPU execution): - **P1 — Failed VRAM readback swallows errors and risks resetting an in-flight copy allocator (`crates/victory-gpu/src/host.rs:3750-3775`, `crates/victory-gpu/src/shadow.rs:1200-1208`)**: - If copier initialization fails (`host.rs:3750`), `copy_buffers` returns early without copying. - At `host.rs:3765-3774`, `ExecuteCommandLists` runs before `Signal` and `SetEventOnCompletion`, errors are only logged and discarded, and `WaitForSingleObject`'s return value is ignored. - Because `pull_vram` (`shadow.rs:1202-1203`) returns normally, callers proceed to read the stale system-memory mirror and clear shader-write dirty tracking (`host.rs:1414-1434`, `memory.rs:684-697`). Worse, if `Signal` or `SetEventOnCompletion` fails after `ExecuteCommandLists`, the submitted copy list may still be in flight when the next call invokes `c.allocator.Reset()` at `host.rs:3759`. - Suggest propagating/checking confirmed fence completion before clearing dirty state or reusing the copy allocator, and falling back to system-memory copies if the copier cannot be initialized. - **P2 — Dual VRAM switches can bypass the new budget in `diagnostics` builds (`crates/victory-gpu/src/shadow.rs:1284-1299`, `crates/victory-gpu/src/host.rs:3645-3658`)**: - `home` is allocated via `host.shared_buffer(size)`, which switches to `D3D12_HEAP_TYPE_GPU_UPLOAD` whenever `VICTORY_COPIES_IN_VIDEO_MEMORY` is set. With both flags enabled, the "system memory side" mirror already occupies VRAM outside `vram::make`, and a budget refusal (`None => (home, None)`) still leaves the buffer in VRAM. Giving `home` an explicit system-memory L0 heap path avoids this bypass. - **P2 — 250 ms cached DXGI usage can overshoot the 85% ceiling (`crates/victory-gpu/src/vram.rs:204-226`, `310-325`)**: - `reading()` adds only `last.charged` (newly admitted copies) during `MAX_AGE = 250ms` and does not observe concurrent texture/render-target VRAM allocations in the same window. Either refresh when other allocations consume headroom or document the 85% margin as approximate within the cache interval.
Author
Owner

@⁠imjustprism on GitHub · 2026-11-26 20:48 UTC · original · reviewed

ran 477c6c6 in the title, since the triage asks for a hardware run of the head with the switch off and at 2, and read the diff. rx 9070 xt (16 GB, gpu upload heaps supported), world, medians per frame:

per frame without this pr, 2 runs this pr, switch off =1 =2
frame, ms 195 and 213 219 206 214
waiting for the gpu, ms 84.6 and 90.6 87.3 91.1 78.1
preparing, ms 70.3 and 72.5 66.7 68.7 78.9
copying back, ms 31.7 and 37.5 34.2 35.4 45.5
of that, the bring-back before the copy-backs (pull_written), ms 0.0 0.3 4.0
refresh copies, ms per MB 0.14 and 0.21 0.15 0.15 0.18
host submissions 21.9 and 26.8 21.3 23.5 22.8
shaders' writes brought back 0.01 MB in 1.0 gpu copies 104 MB in 20.2 gpu copies
copies in video memory at the end 0 203 MB (2,878 read-only) 1,300 MB (2,876 read-only, 585 written)
refused for the budget 0 0
dedicated video memory at minute 8 11.8 GB 12.4 GB 13.8 GB

63bcca4 plus #2122 (this card does not get into the world on main alone) plus local timers around the phases of a submission, with and without this pr merged in; the three runs with the pr are one exe. diag build, series-x, the same scripted key presses, warm shader and pipeline caches, quiet machine, 12-minute runs, medians over 47 to 73 world frame lines per run, one run per switch value. no errors and no device removed in any run, and a 2-minute run at =2 before them was clean too.

how i read it:

  • off: nothing i can tell from the runs without the pr.
  • =2: the wait for the gpu is lower than with the switch off in every draw bucket (3 to 22%, 11% over all), and preparing and copying back are higher (by 12 and 11 ms), so the frame does not move: 214 ms against 219, inside the spread of the runs without. one run each and under 20%, so i would not call the gpu gain measured yet; the direction is the same in all five buckets.
  • =1: only 203 MB goes to video memory here, and nothing changes.
  • the budget did what it says: the cap went from 4,042 MB down to about 1,600 to 1,750 MB as the card filled (11.6 of 14.2 GB at the end), and nothing was refused.
  • at =2 about as many bytes come back as are refreshed (104 MB a frame, nearly all as marked pages), in about one gpu copy per submission (20.2 against 22.8). the bring-back timer accounts for 4.0 of the 11 ms that copying back gained; i did not split the rest.

what i checked from the description:

  • the tests: video_memory, copies_past_the_cap, a_failed_gpu_copy and vram filters with --features diagnostics, 12 tests, all pass here on the hardware adapter, and W0 prints that real gpu upload heaps were used.
  • "without the switch, no code path changes": behaviour does not change and the runs agree, but a little code does run, see below.
  • "one gpu copy per submission": true on average in this scene; the code has three places that each wait for one, see below.
  • "asked at most every 250 ms" and "no code outside vram.rs can read through it": not as written, see below.

points from reading the diff:

  • gpu copies, shadow.rs:481, :1196, :1213. bring_back waits for its own gpu copy at three sites: once for each unmarked declared range of a copy in video memory that no snapshot covers yet (writing, before the submission), once in pull_written, and once per list that uses title memory (memory.rs:684). nothing bounds the first by submission, and overlapping ranges are brought back again each time. each such range also crosses the bus whole twice, before the snapshot and after the submission, however little shaders wrote. here that was 7 MB a frame before snapshots and 39 MB of declared ranges after, so it is small in this scene; the waits hold the submission lock, so a scene with many unmarked root views would show it. gathering the ranges of one submission into one copy before it and one after would make the description's sentence true.
  • no test goes through memory.rs:684. every child test is in shadow.rs or draw.rs, so taking that pull call out leaves the suite green, and with it shader writes at computed addresses into a copy in video memory would be lost silently. computed-address pages were 0.00 MB a frame in my run too, so nothing here covers that path.
  • with_both_switches_the_cpu_sides_stay_in_system_memory (shadow.rs:2101) guards a branch that exists only under diagnostics (host.rs:3648); ci and the gate run tests without that feature, where it cannot fail.
  • a_failed_gpu_copy_of_shaders_writes_loses_none_of_them (shadow.rs:1974): since 477c6c6 the one-shot COPY_FAILS is used up by the bring-back before the snapshot inside writing, so the case its doc describes, a failed copy after the submission, is no longer the one that fails. the outcome is still checked; setting the hook inside the deferred closure would put it back.
  • vram.rs:93 and :103: write and read_back are safe functions that compute self.at.add(at) before anything is cut, and only n is cut. an at past len is undefined behaviour even with n at 0. no caller passes one today; an early return on at >= len closes it. read_back is also pub(crate) and called from shadow.rs:1287, so the type does let code outside the module read through the mapping; moving that fallback loop into vram.rs would make the description's claim hold.
  • vram.rs:372: once the kept reading plus the new copy is past 75% of the budget, every make asks dxgi again (your own test pins that), under BUFFERS, which every find takes, and LAST. the second CreateCommittedResource and the residency call are under BUFFERS too. the description's "at most every 250 ms" holds only below that line.
  • switch off, shadow.rs:616 to :629 and host.rs:1355: the copy-back of a declared range now builds pieces and calls whole.contains once per piece before settle returns for a copy with no video memory side, and a marked vector is allocated per submission that has a gpu write step. (first..last).contains(&(at / PAGE)) gives the same answer without the scan. i could not measure either.
  • vram.rs:58 and :283: these are the first VICTORY_* switches this crate reads in a release build, and the readme has no row for them. =3 or =yes silently means level 1, and a _MB value that does not parse silently means a quarter of the budget.
  • shadow.rs:1295 ("shaders only read it") and the module doc of vram.rs say copies made without unordered access are not written by shaders; shader_writes_into_copies_in_video_memory_come_back writes one. the code is right, the comments invite someone to skip those copies in pull_written later.
  • resource.rs:1596: texture eviction counts the copies as pressure and gives up title textures past 90% of the budget, while the copies never leave video memory; microsoft's residency page says priorities only matter once the system has to demote, so D3D12_RESIDENCY_PRIORITY_LOW does nothing below the budget. that is the opposite order from "copies yield to textures". my run stayed under 85%, so it did not show.
  • a question, shadow.rs:1137 and :1182: page_of upgrades a weak reference and, for a mark past the copy's pages, drops it while the caller holds MARKS; Shadow::drop takes MARKS. if that was the last strong reference, does the submitting thread lock itself? the pattern is older than this pr, pull_written adds a call site.

not this pr's, found while reading it: for a copy in system memory, a title write that lands after a copy-back lets go of its write guard and before the page is taken again is never marked, and a later whole-page copy-back overwrites it (shadow.rs:691 to :702, the same on main). your settle closes that for copies in video memory only.

**@⁠imjustprism** on GitHub · 2026-11-26 20:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2993#pullrequestreview-6080341834) · **reviewed** ran 477c6c6 in the title, since the triage asks for a hardware run of the head with the switch off and at 2, and read the diff. rx 9070 xt (16 GB, gpu upload heaps supported), world, medians per frame: | per frame | without this pr, 2 runs | this pr, switch off | `=1` | `=2` | |---|---|---|---|---| | frame, ms | 195 and 213 | 219 | 206 | 214 | | waiting for the gpu, ms | 84.6 and 90.6 | 87.3 | 91.1 | 78.1 | | preparing, ms | 70.3 and 72.5 | 66.7 | 68.7 | 78.9 | | copying back, ms | 31.7 and 37.5 | 34.2 | 35.4 | 45.5 | | of that, the bring-back before the copy-backs (`pull_written`), ms | | 0.0 | 0.3 | 4.0 | | refresh copies, ms per MB | 0.14 and 0.21 | 0.15 | 0.15 | 0.18 | | host submissions | 21.9 and 26.8 | 21.3 | 23.5 | 22.8 | | shaders' writes brought back | | | 0.01 MB in 1.0 gpu copies | 104 MB in 20.2 gpu copies | | copies in video memory at the end | | 0 | 203 MB (2,878 read-only) | 1,300 MB (2,876 read-only, 585 written) | | refused for the budget | | | 0 | 0 | | dedicated video memory at minute 8 | | 11.8 GB | 12.4 GB | 13.8 GB | 63bcca4 plus #2122 (this card does not get into the world on main alone) plus local timers around the phases of a submission, with and without this pr merged in; the three runs with the pr are one exe. diag build, series-x, the same scripted key presses, warm shader and pipeline caches, quiet machine, 12-minute runs, medians over 47 to 73 world frame lines per run, one run per switch value. no errors and no device removed in any run, and a 2-minute run at `=2` before them was clean too. how i read it: - off: nothing i can tell from the runs without the pr. - `=2`: the wait for the gpu is lower than with the switch off in every draw bucket (3 to 22%, 11% over all), and preparing and copying back are higher (by 12 and 11 ms), so the frame does not move: 214 ms against 219, inside the spread of the runs without. one run each and under 20%, so i would not call the gpu gain measured yet; the direction is the same in all five buckets. - `=1`: only 203 MB goes to video memory here, and nothing changes. - the budget did what it says: the cap went from 4,042 MB down to about 1,600 to 1,750 MB as the card filled (11.6 of 14.2 GB at the end), and nothing was refused. - at `=2` about as many bytes come back as are refreshed (104 MB a frame, nearly all as marked pages), in about one gpu copy per submission (20.2 against 22.8). the bring-back timer accounts for 4.0 of the 11 ms that copying back gained; i did not split the rest. what i checked from the description: - the tests: `video_memory`, `copies_past_the_cap`, `a_failed_gpu_copy` and `vram` filters with `--features diagnostics`, 12 tests, all pass here on the hardware adapter, and W0 prints that real gpu upload heaps were used. - "without the switch, no code path changes": behaviour does not change and the runs agree, but a little code does run, see below. - "one gpu copy per submission": true on average in this scene; the code has three places that each wait for one, see below. - "asked at most every 250 ms" and "no code outside `vram.rs` can read through it": not as written, see below. points from reading the diff: - gpu copies, `shadow.rs:481`, `:1196`, `:1213`. `bring_back` waits for its own gpu copy at three sites: once for each unmarked declared range of a copy in video memory that no snapshot covers yet (`writing`, before the submission), once in `pull_written`, and once per list that uses title memory (`memory.rs:684`). nothing bounds the first by submission, and overlapping ranges are brought back again each time. each such range also crosses the bus whole twice, before the snapshot and after the submission, however little shaders wrote. here that was 7 MB a frame before snapshots and 39 MB of declared ranges after, so it is small in this scene; the waits hold the submission lock, so a scene with many unmarked root views would show it. gathering the ranges of one submission into one copy before it and one after would make the description's sentence true. - no test goes through `memory.rs:684`. every child test is in `shadow.rs` or `draw.rs`, so taking that `pull` call out leaves the suite green, and with it shader writes at computed addresses into a copy in video memory would be lost silently. computed-address pages were 0.00 MB a frame in my run too, so nothing here covers that path. - `with_both_switches_the_cpu_sides_stay_in_system_memory` (`shadow.rs:2101`) guards a branch that exists only under `diagnostics` (`host.rs:3648`); ci and the gate run tests without that feature, where it cannot fail. - `a_failed_gpu_copy_of_shaders_writes_loses_none_of_them` (`shadow.rs:1974`): since 477c6c6 the one-shot `COPY_FAILS` is used up by the bring-back before the snapshot inside `writing`, so the case its doc describes, a failed copy after the submission, is no longer the one that fails. the outcome is still checked; setting the hook inside the deferred closure would put it back. - `vram.rs:93` and `:103`: `write` and `read_back` are safe functions that compute `self.at.add(at)` before anything is cut, and only `n` is cut. an `at` past `len` is undefined behaviour even with `n` at 0. no caller passes one today; an early return on `at >= len` closes it. `read_back` is also `pub(crate)` and called from `shadow.rs:1287`, so the type does let code outside the module read through the mapping; moving that fallback loop into `vram.rs` would make the description's claim hold. - `vram.rs:372`: once the kept reading plus the new copy is past 75% of the budget, every `make` asks dxgi again (your own test pins that), under `BUFFERS`, which every `find` takes, and `LAST`. the second `CreateCommittedResource` and the residency call are under `BUFFERS` too. the description's "at most every 250 ms" holds only below that line. - switch off, `shadow.rs:616` to `:629` and `host.rs:1355`: the copy-back of a declared range now builds `pieces` and calls `whole.contains` once per piece before `settle` returns for a copy with no video memory side, and a `marked` vector is allocated per submission that has a gpu write step. `(first..last).contains(&(at / PAGE))` gives the same answer without the scan. i could not measure either. - `vram.rs:58` and `:283`: these are the first `VICTORY_*` switches this crate reads in a release build, and the readme has no row for them. `=3` or `=yes` silently means level 1, and a `_MB` value that does not parse silently means a quarter of the budget. - `shadow.rs:1295` ("shaders only read it") and the module doc of `vram.rs` say copies made without unordered access are not written by shaders; `shader_writes_into_copies_in_video_memory_come_back` writes one. the code is right, the comments invite someone to skip those copies in `pull_written` later. - `resource.rs:1596`: texture eviction counts the copies as pressure and gives up title textures past 90% of the budget, while the copies never leave video memory; microsoft's residency page says priorities only matter once the system has to demote, so `D3D12_RESIDENCY_PRIORITY_LOW` does nothing below the budget. that is the opposite order from "copies yield to textures". my run stayed under 85%, so it did not show. - a question, `shadow.rs:1137` and `:1182`: `page_of` upgrades a weak reference and, for a mark past the copy's pages, drops it while the caller holds `MARKS`; `Shadow::drop` takes `MARKS`. if that was the last strong reference, does the submitting thread lock itself? the pattern is older than this pr, `pull_written` adds a call site. not this pr's, found while reading it: for a copy in system memory, a title write that lands after a copy-back lets go of its write guard and before the page is taken again is never marked, and a later whole-page copy-back overwrites it (`shadow.rs:691` to `:702`, the same on main). your `settle` closes that for copies in video memory only.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2993/head:github-bot/gh-2993'
git switch 'github-bot/gh-2993'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2993'
git switch 'github-bot/gh-2993'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2993'
git switch 'github-bot/gh-2993'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2993'
git switch 'main'
git merge --squash 'github-bot/gh-2993'
git switch 'main'
git merge --ff-only 'github-bot/gh-2993'
git switch 'main'
git merge 'github-bot/gh-2993'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2993
No description provided.