xmem: write DirectStorage page destinations one view per run #61
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/61"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_physicalmapped, 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_destinationfirst decoded each such request into a zeroedVec, then copied it into the pages.Change
xmem::runslooks the pages up under one lock and groups them into runs of consecutive slices of one section. That is the usual case, sinceXMemAllocatePhysicalPageshands out one section per call.XMemMapPhysicalPagesalready groups pages the same way.write_physicalwrites each run through a single view (an RAIIViewthat maps, commits, and unmaps on drop).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_INVALIDARGfor 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
shortcutnote invictory-gpu/src/watch.rs).This fits with #53 (Wine: sections committed whole, so
commitreturns early):View::mapgoes through the samecommit.Numbers
Synthetic benchmark: a throwaway
--releasetest, not included. It writes 16 MiB destinations, 256 consecutive pages, 20 times each.write_physical, 1 threadwrite_physical, 8 threadsI 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 offsetxmem::writes_cross_runs_and_allocations: a write crossing a run boundary between two sections, with the bytes around it left untouchedxmem::page_windows_cover_one_run_in_placedstorage::zlib_into_pages_in_place_and_across_allocations: zlib into physical pages on both paths, checked through the title's view of themRun:
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 existingfetch_updatedeprecations on a newer stable toolchain.cargo xtask policy: 148 files OKmainitself 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
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:09:44Z.
Tested
4e94c2bstacked 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.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.AI-assisted (DeepSeek V4.1 Flash coding agent).