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

Open
lcg007xd-c wants to merge 1 commit from upstream-pr/201 into main
lcg007xd-c commented 2026-11-25 21:31:22 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by lcg007xd-c on 2026-11-25T21:31:22Z.


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

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5499513903 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/201). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T21:31:22Z. --- `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)
qtLkz commented 2026-11-25 22:09:04 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by qtLkz on 2026-11-25T22:09:04Z.


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).

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7175999967 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/201#issuecomment-7175999967). Originally posted by [qtLkz](https://github.com/qtLkz) on 2026-11-25T22:09:04Z. --- 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 commented 2026-11-25 22:44:49 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by qtLkz on 2026-11-25T22:44:49Z.


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).

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7176738808 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/201#issuecomment-7176738808). Originally posted by [qtLkz](https://github.com/qtLkz) on 2026-11-25T22:44:49Z. --- 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).
Yoshi-233 commented 2026-11-26 01:06:51 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by Yoshi-233 on 2026-11-26T01:06:51Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7179445412 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/201#issuecomment-7179445412). Originally posted by [Yoshi-233](https://github.com/Yoshi-233) on 2026-11-26T01:06:51Z. --- 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.
adrianmjim commented 2026-11-26 19:47:57 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T19:47:57Z.


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.
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7201972387 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/201#issuecomment-7201972387). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-26T19:47:57Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/201:upstream-pr/201'
git switch 'upstream-pr/201'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/201'
git switch 'upstream-pr/201'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/201'
git switch 'upstream-pr/201'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/201'
git switch 'main'
git merge --squash 'upstream-pr/201'
git switch 'main'
git merge --ff-only 'upstream-pr/201'
git switch 'main'
git merge 'upstream-pr/201'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Belobug/VIctory-Belobug-AMD!201
No description provided.