hle(xmem): pool-back MEM_COMMIT calls inside reserved XMemVirtualAlloc ranges #511

Manually merged
github merged 1 commit from github-bot/gh-507 into main 2026-11-28 01:36:53 +00:00 AGit
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 22:37 UTC · original
Sheffy007:fix/xmem-deferred-commit-pool-backing → main · +168 −6 · 4 files · 1 commits · merged 2026-11-28 01:33 UTC

What this changes

Closes #510
Refs #15, #258

On macOS, one-step XMemVirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, ...) backs the allocation with a Pool via xmem_physical::back_with_pool so the native GPU backend can resolve title addresses through PoolTable (a017f770).

When a title instead reserves virtual address space first (MEM_RESERVE or a PAGES_64K placeholder) and commits granules or sub-ranges later via XMemVirtualAlloc(at, size, MEM_COMMIT, ...) or VirtualAlloc(at, size, MEM_COMMIT, ...), xmem_posix.rs and host_posix.rs previously called plain mem::commit on anonymous VM pages, leaving those committed ranges outside PoolTable (title address ... is not in a mapped pool / a buffer view over title memory with a gap stays the null view).

Changes:

  • crates/victory-hle/src/modules/xmem_physical.rs: Add unbacked_ranges to find 64 KiB granules within a reservation span that do not yet have a physical-page view.
  • crates/victory-hle/src/modules/xmem_posix.rs & crates/victory-hle/src/host_posix.rs: Add commit_if_reserved, serialised with forget_physical, to pool-back uncovered 64 KiB granules on MEM_COMMIT inside XMemVirtualAlloc reservations while keeping uncommitted sub-granule prefixes/tails Protect::NO_ACCESS and rejecting commits past the reservation's end.
  • Add tests covering placeholder partial commits, sub-granule incremental commits sharing one pool, out-of-bounds commit rejection, and VirtualAlloc(..., MEM_COMMIT, ...) inside XMemVirtualAlloc reservations.

How it was tested

  • cargo test --target x86_64-apple-darwin -p victory-hle --lib
  • cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy (399 files ok)

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented

cc @⁠Olima34

**@⁠Sheffy007** on GitHub · 2026-11-27 22:37 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507) `Sheffy007:fix/xmem-deferred-commit-pool-backing` → `main` · +168 −6 · 4 files · 1 commits · merged 2026-11-28 01:33 UTC ## What this changes Closes #510 Refs #15, #258 On macOS, one-step `XMemVirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, ...)` backs the allocation with a `Pool` via `xmem_physical::back_with_pool` so the native GPU backend can resolve title addresses through `PoolTable` (`a017f770`). When a title instead reserves virtual address space first (`MEM_RESERVE` or a `PAGES_64K` placeholder) and commits granules or sub-ranges later via `XMemVirtualAlloc(at, size, MEM_COMMIT, ...)` or `VirtualAlloc(at, size, MEM_COMMIT, ...)`, `xmem_posix.rs` and `host_posix.rs` previously called plain `mem::commit` on anonymous VM pages, leaving those committed ranges outside `PoolTable` (`title address ... is not in a mapped pool` / `a buffer view over title memory with a gap stays the null view`). Changes: - **`crates/victory-hle/src/modules/xmem_physical.rs`**: Add `unbacked_ranges` to find 64 KiB granules within a reservation span that do not yet have a physical-page view. - **`crates/victory-hle/src/modules/xmem_posix.rs` & `crates/victory-hle/src/host_posix.rs`**: Add `commit_if_reserved`, serialised with `forget_physical`, to pool-back uncovered 64 KiB granules on `MEM_COMMIT` inside `XMemVirtualAlloc` reservations while keeping uncommitted sub-granule prefixes/tails `Protect::NO_ACCESS` and rejecting commits past the reservation's end. - Add tests covering placeholder partial commits, sub-granule incremental commits sharing one pool, out-of-bounds commit rejection, and `VirtualAlloc(..., MEM_COMMIT, ...)` inside `XMemVirtualAlloc` reservations. ## How it was tested - [x] `cargo test --target x86_64-apple-darwin -p victory-hle --lib` - [x] `cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask` - [x] `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings` - [x] `cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings` - [x] `cargo xtask policy` (399 files ok) ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in `docs/native-host.md` - [x] New diagnostics are behind a `VICTORY_*` variable and documented cc @⁠Olima34
On macOS, XMemVirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, ...) backs
the allocation with a GPU-reachable Pool via xmem_physical::back_with_pool,
whereas reserving first (MEM_RESERVE or PAGES_64K placeholder) and later
committing ranges via XMemVirtualAlloc(at, size, MEM_COMMIT, ...) or
VirtualAlloc(at, size, MEM_COMMIT, ...) previously called plain mem::commit
on anonymous VM pages, leaving those title addresses invisible to PoolTable.

