Textures: VICTORY_TEXTURES_IN_PC=1 places streamed textures in system memory when the card is full #3070

Open
Adriwin06 wants to merge 3 commits from upstream-pr/3070 into main
Adriwin06 commented 2026-11-29 19:52:54 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Adriwin06 on 2026-11-29T19:52:54Z.


What it changes

Off by default. When a streamed texture's host copy cannot be placed
on the card (the budget has no room for it), VICTORY_TEXTURES_IN_PC=1
places it in system memory instead of failing the upload: in a
non-local (L0) custom heap where the adapter supports one, cut from a
pool of 16 MiB system-memory blocks (PC_TEXTURES, reclaimed with the
staging pool), or as a committed allocation of just the texture's size
when a new block would not fit. Admission keeps headroom in the shared
budget (pc_texture_room), the local-VRAM admission still comes first,
and a transient allocation failure is retried. The first spill is
logged once.

Tests: resource::system_texture_admission_keeps_shared_budget_headroom,
resource::system_texture_uses_a_nonlocal_heap_when_the_adapter_supports_it.

Ported from readmet3xt-lab/foxhound@7c53527 (readmet3xt-lab), ba04392
and 5b6ebb4 (dilim), GPL-3.0-or-later.

How it was tested

  • GPU and profile: RTX 4070 SUPER, Ryzen 7 5800X. Not measured in the title on these commits by themselves: they come from a fork of mine that carries them with the rest of this set, and the title ran there. What is below is the unit tests on this branch.
  • Before: n/a (no in-title measurement on this branch)
  • After: n/a
  • cargo test passed for the crates it touches:
    • this change: yes, cargo test -p victory-gpu --lib -- resource:: pool::: 73 passed. host::uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue fails now and then when it runs beside the resource:: tests, on main as on this branch (1 run in 4 on each here): it reads the process-wide UAV spare pool
  • cargo clippy --workspace --all-targets --locked: no finding that main does not already have (main has 34 of its own, which is why the Clippy step of CI is red on main itself).
  • cargo xtask policy: no new finding (main fails it on crates/victory-loader/src/heap_sites/frame_users.rs).
  • With all eleven of my pull requests merged together: cargo clippy also with --all-features adds no finding, and cargo test --workspace --locked fails only tests main also fails on this machine: the five shader tests that fail on main here too (WARP's SM 6.2 and the validator) (barycentric_tests::first_half_values_render_on_hardware_and_warp, hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity, intersect_tests::flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves, rect::tests::rectangles_are_drawn_whole, rect::tests::the_rectangle_stage_is_a_geometry_shader) and xtask's repository_passes_policy (frame_users.rs). 2208 passed, including five that fail on main (three BCPack oracle tests, the menu save race, the shader key test).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related:
    None found for placing streamed textures in system memory (searched "system memory textures", "spill", "L0"). Touches the same alignment line as #3069 (small-alignment) (one line to merge).

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5554485729 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3070). Originally posted by [Adriwin06](https://github.com/Adriwin06) on 2026-11-29T19:52:54Z. --- ## What it changes Off by default. When a streamed texture's host copy cannot be placed on the card (the budget has no room for it), VICTORY_TEXTURES_IN_PC=1 places it in system memory instead of failing the upload: in a non-local (L0) custom heap where the adapter supports one, cut from a pool of 16 MiB system-memory blocks (PC_TEXTURES, reclaimed with the staging pool), or as a committed allocation of just the texture's size when a new block would not fit. Admission keeps headroom in the shared budget (pc_texture_room), the local-VRAM admission still comes first, and a transient allocation failure is retried. The first spill is logged once. Tests: resource::system_texture_admission_keeps_shared_budget_headroom, resource::system_texture_uses_a_nonlocal_heap_when_the_adapter_supports_it. Ported from readmet3xt-lab/foxhound@7c53527 (readmet3xt-lab), ba04392 and 5b6ebb4 (dilim), GPL-3.0-or-later. ## How it was tested - GPU and profile: RTX 4070 SUPER, Ryzen 7 5800X. Not measured in the title on these commits by themselves: they come from a fork of mine that carries them with the rest of this set, and the title ran there. What is below is the unit tests on this branch. - Before: n/a (no in-title measurement on this branch) - After: n/a - `cargo test` passed for the crates it touches: - this change: yes, `cargo test -p victory-gpu --lib -- resource:: pool::`: 73 passed. host::uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue fails now and then when it runs beside the resource:: tests, on main as on this branch (1 run in 4 on each here): it reads the process-wide UAV spare pool - `cargo clippy --workspace --all-targets --locked`: no finding that main does not already have (main has 34 of its own, which is why the Clippy step of CI is red on main itself). - `cargo xtask policy`: no new finding (main fails it on crates/victory-loader/src/heap_sites/frame_users.rs). - With all eleven of my pull requests merged together: `cargo clippy` also with `--all-features` adds no finding, and `cargo test --workspace --locked` fails only tests main also fails on this machine: the five shader tests that fail on main here too (WARP's SM 6.2 and the validator) (barycentric_tests::first_half_values_render_on_hardware_and_warp, hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity, intersect_tests::flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves, rect::tests::rectangles_are_drawn_whole, rect::tests::the_rectangle_stage_is_a_geometry_shader) and xtask's repository_passes_policy (frame_users.rs). 2208 passed, including five that fail on main (three BCPack oracle tests, the menu save race, the shader key test). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: None found for placing streamed textures in system memory (searched "system memory textures", "spill", "L0"). Touches the same alignment line as #3069 (small-alignment) (one line to merge). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Copilot commented 2026-11-29 19:57:20 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Copilot on 2026-11-29T19:57:20Z.

Code review location: crates/victory-gpu/src/draw.rs; line 4455

@@ -4439,6 +4450,17 @@ impl State {
                 served = false;
                 break;
             }
+            if pc_room.is_some() && texture.is_none() {
+                tells.tell(index, write, Told::Held(frame + most));
+                continue;

If system-memory allocation is temporarily refused for a differently formatted view of a host-written texture, the retry can lose its source contents. seed_pending removes the seed before attempting allocation (texture.rs:869–880), so a later successful allocation has nothing to copy and title-memory uploads are skipped for this view. Preserve the seed until its copy is recorded, and keep the descriptor pending while seeding fails.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4732926489 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3070#discussion_r4732926489). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-29T19:57:20Z. **Code review location:** `crates/victory-gpu/src/draw.rs`; line 4455 ~~~~diff @@ -4439,6 +4450,17 @@ impl State { served = false; break; } + if pc_room.is_some() && texture.is_none() { + tells.tell(index, write, Told::Held(frame + most)); + continue; ~~~~ --- If system-memory allocation is temporarily refused for a differently formatted view of a host-written texture, the retry can lose its source contents. `seed_pending` removes the seed before attempting allocation (`texture.rs:869–880`), so a later successful allocation has nothing to copy and title-memory uploads are skipped for this view. Preserve the seed until its copy is recorded, and keep the descriptor pending while seeding fails.
Copilot commented 2026-11-29 19:57:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Copilot on 2026-11-29T19:57:21Z.

Code review location: crates/victory-gpu/src/pool.rs; line 1232

@@ -1185,44 +1220,56 @@ pub(crate) unsafe fn texture(
     } else {
         0
     };
-    let (pool, _) = pool_for(info.Alignment.max(1), small_apart());
+    let (pool, block_size) = match pc {
+        Some(_) => (&PC_TEXTURES, PC_BLOCK),
+        None => (pool_for(info.Alignment.max(1), small_apart()).0, BLOCK),
+    };
     #[cfg_attr(not(feature = "diagnostics"), allow(unused_variables))]
-    let (piece, heap, again) = take_from(pool, info.SizeInBytes, info.Alignment.max(1), Ripe::now, || {
+    let (piece, heap, again) = take_from_with_growth(pool, info.SizeInBytes, info.Alignment.max(1), || {
+        if pc.is_some() { Ripe::ALL } else { Ripe::now() }
+    }, || {
+        if pc.is_some_and(|(_, room)| room < block_size || crate::residency::critical_commit()) {
+            return BlockGrowth::Deferred;

room is a captured DXGI usage sample, but take_from_with_growth releases the pool lock before this check. Concurrent uploads can each allocate a 16 MiB block against the same 16 MiB allowance, crossing the 75% shared-budget ceiling; committed fallbacks in resource::host_texture_as share this issue. Reserve pending bytes across both allocation paths, release reservations on failure, and reconcile successful allocations with usage samples before admitting further growth.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4732926520 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3070#discussion_r4732926520). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-29T19:57:21Z. **Code review location:** `crates/victory-gpu/src/pool.rs`; line 1232 ~~~~diff @@ -1185,44 +1220,56 @@ pub(crate) unsafe fn texture( } else { 0 }; - let (pool, _) = pool_for(info.Alignment.max(1), small_apart()); + let (pool, block_size) = match pc { + Some(_) => (&PC_TEXTURES, PC_BLOCK), + None => (pool_for(info.Alignment.max(1), small_apart()).0, BLOCK), + }; #[cfg_attr(not(feature = "diagnostics"), allow(unused_variables))] - let (piece, heap, again) = take_from(pool, info.SizeInBytes, info.Alignment.max(1), Ripe::now, || { + let (piece, heap, again) = take_from_with_growth(pool, info.SizeInBytes, info.Alignment.max(1), || { + if pc.is_some() { Ripe::ALL } else { Ripe::now() } + }, || { + if pc.is_some_and(|(_, room)| room < block_size || crate::residency::critical_commit()) { + return BlockGrowth::Deferred; ~~~~ --- `room` is a captured DXGI usage sample, but `take_from_with_growth` releases the pool lock before this check. Concurrent uploads can each allocate a 16 MiB block against the same 16 MiB allowance, crossing the 75% shared-budget ceiling; committed fallbacks in `resource::host_texture_as` share this issue. Reserve pending bytes across both allocation paths, release reservations on failure, and reconcile successful allocations with usage samples before admitting further growth.
copilot-pull-request-reviewer[bot] commented 2026-11-29 19:57:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-29T19:57:21Z.

Review: COMMENTED


Critical issues can lose host-written texture contents during allocation retries and let concurrent allocations exceed the shared-memory budget ceiling.

2 open issues
What changed in this PR

Adds an opt-in system-memory fallback for streamed textures when local video-memory admission rejects them, extending the GPU upload path without changing default behavior.

Changes:

  • Adds VICTORY_TEXTURES_IN_PC=1 with shared-budget checks and non-local texture allocations.
  • Introduces 16 MiB texture pools, committed-allocation fallback, and upload retry handling with deferred descriptor publication.
  • Adds tests for shared-budget headroom, nested allocation scopes, and non-local heap placement.
File Description
crates/​victory-gpu/​src/​resource.rs Adds fallback admission, allocation scope, system-memory accounting, and tests.
crates/​victory-gpu/​src/​pool.rs Supports configurable block sizes and a reclaimable system-memory texture pool.
crates/​victory-gpu/​src/​draw.rs Integrates fallback selection, allocation retries, and deferred descriptor publication.

Review effort: Balanced

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6104536682 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3070#pullrequestreview-6104536682). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-29T19:57:21Z. **Review:** COMMENTED --- <!-- ccr-overview-v2 --> ### 🟡 Changes recommended Critical issues can lose host-written texture contents during allocation retries and let concurrent allocations exceed the shared-memory budget ceiling. <details open> <summary><strong>2 open issues</strong></summary> - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Preserve texture seed when allocation fails](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3070#discussion_r4732926489) · New - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Reserve shared budget during concurrent allocations](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3070#discussion_r4732926520) · New </details> <details> <summary><strong>What changed in this PR</strong></summary> Adds an opt-in system-memory fallback for streamed textures when local video-memory admission rejects them, extending the GPU upload path without changing default behavior. **Changes:** - Adds `VICTORY_TEXTURES_IN_PC=1` with shared-budget checks and non-local texture allocations. - Introduces 16 MiB texture pools, committed-allocation fallback, and upload retry handling with deferred descriptor publication. - Adds tests for shared-budget headroom, nested allocation scopes, and non-local heap placement. | File | Description | | ---- | ----------- | | `crates/​victory-gpu/​src/​resource.rs` | Adds fallback admission, allocation scope, system-memory accounting, and tests. | | `crates/​victory-gpu/​src/​pool.rs` | Supports configurable block sizes and a reclaimable system-memory texture pool. | | `crates/​victory-gpu/​src/​draw.rs` | Integrates fallback selection, allocation retries, and deferred descriptor publication. | </details> <sub>Review effort: Balanced</sub>
Adriwin06 commented 2026-11-30 01:10:19 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Adriwin06 on 2026-11-30T01:10:19Z.

Code review location: crates/victory-gpu/src/draw.rs; line 4455

@@ -4439,6 +4450,17 @@ impl State {
                 served = false;
                 break;
             }
+            if pc_room.is_some() && texture.is_none() {
+                tells.tell(index, write, Told::Held(frame + most));
+                continue;

Fixed in a8bec768: seed_pending now leaves the seed in SEEDS until the copy is recorded. Transient failures (no host texture yet, no buffer) keep it for the next use, a shape mismatch still drops it, and releases already clear it. In the texture pass, a system-memory slot is held while seed_waits(resource) is true, so title memory is not uploaded instead.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4734087464 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3070#discussion_r4734087464). Originally posted by [Adriwin06](https://github.com/Adriwin06) on 2026-11-30T01:10:19Z. **Code review location:** `crates/victory-gpu/src/draw.rs`; line 4455 ~~~~diff @@ -4439,6 +4450,17 @@ impl State { served = false; break; } + if pc_room.is_some() && texture.is_none() { + tells.tell(index, write, Told::Held(frame + most)); + continue; ~~~~ --- Fixed in a8bec768: `seed_pending` now leaves the seed in `SEEDS` until the copy is recorded. Transient failures (no host texture yet, no buffer) keep it for the next use, a shape mismatch still drops it, and releases already clear it. In the texture pass, a system-memory slot is held while `seed_waits(resource)` is true, so title memory is not uploaded instead.
Adriwin06 commented 2026-11-30 01:10:22 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Adriwin06 on 2026-11-30T01:10:22Z.

Code review location: crates/victory-gpu/src/pool.rs; line 1232

@@ -1185,44 +1220,56 @@ pub(crate) unsafe fn texture(
     } else {
         0
     };
-    let (pool, _) = pool_for(info.Alignment.max(1), small_apart());
+    let (pool, block_size) = match pc {
+        Some(_) => (&PC_TEXTURES, PC_BLOCK),
+        None => (pool_for(info.Alignment.max(1), small_apart()).0, BLOCK),
+    };
     #[cfg_attr(not(feature = "diagnostics"), allow(unused_variables))]
-    let (piece, heap, again) = take_from(pool, info.SizeInBytes, info.Alignment.max(1), Ripe::now, || {
+    let (piece, heap, again) = take_from_with_growth(pool, info.SizeInBytes, info.Alignment.max(1), || {
+        if pc.is_some() { Ripe::ALL } else { Ripe::now() }
+    }, || {
+        if pc.is_some_and(|(_, room)| room < block_size || crate::residency::critical_commit()) {
+            return BlockGrowth::Deferred;

Fixed in e5fc66e9: each system-memory block (in the pool's growth closure) and each committed fallback now takes a PcReservation. It adds its bytes to PC_ALLOCATING first, takes a fresh DXGI sample, and goes ahead only if what is in use plus every allocation under way stays under 75% of the shared budget (fits_shared). The bytes are given back when the reservation drops, once the allocation is made (the next sample counts it) or refused. Regression test: allocations_under_way_share_one_allowance.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4734087594 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3070#discussion_r4734087594). Originally posted by [Adriwin06](https://github.com/Adriwin06) on 2026-11-30T01:10:22Z. **Code review location:** `crates/victory-gpu/src/pool.rs`; line 1232 ~~~~diff @@ -1185,44 +1220,56 @@ pub(crate) unsafe fn texture( } else { 0 }; - let (pool, _) = pool_for(info.Alignment.max(1), small_apart()); + let (pool, block_size) = match pc { + Some(_) => (&PC_TEXTURES, PC_BLOCK), + None => (pool_for(info.Alignment.max(1), small_apart()).0, BLOCK), + }; #[cfg_attr(not(feature = "diagnostics"), allow(unused_variables))] - let (piece, heap, again) = take_from(pool, info.SizeInBytes, info.Alignment.max(1), Ripe::now, || { + let (piece, heap, again) = take_from_with_growth(pool, info.SizeInBytes, info.Alignment.max(1), || { + if pc.is_some() { Ripe::ALL } else { Ripe::now() } + }, || { + if pc.is_some_and(|(_, room)| room < block_size || crate::residency::critical_commit()) { + return BlockGrowth::Deferred; ~~~~ --- Fixed in e5fc66e9: each system-memory block (in the pool's growth closure) and each committed fallback now takes a `PcReservation`. It adds its bytes to `PC_ALLOCATING` first, takes a fresh DXGI sample, and goes ahead only if what is in use plus every allocation under way stays under 75% of the shared budget (`fits_shared`). The bytes are given back when the reservation drops, once the allocation is made (the next sample counts it) or refused. Regression test: `allocations_under_way_share_one_allowance`.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3070:upstream-pr/3070'
git switch 'upstream-pr/3070'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3070'
git switch 'upstream-pr/3070'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3070'
git switch 'upstream-pr/3070'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3070'
git switch 'main'
git merge --squash 'upstream-pr/3070'
git switch 'main'
git merge --ff-only 'upstream-pr/3070'
git switch 'main'
git merge 'upstream-pr/3070'
git push origin 'main'
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!3070
No description provided.