Admit first-time texture uploads that reuse existing pool ranges at the dynamic VRAM reserve #4827

Closed
BitWuehler wants to merge 2 commits from upstream-pr/4827 into main
BitWuehler commented 2026-12-01 10:25:42 +00:00 (Migrated from github.com)

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 computed others = used.saturating_sub(total) and rejected every first upload where total + reserve > budget - keep - others (equivalent to used + reserve + keep > budget) before consulting the texture pools.

Because DXGI used already includes the entire allocated 64 MiB texture pool heaps (including their free ranges), whereas HOST_TEXTURES[1] (total) counts only individual host textures, free space inside already-allocated pool blocks was counted as non-texture card usage. Once used + keep >= budget, every first-time texture upload was refused (logged under refused by an explicit byte limit, forcing placements onto VICTORY_SMALL_WHEN_FULL 256 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):

  • Fast path under budget - keep: when used + max(reserve, 64 KiB) + keep <= budget (or keep == 0), the upload passes as WithinReserve / Normal without querying GetResourceAllocationInfo or touching pool locks.
  • Exact pool & D3D12 alignment match inside the reserve (b3ca3736): when used + max(reserve, 64 KiB) + keep > budget, pool_placement_for_view constructs the exact PC D3D12_RESOURCE_DESC (honoring held_only base level, format conversion, and pool-eligibility rules), queries pool::texture_placement_info (GetResourceAllocationInfo), and checks pool::can_reuse_texture_range(alloc_size, alloc_align) (Pool::can_place_without_growth) against the specific pool (TEXTURES vs SMALL) that pool_for selects under VICTORY_POOL_SMALL_APART, including alignment padding inside free ranges. Free space in SMALL never admits a 64 KiB-aligned upload targeting TEXTURES.
  • Allocation-time guard for raced ranges (b3ca3736): draw.rs scopes FirstUploadGrowth across host-texture creation:
    • ReuseOnly declines 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 marking CREATION_REFUSED or triggering residency::allocation_error / pool growth backoff, and suppressing speculative short_ahead block allocation.
    • WithinReserve checks may_grow_texture_pool(BLOCK) (and committed byte size for unpooled fallbacks) so a small upload admitted just below budget - keep cannot allocate a new 64 MiB heap across the reserve either.
  • Keeps dynamic_texture_cap unchanged for sweep_idle, and leaves make_small (up to 97% budget) and direct SRV host_copy paths unchanged.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing):
    • Problem observed in play logs at 7d93ee07 on RTX 5080 16 GB (driver 620.73.04, Ryzen 7 9800X3D, Linux / GE-Proton 11-14 vkd3d-proton master, Series X, 1440p, DLSS Balanced, DLSS Frame Generation 2x, ray tracing off), where first-upload room decisions logged up to 14,127 refused by an explicit byte limit per 5 s window (0 allowed) with no explicit VICTORY_TEXTURE_BUDGET_MB set.
    • Unit and host-allocation tests run at b3ca3736 (branched from main 5fabb46e); an isolated single-variable in-game A/B run of b3ca3736 alone has not been measured yet.
  • Before: used + reserve + keep > budget unconditionally refused first uploads even when the target pool already held a usable free range.
  • After: dynamic_reserve_decision admits ReuseOnly uploads only when the exact target pool (SMALL vs TEXTURES) has an aligned range for the actual D3D12 allocation, and texture_for_upload / try_host_texture cleanly defer (Err(TextureDeferred)) if another upload takes that range first.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes).
  • cargo test passed for the crates it touches: yes — at b3ca3736:
    • cargo test --locked -p victory-gpu --lib --target x86_64-pc-windows-msvc under 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, and resource::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) and git diff --check.

