perf(gpu): fix 12 GB VRAM dead-zone stalls (#30), O(1) DynamicPool, and #32 parallel WARP test crash #46

Open
github-bot wants to merge 3 commits from github-bot/gh-46 into beta AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 21:08 UTC · original
Vladimir-Human:perf/vram-12gb-warp-fix → beta · +1658 −183 · 10 files · 3 commits · open

AI-assisted clean-room contribution (victory-gpu, D3D12 WARP/hardware unit tests only — refs #30 and fixes #32; no title files used).

Summary

Combines two orthogonal improvements in crates/victory-gpu/src/ on beta (e328c88):

  1. 12 GB VRAM dead-zone survival + staging trim + O(1) DynamicPool (helps #30):
    • resource.rs: eliminates the room_percent..90% idle-eviction dead zone (evict_trigger_percent default room_percent - 2, floor 45), tightens high-pressure grace to 30 frames / 1000 ms, includes tiles::Tiled reserved textures (HostTexture::card_bytes()) + card_room_kept() + targets_room_kept() + tiles::given_total() in pressure accounting, adds safe rate-limited reclaim_unpinned_idle fallback in room(), and closes the Pass 1 -> Pass 2 TOCTOU window by re-verifying host_wrote, is_idle_at, COM pointer identity, Arc::strong_count == 1, and host::references == 1 under r.host.made before retiring outside locks.
    • descriptor/host.rs & descriptor.rs: replaces linear ring-walk + too_long with a coalescing O(1) bitmask small-bucket (1..=32) + BTreeSet large-extent DynamicPool, opens full count..null view-heap headroom, and keeps HostHeap::evict_kept strictly aligned with HostHeap::mirror's SHADER_HEAPS -> made -> {kept, placed, textures} lock order while retiring COM refs outside all locks (zero edits to HostHeap::mirror / stripes in #16).
    • texture.rs: tracks Staging::{copy_queued, unflushed} accurately across multi-list submissions (defer_host clear immediately after defer_texture) and trims clean idle staging buffers under pressure while keeping host textures and dirty/unflushed uploads intact.
  2. Fixes #32 parallel d3d10warp.dll 0xc0000005 test crashes & parallel watch::tests VA-reuse flake (#[cfg(test)] ONLY):
    • Adds poison-safe host::warp_test_lock() guarding all 5 WARP D3D12 test fixtures (host.rs, indirect.rs WarpHarness, inplace.rs, shadow.rs, tiles.rs Rig), Host::test_sweep_lock() for sweep/eviction tests, and moves title_memory_remapped(...) before UnmapViewOfFile/VirtualFree in the 3 watch.rs #[cfg(test)] view-teardown tests (matching Drop for View so parallel Windows VA reuse never collides). Zero non-test runtime edits for #32, zero weakened/skipped/retried assertions.

Verification (beta e328c88, RTX 4070 SUPER / i5-13400F, Rust 1.98)

  • git diff --check beta..HEAD: clean; git merge-tree clean against beta, #41, #42, #43, and our BVH PR.
  • cargo clippy -p victory-gpu --all-targets (default & --features diagnostics): 0 warnings in all added/modified code.
  • 10/10 consecutive default-parallel cargo test -p victory-gpu --lib --locked runs (WITHOUT --test-threads=1): 10/10 PASSED (161 passed; 0 failed, 3 ignored per run, 1.29s–5.29s, 0 WARP crashes).
**@⁠Vladimir-Human** on GitHub · 2026-11-25 21:08 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/46) `Vladimir-Human:perf/vram-12gb-warp-fix` → `beta` · +1658 −183 · 10 files · 3 commits · open AI-assisted clean-room contribution (`victory-gpu`, D3D12 WARP/hardware unit tests only — refs #30 and fixes #32; no title files used). ### Summary Combines two orthogonal improvements in `crates/victory-gpu/src/` on `beta` (`e328c88`): 1. **12 GB VRAM dead-zone survival + staging trim + O(1) `DynamicPool` (helps #30)**: - **`resource.rs`**: eliminates the `room_percent..90%` idle-eviction dead zone (`evict_trigger_percent` default `room_percent - 2`, floor `45`), tightens high-pressure grace to 30 frames / 1000 ms, includes `tiles::Tiled` reserved textures (`HostTexture::card_bytes()`) + `card_room_kept() + targets_room_kept()` + `tiles::given_total()` in pressure accounting, adds safe rate-limited `reclaim_unpinned_idle` fallback in `room()`, and closes the Pass 1 -> Pass 2 TOCTOU window by re-verifying `host_wrote`, `is_idle_at`, COM pointer identity, `Arc::strong_count == 1`, and `host::references == 1` under `r.host.made` before retiring outside locks. - **`descriptor/host.rs` & `descriptor.rs`**: replaces linear ring-walk + `too_long` with a coalescing `O(1)` bitmask small-bucket (`1..=32`) + `BTreeSet` large-extent `DynamicPool`, opens full `count..null` view-heap headroom, and keeps `HostHeap::evict_kept` strictly aligned with `HostHeap::mirror`'s `SHADER_HEAPS -> made -> {kept, placed, textures}` lock order while retiring COM refs outside all locks (zero edits to `HostHeap::mirror` / stripes in #16). - **`texture.rs`**: tracks `Staging::{copy_queued, unflushed}` accurately across multi-list submissions (`defer_host` clear immediately after `defer_texture`) and trims clean idle staging buffers under pressure while keeping host textures and dirty/unflushed uploads intact. 2. **Fixes #32 parallel `d3d10warp.dll` `0xc0000005` test crashes & parallel `watch::tests` VA-reuse flake (`#[cfg(test)]` ONLY)**: - Adds poison-safe `host::warp_test_lock()` guarding all 5 WARP D3D12 test fixtures (`host.rs`, `indirect.rs` `WarpHarness`, `inplace.rs`, `shadow.rs`, `tiles.rs` `Rig`), `Host::test_sweep_lock()` for sweep/eviction tests, and moves `title_memory_remapped(...)` before `UnmapViewOfFile`/`VirtualFree` in the 3 `watch.rs` `#[cfg(test)]` view-teardown tests (matching `Drop for View` so parallel Windows VA reuse never collides). Zero non-test runtime edits for #32, zero weakened/skipped/retried assertions. ### Verification (`beta` `e328c88`, RTX 4070 SUPER / i5-13400F, Rust 1.98) - `git diff --check beta..HEAD`: clean; `git merge-tree` clean against `beta`, #41, #42, #43, and our BVH PR. - `cargo clippy -p victory-gpu --all-targets` (`default` & `--features diagnostics`): **0 warnings** in all added/modified code. - **10/10 consecutive default-parallel `cargo test -p victory-gpu --lib --locked` runs (WITHOUT `--test-threads=1`)**: **10/10 PASSED** (`161 passed; 0 failed`, 3 ignored per run, `1.29s–5.29s`, 0 WARP crashes).
- Add LRU descriptor-unpin + host-copy eviction aligned to room_percent() (trigger room_percent - 2, target room_percent - 8, 30-frame / 1000 ms high-pressure grace), accounting for both regular and levels-on-demand tiled textures plus reserved buffer/target headroom, with safe rate-limited unpinned reclaim fallback in room() and COM retirement outside all locks.
- Add pressure-driven trimming of clean uploaded staging buffers (uploaded && !unflushed, no in-flight command list) under VRAM or RAM pressure while preserving host textures and dirty/unflushed buffers.
- Hand full view-heap headroom past count up to null to the dynamic pool and replace linear ring-walk dynamic slot allocation with a coalescing O(1) small-bucket bitmask + BTreeSet extent DynamicPool.
- Serialize WARP software D3D12 device usage across unit tests via test-only host::warp_test_lock() (and synchronize sweep/eviction tests via Host::test_sweep_lock()) to eliminate concurrent d3d10warp.dll 0xc0000005 crashes under default parallel cargo test.
- Re-verify idle timestamp, !host_wrote, COM pointer identity, strong_count == 1, and COM refcount == 1 under r.host.made in evict_lru_textures_at Pass 2 (and read used under made in Pass 1).
- Hold HostHeap::made across kept/placed/textures cleanup in evict_kept and retire removed COM refs in evict_kept_resources only after dropping SHADER_HEAPS and heap locks.
- Clear Staging::copy_queued in a deferred host step immediately after defer_texture in upload() (normal and on-demand paths) so multi-list uploads never leak stale copy_queued=true to later skipped-upload refreshes; add regression test.
- Call title_memory_remapped before unmapping/freeing VA ranges (and close section handle) in three watch.rs unit tests so parallel tests cannot race on recycled virtual addresses.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:53:30 +00:00
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 21:10 UTC · original

Thanks a lot @⁠Vladimir-Human! The 12 GB dead-zone stalls are what @⁠mayauxpaul8-droid hit in #30, and a fix for the #32 parallel WARP test crash is welcome too. Same as your other PRs: it goes into our one-change-at-a-time queue on the RX 9070 XT (same save, same 7-minute run, fps and picture against our reference build), and results will be posted here. A run on a 12 GB card from #30 would be the real proof, so @⁠mayauxpaul8-droid, if you can test this branch, please say so here.

**@⁠PastiiJay** on GitHub · 2026-11-25 21:10 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/46#issuecomment-7174716456) Thanks a lot @⁠Vladimir-Human! The 12 GB dead-zone stalls are what @⁠mayauxpaul8-droid hit in #30, and a fix for the #32 parallel WARP test crash is welcome too. Same as your other PRs: it goes into our one-change-at-a-time queue on the RX 9070 XT (same save, same 7-minute run, fps and picture against our reference build), and results will be posted here. A run on a 12 GB card from #30 would be the real proof, so @⁠mayauxpaul8-droid, if you can test this branch, please say so here.
Author
Owner

@⁠HandshakeHackin on GitHub · 2026-11-25 21:20 UTC · original

Two details for interpreting the hardware retests. The original #30 tester reports a standard RTX 4060, which NVIDIA lists with 8 GB. The other tester in that issue reports a 16 GB RTX 4080 SUPER. The 4060 run would give us an 8 GB comparison. A 12 GB card would cover the capacity in the PR title. RTX 4060 report · 4080 SUPER report · NVIDIA specifications

I also ran the threshold functions from b1c90b3 in isolation with a synthetic 10 GiB budget. With both environment overrides unset, eviction became preemptive at 88% effective usage and high-pressure at 90%. With VICTORY_TEXTURE_ROOM_PERCENT=82, those transitions were 80% and 82%, as in the unit fixture. The fixture comment calls 82 the default. Including the room setting and the vram_used_mb / vram_budget_mb values from the eviction line would make the A/B results easier to compare. Threshold calculation

**@⁠HandshakeHackin** on GitHub · 2026-11-25 21:20 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/46#issuecomment-7174948482) Two details for interpreting the hardware retests. The original #30 tester reports a standard RTX 4060, which NVIDIA lists with 8 GB. The other tester in that issue reports a 16 GB RTX 4080 SUPER. The 4060 run would give us an 8 GB comparison. A 12 GB card would cover the capacity in the PR title. [RTX 4060 report](https://git.gtahub.st/github/PastiiJay--klbf-lab/issues/30) · [4080 SUPER report](https://git.gtahub.st/github/PastiiJay--klbf-lab/issues/30) · [NVIDIA specifications](https://www.nvidia.com/en-us/geforce/graphics-cards/40-series/rtx-4060-4060ti/) I also ran the threshold functions from `b1c90b3` in isolation with a synthetic 10 GiB budget. With both environment overrides unset, eviction became preemptive at 88% effective usage and high-pressure at 90%. With `VICTORY_TEXTURE_ROOM_PERCENT=82`, those transitions were 80% and 82%, as in the unit fixture. The fixture comment calls 82 the default. Including the room setting and the `vram_used_mb` / `vram_budget_mb` values from the eviction line would make the A/B results easier to compare. [Threshold calculation](https://github.com/PastiiJay/klbf-lab/blob/b1c90b37c2b61e615ae2b1d48039d7da1942d4f7/crates/victory-gpu/src/resource.rs#L1578-L1603)
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 21:23 UTC · original

Thanks for the correction @⁠HandshakeHackin, you're right: the RTX 4060 in #30 is the standard 8 GB model, so I was wrong to call it a 12 GB case. A run there gives us an 8 GB comparison, and a 12 GB card would still be the direct test of the PR title.

Noted for our A/B runs: we'll log the room setting and the vram_used_mb / vram_budget_mb values from the eviction line. @⁠Vladimir-Human, your thresholds come out at 88/90% with the overrides unset while the fixture comment calls 82 the default; could you say which one you intended?

**@⁠PastiiJay** on GitHub · 2026-11-25 21:23 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/46#issuecomment-7175012371) Thanks for the correction @⁠HandshakeHackin, you're right: the RTX 4060 in #30 is the standard 8 GB model, so I was wrong to call it a 12 GB case. A run there gives us an 8 GB comparison, and a 12 GB card would still be the direct test of the PR title. Noted for our A/B runs: we'll log the room setting and the `vram_used_mb` / `vram_budget_mb` values from the eviction line. @⁠Vladimir-Human, your thresholds come out at 88/90% with the overrides unset while the fixture comment calls 82 the default; could you say which one you intended?
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 00:04 UTC · original

@⁠PastiiJay @⁠HandshakeHackin 88/90% is the intended default: preserving klbf-lab's existing
oom_percent() = 90 default, with preemptive eviction starting 2 percentage points below (88%) to eliminate any dead-zone regardless of VICTORY_TEXTURE_ROOM_PERCENT.

The 82 in the unit test fixture comment was a stale leftover from ictory-perf when porting #30. Pushed 9c68c0b to update crates/victory-gpu/src/resource.rs:

  • Explicitly tests the klbf-lab default (
    oom_percent = 90, rigger = 88: no trigger at 87%, preemptive at 88%, high pressure at 90%).
  • Clarifies the existing VICTORY_TEXTURE_ROOM_PERCENT=82 ( rigger = 80) block as the explicit override case.

Re-verified cargo test -p victory-gpu resource (12/12 passed) and cargo run -p xtask -- policy --staged (1 files ok). Ready for your A/B queue!

**@⁠Vladimir-Human** on GitHub · 2026-11-26 00:04 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/46#issuecomment-7178375017) @⁠PastiiJay @⁠HandshakeHackin **88/90% is the intended default**: preserving klbf-lab's existing oom_percent() = 90 default, with preemptive eviction starting 2 percentage points below (88%) to eliminate any dead-zone regardless of VICTORY_TEXTURE_ROOM_PERCENT. The 82 in the unit test fixture comment was a stale leftover from ictory-perf when porting #30. Pushed 9c68c0b to update crates/victory-gpu/src/resource.rs: - Explicitly tests the klbf-lab default ( oom_percent = 90, rigger = 88: no trigger at 87%, preemptive at 88%, high pressure at 90%). - Clarifies the existing VICTORY_TEXTURE_ROOM_PERCENT=82 ( rigger = 80) block as the explicit override case. Re-verified cargo test -p victory-gpu resource (**12/12 passed**) and cargo run -p xtask -- policy --staged (1 files ok). Ready for your A/B queue!
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-26 00:05 UTC · original

Clear, thanks @⁠Vladimir-Human: 88/90% as the default, 82 only as the explicit override, and the test now says so. It's in the queue.

**@⁠PastiiJay** on GitHub · 2026-11-26 00:05 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/46#issuecomment-7178381175) Clear, thanks @⁠Vladimir-Human: 88/90% as the default, 82 only as the explicit override, and the test now says so. It's in the queue.
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/46/head:github-bot/gh-46'
git switch 'github-bot/gh-46'

Merge

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