GPU: mark retaken aliases without collecting temporary page numbers #3395

Open
Desamodeth wants to merge 2 commits from upstream-pr/3395 into main
Desamodeth commented 2026-11-26 21:58:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-26T21:58:01Z.


memory::retake_dropped calls watch::retake for ranges withheld until frame end. Each call collected the linked page numbers into a temporary vector while holding the global guard lock. mark updates each tracker's dirty state, so retake can borrow the alias lists under that lock. It marks the original range first, followed by its aliases in the existing order.

Windows x64, Ryzen 7 9800X3D, rustc 1.98.1 release. Results per call on main@63bcca43 and this change:

Source pages × aliases per page CPU time, before → after Temporary peak, before → after Heap requests, before → after
1 × 0 27.9 → 24.9 ns 0 → 0 B 0 → 0
1 × 1 67.5 → 42.2 ns 32 → 0 B 1 → 0
8 × 1 313 → 258 ns 64 → 0 B 2 → 0
64 × 4 6.55 → 6.08 µs 2,048 → 0 B 7 → 0

The synthetic fixture used the production retake, mark, guard mutex, alias map and dirty trackers. Each measured page had a buffer-copy tracker and a texture tracker. The table uses already-dirty copies to isolate temporary storage. Starting from a clean tracker at 64 × 4, both versions retained 5,976 B of dirty-set nodes. Peak live heap growth fell from 8,024 to 5,976 B. The fixture checked the exact marked pages, the untouched texture tracker, and the range end. Timings are medians of 12 batches in alternating order, with allocation counts from a separate binary. Game frame time was not measured.

Windows checks: cargo test -p victory-gpu --lib watch:: -- --test-threads=1 and workspace Clippy with --all-targets -- -D warnings, both with default features and all features. cargo xtask policy also passed.

Coordination claim. AI-assisted with Codex Astra 6.2 High.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5517700420 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3395). Originally posted by [Desamodeth](https://github.com/Desamodeth) on 2026-11-26T21:58:01Z. --- `memory::retake_dropped` calls `watch::retake` for ranges withheld until frame end. Each call collected the linked page numbers into a temporary vector while holding the global guard lock. `mark` updates each tracker's dirty state, so `retake` can borrow the alias lists under that lock. It marks the original range first, followed by its aliases in the existing order. Windows x64, Ryzen 7 9800X3D, rustc 1.98.1 release. Results per call on `main@63bcca43` and this change: | Source pages × aliases per page | CPU time, before → after | Temporary peak, before → after | Heap requests, before → after | | --- | ---: | ---: | ---: | | 1 × 0 | 27.9 → 24.9 ns | 0 → 0 B | 0 → 0 | | 1 × 1 | 67.5 → 42.2 ns | 32 → 0 B | 1 → 0 | | 8 × 1 | 313 → 258 ns | 64 → 0 B | 2 → 0 | | 64 × 4 | 6.55 → 6.08 µs | 2,048 → 0 B | 7 → 0 | The synthetic fixture used the production `retake`, `mark`, guard mutex, alias map and dirty trackers. Each measured page had a buffer-copy tracker and a texture tracker. The table uses already-dirty copies to isolate temporary storage. Starting from a clean tracker at 64 × 4, both versions retained 5,976 B of dirty-set nodes. Peak live heap growth fell from 8,024 to 5,976 B. The fixture checked the exact marked pages, the untouched texture tracker, and the range end. Timings are medians of 12 batches in alternating order, with allocation counts from a separate binary. Game frame time was not measured. Windows checks: `cargo test -p victory-gpu --lib watch:: -- --test-threads=1` and workspace Clippy with `--all-targets -- -D warnings`, both with default features and all features. `cargo xtask policy` also passed. [Coordination claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7204147852). AI-assisted with Codex Astra 6.2 High.
Dukestar69 commented 2026-11-26 22:08:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T22:08:03Z.

Review: APPROVED


LGTM — verified on Windows against origin/main (63bcca4).

  • Iterating g.alias_of.range(first..last).flat_map(|(_, links)| links) directly in retake avoids a heap allocation on every call since mark only needs &Guards.
  • cargo test -p victory-gpu --lib watch:: -- --test-threads=1: 15 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6080997462 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3395#pullrequestreview-6080997462). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T22:08:03Z. **Review:** APPROVED --- LGTM — verified on Windows against `origin/main` (`63bcca4`). - Iterating `g.alias_of.range(first..last).flat_map(|(_, links)| links)` directly in `retake` avoids a heap allocation on every call since `mark` only needs `&Guards`. - `cargo test -p victory-gpu --lib watch:: -- --test-threads=1`: 15 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 22:24:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:24:22Z.

Review: APPROVED


Looks good. watch::retake (crates/victory-gpu/src/watch.rs:840-847) cleanly avoids the temporary Vec<usize> allocation by iterating g.alias_of.range(first..last).flat_map(|(_, links)| links.iter()) directly while holding the shared Guards borrow. mark (watch.rs:851-859) only takes &Guards, does not mutate alias_of, and preserves the GUARDS -> Changed.0 lock ordering.

Verified by merging 31a5b6bd onto origin/main (63bcca43):

  • cargo xtask policy (191 files ok) and cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics) pass cleanly.
  • watch::tests:: (15/15) passes on both RTX 5090 and WARP (--features diagnostics, VICTORY_D3D12_DEBUG=1).
  • Also verified with a multi-alias retake test covering 0, 1, and multiple aliased pages alongside a non-copy tracker: all aliased copy trackers are marked dirty, non-copy trackers remain clean, untouched pages stay clean, and existing page guards stay protected.
