victory-gpu: skip repeated dynamic descriptor slot searches after failure #2394

Open
github-bot wants to merge 1 commit from github-bot/gh-2394 into main AGit
Owner

@⁠bartikele on GitHub · 2026-11-25 12:40 UTC · original
bartikele:gpu-dynamic-slot-search-cache → main · +79 −12 · 1 files · 1 commits · open

Summary

  • Track
    o_run (the smallest run size that failed to allocate since the last
    elease) and per-frame ailed_walks inside HostHeap's DynamicSlots state (crates/victory-gpu/src/descriptor/host.rs).
  • When a dynamic slot search for
    slots fails, subsequent requests for >= n slots return None immediately until a
    elease frees slots, and full failed walks are capped at 8 per presented frame (crate::queue::presented(), un-gated from diagnostics in crates/victory-gpu/src/queue.rs).
  • Prevents multi-second per-frame CPU stalls when dynamic descriptor slots saturate in heavy frames.
  • Add unit test descriptor::host::tests::dynamic_failed_search_is_cached_until_release.

Inspired by Belobug's VIctory-Belobug-AMD (788ea46).

Verification

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean (default and --all-features)
  • cargo test -p victory-gpu --locked descriptor::host::tests -- --test-threads=1: 5 passed (dynamic_failed_search_is_cached_until_release and dynamic_search_can_find_a_run_across_the_cursor passed), 1 pre-existing NVIDIA heap-cap failure (dynamic_slots_are_held_until_released)
  • cargo xtask policy: 182 files ok
**@⁠bartikele** on GitHub · 2026-11-25 12:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2394) `bartikele:gpu-dynamic-slot-search-cache` → `main` · +79 −12 · 1 files · 1 commits · open ## Summary - Track o_run (the smallest run size that failed to allocate since the last elease) and per-frame ailed_walks inside HostHeap's DynamicSlots state (crates/victory-gpu/src/descriptor/host.rs). - When a dynamic slot search for slots fails, subsequent requests for >= n slots return None immediately until a elease frees slots, and full failed walks are capped at 8 per presented frame (crate::queue::presented(), un-gated from diagnostics in crates/victory-gpu/src/queue.rs). - Prevents multi-second per-frame CPU stalls when dynamic descriptor slots saturate in heavy frames. - Add unit test descriptor::host::tests::dynamic_failed_search_is_cached_until_release. Inspired by Belobug's VIctory-Belobug-AMD (788ea46). ## Verification - cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean (default and --all-features) - cargo test -p victory-gpu --locked descriptor::host::tests -- --test-threads=1: 5 passed (dynamic_failed_search_is_cached_until_release and dynamic_search_can_find_a_run_across_the_cursor passed), 1 pre-existing NVIDIA heap-cap failure (dynamic_slots_are_held_until_released) - cargo xtask policy: 182 files ok
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:04:30 +00:00
Author
Owner

@⁠qtLkz on GitHub · 2026-11-25 12:44 UTC · original

Tested on NVIDIA: RTX 4070 Ti (Ada), driver 621.01, Windows 11 Pro build 26300, Rust 1.98.1 pinned, base main 940d32f.

cargo test -p victory-gpu --locked descriptor::host::tests -- --test-threads=1

This PR alone: 5 passed, 1 failed, the same result you got. dynamic_failed_search_is_cached_until_release and dynamic_search_can_find_a_run_across_the_cursor pass. The one failure is the pre-existing heap cap (dynamic_slots_are_held_until_released, NumDescriptors >= HEAP_VIEWS at host.rs:1526), which this PR does not cause.

This PR merged on top of #2315 + #2322 (the NVIDIA heap-cap fix, see #2317): merges cleanly, 7/7 pass, including dynamic_slots_are_held_until_released and the_clamp_bound_fits_in_a_host_heap. So the new cached-failure logic also works with the clamped heap that NVIDIA gets.

AI-assisted (Claude).

**@⁠qtLkz** on GitHub · 2026-11-25 12:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2394#issuecomment-7162799759) Tested on NVIDIA: RTX 4070 Ti (Ada), driver 621.01, Windows 11 Pro build 26300, Rust 1.98.1 pinned, base main `940d32f`. `cargo test -p victory-gpu --locked descriptor::host::tests -- --test-threads=1` **This PR alone:** 5 passed, 1 failed, the same result you got. `dynamic_failed_search_is_cached_until_release` and `dynamic_search_can_find_a_run_across_the_cursor` pass. The one failure is the pre-existing heap cap (`dynamic_slots_are_held_until_released`, `NumDescriptors >= HEAP_VIEWS` at host.rs:1526), which this PR does not cause. **This PR merged on top of #2315 + #2322** (the NVIDIA heap-cap fix, see #2317): merges cleanly, **7/7 pass**, including `dynamic_slots_are_held_until_released` and `the_clamp_bound_fits_in_a_host_heap`. So the new cached-failure logic also works with the clamped heap that NVIDIA gets. AI-assisted (Claude).
Author
Owner

