GPU: host copies of title buffers are in video memory by default where the host has GPU upload heaps #2868

Closed
0xkn0wh3r3 wants to merge 10 commits from upstream-pr/2870 into main
0xkn0wh3r3 commented 2026-11-25 22:46:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T22:46:59Z.


Stacked on #2222 (→ #2130 → #2120): the copies in GPU upload heaps, their mirrors and the budget that sizes them come from there. All commits but the last are those PRs'; the last one is this change.

Problem

Slow host submissions of a few hundred compute dispatches (slow host submission ms=497 lists=9 pipelines={~250 compute pipelines ...}) spend their GPU time on shaders reading and writing host copies of title buffers. Those copies were in system memory unless VICTORY_GPU_UPLOAD=1 (and VICTORY_GPU_UPLOAD_WRITES=1) were set, so every access crossed PCI Express: ~23 GB/s, against ~720 GB/s for video memory on an RTX 5070 Ti. The existing benchmarks timed one big copy. This adds one shaped like a title's compute passes, and decides the defaults from it.

Measurements

shadow::bench::compute_heavy_submissions_by_copy_placement (ignored; cargo test --release -p victory-gpu --lib compute_heavy -- --ignored --nocapture) goes through the copies' real paths: shadow::find, Shadow::refresh, Shadow::gpu_writes, HostList and Host::execute. One submission is 200 dispatches in 8 lists over six title buffers: four of 64 MiB made without unordered access, and two of 32 MiB that shaders write (320 MiB in all). Each dispatch reads 4 MiB of a read-only buffer, reads and writes 1 MiB of a written one, and reads 256 KiB more, with a UAV barrier after it. Shaders find what they wrote in one of two ways:

  • write marks: each store sets its page's bit where still clear, as translated shaders do;
  • snapshots of the declared ranges.

Between submissions the title either leaves its data alone or writes 16 MiB of it, so the CPU's refresh cost through the BAR is counted. Each placement runs in its own child process, because the switches are read once per process. All of them must leave title memory the same.

RTX 5070 Ti (driver 621.24), Ryzen 9 7900X, Windows 11. Each number is the median of three runs, each the median of 5 submissions, in ms. total is all of Host::execute: prepare (refreshes, snapshots) + GPU (the wait for it) + copy-back (including bringing written pages back from video memory):

copies writes found by title writes total prepare GPU copy-back
system memory write marks none 59.7 0.0 44.0 15.7
system memory write marks 16 MiB per submission 61.6 2.3 43.8 15.2
system memory snapshots none 73.5 12.4 43.4 17.8
system memory snapshots 16 MiB per submission 76.4 14.6 43.0 18.1
read-only copies in video memory write marks none 31.0 0.0 15.7 15.1
read-only copies in video memory write marks 16 MiB per submission 32.9 2.1 15.8 15.0
read-only copies in video memory snapshots none 43.3 12.2 12.9 18.3
read-only copies in video memory snapshots 16 MiB per submission 45.6 14.3 12.8 18.2
all copies in video memory write marks none 31.7 0.0 12.0 19.6
all copies in video memory write marks 16 MiB per submission 32.3 1.8 11.0 19.4
all copies in video memory snapshots none 35.9 12.1 2.1 21.8
all copies in video memory snapshots 16 MiB per submission 37.7 14.0 2.1 21.4
  • Read-only copies in video memory halve the submission with marks (60 → 31 ms) and cut 40% with snapshots (74 → 43). GPU time drops from 44 ms to 13-16, and nothing else changes. Refreshing through the BAR costs the same as refreshing system memory (2 ms for 16 MiB).
  • Written copies in video memory as well bring GPU time down to 11-12 ms with marks and 2 ms with snapshots. Bringing written pages back to their mirrors (48 MiB per submission here) adds 4 ms of copy-back. CPU and GPU together:
    • with marks it is even (31.7 / 32.3 ms against 31.0 / 32.9; within the spread between runs);
    • with snapshots it is 17% faster (36 against 43 ms);
    • the GPU's own time is a quarter lower with marks and a sixth of what it was with snapshots.
  • With all copies in video memory, marking takes about 9 of the 11-12 GPU ms. The written-pages bitmap is in system memory, and each store reads it across the bus. docs/gpu-memory.md lists this as a further step (not done here). Without that cost, the marked path would gain from written copies in video memory as the snapshot path does.

