GPU: store watch protected/clean guards as coalesced BlockRuns intervals #1065

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

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


Guards.protected and Guards.clean in watch.rs were BTreeSet<usize> holding one entry per 64 KiB block. Each watch::guard() call allocated a Vec<usize> over g.clean.range(first..last) (up to ~150k blocks/frame across ~10 GB of view memory), locked GUARDS twice, and walked every block in first..=last whenever any block in a range was dirty.

  • Replaces protected and clean with BlockRuns (BTreeMap<usize, usize> storing maximal disjoint [start, end) block intervals).
  • Single-lock O(log runs) g.clean.covers(first, last) fast path in guard() with zero allocation when a range is clean, and walks only g.clean.missing_runs(first, last) gaps when blocks are dirty (with install() hoisted above the lock to avoid VEH lock-order inversion).
  • open_here() uses take_runs() to remove and VirtualProtect contiguous runs directly (falling back per-block if a run spans regions).
  • Adds unit test block_runs_intervals_merge_split_and_query.

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

  • watches dropped from ~21.2 ms to ~16.8 ms/frame (guards 17.3 -> 13.4 ms/frame), 0 GPUVM faults, picture unchanged
  • All 12 watch::tests pass under Wine.
<!-- greyfinch-sync:fxceless/victory-fork:issue:6610877127 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1067). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-25T18:18:36Z. --- `Guards.protected` and `Guards.clean` in `watch.rs` were `BTreeSet<usize>` holding one entry per 64 KiB block. Each `watch::guard()` call allocated a `Vec<usize>` over `g.clean.range(first..last)` (up to ~150k blocks/frame across ~10 GB of view memory), locked `GUARDS` twice, and walked every block in `first..=last` whenever any block in a range was dirty. - Replaces `protected` and `clean` with `BlockRuns` (`BTreeMap<usize, usize>` storing maximal disjoint `[start, end)` block intervals). - Single-lock O(log runs) `g.clean.covers(first, last)` fast path in `guard()` with zero allocation when a range is clean, and walks only `g.clean.missing_runs(first, last)` gaps when blocks are dirty (with `install()` hoisted above the lock to avoid VEH lock-order inversion). - `open_here()` uses `take_runs()` to remove and `VirtualProtect` contiguous runs directly (falling back per-block if a run spans regions). - Adds unit test `block_runs_intervals_merge_split_and_query`. Tested on Linux + Wine 11.22 + RX 7900 XT (RADV, `VICTORY_RELAY=2`, 480 s run into the cell scene): - `watches` dropped from ~21.2 ms to ~16.8 ms/frame (`guards` 17.3 -> 13.4 ms/frame), 0 GPUVM faults, picture unchanged - All 12 `watch::tests` pass under Wine.
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/1067:upstream-pr/1067'
git switch 'upstream-pr/1067'

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/1067'
git switch 'upstream-pr/1067'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1067'
git switch 'upstream-pr/1067'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1067'
git switch 'main'
git merge --squash 'upstream-pr/1067'
git switch 'main'
git merge --ff-only 'upstream-pr/1067'
git switch 'main'
git merge 'upstream-pr/1067'
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!1065
No description provided.