GPU: pool persistently mapped ReadBack buffers and fix texback hazards #876
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!876
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Starchaser1024 on GitHub · 2026-11-28 08:25 UTC · original
Starchaser1024:fix/texback-pool-and-hazards→main· +929 −90 · 4 files · 1 commits · closed without mergingSummary
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.Fix two GPU-to-CPU texture readback coherency bugs and eliminate per-frame D3D12_HEAP_TYPE_READBACK allocation, footprint query, map/unmap, and scratch allocation churn across VICTORY_TEXTURE_BACK and VICTORY_READ_BACK: - card_steps::writers: push Writer { shadow: None } for every range in flight.texture_back_ranges so holder refuses to copy stale pre-compute Shadow bytes while a flight's texture readback has not yet landed. - host::joinable: include deferred.texture_backs ranges in written so part joining never prepares CPU reads (Step::Fill / Step::Copy / Step::Texture) ahead of an earlier part's pending texture readback. - texback::ReadBack: pool persistently mapped D3D12_HEAP_TYPE_READBACK buffers bucketed by size.max(4096).next_power_of_two(), capped at 64 MiB (32 MiB on limited host RAM), trimmed under allocator_trim and host memory pressure, gated by VICTORY_READBACK_POOL (default 1). Recycle straight to the pool on HostList::reset() after fence completion and retire via host::retire on Drop so aborted/unreset lists never race in-flight GPU copies. - texback::record / land: cache Arc<Footprints> per texture shape and reuse a 4 MiB-capped thread-local tiling buffer, removing per-readback COM GetCopyableFootprints, Map/Unmap, and 512 KiB heap zero-fills. - Add unit tests for card_steps::writers + holder, host::joinable, ReadBack pool/retire/footprints invariants, and a 50-iteration RTX 5060 Ti GPU bit-exactness test & A/B benchmark (38.14 ms -> 7.79 ms end-to-end, 4.90x; 30.31 ms -> 0.67 ms CPU record+reset, 45.48x).GPU: pool persistently mapped ReadBack buffers and fix texback hazardsto [pr-fix][pr-performance][memory][NVIDIA] GPU: pool persistently mapped ReadBack buffers and fix texback hazards6dc6a5ed2cto1da999c40c[pr-fix][pr-performance][memory][NVIDIA] GPU: pool persistently mapped ReadBack buffers and fix texback hazardsto GPU: pool persistently mapped ReadBack buffers and fix texback hazardsPull request closed