Repository navigation
GPU: copies of read-only title buffers in GPU upload heaps (opt-in) - #2120
0xkn0wh3r3 wants to merge 2 commits into
Conversation
|
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:
Not measured on my side: the read-only share of those 1.2 GB. Your |
|
The 2 GiB allowance currently counts successful allocations across the lifetime of the process. On 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. |
catminou4
left a comment
There was a problem hiding this comment.
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).
|
@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 Regression test: @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 |
…mmit Marvisak#2130 was rewritten on top of Marvisak#2120's update, so layering it on the old merges kept two versions of it. This tree is upstream main (940d32f) with all 32 open PRs of 0xkn0wh3r3 at their current commits, the upstream fixes Marvisak#1887, Marvisak#1717, Marvisak#1832, Marvisak#1630, Marvisak#1763 and Marvisak#1613, and the demo-only conformance list; the old history stays as this merge's first parent.
…exture's first use) Taken in place of Marvisak#1969: with Marvisak#1969 a placed view used first made the memory's host texture with its own (fewer) uses, and the title texture the GPU writes then got another, so the placed view did not see the GPU's writes (draw test a_texture_written_in_one_format_reads_in_another _through_a_placed_view failed on WARP). Marvisak#2221's `lead` makes it as the title texture of the memory with the most uses. Conflicts in resource.rs: - hand_out_resource: kept layer 4's read-only buffer registration (Marvisak#2120); textures are counted as waiting and listed by memory at creation (Marvisak#2221). - alias_source: kept layer 4's order (cheap tests first, layouts last) with Marvisak#2221's made()/host_texture() in place of the host field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Needs work: needs the maintainer's decision. It now merges cleanly into Behind Remaining items:
#2130 and #2222 are stacked on this branch, so this one lands first. Generated by Claude Code |
resource.rs: read-only registration inside upstream's new host_desc condition. shadow.rs: upstream's arena fields and Marvisak#2120's upload flag; the arena serves offset views, Marvisak#2120 decides at whole-buffer copies (find). host.rs: Marvisak#2120's helper renamed copy_buffer, apart from upstream's new mapped_buffer (upload/readback). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f6R3kMoarujHzzA1AvSBb
772c567 to
3cf0e2a
Compare
|
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 Written with Claude Code; tested locally. |
|
Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP verification and review of Verification (
|
…ies, written copies, residency and the memory budget) into demo With Marvisak#2051, queued refreshes of a copy in video memory copy at once (`Shadow::copy` writes the video memory, not the mirror). With Marvisak#2226, textures in a title heap's host heap take that heap's residency priority (D3D12 gives placed resources none of their own), and Marvisak#2222's test makes its textures with no spot.
3cf0e2a to
2c9f789
Compare
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. 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_only` registers such buffers (`resource.rs`, from the title's `ALLOW_UNORDERED_ACCESS` flag), and `shadow::find` makes their copies with `Host::gpu_upload_buffer`; - copies past 2 GiB of video memory, and every copy on hosts without GPU upload heaps, stay in system memory, as before; - shaders that still write such a copy (through a view of the same memory under another resource) get it right, slowly: the copy-back reads video memory at ~50 MB/s; a warning names the first one. Measured on an RTX 5070 Ti (driver 621.24, Ryzen 9 7900X), 256 MiB, through `shadow::find` (`reading_copies_in_video_and_system_memory`): | copy | shader reads | refresh writes (first, every page) | |---|---|---| | writable buffer's (system memory) | 11.74 ms, 22.9 GB/s | 42.1 ms | | read-only buffer's (GPU upload heap) | 0.38 ms, 713 GB/s | 32.8 ms | 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. `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. The victory-gpu tests give the same results with the switch on and off.
The 2 GiB allowance for host copies in GPU upload heaps counted every copy made over the whole run and never took any back. After enough read- only buffers came and went (64 of 32 MiB on an RTX 3050 Laptop, with only one alive at a time), every later copy went to system memory for the rest of the run. A copy's bytes now leave the count when D3D12 destroys its buffer, through the buffer's destruction notifier. That is when the last reference goes (the copy's, and the clones lists and descriptor tables hold), not when the copy drops. A host without the notifier keeps copies in system memory instead of charging them for good. Test: upload_budget_is_given_back_when_copies_go. It makes 20 copies of 128 MiB one after another (2.5 GiB, past the budget). Each one is in a GPU upload heap, stays charged while a clone of its buffer is held after the copy dropped, and is given back once the clone goes. With the callback doing nothing, it fails in the first round.
2c9f789 to
b7e4a6f
Compare
|
Thanks. Rebased onto 63bcca4; head is now
Checks on |
Read-only buffers are told apart by the module's UNORDERED flag.
|
Independent AMD RDNA 4 verification + live title read-only share measurement of Setup: Windows 11 ( Checks & microbenchmark:
Live title run (
(Steady tail, last 20 heavy samples: GPU This confirms Machad3x's RTX 3080 Ti observation and directly explains why Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity. |
|
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. |
The 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 (NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #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 13f91ca
Host::mapped_buffer. This PR'smapped_buffer(size, upload), whichshared_bufferandgpu_upload_buffershare, is renamedshared_mapped_buffer.VICTORY_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 63bcca4
hand_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 (NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #1835).cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.cargo xtask policy: ok.