xmem: map a run of physical pages over several placeholders #76
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!76
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-76"
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?
@SuryaK5125 on GitHub · 2026-11-24 00:15 UTC · original
SuryaK5125:fix/xmem-placeholder-remap→main· +314 −21 · 1 files · 1 commits · openXMemMapPhysicalPagesfails withERROR_INVALID_ADDRESSwhen mapping a run of physical pages across multiple placeholders. This can happen after a partial unmap or scatter mapping, since unmapping doesn't join the placeholders back together.Instead of mapping the entire run as one view, this change maps each placeholder separately and rolls back if a mapping fails. Existing placeholder boundaries are preserved, since coalescing can also join unrelated reservations.
The split operation now checks that the affected memory is reserved before proceeding to avoid freeing committed pages.
Rebased onto current main (
940d32f) asce93a81. The upstream alias tracking inmap()is kept: the GPU side is told once that the whole run was remapped, then each page of each view is linked with its other views, as for a single view.Testing (
ce93a81):XMemMapPhysicalPagesreturns NULL).cargo test -p victory-hleon Windows 11: 149 passed, 0 failed.xmem.rs. rustfmt is clean for the changed lines.Earlier testing (
dea90cc, the previous revision on9aef3d9):ce93a81has not been tested under Wine.Also checked compatibility with #53 and #61. All three changes together passed the HLE tests at
dea90cc.@DaviTostes on GitHub · 2026-11-24 00:24 UTC · original
Tested
b44fd4bstacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.cargo test --workspace: 156 passed, 0 failed, 3 ignored; merge with #39 clean.#[test]s for the placeholder mapping, included in that run.VirtualAlloc2/placeholder path, so the tests that exercise it are the portable ones only.AI-assisted (DeepSeek V4.1 Flash coding agent).
@SkippySteve on GitHub · 2026-11-24 01:29 UTC · original
I ran the
victory-hletests for this PR under Wine on Linux. No game files were used and the title was not run.Environment
wine-11.0), using Proton'sfiles/bin/winedirectly with a fresh, dedicatedWINEPREFIXandWINEDEBUG=-allcargo xwin test -p victory-hle --target x86_64-pc-windows-msvc --no-run(Rust 1.98.1 fromrust-toolchain.toml)lib/vkd3d/x86_64-windows/libvkd3d-*.dllcopied next to the test exe, because the test binary imports d3d12/dxgi and plainwine(unlikeproton run/umu) doesn't put them in the prefixCommands
Results (
victory_hleunit tests)dea90cc(on9aef3d9)xmemtests passmain(d2a4bae)xmemtests passmaind2a4bae, unchangedmain+ only this PR's 4 new tests (code unchanged)main,a_run_maps_again_after_a_partial_unmap,a_run_maps_across_two_placeholdersanda_run_keeps_the_placeholders_it_spansall fail the same way under Wine:XMemMapPhysicalPagesreturns null (left: 0x0, right: 0x1012b0000, etc.). This PR's code makes all three pass. So the multi-placeholder bug happens on Wine too, not just on Windows, and the fix works there.a_failed_run_leaves_no_viewpasses on both, which is expected because main also returns null in that case.modules::net::tests::only_loopback_is_reachable(ws2_32.dll lacks WSAConnectByList). Wine's ws2_32 doesn't exportWSAConnectByList, and the test fails the same way onmain, so it has nothing to do with this PR.xmemfilter on the PR build 5× serially and 1× with parallel test threads: 13/13 passed every time.no_dll_plantingpasses (1/1).This only covers synthetic tests. I didn't check a title load under Proton.
@Marvisak on GitHub · 2026-11-25 00:15 UTC · original · edited 2026-11-25 11:25 UTC
Automated triage for the maintainers.
Merge candidate. Recommending a look, not approving. The head is the same as at the earlier note, and it still merges cleanly onto
main.mapincrates/victory-hle/src/modules/xmem.rsmaps one view for each placeholder the run covers. If any view fails, it unmaps the views already made.split_atsplits only reserved memory. The GPU alias bookkeeping runs once every view has succeeded. Placeholders are never joined, so separate reservations stay separate.coalesce_placeholders). It is open with its own needs-work note. Your comparison in the thread (6/6 regressions here, 3/6 on #1224) points to behaviour this PR keeps and #1224 does not: a run that starts inside a placeholder, placeholders the title split itself, and adjacent reservations kept separate. The cost you measured is slower map/unmap when a run spans many placeholders (about 100 µs against 31–54 µs at 16 placeholders, debug build). Only one of the two can land, so the maintainer should pick.CI:
checkpassing.On your reply: thanks for the side-by-side comparison. It makes the choice clearer and leaves this verdict unchanged.
Generated by Claude Code
@SuryaK5125 on GitHub · 2026-11-25 09:18 UTC · original
Rebased onto
940d32f(ce93a81). All 149 HLE tests and CI pass.Since #1224 addresses the same issue, I tested both approaches against the same upstream base using six regression tests:
The three failures on #1224 involve a run starting inside a placeholder, preservation of title-created placeholder boundaries, and preservation of adjacent independent reservations. The first appears fixable independently of the coalescing approach.
There is a performance trade-off: in a synthetic Windows debug-build benchmark with 16 pages across 16 placeholders, #76 took approximately 100/77 µs for map/unmap, versus 31–54/24–29 µs for #1224. At four placeholders or fewer, the difference was close to measurement noise. Wine performance was not measured.
Coalescing only internally created splits might eventually combine the advantages of both approaches, but would require additional reservation tracking.
All testing was synthetic, without game files.
@fuzeofficlal on GitHub · 2026-11-26 01:20 UTC · original
Code review and Windows 11 verification at head
ce93a8137a6bmerged cleanly ontomain(63bcca43c6a0):crates/victory-hle/src/modules/xmem.rs:810-850, 908-924):mapsplits[base, end)at both boundaries viasplit_at(which verifies a contiguousMEM_RESERVE | MEM_PRIVATEregion fromAllocationBasewith noMEM_COMMITpages before splitting) and maps segment-by-segment across existing placeholders without coalescing separate reservations.map_viewor alignment failure, every already-mapped segment inmadeis rolled back withUnmapViewOfFile2(..., MEM_PRESERVE_PLACEHOLDER)beforetitle_memory_remapped/aliased,physical.views, orphysical.shownare updated.#2742(#76guards multi-placeholder mapping inside a singlemap()run;#2742guards multi-run rollback inXMemMapPhysicalPages).cargo xtask policy:191 files ok;cargo clippy -p victory-hle --all-targets -- -D warnings: 0 warningsvictory-hle: 158/158 unit (including all 6 new multi-placeholder tests) +fidelityfx+no_dll_plantingpassed.LGTM.
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.