HLE: a persistent view above the title's memory, three-state commits, and a write generation per page #871

Open
HailLucifer666 wants to merge 5 commits from upstream-pr/872 into main
HailLucifer666 commented 2026-11-25 11:24:39 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-25T11:24:39Z.


⚠️ Stacked on #231 (perf/xmem-persistent-section-views, still open). The diff here shows both because the base branch lives on this fork, not upstream: once #231 lands, this shrinks to the one commit it actually adds. Do not merge before #231.

Three changes to the physical-page path, none of which changes it by default (VICTORY_XMEM_PERSISTENT_VIEW still off):

The view's address. It used to be wherever MapViewOfFile put it, which can be inside the range the title itself owns — below 40 bits, the range decision 0001 says title structures must live in. A view there either takes an address the title is about to ask for, or makes our own mapping look like a title address to the title's own pointer arithmetic. It is now reserved with VirtualAlloc2's address requirement from 1 TiB to GetSystemInfo().lpMaximumApplicationAddress (asked, never assumed) and mapped into that reservation with MapViewOfFile3. A view that comes back below the ceiling anyway is released and the caller keeps its temporary view — the host is not trusted to honour the requirement.

Commit state, three states per page instead of one bit. The bit recorded "committed" but could not promise anything at the moment it mattered: the DirectStorage workers write these sections concurrently, and a thread that lost the race to VirtualAlloc(MEM_COMMIT) would store into a page whose commit was still in flight. Pages are now FREE → COMMITTING (claimed by one thread) → COMMITTED (set only after VirtualAlloc returned); a loser spins on COMMITTING instead of writing. A bounded spin then gives up to the temporary path, which is always correct, so a thread that died mid-commit cannot hang the title.

A write generation per 64 KiB page. Bumped after the bytes are written (release), read with acquire: an unchanged digest is a promise about the bytes, not only about the counter. physical_generation_digest(pages, offset, len) folds a range into one number — the input phase F needs to stop hashing texture memory it already knows. It has no caller here yet beyond its test, and the allow(dead_code) says so rather than pretending otherwise.

Tests (3, all device-free):

  • persistent_view_maps_above_the_title_memory_ceiling — the view lands at or above 1 TiB, a write through it is in the section's pages, and the rule refuses one page below the ceiling.
  • concurrent_commit_state_never_exposes_an_uncommitted_page — eight threads commit the same four uncommitted pages; all eight succeed and every byte each wrote is still there.
  • dirty_generation_digest_changes_on_write_and_stays_stable_when_clean — a physical write moves the range's digest but not an untouched page's; a second identical write moves it again; a page window's bytes count when the window goes; unknown pages and ranges past the end are refused.

/kee probes, each restored byte-identical:

mutation result
generation bump after a physical write removed fails, a write must show
page window's bump on drop removed fails, a page window's bytes must show
above_title_memory always true fails on the page below the ceiling
LowestStartingAddress set to null passes — nothing catches it

That last row is the honest part: this host's allocator is already top-down, so it returns an address above 1 TiB with or without the requirement. The requirement is a belt no test here can reach; the predicate is the pin, and that is the one the probe breaks. Said out loud rather than reported as a passing probe.

Gate on 2853f67e: cargo test -p victory-hle xmem:: → 22 passed; cargo test -p victory-hle → 108 passed, 0 failed; both clippy --workspace --all-targets passes red only on main's three pre-existing lints; xtask 4 passed.

