GPU: scan virtual regions on copy_mapped and write_mapped fallback (#783) #1350

Closed
wbkepler wants to merge 1 commit from upstream-pr/1350 into main
wbkepler commented 2026-11-24 17:34:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T17:34:52Z.


Summary

Implements #783:

  • Adds VirtualQuery region-scan copy fallback in copy_mapped and write_mapped (crates/victory-gpu/src/host.rs) so mapped copies spanning uncommitted or guard-page gaps copy committed sub-regions safely instead of failing the entire span.
  • Adds unit/WARP regression tests covering partial/gapped virtual region copies.

Verification

  • cargo clippy -p victory-gpu --all-targets — passed
  • cargo test -p victory-gpu — passed
  • cargo xtask policy — passed
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587727739 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1350). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T17:34:52Z. --- ## Summary Implements #783: - Adds `VirtualQuery` region-scan copy fallback in `copy_mapped` and `write_mapped` (`crates/victory-gpu/src/host.rs`) so mapped copies spanning uncommitted or guard-page gaps copy committed sub-regions safely instead of failing the entire span. - Adds unit/WARP regression tests covering partial/gapped virtual region copies. ## Verification - `cargo clippy -p victory-gpu --all-targets` — passed - `cargo test -p victory-gpu` — passed - `cargo xtask policy` — passed
maplerouteadmin-dev commented 2026-11-24 18:06:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by maplerouteadmin-dev on 2026-11-24T17:58:01Z.


Tested on hardware that hits the fallback path hard; it helps a lot here.

Setup: RTX 5070 12 GB (driver 32.0.16.2114), Ryzen 5 5600X, 32 GB, Windows 11; Xbox Series 1.0.2.1; diag build (--profile diag --features diagnostics), VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1, warm shader cache. Base: main at ffe310e plus #966, Peppacodes exp/mesh-host-lanes (#940/#189) and a port of the #951 fix, needed to reach the world on NVIDIA. #1350 merged on top with one trivial conflict (both sides append at the end of host.rs; kept both). cargo test -p victory-gpu passes. No game data used.

Same route both runs: boot, menus, first cutscene into the world, about 60 s there. Medians over the 5 s frame-rate lines with frames over 500 ms (world only):

before with #1350
ms/frame 6 134 2 200
copies, ms/frame 5 382 1 223
copies, MB/frame 3 244 1 220
copy cost, s per GB (median per line) ~1.53 ~0.50
fallbacks/frame (copystat) 5 744 ~3 000
on the GPU, ms/frame 345 376
copying back, ms/frame 184 273

The two runs do not copy the same amount per frame (the scene differs from second to second), so the per-GB figure is the fairer comparison: about 3x cheaper. moves (the first ReadProcessMemory) stays at 65-90 ms/frame in both, so before the change almost all of the copy time was the 64 KiB / 4 KiB retry.

Unchanged by the PR: draws dropped without a host pipeline are similar in both runs (hundreds to thousands per frame, untranslated shaders) and the scene is black in both. No crash, no device removal.

What dominates with the PR in: copies are still ~1.2 s/frame, and in some lines write-watch askings take up to ~1.2 s/frame (1480 watches 1175.70 ms, 14644.6 MB checked, 10186.5 MB unchanged), with GPU time spiking to 1.2-1.4 s in a few lines.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139962863 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1350#issuecomment-7139962863). Originally posted by [maplerouteadmin-dev](https://github.com/maplerouteadmin-dev) on 2026-11-24T17:58:01Z. --- Tested on hardware that hits the fallback path hard; it helps a lot here. **Setup:** RTX 5070 12 GB (driver 32.0.16.2114), Ryzen 5 5600X, 32 GB, Windows 11; Xbox Series 1.0.2.1; diag build (`--profile diag --features diagnostics`), `VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1`, warm shader cache. Base: `main` at `ffe310e` plus #966, Peppacodes `exp/mesh-host-lanes` (#940/#189) and a port of the #951 fix, needed to reach the world on NVIDIA. #1350 merged on top with one trivial conflict (both sides append at the end of `host.rs`; kept both). `cargo test -p victory-gpu` passes. No game data used. **Same route both runs:** boot, menus, first cutscene into the world, about 60 s there. Medians over the 5 s frame-rate lines with frames over 500 ms (world only): | | before | with #1350 | |---|---|---| | ms/frame | 6 134 | 2 200 | | copies, ms/frame | 5 382 | 1 223 | | copies, MB/frame | 3 244 | 1 220 | | **copy cost, s per GB** (median per line) | **~1.53** | **~0.50** | | fallbacks/frame (copystat) | 5 744 | ~3 000 | | on the GPU, ms/frame | 345 | 376 | | copying back, ms/frame | 184 | 273 | The two runs do not copy the same amount per frame (the scene differs from second to second), so the per-GB figure is the fairer comparison: about **3x cheaper**. `moves` (the first `ReadProcessMemory`) stays at 65-90 ms/frame in both, so before the change almost all of the copy time was the 64 KiB / 4 KiB retry. Unchanged by the PR: draws dropped without a host pipeline are similar in both runs (hundreds to thousands per frame, untranslated shaders) and the scene is black in both. No crash, no device removal. What dominates with the PR in: copies are still ~1.2 s/frame, and in some lines write-watch askings take up to ~1.2 s/frame (`1480 watches 1175.70 ms, 14644.6 MB checked, 10186.5 MB unchanged`), with GPU time spiking to 1.2-1.4 s in a few lines.
DaviTostes commented 2026-11-24 19:04:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T18:09:04Z.


