Batch consecutive pool-page mappings in an opt-in mode #1063

Open
github-bot wants to merge 2 commits from github-bot/gh-1063 into main AGit
Owner

@⁠gmankab on GitHub · 2026-11-25 18:07 UTC · original
gmankab:perf/batch-page-mapping-runs → main · +192 −40 · 4 files · 2 commits · draft

Texture streaming can spend substantial time replacing one host view per mapped page. This experiment combines consecutive pool-page requests and maps one host view when the backing pages are also consecutive in the same section.

Enable with VICTORY_BATCH_PAGE_MAPPINGS=1. Overlapping source and destination ranges and repeated-page mappings retain their original order. A failed joined request retries the original requests. A successful multi-page view can later be split by an ordinary one-page update.

The queue fixture passed, and all 12 XMem tests passed with the switch on and with it off. The XMem fixture verifies the common allocation base and reads both neighbors after a one-page replacement.

In a separate Win32 API microbenchmark under Wine, 4,096 updates of four pages took 821–830 ms with individual views and 196–197 ms with a four-page view. Both modes verified the bytes they mapped. That measures the remap calls in isolation.

Paired RX 6800 title run

Both 420-second Series S runs used the same instrumented executable, input sequence, and separate reflink clones of one Wine prefix. VICTORY_BATCH_PAGE_MAPPINGS was the only setting changed. Both runs opened the story archives and reached 3D rendering.

Measurement Off On
Loading median 33 ms 33 ms
Loading p95 / p99 40 / 119 ms 47 / 216 ms
Remap time per usual loading frame 11.14 ms 11.77 ms
Remap time per call in those frames 561 µs 551 µs
Mean FPS over recorded 3D intervals 0.16 (28 frames) 0.11 (20 frames)

The loading window covers 10 to 120 seconds after the story archive opened. The 3D window starts at the first host report with at least 500 draws per frame and covers 162 seconds. Draw counts differ between the two 3D samples. This pair provides insufficient evidence for a repeatable FPS gain or a texture-correctness claim, so the switch stays opt-in and the PR remains a draft.

Depends-on: #1060
Tested-on: RX 6800, Xeon E5-2670 v3, Fedora Linux 45 x86_64, Wayland, Wine and RADV in the Victory Flatpak. Synthetic tests used the same Wine environment with DRM devices hidden.
Assisted-by: gpt-6.2 sol xhigh

