Admit first-time texture uploads that reuse existing pool ranges at the dynamic VRAM reserve #4827
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4827"
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 BitWuehler on 2026-12-01T10:25:42Z.
Refs #4236
What it changes
In
room_for_first_upload(crates/victory-gpu/src/resource.rs), the dynamic VRAM reserve check (VICTORY_TEXTURE_KEEP_FREE_MB, default 512 MiB) previously computedothers = used.saturating_sub(total)and rejected every first upload wheretotal + reserve > budget - keep - others(equivalent toused + reserve + keep > budget) before consulting the texture pools.Because DXGI
usedalready includes the entire allocated 64 MiB texture pool heaps (including their free ranges), whereasHOST_TEXTURES[1](total) counts only individual host textures, free space inside already-allocated pool blocks was counted as non-texture card usage. Onceused + keep >= budget, every first-time texture upload was refused (logged underrefused by an explicit byte limit, forcing placements ontoVICTORY_SMALL_WHEN_FULL256 KiB mips), even when an existing free range in the target texture pool could hold the texture without allocating a new block or growing card memory.This replaces that flat rejection with
dynamic_reserve_decision+FirstUploadGrowth(crates/victory-gpu/src/{resource,pool,draw}.rs):budget - keep: whenused + max(reserve, 64 KiB) + keep <= budget(orkeep == 0), the upload passes asWithinReserve/Normalwithout queryingGetResourceAllocationInfoor touching pool locks.b3ca3736): whenused + max(reserve, 64 KiB) + keep > budget,pool_placement_for_viewconstructs the exact PCD3D12_RESOURCE_DESC(honoringheld_onlybase level, format conversion, and pool-eligibility rules), queriespool::texture_placement_info(GetResourceAllocationInfo), and checkspool::can_reuse_texture_range(alloc_size, alloc_align)(Pool::can_place_without_growth) against the specific pool (TEXTURESvsSMALL) thatpool_forselects underVICTORY_POOL_SMALL_APART, including alignment padding inside free ranges. Free space inSMALLnever admits a 64 KiB-aligned upload targetingTEXTURES.b3ca3736):draw.rsscopesFirstUploadGrowthacross host-texture creation:ReuseOnlydeclines pool heap growth (BlockGrowth::Deferred->PoolTexture::Deferred->HostTextureMade::Deferred->Err(TextureDeferred)) as well as tiled/committed fallbacks if a concurrent upload took the reusable range first, keeping the slot due without markingCREATION_REFUSEDor triggeringresidency::allocation_error/ pool growth backoff, and suppressing speculativeshort_aheadblock allocation.WithinReservechecksmay_grow_texture_pool(BLOCK)(and committed byte size for unpooled fallbacks) so a small upload admitted just belowbudget - keepcannot allocate a new 64 MiB heap across the reserve either.dynamic_texture_capunchanged forsweep_idle, and leavesmake_small(up to 97% budget) and direct SRVhost_copypaths unchanged.How it was tested
7d93ee07on RTX 5080 16 GB (driver 620.73.04, Ryzen 7 9800X3D, Linux / GE-Proton 11-14vkd3d-proton master, Series X, 1440p, DLSS Balanced, DLSS Frame Generation 2x, ray tracing off), wherefirst-upload room decisionslogged up to14,127 refused by an explicit byte limitper 5 s window (0 allowed) with no explicitVICTORY_TEXTURE_BUDGET_MBset.b3ca3736(branched frommain5fabb46e); an isolated single-variable in-game A/B run ofb3ca3736alone has not been measured yet.used + reserve + keep > budgetunconditionally refused first uploads even when the target pool already held a usable free range.dynamic_reserve_decisionadmitsReuseOnlyuploads only when the exact target pool (SMALLvsTEXTURES) has an aligned range for the actual D3D12 allocation, andtexture_for_upload/try_host_texturecleanly defer (Err(TextureDeferred)) if another upload takes that range first.cargo testpassed for the crates it touches: yes — atb3ca3736:cargo test --locked -p victory-gpu --lib --target x86_64-pc-windows-msvcunder Wine/ntsync (pool::tests::pool_selection_does_not_credit_small_pool_free_space_to_64k_aligned_uploads,pool::tests::deferred_growth_declines_without_backoff_when_reusable_range_was_taken,resource::tests::dynamic_reserve_admits_first_uploads_that_reuse_existing_pool_ranges,resource::tests::deferred_reserve_placement_keeps_texture_eligible_without_oom_cooldown,first_upload, andresource::tests::host_texture_oom_cools_down_then_recovers: 15 passed, 0 failed)cargo check --locked -p victory-gpu --features diagnostics --target x86_64-pc-windows-msvc(0 warnings)cargo clippy --locked -p victory-gpu --lib --tests --target x86_64-pc-windows-msvc(exit 0, 0 findings)cargo run --locked -p xtask -- policy(464 files ok) andgit diff --check.(Prepared with AI assistance.)
Checked for overlap
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by andrewpozdnakov7-jpg on 2026-12-01T10:52:32Z.
I found one case where the new reserve check admits an upload that can't use the free range it counted.
texture_widest_free()takes the maximum across the two texture pools.pool::texture()selects a specific pool using the actual D3D12 alignment. With the defaultVICTORY_POOL_SMALL_APART, those can be different pools.Using the exact
454be948helpers with an in-memory fixture, I set the budget to 13,400 MiB, use to 13,000 MiB and the reserve to 512 MiB. A 4 MiB upload passed with 64 MiB free entirely in the small pool. With a 64 KiB alignment the same upload selectedTEXTURES, which had zero space in the fixture. The real allocator can then try to grow that pool. Reserve check · Pool selection and allocationThe reuse exception needs the pool and alignment of the actual placement. The allocation must still be able to decline that exception when the reusable range has been taken by another upload. The fixture covered the admission decision and pool selection.
AI-assisted with OpenAI Codex.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by BitWuehler on 2026-12-01T12:24:01Z.
Thanks @andrewpozdnakov7-jpg — great catch on both the
SMALLvsTEXTURESsplit underVICTORY_POOL_SMALL_APARTand the race window if another upload claims the range before placement.Fixed in
b3ca3736:resource.rs,pool.rs):used + max(reserve, 64 KiB) + keep > budget),pool_placement_for_viewbuilds the same PCD3D12_RESOURCE_DESC(includingheld_onlybase-mip selection, format mapping, and pool-eligibility / non-tiled checks) and queriespool::texture_placement_info(GetResourceAllocationInfo) for the actual(SizeInBytes, Alignment).pool::can_reuse_texture_range(len, align)selects the exact pool viapool_for(align, small_apart())and checksPool::can_place_without_growth(len, align, ...)(including alignment rounding within free ranges andBLOCK / 2vsBLOCKlimits). With 64 MiB free inSMALLand 0 inTEXTURES, a 4 MiB / 64 KiB-aligned upload now seescan_reuse = falseand is refused.pool.rs,resource.rs,draw.rs):room_for_first_uploadreturnsOption<FirstUploadGrowth>(Normal,WithinReserve,ReuseOnly), scoped across host-texture creation indraw.rs.ReuseOnlyshort-circuits growth intake_from_detailed/texture_for_upload(PoolTexture::Deferred->HostTextureMade::Deferred->Err(TextureDeferred)), blocks fallthrough toCreateCommittedResourceortiles, suppresses speculativeshort_aheadheap creation, and leaves the slot due (CREATION_REFUSEDuntouched, no pool/residency OOM backoff).WithinReservealso checksmay_grow_texture_pool(BLOCK)(and committed byte size on unpooled fallbacks) so a small upload admitted just belowbudget - keepcannot allocate a 64 MiB heap across the reserve.Added unit/host tests covering your exact 4 MiB
SMALLvsTEXTURESfixture, unaligned range remainders underVICTORY_POOL_SMALL_APART=0, racedReuseOnlydeferral without backoff, andHostTextureMade::Deferredkeeping the texture retry-eligible without OOM cooldown.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:31:11Z.
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed