hle(xmem),gpu(watch): mark decommitted and released pages written in watch journal #147

Merged
Androtim merged 1 commit from upstream-pr/147 into main 2026-11-29 16:41:32 +00:00
Androtim commented 2026-11-29 16:08:45 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T16:08:45Z.


Problem

When a title decommits or releases virtual memory via VirtualFree or XMemFreeDefault, Windows does not set write-watch dirty bits for those pages (nor when zero-filling pages upon later recommit). As a result, host copies tracked by victory-gpu::watch can retain stale non-zero contents after memory is freed and reallocated/recommitted.

Changes

  • crates/victory-gpu/src/watch.rs & crates/victory-gpu/src/lib.rs:
    • Added and re-exported title_memory_decommitted(at, len) to mark decommitted/released pages as written (WHOLE) in the watch Journal (intersecting live shadow::spans() for very large region releases exceeding 1 << 18 pages).
    • Added unit test many_askers_tests::title_memory_decommitted_marks_pages_written_in_journal.
  • crates/victory-hle/src/modules/xmem.rs:
    • Added HOST_PAGE, host_pages, allocation_span, and freed_span helpers to resolve the exact byte span affected by VirtualFree decommit/release calls (ignoring placeholder split/coalesce and invalid flag combinations).
    • Wired victory_gpu::title_memory_decommitted after successful VirtualFree in title_virtual_free and the ALLOC_32BIT release path of XMemFreeDefault.
    • Added unit test tests::freed_span_covers_decommits_and_releases_without_placeholders.

Verification

Ran locally on feat/iter148-xmem-decommit-dirty-and-live-commit:

  • cargo xtask policy: 304 files ok
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-hle xmem:: --locked: 26 passed; 0 failed; 1 ignored
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu watch:: --locked -- --test-threads=1: 50 passed; 0 failed
  • Dual workspace clippy --all-targets -- -D warnings (default and --features diagnostics): 0 warnings
<!-- greyfinch-sync:Androtim/MiniVI:issue:5552538446 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/147). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-29T16:08:45Z. --- ## Problem When a title decommits or releases virtual memory via `VirtualFree` or `XMemFreeDefault`, Windows does not set write-watch dirty bits for those pages (nor when zero-filling pages upon later recommit). As a result, host copies tracked by `victory-gpu::watch` can retain stale non-zero contents after memory is freed and reallocated/recommitted. ## Changes - **`crates/victory-gpu/src/watch.rs` & `crates/victory-gpu/src/lib.rs`**: - Added and re-exported `title_memory_decommitted(at, len)` to mark decommitted/released pages as written (`WHOLE`) in the watch `Journal` (intersecting live `shadow::spans()` for very large region releases exceeding `1 << 18` pages). - Added unit test `many_askers_tests::title_memory_decommitted_marks_pages_written_in_journal`. - **`crates/victory-hle/src/modules/xmem.rs`**: - Added `HOST_PAGE`, `host_pages`, `allocation_span`, and `freed_span` helpers to resolve the exact byte span affected by `VirtualFree` decommit/release calls (ignoring placeholder split/coalesce and invalid flag combinations). - Wired `victory_gpu::title_memory_decommitted` after successful `VirtualFree` in `title_virtual_free` and the `ALLOC_32BIT` release path of `XMemFreeDefault`. - Added unit test `tests::freed_span_covers_decommits_and_releases_without_placeholders`. ## Verification Ran locally on `feat/iter148-xmem-decommit-dirty-and-live-commit`: - `cargo xtask policy`: `304 files ok` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-hle xmem:: --locked`: `26 passed; 0 failed; 1 ignored` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu watch:: --locked -- --test-threads=1`: `50 passed; 0 failed` - Dual workspace `clippy --all-targets -- -D warnings` (default and `--features diagnostics`): 0 warnings
Androtim commented 2026-11-29 16:16:08 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T16:16:08Z.


Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

Logic and safety look solid, CI is passing, and both crates include targeted unit tests covering the new behavior.

What was checked

  • crates/victory-gpu/src/watch.rs & crates/victory-gpu/src/lib.rs:
    • title_memory_decommitted(at, len) marks affected 64 KiB watch pages as WHOLE in Journal under journal_mut(), advances j.ahead_asked to now so active ask_ahead readers stay consistent with the new stamp, and falls back to intersecting live crate::shadow::spans() when the span exceeds MOST (1 << 18 pages = 16 GiB).
    • many_askers_tests::title_memory_decommitted_marks_pages_written_in_journal verifies the journal stamp advances past the prior writes() ask stamp.
  • crates/victory-hle/src/modules/xmem.rs:
    • host_pages, allocation_span, and freed_span accurately resolve the byte range affected by MEM_DECOMMIT and MEM_RELEASE (both sized and zero-sized) while ignoring placeholder split/coalesce (MEM_PRESERVE_PLACEHOLDER, MEM_COALESCE_PLACEHOLDERS) and invalid flag combinations.
    • title_virtual_free and the ALLOC_32BIT path of XMemFreeDefault capture freed_span before VirtualFree and call victory_gpu::title_memory_decommitted only when VirtualFree succeeds (ok != 0). XMemFreeDefault also now calls victory_gpu::title_memory_freed before releasing.
    • tests::freed_span_covers_decommits_and_releases_without_placeholders exercises the span helpers across commit/decommit/release/placeholder cases.

Minor non-blocking notes

  • allocation_span in crates/victory-hle/src/modules/xmem.rs uses plain + (info.BaseAddress as usize + info.RegionSize) and title_memory_decommitted uses (start + bytes) as usize in the > MOST branch; saturating_add (matching watch.rs::allocation_end) would be slightly more defensive, though neither overflows for valid user-mode spans.

