Batch adjacent physical-page scatter unmaps #108

Closed
Kamiloj9 wants to merge 1 commit from upstream-pr/108 into main
Kamiloj9 commented 2026-11-24 21:32:38 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Kamiloj9 on 2026-11-24T21:32:38Z.


Summary

  • Unmap consecutive 64 KiB destinations with zero page entries as one operation in XMemMapPhysicalPagesScatter.
  • Preserve per-entry behavior for nonzero mappings, gaps, reverse order, duplicate addresses and input-array overlap.
  • Cover run selection, neighboring mappings, mixed zero and nonzero entries, and early failure in regression tests.

Verification

  • All 97 victory-hle library tests passed with diagnostics on the PR base. Targeted Clippy, the diagnostic build and the asset-policy check passed locally.
  • On RTX 4080 SUPER, instrumentation counted 8,951 remapping lock acquisitions across 17,656 entries in 68 successful scatter calls. The previous loop acquired the lock once per entry.
  • In one warm-cache replay, median host-present gaps were 753 → 643 ms in the early 3D window and 2,186 → 763 ms in the following window. The windows are relative to the first frame with 500 draws. Shots and streaming activity can vary between runs.
<!-- greyfinch-sync:fxceless/victory-fork:issue:6591839292 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/108). Originally posted by [Kamiloj9](https://github.com/Kamiloj9) on 2026-11-24T21:32:38Z. --- ## Summary - Unmap consecutive 64 KiB destinations with zero page entries as one operation in `XMemMapPhysicalPagesScatter`. - Preserve per-entry behavior for nonzero mappings, gaps, reverse order, duplicate addresses and input-array overlap. - Cover run selection, neighboring mappings, mixed zero and nonzero entries, and early failure in regression tests. ## Verification - All 97 `victory-hle` library tests passed with diagnostics on the PR base. Targeted Clippy, the diagnostic build and the asset-policy check passed locally. - On RTX 4080 SUPER, instrumentation counted 8,951 remapping lock acquisitions across 17,656 entries in 68 successful scatter calls. The previous loop acquired the lock once per entry. - In one warm-cache replay, median host-present gaps were 753 → 643 ms in the early 3D window and 2,186 → 763 ms in the following window. The windows are relative to the first frame with 500 draws. Shots and streaming activity can vary between runs.
BitWuehler commented 2026-11-24 23:09:38 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by BitWuehler on 2026-11-24T22:40:03Z.


Tested on CachyOS Linux (Ryzen 7 9800X3D, RTX 5080 620.73.04, GE-Proton11-14, release build) bundled with #95, #92, #159 on top of 4e17478 + #454/#127/#154:

  • victory-hle under GE-Proton11-14 (wine): 96 passed, 1 failed (pre-existing Wine only_loopback_is_reachable missing WSAConnectByList; all xmem scatter-unmap & remap tests pass).
  • Clean 353 s world session with 49–67 mapping changes/frame logged, 0.00 ms waiting for title memory to hold still, and 0 crashes or device removals.

(AI-assisted build/log analysis.)

<!-- greyfinch-sync:fxceless/victory-fork:comment:7146502363 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/108#issuecomment-7146502363). Originally posted by [BitWuehler](https://github.com/BitWuehler) on 2026-11-24T22:40:03Z. --- Tested on CachyOS Linux (`Ryzen 7 9800X3D`, `RTX 5080` `620.73.04`, `GE-Proton11-14`, release build) bundled with `#95`, `#92`, `#159` on top of `4e17478` + `#454`/`#127`/`#154`: - `victory-hle` under `GE-Proton11-14` (`wine`): **96 passed, 1 failed** (pre-existing Wine `only_loopback_is_reachable` missing `WSAConnectByList`; all `xmem` scatter-unmap & remap tests pass). - Clean 353 s world session with `49–67` mapping changes/frame logged, `0.00 ms` `waiting for title memory to hold still`, and 0 crashes or device removals. *(AI-assisted build/log analysis.)*
LastThylacine commented 2026-11-24 23:09:38 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by LastThylacine on 2026-11-24T22:42:01Z.


Measured together with #95 (range locks for title-memory mapping), which changes the same lock in xmem.rs. The two merge without conflicts, and #92 merges cleanly on top of both.

Setup. One exe: #95 (b18da0e) + this PR (2765f3d) + #92 (02c2743), all on 4e17478. Each change can be turned off by a switch, so every run uses the same warm shader cache. VICTORY_MAPPING_RANGES=0 is in #95. The other two switches were local, for this measurement only: one unmaps entry by entry as before this PR, the other detiles whole as before #92. Hardware: RTX 5070 Ti, i5-13600KF. Diag build, no speed switches, 8 min a run, each run started from the same fresh data. Medians are over the world (frame lines with ≥ 300 draws).

A: none B: #95 C: #95 + #108 D: #95 + #108 + #92 A2: none, again
frame, median / mean 956 / 1,036 ms 527 / 575 ms 517 / 646 ms 561 / 671 ms 819 / 1,069 ms
textures 382 ms 52 ms 36 ms 45 ms 369 ms
texture refresh, all threads 228 ms 48 ms 42 ms 47 ms 268 ms
waiting for title memory to hold still 174 ms 0 0 0 216 ms
mapping changes per frame 1,076 778 516 546 —
GPU / copies / copy back 148 / 45 / 83 ms 139 / 43 / 91 ms 139 / 41 / 87 ms 150 / 42 / 84 ms 144 / 41 / 79 ms
device removed no no no no no

What this PR does on top of #95. It cuts the mapping changes the runtime makes per frame by a third (778 → 516), and texture time drops a little (52 → 36 ms). The frame median does not move beyond noise. The two "none" runs, A and A2, differ by 14% in median, so differences under ~15% are not resolved by one run each. Once #95 lets reads and remaps of different bytes go on together, the lock is no longer where frames wait. The fewer acquisitions this PR gives then save CPU rather than wait time. Your standalone numbers (753 → 643 ms) are measured without #95, and these runs do not contradict them.

Together. The victory-hle, victory-gpu and victory-formats tests pass on the combination. The xmem tests also pass with VICTORY_MAPPING_RANGES=0 and with entry-by-entry unmaps. No device removal in any run.

AI use: measured and written with Claude Code (Claude Opus 5.5); posted with my approval.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7146540982 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/108#issuecomment-7146540982). Originally posted by [LastThylacine](https://github.com/LastThylacine) on 2026-11-24T22:42:01Z. --- Measured together with #95 (range locks for title-memory mapping), which changes the same lock in `xmem.rs`. The two merge without conflicts, and #92 merges cleanly on top of both. **Setup.** One exe: #95 (b18da0e) + this PR (2765f3d) + #92 (02c2743), all on 4e17478. Each change can be turned off by a switch, so every run uses the same warm shader cache. `VICTORY_MAPPING_RANGES=0` is in #95. The other two switches were local, for this measurement only: one unmaps entry by entry as before this PR, the other detiles whole as before #92. Hardware: RTX 5070 Ti, i5-13600KF. Diag build, no speed switches, 8 min a run, each run started from the same fresh data. Medians are over the world (frame lines with ≥ 300 draws). | | A: none | B: #95 | C: #95 + #108 | D: #95 + #108 + #92 | A2: none, again | |---|---:|---:|---:|---:|---:| | frame, median / mean | 956 / 1,036 ms | 527 / 575 ms | 517 / 646 ms | 561 / 671 ms | 819 / 1,069 ms | | textures | 382 ms | 52 ms | 36 ms | 45 ms | 369 ms | | texture refresh, all threads | 228 ms | 48 ms | 42 ms | 47 ms | 268 ms | | waiting for title memory to hold still | 174 ms | 0 | 0 | 0 | 216 ms | | mapping changes per frame | 1,076 | 778 | **516** | 546 | — | | GPU / copies / copy back | 148 / 45 / 83 ms | 139 / 43 / 91 ms | 139 / 41 / 87 ms | 150 / 42 / 84 ms | 144 / 41 / 79 ms | | device removed | no | no | no | no | no | **What this PR does on top of #95.** It cuts the mapping changes the runtime makes per frame by a third (778 → 516), and texture time drops a little (52 → 36 ms). The frame median does not move beyond noise. The two "none" runs, A and A2, differ by 14% in median, so differences under ~15% are not resolved by one run each. Once #95 lets reads and remaps of different bytes go on together, the lock is no longer where frames wait. The fewer acquisitions this PR gives then save CPU rather than wait time. Your standalone numbers (753 → 643 ms) are measured without #95, and these runs do not contradict them. **Together.** The victory-hle, victory-gpu and victory-formats tests pass on the combination. The xmem tests also pass with `VICTORY_MAPPING_RANGES=0` and with entry-by-entry unmaps. No device removal in any run. AI use: measured and written with Claude Code (Claude Opus 5.5); posted with my approval.
sprunk-addict commented 2026-11-25 09:08:48 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by sprunk-addict on 2026-11-25T08:15:50Z.


Loading time with this PR on top of #95, RTX 3060 Ti 8 GB / i7-10700KF: no measurable difference (4 pairs), no errors.

Setup: Windows 11 Pro 26300, 32 GB, diagnostics build of main a26859f + #95 (b18da0e) + this PR (2765f3d), all merged without conflicts; shader cache and pipeline library warm; Series X profile. For an A/B in one exe I added a local switch (not proposed here) that sends scatter unmaps one page at a time as before when VICTORY_SCATTER_RUNS=0. Each run presses Enter once on the account screen, loads the autosave at the cell window and stops 5 s after the first frame with 500+ draws. Order: off, on, on, off, off, on, on, off.

Run Batched unmaps Enter to world Remap time during loading (sum of #95's "under way") Changes during loading
1 off 69 s 24 s ~110k
2 on 78 s 74 s ~221k
3 on 76 s 32 s ~137k
4 off 47 s 6 s ~160k
5 off 49 s 5 s ~159k
6 on 48 s 4.5 s ~134k
7 on 46 s 3 s ~207k
8 off 46 s 2 s ~136k
  • Loading takes 46-49 s either way, except in runs that hit a slow phase where each change of the mapping costs 250-600 µs instead of about 10 µs and the page-table lock is busy most of the time. That phase hit the first three runs, with and without the batching, so this PR does not prevent it; its cause is still open (memory or file-cache state is my first guess).
  • No access violations, device removals or failed page mappings in any run; cargo test -p victory-hle xmem passes on the merge (14, including the two new tests).

AI-assisted (Claude Code): the merge, the runs and the log parsing.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7156811083 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/108#issuecomment-7156811083). Originally posted by [sprunk-addict](https://github.com/sprunk-addict) on 2026-11-25T08:15:50Z. --- **Loading time with this PR on top of #95, RTX 3060 Ti 8 GB / i7-10700KF: no measurable difference (4 pairs), no errors.** Setup: Windows 11 Pro 26300, 32 GB, diagnostics build of `main` `a26859f` + #95 (`b18da0e`) + this PR (`2765f3d`), all merged without conflicts; shader cache and pipeline library warm; Series X profile. For an A/B in one exe I added a local switch (not proposed here) that sends scatter unmaps one page at a time as before when `VICTORY_SCATTER_RUNS=0`. Each run presses Enter once on the account screen, loads the autosave at the cell window and stops 5 s after the first frame with 500+ draws. Order: off, on, on, off, off, on, on, off. | Run | Batched unmaps | Enter to world | Remap time during loading (sum of #95's "under way") | Changes during loading | |---|---|---|---|---| | 1 | off | 69 s | 24 s | ~110k | | 2 | on | 78 s | 74 s | ~221k | | 3 | on | 76 s | 32 s | ~137k | | 4 | off | 47 s | 6 s | ~160k | | 5 | off | 49 s | 5 s | ~159k | | 6 | on | 48 s | 4.5 s | ~134k | | 7 | on | 46 s | 3 s | ~207k | | 8 | off | 46 s | 2 s | ~136k | - Loading takes 46-49 s either way, except in runs that hit a slow phase where each change of the mapping costs 250-600 µs instead of about 10 µs and the page-table lock is busy most of the time. That phase hit the first three runs, with and without the batching, so this PR does not prevent it; its cause is still open (memory or file-cache state is my first guess). - No access violations, device removals or failed page mappings in any run; `cargo test -p victory-hle xmem` passes on the merge (14, including the two new tests). AI-assisted (Claude Code): the merge, the runs and the log parsing.
upstream-sync closed this pull request 2026-11-26 01:05:51 +00:00

Pull request closed

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!108
No description provided.