GPU: prototype idle mip reclamation with retained texture versions #1153

Open
github-bot wants to merge 2 commits from github-bot/gh-1153 into main AGit
Owner

@⁠ilyaux on GitHub · 2026-11-25 21:50 UTC · original
ilyaux:fix/reclaim-mip-levels → main · +638 −23 · 7 files · 2 commits · draft

Problem and proposal

Draft for design feedback, related to #898. Validation of the new reclamation path is limited to synthetic textures on WARP; native NVIDIA and retail-title runs are pending.

Levels-on-demand copies retain backing for mip levels the title no longer holds until the entire host copy is destroyed. This adds an opt-in VICTORY_LEVELS_RECLAIM=1 path, alongside VICTORY_LEVELS_ON_DEMAND=1, which replaces eligible idle copies while keeping old readers valid.

  • Keep the resource dimensions and mip numbering. A replacement starts with fresh staging state and uploads the retained levels.
  • Keep the original resource and its tiles for old descriptors and recorded/in-flight lists. Indexed views switch after the replacement upload's submission fence completes. A newly recorded table selects the retained mip range.
  • Exclude GPU-written or claimed levels and copies with pending deferred users. Keep a packed mip tail together.
  • Reuse free tiles in existing, device-matched pool heaps at a full physical budget without growing the pool. An explicit logical texture byte limit still applies.

The sweep follows the existing idle grace for borrowed host_resource references. Reclamation can be delayed by old readers or insufficient reusable pool space. The feature is off by default.

Dependency and attribution

This draft carries LeonardoS11's #795 as its first commit, reapplied from 32772d93ea1ec529a8508d08e980c3867c2701ff with the original author metadata and message preserved:

  1. bf41d7a12528b8fad5ad2093d4813b04f62f8319: #795's backing-lifetime fix.
  2. b472041c778420d2d4397957d18d65ab62624464: reclamation, pool reuse, regressions and documentation.

The native RTX 3080 Ti results in the carried commit message belong to the original author's report. They are not validation performed for this draft. The second commit contains the new work; the dependency commit can be dropped once #795 lands.

Validation

Tested head: b472041c778420d2d4397957d18d65ab62624464, based on main at 9c184b35b43de3455b74ac1770e1c8734a047810.

Windows 11; rustc/cargo 1.98.1; WARP, tiled resources tier 3. The D3D12 debug layer is not installed.

With VICTORY_D3D12_WARP=1 and VICTORY_TILES_TEST_CARD=0:

Check Result
cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1 --skip depth_bounds_pipeline_loads_and_filters_draws --skip warp_budget_saturates_without_wraparound_and_preserves_draw_fields 202 passed, 0 failed, 6 ignored, 2 excluded
cargo test --locked -p victory-gpu --features diagnostics tiles::tests -- --include-ignored --nocapture --test-threads=1 6 passed, 0 failed, 0 ignored
cargo check --locked -p victory --features diagnostics Passed
cargo xtask policy 185 files OK

The two excluded tests were each run separately on unmodified main at 9c184b3 and failed there too. A full cargo test --workspace --locked attempt stops at the existing indirect-budget test: the GPU package reports 185 passed, 1 failed, 5 ignored. A fully passing workspace run is not claimed.

Both strict workspace Clippy commands from CI were attempted locally and fail on nonminimal_bool in unchanged victory-shader files. The locally available Clippy reports 0.1.93 despite the 1.98.1 rustc/cargo toolchain, so strict CI validation remains open.

For each synthetic BC7/BC3 texture, assigned backing changes from 1856 KiB to 512 KiB after old readers release it. The test checks old-reader contents, heap size without growth, and reintroduced fine-mip contents by readback. These are per-texture tile bytes, not whole-process VRAM or gameplay FPS.

The production sweep and actual Host::execute retirement boundary have a regression. During development, replacing deferred retirement with an immediate drop made the fence-publication assertion fail; that mutation was reverted.

Pending validation and feedback

  • No game executable, native NVIDIA run, gameplay stability, FPS improvement or real-title VRAM reduction has been verified.
  • Packed-tail policy has a unit regression; native packed-mip mappings still need hardware validation.
  • Are idle copy versions an acceptable first step for reclaiming backing while preserving recorded readers? Would you prefer pool reuse as a separate change?

AI use: Codex developed the reclamation changes and synthetic tests, ran local validation and drafted this description. The carried dependency retains its original credits.

