GPU: the dynamic slot search finds a free run across its starting point (port of VIctory#974) #201

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

@⁠lcg007xd-c on GitHub · 2026-11-25 21:31 UTC · original
lcg007xd-c:port/dynamic-wrap-scan → main · +26 −2 · 1 files · 1 commits · open

HostHeap::dynamic looks for n free slots in a row. It searches from next to the end, then from 0 to next. A free run that starts before next and ends after it is never seen whole: the first pass sees only its tail, and the second pass stops at next. If that run is the only one big enough, the search fails even though the slots are free, and then:

  • no_run is set to n, so no table of n slots or more is made on that heap until the next release;
  • the failure counts toward the 8 failed walks allowed per frame. Once those are used up, every dynamic table in the frame fails, on every heap.

So a heap with enough free slots can still drop tables, which is the README's known problem "when they run out, some draws of a frame are dropped".

What

  • Port of upstream VIctory#974 (c1c3281, pushkarreddyy), cherry-picked with -x. The second pass now goes n - 1 slots past next (but never past the end), so a run that crosses next is found. This is a two-line change. The walk cap and the no_run memo of this fork are unchanged.
  • The upstream test is replaced. In that test, after the release, the search found the free slots at next (16 and up) rather than the run across it, so it did not test the bug. The new test, a_free_run_across_the_search_start_is_found, leaves exactly one free run of 20 across next. Main misses it; this branch returns it.

Tested (Linux, no GPU)

victory-gpu does not build on Linux, so I copied the search loop, old and new, into a small program:

  • the test's case: the old loop returns None, the new one returns the run;
  • 200,000 random heaps (1 to 64 slots, random taken slots, random next and n), compared with a brute-force search. The new loop finds a run exactly when one exists, and every run it returns is free. The old loop missed an existing run in 5,875 of those heaps.

Also:

  • cargo clippy -p victory-gpu --no-deps --all-targets --target x86_64-pc-windows-msvc: the same findings as main, none new.
  • cargo check -p victory-gpu --tests --target x86_64-pc-windows-msvc: builds.

Not tested

  • The new GPU test itself (Windows with a GPU).
  • The title: I don't know how often a free run crosses next in a heavy frame, so I can't say how many dropped tables this recovers.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 21:31 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/201) `lcg007xd-c:port/dynamic-wrap-scan` → `main` · +26 −2 · 1 files · 1 commits · open `HostHeap::dynamic` looks for `n` free slots in a row. It searches from `next` to the end, then from 0 to `next`. A free run that starts before `next` and ends after it is never seen whole: the first pass sees only its tail, and the second pass stops at `next`. If that run is the only one big enough, the search fails even though the slots are free, and then: - `no_run` is set to `n`, so no table of `n` slots or more is made on that heap until the next release; - the failure counts toward the 8 failed walks allowed per frame. Once those are used up, every dynamic table in the frame fails, on every heap. So a heap with enough free slots can still drop tables, which is the README's known problem *"when they run out, some draws of a frame are dropped"*. ## What - **Port of upstream VIctory#974 (`c1c3281`, pushkarreddyy), cherry-picked with `-x`.** The second pass now goes `n - 1` slots past `next` (but never past the end), so a run that crosses `next` is found. This is a two-line change. The walk cap and the `no_run` memo of this fork are unchanged. - **The upstream test is replaced.** In that test, after the release, the search found the free slots at `next` (16 and up) rather than the run across it, so it did not test the bug. The new test, `a_free_run_across_the_search_start_is_found`, leaves exactly one free run of 20 across `next`. Main misses it; this branch returns it. ## Tested (Linux, no GPU) victory-gpu does not build on Linux, so I copied the search loop, old and new, into a small program: - the test's case: the old loop returns `None`, the new one returns the run; - 200,000 random heaps (1 to 64 slots, random taken slots, random `next` and `n`), compared with a brute-force search. The new loop finds a run exactly when one exists, and every run it returns is free. The old loop missed an existing run in 5,875 of those heaps. Also: - `cargo clippy -p victory-gpu --no-deps --all-targets --target x86_64-pc-windows-msvc`: the same findings as main, none new. - `cargo check -p victory-gpu --tests --target x86_64-pc-windows-msvc`: builds. ## Not tested - The new GPU test itself (Windows with a GPU). - The title: I don't know how often a free run crosses `next` in a heavy frame, so I can't say how many dropped tables this recovers. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
(cherry picked from commit c1c32819e93e3f5e2f6ad4b1ef8155cac06ef46d)