What changed

  • host::upload_placement(supported, nvidia, VICTORY_GPU_UPLOAD, VICTORY_GPU_UPLOAD_WRITES) decides once per run, from GPUUploadHeapSupported, the adapter's vendor and the switches, where copies go. Host::gpu_upload and Host::gpu_upload_writes read from it. One log line gives the outcome: host copies of title buffers in GPU upload heaps, with supported, vendor, read_only and written.
  • switch::on_unless_off handles switches that are on by default (unset or any value but 0).
  • docs/gpu-memory.md covers the defaults and opt-outs (switch table, flowchart), the new measurements and why both copies default to video memory, plus the further step for the bitmap. The README names the opt-outs.
  • The benchmark lives in crates/victory-gpu/src/shadow/bench.rs. A test-only host::take_submission_us reads the submission timers.

Defaults and opt-outs

switch default where the host has GPU upload heaps 0
VICTORY_GPU_UPLOAD on: copies of read-only buffers in video memory every copy in system memory
VICTORY_GPU_UPLOAD_WRITES on NVIDIA (with the one above): copies of written buffers in video memory, with a mirror; 1 turns it on for any GPU written copies in system memory

On a host without GPU upload heaps (no Resizable BAR, older drivers or runtimes), every copy stays in system memory whatever the switches say. Copies past their share of the video memory budget (#2222) do too.

Caveat: the synthetic world frame in docs/gpu-memory.md (#2130) declares gigabytes of written ranges without marks, and the lazy mirror cost it more CPU time (708 → 950 ms). Translated shaders now mark their writes through views, so such ranges should be rare. A title that still has them can set VICTORY_GPU_UPLOAD_WRITES=0. No title run has been measured with the new default yet. VICTORY_GPU_TIMING=1 with and without VICTORY_GPU_UPLOAD=0 would show it.

Tests

  • New: host::tests::copies_are_in_video_memory_by_default_where_the_host_can, which checks the placement for each combination of host support and switch values, and switch::tests::a_switch_on_by_default_is_off_at_zero_only.
  • The tests that need the switches on already set them explicitly in a child process. victory-gpu's tests pass with the new default, with VICTORY_GPU_UPLOAD=0 and with VICTORY_GPU_UPLOAD_WRITES=0.
  • cargo test --workspace --exclude victory-shader --no-fail-fast and cargo test -p victory-shader --no-fail-fast -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_index pass apart from failures that also happen on the base on this machine:
    • descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views, checked on the base without this change;
    • the hardware shader checks in stride_tests and synthetic_tests; victory-shader is untouched here.
  • cargo clippy --workspace --all-targets, with and without --features victory-gpu/diagnostics: no warnings.

Written copies default to video memory on NVIDIA only

@MeMako measured #2120 and #2130 in the title on an AMD RX 9070 XT (in #2130). With written copies in video memory, a world frame's GPU time fell by only about 4–8 ms, while the mirrors added 38–54 ms to preparing and 29–37 ms to copy-back. NVIDIA cards gain much more, because their reads from system memory were the bottleneck. So VICTORY_GPU_UPLOAD_WRITES now defaults to on only where the adapter's vendor is NVIDIA (0x10DE). Set to 1, it turns written copies on for any GPU; 0 still turns them off. Read-only copies keep their default everywhere.

Memory cost

This PR trades memory for GPU time. A written copy in video memory keeps its mirror in system memory, so it adds memory rather than moving it. @kawaii-shakal measured this in the title on an RTX 5070 Ti (with #2389): video memory 6,112 → 7,326 MB, GPU memory in system memory 8,502 → 8,755 MB, and process commit 24,775 → 26,372 MB. Nearly all of the title's copied bytes are in buffers shaders write (#2120), so nearly all of that 1.2 GB keeps its mirror. It doesn't free RAM; VICTORY_GPU_UPLOAD_WRITES=0 keeps written copies out of video memory.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6615312829 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2870). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T22:46:59Z. --- Stacked on #2222 (→ #2130 → #2120): the copies in GPU upload heaps, their mirrors and the budget that sizes them come from there. All commits but the last are those PRs'; the last one is this change. ## Problem Slow host submissions of a few hundred compute dispatches (`slow host submission ms=497 lists=9 pipelines={~250 compute pipelines ...}`) spend their GPU time on shaders reading and writing host copies of title buffers. Those copies were in system memory unless `VICTORY_GPU_UPLOAD=1` (and `VICTORY_GPU_UPLOAD_WRITES=1`) were set, so every access crossed PCI Express: ~23 GB/s, against ~720 GB/s for video memory on an RTX 5070 Ti. The existing benchmarks timed one big copy. This adds one shaped like a title's compute passes, and decides the defaults from it. ## Measurements `shadow::bench::compute_heavy_submissions_by_copy_placement` (ignored; `cargo test --release -p victory-gpu --lib compute_heavy -- --ignored --nocapture`) goes through the copies' real paths: `shadow::find`, `Shadow::refresh`, `Shadow::gpu_writes`, `HostList` and `Host::execute`. One submission is 200 dispatches in 8 lists over six title buffers: four of 64 MiB made without unordered access, and two of 32 MiB that shaders write (320 MiB in all). Each dispatch reads 4 MiB of a read-only buffer, reads and writes 1 MiB of a written one, and reads 256 KiB more, with a UAV barrier after it. Shaders find what they wrote in one of two ways: - write marks: each store sets its page's bit where still clear, as translated shaders do; - snapshots of the declared ranges. Between submissions the title either leaves its data alone or writes 16 MiB of it, so the CPU's refresh cost through the BAR is counted. Each placement runs in its own child process, because the switches are read once per process. All of them must leave title memory the same. RTX 5070 Ti (driver 621.24), Ryzen 9 7900X, Windows 11. Each number is the median of three runs, each the median of 5 submissions, in ms. `total` is all of `Host::execute`: `prepare` (refreshes, snapshots) + `GPU` (the wait for it) + `copy-back` (including bringing written pages back from video memory): | copies | writes found by | title writes | total | prepare | GPU | copy-back | |---|---|---|---|---|---|---| | system memory | write marks | none | 59.7 | 0.0 | 44.0 | 15.7 | | system memory | write marks | 16 MiB per submission | 61.6 | 2.3 | 43.8 | 15.2 | | system memory | snapshots | none | 73.5 | 12.4 | 43.4 | 17.8 | | system memory | snapshots | 16 MiB per submission | 76.4 | 14.6 | 43.0 | 18.1 | | read-only copies in video memory | write marks | none | 31.0 | 0.0 | 15.7 | 15.1 | | read-only copies in video memory | write marks | 16 MiB per submission | 32.9 | 2.1 | 15.8 | 15.0 | | read-only copies in video memory | snapshots | none | 43.3 | 12.2 | 12.9 | 18.3 | | read-only copies in video memory | snapshots | 16 MiB per submission | 45.6 | 14.3 | 12.8 | 18.2 | | all copies in video memory | write marks | none | 31.7 | 0.0 | 12.0 | 19.6 | | all copies in video memory | write marks | 16 MiB per submission | 32.3 | 1.8 | 11.0 | 19.4 | | all copies in video memory | snapshots | none | 35.9 | 12.1 | 2.1 | 21.8 | | all copies in video memory | snapshots | 16 MiB per submission | 37.7 | 14.0 | 2.1 | 21.4 | - **Read-only copies in video memory** halve the submission with marks (60 → 31 ms) and cut 40% with snapshots (74 → 43). GPU time drops from 44 ms to 13-16, and nothing else changes. Refreshing through the BAR costs the same as refreshing system memory (2 ms for 16 MiB). - **Written copies in video memory as well** bring GPU time down to 11-12 ms with marks and 2 ms with snapshots. Bringing written pages back to their mirrors (48 MiB per submission here) adds 4 ms of copy-back. CPU and GPU together: - with marks it is even (31.7 / 32.3 ms against 31.0 / 32.9; within the spread between runs); - with snapshots it is 17% faster (36 against 43 ms); - the GPU's own time is a quarter lower with marks and a sixth of what it was with snapshots. - With all copies in video memory, marking takes about 9 of the 11-12 GPU ms. The written-pages bitmap is in system memory, and each store reads it across the bus. `docs/gpu-memory.md` lists this as a further step (not done here). Without that cost, the marked path would gain from written copies in video memory as the snapshot path does. ## What changed - `host::upload_placement(supported, nvidia, VICTORY_GPU_UPLOAD, VICTORY_GPU_UPLOAD_WRITES)` decides once per run, from `GPUUploadHeapSupported`, the adapter's vendor and the switches, where copies go. `Host::gpu_upload` and `Host::gpu_upload_writes` read from it. One log line gives the outcome: `host copies of title buffers in GPU upload heaps`, with `supported`, `vendor`, `read_only` and `written`. - `switch::on_unless_off` handles switches that are on by default (unset or any value but `0`). - `docs/gpu-memory.md` covers the defaults and opt-outs (switch table, flowchart), the new measurements and why both copies default to video memory, plus the further step for the bitmap. The README names the opt-outs. - The benchmark lives in `crates/victory-gpu/src/shadow/bench.rs`. A test-only `host::take_submission_us` reads the submission timers. ## Defaults and opt-outs | switch | default where the host has GPU upload heaps | `0` | |---|---|---| | `VICTORY_GPU_UPLOAD` | on: copies of read-only buffers in video memory | every copy in system memory | | `VICTORY_GPU_UPLOAD_WRITES` | on NVIDIA (with the one above): copies of written buffers in video memory, with a mirror; `1` turns it on for any GPU | written copies in system memory | On a host without GPU upload heaps (no Resizable BAR, older drivers or runtimes), every copy stays in system memory whatever the switches say. Copies past their share of the video memory budget (#2222) do too. Caveat: the synthetic world frame in `docs/gpu-memory.md` (#2130) declares gigabytes of written ranges without marks, and the lazy mirror cost it more CPU time (708 → 950 ms). Translated shaders now mark their writes through views, so such ranges should be rare. A title that still has them can set `VICTORY_GPU_UPLOAD_WRITES=0`. No title run has been measured with the new default yet. `VICTORY_GPU_TIMING=1` with and without `VICTORY_GPU_UPLOAD=0` would show it. ## Tests - New: `host::tests::copies_are_in_video_memory_by_default_where_the_host_can`, which checks the placement for each combination of host support and switch values, and `switch::tests::a_switch_on_by_default_is_off_at_zero_only`. - The tests that need the switches on already set them explicitly in a child process. `victory-gpu`'s tests pass with the new default, with `VICTORY_GPU_UPLOAD=0` and with `VICTORY_GPU_UPLOAD_WRITES=0`. - `cargo test --workspace --exclude victory-shader --no-fail-fast` and `cargo test -p victory-shader --no-fail-fast -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_index` pass apart from failures that also happen on the base on this machine: - `descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`, checked on the base without this change; - the hardware shader checks in `stride_tests` and `synthetic_tests`; `victory-shader` is untouched here. - `cargo clippy --workspace --all-targets`, with and without `--features victory-gpu/diagnostics`: no warnings. ### Written copies default to video memory on NVIDIA only @MeMako measured #2120 and #2130 in the title on an AMD RX 9070 XT (in #2130). With written copies in video memory, a world frame's GPU time fell by only about 4–8 ms, while the mirrors added 38–54 ms to preparing and 29–37 ms to copy-back. NVIDIA cards gain much more, because their reads from system memory were the bottleneck. So `VICTORY_GPU_UPLOAD_WRITES` now defaults to on only where the adapter's vendor is NVIDIA (`0x10DE`). Set to `1`, it turns written copies on for any GPU; `0` still turns them off. Read-only copies keep their default everywhere. ### Memory cost This PR trades memory for GPU time. A written copy in video memory keeps its mirror in system memory, so it adds memory rather than moving it. @kawaii-shakal measured this in the title on an RTX 5070 Ti (with #2389): video memory 6,112 → 7,326 MB, GPU memory in system memory 8,502 → 8,755 MB, and process commit 24,775 → 26,372 MB. Nearly all of the title's copied bytes are in buffers shaders write (#2120), so nearly all of that 1.2 GB keeps its mirror. It doesn't free RAM; `VICTORY_GPU_UPLOAD_WRITES=0` keeps written copies out of video memory.
kotekompotek commented 2026-11-25 23:05:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T22:52:45Z.

Review: COMMENTED


Scoped review (+3k, can't claim full coverage): this is the third piece of the video-memory-copies series after #2705's host-copy tracking and #2821's lock removal — the new budget.rs makes video-memory residency a budgeted resource rather than unconditional, which is the right gate for making it default. Points worth a maintainer look: (1) the fallback when the budget is exhausted — does a title buffer silently stay in shared memory, or stall; (2) interaction with the alias/copy-back page tracking — shadow.rs changes here sit next to the recently-merged guard fixes; (3) whether the default flips per-host or is probe-gated. The bulk is test coverage of the placement paths.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066084273 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2870#pullrequestreview-6066084273). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T22:52:45Z. **Review:** COMMENTED --- Scoped review (+3k, can't claim full coverage): this is the third piece of the video-memory-copies series after #2705's host-copy tracking and #2821's lock removal — the new budget.rs makes video-memory residency a budgeted resource rather than unconditional, which is the right gate for making it default. Points worth a maintainer look: (1) the fallback when the budget is exhausted — does a title buffer silently stay in shared memory, or stall; (2) interaction with the alias/copy-back page tracking — shadow.rs changes here sit next to the recently-merged guard fixes; (3) whether the default flips per-host or is probe-gated. The bulk is test coverage of the placement paths.
fuzeofficlal commented 2026-11-25 23:06:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T22:54:25Z.


Reviewed and benchmarked 8cbe37f4 on Windows 11 (RTX 5090 with GPU Upload Heaps + WARP fallback) against main (842b0cb):

Verification

  • cargo xtask policy (193 files ok), cargo clippy --locked -p victory-gpu --all-targets (default & --features diagnostics, 0 warnings).
  • RTX 5090 (GPU upload heaps enabled): budget::tests 5/5, switch::tests 2/2, shadow::tests 20/20 (2 ignored), resource::tests 18/18, draw::tests 20/20 passed.
  • WARP (VICTORY_D3D12_WARP=1, system-memory fallback): budget::tests 5/5, shadow::tests 20/20 (2 ignored), resource::tests 18/18, draw::tests 20/20 passed.

RTX 5090 --release Benchmarks

  • shadow::tests::reading_copies_in_video_and_system_memory (256 MiB shader read): system memory 7.47 ms (35.9 GB/s) / refresh 37.5 ms (7.1 GB/s) -> GPU upload heap 0.43 ms (624.7 GB/s, 17.4x faster) / refresh 54.4 ms (4.9 GB/s).
  • shadow::tests::written_copies_in_video_and_system_memory (256 MiB R+W): system memory 172.72 ms (1.6 GB/s) -> GPU upload heap 0.77 ms (347.0 GB/s, 224x faster); 64-page pull 0.132 ms, 1-page overhead 0.040 ms.
  • shadow::bench::compute_heavy_submissions_by_copy_placement (200 dispatches / 8 lists):
    • Write marks (no title writes): system 42.6 ms (GPU 28.6) -> read-only VRAM 28.5 ms (GPU 15.0) -> all VRAM 29.4 ms (GPU 13.0); with 16 MiB title writes: 44.5 ms -> 29.3 ms (-34%).
    • Snapshots (no title writes): system 52.9 ms (GPU 26.2) -> read-only VRAM 33.9 ms (GPU 8.6) -> all VRAM 29.6 ms (GPU 1.4 ms, -44% wall / 18.7x GPU speedup).

Audit Notes

  • D3D12_FEATURE_D3D12_OPTIONS16 OnceLock detection, VICTORY_GPU_UPLOAD=0 / VICTORY_GPU_UPLOAD_WRITES=0 override semantics, atomic UPLOAD_BYTES reservation with RegisterDestructionCallback return (give_back_upload), and mirror+video pull paths look solid.
  • Tiny non-blocking nit: host.rs:3816 own + size <= limit could use own.saturating_add(size) <= limit.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7176923914 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2870#issuecomment-7176923914). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T22:54:25Z. --- Reviewed and benchmarked `8cbe37f4` on Windows 11 (RTX 5090 with GPU Upload Heaps + WARP fallback) against `main` (`842b0cb`): ### Verification - `cargo xtask policy` (`193 files ok`), `cargo clippy --locked -p victory-gpu --all-targets` (default & `--features diagnostics`, 0 warnings). - **RTX 5090 (GPU upload heaps enabled)**: `budget::tests` 5/5, `switch::tests` 2/2, `shadow::tests` 20/20 (2 ignored), `resource::tests` 18/18, `draw::tests` 20/20 passed. - **WARP (`VICTORY_D3D12_WARP=1`, system-memory fallback)**: `budget::tests` 5/5, `shadow::tests` 20/20 (2 ignored), `resource::tests` 18/18, `draw::tests` 20/20 passed. ### RTX 5090 `--release` Benchmarks - `shadow::tests::reading_copies_in_video_and_system_memory` (256 MiB shader read): system memory `7.47 ms` (`35.9 GB/s`) / refresh `37.5 ms` (`7.1 GB/s`) -> GPU upload heap **`0.43 ms` (`624.7 GB/s`, 17.4x faster)** / refresh `54.4 ms` (`4.9 GB/s`). - `shadow::tests::written_copies_in_video_and_system_memory` (256 MiB R+W): system memory `172.72 ms` (`1.6 GB/s`) -> GPU upload heap **`0.77 ms` (`347.0 GB/s`, 224x faster)**; 64-page pull `0.132 ms`, 1-page overhead `0.040 ms`. - `shadow::bench::compute_heavy_submissions_by_copy_placement` (200 dispatches / 8 lists): - Write marks (no title writes): system `42.6 ms` (GPU `28.6`) -> read-only VRAM `28.5 ms` (GPU `15.0`) -> all VRAM `29.4 ms` (GPU `13.0`); with 16 MiB title writes: `44.5 ms` -> `29.3 ms` (**-34%**). - Snapshots (no title writes): system `52.9 ms` (GPU `26.2`) -> read-only VRAM `33.9 ms` (GPU `8.6`) -> all VRAM **`29.6 ms` (GPU `1.4 ms`, -44% wall / 18.7x GPU speedup)**. ### Audit Notes - `D3D12_FEATURE_D3D12_OPTIONS16` `OnceLock` detection, `VICTORY_GPU_UPLOAD=0` / `VICTORY_GPU_UPLOAD_WRITES=0` override semantics, atomic `UPLOAD_BYTES` reservation with `RegisterDestructionCallback` return (`give_back_upload`), and mirror+video pull paths look solid. - Tiny non-blocking nit: `host.rs:3816` `own + size <= limit` could use `own.saturating_add(size) <= limit`.
0xkn0wh3r3 commented 2026-11-26 05:04:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T04:37:10Z.


Thanks both. On the three points:

  1. Budget used up: no stall. Host::gpu_upload_buffer (host.rs) returns None once a new copy would pass UPLOAD_POOL's share of the budget, and the copy is made in system memory as before. The first time this happens it is logged once at info level ("host copies past their share of the video memory budget go to system memory"). The charge goes back when the buffer is destroyed (destruction callback), so later copies can use video memory again. On a host without destruction callbacks, copies stay in system memory.
  2. Page tracking: a buffer shaders write keeps a system-memory mirror next to its video-memory copy. The pages the GPU may have written are marked stale (Shadow::stale), and before any CPU read of a range (snapshot, compare, copy-back), Shadow::freshen brings those pages back from video memory in one GPU copy. So the guard and copy-back paths still read the mirror, and it's current when they do. Copies of buffers shaders only read have no mirror: the GPU never changes them, so nothing has to be copied back.
  3. When it turns on: it's probe-gated. It's on only where D3D12_OPTIONS16.GPUUploadHeapSupported is true (resizable BAR and a recent runtime), so hosts without it are unchanged. VICTORY_GPU_UPLOAD=0 keeps every copy in system memory, and VICTORY_GPU_UPLOAD_WRITES=0 keeps written buffers there while read-only copies still use video memory.

@fuzeofficlal: took the saturating_add nit in upload_fits.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182752135 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2870#issuecomment-7182752135). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T04:37:10Z. --- Thanks both. On the three points: 1. **Budget used up:** no stall. `Host::gpu_upload_buffer` (`host.rs`) returns `None` once a new copy would pass `UPLOAD_POOL`'s share of the budget, and the copy is made in system memory as before. The first time this happens it is logged once at info level ("host copies past their share of the video memory budget go to system memory"). The charge goes back when the buffer is destroyed (destruction callback), so later copies can use video memory again. On a host without destruction callbacks, copies stay in system memory. 2. **Page tracking:** a buffer shaders write keeps a system-memory mirror next to its video-memory copy. The pages the GPU may have written are marked stale (`Shadow::stale`), and before any CPU read of a range (snapshot, compare, copy-back), `Shadow::freshen` brings those pages back from video memory in one GPU copy. So the guard and copy-back paths still read the mirror, and it's current when they do. Copies of buffers shaders only read have no mirror: the GPU never changes them, so nothing has to be copied back. 3. **When it turns on:** it's probe-gated. It's on only where `D3D12_OPTIONS16.GPUUploadHeapSupported` is true (resizable BAR and a recent runtime), so hosts without it are unchanged. `VICTORY_GPU_UPLOAD=0` keeps every copy in system memory, and `VICTORY_GPU_UPLOAD_WRITES=0` keeps written buffers there while read-only copies still use video memory. @fuzeofficlal: took the `saturating_add` nit in `upload_fits`.
0xkn0wh3r3 commented 2026-11-26 07:01:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T06:38:52Z.


fb9ac25f limits the written-buffer default to NVIDIA, following @MeMako's RX 9070 XT run in #2130. There, written copies in video memory saved about 4–8 ms of GPU time in a world frame but added more than that to preparing and copy-back. With VICTORY_GPU_UPLOAD_WRITES unset, written copies now go to GPU upload heaps only where the adapter's vendor is NVIDIA. Set to 1, it turns them on for any GPU; 0 still turns them off. Read-only copies keep their default everywhere, and the placement log line now includes the adapter's vendor. The description, README and docs/gpu-memory.md say the same.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184637730 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2870#issuecomment-7184637730). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T06:38:52Z. --- fb9ac25f limits the written-buffer default to NVIDIA, following @MeMako's RX 9070 XT run in #2130. There, written copies in video memory saved about 4–8 ms of GPU time in a world frame but added more than that to preparing and copy-back. With `VICTORY_GPU_UPLOAD_WRITES` unset, written copies now go to GPU upload heaps only where the adapter's vendor is NVIDIA. Set to `1`, it turns them on for any GPU; `0` still turns them off. Read-only copies keep their default everywhere, and the placement log line now includes the adapter's `vendor`. The description, README and `docs/gpu-memory.md` say the same.
kawaii-shakal commented 2026-11-26 08:03:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kawaii-shakal on 2026-11-26T07:13:25Z.


A memory measurement of this PR in the title, together with #2389. Native Windows 11 26300, RTX 5070 Ti 16 GB (Resizable BAR), title 1.0.2.1, default console. Three diagnostics builds: main 63bcca4, main + #2389, and main + #2389 + this PR (577f40f). Defaults for this PR, and the log says supported=true vendor=0x10de read_only=true written=true. Same save, standing still in the world, read 120 s after the world appears, from the process's own video memory: line (QueryVideoMemoryInfo, GetProcessMemoryInfo) and the host copies of title memory line:

main + #2389 + #2389 + this PR
video memory on the card 6,512 MB 6,112 MB 7,326 MB
GPU memory in system memory 8,592 MB 8,502 MB 8,755 MB
process commit 25,341 MB 24,775 MB 26,372 MB
host copies of title memory 7,777 MB 7,684 MB 7,952 MB

About 1.2 GB of copies went to video memory, and GPU memory in system memory did not go down. I read that as the mirrors of written copies keeping the system-memory side, so commit rises by about 1.6 GB against #2389 alone. That fits the design: this PR is about GPU time, not memory. I'm noting it for anyone who picks it to free RAM: on this card it doesn't, even though the card has about 9 GB of budget left. I did not measure GPU time in this run.

🤖 Generated with Claude Code (Claude Opus 5.5)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7185226758 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2870#issuecomment-7185226758). Originally posted by [kawaii-shakal](https://github.com/kawaii-shakal) on 2026-11-26T07:13:25Z. --- A memory measurement of this PR in the title, together with #2389. Native Windows 11 26300, RTX 5070 Ti 16 GB (Resizable BAR), title 1.0.2.1, default console. Three diagnostics builds: `main` 63bcca4, `main` + #2389, and `main` + #2389 + this PR (577f40f). Defaults for this PR, and the log says `supported=true vendor=0x10de read_only=true written=true`. Same save, standing still in the world, read 120 s after the world appears, from the process's own `video memory:` line (`QueryVideoMemoryInfo`, `GetProcessMemoryInfo`) and the `host copies of title memory` line: | | `main` | + #2389 | + #2389 + this PR | |---|---|---|---| | video memory on the card | 6,512 MB | 6,112 MB | 7,326 MB | | GPU memory in system memory | 8,592 MB | 8,502 MB | 8,755 MB | | process commit | 25,341 MB | 24,775 MB | 26,372 MB | | host copies of title memory | 7,777 MB | 7,684 MB | 7,952 MB | About 1.2 GB of copies went to video memory, and GPU memory in system memory did not go down. I read that as the mirrors of written copies keeping the system-memory side, so commit rises by about 1.6 GB against #2389 alone. That fits the design: this PR is about GPU time, not memory. I'm noting it for anyone who picks it to free RAM: on this card it doesn't, even though the card has about 9 GB of budget left. I did not measure GPU time in this run. 🤖 Generated with [Claude Code](https://claude.com/claude-code) (Claude Opus 5.5)
0xkn0wh3r3 commented 2026-11-26 08:03:21 +00:00 (Migrated from github.com)

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


Thanks, that's the expected cost, and it's useful to have it measured in the title. A written copy in video memory keeps its mirror in system memory, so it adds memory rather than moving it. Per @MeMako's split on #2120, about 98% of the title's copied bytes are in buffers shaders write. So nearly all of the 1.2 GB that went to video memory still has its system-memory side, and commit rises instead of shifting. Only the read-only copies (about 23 MB there) actually move. I've added a "Memory cost" section to the description with your numbers, so nobody picks this to free RAM. VICTORY_GPU_UPLOAD_WRITES=0 keeps written copies out of video memory.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7185594457 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2870#issuecomment-7185594457). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T07:33:59Z. --- Thanks, that's the expected cost, and it's useful to have it measured in the title. A written copy in video memory keeps its mirror in system memory, so it adds memory rather than moving it. Per @MeMako's split on #2120, about 98% of the title's copied bytes are in buffers shaders write. So nearly all of the 1.2 GB that went to video memory still has its system-memory side, and commit rises instead of shifting. Only the read-only copies (about 23 MB there) actually move. I've added a "Memory cost" section to the description with your numbers, so nobody picks this to free RAM. `VICTORY_GPU_UPLOAD_WRITES=0` keeps written copies out of video memory.
upstream-sync closed this pull request 2026-11-26 09:05:23 +00:00
0xkn0wh3r3 commented 2026-11-26 09:06:03 +00:00 (Migrated from github.com)

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


Replaced by #3102, which combines this with the rest of the host-memory placement work in one PR, with measurements on a discrete and an integrated GPU. Closing here.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186177122 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2870#issuecomment-7186177122). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T08:05:38Z. --- Replaced by #3102, which combines this with the rest of the host-memory placement work in one PR, with measurements on a discrete and an integrated GPU. Closing here.

Pull request closed

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!2868
No description provided.