GPU: bound shadow buffer lookup by maximum registered size instead of 64 entries #2096

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

@⁠fuzeofficlal on GitHub · 2026-11-25 04:49 UTC · original
fuzeofficlal:fix/gpu-shadow-overflow-and-find-906 → main · +143 −21 · 1 files · 1 commits · open

Refs #906.

Summary

  • Replace the fixed .take(64) cap in shadow::find (crates/victory-gpu/src/shadow.rs) with a reverse scan bounded by the maximum buffer size currently registered in BUFFERS (lowest = end.saturating_sub(max_size), returning None immediately when lowest > address).
  • Track max_size on Buffers::insert and recompute it on Buffers::remove when the previous maximum-size entry is unregistered, so misses reaching loose() stop at the live maximum buffer bound while lookups still reach a covering outer buffer past more than 64 smaller inner buffers.

Verification

  • shadow::tests::find_reaches_covering_buffer_past_many_inner_buffers
  • shadow::tests::find_stops_at_max_size_bound_and_tightens_on_unregister
  • cargo clippy -p victory-gpu --tests --locked -- -D warnings and cargo xtask policy: passed.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 04:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2096) `fuzeofficlal:fix/gpu-shadow-overflow-and-find-906` → `main` · +143 −21 · 1 files · 1 commits · open Refs #906. ### Summary - Replace the fixed `.take(64)` cap in `shadow::find` (`crates/victory-gpu/src/shadow.rs`) with a reverse scan bounded by the maximum buffer size currently registered in `BUFFERS` (`lowest = end.saturating_sub(max_size)`, returning `None` immediately when `lowest > address`). - Track `max_size` on `Buffers::insert` and recompute it on `Buffers::remove` when the previous maximum-size entry is unregistered, so misses reaching `loose()` stop at the live maximum buffer bound while lookups still reach a covering outer buffer past more than 64 smaller inner buffers. ### Verification - `shadow::tests::find_reaches_covering_buffer_past_many_inner_buffers` - `shadow::tests::find_stops_at_max_size_bound_and_tightens_on_unregister` - `cargo clippy -p victory-gpu --tests --locked -- -D warnings` and `cargo xtask policy`: passed.
Replace the fixed `.take(64)` cap in `shadow::find` with a scan bounded
by the maximum buffer size currently registered in `BUFFERS`:

- Track `max_size` alongside the `BUFFERS` map, updating it on `register`
  and recomputing it on `unregister` (or replacement shrinkage) when the
  previous maximum-size entry is removed, so the bound stays tight.
- Bound the reverse scan in `find_buffer` using `max_size`, allowing
  lookups to reach a covering outer buffer past more than 64 smaller
  inner buffers while stopping misses immediately outside `max_size`.
- Add unit tests covering lookup past 128 inner buffers and `max_size`
  bounding/tightening on `unregister`.

Refs #906.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:41 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:36 UTC · original · edited 2026-11-25 11:23 UTC

Automated triage for the maintainers.

Merge candidate. shadow::find now scans backwards only from end - max_size (find_buffer), where Buffers tracks the largest registered length and recomputes it when the largest entry is removed or replaced; a buffer that covers [address, end) must start at or after that bound, so lookups still reach an outer buffer past many smaller ones while misses reaching loose() stop early. The overflow guards and the equal-start tie-breaker are gone. #402 overlaps but currently has merge conflicts; this one merges cleanly. CI passes.

On your reply: confirmed in 2f43424, this is what was asked. A minor follow-up, not a blocker: Buffers::remove rescans the whole map each time an entry of the maximum size goes, which is O(n) per release if many buffers share that size; a size-count map would make it O(log n).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2096#issuecomment-7159924855) · edited 2026-11-25 11:23 UTC <!-- victory-triage v1 head=2f434243f82c511c9169b8e5b64363fc3ac0caa9 verdict=merge-candidate at=2026-11-25T11:23:40Z --> Automated triage for the maintainers. **Merge candidate.** `shadow::find` now scans backwards only from `end - max_size` (`find_buffer`), where `Buffers` tracks the largest registered length and recomputes it when the largest entry is removed or replaced; a buffer that covers `[address, end)` must start at or after that bound, so lookups still reach an outer buffer past many smaller ones while misses reaching `loose()` stop early. The overflow guards and the equal-start tie-breaker are gone. #402 overlaps but currently has merge conflicts; this one merges cleanly. CI passes. On your reply: confirmed in `2f43424`, this is what was asked. A minor follow-up, not a blocker: `Buffers::remove` rescans the whole map each time an entry of the maximum size goes, which is O(n) per release if many buffers share that size; a size-count map would make it O(log n). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 10:51 UTC · original

Updated in 2f434243 per triage feedback:

  • Bounded find_buffer by the maximum currently registered buffer size (lowest = end.saturating_sub(max_size) over (lowest, 0)..=(address, usize::MAX)), tightening max_size on unregister when the largest buffer is removed so misses stop early instead of walking the map.
  • Dropped all u64::MAX overflow/saturating guards and the equal-start tie-breaker.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 10:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2096#issuecomment-7160276566) Updated in `2f434243` per triage feedback: - Bounded `find_buffer` by the maximum currently registered buffer size (`lowest = end.saturating_sub(max_size)` over `(lowest, 0)..=(address, usize::MAX)`), tightening `max_size` on `unregister` when the largest buffer is removed so misses stop early instead of walking the map. - Dropped all `u64::MAX` overflow/saturating guards and the equal-start tie-breaker.
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/2096/head:github-bot/gh-2096'
git switch 'github-bot/gh-2096'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2096'
git switch 'github-bot/gh-2096'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2096'
git switch 'github-bot/gh-2096'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2096'
git switch 'main'
git merge --squash 'github-bot/gh-2096'
git switch 'main'
git merge --ff-only 'github-bot/gh-2096'
git switch 'main'
git merge 'github-bot/gh-2096'
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!2096
No description provided.