**@⁠gmankab** on GitHub · 2026-11-25 18:07 UTC · [original](https://github.com/fxceless/victory-fork/pull/1063) `gmankab:perf/batch-page-mapping-runs` → `main` · +192 −40 · 4 files · 2 commits · draft Texture streaming can spend substantial time replacing one host view per mapped page. This experiment combines consecutive pool-page requests and maps one host view when the backing pages are also consecutive in the same section. Enable with `VICTORY_BATCH_PAGE_MAPPINGS=1`. Overlapping source and destination ranges and repeated-page mappings retain their original order. A failed joined request retries the original requests. A successful multi-page view can later be split by an ordinary one-page update. The queue fixture passed, and all 12 XMem tests passed with the switch on and with it off. The XMem fixture verifies the common allocation base and reads both neighbors after a one-page replacement. In a separate Win32 API microbenchmark under Wine, 4,096 updates of four pages took 821–830 ms with individual views and 196–197 ms with a four-page view. Both modes verified the bytes they mapped. That measures the remap calls in isolation. ### Paired RX 6800 title run Both 420-second Series S runs used the same instrumented executable, input sequence, and separate reflink clones of one Wine prefix. `VICTORY_BATCH_PAGE_MAPPINGS` was the only setting changed. Both runs opened the story archives and reached 3D rendering. | Measurement | Off | On | | --- | ---: | ---: | | Loading median | 33 ms | 33 ms | | Loading p95 / p99 | 40 / 119 ms | 47 / 216 ms | | Remap time per usual loading frame | 11.14 ms | 11.77 ms | | Remap time per call in those frames | 561 µs | 551 µs | | Mean FPS over recorded 3D intervals | 0.16 (28 frames) | 0.11 (20 frames) | The loading window covers 10 to 120 seconds after the story archive opened. The 3D window starts at the first host report with at least 500 draws per frame and covers 162 seconds. Draw counts differ between the two 3D samples. This pair provides insufficient evidence for a repeatable FPS gain or a texture-correctness claim, so the switch stays opt-in and the PR remains a draft. Depends-on: https://git.gtahub.st/github/fxceless--victory-fork/pulls/1060 Tested-on: RX 6800, Xeon E5-2670 v3, Fedora Linux 45 x86_64, Wayland, Wine and RADV in the Victory Flatpak. Synthetic tests used the same Wine environment with DRM devices hidden. Assisted-by: gpt-6.2 sol xhigh
Unmapping adjacent one-page file views returns separate placeholders.
A later request can map consecutive physical pages over both addresses,
but MapViewOfFile3 requires a single placeholder of the same size as the
replacement. The former preparation only split a placeholder, so that
sequence can leave the destination unmapped.

If a multi-page replacement fails, coalesce the exact placeholder
range and retry only when the merge succeeds. Extend the physical-page
test to write distinct values and read back both pages after replacing
the adjacent old slots.

Tested-on: Fedora Linux 45 x86_64, Wine in the Victory Flatpak, DRM devices hidden
Assisted-by: gpt-6.2 sol xhigh
Texture streaming can issue a separate mapping request for every page.
Even as the GPU sits idle, each request acquires the mapping guard and
has the host replace a view. Consecutive requests can share that work
when they name successive pages of the same backing section.

Recognize consecutive pool ranges and use one host view when their
source and destination do not overlap. Keep repeated-page requests in
their original form and retry failed batches in order. Check that a
later one-page replacement preserves the neighboring aliases.

Tested-on: Fedora Linux 45 x86_64, Wine in the Victory Flatpak, DRM devices hidden
Assisted-by: gpt-6.2 sol xhigh
Depends-on: https://github.com/fxceless/victory-fork/pull/1060
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:56:55 +00:00
Author
Owner

@⁠tikD1337 on GitHub · 2026-11-25 19:22 UTC · original

Heads-up: I'm testing this PR right now on native Windows 11 + NVIDIA (RTX 4070 Ti SUPER, Ryzen 5 7600), Series X profile, merged on current main. Three scripted launches with VICTORY_BATCH_PAGE_MAPPINGS=1 and three without, same diagnostics build: failed multi-page views, remap time per frame, frame time while streaming, and frame captures compared for corruption. Results here in about 20 minutes.

For context, on the same machine a plain batch WITHOUT coalescing the destination's one-page placeholders failed 4,913 of 47,808 multi-page views with error 487 in MapViewOfFile3(MEM_REPLACE_PLACEHOLDER), leaving pages unmapped, which looks like the cause of the black and red faces in the README's reverted attempt. So the coalescing step in this PR matters.

**@⁠tikD1337** on GitHub · 2026-11-25 19:22 UTC · [original](https://github.com/fxceless/victory-fork/pull/1063#issuecomment-7172198048) Heads-up: I'm testing this PR right now on native Windows 11 + NVIDIA (RTX 4070 Ti SUPER, Ryzen 5 7600), Series X profile, merged on current `main`. Three scripted launches with `VICTORY_BATCH_PAGE_MAPPINGS=1` and three without, same diagnostics build: failed multi-page views, remap time per frame, frame time while streaming, and frame captures compared for corruption. Results here in about 20 minutes. For context, on the same machine a plain batch WITHOUT coalescing the destination's one-page placeholders failed 4,913 of 47,808 multi-page views with error 487 in `MapViewOfFile3(MEM_REPLACE_PLACEHOLDER)`, leaving pages unmapped, which looks like the cause of the black and red faces in the README's reverted attempt. So the coalescing step in this PR matters.
Author
Owner

@⁠tikD1337 on GitHub · 2026-11-25 20:09 UTC · original

Tested on native Windows 11, RTX 4070 Ti SUPER (driver 621.01), Ryzen 5 7600, Series X profile: a diagnostics build of origin/main (d510ee4) with this PR merged, plus counters of my own around the batch path (not part of the PR). Launcher switches ASYNC_SUBMIT QUEUE2 TEXTURE_NO_WAIT WIDE_REFRESH JOIN_PARTS BACK_OWN_VIEW, warm cache. Every run is the same 330 s script: menus, then the opening cutscene, then standing in the prison, with no input after the menu. 3 runs with VICTORY_BATCH_PAGE_MAPPINGS=1 and 3 without, alternating, all on the same build.

The batch path is used. Each run asks for about 20k multi-page mappings, nearly all of them one run of one section.

run asked first MapViewOfFile3 failed (487) mapped after coalescing fell back to page by page
on1 19,811 6,168 3,659 2,509
on2 20,357 6,428 3,839 2,589
on3 20,276 5,627 3,367 2,260
  • No pages are left unmapped: every refused batch falls back to page by page. Each fallback logs an unthrottled mapping physical pages failed WARN, about 2.3–2.6k lines a run.
  • Why coalescing is refused (11–13% of batches): MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS only accepts a range made of whole placeholders. It is refused when the first or the last placeholder reaches past the range, for example a leftover piece of a larger view that unmap split, or the untouched part of the reservation.
  • Suggestion: split at both ends first, VirtualFree(base, 64K, MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER) and the same for base + len - 64K, then coalesce. In my own variant of the batching, which does that, 3 runs of about 50k multi-page views each had 0 failures.

Speed: remap time falls, frame time does not. Means over all world frames (more than 1,000 draws a frame) of the 3 runs:

remap ms/frame mean frame
batch on 55.5 204.6 ms (4.89 fps)
batch off 76.6 193.8 ms (5.16 fps)

My variant showed the same pattern: 50.9 vs 83.6 ms remap, 212 vs 204 ms frame. In every run the frame log's RemapWaitUs is at most 0.2 ms/frame: the remap time is spent holding the lock, not waiting for readers. See #1069.

Picture.

  • Prison, standing: best-matching frames between runs. Without batching the runs repeat each other: picture difference 1.3 on a 0–255 scale, brightness difference within 0.2. on1 and on2 match the runs without batching (difference 1.6 and 2.1, brightness +0.2 and +0.3). on3 does not: difference 13.1, darker by 1.3, camera slightly shifted.
  • My variant (no fallback, every run batched): showed that same darker, shifted picture in 3 of 3 runs.
  • Seen by eye, not measured: in on1, very smeared hair in the prison, with normal light. In on3 the waitress's face in the café went black after she left the shot, and the café building turned very dark. on1 had pixel artifacts on her face. Face artifacts were also seen once without batching on the other build.
  • Cause not established: nothing is left unmapped, so it is not the missing pages of the original attempt.

Verdict. Correct mapping on Windows, no frame-rate gain on this machine, and an open question about the different picture in some batched runs.

**@⁠tikD1337** on GitHub · 2026-11-25 20:09 UTC · [original](https://github.com/fxceless/victory-fork/pull/1063#issuecomment-7173263304) Tested on native Windows 11, RTX 4070 Ti SUPER (driver 621.01), Ryzen 5 7600, Series X profile: a diagnostics build of `origin/main` (d510ee4) with this PR merged, plus counters of my own around the batch path (not part of the PR). Launcher switches `ASYNC_SUBMIT QUEUE2 TEXTURE_NO_WAIT WIDE_REFRESH JOIN_PARTS BACK_OWN_VIEW`, warm cache. Every run is the same 330 s script: menus, then the opening cutscene, then standing in the prison, with no input after the menu. 3 runs with `VICTORY_BATCH_PAGE_MAPPINGS=1` and 3 without, alternating, all on the same build. **The batch path is used.** Each run asks for about 20k multi-page mappings, nearly all of them one run of one section. | run | asked | first `MapViewOfFile3` failed (487) | mapped after coalescing | fell back to page by page | |---|---|---|---|---| | on1 | 19,811 | 6,168 | 3,659 | 2,509 | | on2 | 20,357 | 6,428 | 3,839 | 2,589 | | on3 | 20,276 | 5,627 | 3,367 | 2,260 | - **No pages are left unmapped:** every refused batch falls back to page by page. Each fallback logs an unthrottled `mapping physical pages failed` WARN, about 2.3–2.6k lines a run. - **Why coalescing is refused (11–13% of batches):** `MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS` only accepts a range made of whole placeholders. It is refused when the first or the last placeholder reaches past the range, for example a leftover piece of a larger view that `unmap` split, or the untouched part of the reservation. - **Suggestion:** split at both ends first, `VirtualFree(base, 64K, MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)` and the same for `base + len - 64K`, then coalesce. In my own variant of the batching, which does that, 3 runs of about 50k multi-page views each had 0 failures. **Speed: remap time falls, frame time does not.** Means over all world frames (more than 1,000 draws a frame) of the 3 runs: | | remap ms/frame | mean frame | |---|---|---| | batch on | 55.5 | 204.6 ms (4.89 fps) | | batch off | 76.6 | 193.8 ms (5.16 fps) | My variant showed the same pattern: 50.9 vs 83.6 ms remap, 212 vs 204 ms frame. In every run the frame log's `RemapWaitUs` is at most 0.2 ms/frame: the remap time is spent holding the lock, not waiting for readers. See #1069. **Picture.** - **Prison, standing:** best-matching frames between runs. Without batching the runs repeat each other: picture difference 1.3 on a 0–255 scale, brightness difference within 0.2. on1 and on2 match the runs without batching (difference 1.6 and 2.1, brightness +0.2 and +0.3). on3 does not: difference 13.1, darker by 1.3, camera slightly shifted. - **My variant (no fallback, every run batched):** showed that same darker, shifted picture in 3 of 3 runs. - **Seen by eye, not measured:** in on1, very smeared hair in the prison, with normal light. In on3 the waitress's face in the café went black after she left the shot, and the café building turned very dark. on1 had pixel artifacts on her face. Face artifacts were also seen once without batching on the other build. - **Cause not established:** nothing is left unmapped, so it is not the missing pages of the original attempt. **Verdict.** Correct mapping on Windows, no frame-rate gain on this machine, and an open question about the different picture in some batched runs.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/queue.rs
  • crates/victory-hle/src/modules/xmem.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1063/head:github-bot/gh-1063'
git switch 'github-bot/gh-1063'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1063'
git switch 'github-bot/gh-1063'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1063'
git switch 'github-bot/gh-1063'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1063'
git switch 'main'
git merge --squash 'github-bot/gh-1063'
git switch 'main'
git merge --ff-only 'github-bot/gh-1063'
git switch 'main'
git merge 'github-bot/gh-1063'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.