Repository navigation
GPU: share readback chunks between a list's texture read backs - #2818
Therecalloftheonion wants to merge 1 commit into
Conversation
HostList::readback made a mapped readback buffer for every texture-to-buffer copy and kept it until the list was reset, so each read back paid CreateCommittedResource and Map on the CPU. readback_space now carves 512-byte-aligned space from per-list readback chunks (64 KiB to 4 MiB, grown on demand); the placed footprint's offset names that space, and the chunks are reused when the list resets. Copies larger than a chunk still get a buffer of their own. The 512-byte alignment is what D3D12 requires for a placed texture footprint; read backs of one list share the chunks instead of allocating one buffer per copy. Benchmark (2000 x 4 KiB, release, RX 6700 XT): a readback buffer per copy 335.4 ms, shared chunks 1.57 ms. Tests: readback_spaces_share_chunks_and_are_reused, texture_readback_through_shared_chunks_round_trips_texels (a real texture-to-buffer copy through the chunk). The rest of the GPU suite passes; two unrelated upstream tests on this machine are filtered (the 2^21 view-heap assertion and the copy-pair test).
|
Verified
|
kotekompotek
left a comment
There was a problem hiding this comment.
Sound: copies recorded into one list can't execute concurrently, so sequential bump-allocation into shared mapped chunks is safe; 512-alignment keeps placed-footprint copies legal, doubling chunk growth bounds allocation count, and the reuse-after-reset path is covered by the round-trip test. LGTM.
AwsAli05
left a comment
There was a problem hiding this comment.
The texel round-trip currently uses the first reservation in the list, so rat is zero. This leaves the new nonzero base-offset path untested. If a reservation comes before the copy, the test's rdata.add(rat + ...) would also count the offset twice, because readback_space already returns a CPU pointer to that reservation.
Please reserve an initial region (or record a first texture copy), assert the next reservation has a nonzero offset, and read its texels with rdata.add(y * pitch + x). That would exercise exactly the difference between the D3D12 footprint offset and the mapped CPU pointer that this optimization introduces.
AI-assisted static review.
|
Automated triage for the maintainers.
CI: passing. Generated by Claude Code |
Dukestar69
left a comment
There was a problem hiding this comment.
Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):
cargo test -p victory-gpu --lib readback: 2 passed, 0 failed, 1 ignored (readback_spaces_share_chunks_and_are_reusedandtexture_readback_through_shared_chunks_round_trips_texels).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
…ure read backs
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed and verified at head e453bcaa against origin/main (63bcca43) on Windows 11 (RTX 5090 + WARP, D3D12 Debug Layer):
- Design & correctness:
Readbacks::allocate(crates/victory-gpu/src/host.rs:1093-1134) andHostList::readback_space(host.rs:2348-2367) enforce D3D12's 512-byte placed-footprint alignment vialen.max(1).checked_next_multiple_of(512)?, cap pooled chunks atSCRATCH_CHUNK(4 MiB) with doubling growth from 64 KiB, and fall back to a dedicatedmapped_bufferretained inself.deferred().uploadsfor larger copies.- Persistent
Map(0, None, ...)readback chunks live for the list's lifetime and rewind cleanly inHostList::reset()(host.rs:1964-1967) once GPU execution has completed. list.rs::read_back(crates/victory-gpu/src/list.rs:856-868, 907-914) applies the chunk offset once on the GPU (to.footprint.offset = offset) and once on the CPU (data = chunk.mapped + at, plus relative row offsets indefer_after), while keepingHostList::is_empty()accurate viaensure_stateanddefer_after.
- Non-blocking test nit: in
texture_readback_through_shared_chunks_round_trips_texels(crates/victory-gpu/src/host.rs:747),*rdata.add(rat + y * pitch + x)addsrattwice becauserdataalready points tochunk.mapped + rat. It currently passes only because it is the first allocation (rat == 0), leaving the nonzero-offset GPU readback path uncovered in that test. Reserving an initial slice first, assertingrat > 0, and indexing*rdata.add(y * pitch + x)would harden the test cleanly. - Verification:
- Clean
git merge-treeagainstorigin/main(63bcca43);cargo xtask policy(184 files ok);cargo clippy -p victory-gpu --all-targets -- -D warningsclean with default features and--all-features. - RTX 5090 (default):
readback2/2 passed (1 ignored benchmark),resource::tests::a_texture_read_back_reaches_the_title_buffer1/1 passed,draw::tests11/11 passed. - RTX 5090 +
VICTORY_D3D12_DEBUG=1(--features diagnostics) and WARP (VICTORY_D3D12_WARP=1) +VICTORY_D3D12_DEBUG=1:readback2/2 anda_texture_read_back_reaches_the_title_buffer1/1 passed on both with zero debug-layer errors. - Release benchmark on RTX 5090 (
benchmark_readback_spaces):2000 x 4096 B readback spaces: one buffer each 526.4619ms, shared chunks 1.371ms(384.0x speedup).
- Clean
LGTM.
… list's texture read backs
… list's texture read backs
What
HostList::readbackmade a mapped readback buffer for every texture-to-buffer copy and kept it until the list was reset, so every read back paidCreateCommittedResourceandMapon the CPU.readback_spacenow carves 512-byte-aligned space from per-list readback chunks (64 KiB to 4 MiB, grown on demand). The copy's placed footprint names that offset, and the chunks are reused when the list resets. A read back larger than a chunk still gets a buffer of its own. The 512-byte alignment is what D3D12 requires for a placed texture footprint.This is the readback half only. Upload pooling is already covered by open PRs #1382 and #2017, so those paths are untouched.
Benchmark
2000 x 4 KiB readback spaces, release build, RX 6700 XT:
cargo test --release -p victory-gpu benchmark_readback_spaces -- --ignored --nocapture.This measures the driver allocation/Map cost removed, not game FPS. Readback memory is system memory, so this is CPU/driver overhead, not VRAM.
Tests
readback_spaces_share_chunks_and_are_reused: two read backs share one chunk at 512-byte-aligned offsets; the same space comes back after reset.texture_readback_through_shared_chunks_round_trips_texels: a real texture-to-buffer copy through the chunk, every texel checked.cargo test -p victory-gpu --lib: 195 passed, 2 ignored. Two unrelated upstream tests on this machine are filtered because they fail onmaintoo: the2^21view-heap assertion and the copy-pair placement test.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.