@⁠bartikele on GitHub · 2026-11-25 13:25 UTC · original

Thank you @⁠AndyLatimer for catching that! You're completely right — capping failed walks per frame would drop draws later in the same frame even after releases free the heap.

Updated gpu-dynamic-slot-search-cache with your upper-bound
o_run update on
elease:

  • Removed ailed_frame, ailed_walks, the 8-walk cap, and the queue.rs change (this PR now touches only crates/victory-gpu/src/descriptor/host.rs).
  • On
    elease, guard.no_run is updated to guard.no_run.max(left + (end - at) + right + 1) over the newly merged free run, keeping larger tables fast-failing when only small fragments are freed while immediately allowing tables that fit once enough contiguous slots are released.
  • Added descriptor::host::tests::a_frame_of_failed_searches_still_gets_slots_after_a_release and updated dynamic_failed_search_is_cached_until_release.

Verified:

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default and --all-features): clean
  • cargo test -p victory-gpu --locked descriptor::host::tests -- --test-threads=1: 6 passed (_frame_of_failed_searches_still_gets_slots_after_a_release, dynamic_failed_search_is_cached_until_release, and dynamic_search_can_find_a_run_across_the_cursor pass), 1 pre-existing NVIDIA heap-cap failure (dynamic_slots_are_held_until_released)
  • cargo xtask policy: 182 files ok
**@⁠bartikele** on GitHub · 2026-11-25 13:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2394#issuecomment-7163768771) Thank you @⁠AndyLatimer for catching that! You're completely right — capping failed walks per frame would drop draws later in the same frame even after releases free the heap. Updated gpu-dynamic-slot-search-cache with your upper-bound o_run update on elease: - Removed ailed_frame, ailed_walks, the 8-walk cap, and the queue.rs change (this PR now touches only crates/victory-gpu/src/descriptor/host.rs). - On elease, guard.no_run is updated to guard.no_run.max(left + (end - at) + right + 1) over the newly merged free run, keeping larger tables fast-failing when only small fragments are freed while immediately allowing tables that fit once enough contiguous slots are released. - Added descriptor::host::tests::a_frame_of_failed_searches_still_gets_slots_after_a_release and updated dynamic_failed_search_is_cached_until_release. Verified: - cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default and --all-features): clean - cargo test -p victory-gpu --locked descriptor::host::tests -- --test-threads=1: 6 passed (_frame_of_failed_searches_still_gets_slots_after_a_release, dynamic_failed_search_is_cached_until_release, and dynamic_search_can_find_a_run_across_the_cursor pass), 1 pre-existing NVIDIA heap-cap failure (dynamic_slots_are_held_until_released) - cargo xtask policy: 182 files ok
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:01 UTC · original · edited 2026-11-25 22:17 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main: main has moved since the last triage, and the branch now conflicts in crates/victory-gpu/src/descriptor/host.rs. It will be reviewed again once it is rebased onto current main.

Previous verdict for this head: merge candidate.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2394#issuecomment-7166170341) · edited 2026-11-25 22:17 UTC <!-- victory-triage v1 head=594728c2bc0ac94e02c6c3262d56e920d03d400c verdict=needs-rebase at=2026-11-25T22:21:00Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main`: `main` has moved since the last triage, and the branch now conflicts in `crates/victory-gpu/src/descriptor/host.rs`. It will be reviewed again once it is rebased onto current `main`. Previous verdict for this head: merge candidate. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠AndyLatimer on GitHub · 2026-11-25 12:52 UTC · original · reviewed

Tested on an RTX 3060 Ti (driver 610.88), Windows 11 26200, d179a25.

The per-frame cap drops tables that would fit. release resets no_run but not failed_walks, and failed_frame only moves when present runs. Once a frame has had 8 failed walks, every dynamic call returns None until the next present, even after releases have freed the whole heap. draw.rs then drops the draw or dispatch (table_failed), and pair() falls back to dynamic(2) for host copies' views. On main those calls succeed once slots come back. A saturated frame is the case this PR is for, so after the 8th failed search the rest of that frame loses draws main makes. Before the first present, it lasts until one comes.

