GPU: share readback chunks between a list's texture read backs #2818
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!2818
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2818"
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?
@Therecalloftheonion on GitHub · 2026-11-25 21:26 UTC · original
Therecalloftheonion:pr/gpu-copy-arenas→main· +230 −10 · 2 files · 1 commits · openWhat
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.@fuzeofficlal on GitHub · 2026-11-25 21:40 UTC · original
Verified
e453bcaaon Windows 11 (RTX 5090 + WARP,--features diagnostics):cargo xtask policy: 184 files ok;cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default &--features diagnostics): 0 warnings.--releasebenchmark (benchmark_readback_spaces):2000 x 4096 B readback spaces: one buffer each 503.022ms, shared chunks 1.624ms(~310× speedup).--features diagnostics --test-threads=1): both new tests (readback_spaces_share_chunks_and_are_reusedandtexture_readback_through_shared_chunks_round_trips_texels) plusdraw::tests(11/11) passed;host/descriptor::host/pipeline::host27/28 passed (only pre-existing >1M heap-limitdynamic_slots_are_held_until_released).VICTORY_D3D12_WARP=1,--features diagnostics --test-threads=1): 200 passed, 0 failed, 2 ignored.len.max(1)),> SCRATCH_CHUNKfallback retaining buffer lifetime indeferred().uploads, single offset accounting (footprint.offset = offsetwithdata = chunk.mapped + at), and reset reuse onHostList::reset()all check out. Cleangit merge-treeagainstorigin/main13f91caand #2608.@Marvisak on GitHub · 2026-11-26 02:21 UTC · original
Automated triage for the maintainers.
HostList::readback_space(host.rs) gives texture-to-buffer read backs 512-byte-aligned space in per-list readback chunks, reused after the list resets, instead of a committed buffer per copy. Copies larger than a chunk still get their own buffer.list.rs::read_backpasses the offset into the placed footprint. The memory lives exactly as long as before (until reset). 512 bytes is D3D12's placement alignment for texture footprints. The tests include a real texture round trip through the chunk.CI: passing.
Generated by Claude Code
@kotekompotek on GitHub · 2026-11-25 21:58 UTC · original · reviewed
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 on GitHub · 2026-11-25 23:08 UTC · original · reviewed
The texel round-trip currently uses the first reservation in the list, so
ratis zero. This leaves the new nonzero base-offset path untested. If a reservation comes before the copy, the test'srdata.add(rat + ...)would also count the offset twice, becausereadback_spacealready 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.
@Dukestar69 on GitHub · 2026-11-26 02:47 UTC · original · approved these changes
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).
@fuzeofficlal on GitHub · 2026-11-26 11:56 UTC · original · approved these changes
Reviewed and verified at head
e453bcaaagainstorigin/main(63bcca43) on Windows 11 (RTX 5090 + WARP, D3D12 Debug Layer):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.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.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.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.readback2/2 passed (1 ignored benchmark),resource::tests::a_texture_read_back_reaches_the_title_buffer1/1 passed,draw::tests11/11 passed.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.benchmark_readback_spaces):2000 x 4096 B readback spaces: one buffer each 526.4619ms, shared chunks 1.371ms(384.0x speedup).LGTM.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.