Next step

Because this touches victory-gpu::watch journal stamping (JOURNAL write lock and ahead_asked) on every title VirtualFree/XMemFreeDefault, run a local real-GPU title smoke test to confirm no frame-time regression, lock contention spikes, or stale host-copy artifacts before merging.


Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7258750973 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/147#issuecomment-7258750973). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-29T16:16:08Z. --- <!-- minivi-triage v1 head=94b92df60a2a77275ca1deced8059f375ecb07c6 verdict=needs-gpu-test ci=passing at=2026-11-29T16:16:39Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic and safety look solid, CI is passing, and both crates include targeted unit tests covering the new behavior. #### What was checked - **`crates/victory-gpu/src/watch.rs` & `crates/victory-gpu/src/lib.rs`**: - `title_memory_decommitted(at, len)` marks affected 64 KiB watch pages as `WHOLE` in `Journal` under `journal_mut()`, advances `j.ahead_asked` to `now` so active `ask_ahead` readers stay consistent with the new stamp, and falls back to intersecting live `crate::shadow::spans()` when the span exceeds `MOST` (`1 << 18` pages = 16 GiB). - `many_askers_tests::title_memory_decommitted_marks_pages_written_in_journal` verifies the journal stamp advances past the prior `writes()` ask stamp. - **`crates/victory-hle/src/modules/xmem.rs`**: - `host_pages`, `allocation_span`, and `freed_span` accurately resolve the byte range affected by `MEM_DECOMMIT` and `MEM_RELEASE` (both sized and zero-sized) while ignoring placeholder split/coalesce (`MEM_PRESERVE_PLACEHOLDER`, `MEM_COALESCE_PLACEHOLDERS`) and invalid flag combinations. - `title_virtual_free` and the `ALLOC_32BIT` path of `XMemFreeDefault` capture `freed_span` before `VirtualFree` and call `victory_gpu::title_memory_decommitted` only when `VirtualFree` succeeds (`ok != 0`). `XMemFreeDefault` also now calls `victory_gpu::title_memory_freed` before releasing. - `tests::freed_span_covers_decommits_and_releases_without_placeholders` exercises the span helpers across commit/decommit/release/placeholder cases. #### Minor non-blocking notes - `allocation_span` in `crates/victory-hle/src/modules/xmem.rs` uses plain `+` (`info.BaseAddress as usize + info.RegionSize`) and `title_memory_decommitted` uses `(start + bytes) as usize` in the `> MOST` branch; `saturating_add` (matching `watch.rs::allocation_end`) would be slightly more defensive, though neither overflows for valid user-mode spans. #### Next step Because this touches `victory-gpu::watch` journal stamping (`JOURNAL` write lock and `ahead_asked`) on every title `VirtualFree`/`XMemFreeDefault`, run a local real-GPU title smoke test to confirm no frame-time regression, lock contention spikes, or stale host-copy artifacts before merging. --- _Generated with Antigravity CLI (`agy`)._
Androtim commented 2026-11-29 16:41:29 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T16:41:29Z.


Automated RTX 4060 Ti 8 GB hardware verification PASSED (playtest/wave4-no141 vs origin/main 17a2f09 — 5/5 A/B gates PASS):

  • Hardware cargo test (RTX 4060 Ti): victory 39 passed, 0 failed; victory-gpu 552 passed, 0 failed (37 ignored).
  • Automated 45s in-world A/B (scripts/verify-world.ps1, DLSS Quality + golden autosave):
    • FPS: median 11.9 fps (84.15 ms) vs 11.2 fps (88.9 ms) baseline (+0.70 fps, min improved 7.0 vs 4.6, preparing 43.2 ms vs 45.1 ms)
    • Stability: 0 crashes / 0 DRED / 0 untranslated shaders
    • VRAM: max 5641 MB vs 5760 MB (-119 MB, 0 MB over budget)
    • Texture backlog: final_waiting=5924 vs 5753 (PASS)
    • Residency stalls: mapped_rate=8.69 ms/s vs 14.96 ms/s (-42%)
    • Visual check: Clean solid skin and lighting (frame-3923.png, frame-3955.png), luma 66.54, edge energy 2.1, magenta 0.0%.
<!-- greyfinch-sync:Androtim/MiniVI:comment:7259101713 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/147#issuecomment-7259101713). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-29T16:41:29Z. --- Automated RTX 4060 Ti 8 GB hardware verification **PASSED** (`playtest/wave4-no141` vs `origin/main` `17a2f09` — **5/5 A/B gates PASS**): - **Hardware `cargo test` (RTX 4060 Ti):** `victory` **39 passed, 0 failed**; `victory-gpu` **552 passed, 0 failed** (37 ignored). - **Automated 45s in-world A/B (`scripts/verify-world.ps1`, DLSS Quality + golden autosave):** - **FPS:** median **`11.9 fps`** (`84.15 ms`) vs `11.2 fps` (`88.9 ms`) baseline (**+0.70 fps**, min improved **`7.0`** vs `4.6`, preparing **`43.2 ms`** vs `45.1 ms`) - **Stability:** **0** crashes / **0** DRED / **0** untranslated shaders - **VRAM:** max **`5641 MB`** vs `5760 MB` (**-119 MB**, `0 MB` over budget) - **Texture backlog:** `final_waiting=5924` vs `5753` (PASS) - **Residency stalls:** `mapped_rate=8.69 ms/s` vs `14.96 ms/s` (**-42%**) - **Visual check:** Clean solid skin and lighting (`frame-3923.png`, `frame-3955.png`), luma `66.54`, edge energy `2.1`, magenta `0.0%`.
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
Androtim/MiniVI!147
No description provided.