(Prepared with AI assistance.)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #4768, #4454, #4339, #4199 (none of them credit reusable pool ranges in the dynamic VRAM reserve check).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5583759292 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4827). Originally posted by [BitWuehler](https://github.com/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 computed `others = used.saturating_sub(total)` and rejected every first upload where `total + reserve > budget - keep - others` (equivalent to `used + reserve + keep > budget`) before consulting the texture pools. Because DXGI `used` already includes the entire allocated 64 MiB texture pool heaps (including their free ranges), whereas `HOST_TEXTURES[1]` (`total`) counts only individual host textures, free space inside already-allocated pool blocks was counted as non-texture card usage. Once `used + keep >= budget`, every first-time texture upload was refused (logged under `refused by an explicit byte limit`, forcing placements onto `VICTORY_SMALL_WHEN_FULL` 256 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`): - **Fast path under `budget - keep`**: when `used + max(reserve, 64 KiB) + keep <= budget` (or `keep == 0`), the upload passes as `WithinReserve` / `Normal` without querying `GetResourceAllocationInfo` or touching pool locks. - **Exact pool & D3D12 alignment match inside the reserve (`b3ca3736`)**: when `used + max(reserve, 64 KiB) + keep > budget`, `pool_placement_for_view` constructs the exact PC `D3D12_RESOURCE_DESC` (honoring `held_only` base level, format conversion, and pool-eligibility rules), queries `pool::texture_placement_info` (`GetResourceAllocationInfo`), and checks `pool::can_reuse_texture_range(alloc_size, alloc_align)` (`Pool::can_place_without_growth`) against the specific pool (`TEXTURES` vs `SMALL`) that `pool_for` selects under `VICTORY_POOL_SMALL_APART`, including alignment padding inside free ranges. Free space in `SMALL` never admits a 64 KiB-aligned upload targeting `TEXTURES`. - **Allocation-time guard for raced ranges (`b3ca3736`)**: `draw.rs` scopes `FirstUploadGrowth` across host-texture creation: - `ReuseOnly` declines 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 marking `CREATION_REFUSED` or triggering `residency::allocation_error` / pool growth backoff, and suppressing speculative `short_ahead` block allocation. - `WithinReserve` checks `may_grow_texture_pool(BLOCK)` (and committed byte size for unpooled fallbacks) so a small upload admitted just below `budget - keep` cannot allocate a new 64 MiB heap across the reserve either. - Keeps `dynamic_texture_cap` unchanged for `sweep_idle`, and leaves `make_small` (up to 97% budget) and direct SRV `host_copy` paths unchanged. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): - Problem observed in play logs at `7d93ee07` on RTX 5080 16 GB (driver 620.73.04, Ryzen 7 9800X3D, Linux / GE-Proton 11-14 `vkd3d-proton master`, Series X, 1440p, DLSS Balanced, DLSS Frame Generation 2x, ray tracing off), where `first-upload room decisions` logged up to `14,127 refused by an explicit byte limit` per 5 s window (`0 allowed`) with no explicit `VICTORY_TEXTURE_BUDGET_MB` set. - Unit and host-allocation tests run at `b3ca3736` (branched from `main` `5fabb46e`); an isolated single-variable in-game A/B run of `b3ca3736` alone has not been measured yet. - Before: `used + reserve + keep > budget` unconditionally refused first uploads even when the target pool already held a usable free range. - After: `dynamic_reserve_decision` admits `ReuseOnly` uploads only when the exact target pool (`SMALL` vs `TEXTURES`) has an aligned range for the actual D3D12 allocation, and `texture_for_upload` / `try_host_texture` cleanly defer (`Err(TextureDeferred)`) if another upload takes that range first. - For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes). - `cargo test` passed for the crates it touches: yes — at `b3ca3736`: - `cargo test --locked -p victory-gpu --lib --target x86_64-pc-windows-msvc` under 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`, and `resource::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`) and `git diff --check`. (Prepared with AI assistance.) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #4768, #4454, #4339, #4199 (none of them credit reusable pool ranges in the dynamic VRAM reserve check).
andrewpozdnakov7-jpg commented 2026-12-01 10:52:32 +00:00 (Migrated from github.com)

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 default VICTORY_POOL_SMALL_APART, those can be different pools.

Using the exact 454be948 helpers 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 selected TEXTURES, which had zero space in the fixture. The real allocator can then try to grow that pool. Reserve check · Pool selection and allocation

The 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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7308851244 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4827#issuecomment-7308851244). Originally posted by [andrewpozdnakov7-jpg](https://github.com/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 default `VICTORY_POOL_SMALL_APART`, those can be different pools. Using the exact `454be948` helpers 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 selected `TEXTURES`, which had zero space in the fixture. The real allocator can then try to grow that pool. [Reserve check](https://github.com/trustno1-coder/VIctory-NVIDIA/blob/454be9480ccab4156307ccff5c3ea874cde1734e/crates/victory-gpu/src/resource.rs#L2613) · [Pool selection and allocation](https://github.com/trustno1-coder/VIctory-NVIDIA/blob/454be9480ccab4156307ccff5c3ea874cde1734e/crates/victory-gpu/src/pool.rs#L1257) The 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.
BitWuehler commented 2026-12-01 12:24:01 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by BitWuehler on 2026-12-01T12:24:01Z.


Thanks @andrewpozdnakov7-jpg — great catch on both the SMALL vs TEXTURES split under VICTORY_POOL_SMALL_APART and the race window if another upload claims the range before placement.

