xmem: write DirectStorage page destinations one view per run #61

Manually merged
github merged 1 commit from gh-pr/61/head into gh-pr/61/base 2026-11-26 03:48:51 +00:00
Owner

@⁠TG0000 on GitHub · 2026-11-24 00:00 UTC · original
TG0000:hle/physical-page-runs → main · +273 −41 · 2 files · 1 commits · merged 2026-11-24 00:41 UTC

The README lists loading as "limited by writes into title memory". One part of that is DirectStorage requests that write physical pages (PAGE_DESTINATION):

  • xmem::write_physical mapped, committed and unmapped a separate view for every 64 KiB page. Each unmap flushes every core's TLB, so with all the DirectStorage workers writing at once, this cost was paid serially, once per page.
  • dstorage::into_destination first decoded each such request into a zeroed Vec, then copied it into the pages.

Change

  • xmem::runs looks the pages up under one lock and groups them into runs of consecutive slices of one section. That is the usual case, since XMemAllocatePhysicalPages hands out one section per call. XMemMapPhysicalPages already groups pages the same way.
  • write_physical writes each run through a single view (an RAII View that maps, commits, and unmaps on drop).
  • New xmem::page_window: when a request's pages form one run, DirectStorage inflates or unpacks straight into that view, with no buffer and no copy. Pages from several allocations, or out of order, still go through the buffer and are written run by run. Errors are reported the same way as before (E_INVALIDARG for an unknown page).

Behaviour is unchanged apart from cost. As before, only the bytes the decoder produced are written, and the GPU side's guards are unaffected: these writes go through our own view, as they did before (the shortcut note in victory-gpu/src/watch.rs).

This fits with #53 (Wine: sections committed whole, so commit returns early): View::map goes through the same commit.

Numbers

Synthetic benchmark: a throwaway --release test, not included. It writes 16 MiB destinations, 256 consecutive pages, 20 times each.

before after
write_physical, 1 thread 1.92 GiB/s 2.19 GiB/s
write_physical, 8 threads 3.47 GiB/s 7.79 GiB/s
decode path: zeroed buffer + copy vs in place 0.96 GiB/s 2.13 GiB/s

I haven't measured the effect on in-game load time. I didn't run the title for this change.

Tests

New unit tests, all synthetic (our own data):

  • xmem::runs_group_consecutive_pages_of_one_allocation: run grouping, offsets that reach only some pages, out-of-order pages, pages from two allocations, too few pages, unknown pages, an overflowing offset
  • xmem::writes_cross_runs_and_allocations: a write crossing a run boundary between two sections, with the bytes around it left untouched
  • xmem::page_windows_cover_one_run_in_place
  • dstorage::zlib_into_pages_in_place_and_across_allocations: zlib into physical pages on both paths, checked through the title's view of them