In-game A/B on AMD/Linux, since the PR has unit/WARP checks but no title numbers.

Setup: RX 9060 XT (RDNA4, RADV 26.3.1), Arch, Wine 11.22, DXVK 3.1.1 dxgi, vkd3d-proton 3.2.0, WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=n"; release MSVC build, package 1.0.2.1 (build unknown (b99f876b…)); scripted Enter through the menus, 600 s per run.

main ffe310e this head 2f27ea1
world lines 33 35
fps 0.30 0.50
frame 4027 ms 2942 ms
copies 2627 ms / 56.7 MB 1127 ms / 35.8 MB
textures 421 ms 535 ms

So the fallback does what it says on AMD/Wine too: copy time roughly halves to a third in the world, and the frame gets shorter. Directional only — two runs, not the same save/frame window.

Both runs reach the prologue (credits render; the 3D scene behind stays black, #841), then hit RtlReleaseSRWLockExclusive and the title's +0x2215c35 null write (#774); no device removal in either. Not tested: Windows/NVIDIA, controlled same-save, long sessions.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140230937 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1350#issuecomment-7140230937). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T18:09:04Z. --- In-game A/B on **AMD/Linux**, since the PR has unit/WARP checks but no title numbers. **Setup:** RX 9060 XT (RDNA4, RADV 26.3.1), Arch, Wine 11.22, DXVK 3.1.1 `dxgi`, vkd3d-proton 3.2.0, `WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=n"`; release MSVC build, package 1.0.2.1 (`build unknown (b99f876b…)`); scripted Enter through the menus, 600 s per run. | | `main` `ffe310e` | this head `2f27ea1` | |---|---:|---:| | world lines | 33 | 35 | | fps | 0.30 | **0.50** | | frame | 4027 ms | **2942 ms** | | copies | 2627 ms / 56.7 MB | **1127 ms / 35.8 MB** | | textures | 421 ms | 535 ms | So the fallback does what it says on AMD/Wine too: copy time roughly halves to a third in the world, and the frame gets shorter. Directional only — two runs, not the same save/frame window. Both runs reach the prologue (credits render; the 3D scene behind stays black, #841), then hit `RtlReleaseSRWLockExclusive` and the title's `+0x2215c35` null write (#774); no device removal in either. **Not tested:** Windows/NVIDIA, controlled same-save, long sessions.
catminou4 commented 2026-11-24 21:02:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:09:07Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; this is source review plus the PR's own Windows tests.

copy_mapped/write_mapped now walk regions with for_regions (VirtualQuery) instead of blind 64 KiB/4 KiB piece retries: the whole-range RPM/WPM prefix is preserved (done.min(len)), unreadable source pages are zeroed in one write_bytes call (zero_unmapped), and only committed readable regions go through RPM/WPM with piece fallback if a region unmaps mid-read. read/write now return (ok, bytes_done) so partial progress is not re-copied. This removes the quadratic retry behavior on sparsely-mapped title memory. Windows-only; logic is careful (wrapping_add offsets, dst bounds by construction).

<!-- greyfinch-sync:Marvisak/VIctory:review:6046547146 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1350#pullrequestreview-6046547146). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:09:07Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; this is source review plus the PR's own Windows tests. copy_mapped/write_mapped now walk regions with for_regions (VirtualQuery) instead of blind 64 KiB/4 KiB piece retries: the whole-range RPM/WPM prefix is preserved (done.min(len)), unreadable source pages are zeroed in one write_bytes call (zero_unmapped), and only committed readable regions go through RPM/WPM with piece fallback if a region unmaps mid-read. read/write now return (ok, bytes_done) so partial progress is not re-copied. This removes the quadratic retry behavior on sparsely-mapped title memory. Windows-only; logic is careful (wrapping_add offsets, dst bounds by construction).
maplerouteadmin-dev commented 2026-11-24 21:28:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by maplerouteadmin-dev on 2026-11-24T21:15:31Z.


Correction to my earlier numbers on #1350 and #1351. After posting them I found a background GPU process on the test machine (a hidden CUDA miner, since removed) holding about 2.8 GB of VRAM and using the GPU. Every build was measured under the same conditions, so the comparisons between builds hold, but the absolute frame times and some of the device removals were inflated by it. Re-measured on the clean machine:

RTX 5070 12 GB (driver 32.0.16.2114), Ryzen 5 5600X, 32 GB, Windows 11; Xbox Series 1.0.2.1; diag build; same scripted input (VICTORY_KEYS), 240 s per run, builds alternated, one process at a time. Base = main ffe310e + #966 + Peppacodes exp/mesh-host-lanes + a #951 port. Medians over world frame-rate lines (frames over 500 ms). No game data used.

base + #1350 + #1350 + #1351 + #1350 + #1351 + gap fix
runs 2 2 2 3
ms/frame 4 667 2 434 2 000 1 633
copies, ms/frame 4 240 1 222 1 347 635
copied per draw, MB 2.69 3.20 4.13 2.54
write-watch, ms/frame 271 479 456 238
runs ending in device removal 1 1 1 1

Same conclusions as before: #1350 cuts the copy cost sharply; #1351 as is copies more per draw (the copies left unwatched after a failed gap, see my comment on #1351); with the gap fix it is the fastest of the four. The device removals are real on this card without the background process too: about one run in two, on every build, so they are not caused by either PR.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144689244 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1350#issuecomment-7144689244). Originally posted by [maplerouteadmin-dev](https://github.com/maplerouteadmin-dev) on 2026-11-24T21:15:31Z. --- **Correction to my earlier numbers on #1350 and #1351.** After posting them I found a background GPU process on the test machine (a hidden CUDA miner, since removed) holding about 2.8 GB of VRAM and using the GPU. Every build was measured under the same conditions, so the comparisons between builds hold, but the absolute frame times and some of the device removals were inflated by it. Re-measured on the clean machine: RTX 5070 12 GB (driver 32.0.16.2114), Ryzen 5 5600X, 32 GB, Windows 11; Xbox Series 1.0.2.1; diag build; same scripted input (`VICTORY_KEYS`), 240 s per run, builds alternated, one process at a time. Base = `main` `ffe310e` + #966 + Peppacodes `exp/mesh-host-lanes` + a #951 port. Medians over world frame-rate lines (frames over 500 ms). No game data used. | | base | + #1350 | + #1350 + #1351 | + #1350 + #1351 + gap fix | |---|---|---|---|---| | runs | 2 | 2 | 2 | 3 | | ms/frame | 4 667 | 2 434 | 2 000 | **1 633** | | copies, ms/frame | 4 240 | 1 222 | 1 347 | **635** | | copied per draw, MB | 2.69 | 3.20 | 4.13 | **2.54** | | write-watch, ms/frame | 271 | 479 | 456 | **238** | | runs ending in device removal | 1 | 1 | 1 | 1 | Same conclusions as before: #1350 cuts the copy cost sharply; #1351 as is copies more per draw (the copies left unwatched after a failed gap, see my comment on #1351); with the gap fix it is the fastest of the four. The device removals are real on this card without the background process too: about one run in two, on every build, so they are not caused by either PR.
upstream-sync closed this pull request 2026-11-25 01:06:18 +00:00
Marvisak commented 2026-11-25 01:08:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:38:04Z.


Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #943. The same VirtualQuery region walk as #943 (same issue), larger (357 lines), without measurements, and its test must find a 5 MiB MEM_FREE hole in a shared test process within 16 tries (flaky).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148717206 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1350#issuecomment-7148717206). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:38:04Z. --- Automated triage for the maintainers. Closing because another open pull request covers the same change. See #943. The same VirtualQuery region walk as #943 (same issue), larger (357 lines), without measurements, and its test must find a 5 MiB MEM_FREE hole in a shared test process within 16 tries (flaky). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

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
Marvisak/VIctory!1350
No description provided.