Fixed in b3ca3736:

  1. Exact D3D12 placement & target-pool check at admission (resource.rs, pool.rs):
    • Inside the dynamic reserve (used + max(reserve, 64 KiB) + keep > budget), pool_placement_for_view builds the same PC D3D12_RESOURCE_DESC (including held_only base-mip selection, format mapping, and pool-eligibility / non-tiled checks) and queries pool::texture_placement_info (GetResourceAllocationInfo) for the actual (SizeInBytes, Alignment).
    • pool::can_reuse_texture_range(len, align) selects the exact pool via pool_for(align, small_apart()) and checks Pool::can_place_without_growth(len, align, ...) (including alignment rounding within free ranges and BLOCK / 2 vs BLOCK limits). With 64 MiB free in SMALL and 0 in TEXTURES, a 4 MiB / 64 KiB-aligned upload now sees can_reuse = false and is refused.
  2. Allocation-time deferral when a reusable range was raced (pool.rs, resource.rs, draw.rs):
    • room_for_first_upload returns Option<FirstUploadGrowth> (Normal, WithinReserve, ReuseOnly), scoped across host-texture creation in draw.rs.
    • ReuseOnly short-circuits growth in take_from_detailed / texture_for_upload (PoolTexture::Deferred -> HostTextureMade::Deferred -> Err(TextureDeferred)), blocks fallthrough to CreateCommittedResource or tiles, suppresses speculative short_ahead heap creation, and leaves the slot due (CREATION_REFUSED untouched, no pool/residency OOM backoff).
    • WithinReserve also checks may_grow_texture_pool(BLOCK) (and committed byte size on unpooled fallbacks) so a small upload admitted just below budget - keep cannot allocate a 64 MiB heap across the reserve.

Added unit/host tests covering your exact 4 MiB SMALL vs TEXTURES fixture, unaligned range remainders under VICTORY_POOL_SMALL_APART=0, raced ReuseOnly deferral without backoff, and HostTextureMade::Deferred keeping the texture retry-eligible without OOM cooldown.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7311076169 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4827#issuecomment-7311076169). Originally posted by [BitWuehler](https://github.com/BitWuehler) on 2026-12-01T12:24:01Z. --- Thanks @andrewpozdnakov7-jpg — great catch on both the `SMALL` vs `TEXTURES` split under `VICTORY_POOL_SMALL_APART` and the race window if another upload claims the range before placement. Fixed in `b3ca3736`: 1. **Exact D3D12 placement & target-pool check at admission (`resource.rs`, `pool.rs`)**: - Inside the dynamic reserve (`used + max(reserve, 64 KiB) + keep > budget`), `pool_placement_for_view` builds the same PC `D3D12_RESOURCE_DESC` (including `held_only` base-mip selection, format mapping, and pool-eligibility / non-tiled checks) and queries `pool::texture_placement_info` (`GetResourceAllocationInfo`) for the actual `(SizeInBytes, Alignment)`. - `pool::can_reuse_texture_range(len, align)` selects the exact pool via `pool_for(align, small_apart())` and checks `Pool::can_place_without_growth(len, align, ...)` (including alignment rounding within free ranges and `BLOCK / 2` vs `BLOCK` limits). With 64 MiB free in `SMALL` and 0 in `TEXTURES`, a 4 MiB / 64 KiB-aligned upload now sees `can_reuse = false` and is refused. 2. **Allocation-time deferral when a reusable range was raced (`pool.rs`, `resource.rs`, `draw.rs`)**: - `room_for_first_upload` returns `Option<FirstUploadGrowth>` (`Normal`, `WithinReserve`, `ReuseOnly`), scoped across host-texture creation in `draw.rs`. - `ReuseOnly` short-circuits growth in `take_from_detailed` / `texture_for_upload` (`PoolTexture::Deferred` -> `HostTextureMade::Deferred` -> `Err(TextureDeferred)`), blocks fallthrough to `CreateCommittedResource` or `tiles`, suppresses speculative `short_ahead` heap creation, and leaves the slot due (`CREATION_REFUSED` untouched, no pool/residency OOM backoff). - `WithinReserve` also checks `may_grow_texture_pool(BLOCK)` (and committed byte size on unpooled fallbacks) so a small upload admitted just below `budget - keep` cannot allocate a 64 MiB heap across the reserve. Added unit/host tests covering your exact 4 MiB `SMALL` vs `TEXTURES` fixture, unaligned range remainders under `VICTORY_POOL_SMALL_APART=0`, raced `ReuseOnly` deferral without backoff, and `HostTextureMade::Deferred` keeping the texture retry-eligible without OOM cooldown.
trustno1-coder commented 2026-12-01 18:31:11 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321075922 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4827#issuecomment-7321075922). Originally posted by [trustno1-coder](https://github.com/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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!4827
No description provided.