Run:

  • cargo +stable-x86_64-pc-windows-msvc test --workspace: 228 passed, 0 failed, 3 ignored (224 before this change)
  • cargo clippy -p victory-hle --all-targets: no new warnings. The only warnings are the existing fetch_update deprecations on a newer stable toolchain.
  • cargo xtask policy: 148 files OK
  • Changed hunks formatted with rustfmt (main itself is not rustfmt-clean yet, see #17)

Machine: Windows 11 Pro, AMD Ryzen 9 5900X, AMD Radeon RX 6800. These tests are CPU-only, so no GPU tests were needed.

This PR was AI-assisted (Claude Code). I reviewed the change and the tests.

🤖 Generated with Claude Code

**@⁠TG0000** on GitHub · 2026-11-24 00:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/61) `TG0000:hle/physical-page-runs` → `main` · +273 −41 · 2 files · 1 commits · merged 2026-11-24 00:41 UTC The README lists loading as "limited by writes into title memory". One part of that is DirectStorage requests that write physical pages (`PAGE_DESTINATION`): - `xmem::write_physical` mapped, committed and unmapped a separate view for **every 64 KiB page**. Each unmap flushes every core's TLB, so with all the DirectStorage workers writing at once, this cost was paid serially, once per page. - `dstorage::into_destination` first decoded each such request into a zeroed `Vec`, then copied it into the pages. ## Change - `xmem::runs` looks the pages up under one lock and groups them into runs of consecutive slices of one section. That is the usual case, since `XMemAllocatePhysicalPages` hands out one section per call. `XMemMapPhysicalPages` already groups pages the same way. - `write_physical` writes each run through a single view (an RAII `View` that maps, commits, and unmaps on drop). - New `xmem::page_window`: when a request's pages form one run, DirectStorage inflates or unpacks straight into that view, with no buffer and no copy. Pages from several allocations, or out of order, still go through the buffer and are written run by run. Errors are reported the same way as before (`E_INVALIDARG` for an unknown page). Behaviour is unchanged apart from cost. As before, only the bytes the decoder produced are written, and the GPU side's guards are unaffected: these writes go through our own view, as they did before (the `shortcut` note in `victory-gpu/src/watch.rs`). This fits with #53 (Wine: sections committed whole, so `commit` returns early): `View::map` goes through the same `commit`. ## Numbers Synthetic benchmark: a throwaway `--release` test, not included. It writes 16 MiB destinations, 256 consecutive pages, 20 times each. | | before | after | |---|---|---| | `write_physical`, 1 thread | 1.92 GiB/s | 2.19 GiB/s | | `write_physical`, 8 threads | 3.47 GiB/s | 7.79 GiB/s | | decode path: zeroed buffer + copy vs in place | 0.96 GiB/s | 2.13 GiB/s | I haven't measured the effect on in-game load time. I didn't run the title for this change. ## Tests New unit tests, all synthetic (our own data): - `xmem::runs_group_consecutive_pages_of_one_allocation`: run grouping, offsets that reach only some pages, out-of-order pages, pages from two allocations, too few pages, unknown pages, an overflowing offset - `xmem::writes_cross_runs_and_allocations`: a write crossing a run boundary between two sections, with the bytes around it left untouched - `xmem::page_windows_cover_one_run_in_place` - `dstorage::zlib_into_pages_in_place_and_across_allocations`: zlib into physical pages on both paths, checked through the title's view of them Run: - `cargo +stable-x86_64-pc-windows-msvc test --workspace`: 228 passed, 0 failed, 3 ignored (224 before this change) - `cargo clippy -p victory-hle --all-targets`: no new warnings. The only warnings are the existing `fetch_update` deprecations on a newer stable toolchain. - `cargo xtask policy`: 148 files OK - Changed hunks formatted with rustfmt (`main` itself is not rustfmt-clean yet, see #17) Machine: Windows 11 Pro, AMD Ryzen 9 5900X, AMD Radeon RX 6800. These tests are CPU-only, so no GPU tests were needed. This PR was AI-assisted (Claude Code). I reviewed the change and the tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
write_physical mapped, committed and unmapped a view for every 64 KiB
page it wrote, and DirectStorage decoded each page-destination request
into a zeroed buffer first, then copied it. Every unmap flushes every
core's TLB, so with all the workers loading at once these writes were a
serial cost per page.

Pages are now looked up once and grouped into runs of consecutive slices
of one section (how titles allocate them), and each run is written
through one view. When a request's pages form a single run, DirectStorage
inflates or unpacks straight into that view instead of a buffer; pages of
several allocations still go through the buffer, written run by run.

Synthetic release benchmark (16 MiB destinations, Ryzen 9 5900X):
8 threads 3.5 -> 7.8 GiB/s; one thread, buffered then copied 0.96 GiB/s
vs in place 2.1 GiB/s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:48:51 +00:00
github manually merged commit 4e94c2b05a into gh-pr/61/base 2026-11-26 03:48:51 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:09 UTC · original

Tested 4e94c2b stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass (no regression only).

  • cargo test --workspace: 155 passed, 0 failed, 3 ignored; merge with #39 clean.
  • Scope note: the diff is xmem.rs + dstorage.rs (+273/−41) and adds no test, so this run shows the portable HLE suite still passes rather than covering the one-view-per-run destination writes. A synthetic DirectStorage destination layout with several runs in one page would pin it.
  • No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/61#issuecomment-7117770336) Tested `4e94c2b` stacked on **#39** on **Arch Linux x86_64, rustc 1.98.1**: **pass (no regression only)**. - `cargo test --workspace`: **155 passed, 0 failed, 3 ignored**; merge with #39 clean. - Scope note: the diff is `xmem.rs` + `dstorage.rs` (+273/−41) and adds no test, so this run shows the portable HLE suite still passes rather than covering the one-view-per-run destination writes. A synthetic DirectStorage destination layout with several runs in one page would pin it. - No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!61
No description provided.