HLE: mapping the pages a range already shows changes nothing #3845
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3845"
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 Ingenioeren on 2026-11-29T15:15:24Z.
What
XMemMapPhysicalPagesreturns at once when every address in the range already shows the requested page.XMemMapPhysicalPagesScattercalls it per page, so it gets the same short cut.Why
Before, re-mapping the page an address already shows still unmapped the range and mapped it again:
UnmapViewOfFile2, aVirtualFreesplit, aMapViewOfFile3and a commit per call;victory_gpu::title_memory_remappedis called, so the GPU side treats the range as showing new memory and its copies stop guarding it, even though nothing changed.Unknown pages, null
pages(unmap) andn == 0take the old path unchanged.The idea of skipping identical page mappings comes from crossducking/RAZDA4A-XEN (wave 15 notes, GPL-3.0). It publishes no source, so this code is written from scratch.
How tested
xmem::tests::mapping_the_pages_already_shown_keeps_the_view: maps 3 pages as one view, maps each page again at its own address (scatter) and as a 2-page run, and checks the view is still one 3-page view,shownhas one address for the page, and the bytes survive. It then maps another page there and checks that still replaces it. With the early return disabled it fails (the one view stays whole:Some(65536)vsSome(196608)). With the fix it passes.cargo test --locked --offline -p victory-hle --lib: 153 passed.cargo clippy --locked --offline -p victory-hle --all-targets: no warnings.rustfmt --config-path rustfmt.toml --checkon the file: clean.cargo run -p xtask -- policy --staged: ok.XMemMapPhysicalPagesScatterof the same 256 pages 20 times, 3 runs each. Before: 6.46-6.59 µs per page. After: 17 ns per page. This harness has no GPU behindtitle_memory_remapped, so the GPU-side cost that is also skipped is not included.Not tested: no game run. I don't know how often the title re-maps a page that is already shown, so I'm not claiming any in-game gain.
AI assistance: prepared with Claude Code, reviewed by Ingenioeren.
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-29T16:29:36Z.
Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):
8427125961f501c9f1ee251e1ae18071b4ecc0d2, base/parent63bcca43c6a00a758510398fa43096ce7e4f7df0.cargo test --locked -p victory-hle --lib -- modules::xmem::tests::mapping_the_pages_already_shown_keeps_the_view --exact --test-threads=1 --quiet→ 1 passed, 0 failed, 152 filtered, exit 0.git grep -Ffor the test name on the base returned no match (test is new on this PR);git diff --check 63bcca4 HEADclean (1 file, +74/-4).CARGO_TARGET_DIR(never shared) withCARGO_BUILD_JOBS=2.AI-assisted (Hy4 flash).
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-30T10:52:56Z.
Verified independently on Windows / Rust 1.100.0 / MSVC, source + synthetic inputs only.
D:\Victory-Contrib\pr-3845-watch, dedicatedCARGO_TARGET_DIR=D:\Victory-Contrib\target-3845(never shared).git grep -F mapping_the_pages_already_shown_keeps_the_view 63bcca43c6a00a758510398fa43096ce7e4f7df0 -- crates/victory-hle/src/modules/xmem.rs→ no match (test is new on the base).git diff --check "$base..HEAD"→ exit 0.cargo test --locked -p victory-hle --lib -- modules::xmem::tests::mapping_the_pages_already_shown_keeps_the_view --exact --test-threads=1 --quiet→1 passed; 0 failed; 152 filtered out, exit 0 (rustc 1.100.0).GPU/driver: N/A (CPU-only synthetic unit test). No game data, assets, extracted shaders, DRM or decrypt used or uploaded. AI-assisted (Hy4 flash).
Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-12-01T12:30:23Z.
On
84271259I observed calls totitle_memory_remappedfrom the Windows HLE mapping paths. Reapplying the same three pages, both as one range and as a scatter, produced zero notifications.A scatter that replaced only the middle page of an existing three-page view produced four notifications, in this order,
(0,3),(0,1),(2,1),(1,1), expressed as (page offset, page count). The three mapped bytes read back as[49,52,51]. After writing 116 through the new middle mapping, the four-page alias read[49,50,51,116]. The alias data checks passed. The assertion expecting notifications only for the middle page failed. This measures the notification ranges on this head. Attribution to a change in this PR would require a parent-side comparison.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.