<!-- greyfinch-sync:Marvisak/VIctory:review:6081101780 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3395#pullrequestreview-6081101780). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T22:24:22Z. **Review:** APPROVED --- Looks good. `watch::retake` (`crates/victory-gpu/src/watch.rs:840-847`) cleanly avoids the temporary `Vec<usize>` allocation by iterating `g.alias_of.range(first..last).flat_map(|(_, links)| links.iter())` directly while holding the shared `Guards` borrow. `mark` (`watch.rs:851-859`) only takes `&Guards`, does not mutate `alias_of`, and preserves the `GUARDS -> Changed.0` lock ordering. Verified by merging `31a5b6bd` onto `origin/main` (`63bcca43`): - `cargo xtask policy` (191 files ok) and `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`) pass cleanly. - `watch::tests::` (15/15) passes on both RTX 5090 and WARP (`--features diagnostics`, `VICTORY_D3D12_DEBUG=1`). - Also verified with a multi-alias retake test covering 0, 1, and multiple aliased pages alongside a non-copy tracker: all aliased copy trackers are marked dirty, non-copy trackers remain clean, untouched pages stay clean, and existing page guards stay protected.
Jackster commented 2026-11-26 22:29:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:29:00Z.


Windows 11, 63bcca4 + this PR, Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010):

  • cargo test -p victory-gpu --lib: 231 passed / 0 failed / 1 ignored — the same counts as unpatched 63bcca4 here.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.

No test is added, so this is behavioural coverage: the watch tests around title_memory_remapped/retake pass, and the change removes the temporary Vec that was collected while the guards lock was held — the range is still first..last and every alias link is still marked. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204717878 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3395#issuecomment-7204717878). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T22:29:00Z. --- Windows 11, `63bcca4` + this PR, Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010): - `cargo test -p victory-gpu --lib`: 231 passed / 0 failed / 1 ignored — the same counts as unpatched `63bcca4` here. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. No test is added, so this is behavioural coverage: the watch tests around `title_memory_remapped`/`retake` pass, and the change removes the temporary `Vec` that was collected while the guards lock was held — the range is still `first..last` and every alias link is still marked. Synthetic only. AI-assisted.
Desamodeth commented 2026-11-30 06:34:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-30T06:34:10Z.


Handoff note: I'm stepping away from this project. This PR is clean on main (63bcca43) with green CI and 2 approvals — maintainers or other contributors are welcome to merge or take it over.

AI-assisted with Gemini 4 Neon

<!-- greyfinch-sync:Marvisak/VIctory:comment:7270782818 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3395#issuecomment-7270782818). Originally posted by [Desamodeth](https://github.com/Desamodeth) on 2026-11-30T06:34:10Z. --- **Handoff note:** I'm stepping away from this project. This PR is clean on `main` (`63bcca43`) with green CI and 2 approvals — maintainers or other contributors are welcome to merge or take it over. *AI-assisted with Gemini 4 Neon*
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/3395:upstream-pr/3395'
git switch 'upstream-pr/3395'

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