Detect commits inside XMemVirtualAlloc reservations, back any uncovered
64 KiB granules in the committed span with pools while keeping uncommitted
host-page prefixes/tails NO_ACCESS, and release them cleanly with the
enclosing reservation.

Closes #506
Refs #15, #258
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 22:40:42 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 22:38 UTC · original

Thanks @⁠Sheffy007, this closes a gap we left open in #267. Our wrap of non-linear heap views only covers ranges the pool table maps with no gap. Anything else stays the null view, with the "a buffer view over title memory with a gap stays the null view" line you quote. Committed ranges outside PoolTable were exactly the case we couldn't serve. It should also cut the ~490 commands per frame that name memory "outside every mapped pool", which we counted on #258 earlier.

It may matter for one more thing we're chasing. On the preview branch, indirect dispatch and draw records sometimes hold foreign data (e.g. a whole 512-record buffer overwritten with vertex-like triples during a skinning pass). In one run we also saw more than 2,048 heap views whose title pages moved in their pool while the host entry still pointed at the old ones. Memory the title commits later, inside a reservation and outside any pool, is another way for host and title to disagree on where a buffer lives.

We'll add #511 to our next runs on the preview branch, together with #463, #487 and #503, and post whether the "not in a mapped pool" lines, the gap-null views and the garbage records go down.

**@⁠Olima34** on GitHub · 2026-11-27 22:38 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507#issuecomment-7229500123) Thanks @⁠Sheffy007, this closes a gap we left open in #267. Our wrap of non-linear heap views only covers ranges the pool table maps with no gap. Anything else stays the null view, with the "a buffer view over title memory with a gap stays the null view" line you quote. Committed ranges outside `PoolTable` were exactly the case we couldn't serve. It should also cut the ~490 commands per frame that name memory "outside every mapped pool", which we counted on #258 earlier. It may matter for one more thing we're chasing. On the preview branch, indirect dispatch and draw records sometimes hold foreign data (e.g. a whole 512-record buffer overwritten with vertex-like triples during a skinning pass). In one run we also saw more than 2,048 heap views whose title pages moved in their pool while the host entry still pointed at the old ones. Memory the title commits later, inside a reservation and outside any pool, is another way for host and title to disagree on where a buffer lives. We'll add #511 to our next runs on the preview branch, together with #463, #487 and #503, and post whether the "not in a mapped pool" lines, the gap-null views and the garbage records go down.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 22:40 UTC · original

@⁠Sheffy007 a side question: are you on the project's Discord (Native macOS-Victory)? We're pairing a lot on the same areas tonight (fences, waits, title memory), and it would be easier to compare runs and avoid overlap there. If you're not on it yet and you'd like to join, say so here and we'll send you an invite.

**@⁠Olima34** on GitHub · 2026-11-27 22:40 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507#issuecomment-7229528784) @⁠Sheffy007 a side question: are you on the project's Discord (Native macOS-Victory)? We're pairing a lot on the same areas tonight (fences, waits, title memory), and it would be easier to compare runs and avoid overlap there. If you're not on it yet and you'd like to join, say so here and we'll send you an invite.
Author
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 00:02 UTC · original

@⁠Sheffy007 a side question: are you on the project's Discord (Native macOS-Victory)? We're pairing a lot on the same areas tonight (fences, waits, title memory), and it would be easier to compare runs and avoid overlap there. If you're not on it yet and you'd like to join, say so here and we'll send you an invite.

@⁠Olima34, I'm not currently but yeah please send an invite! Gemini is doing the work for me but I'm happy to direct it wherever it needs to go.

