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

Merged
TG0000 merged 1 commit from upstream-pr/61 into main 2026-11-24 00:41:55 +00:00
TG0000 commented 2026-11-24 00:00:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TG0000 on 2026-11-24T00:00:23Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6571424722 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/61). Originally posted by [TG0000](https://github.com/TG0000) on 2026-11-24T00:00:23Z. --- 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)
upstream-sync closed this pull request 2026-11-24 06:51:08 +00:00
DaviTostes commented 2026-11-24 06:54:35 +00:00 (Migrated from github.com)

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


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7117770336 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/61#issuecomment-7117770336). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:09:44Z. --- 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).
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!61
No description provided.