GPU: copies of read-only title buffers in GPU upload heaps (opt-in) #2120
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!2120
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2120"
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 05:30 UTC · original
0xkn0wh3r3:gpu/upload-heap-copies→main· +457 −10 · 3 files · 2 commits · closed without mergingThe problem
Shaders read title buffers about 30 times slower than the console's GPU does.
Host copies of title buffers are in system memory (
Host::shared_buffer: a custom heap, write-back, memory pool L0), so that the CPU can refresh them and read back what shaders write. Every shader read of a copy then crosses PCIe. On an RTX 5070 Ti a shader reads 256 MiB from such a copy at 22.9 GB/s, and from video memory at 713 GB/s. The console's memory is one pool, and the GPU reads it at video memory speed.The fix
A buffer the title makes without unordered access is one shaders only read: nothing reads its copy back, and the CPU only writes it (refreshes). Its copy can be in video memory the CPU writes through the PCI BAR: a GPU upload heap (
D3D12_HEAP_TYPE_GPU_UPLOAD,D3D12_OPTIONS16, on hosts with resizable BAR).With
VICTORY_GPU_UPLOAD=1:shadow::register_read_onlyregisters such buffers (resource.rs, from the title'sALLOW_UNORDERED_ACCESSflag), andshadow::findmakes their copies withHost::gpu_upload_buffer.Measured on an RTX 5070 Ti (driver 621.24, Ryzen 9 7900X), 256 MiB, through
shadow::find(reading_copies_in_video_and_system_memory):Off by default: how much of a world frame's GPU time this is depends on which buffers the title makes without unordered access, which needs a run of the title to measure.
How to try it
Set
VICTORY_GPU_UPLOAD=1beforevictory run. The log says whether it is on (host copies that shaders only read in GPU upload heaps). It needs resizable BAR enabled (Windows 11 or a recent Agility SDK runtime). A world-frame comparison with and without it (GPU time per frame,VICTORY_GPU_TIMING=1) is what would tell whether to turn it on by default.Testing
read_only_buffers_get_their_copies_in_video_memory(in a child process with the switch on): checks that a read-only buffer's copy is in a GPU upload heap, that the GPU reads what a refresh wrote there, and that a writable buffer's copy stays in system memory.reading_copies_in_video_and_system_memoryis the benchmark behind the table above (ignored by default; run in release with--ignored --nocapture).cargo test -p victory-gpu --lib, with and withoutVICTORY_GPU_UPLOAD=1: 142 passed, the same 2 failing as onmainon this GPU (#1835). The victory-gpu tests give the same results with the switch on and off.cargo clippy -p victory-gpu --all-targetswith and without--features diagnostics: clean.Related
Rebased onto
13f91caHost::mapped_buffer. This PR'smapped_buffer(size, upload), whichshared_bufferandgpu_upload_buffershare, is renamedshared_mapped_buffer.c4e022daddsVICTORY_COPIES_IN_VIDEO_MEMORY=1, a diagnostics switch that puts every shared buffer, copies shaders write included, in a GPU upload heap to measure the cost of reads across the bus. CPU reads of those copies become slow, so it is for that measurement only and does not replace this PR. This PR puts only copies of read-only buffers in video memory, so copy-back still reads system memory.Rebased onto
63bcca4hand_out_resourcetests the title's flags againstresource.rs's existingUNORDEREDconstant instead of a localALLOW_UNORDERED_ACCESS = 0x4(folded into the first commit).cargo test -p victory-gpu --lib, with and withoutVICTORY_GPU_UPLOAD=1: 231 passed, the same 2 failing as onmainon this GPU (#1835).cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.cargo xtask policy: ok.github-bot referenced this pull request2026-11-26 05:07:28 +00:00
github-bot referenced this pull request2026-11-26 05:17:22 +00:00
@desplmfao on GitHub · 2026-11-25 05:31 UTC · original
Thanks for the bandwidth numbers. The 22.9 vs 713 GB/s comparison is very useful. Some context from the #2112 side, in case it helps decide how the two fit together:
maintoday: those already live inshared_buffer(custom heap, L0, system memory). So in place doesn't make shader reads slower than now. It only removes the copy and its refreshes. This PR is the one that makes reads faster.QueryVideoMemoryInfobudget), and in place otherwise. Both touchshadow::find, so whichever lands second will need a small rebase. I'm happy to do that on my side.Not measured on my side: the read-only share of those 1.2 GB. Your
register_read_onlywould give that directly if a run logs it.@Dathinel on GitHub · 2026-11-25 05:38 UTC · original
The 2 GiB allowance currently counts successful allocations across the lifetime of the process. On
e8df416I repeatedly registered one synthetic 32 MiB read-only buffer, calledshadow::find, inspected its heap type, then unregistered it and dropped the last shadow reference before the next iteration. I verified that itsWeakreference expired each time.With the production budget and counter unchanged on an RTX 3050 Laptop, allocations 1–64 used GPU upload heaps; 65 and 66 used system memory. This can permanently disable the fast path after enough resource turnover even when very few shadows are live at once.
If the intent is an outstanding-allocation cap, successful reservations need a matching release. A separate one-page-headroom control still fell back while the first shadow was held; experimentally returning its charge on final shadow drop allowed the next allocation to use GPU upload again. When choosing the release point, consider that the descriptor path also clones the underlying D3D resource. The test establishes budget exhaustion, not leaked VRAM.
AI-assisted. Synthetic buffers only.
@0xkn0wh3r3 on GitHub · 2026-11-25 06:13 UTC · original
@Dathinel thanks, good catch. The allowance was meant to cap outstanding copies, and it never took any back. Fixed in 772c567.
A copy's bytes now leave the count when D3D12 destroys its buffer: the buffer's
ID3DDestructionNotifiercallback gives the charge back. That covers your point about the descriptor path. The copy, lists and descriptor tables all hold clones of the same resource, so the charge stays until the last one goes, not just until theShadowdrops. A host without the notifier keeps these copies in system memory rather than charging them for good.Regression test:
upload_budget_is_given_back_when_copies_go. It makes 20 copies of 128 MiB, one after another (2.5 GiB in all, past the 2 GiB budget). Each copy lands in a GPU upload heap, stays charged while a clone of its buffer is held after theShadowdropped, and is given back once the clone goes. With the callback doing nothing, it fails in the first round.cargo test -p victory-gpu --libis unchanged with and withoutVICTORY_GPU_UPLOAD=1, apart from the two NVIDIA #1835 failures.@desplmfao thanks, that fits. Measured against the budget rather than a fixed 2 GiB, the two paths make a natural split: a GPU upload copy while video memory has room, in place otherwise. The fixed 2 GiB is already marked as a shortcut in the code for that reason. I'm happy for whichever lands second to take the small rebase in
shadow::find. Logging the read-only share of the 1.2 GB throughregister_read_onlyis a good idea; I'll add that when this comes out of draft.@Marvisak on GitHub · 2026-11-25 16:18 UTC · original · edited 2026-11-25 19:25 UTC
Automated triage for the maintainers.
Needs work: needs the maintainer's decision. It now merges cleanly into
main. CI: not run on this head.Behind
VICTORY_GPU_UPLOAD=1, this puts host copies of title buffers made without unordered access into GPU upload heaps:Host::gpu_upload_bufferinhost.rs, andregister_read_only/findinshadow.rs. The 2 GiB budget is now given back throughID3DDestructionNotifierwhen a buffer is destroyed, which fixes the turnover problem raised in this thread.Shadow::updateonly writes the copy on refresh paths. A GPU write that does reach such a copy is still correct but slow, and it logs a warning.Remaining items:
rerun_with_gpu_uploadspawns the test binary as a child process, which needs the maintainer's decision.hand_out_resourcedeclares a localALLOW_UNORDERED_ACCESS = 0x4, butresource.rsalready hasUNORDEREDfor the same flag. Please reuse it.mainalready has the diagnostics switchVICTORY_COPIES_IN_VIDEO_MEMORYfor all copies. A title measurement with this narrower switch (on its own, without #2130) would make the case for adding it. The read-only share log you mentioned would help too.#2130 and #2222 are stacked on this branch, so this one lands first.
Generated by Claude Code
@Machad3x on GitHub · 2026-11-25 19:41 UTC · original
Setup: RTX 3080 Ti (driver 621.24), Windows 11, resizable BAR, a local stack of open PRs merged with main
67e8ae1.1df99a6 has one conflict in
shadow.rs(register, rewritten here around a split buffer index), and test entries made by hand needread_only: false.victory-gputests pass. At one scene of an 8-minute game run withVICTORY_GPU_UPLOAD=1: frame 919 to 881 ms, GPU step 577 to 557 ms (means of 20 reports, one run each, so within run-to-run variation). No device removal.Written with Claude Code; tested locally.
@fuzeofficlal on GitHub · 2026-11-25 19:50 UTC · original
Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP verification and review of
3cf0e2ae(on13f91ca):Verification (
rustc 1.98.1MSVC)cargo xtask policy: 184 files ok;cargo clippy --locked -p victory-gpu --all-targets(default &--features diagnostics): 0 warnings.VICTORY_D3D12_WARP=1,--features diagnostics --test-threads=1): 200 passed, 0 failed, 2 ignored with bothVICTORY_GPU_UPLOADunset and=1(includingread_only_buffers_get_their_copies_in_video_memoryandupload_budget_is_given_back_when_copies_go).shadow::tests10 passed, 0 failed, 1 ignored (both unset andVICTORY_GPU_UPLOAD=1),draw::tests11 passed, 0 failed.Review & Ecosystem Note (#2120 vs #2130 vs #2705)
ID3DDestructionNotifierbudget refunding on actual D3D12 resource destruction, and safe fallback on unexpected writes.DEFAULTVRAM + staging DMA for writable buffers and non-ReBAR GPUs) once #2705 skips buffers already placed inGPU_UPLOAD.@0xkn0wh3r3 on GitHub · 2026-11-26 00:27 UTC · original
Thanks. Rebased onto
63bcca4; head is nowb7e4a6f6.ALLOW_UNORDERED_ACCESS = 0x4: gone.hand_out_resourcenow testsdesc.flags & UNORDEREDagainst the existing constant (crates/victory-gpu/src/resource.rs:1765, constant at:1139; both are#[cfg(windows)]). Folded into the first commit,4941d712.rerun_with_gpu_uploadchild process: your call. The switches are read once per process (OnceLock), which is why the tests re-run themselves.Checks on
b7e4a6f6(RTX 5070 Ti, driver 621.24):cargo test -p victory-gpu --libwith and withoutVICTORY_GPU_UPLOAD=1gives 231 passed, with the same 2 failures as onmainhere (#1835).cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.cargo xtask policy: ok. #2130 and #2222 are rebased on top.@catminou4 on GitHub · 2026-11-25 05:48 UTC · original · reviewed
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Read-only title buffers copied into GPU upload heaps — upload-heap placement for RO buffers; pairs with #2130's written-buffer path (complementary, not dupes).
@MeMako on GitHub · 2026-11-26 04:37 UTC · original
Independent AMD RDNA 4 verification + live title read-only share measurement of
#2120(b7e4a6fvia#2130'seff9f91):Setup: Windows 11 (
10.0.26200), Ryzen 9 7950X, AMD Radeon RX 9070 XT (RDNA 4, driver32.0.32029.2010, Resizable BAR enabled, 16 GB VRAM), local integration branch onorigin/main63bcca4with#2051+#2472+#2918+#1010.Checks & microbenchmark:
cargo clippy -p victory-gpu -p victory --all-targets --locked -- -D warnings(default &--all-features): clean.cargo test -p victory-gpu --locked: 264 passed, 0 failed (includingread_only_buffers_get_their_copies_in_video_memoryandupload_budget_is_given_back_when_copies_go).reading_copies_in_video_and_system_memory(256 MiB, release):51.2 GB/s) shader reads;64.6 ms(4.2 GB/s) refresh writes427.2 GB/s, 8.3x) shader reads;65.9 ms(4.1 GB/s) refresh writesLive title run (
VICTORY_GPU_UPLOAD=1,VICTORY_GPU_UPLOAD_WRITESoff, 11.5 min):shadow::buffers()stat):UNORDERED == 0):3,163buffers =22.8 MB(2.1%)UNORDERED != 0):650–718buffers =1,080.5 MB(97.9%)>=4,000draws/frame):copies)2.20 fps)69.8 ms / 149 MB)VICTORY_GPU_UPLOAD=12.10 fps)64.8 ms / 138 MB)(Steady tail, last 20 heavy samples: GPU
155.1 → 164.9 ms, frame414.1 → 469.8 ms.)This confirms Machad3x's RTX 3080 Ti observation and directly explains why
#2120alone shows no measurable world-frame GPU speedup: ~98% of the title's copied buffer bytes are created withALLOW_UNORDERED_ACCESS, leaving only ~23 MB eligible for the read-only path. Keeping it opt-in (or as the foundation for writable-buffer VRAM paths) makes sense given that share.Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.
@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