GPU: cache registered shadow buffer lookups #46

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

@⁠Adika713 on GitHub · 2026-11-25 20:31 UTC · original
Adika713:perf/dexnom-find-cache → main · +155 −12 · 1 files · 1 commits · open

Avoid the global buffer-map lock on repeated host buffer lookups.

Every shadow::find / find_any call took the BUFFERS mutex and scanned
the buffer map. Draws bind the same vertex/index buffer repeatedly, so a
recording thread can reuse its last registered-buffer hit. A weak reference
avoided keeping a released copy alive; the existing buffer generation
invalidates the entry when a buffer is registered, unregistered or taken out
of place. Generation bumps now happen before the map change, so a second
generation read cannot miss an invalidation. Loose windows are not cached:
they have no generation and can be let go under another thread's lock.

What is in it

  • A one-entry thread-local cache of registered-buffer hits in shadow.rs.
  • Generation bumps moved before the corresponding BUFFERS mutation in
    register, unregister and in_place_let_go.
  • A regression test for a buffer replaced at the same address, plus an
    ignored CPU-only A/B benchmark.

Tested

Hardware/toolchain: AMD Radeon RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB RAM,
Windows 11, rustc 1.98.1, cargo 1.98.1.

  • cargo check --manifest-path <worktree>/Cargo.toml -p victory-gpu --lib --tests --locked: exit 0.
  • cargo test --manifest-path <worktree>/Cargo.toml -p victory-gpu --lib shadow::find_cache_tests:: -- --test-threads=1: 1 passed; 0 failed; 1 ignored.
  • cargo test --release --manifest-path <worktree>/Cargo.toml -p victory-gpu --lib cached_find_lookup -- --ignored --nocapture --test-threads=1, 3 runs, median of 5 samples of 300,000 calls: locked 30.5 / 30.5 / 30.1 ns, cached 15.8 / 15.5 / 16.7 ns per lookup.
  • cargo test --manifest-path <worktree>/Cargo.toml -p victory-gpu --lib -- --test-threads=1: 20 serial runs, 0 failed; each 189 passed; 0 failed; 4 ignored.
  • cargo test --manifest-path <worktree>/Cargo.toml --workspace -- --test-threads=1: exit 0, 0 failed suites.

Not tested

No game files or paths were supplied, so the game was not run and no in-game
FPS was measured. The benchmark is synthetic and CPU-only.

AI-assisted: OpenCode, model Big Pickle. No game data.

**@⁠Adika713** on GitHub · 2026-11-25 20:31 UTC · [original](https://github.com/DexNom/VIctory/pull/46) `Adika713:perf/dexnom-find-cache` → `main` · +155 −12 · 1 files · 1 commits · open Avoid the global buffer-map lock on repeated host buffer lookups. Every `shadow::find` / `find_any` call took the `BUFFERS` mutex and scanned the buffer map. Draws bind the same vertex/index buffer repeatedly, so a recording thread can reuse its last registered-buffer hit. A weak reference avoided keeping a released copy alive; the existing buffer generation invalidates the entry when a buffer is registered, unregistered or taken out of place. Generation bumps now happen before the map change, so a second generation read cannot miss an invalidation. Loose windows are not cached: they have no generation and can be let go under another thread's lock. **What is in it** - A one-entry thread-local cache of registered-buffer hits in `shadow.rs`. - Generation bumps moved before the corresponding `BUFFERS` mutation in `register`, `unregister` and `in_place_let_go`. - A regression test for a buffer replaced at the same address, plus an ignored CPU-only A/B benchmark. **Tested** Hardware/toolchain: AMD Radeon RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB RAM, Windows 11, `rustc 1.98.1`, `cargo 1.98.1`. - `cargo check --manifest-path <worktree>/Cargo.toml -p victory-gpu --lib --tests --locked`: exit 0. - `cargo test --manifest-path <worktree>/Cargo.toml -p victory-gpu --lib shadow::find_cache_tests:: -- --test-threads=1`: 1 passed; 0 failed; 1 ignored. - `cargo test --release --manifest-path <worktree>/Cargo.toml -p victory-gpu --lib cached_find_lookup -- --ignored --nocapture --test-threads=1`, 3 runs, median of 5 samples of 300,000 calls: locked `30.5 / 30.5 / 30.1 ns`, cached `15.8 / 15.5 / 16.7 ns` per lookup. - `cargo test --manifest-path <worktree>/Cargo.toml -p victory-gpu --lib -- --test-threads=1`: 20 serial runs, 0 failed; each `189 passed; 0 failed; 4 ignored`. - `cargo test --manifest-path <worktree>/Cargo.toml --workspace -- --test-threads=1`: exit 0, 0 failed suites. **Not tested** No game files or paths were supplied, so the game was not run and no in-game FPS was measured. The benchmark is synthetic and CPU-only. AI-assisted: OpenCode, model Big Pickle. No game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:32:33 +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/46/head:github-bot/gh-46'
git switch 'github-bot/gh-46'

Merge

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