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

Merged
Sheffy007 merged 1 commit from upstream-pr/507 into main 2026-11-28 01:33:22 +00:00
Sheffy007 commented 2026-11-27 22:37:35 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T22:37:35Z.


What this changes

Closes #506
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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5533991563 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T22:37:35Z. --- ## What this changes Closes #506 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
Olima34 commented 2026-11-27 22:38:45 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T22:38:45Z.


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 #507 to our next runs on the preview branch, together with #459, #483 and #499, and post whether the "not in a mapped pool" lines, the gap-null views and the garbage records go down.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7229500123 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507#issuecomment-7229500123). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T22:38:45Z. --- 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 #507 to our next runs on the preview branch, together with #459, #483 and #499, and post whether the "not in a mapped pool" lines, the gap-null views and the garbage records go down.
Olima34 commented 2026-11-27 22:40:51 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T22:40:51Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7229528784 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507#issuecomment-7229528784). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T22:40:51Z. --- @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.
Sheffy007 commented 2026-11-28 00:02:07 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-28T00:02:07Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7230593959 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507#issuecomment-7230593959). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-28T00:02:07Z. --- > @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.
Olima34 commented 2026-11-28 00:06:20 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T00:06:20Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7230650898 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507#issuecomment-7230650898). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T00:06:20Z. --- @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 commented 2026-11-28 01:33:18 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T01:33:18Z.

Review: APPROVED


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 #454, #499 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 + #459 + #513 + #499 + #483 + 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!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6094914724 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/507#pullrequestreview-6094914724). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T01:33:18Z. **Review:** APPROVED --- 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 #454, #499 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 + #459 + #513 + #499 + #483 + 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!
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
LakshanSivakumar/Native-Victory-macOS!507
No description provided.