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

Closed
github-bot wants to merge 2 commits from github-bot/gh-4827 into main AGit
Owner

@⁠BitWuehler on GitHub · 2026-12-01 10:25 UTC · original
BitWuehler:fix/dynamic-texture-cap-pool-reuse → main · +668 −107 · 3 files · 2 commits · closed without merging

Refs #4237

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: #4769, #4455, #4340, #4200 (none of them credit reusable pool ranges in the dynamic VRAM reserve check).
**@⁠BitWuehler** on GitHub · 2026-12-01 10:25 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4827) `BitWuehler:fix/dynamic-texture-cap-pool-reuse` → `main` · +668 −107 · 3 files · 2 commits · closed without merging Refs #4237 ## 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: #4769, #4455, #4340, #4200 (none of them credit reusable pool ranges in the dynamic VRAM reserve check).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 10:30:36 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-12-01 10:52 UTC · original

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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-12-01 10:52 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4827#issuecomment-7308851244) 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.
Address review feedback on #4827:

- Resolve the actual PC D3D12 `(SizeInBytes, Alignment)` via
  `pool_placement_for_view` / `pool::texture_placement_info` when checking
  reuse inside `VICTORY_TEXTURE_KEEP_FREE_MB`, and query only the specific
  pool (`TEXTURES` vs `SMALL`) that `pool_for` selects for that alignment via
  `can_reuse_texture_range` (`Pool::can_place_without_growth`), respecting
  alignment padding inside free ranges and non-pooled texture shapes.
- Classify first-upload admission into `FirstUploadGrowth::{Normal,
  WithinReserve, ReuseOnly}` and scope it across host-texture creation in
  `draw.rs`:
  - `ReuseOnly` declines both pool block growth (`BlockGrowth::Deferred` ->
    `PoolTexture::Deferred` -> `HostTextureMade::Deferred` ->
    `Err(TextureDeferred)`) and committed/tiled fallbacks if a concurrent
    upload took the reusable range first, keeping the slot due without
    marking `CREATION_REFUSED` or starting OOM backoff.
  - `WithinReserve` checks `may_grow_texture_pool(BLOCK)` (and committed byte
    size on unpooled fallbacks) so a small upload admitted near the boundary
    cannot grow a new 64 MiB heap into the reserve either.
- Add unit tests for the `SMALL` vs `TEXTURES` 4 MiB / 64 KiB-aligned split,
  unaligned range remainders under `VICTORY_POOL_SMALL_APART=0`, raced
  `ReuseOnly` deferral without backoff, and `HostTextureMade::Deferred`
  preserving retry eligibility without OOM cooldown.
Author
Owner

@⁠BitWuehler on GitHub · 2026-12-01 12:24 UTC · original

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.

**@⁠BitWuehler** on GitHub · 2026-12-01 12:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4827#issuecomment-7311076169) 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.
github-bot closed this pull request 2026-12-01 18:36:27 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:31 UTC · original

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.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:31 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4827#issuecomment-7321075922) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

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