**@⁠Sheffy007** on GitHub · 2026-11-28 00:02 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507#issuecomment-7230593959) > @⁠Sheffy007 a side question: are you on the project's Discord (Native macOS-Victory)? We're pairing a lot on the same areas tonight (fences, waits, title memory), and it would be easier to compare runs and avoid overlap there. If you're not on it yet and you'd like to join, say so here and we'll send you an invite. @⁠Olima34, I'm not currently but yeah please send an invite! Gemini is doing the work for me but I'm happy to direct it wherever it needs to go.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 00:06 UTC · original

@⁠Sheffy007 great, here it is: https://discord.gg/xut5NhywZ. Welcome! Say hi in the channel when you're in. Pointing your agent at the open blockers is exactly what helps most: tell us what it's on, and we'll share the runs and traces we have for that area.

**@⁠Olima34** on GitHub · 2026-11-28 00:06 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507#issuecomment-7230650898) @⁠Sheffy007 great, here it is: https://discord.gg/xut5NhywZ. Welcome! Say hi in the channel when you're in. Pointing your agent at the open blockers is exactly what helps most: tell us what it's on, and we'll share the runs and traces we have for that area.
github manually merged commit a8fc755116 into main 2026-11-28 01:36:53 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 01:33 UTC · original · approved these changes

Check report (helping the maintainer clear the queue):

  • CI: check and macos-scripts green on fdd8c709.
  • Read: the whole diff. A MEM_COMMIT inside an XMemVirtualAlloc reservation (through XMemVirtualAlloc or VirtualAlloc) now backs the touched 64 KiB granules that have no physical-page view yet with a pool (unbacked_ranges + back_with_pool). It keeps the uncommitted head and tail of a granule no-access and refuses a commit past the reservation's end. COMMIT_LOCK serialises it with forget_physical. Tests cover a placeholder's partial commit, sub-granule commits sharing one pool without wiping each other, the out-of-range commit, and VirtualAlloc inside an XMem reservation, each checking the pool's own mapping sees the write.
  • Local check on current main (226645f9) merged with #458, #503 and this PR: victory-hle tests pass on x86_64-apple-darwin, Windows clippy (-D warnings) clean, cargo xtask policy ok.
  • Game runs, from one of our test sessions (one windowed 300 s run, Series S, preview b3c1a1b0 + #463 + #517 + #503 + #487 + this PR, VICTORY_TRACE_GPU_FAILS=1 VICTORY_PASSES_PER_BUFFER=1): 0 GPU errors, clean end, 2432 frames, the same as without it. Indirect records past the gates' limits were 15, 12 and 17 across control and the two trees, so this doesn't change those.
  • Suggestion, not blocking: a sentence in docs/native-host.md (near the XMem pool backing) on deferred commits being pool-backed would help the next reader.

Thanks @⁠Sheffy007!

**@⁠Olima34** on GitHub · 2026-11-28 01:33 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507#pullrequestreview-6094914724) · **approved these changes** Check report (helping the maintainer clear the queue): - **CI:** `check` and `macos-scripts` green on fdd8c709. - **Read:** the whole diff. A `MEM_COMMIT` inside an `XMemVirtualAlloc` reservation (through `XMemVirtualAlloc` or `VirtualAlloc`) now backs the touched 64 KiB granules that have no physical-page view yet with a pool (`unbacked_ranges` + `back_with_pool`). It keeps the uncommitted head and tail of a granule no-access and refuses a commit past the reservation's end. `COMMIT_LOCK` serialises it with `forget_physical`. Tests cover a placeholder's partial commit, sub-granule commits sharing one pool without wiping each other, the out-of-range commit, and `VirtualAlloc` inside an XMem reservation, each checking the pool's own mapping sees the write. - **Local check on current main (226645f9) merged with #458, #503 and this PR:** `victory-hle` tests pass on x86_64-apple-darwin, Windows clippy (`-D warnings`) clean, `cargo xtask policy` ok. - **Game runs, from one of our test sessions** (one windowed 300 s run, Series S, preview b3c1a1b0 + #463 + #517 + #503 + #487 + this PR, `VICTORY_TRACE_GPU_FAILS=1 VICTORY_PASSES_PER_BUFFER=1`): 0 GPU errors, clean end, 2432 frames, the same as without it. Indirect records past the gates' limits were 15, 12 and 17 across control and the two trees, so this doesn't change those. - **Suggestion, not blocking:** a sentence in docs/native-host.md (near the XMem pool backing) on deferred commits being pool-backed would help the next reader. Thanks @⁠Sheffy007!
This discussion has been locked. Commenting is limited to contributors.
No description provided.