GPU: pool persistently mapped ReadBack buffers and fix texback hazards #876
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/876"
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?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Starchaser1024 on 2026-11-28T08:25:30Z.
Summary
Fixes two GPU-to-CPU texture readback coherency hazards and eliminates steady-state
D3D12_HEAP_TYPE_READBACKresource creation/destruction,GetCopyableFootprintsCOM calls,Map/Unmap, and tiling heap allocations acrossVICTORY_TEXTURE_BACKandVICTORY_READ_BACK(both on by default).Coherency Fixes
card_steps::writers(crates/victory-gpu/src/host/card_steps.rs):Host::send_laterecordssent.texture_back_rangesintoline.writtenbecause compute-written textures (such as the ocean height and displacement maps) are not tiled into title memory untiltexback::landruns on flight landing.card_steps::writerspreviously pushedWriter { shadow: None }forflight.lists[i].host().deferred().backswhile omittingflight.texture_back_ranges, allowingcard_steps::holderto serve stale pre-compute bytes from any coveringShadowbuffer beforetexback::landcompleted.host::joinable(crates/victory-gpu/src/host.rs):joinable(VICTORY_JOIN_PARTS) previously checkeddeclared_writes,deferred.writes, anddeferred.backs, omittingdeferred.texture_backs. Includingdeferred.texture_backsprevents merging partN(writing a readback texture) with partN + 1reading overlapping title bytes on the CPU (Step::Fill,Step::Copy,Step::Texture).Readback Pooling & Zero-Alloc Tiling (
crates/victory-gpu/src/texback.rs,host.rs,list.rs)texback::ReadBack: persistently mappedD3D12_HEAP_TYPE_READBACKbuffers (Maponce at creation,Unmapon final drop), bucketed bysize.max(4096).next_power_of_two(), capped at64 MiB(32 MiBon limited host RAM), trimmed underallocator_trimand cleared underresidency::pressured(), gated byVICTORY_READBACK_POOL(default1).ReadBack::recyclereturns completed buffers straight toREADBACK_POOLinsideHostList::reset()/list::recycle(ranlists), whereasDrop for ReadBackretires buffers viahost::retireso aborted or unreset lists never race in-flight GPUCopyTextureRegion/CopyBufferRegionwrites.texback::record&texback::land: cachesArc<Footprints>keyed by(Width, Height, DepthOrArraySize, MipLevels, Format)(0steady-stateGetCopyableFootprintscalls orVecallocations) and reuses a4 MiB-capped thread-local tiling buffer instead ofvec![0u8; size]per readback.Benchmark & Verification (RTX 5060 Ti 16 GB, Windows 11)
texback::tests::gpu_texback_and_read_backs_bit_exact_and_pool_benchmark(50 iterations of256x256R32G32_FLOAT512 KiBCopyTextureRegion+Swizzle::SW_4KB_Stiling viatexback::land+5x2RGBA32Fexposureread_backs+HostList::reset(), verifying bit-exact detiled texels and pitched row preservation):VICTORY_READBACK_POOL=0VICTORY_READBACK_POOL=1--releaserecord + reset(50 iters)609.3 usmedian)14.5 usmedian)42.0xmedian)--release750.8 usmedian)149.1 usmedian)5.04xmedian)debugrecord + reset(50 iters)918.6 usmedian)51.0 usmedian)18.0xmedian)host::card_steps::tests::flight_texture_back_ranges_refuse_stale_shadow_holder: pass.host::batch::joinable_waits_for_texture_backs_and_joins_disjoint_parts: pass.cargo test -p victory-gpu --locked: 458 passed, 0 failed.cargo clippy --workspace --all-targets --all-features --locked: 0 warnings in changed files.cargo xtask policy: 294 files ok.Pull request closed