fix(victory): deduplicate prepare queue slots and refcount waiting slots #442

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

@⁠mauroalvare on GitHub · 2026-11-26 18:53 UTC · original
mauroalvare:fix/victory-prepare-slot-dedup → main · +238 −21 · 1 files · 2 commits · closed without merging

Change

Fixes two slot-tracking leaks in victory-gpu's background texture preparation queue (third_party/victory/crates/victory-gpu/src/texture/prepare.rs):

  1. Duplicate slots & pinned Arc<Staging> / budget leak when finish() replaces a same-mip Ready entry:

    • Previously, finish() called q.hint(&slots) before merging slots.append(&mut old.slots) and calling q.gone(&old). Because append emptied old.slots, q.gone(&old) did not call unhint on old's slots, leaving any slot shared between slots and old.slots duplicated in Ready.slots and double-counted in ready_slots.
    • When take_ready() or served() served that slot, iter().position(...) removed only one occurrence, leaving the entry in q.ready with its Arc<Staging> upload buffer pinned in STAGED (preventing return to STAGE_POOL), q.outstanding inflated against VICTORY_TEXTURE_STAGE_MB, and prepare::slot(slot) stuck reporting Slot::Ready until prune() evicted it after 2+ seconds.
    • Fix: retire old via q.gone(old) first, merge only non-duplicate slots from old.slots, and then call q.hint(&slots) once for the deduplicated set.
  2. Premature waiting removal and duplicate pending entries across concurrent jobs:

    • Previously, Queue::waiting was a HashSet<u32>, so finishing one pending job unconditionally removed slot from q.waiting even if another pending job still listed slot, and look() pushed slot into q.pending[key] without checking whether it was already present.
    • Fix: track Queue::waiting as a per-slot refcount (HashMap<u32, u32>, mirroring ready_slots) via wait()/unwait(), and skip duplicate pushes in look().

Verification

Base SHA: c3cc02932fc596ee9d937e5743f73007c538365a (LooperSalty/AnyXboxX:main).
Hardware: Windows x64, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (15995 MiB VRAM, driver 32.0.16.2140), 32 GB RAM.

Regression test — Base vs Fix (synthetic 1024×1024 RGBA8 4 MiB texture on RTX 5070 Ti)

Command:

cargo test --locked -p victory-gpu --lib texture::prepare::tests -- --nocapture --test-threads=1
  • Base (c3cc029) — FAILS:
    adapter: NVIDIA GeForce RTX 5070 Ti (15995 MiB VRAM)
    prepare_dedup metrics: census=[0, 1, 4194304] slot10=Ready slot11=Other staging_strong=1 leaked_staged_count=1 leaked_staged_bytes=4194304
    assertion `left == right` failed: ready entry and outstanding budget must drain after serving all slots
      left: [0, 1, 4194304]
     right: [0, 0, 0]
    
  • Fix — PASSES:
    adapter: NVIDIA GeForce RTX 5070 Ti (15995 MiB VRAM)
    prepare_dedup metrics: census=[0, 0, 0] slot10=Other slot11=Other staging_strong=0 leaked_staged_count=0 leaked_staged_bytes=0
    test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 262 filtered out; finished in 0.32s
    

Additional checks

cargo test --locked -p victory-gpu --lib draw::heap_texture_tests::prepare_threads_make_the_textures_off_the_recording_thread -- --nocapture --test-threads=1
# → adapter=Some(("NVIDIA GeForce RTX 5070 Ti", 16771973120)), uploads=83, made_ready=48, host_copies_by_threads=8, host_copies_here=0, staging_buffers_here=0, passes_needed=2
# → test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 263 filtered out; finished in 0.61s

cargo test --locked -p victory-gpu --lib --features diagnostics texture::prepare::tests -- --test-threads=1
# → test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 274 filtered out; finished in 0.26s

cargo test --locked -p victory-loader --test load_probe
# → test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.11s

cargo clippy --locked -p victory-gpu --tests
# → Finished `dev` profile [unoptimized + debuginfo] (0 warnings in prepare.rs)

cargo xtask policy
# → asset policy: 215 files ok

Oracle and test data

  • All test data is synthetic: a 1024×1024 RGBA8 committed texture created via resource::create_committed + real Staging upload buffers via texture::prepared_staging on the local RTX 5070 Ti.
  • texture::prepare::tests::replacing_ready_deduplicates_slots_and_releases_staging fails on c3cc029 (leaking 1 Ready entry, 4 MiB in q.outstanding, 4 MiB in STAGED, Arc<Staging> refcount = 1, and stale Slot::Ready) and passes with this fix (0 leaked across all metrics).

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 README changes needed.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none (synthetic tests only).
  • Code taken from another project: none.

This change was investigated, implemented, and verified with AI assistance.

