fix(victory): count mapped tile bytes for levels-on-demand VRAM accounting and eviction #287

Open
github-bot wants to merge 3 commits from github-bot/gh-287 into main AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-26 01:16 UTC · original
mauroalvare:fix/victory-tiled-vram-eviction → main · +76 −11 · 1 files · 3 commits · open

## Change

In third_party/victory/crates/victory-gpu/src/resource.rs, levels-on-demand host textures (HostTexture::new_tiled, enabled by default via VICTORY_LEVELS_ON_DEMAND=1 in tools/lancer_victory.ps1) set host.bytes = 0 because their VRAM lives in crate::tiles::Tiled (given_bytes()).

While room() and card_accounting() already accounted for tiled bytes, several eviction and VRAM-accounting paths still read host.bytes directly (seeing 0 for every tiled texture):

  • pressure_victims() (VICTORY_VRAM_EVICT) and slot_evict() (VICTORY_SLOT_EVICT) passed 0 bytes into oldest_covering(), causing sweeps under VRAM pressure to blow past the excess/rate cap and over-evict tiled textures (leading to unnecessary re-creation and re-upload thrashing).
  • pressure_victims() also did not filter out crate::texture::host_wrote(at) textures (which let_go_idle() skips), and both pressure paths considered 0-tile reserved textures that free 0 VRAM bytes.
  • let_go_idle(), slot_evict(), account() (VRAM_KINDS), copy_state(), targets_census(), and census() all reported 0 bytes for levels-on-demand textures.

This change adds HostTexture::card_bytes() (returning tiled.given_bytes() for levels-on-demand textures and self.bytes otherwise), uses it across all eviction and reporting paths (without altering HOST_TEXTURES[1] / KINDS[1] invariants used by room() and targets_room_kept()), skips host_wrote and 0-byte copies during pressure selection, and adds an RTX-verified regression test.

Verification

Base SHA: c4c93bdc413191a9dc909998d2d53080a3f0c880
GPU: NVIDIA GeForce RTX 5070 Ti (15995 MiB VRAM, driver 32.0.16.2140), D3D12 Tiled Resources Tier 2+.

Synthetic reproduction (tiled_textures_account_vram_and_bound_pressure_eviction: 6 backed 1024×1024 RGBA8 11-mip levels-on-demand textures of 5,636,096 B each, 1 host-written tiled texture, and 1 unbacked 0-tile reserved texture, with eviction excess = 1.5× one texture = 8,454,144 B):

Metric Base (c4c93bd) Fix
copy_state reported bytes 0 5,636,096 (5,504 KiB)
VRAM_KINDS[1] (filled placed) 0 39,452,672 (37.6 MiB)
pressure_victims selected (expected 2) 8 (all 6 backed + host-written + 0-tile) 2 (only the 2 oldest backed evictable)
Tiles reclaimed / surviving GPU texels Over-evicted 4 active textures (22,544,384 B redundant re-upload) Reclaimed 11,272,192 B; 4 surviving textures read back identical texels

Commands run from third_party/victory (Rust 1.98.1):

cargo test --locked -p victory-gpu --lib resource::tests::tiled_textures_account_vram_and_bound_pressure_eviction -- --exact --nocapture  → 1 passed; 0 failed (0.21s)
cargo test --locked -p victory-gpu --lib resource::tests                                                                                   → 15 passed; 0 failed (0.22s)
cargo test --locked -p victory-gpu --features diagnostics --lib resource::tests                                                            → 15 passed; 0 failed (0.22s)
cargo test --locked -p victory-gpu --lib tiles::tests                                                                                      → 3 passed; 0 failed; 1 ignored (0.19s)
cargo test --locked -p victory-loader --test load_probe                                                                                    → 2 passed; 0 failed (0.12s)
cargo clippy --locked -p victory-gpu --tests                                                                                               → 0 warnings in resource.rs
cargo xtask policy                                                                                                                         → asset policy: 199 files ok

Note: Python tests (pytest / ruff) were not modified because this PR only touches third_party/victory (covered by CI politique VIctory and lint/pytest).

Oracle and test data

  • Synthetic 1024×1024 RGBA8 11-mip textures built in memory inside resource::tests::tiled_textures_account_vram_and_bound_pressure_eviction using D3D12 CreateReservedResource and UpdateTileMappings on the local RTX 5070 Ti.
  • Failure case on base (c4c93bd with VICTORY_VRAM_EVICT=80): tiled_textures_account_vram_and_bound_pressure_eviction fails with copy_state=0 (expected 5636096), VRAM_KINDS[1]=0 (expected >= 39452672), and pressure_victims_total=8 (backed=6, includes_host_written=true, includes_empty=true) instead of 2.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: no test count hundred crossed / no README change needed.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none (reproduced from code inspection and synthetic D3D12 tiled textures).
  • Code taken from another project: none.

Made with AI assistance (Antigravity / Gemini).

