GPU: host copies of title buffers are in video memory by default where the host has GPU upload heaps #2870
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2870
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2870"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@0xkn0wh3r3 on GitHub · 2026-11-25 22:46 UTC · original
0xkn0wh3r3:gpu/video-memory-copies-by-default-2→main· +3055 −25 · 13 files · 10 commits · closed without mergingStacked 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 unlessVICTORY_GPU_UPLOAD=1(andVICTORY_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,HostListandHost::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: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.
totalis all ofHost::execute:prepare(refreshes, snapshots) +GPU(the wait for it) +copy-back(including bringing written pages back from video memory):docs/gpu-memory.mdlists 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, fromGPUUploadHeapSupported, the adapter's vendor and the switches, where copies go.Host::gpu_uploadandHost::gpu_upload_writesread from it. One log line gives the outcome:host copies of title buffers in GPU upload heaps, withsupported,vendor,read_onlyandwritten.switch::on_unless_offhandles switches that are on by default (unset or any value but0).docs/gpu-memory.mdcovers 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.crates/victory-gpu/src/shadow/bench.rs. A test-onlyhost::take_submission_usreads the submission timers.Defaults and opt-outs
0VICTORY_GPU_UPLOADVICTORY_GPU_UPLOAD_WRITES1turns it on for any GPUOn 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 setVICTORY_GPU_UPLOAD_WRITES=0. No title run has been measured with the new default yet.VICTORY_GPU_TIMING=1with and withoutVICTORY_GPU_UPLOAD=0would show it.Tests
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, andswitch::tests::a_switch_on_by_default_is_off_at_zero_only.victory-gpu's tests pass with the new default, withVICTORY_GPU_UPLOAD=0and withVICTORY_GPU_UPLOAD_WRITES=0.cargo test --workspace --exclude victory-shader --no-fail-fastandcargo test -p victory-shader --no-fail-fast -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_indexpass apart from failures that also happen on the base on this machine:descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views, checked on the base without this change;stride_testsandsynthetic_tests;victory-shaderis 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_WRITESnow defaults to on only where the adapter's vendor is NVIDIA (0x10DE). Set to1, it turns written copies on for any GPU;0still 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=0keeps written copies out of video memory.@kotekompotek on GitHub · 2026-11-25 22:52 UTC · original · reviewed
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 on GitHub · 2026-11-25 22:54 UTC · original
Reviewed and benchmarked
8cbe37f4on Windows 11 (RTX 5090 with GPU Upload Heaps + WARP fallback) againstmain(842b0cb):Verification
cargo xtask policy(193 files ok),cargo clippy --locked -p victory-gpu --all-targets(default &--features diagnostics, 0 warnings).budget::tests5/5,switch::tests2/2,shadow::tests20/20 (2 ignored),resource::tests18/18,draw::tests20/20 passed.VICTORY_D3D12_WARP=1, system-memory fallback):budget::tests5/5,shadow::tests20/20 (2 ignored),resource::tests18/18,draw::tests20/20 passed.RTX 5090
--releaseBenchmarksshadow::tests::reading_copies_in_video_and_system_memory(256 MiB shader read): system memory7.47 ms(35.9 GB/s) / refresh37.5 ms(7.1 GB/s) -> GPU upload heap0.43 ms(624.7 GB/s, 17.4x faster) / refresh54.4 ms(4.9 GB/s).shadow::tests::written_copies_in_video_and_system_memory(256 MiB R+W): system memory172.72 ms(1.6 GB/s) -> GPU upload heap0.77 ms(347.0 GB/s, 224x faster); 64-page pull0.132 ms, 1-page overhead0.040 ms.shadow::bench::compute_heavy_submissions_by_copy_placement(200 dispatches / 8 lists):42.6 ms(GPU28.6) -> read-only VRAM28.5 ms(GPU15.0) -> all VRAM29.4 ms(GPU13.0); with 16 MiB title writes:44.5 ms->29.3 ms(-34%).52.9 ms(GPU26.2) -> read-only VRAM33.9 ms(GPU8.6) -> all VRAM29.6 ms(GPU1.4 ms, -44% wall / 18.7x GPU speedup).Audit Notes
D3D12_FEATURE_D3D12_OPTIONS16OnceLockdetection,VICTORY_GPU_UPLOAD=0/VICTORY_GPU_UPLOAD_WRITES=0override semantics, atomicUPLOAD_BYTESreservation withRegisterDestructionCallbackreturn (give_back_upload), and mirror+video pull paths look solid.host.rs:3816own + size <= limitcould useown.saturating_add(size) <= limit.@0xkn0wh3r3 on GitHub · 2026-11-26 04:37 UTC · original
Thanks both. On the three points:
Host::gpu_upload_buffer(host.rs) returnsNoneonce a new copy would passUPLOAD_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.Shadow::stale), and before any CPU read of a range (snapshot, compare, copy-back),Shadow::freshenbrings 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.D3D12_OPTIONS16.GPUUploadHeapSupportedis true (resizable BAR and a recent runtime), so hosts without it are unchanged.VICTORY_GPU_UPLOAD=0keeps every copy in system memory, andVICTORY_GPU_UPLOAD_WRITES=0keeps written buffers there while read-only copies still use video memory.@fuzeofficlal: took the
saturating_addnit inupload_fits.@0xkn0wh3r3 on GitHub · 2026-11-26 06:38 UTC · original
fb9ac25flimits 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. WithVICTORY_GPU_UPLOAD_WRITESunset, written copies now go to GPU upload heaps only where the adapter's vendor is NVIDIA. Set to1, it turns them on for any GPU;0still turns them off. Read-only copies keep their default everywhere, and the placement log line now includes the adapter'svendor. The description, README anddocs/gpu-memory.mdsay the same.@kawaii-shakal on GitHub · 2026-11-26 07:13 UTC · original
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:
main63bcca4,main+ #2389, andmain+ #2389 + this PR (577f40f). Defaults for this PR, and the log sayssupported=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 ownvideo memory:line (QueryVideoMemoryInfo,GetProcessMemoryInfo) and thehost copies of title memoryline:mainAbout 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)
@0xkn0wh3r3 on GitHub · 2026-11-26 07:33 UTC · original
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=0keeps written copies out of video memory.@0xkn0wh3r3 on GitHub · 2026-11-26 08:05 UTC · original
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