GPU: reuse page buffers in tracking and copy-back #3772

Open
xjimwilson wants to merge 2 commits from upstream-pr/3772 into main
xjimwilson commented 2026-11-28 17:46:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by xjimwilson on 2026-11-28T17:46:52Z.


Low-risk CPU-side cleanups in victory-gpu's page tracking and copy-back paths. Each one removes avoidable work; none changes behaviour.

Changes

  • watch.rs: no allocation in the write-fault handler. Changed::save ran under the guard lock on the title's threads and allocated and zeroed a fresh 64 KiB buffer on every first write to an armed page. It now takes one from a small pool (SPARE_PAGES, up to 256 pages / 16 MiB). Pages that are taken, disarmed or consumed by copy_back_marked give their buffer back.
  • shadow.rs: one page buffer per thread for copy-back comparisons. copy_back_page, copy_back_marked and copy_back_or_not each allocated a new 64 KiB Vec per page compared. They now share a per-thread PageScratch. Its stale contents are never read: each use starts with a full successful read.
  • watch.rs: take_split uses binary search for unmapped pages. protect_noting builds the unmapped list in page order (checked with a debug_assert!), so the per-page contains scan became binary_search.
  • watch.rs: cheaper Drop for Tracked. It now walks only the held pages (range_mut) and swap-removes itself, instead of looking up every page in its range and running retain. A tracker holds each page at most once, and holder order is not used anywhere.
  • host.rs: withheld ranges grouped by copy. Each copy-back range is now checked only against its own copy's withheld ranges, not every withheld range in the submission.

Testing

  • cargo clippy -p victory-gpu --target x86_64-pc-windows-msvc --tests, with and without --features diagnostics: no warnings. This was cross-checked from Linux with blake3 built pure-Rust, because ml64.exe isn't available there.
  • Not run: cargo test --workspace and an in-game frame-rate comparison. Both need Windows. Please run the tests before merging.

Expected impact is small (CPU-side overhead only). The larger items (overlapping CPU/GPU submissions, splitting the guard lock, finer write marks, shader lookup hoisting) are deferred until the diagnostics frame-rate line shows where a world frame's time goes.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5542967807 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3772). Originally posted by [xjimwilson](https://github.com/xjimwilson) on 2026-11-28T17:46:52Z. --- Low-risk CPU-side cleanups in `victory-gpu`'s page tracking and copy-back paths. Each one removes avoidable work; none changes behaviour. ## Changes - **`watch.rs`: no allocation in the write-fault handler.** `Changed::save` ran under the guard lock on the title's threads and allocated and zeroed a fresh 64 KiB buffer on every first write to an armed page. It now takes one from a small pool (`SPARE_PAGES`, up to 256 pages / 16 MiB). Pages that are taken, disarmed or consumed by `copy_back_marked` give their buffer back. - **`shadow.rs`: one page buffer per thread for copy-back comparisons.** `copy_back_page`, `copy_back_marked` and `copy_back_or_not` each allocated a new 64 KiB `Vec` per page compared. They now share a per-thread `PageScratch`. Its stale contents are never read: each use starts with a full successful read. - **`watch.rs`: `take_split` uses binary search for unmapped pages.** `protect_noting` builds the unmapped list in page order (checked with a `debug_assert!`), so the per-page `contains` scan became `binary_search`. - **`watch.rs`: cheaper `Drop for Tracked`.** It now walks only the held pages (`range_mut`) and swap-removes itself, instead of looking up every page in its range and running `retain`. A tracker holds each page at most once, and holder order is not used anywhere. - **`host.rs`: withheld ranges grouped by copy.** Each copy-back range is now checked only against its own copy's withheld ranges, not every withheld range in the submission. ## Testing - `cargo clippy -p victory-gpu --target x86_64-pc-windows-msvc --tests`, with and without `--features diagnostics`: no warnings. This was cross-checked from Linux with `blake3` built pure-Rust, because `ml64.exe` isn't available there. - **Not run:** `cargo test --workspace` and an in-game frame-rate comparison. Both need Windows. Please run the tests before merging. Expected impact is small (CPU-side overhead only). The larger items (overlapping CPU/GPU submissions, splitting the guard lock, finer write marks, shader lookup hoisting) are deferred until the diagnostics frame-rate line shows where a world frame's time goes. --- _Generated by [Claude Code](https://claude.ai/code)_
oni-swr commented 2026-11-28 19:10:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T19:10:20Z.


Independent CPU-only WARP verification on Windows 11 Pro build 26200.9974 using system WARP 10.0.26100.9818 and SDK dxil.dll 1.8.2502.11. Both WARP flags were set, and the compositor initialized on the Microsoft software adapter. The synthetic SDK validator smoke test passed.

Revision victory-gpu tests with diagnostics
main 63bcca43c6a00a758510398fa43096ce7e4f7df0 246 passed, 0 failed, 1 ignored benchmark
PR head 7dcddfbe5e46fac6dee280df127da6629093d98c 246 passed, 0 failed, 1 ignored benchmark

Strict victory-gpu Clippy passed in both default and diagnostics configurations on both revisions. The asset-policy check passed for all 191 files on each. I found no correctness defect in pool hand-back when pages are taken, disarmed, or consumed by marked copy-back, including its failed-read return.

AI-assisted by Codex (gpt-6.2-sol).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7244343487 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3772#issuecomment-7244343487). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-28T19:10:20Z. --- Independent CPU-only WARP verification on Windows 11 Pro build 26200.9974 using system WARP 10.0.26100.9818 and SDK dxil.dll 1.8.2502.11. Both WARP flags were set, and the compositor initialized on the Microsoft software adapter. The synthetic SDK validator smoke test passed. | Revision | victory-gpu tests with diagnostics | | --- | --- | | main `63bcca43c6a00a758510398fa43096ce7e4f7df0` | 246 passed, 0 failed, 1 ignored benchmark | | PR head `7dcddfbe5e46fac6dee280df127da6629093d98c` | 246 passed, 0 failed, 1 ignored benchmark | Strict `victory-gpu` Clippy passed in both default and diagnostics configurations on both revisions. The asset-policy check passed for all 191 files on each. I found no correctness defect in pool hand-back when pages are taken, disarmed, or consumed by marked copy-back, including its failed-read return. AI-assisted by Codex (gpt-6.2-sol).
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/3772:upstream-pr/3772'
git switch 'upstream-pr/3772'

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