GPU: cache registered shadow buffer lookups, with the generation bump after the take #53

Open
github-bot wants to merge 2 commits from github-bot/gh-53 into main AGit
Owner

@⁠Barba2k2 on GitHub · 2026-11-25 22:08 UTC · original
Barba2k2:fix/find-cache-generation-order → main · +160 −12 · 1 files · 2 commits · open

Two commits. The first (4784a4a, authored by Adika713, unchanged) adds a one-entry thread-local cache for registered-buffer hits in shadow::find / find_any, validated by the buffer generation. The second fixes the ordering of that generation bump in in_place_let_go.

The cache validates a hit by reading the generation before and after lookup, which only works if a change is followed by its bump. With the bump at the top of in_place_let_go, a recording thread can read the new generation, find the copy that is about to be taken, and cache it with nothing left to invalidate it. The fix bumps under the buffers() lock right after the take, and only when something was taken. register and unregister already bump under that lock. Also uses ? in cached_lookup (clippy::question_mark).

The race only affects VICTORY_INPLACE=2 (off by default).

Tested: cargo clippy -p victory-gpu --lib --tests --locked clean; cargo test -p victory-gpu --lib --locked -- --test-threads=1 189 passed, 0 failed, 4 ignored. No regression test for the interleaving (it needs a real placed shadow). Not run in-game.

**@⁠Barba2k2** on GitHub · 2026-11-25 22:08 UTC · [original](https://github.com/DexNom/VIctory/pull/53) `Barba2k2:fix/find-cache-generation-order` → `main` · +160 −12 · 1 files · 2 commits · open Two commits. The first (4784a4a, authored by Adika713, unchanged) adds a one-entry thread-local cache for registered-buffer hits in `shadow::find` / `find_any`, validated by the buffer generation. The second fixes the ordering of that generation bump in `in_place_let_go`. The cache validates a hit by reading the generation before and after `lookup`, which only works if a change is followed by its bump. With the bump at the top of `in_place_let_go`, a recording thread can read the new generation, find the copy that is about to be taken, and cache it with nothing left to invalidate it. The fix bumps under the `buffers()` lock right after the `take`, and only when something was taken. `register` and `unregister` already bump under that lock. Also uses `?` in `cached_lookup` (clippy::question_mark). The race only affects `VICTORY_INPLACE=2` (off by default). Tested: `cargo clippy -p victory-gpu --lib --tests --locked` clean; `cargo test -p victory-gpu --lib --locked -- --test-threads=1` 189 passed, 0 failed, 4 ignored. No regression test for the interleaving (it needs a real placed shadow). Not run in-game.
The find cache validates a hit by reading the generation before and after
`lookup`. That only works if a change is followed by its bump. Bumping at
the top of `in_place_let_go` let a recording thread read the new
generation, find the copy that was about to be taken, and cache it at that
generation with nothing left to invalidate it.

Bump under the `buffers()` lock right after the `take`, and only when
something was taken. `register` and `unregister` already bump under that
lock, so they need no change.

Also use `?` in `cached_lookup` (clippy::question_mark).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:32:46 +00:00
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/53/head:github-bot/gh-53'
git switch 'github-bot/gh-53'

Merge

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