Adapted to this fork: the search runs over `spare` slots, and the walk
cap and the no-run memo before it are kept. The upstream test is
replaced: after its release the search found the free slots at the
cursor (16 on), not the run across it, so it did not test the case.
`a_free_run_across_the_search_start_is_found` leaves one run of 20,
across the place the search goes on from: missed before the change
(no table of 20 or more was made until the next release), found with it.

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

@⁠qtLkz on GitHub · 2026-11-25 22:09 UTC · original

Tested on NVIDIA, where the view heap is capped at 1,000,000: RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, this PR on main 4f62c2a.

On its own, the new test fails here:

descriptor::host::tests::a_free_run_across_the_search_start_is_found
left:  (933440, 933490)
right: (4, 54)

On a capped heap the dynamic range starts after the title slots (933,440), not at 4. This is the same assumption that makes dynamic_slots_are_held_until_released fail on NVIDIA on main. With #153 applied as well, both tests pass, so it's the test's expectation rather than the search itself. Comparing against the heap's first dynamic slot, rather than a literal 4, would make it pass on its own.

AI-assisted (Claude).

**@⁠qtLkz** on GitHub · 2026-11-25 22:09 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/201#issuecomment-7175999967) Tested on NVIDIA, where the view heap is capped at 1,000,000: RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, this PR on main `4f62c2a`. On its own, the new test fails here: ``` descriptor::host::tests::a_free_run_across_the_search_start_is_found left: (933440, 933490) right: (4, 54) ``` On a capped heap the dynamic range starts after the title slots (933,440), not at 4. This is the same assumption that makes `dynamic_slots_are_held_until_released` fail on NVIDIA on main. With #153 applied as well, both tests pass, so it's the test's expectation rather than the search itself. Comparing against the heap's first dynamic slot, rather than a literal 4, would make it pass on its own. AI-assisted (Claude).
Author
Owner

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

A fix for the NVIDIA failure of the new test, verified on an RTX 4070 Ti (capped 1,000,000-slot heap), on top of this PR's head 5f03aee.

One commit, cherry-pickable: https://github.com/qtLkz/VIctory-Belobug-AMD/tree/pr201-capped-heap-test

The test assumed the dynamic slots start at 4. On a capped heap they start after the 933,440 title slots, so it now takes the start from heap.count:

let first = heap.count;
...
assert_eq!((a, b), (first, first + 50));
...
assert_eq!(heap.dynamic(20), Some(first + spare - 20));

The search it checks is unchanged, and on an uncapped heap heap.count is still 4.

cargo test -p victory-gpu --lib --locked, three runs: a_free_run_across_the_search_start_is_found ... ok each time (it failed with left: (933440, 933490), right: (4, 54) before). The one remaining failure, dynamic_slots_are_held_until_released, is the pre-existing main one that #153 fixes; it is not from this PR.

git fetch https://github.com/qtLkz/VIctory-Belobug-AMD.git pr201-capped-heap-test
git cherry-pick 2704d02

AI-assisted (Claude).

**@⁠qtLkz** on GitHub · 2026-11-25 22:44 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/201#issuecomment-7176738808) A fix for the NVIDIA failure of the new test, verified on an RTX 4070 Ti (capped 1,000,000-slot heap), on top of this PR's head `5f03aee`. One commit, cherry-pickable: https://github.com/qtLkz/VIctory-Belobug-AMD/tree/pr201-capped-heap-test The test assumed the dynamic slots start at 4. On a capped heap they start after the 933,440 title slots, so it now takes the start from `heap.count`: ```rust let first = heap.count; ... assert_eq!((a, b), (first, first + 50)); ... assert_eq!(heap.dynamic(20), Some(first + spare - 20)); ``` The search it checks is unchanged, and on an uncapped heap `heap.count` is still 4. `cargo test -p victory-gpu --lib --locked`, three runs: `a_free_run_across_the_search_start_is_found ... ok` each time (it failed with `left: (933440, 933490), right: (4, 54)` before). The one remaining failure, `dynamic_slots_are_held_until_released`, is the pre-existing main one that #153 fixes; it is not from this PR. ``` git fetch https://github.com/qtLkz/VIctory-Belobug-AMD.git pr201-capped-heap-test git cherry-pick 2704d02 ``` AI-assisted (Claude).
Author
Owner

@⁠Yoshi-233 on GitHub · 2026-11-26 01:06 UTC · original

I checked the allocator logic on Ubuntu x86-64 using the actual HostHeap::dynamic and release method bodies from 4f62c2a and 5f03aee in a CPU harness.

