GPU: use RwLock read fast path for shadow::BUFFERS and batch heap_buffers defer_refreshes #1066

Open
UwUCammie wants to merge 1 commit from upstream-pr/1068 into main
UwUCammie commented 2026-11-25 18:18:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by UwUCammie on 2026-11-25T18:18:37Z.


All recording threads and heap_buffers contend on the global shadow::BUFFERS mutex on every shadow::find lookup, even though almost all lookups hit an already-created shadow copy. heap_buffers also locked HostList::deferred ~4,600 times per frame in its refresh loop.

  • Switches shadow::BUFFERS from Mutex to RwLock with a shared read-lock fast path in lookup() (only taking the write lock when a buffer entry has not lazily created its shadow yet).
  • Adds HostList::defer_refreshes / Shadow::refresh_many so heap_buffers records all eligible spans under a single deferred() lock.

Tested on Linux + Wine 11.22 + RX 7900 XT (RADV, VICTORY_RELAY=2, 480 s run into the cell scene):

  • Recording time (all threads) dropped from ~242–250 ms to ~210–220 ms/frame, heap buffers non-16th pass dropped from ~39–40 ms to ~33–36 ms, 0 GPUVM faults, picture unchanged.
<!-- greyfinch-sync:fxceless/victory-fork:issue:6610877524 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1068). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-25T18:18:37Z. --- All recording threads and `heap_buffers` contend on the global `shadow::BUFFERS` mutex on every `shadow::find` lookup, even though almost all lookups hit an already-created shadow copy. `heap_buffers` also locked `HostList::deferred` ~4,600 times per frame in its refresh loop. - Switches `shadow::BUFFERS` from `Mutex` to `RwLock` with a shared read-lock fast path in `lookup()` (only taking the write lock when a buffer entry has not lazily created its shadow yet). - Adds `HostList::defer_refreshes` / `Shadow::refresh_many` so `heap_buffers` records all eligible spans under a single `deferred()` lock. Tested on Linux + Wine 11.22 + RX 7900 XT (RADV, `VICTORY_RELAY=2`, 480 s run into the cell scene): - Recording time (all threads) dropped from ~242–250 ms to ~210–220 ms/frame, `heap buffers` non-16th pass dropped from ~39–40 ms to ~33–36 ms, 0 GPUVM faults, picture unchanged.
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/1068:upstream-pr/1068'
git switch 'upstream-pr/1068'

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/1068'
git switch 'upstream-pr/1068'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1068'
git switch 'upstream-pr/1068'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1068'
git switch 'main'
git merge --squash 'upstream-pr/1068'
git switch 'main'
git merge --ff-only 'upstream-pr/1068'
git switch 'main'
git merge 'upstream-pr/1068'
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
fxceless/victory-fork!1066
No description provided.