**@⁠mauroalvare** on GitHub · 2026-11-26 18:53 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/442) `mauroalvare:fix/victory-prepare-slot-dedup` → `main` · +238 −21 · 1 files · 2 commits · closed without merging ## Change Fixes two slot-tracking leaks in `victory-gpu`'s background texture preparation queue (`third_party/victory/crates/victory-gpu/src/texture/prepare.rs`): 1. **Duplicate slots & pinned `Arc<Staging>` / budget leak when `finish()` replaces a same-mip `Ready` entry**: - Previously, `finish()` called `q.hint(&slots)` before merging `slots.append(&mut old.slots)` and calling `q.gone(&old)`. Because `append` emptied `old.slots`, `q.gone(&old)` did not call `unhint` on `old`'s slots, leaving any slot shared between `slots` and `old.slots` duplicated in `Ready.slots` and double-counted in `ready_slots`. - When `take_ready()` or `served()` served that slot, `iter().position(...)` removed only one occurrence, leaving the entry in `q.ready` with its `Arc<Staging>` upload buffer pinned in `STAGED` (preventing return to `STAGE_POOL`), `q.outstanding` inflated against `VICTORY_TEXTURE_STAGE_MB`, and `prepare::slot(slot)` stuck reporting `Slot::Ready` until `prune()` evicted it after 2+ seconds. - Fix: retire `old` via `q.gone(old)` first, merge only non-duplicate slots from `old.slots`, and then call `q.hint(&slots)` once for the deduplicated set. 2. **Premature `waiting` removal and duplicate `pending` entries across concurrent jobs**: - Previously, `Queue::waiting` was a `HashSet<u32>`, so finishing one pending job unconditionally removed `slot` from `q.waiting` even if another pending job still listed `slot`, and `look()` pushed `slot` into `q.pending[key]` without checking whether it was already present. - Fix: track `Queue::waiting` as a per-slot refcount (`HashMap<u32, u32>`, mirroring `ready_slots`) via `wait()`/`unwait()`, and skip duplicate pushes in `look()`. ## Verification Base SHA: `c3cc02932fc596ee9d937e5743f73007c538365a` (`LooperSalty/AnyXboxX:main`). Hardware: Windows x64, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (15995 MiB VRAM, driver `32.0.16.2140`), 32 GB RAM. ### Regression test — Base vs Fix (synthetic 1024×1024 RGBA8 4 MiB texture on RTX 5070 Ti) Command: ```powershell cargo test --locked -p victory-gpu --lib texture::prepare::tests -- --nocapture --test-threads=1 ``` - **Base (`c3cc029`) — FAILS**: ``` adapter: NVIDIA GeForce RTX 5070 Ti (15995 MiB VRAM) prepare_dedup metrics: census=[0, 1, 4194304] slot10=Ready slot11=Other staging_strong=1 leaked_staged_count=1 leaked_staged_bytes=4194304 assertion `left == right` failed: ready entry and outstanding budget must drain after serving all slots left: [0, 1, 4194304] right: [0, 0, 0] ``` - **Fix — PASSES**: ``` adapter: NVIDIA GeForce RTX 5070 Ti (15995 MiB VRAM) prepare_dedup metrics: census=[0, 0, 0] slot10=Other slot11=Other staging_strong=0 leaked_staged_count=0 leaked_staged_bytes=0 test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 262 filtered out; finished in 0.32s ``` ### Additional checks ```powershell cargo test --locked -p victory-gpu --lib draw::heap_texture_tests::prepare_threads_make_the_textures_off_the_recording_thread -- --nocapture --test-threads=1 # → adapter=Some(("NVIDIA GeForce RTX 5070 Ti", 16771973120)), uploads=83, made_ready=48, host_copies_by_threads=8, host_copies_here=0, staging_buffers_here=0, passes_needed=2 # → test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 263 filtered out; finished in 0.61s cargo test --locked -p victory-gpu --lib --features diagnostics texture::prepare::tests -- --test-threads=1 # → test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 274 filtered out; finished in 0.26s cargo test --locked -p victory-loader --test load_probe # → test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.11s cargo clippy --locked -p victory-gpu --tests # → Finished `dev` profile [unoptimized + debuginfo] (0 warnings in prepare.rs) cargo xtask policy # → asset policy: 215 files ok ``` ## Oracle and test data - All test data is synthetic: a 1024×1024 RGBA8 committed texture created via `resource::create_committed` + real `Staging` upload buffers via `texture::prepared_staging` on the local RTX 5070 Ti. - `texture::prepare::tests::replacing_ready_deduplicates_slots_and_releases_staging` fails on `c3cc029` (leaking 1 `Ready` entry, 4 MiB in `q.outstanding`, 4 MiB in `STAGED`, `Arc<Staging>` refcount = 1, and stale `Slot::Ready`) and passes with this fix (`0` leaked across all metrics). ## 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 README changes needed. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none (synthetic tests only). - [x] Code taken from another project: none. *This change was investigated, implemented, and verified with AI assistance.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:56:41 +00:00
github-bot closed this pull request 2026-11-27 00:35:53 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 23:08 UTC · original

Closing after #454 moved third_party/victory to the Vice-Tay base (TaynanGT/Vice-Tay a252348).

texture/prepare.rs does not exist on the new base; Vice-Tay's texture queue (texture/ahead.rs) works differently.

Thanks for the work. If you measure a gain on the new base, a new PR against main is welcome.

🤖 Closed by Claude Code on behalf of the maintainer

**@⁠LooperSalty** on GitHub · 2026-11-26 23:08 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/442#issuecomment-7205295370) Closing after #454 moved `third_party/victory` to the Vice-Tay base (TaynanGT/Vice-Tay a252348). `texture/prepare.rs` does not exist on the new base; Vice-Tay's texture queue (`texture/ahead.rs`) works differently. Thanks for the work. If you measure a gain on the new base, a new PR against `main` is welcome. _🤖 Closed by [Claude Code](https://claude.com/claude-code) on behalf of the maintainer_

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.