**@⁠mauroalvare** on GitHub · 2026-11-26 01:16 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/287) `mauroalvare:fix/victory-tiled-vram-eviction` → `main` · +76 −11 · 1 files · 3 commits · open ## Change In `third_party/victory/crates/victory-gpu/src/resource.rs`, levels-on-demand host textures (`HostTexture::new_tiled`, enabled by default via `VICTORY_LEVELS_ON_DEMAND=1` in `tools/lancer_victory.ps1`) set `host.bytes = 0` because their VRAM lives in `crate::tiles::Tiled` (`given_bytes()`). While `room()` and `card_accounting()` already accounted for tiled bytes, several eviction and VRAM-accounting paths still read `host.bytes` directly (seeing `0` for every tiled texture): - `pressure_victims()` (`VICTORY_VRAM_EVICT`) and `slot_evict()` (`VICTORY_SLOT_EVICT`) passed `0` bytes into `oldest_covering()`, causing sweeps under VRAM pressure to blow past the excess/rate cap and over-evict tiled textures (leading to unnecessary re-creation and re-upload thrashing). - `pressure_victims()` also did not filter out `crate::texture::host_wrote(at)` textures (which `let_go_idle()` skips), and both pressure paths considered 0-tile reserved textures that free 0 VRAM bytes. - `let_go_idle()`, `slot_evict()`, `account()` (`VRAM_KINDS`), `copy_state()`, `targets_census()`, and `census()` all reported `0` bytes for levels-on-demand textures. This change adds `HostTexture::card_bytes()` (returning `tiled.given_bytes()` for levels-on-demand textures and `self.bytes` otherwise), uses it across all eviction and reporting paths (without altering `HOST_TEXTURES[1]` / `KINDS[1]` invariants used by `room()` and `targets_room_kept()`), skips `host_wrote` and 0-byte copies during pressure selection, and adds an RTX-verified regression test. ## Verification Base SHA: `c4c93bdc413191a9dc909998d2d53080a3f0c880` GPU: `NVIDIA GeForce RTX 5070 Ti` (15995 MiB VRAM, driver `32.0.16.2140`), D3D12 Tiled Resources Tier 2+. Synthetic reproduction (`tiled_textures_account_vram_and_bound_pressure_eviction`: 6 backed 1024×1024 RGBA8 11-mip levels-on-demand textures of 5,636,096 B each, 1 host-written tiled texture, and 1 unbacked 0-tile reserved texture, with eviction excess = 1.5× one texture = 8,454,144 B): | Metric | Base (`c4c93bd`) | Fix | | --- | --- | --- | | `copy_state` reported bytes | `0` | `5,636,096` (5,504 KiB) | | `VRAM_KINDS[1]` (`filled placed`) | `0` | `39,452,672` (37.6 MiB) | | `pressure_victims` selected (expected 2) | `8` (all 6 backed + host-written + 0-tile) | `2` (only the 2 oldest backed evictable) | | Tiles reclaimed / surviving GPU texels | Over-evicted 4 active textures (22,544,384 B redundant re-upload) | Reclaimed `11,272,192` B; 4 surviving textures read back identical texels | Commands run from `third_party/victory` (Rust `1.98.1`): ``` cargo test --locked -p victory-gpu --lib resource::tests::tiled_textures_account_vram_and_bound_pressure_eviction -- --exact --nocapture → 1 passed; 0 failed (0.21s) cargo test --locked -p victory-gpu --lib resource::tests → 15 passed; 0 failed (0.22s) cargo test --locked -p victory-gpu --features diagnostics --lib resource::tests → 15 passed; 0 failed (0.22s) cargo test --locked -p victory-gpu --lib tiles::tests → 3 passed; 0 failed; 1 ignored (0.19s) cargo test --locked -p victory-loader --test load_probe → 2 passed; 0 failed (0.12s) cargo clippy --locked -p victory-gpu --tests → 0 warnings in resource.rs cargo xtask policy → asset policy: 199 files ok ``` Note: Python tests (`pytest` / `ruff`) were not modified because this PR only touches `third_party/victory` (covered by CI `politique VIctory` and `lint`/`pytest`). ## Oracle and test data - Synthetic 1024×1024 RGBA8 11-mip textures built in memory inside `resource::tests::tiled_textures_account_vram_and_bound_pressure_eviction` using D3D12 `CreateReservedResource` and `UpdateTileMappings` on the local RTX 5070 Ti. - Failure case on base (`c4c93bd` with `VICTORY_VRAM_EVICT=80`): `tiled_textures_account_vram_and_bound_pressure_eviction` fails with `copy_state=0` (expected `5636096`), `VRAM_KINDS[1]=0` (expected `>= 39452672`), and `pressure_victims_total=8` (backed=6, includes_host_written=true, includes_empty=true) instead of `2`. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: no test count hundred crossed / no README change needed. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none (reproduced from code inspection and synthetic D3D12 tiled textures). - [x] Code taken from another project: none. Made with AI assistance (Antigravity / Gemini).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:02 +00:00
github-bot force-pushed github-bot/gh-287 from adb0aece5c to 806d1419db 2026-11-26 18:40:40 +00:00 Compare
Author
Owner

@⁠mauroalvare on GitHub · 2026-11-26 18:41 UTC · original

The branch was rebased while I was testing the resolution. I verified that its new head matches the tree I tested and that GitHub reports the PR as mergeable.

The resolved code counts mapped tile bytes and keeps main's lock release and resource-liveness checks in the slot-eviction path. All 17 resource tests passed on the RTX 5070 Ti. The pressure regression selected two backed textures and excluded the host-written and unbacked textures.

GitHub Actions for this revision.

**@⁠mauroalvare** on GitHub · 2026-11-26 18:41 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/287#issuecomment-7200744413) The branch was rebased while I was testing the resolution. I verified that its new head matches the tree I tested and that GitHub reports the PR as mergeable. The resolved code counts mapped tile bytes and keeps main's lock release and resource-liveness checks in the slot-eviction path. All 17 resource tests passed on the RTX 5070 Ti. The pressure regression selected two backed textures and excluded the host-written and unbacked textures. [GitHub Actions for this revision](https://github.com/LooperSalty/AnyXboxX/actions/runs/45877297723).
github-bot force-pushed github-bot/gh-287 from 806d1419db to 5635bea896 2026-11-26 19:51:02 +00:00 Compare
github-bot force-pushed github-bot/gh-287 from 5635bea896 to 3dd4104747 2026-11-27 00:36:42 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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