A test for it. On this PR it fails at the last line (left: None, right: Some(4)). On main (without the no_run line, which main doesn't have) it passes, and it passes with the change below:

/// Releases that free only single slots keep runs of two known missing
/// (no walk), and once the heap is free again a table gets its slots in
/// the same frame, however many searches failed before.
#[test]
fn a_frame_of_failed_searches_still_gets_slots_after_a_release() {
    let Some(heap) = HostHeap::new(false, 4) else {
        eprintln!("no host descriptor heap; skipped");
        return;
    };
    let all = heap.dynamic(heap.dynamic).unwrap();
    for k in 0..16 {
        // Every other slot: no two free slots are next to each other.
        heap.release(all + 2 * k, 1);
        assert_eq!(heap.dynamic(2), None);
    }
    assert_eq!(heap.next.lock().unwrap().no_run, 2);
    heap.release(all, heap.dynamic);
    assert_eq!(heap.dynamic(2), Some(all));
}

A change that keeps the speed-up without the cap. Instead of clearing no_run, a release can keep it an upper bound. The only free run a release changes is the one the freed slots join. Its two sides were free runs already, so they are shorter than no_run, and so is the walk over them:

let (at, end) = (at as usize, (at + n).min(self.dynamic) as usize);
if at >= end {
    return;
}
guard.taken[at..end].fill(false);
if guard.no_run != usize::MAX {
    let left = guard.taken[..at].iter().rev().take_while(|t| !**t).count();
    let right = guard.taken[end..].iter().take_while(|t| !**t).count();
    guard.no_run = guard.no_run.max(left + (end - at) + right + 1);
}

Freeing a few slots in a full heap then keeps bigger tables failing fast without a walk, which is what the cap was for, and nothing depends on presents: failed_frame, failed_walks, the cap and the queue.rs change can go. Your test only loses its two failed_walks asserts. no_run == 2 still holds, and the release at its end lifts no_run to 3, so dynamic(2) still finds bulk. Between two releases, what is left is at most one failed walk per distinct table size below no_run, since each failure lowers it.

With that change (031e5b9, a local branch on d179a25, 41 lines added and 34 removed):

  • descriptor::host::tests: all pass but the known heap-cap size check. With that check (lines 1520 and 1522) commented out, dynamic_slots_are_held_until_released passes too, so its dynamic/release part runs against the change.
  • cargo test -p victory-gpu --locked: 143 passed, plus the 2 known heap-cap failures (main here: 141 passed and the same 2).
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, default and --all-features: clean.

Not measured: walks per frame in the title, with or without either version.

**@⁠AndyLatimer** on GitHub · 2026-11-25 12:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2394#pullrequestreview-6057951717) · **reviewed** Tested on an RTX 3060 Ti (driver 610.88), Windows 11 26200, `d179a25`. **The per-frame cap drops tables that would fit.** `release` resets `no_run` but not `failed_walks`, and `failed_frame` only moves when `present` runs. Once a frame has had 8 failed walks, every `dynamic` call returns `None` until the next present, even after releases have freed the whole heap. `draw.rs` then drops the draw or dispatch (`table_failed`), and `pair()` falls back to `dynamic(2)` for host copies' views. On `main` those calls succeed once slots come back. A saturated frame is the case this PR is for, so after the 8th failed search the rest of that frame loses draws `main` makes. Before the first present, it lasts until one comes. A test for it. On this PR it fails at the last line (`left: None`, `right: Some(4)`). On `main` (without the `no_run` line, which `main` doesn't have) it passes, and it passes with the change below: ```rust /// Releases that free only single slots keep runs of two known missing /// (no walk), and once the heap is free again a table gets its slots in /// the same frame, however many searches failed before. #[test] fn a_frame_of_failed_searches_still_gets_slots_after_a_release() { let Some(heap) = HostHeap::new(false, 4) else { eprintln!("no host descriptor heap; skipped"); return; }; let all = heap.dynamic(heap.dynamic).unwrap(); for k in 0..16 { // Every other slot: no two free slots are next to each other. heap.release(all + 2 * k, 1); assert_eq!(heap.dynamic(2), None); } assert_eq!(heap.next.lock().unwrap().no_run, 2); heap.release(all, heap.dynamic); assert_eq!(heap.dynamic(2), Some(all)); } ``` **A change that keeps the speed-up without the cap.** Instead of clearing `no_run`, a release can keep it an upper bound. The only free run a release changes is the one the freed slots join. Its two sides were free runs already, so they are shorter than `no_run`, and so is the walk over them: ```rust let (at, end) = (at as usize, (at + n).min(self.dynamic) as usize); if at >= end { return; } guard.taken[at..end].fill(false); if guard.no_run != usize::MAX { let left = guard.taken[..at].iter().rev().take_while(|t| !**t).count(); let right = guard.taken[end..].iter().take_while(|t| !**t).count(); guard.no_run = guard.no_run.max(left + (end - at) + right + 1); } ``` Freeing a few slots in a full heap then keeps bigger tables failing fast without a walk, which is what the cap was for, and nothing depends on presents: `failed_frame`, `failed_walks`, the cap and the `queue.rs` change can go. Your test only loses its two `failed_walks` asserts. `no_run == 2` still holds, and the release at its end lifts `no_run` to 3, so `dynamic(2)` still finds `bulk`. Between two releases, what is left is at most one failed walk per distinct table size below `no_run`, since each failure lowers it. With that change (`031e5b9`, a local branch on `d179a25`, 41 lines added and 34 removed): - `descriptor::host::tests`: all pass but the known heap-cap size check. With that check (lines 1520 and 1522) commented out, `dynamic_slots_are_held_until_released` passes too, so its `dynamic`/`release` part runs against the change. - `cargo test -p victory-gpu --locked`: 143 passed, plus the 2 known heap-cap failures (`main` here: 141 passed and the same 2). - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`, default and `--all-features`: clean. Not measured: walks per frame in the title, with or without either version.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 13:19 UTC · original · reviewed

Skip repeated dynamic descriptor slot searches (DynamicSlots cursor). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

**@⁠catminou4** on GitHub · 2026-11-25 13:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2394#pullrequestreview-6058344691) · **reviewed** Skip repeated dynamic descriptor slot searches (DynamicSlots cursor). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
Author
Owner

@⁠Desamodeth on GitHub · 2026-11-26 20:54 UTC · original · reviewed

Ordered releases become quadratic after a single failed allocation in 594728c2. Each release walks through the slots freed by earlier calls while holding the heap mutex. draw::State::drop returns ranges in recording order.

Adjacent two-slot ranges returned main 63bcca43 This PR #3218 249ba2a6
4,096 40.2 µs 3.34 ms 37.6 µs
8,192 80.4–80.5 µs 13.59–13.78 ms 75.2 µs

To reproduce, allocate the two-slot ranges from an empty 65,536-slot heap, take the remainder in one allocation, then call dynamic(1) once and check it fails. Time only the loop returning the pairs in allocation order. Afterwards, one allocation reclaimed the entire released span at the original index. Omitting the failed request brought this PR back to 42 µs at 4,096 ranges, including with one free slot.

I’d favor #3218 for this path. It also completed 128 cycles of releasing a pair, trying three slots and reclaiming the pair in 0.17 ms (4.85–4.91 ms here). A local 64-slot cap on each neighbor scan fixed the ordered case but was slower on that second workload. CPU-only harness using the production allocator methods and mutex, Ryzen 7 9800X3D, rustc 1.98.1 -C opt-level=3. Two runs with opposite case order, 13 timed samples per case per run after warm-up. In-game frequency and frame time remain unmeasured.

AI-assisted review with Codex.

**@⁠Desamodeth** on GitHub · 2026-11-26 20:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2394#pullrequestreview-6080381236) · **reviewed** Ordered releases become quadratic after a single failed allocation in `594728c2`. Each `release` walks through the slots freed by earlier calls while holding the heap mutex. [`draw::State::drop`](https://github.com/Marvisak/VIctory/blob/63bcca43c6a00a758510398fa43096ce7e4f7df0/crates/victory-gpu/src/draw.rs#L111-L119) returns ranges in recording order. | Adjacent two-slot ranges returned | main `63bcca43` | This PR | #3218 `249ba2a6` | | ---: | ---: | ---: | ---: | | 4,096 | 40.2 µs | 3.34 ms | 37.6 µs | | 8,192 | 80.4–80.5 µs | 13.59–13.78 ms | 75.2 µs | To reproduce, allocate the two-slot ranges from an empty 65,536-slot heap, take the remainder in one allocation, then call `dynamic(1)` once and check it fails. Time only the loop returning the pairs in allocation order. Afterwards, one allocation reclaimed the entire released span at the original index. Omitting the failed request brought this PR back to 42 µs at 4,096 ranges, including with one free slot. I’d favor #3218 for this path. It also completed 128 cycles of releasing a pair, trying three slots and reclaiming the pair in 0.17 ms (4.85–4.91 ms here). A local 64-slot cap on each neighbor scan fixed the ordered case but was slower on that second workload. CPU-only harness using the production allocator methods and mutex, Ryzen 7 9800X3D, rustc 1.98.1 `-C opt-level=3`. Two runs with opposite case order, 13 timed samples per case per run after warm-up. In-game frequency and frame time remain unmeasured. AI-assisted review with Codex.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.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/2394/head:github-bot/gh-2394'
git switch 'github-bot/gh-2394'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2394'
git switch 'github-bot/gh-2394'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2394'
git switch 'github-bot/gh-2394'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2394'
git switch 'main'
git merge --squash 'github-bot/gh-2394'
git switch 'main'
git merge --ff-only 'github-bot/gh-2394'
git switch 'main'
git merge 'github-bot/gh-2394'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2394
No description provided.