**@⁠ilyaux** on GitHub · 2026-11-25 21:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/1153) `ilyaux:fix/reclaim-mip-levels` → `main` · +638 −23 · 7 files · 2 commits · draft ## Problem and proposal Draft for design feedback, related to #898. Validation of the new reclamation path is limited to synthetic textures on WARP; native NVIDIA and retail-title runs are pending. Levels-on-demand copies retain backing for mip levels the title no longer holds until the entire host copy is destroyed. This adds an opt-in `VICTORY_LEVELS_RECLAIM=1` path, alongside `VICTORY_LEVELS_ON_DEMAND=1`, which replaces eligible idle copies while keeping old readers valid. - Keep the resource dimensions and mip numbering. A replacement starts with fresh staging state and uploads the retained levels. - Keep the original resource and its tiles for old descriptors and recorded/in-flight lists. Indexed views switch after the replacement upload's submission fence completes. A newly recorded table selects the retained mip range. - Exclude GPU-written or claimed levels and copies with pending deferred users. Keep a packed mip tail together. - Reuse free tiles in existing, device-matched pool heaps at a full physical budget without growing the pool. An explicit logical texture byte limit still applies. The sweep follows the existing idle grace for borrowed `host_resource` references. Reclamation can be delayed by old readers or insufficient reusable pool space. The feature is off by default. ## Dependency and attribution This draft carries **[LeonardoS11](https://github.com/LeonardoS11)'s #795** as its first commit, reapplied from `32772d93ea1ec529a8508d08e980c3867c2701ff` with the original author metadata and message preserved: 1. `bf41d7a12528b8fad5ad2093d4813b04f62f8319`: #795's backing-lifetime fix. 2. `b472041c778420d2d4397957d18d65ab62624464`: reclamation, pool reuse, regressions and documentation. The native RTX 3080 Ti results in the carried commit message belong to the original author's report. They are not validation performed for this draft. The second commit contains the new work; the dependency commit can be dropped once #795 lands. ## Validation Tested head: `b472041c778420d2d4397957d18d65ab62624464`, based on `main` at `9c184b35b43de3455b74ac1770e1c8734a047810`. Windows 11; rustc/cargo 1.98.1; WARP, tiled resources tier 3. The D3D12 debug layer is not installed. With `VICTORY_D3D12_WARP=1` and `VICTORY_TILES_TEST_CARD=0`: | Check | Result | | --- | --- | | `cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1 --skip depth_bounds_pipeline_loads_and_filters_draws --skip warp_budget_saturates_without_wraparound_and_preserves_draw_fields` | 202 passed, 0 failed, 6 ignored, 2 excluded | | `cargo test --locked -p victory-gpu --features diagnostics tiles::tests -- --include-ignored --nocapture --test-threads=1` | 6 passed, 0 failed, 0 ignored | | `cargo check --locked -p victory --features diagnostics` | Passed | | `cargo xtask policy` | 185 files OK | The two excluded tests were each run separately on unmodified `main` at `9c184b3` and failed there too. A full `cargo test --workspace --locked` attempt stops at the existing indirect-budget test: the GPU package reports 185 passed, 1 failed, 5 ignored. A fully passing workspace run is not claimed. Both strict workspace Clippy commands from CI were attempted locally and fail on `nonminimal_bool` in unchanged `victory-shader` files. The locally available Clippy reports 0.1.93 despite the 1.98.1 rustc/cargo toolchain, so strict CI validation remains open. For each synthetic BC7/BC3 texture, assigned backing changes from **1856 KiB to 512 KiB** after old readers release it. The test checks old-reader contents, heap size without growth, and reintroduced fine-mip contents by readback. These are per-texture tile bytes, not whole-process VRAM or gameplay FPS. The production sweep and actual `Host::execute` retirement boundary have a regression. During development, replacing deferred retirement with an immediate drop made the fence-publication assertion fail; that mutation was reverted. ## Pending validation and feedback - No game executable, native NVIDIA run, gameplay stability, FPS improvement or real-title VRAM reduction has been verified. - Packed-tail policy has a unit regression; native packed-mip mappings still need hardware validation. - Are idle copy versions an acceptable first step for reclaiming backing while preserving recorded readers? Would you prefer pool reuse as a separate change? AI use: Codex developed the reclamation changes and synthetic tests, ran local validation and drafted this description. The carried dependency retains its original credits.
The tiles of a texture made level by level (VICTORY_LEVELS_ON_DEMAND=1) are
in heaps of ours, not in the texture. A list recorded or in the air keeps
the texture it names (`HostList::keep`), not its host copy, so the host
copy could be let go (the sweep, the title's release) while a list still to
run read through the texture's mappings: the tiles went back to the pool,
were given to other textures, and a heap with all of its tiles free went
back to the card.

On an RTX 3080 Ti, Series X, levels on demand with room for buffers: the
device was removed (0x887A0006) in 1 run of 3, about ten seconds into the
world, 6.4 s after a sweep let go 610 host copies of textures, with one
heap given back to the card; in the runs that went on none was. With this
change: 0 removals in 4 runs (292, 274, 279 and 272 ms a frame), two of
them with a heap given back.

A host copy let go now hands its texture and tiles to a list
(`tiles::let_go`); the tiles go back when nothing but that list names the
texture (`tiles::give_back_let_go`, at every sweep), at once if nothing
does already. Step 8 of the levels-on-demand test lets go of a texture a
list still keeps and checks that its tiles wait until the list is reset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:31 +00:00
Author
Owner

@⁠fladit123 on GitHub · 2026-11-25 23:10 UTC · original

Independent native hardware validation of HEAD b472041c778420d2d4397957d18d65ab62624464.

Environment

  • Windows 11
  • NVIDIA RTX 4060 8 GB, driver 610.88
  • Rust 1.98.1
  • Release build with diagnostics
  • D3D12 debug layer enabled for the tiled-resource fixtures

Results

Test Result
Packed mip-tail preservation PASS
Mip reclamation on WARP, tier 3 PASS
Production sweep and submission publication on WARP PASS
Mip reclamation on the native adapter, tier 4 PASS
Native levels-on-demand integration fixture PASS

Five successful test executions, no skips, no timeouts and no detected device removal.

Assigned backing per synthetic BC7/BC3 texture

Adapter Before After Reduction
WARP 1856 KiB 512 KiB 72.41%
Native adapter 1408 KiB 64 KiB 95.45%

Both adapters released 1344 KiB of assigned backing per texture.

The reclamation regression verified retained old-reader contents, no pool growth during replacement, and correct restoration of fine mip contents.

No D3D12 errors were reported. The native levels-on-demand fixture emitted one warning, ID 1328, concerning the initial UAV state of a buffer being treated as COMMON. The corresponding fixture code is unchanged from the original base, although I did not rerun that base to reproduce the warning.

Executable SHA256:
F827851C759D8B9D146EBC0FA228DB04AB559D9EB5BC840F210C6CC2F9CB52F9

Limitations

The native fixture selects the default D3D12 hardware adapter. The system reports an RTX 4060 and two virtual display adapters; the fixture did not print the selected adapter's LUID.

Validation used a source-only copy with verified Git blob hashes and the unrelated BCPack module excluded locally. No game data was used.

These results measure assigned texture backing, not total physical VRAM savings or gameplay performance. Integration with current main remains untested.

The synthetic native hardware results are encouraging, particularly for memory-constrained GPUs.

AI-assisted validation with ChatGPT; all tests executed locally.

**@⁠fladit123** on GitHub · 2026-11-25 23:10 UTC · [original](https://github.com/fxceless/victory-fork/pull/1153#issuecomment-7177224561) Independent native hardware validation of HEAD `b472041c778420d2d4397957d18d65ab62624464`. **Environment** - Windows 11 - NVIDIA RTX 4060 8 GB, driver 610.88 - Rust 1.98.1 - Release build with diagnostics - D3D12 debug layer enabled for the tiled-resource fixtures **Results** | Test | Result | |---|---| | Packed mip-tail preservation | PASS | | Mip reclamation on WARP, tier 3 | PASS | | Production sweep and submission publication on WARP | PASS | | Mip reclamation on the native adapter, tier 4 | PASS | | Native levels-on-demand integration fixture | PASS | Five successful test executions, no skips, no timeouts and no detected device removal. **Assigned backing per synthetic BC7/BC3 texture** | Adapter | Before | After | Reduction | |---|---:|---:|---:| | WARP | 1856 KiB | 512 KiB | 72.41% | | Native adapter | 1408 KiB | 64 KiB | 95.45% | Both adapters released 1344 KiB of assigned backing per texture. The reclamation regression verified retained old-reader contents, no pool growth during replacement, and correct restoration of fine mip contents. No D3D12 errors were reported. The native levels-on-demand fixture emitted one warning, ID 1328, concerning the initial UAV state of a buffer being treated as COMMON. The corresponding fixture code is unchanged from the original base, although I did not rerun that base to reproduce the warning. Executable SHA256: `F827851C759D8B9D146EBC0FA228DB04AB559D9EB5BC840F210C6CC2F9CB52F9` **Limitations** The native fixture selects the default D3D12 hardware adapter. The system reports an RTX 4060 and two virtual display adapters; the fixture did not print the selected adapter's LUID. Validation used a source-only copy with verified Git blob hashes and the unrelated BCPack module excluded locally. No game data was used. These results measure assigned texture backing, not total physical VRAM savings or gameplay performance. Integration with current main remains untested. The synthetic native hardware results are encouraging, particularly for memory-constrained GPUs. AI-assisted validation with ChatGPT; all tests executed locally.
Author
Owner

@⁠fladit123 on GitHub · 2026-11-26 01:59 UTC · original

Following up on my earlier hardware validation, I investigated the admission and upload boundary more closely.

I reproduced a case where reclaimed_on() checks available pool capacity, but another texture consumes that capacity before the replacement's first upload. With growth disabled, the replacement initially received zero backing. With growth enabled, the pool grew from 64 to 128 MiB.

An experimental reservation-based complement prevented this growth and guaranteed backing for the retained mip groups. However, further qualification exposed important trade-offs:

  • Four competing texture uploads made no progress during a two-second window while idle replacements held their reservations. All four recovered after those replacements were discarded.
  • A 256 KiB reservation prevented a 64 MiB heap from being returned.
  • A WARP cancellation probe left a replacement with 512 KiB reserved and zero mapped backing, although a newly created descriptor already referenced it. Readback returned 0x00 before initialization and 0x22 after a subsequent successful upload.

The experiments also identified and corrected two accounting issues in the experimental complement: stale logical-budget admission and transient double counting during reservation conversion.

The qualified reservation implementation passed 17 WARP controls and two RTX 4060 tests, but I do not recommend integrating it as-is because of the demonstrated progress regression.

A possible alternative would be:

  1. Keep the previous resource version available.
  2. Record a replacement intent without reserving tiles for idle textures.
  3. Reserve and initialize a private replacement when a submission has valid staging and sufficient capacity.
  4. Promote the initialized version only after fence completion and generation revalidation.
  5. Preserve the previous resource and its backing for existing readers.

The main complication is that recorded D3D12 commands already reference concrete resources. Changing made at submission time cannot redirect those commands.

I therefore stopped at the design boundary rather than introducing a broader production change without coordination.

Would this private-initialization and deferred-promotion model fit your intended architecture? I can share the synthetic reproductions, accounting fixes and experimental patches separately if useful.

These experiments used synthetic data only. Gameplay performance and total process VRAM savings remain unmeasured.

AI-assisted investigation with ChatGPT and Codex; tests executed locally.

**@⁠fladit123** on GitHub · 2026-11-26 01:59 UTC · [original](https://github.com/fxceless/victory-fork/pull/1153#issuecomment-7180351614) Following up on my earlier hardware validation, I investigated the admission and upload boundary more closely. I reproduced a case where `reclaimed_on()` checks available pool capacity, but another texture consumes that capacity before the replacement's first upload. With growth disabled, the replacement initially received zero backing. With growth enabled, the pool grew from 64 to 128 MiB. An experimental reservation-based complement prevented this growth and guaranteed backing for the retained mip groups. However, further qualification exposed important trade-offs: - Four competing texture uploads made no progress during a two-second window while idle replacements held their reservations. All four recovered after those replacements were discarded. - A 256 KiB reservation prevented a 64 MiB heap from being returned. - A WARP cancellation probe left a replacement with 512 KiB reserved and zero mapped backing, although a newly created descriptor already referenced it. Readback returned `0x00` before initialization and `0x22` after a subsequent successful upload. The experiments also identified and corrected two accounting issues in the experimental complement: stale logical-budget admission and transient double counting during reservation conversion. The qualified reservation implementation passed 17 WARP controls and two RTX 4060 tests, but I do not recommend integrating it as-is because of the demonstrated progress regression. A possible alternative would be: 1. Keep the previous resource version available. 2. Record a replacement intent without reserving tiles for idle textures. 3. Reserve and initialize a private replacement when a submission has valid staging and sufficient capacity. 4. Promote the initialized version only after fence completion and generation revalidation. 5. Preserve the previous resource and its backing for existing readers. The main complication is that recorded D3D12 commands already reference concrete resources. Changing `made` at submission time cannot redirect those commands. I therefore stopped at the design boundary rather than introducing a broader production change without coordination. Would this private-initialization and deferred-promotion model fit your intended architecture? I can share the synthetic reproductions, accounting fixes and experimental patches separately if useful. These experiments used synthetic data only. Gameplay performance and total process VRAM savings remain unmeasured. AI-assisted investigation with ChatGPT and Codex; tests executed locally.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/resource.rs
  • crates/victory-gpu/src/tiles.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1153/head:github-bot/gh-1153'
git switch 'github-bot/gh-1153'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1153'
git switch 'github-bot/gh-1153'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1153'
git switch 'github-bot/gh-1153'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1153'
git switch 'main'
git merge --squash 'github-bot/gh-1153'
git switch 'main'
git merge --ff-only 'github-bot/gh-1153'
git switch 'main'
git merge 'github-bot/gh-1153'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.