For each of two dynamic range starts (4 and 933,440), I swept all 256 occupancy masks of an eight-slot range, eight cursor positions, and requests of one to eight slots. A separate oracle tried every valid contiguous start in cursor order. On each 16,384-case sweep, main falsely reported exhaustion 450 times. The PR had zero mismatches. Releasing successful allocations restored the original bitmap.

With 65,536 spare slots, the 20-slot run crossing the cursor was also found at the expected absolute index for both starts: 65,520 and 998,956. Main missed both. This independently supports using the heap's actual start in the hardware test, as qtLkz suggested above. The D3D12 device and heap construction were outside this check.

**@⁠Yoshi-233** on GitHub · 2026-11-26 01:06 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/201#issuecomment-7179445412) I checked the allocator logic on Ubuntu x86-64 using the actual `HostHeap::dynamic` and `release` method bodies from `4f62c2a` and `5f03aee` in a CPU harness. For each of two dynamic range starts (4 and 933,440), I swept all 256 occupancy masks of an eight-slot range, eight cursor positions, and requests of one to eight slots. A separate oracle tried every valid contiguous start in cursor order. On each 16,384-case sweep, main falsely reported exhaustion 450 times. The PR had zero mismatches. Releasing successful allocations restored the original bitmap. With 65,536 spare slots, the 20-slot run crossing the cursor was also found at the expected absolute index for both starts: 65,520 and 998,956. Main missed both. This independently supports using the heap's actual start in the hardware test, as qtLkz suggested above. The D3D12 device and heap construction were outside this check.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 19:47 UTC · original

Tested natively on Windows with an AMD card: RX 7900 XT (RDNA3), driver 32.0.32029.2010, Windows 11 Pro 26300. Head 5f03aee on 4f62c2a. The heap tests run on the hardware adapter, not WARP. On this card the view heap is not capped (1,048,576 dynamic slots).

  • a_free_run_across_the_search_start_is_found passes on this branch, alone and in 30 of 30 full-lib runs. All 13 descriptor::host tests pass, including dynamic_slots_are_held_until_released.
  • With only the new test applied onto 4f62c2a, it fails every run with left: None, right: Some(1048560). So on real hardware the test catches the missed run when the fix is not there.
  • cargo test -p victory-gpu --lib (debug), 30 runs each of base and branch, interleaved: none of the branch's failures is new.
    • frame::tests::waits_end_on_ticks_and_count_frames failed in 20 of 30 base runs and 23 of 30 branch runs.
    • The watch::tests write-report tests failed a few times on both.
    • Two tests failed once each on the branch only: query::tests::host_timestamps_are_on_the_title_clock and queue::tests::work_after_a_wait_runs_once_the_other_queue_signals. Both also fail on base when the query and queue tests are run again on their own (1 of 100 and 2 of 40).
    • Other heavy jobs were running on the machine at the same time.

Not tested:

  • qtLkz's capped-heap test fix (2704d02). This card has no capped heap.
  • A game run, so I can't say how many dropped tables this recovers in a real frame.
**@⁠adrianmjim** on GitHub · 2026-11-26 19:47 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/201#issuecomment-7201972387) Tested natively on Windows with an AMD card: RX 7900 XT (RDNA3), driver 32.0.32029.2010, Windows 11 Pro 26300. Head 5f03aee on 4f62c2a. The heap tests run on the hardware adapter, not WARP. On this card the view heap is not capped (1,048,576 dynamic slots). - `a_free_run_across_the_search_start_is_found` passes on this branch, alone and in 30 of 30 full-lib runs. All 13 `descriptor::host` tests pass, including `dynamic_slots_are_held_until_released`. - With only the new test applied onto 4f62c2a, it fails every run with `left: None, right: Some(1048560)`. So on real hardware the test catches the missed run when the fix is not there. - `cargo test -p victory-gpu --lib` (debug), 30 runs each of base and branch, interleaved: none of the branch's failures is new. - `frame::tests::waits_end_on_ticks_and_count_frames` failed in 20 of 30 base runs and 23 of 30 branch runs. - The `watch::tests` write-report tests failed a few times on both. - Two tests failed once each on the branch only: `query::tests::host_timestamps_are_on_the_title_clock` and `queue::tests::work_after_a_wait_runs_once_the_other_queue_signals`. Both also fail on base when the query and queue tests are run again on their own (1 of 100 and 2 of 40). - Other heavy jobs were running on the machine at the same time. Not tested: - qtLkz's capped-heap test fix (2704d02). This card has no capped heap. - A game run, so I can't say how many dropped tables this recovers in a real frame.
This pull request can be merged automatically.
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/201/head:github-bot/gh-201'
git switch 'github-bot/gh-201'

Merge

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