Not covered: no run in the game, so whether the high address helps anything in practice is unmeasured. VICTORY_XMEM_PERSISTENT_VIEW stays off.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6603394809 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/872). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-25T11:24:39Z. --- > ⚠️ **Stacked on #231** (`perf/xmem-persistent-section-views`, still open). The diff here shows both because the base branch lives on this fork, not upstream: once #231 lands, this shrinks to the one commit it actually adds. **Do not merge before #231.** Three changes to the physical-page path, none of which changes it by default (`VICTORY_XMEM_PERSISTENT_VIEW` still off): **The view's address.** It used to be wherever `MapViewOfFile` put it, which can be inside the range the title itself owns — below 40 bits, the range decision 0001 says title structures must live in. A view there either takes an address the title is about to ask for, or makes our own mapping look like a title address to the title's own pointer arithmetic. It is now reserved with `VirtualAlloc2`'s address requirement from 1 TiB to `GetSystemInfo().lpMaximumApplicationAddress` (asked, never assumed) and mapped into that reservation with `MapViewOfFile3`. A view that comes back below the ceiling anyway is released and the caller keeps its temporary view — the host is not trusted to honour the requirement. **Commit state, three states per page instead of one bit.** The bit recorded "committed" but could not promise anything at the moment it mattered: the DirectStorage workers write these sections concurrently, and a thread that lost the race to `VirtualAlloc(MEM_COMMIT)` would store into a page whose commit was still **in flight**. Pages are now `FREE` → `COMMITTING` (claimed by one thread) → `COMMITTED` (set only after `VirtualAlloc` returned); a loser spins on `COMMITTING` instead of writing. A bounded spin then gives up to the temporary path, which is always correct, so a thread that died mid-commit cannot hang the title. **A write generation per 64 KiB page.** Bumped *after* the bytes are written (release), read with acquire: an unchanged digest is a promise about the bytes, not only about the counter. `physical_generation_digest(pages, offset, len)` folds a range into one number — the input phase F needs to stop hashing texture memory it already knows. It has no caller here yet beyond its test, and the `allow(dead_code)` says so rather than pretending otherwise. Tests (3, all device-free): - `persistent_view_maps_above_the_title_memory_ceiling` — the view lands at or above 1 TiB, a write through it is in the section's pages, and the rule refuses one page below the ceiling. - `concurrent_commit_state_never_exposes_an_uncommitted_page` — eight threads commit the same four uncommitted pages; all eight succeed and every byte each wrote is still there. - `dirty_generation_digest_changes_on_write_and_stays_stable_when_clean` — a physical write moves the range's digest but not an untouched page's; a second identical write moves it again; a page window's bytes count when the window goes; unknown pages and ranges past the end are refused. `/kee` probes, each restored byte-identical: | mutation | result | |---|---| | generation bump after a physical write removed | fails, `a write must show` | | page window's bump on drop removed | fails, `a page window's bytes must show` | | `above_title_memory` always true | fails on the page below the ceiling | | `LowestStartingAddress` set to null | **passes — nothing catches it** | That last row is the honest part: this host's allocator is already top-down, so it returns an address above 1 TiB with or without the requirement. The requirement is a belt no test here can reach; the predicate is the pin, and that is the one the probe breaks. Said out loud rather than reported as a passing probe. Gate on `2853f67e`: `cargo test -p victory-hle xmem::` → 22 passed; `cargo test -p victory-hle` → 108 passed, 0 failed; both `clippy --workspace --all-targets` passes red only on `main`'s three pre-existing lints; `xtask` 4 passed. Not covered: no run in the game, so whether the high address helps anything in practice is unmeasured. `VICTORY_XMEM_PERSISTENT_VIEW` stays off.
MamaLeVrai commented 2026-11-25 13:05:59 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by MamaLeVrai on 2026-11-25T12:23:15Z.


Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head 2853f67 into main f85101b in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings fails with exactly the errors main itself has on this machine (placed_filler_twins, depth_written, a sort; PR #841 fixes them), also with --all-features; this PR adds none. cargo test --workspace --locked: run 1: stopped at indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields (the one that fails on main itself most runs here (PR #849 and #847 fix its assertion)); run 2: stopped at indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields (the one that fails on main itself most runs here (PR #849 and #847 fix its assertion)) (main alone: 555 passed, 0 failed, 11 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7162303684 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/872#issuecomment-7162303684). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T12:23:15Z. --- Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head `2853f67` into `main` `f85101b` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings` fails with exactly the errors `main` itself has on this machine (`placed_filler_twins`, `depth_written`, a sort; PR #841 fixes them), also with `--all-features`; this PR adds none. `cargo test --workspace --locked`: run 1: stopped at `indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields` (the one that fails on `main` itself most runs here (PR #849 and #847 fix its assertion)); run 2: stopped at `indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields` (the one that fails on `main` itself most runs here (PR #849 and #847 fix its assertion)) (`main` alone: 555 passed, 0 failed, 11 ignored). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
HailLucifer666 commented 2026-11-26 14:03:31 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-26T13:56:58Z.


Rebased onto the new #231 head (ad67d255); this head is now 1e653717 (--onto so only this PR's commit replayed). One import conflict, resolved as the union (GetSystemInfo/SYSTEM_INFO plus GetCurrentProcess/GetCurrentThread), a stray brace removed from the Drop match, and one new-toolchain lint fixed (let...else exactly equal to ? in the view-size rounding). Verified: cargo check and clippy -D warnings on victory-hle clean; victory-hle xmem:: 24 passed, 0 failed (the 21 from #231 plus this PR's 3).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7194061623 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/872#issuecomment-7194061623). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-26T13:56:58Z. --- Rebased onto the new `#231` head (`ad67d255`); this head is now `1e653717` (`--onto` so only this PR's commit replayed). One import conflict, resolved as the union (`GetSystemInfo`/`SYSTEM_INFO` plus `GetCurrentProcess`/`GetCurrentThread`), a stray brace removed from the `Drop` match, and one new-toolchain lint fixed (`let...else` exactly equal to `?` in the view-size rounding). Verified: `cargo check` and `clippy -D warnings` on victory-hle clean; `victory-hle xmem::` 24 passed, 0 failed (the 21 from #231 plus this PR's 3).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/872:upstream-pr/872'
git switch 'upstream-pr/872'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/872'
git switch 'upstream-pr/872'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/872'
git switch 'upstream-pr/872'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/872'
git switch 'main'
git merge --squash 'upstream-pr/872'
git switch 'main'
git merge --ff-only 'upstream-pr/872'
git switch 'main'
git merge 'upstream-pr/872'
git push origin 'main'
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
fxceless/victory-fork!871
No description provided.