GPU: skip pending copy-backs and clear saved snapshots on remapped pages #2612

Open
github-bot wants to merge 7 commits from github-bot/gh-2612 into main AGit
Owner

@⁠ashrafsdrop on GitHub · 2026-11-25 16:47 UTC · original
ashrafsdrop:gpu/remap-skips-pending-copy-back → main · +789 −34 · 6 files · 7 commits · open

Summary

Addresses FIND-14: when title memory is unmapped or remapped (watch::title_memory_remapped) while a submission's copy-back is still pending, stale pre-remap GPU writes must not be diffed and written back over the newly mapped memory.

  • In watch.rs, track remapped pages in Saved::remapped via Changed::remapped from title_memory_remapped, clear armed and saved pre-write bytes for those pages, expose Tracked::was_remapped, and clear per-submission remap state in Changed::taken and Tracked::disarm.
  • In shadow.rs, skip was_remapped pages in Shadow::copy_back_or_not so new title memory is preserved and the page remains dirty (changed) for the next Shadow::update.
  • Added unit tests:
    • watch::tests::remapping_clears_saved_bytes_and_marks_page_remapped
    • shadow::tests::remapping_while_copy_back_is_pending_keeps_new_title_bytes
    • shadow::tests::remapping_after_title_write_discards_saved_bytes_for_marked_copy_back

Verification

  • cargo test -p victory-gpu --lib watch — 13 passed, 0 failed
  • cargo test -p victory-gpu --lib shadow — 10 passed, 0 failed
  • cargo test -p victory-gpu --lib -- --skip a_texture_written_in_one_format_reads_in_another_through_a_placed_view — 197 passed, 0 failed, 1 ignored, 1 filtered out (a_texture_written_in_one_format_reads_in_another_through_a_placed_view fails identically on origin/main 67e8ae1 on this host without Agility SDK)
  • cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings — clean
  • cargo run -p xtask -- policy — 184 files ok
  • git diff --check — clean
**@⁠ashrafsdrop** on GitHub · 2026-11-25 16:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612) `ashrafsdrop:gpu/remap-skips-pending-copy-back` → `main` · +789 −34 · 6 files · 7 commits · open ### Summary Addresses `FIND-14`: when title memory is unmapped or remapped (`watch::title_memory_remapped`) while a submission's copy-back is still pending, stale pre-remap GPU writes must not be diffed and written back over the newly mapped memory. - In [watch.rs](file:///e:/VIctory/crates/victory-gpu/src/watch.rs), track remapped pages in `Saved::remapped` via `Changed::remapped` from `title_memory_remapped`, clear `armed` and saved pre-write `bytes` for those pages, expose `Tracked::was_remapped`, and clear per-submission remap state in `Changed::taken` and `Tracked::disarm`. - In [shadow.rs](file:///e:/VIctory/crates/victory-gpu/src/shadow.rs), skip `was_remapped` pages in `Shadow::copy_back_or_not` so new title memory is preserved and the page remains dirty (`changed`) for the next `Shadow::update`. - Added unit tests: - `watch::tests::remapping_clears_saved_bytes_and_marks_page_remapped` - `shadow::tests::remapping_while_copy_back_is_pending_keeps_new_title_bytes` - `shadow::tests::remapping_after_title_write_discards_saved_bytes_for_marked_copy_back` ### Verification - `cargo test -p victory-gpu --lib watch` — 13 passed, 0 failed - `cargo test -p victory-gpu --lib shadow` — 10 passed, 0 failed - `cargo test -p victory-gpu --lib -- --skip a_texture_written_in_one_format_reads_in_another_through_a_placed_view` — 197 passed, 0 failed, 1 ignored, 1 filtered out (`a_texture_written_in_one_format_reads_in_another_through_a_placed_view` fails identically on `origin/main` `67e8ae1` on this host without Agility SDK) - `cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings` — clean - `cargo run -p xtask -- policy` — 184 files ok - `git diff --check` — clean
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:20 +00:00
github-bot force-pushed github-bot/gh-2612 from d687c71fae to 4f47bdcf10 2026-11-26 06:32:06 +00:00 Compare
Author
Owner

@⁠ashrafsdrop on GitHub · 2026-11-25 17:03 UTC · original

Addressed in d687c71 — good catch on that window.

Changes

  • Added a shared mapping lock (MAPPING) with a thread-reentrant RAII guard victory_gpu::title_memory_remapping() in crates/victory-gpu/src/watch.rs (re-exported in crates/victory-gpu/src/lib.rs).
  • XMemMapPhysicalPages and map_alias (crates/victory-hle/src/modules/xmem.rs) and Upload::drop (crates/victory-gpu/src/list.rs) hold title_memory_remapping() across both the OS map/unmap/VirtualFree calls and title_memory_remapped; standalone title_memory_remapped calls acquire it directly.
  • Added watch::write_back, which acquires MAPPING, re-checks Tracked::was_remapped for [at, at + len), and executes write_mapped inside watch::writing without releasing MAPPING. Routed copy_back_page, copy_back_or_not, and copy_back_marked (crates/victory-gpu/src/shadow.rs) through it, and filtered was_remapped pages under MAPPING inside Tracked::taken so a remap between write_back and taken cannot clear changed.
  • Added pause-and-remap regression tests in crates/victory-gpu/src/shadow.rs:
    • shadow::tests::remapping_after_copy_back_check_before_write_skips_write_back (pauses copy_back_or_not after the initial check, remaps on another thread, resumes)
    • shadow::tests::remapping_after_marked_snapshot_taken_before_write_skips_write_back (pauses copy_back_marked after t.saved() moved the snapshot out, remaps on another thread, resumes)
    • shadow::tests::copy_back_write_waits_for_in_flight_remapping_guard (holds title_memory_remapping() on another thread while copy-back enters write_back, then remaps and releases)

Verification

  • cargo test -p victory-gpu --lib -- --skip a_texture_written_in_one_format_reads_in_another_through_a_placed_view — 200 passed, 0 failed, 1 ignored, 1 filtered out (the skipped test fails identically on origin/main 67e8ae1 on this host without Agility SDK)
  • cargo test -p victory-hle xmem — 11 passed, 0 failed
  • cargo clippy -p victory-gpu -p victory-hle --all-targets --all-features -- -D warnings — clean
  • cargo run -p xtask -- policy — 184 files ok
  • git diff --check — clean
**@⁠ashrafsdrop** on GitHub · 2026-11-25 17:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7168946360) Addressed in [`d687c71`](https://github.com/ashrafsdrop/VIctory/commit/d687c71) — good catch on that window. ### Changes - Added a shared mapping lock (`MAPPING`) with a thread-reentrant RAII guard `victory_gpu::title_memory_remapping()` in `crates/victory-gpu/src/watch.rs` (re-exported in `crates/victory-gpu/src/lib.rs`). - `XMemMapPhysicalPages` and `map_alias` (`crates/victory-hle/src/modules/xmem.rs`) and `Upload::drop` (`crates/victory-gpu/src/list.rs`) hold `title_memory_remapping()` across both the OS map/unmap/`VirtualFree` calls and `title_memory_remapped`; standalone `title_memory_remapped` calls acquire it directly. - Added `watch::write_back`, which acquires `MAPPING`, re-checks `Tracked::was_remapped` for `[at, at + len)`, and executes `write_mapped` inside `watch::writing` without releasing `MAPPING`. Routed `copy_back_page`, `copy_back_or_not`, and `copy_back_marked` (`crates/victory-gpu/src/shadow.rs`) through it, and filtered `was_remapped` pages under `MAPPING` inside `Tracked::taken` so a remap between `write_back` and `taken` cannot clear `changed`. - Added pause-and-remap regression tests in `crates/victory-gpu/src/shadow.rs`: - `shadow::tests::remapping_after_copy_back_check_before_write_skips_write_back` (pauses `copy_back_or_not` after the initial check, remaps on another thread, resumes) - `shadow::tests::remapping_after_marked_snapshot_taken_before_write_skips_write_back` (pauses `copy_back_marked` after `t.saved()` moved the snapshot out, remaps on another thread, resumes) - `shadow::tests::copy_back_write_waits_for_in_flight_remapping_guard` (holds `title_memory_remapping()` on another thread while copy-back enters `write_back`, then remaps and releases) ### Verification - `cargo test -p victory-gpu --lib -- --skip a_texture_written_in_one_format_reads_in_another_through_a_placed_view` — 200 passed, 0 failed, 1 ignored, 1 filtered out (the skipped test fails identically on `origin/main` `67e8ae1` on this host without Agility SDK) - `cargo test -p victory-hle xmem` — 11 passed, 0 failed - `cargo clippy -p victory-gpu -p victory-hle --all-targets --all-features -- -D warnings` — clean - `cargo run -p xtask -- policy` — 184 files ok - `git diff --check` — clean
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 17:15 UTC · original

Independent Windows verification of PR #2612 (head d687c71) on a native RTX 5060 Laptop (driver 621.24) and on WARP.

Toolchain: rustc/cargo 1.100.0, Windows MSVC (the repo pins 1.98.1 in rust-toolchain.toml; no clippy component is available locally). Synthetic tests only, no game data, no source edits.

  • cargo test --locked -p victory-gpu --lib remapping -- --test-threads=1 on the PR head: 6 passed, 196 filtered. The three named regressions pass: watch::tests::remapping_clears_saved_bytes_and_marks_page_remapped, shadow::tests::remapping_while_copy_back_is_pending_keeps_new_title_bytes, shadow::tests::remapping_after_title_write_discards_saved_bytes_for_marked_copy_back.
  • watch::tests 13 passed, shadow::tests 13 passed on the PR head.
  • Negative control on the merge base 67e8ae1: the same remapping filter reports 0 tests (the new tests are absent).
  • WARP (VICTORY_D3D12_WARP=1, --features diagnostics, --test-threads=1, skipping only the known placed-view flake a_texture_written_in_one_format_reads_in_another_through_a_placed_view): 203 passed, 1 ignored, 1 filtered, 0 failed.
  • RTX 5060 Laptop (VICTORY_D3D12_WARP=0) full lib initially reported 201 passed, 2 failed: descriptor::host::tests::dynamic_slots_are_held_until_released (host.rs:2030, NumDescriptors >= HEAP_VIEWS) and memory::tests::lists_share_a_table_and_copies_keep_their_views (memory.rs:767, 'past the dynamic slots'). Both reproduce on unmodified base 67e8ae1 with WARP=0, so they are pre-existing hardware-specific failures, not regressions from this PR. Rerunning while skipping those two plus the placed-view flake: 201 passed, 0 failed, 1 ignored, 3 filtered.

No competing implementation or PR. AI-assisted (Hy4 flash).

**@⁠cloph-dsp** on GitHub · 2026-11-25 17:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7169230211) Independent Windows verification of PR #2612 (head `d687c71`) on a native RTX 5060 Laptop (driver 621.24) and on WARP. Toolchain: rustc/cargo 1.100.0, Windows MSVC (the repo pins 1.98.1 in `rust-toolchain.toml`; no clippy component is available locally). Synthetic tests only, no game data, no source edits. - `cargo test --locked -p victory-gpu --lib remapping -- --test-threads=1` on the PR head: **6 passed**, 196 filtered. The three named regressions pass: `watch::tests::remapping_clears_saved_bytes_and_marks_page_remapped`, `shadow::tests::remapping_while_copy_back_is_pending_keeps_new_title_bytes`, `shadow::tests::remapping_after_title_write_discards_saved_bytes_for_marked_copy_back`. - `watch::tests` 13 passed, `shadow::tests` 13 passed on the PR head. - Negative control on the merge base `67e8ae1`: the same `remapping` filter reports **0 tests** (the new tests are absent). - WARP (`VICTORY_D3D12_WARP=1`, `--features diagnostics`, `--test-threads=1`, skipping only the known placed-view flake `a_texture_written_in_one_format_reads_in_another_through_a_placed_view`): **203 passed**, 1 ignored, 1 filtered, 0 failed. - RTX 5060 Laptop (`VICTORY_D3D12_WARP=0`) full lib initially reported 201 passed, 2 failed: `descriptor::host::tests::dynamic_slots_are_held_until_released` (`host.rs:2030`, `NumDescriptors >= HEAP_VIEWS`) and `memory::tests::lists_share_a_table_and_copies_keep_their_views` (`memory.rs:767`, 'past the dynamic slots'). Both reproduce on unmodified base `67e8ae1` with WARP=0, so they are pre-existing hardware-specific failures, not regressions from this PR. Rerunning while skipping those two plus the placed-view flake: **201 passed**, 0 failed, 1 ignored, 3 filtered. No competing implementation or PR. AI-assisted (Hy4 flash).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 17:15 UTC · original

WARP verification of d687c71 merged cleanly onto origin/main 13f91ca (detached checkout). I first tested the earlier head 4112fd7, then re-ran everything on d687c71 after it landed.

Environment: Windows 11. No physical GPU device was created: VICTORY_D3D12_WARP=1, VICTORY_WARP=1, cargo -j 4, separate CARGO_TARGET_DIR.

Commands and results (head d687c71):

  • cargo clippy -j 4 -p victory-gpu -p victory-hle --features victory-gpu/diagnostics --all-targets: clean.
  • cargo test -j 4 -p victory-gpu --features diagnostics --lib: 204 passed, 0 failed, 1 ignored (origin/main: 198). a_texture_written_in_one_format_reads_in_another_through_a_placed_view passes on WARP here, so no skip was needed.
  • cargo test -j 4 -p victory-hle --lib xmem: 11 passed, 0 failed.
  • Negative control on d687c71: removing the was_remapped recheck in watch::write_back makes remapping_after_copy_back_check_before_write_skips_write_back, remapping_after_marked_snapshot_taken_before_write_skips_write_back and copy_back_write_waits_for_in_flight_remapping_guard fail. On the earlier 4112fd7, removing the shadow.rs skip fails remapping_while_copy_back_is_pending_keeps_new_title_bytes.
  • The new tests have a "no host GPU here" early return. On WARP they run (reported ok, not skipped), so they do exercise the code.

Review notes:

  • Overlap with #2455: merging #2455 onto this PR conflicts in watch.rs (needs a manual merge). #2434 (shadow.rs only) merges textually clean. I did not build or test either combination.
  • Locking: MAPPING is taken by title_memory_remapping (reentrant per thread), but write_back and Tracked::taken call MAPPING.lock() directly (non-reentrant). A thread that holds a Remapping guard and then reaches either one would self-deadlock. I found no such path in xmem.rs, Upload::drop or the tests (the tests' hook runs before the lock is taken), but it is worth a comment. In xmem.rs the order is physical() then MAPPING; I found nothing taking them the other way round.
  • Pre-existing flake (not from this PR): memory::a_submission_that_missed_leaves_the_copies_at_once failed in about 4 of 20 full runs on both this PR and origin/main.

Not tested: physical GPU, real remap races under load, or a retail title. The pause-and-remap tests are deterministic stand-ins for the race.

Independent review and WARP verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or retail data were used.

**@⁠oni-swr** on GitHub · 2026-11-25 17:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7169246519) **WARP verification** of `d687c71` merged cleanly onto `origin/main` `13f91ca` (detached checkout). I first tested the earlier head `4112fd7`, then re-ran everything on `d687c71` after it landed. Environment: Windows 11. No physical GPU device was created: `VICTORY_D3D12_WARP=1`, `VICTORY_WARP=1`, `cargo -j 4`, separate `CARGO_TARGET_DIR`. Commands and results (head `d687c71`): - `cargo clippy -j 4 -p victory-gpu -p victory-hle --features victory-gpu/diagnostics --all-targets`: clean. - `cargo test -j 4 -p victory-gpu --features diagnostics --lib`: **204 passed, 0 failed, 1 ignored** (`origin/main`: 198). `a_texture_written_in_one_format_reads_in_another_through_a_placed_view` passes on WARP here, so no skip was needed. - `cargo test -j 4 -p victory-hle --lib xmem`: 11 passed, 0 failed. - Negative control on `d687c71`: removing the `was_remapped` recheck in `watch::write_back` makes `remapping_after_copy_back_check_before_write_skips_write_back`, `remapping_after_marked_snapshot_taken_before_write_skips_write_back` and `copy_back_write_waits_for_in_flight_remapping_guard` fail. On the earlier `4112fd7`, removing the `shadow.rs` skip fails `remapping_while_copy_back_is_pending_keeps_new_title_bytes`. - The new tests have a "no host GPU here" early return. On WARP they run (reported `ok`, not skipped), so they do exercise the code. Review notes: - Overlap with #2455: merging #2455 onto this PR **conflicts in `watch.rs`** (needs a manual merge). #2434 (`shadow.rs` only) merges textually clean. I did not build or test either combination. - Locking: `MAPPING` is taken by `title_memory_remapping` (reentrant per thread), but `write_back` and `Tracked::taken` call `MAPPING.lock()` directly (non-reentrant). A thread that holds a `Remapping` guard and then reaches either one would self-deadlock. I found no such path in `xmem.rs`, `Upload::drop` or the tests (the tests' hook runs before the lock is taken), but it is worth a comment. In `xmem.rs` the order is `physical()` then `MAPPING`; I found nothing taking them the other way round. - Pre-existing flake (not from this PR): `memory::a_submission_that_missed_leaves_the_copies_at_once` failed in about 4 of 20 full runs on both this PR and `origin/main`. Not tested: physical GPU, real remap races under load, or a retail title. The pause-and-remap tests are deterministic stand-ins for the race. _Independent review and WARP verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or retail data were used._
Author
Owner

@⁠ashrafsdrop on GitHub · 2026-11-25 17:48 UTC · original

Thanks @cloph-dsp and @oni-swr for the independent RTX 5060 / WARP verifications and negative-control checks!

Re @oni-swr's note: confirmed — title_memory_remapping() is only held around XMemMapPhysicalPages, map_alias, Upload::drop, and title_memory_remapped, none of which enter write_back or Tracked::taken (and Remapping is !Send), so MAPPING cannot self-deadlock. Happy to add that invariant note if maintainers want a follow-up touch; leaving d687c71 untouched for now so the existing checks and approval stay intact.

**@⁠ashrafsdrop** on GitHub · 2026-11-25 17:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7170036579) Thanks `@cloph-dsp` and `@oni-swr` for the independent RTX 5060 / WARP verifications and negative-control checks! Re `@oni-swr`'s note: confirmed — `title_memory_remapping()` is only held around `XMemMapPhysicalPages`, `map_alias`, `Upload::drop`, and `title_memory_remapped`, none of which enter `write_back` or `Tracked::taken` (and `Remapping` is `!Send`), so `MAPPING` cannot self-deadlock. Happy to add that invariant note if maintainers want a follow-up touch; leaving `d687c71` untouched for now so the existing checks and approval stay intact.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:51 UTC · original

Reviewed: two coordinated fixes — the copy-back write is now gated through watch::write_back under the remapping lock (so a remap during the write can't leave stale bytes), and pages that were remapped while tracked are skipped entirely on refresh (was_remapped) plus pending copy-backs dropped — matching 'remapped memory is new memory' on the free path. The remap/notify ordering under one lock closes the TOCTOU. CI green.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7170100368) Reviewed: two coordinated fixes — the copy-back write is now gated through `watch::write_back` under the remapping lock (so a remap during the write can't leave stale bytes), and pages that were remapped while tracked are skipped entirely on refresh (`was_remapped`) plus pending copy-backs dropped — matching 'remapped memory is new memory' on the free path. The remap/notify ordering under one lock closes the TOCTOU. CI green.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 21:52 UTC · original

Thanks for this. We had been writing the same fix (per-page remap state checked by every copy-back) and will not open a competing PR. We ran #2612's head (d687c71f) on WARP with our own tests ported onto it, changing none of its code. Results below.

What it covers. We checked each case with a test where another thread writes a byte and then reports the page through title_memory_remapped while the copy-back is pending:

case result on d687c71f
declared range, snapshot path (copy_back) covered: the remapped page keeps the new memory (passed)
marked page whose bytes the title's first write saved (copy_back_marks → copy_back_marked) covered: the remapped page keeps the new memory (passed)
page at a computed address (copy_back_page) covered: copy_back_page returns 0 and leaves the page alone (passed)
controls: pages the title only wrote, or nobody wrote, still get the shaders' bytes unchanged: all three get the shaders' bytes (passed)
the next refresh takes the new memory yes (passed)
a submission that begins after the remap writes back as usual yes (passed)
#2612's own tests (cargo test -p victory-gpu --features diagnostics --lib, WARP) all pass: 206 passed, 0 failed, 1 ignored (a release benchmark), with our two ported tests included

The mapping lock around XMemMapPhysicalPages and map_alias also closes the window between MapViewOfFile3 and the report. Our version left that window open as a documented shortcut, so #2612 is the stronger of the two there.

What it leaves out.

  1. XMemVirtualAlloc does not report new memory. Suppose the title frees memory a copy holds with the host's VirtualFree (VIctory does not see that call) and then allocates at the same address with XMemVirtualAlloc. The tracker still holds the page as taken and guarded, but the new memory has no guard, so title writes there do not fault and are never copied. This is the same "remapped under a tracker" class, reached through allocation instead of a page mapping. On d687c71f, the test below shows the write is missed while unreported (passed: the unreported case asserts the miss). With the one-line report our branch adds to XMemVirtualAlloc, it is taken again and guarded again (passed; here the test makes the report itself, as XMemVirtualAlloc would). The change is in crates/victory-hle/src/modules/xmem.rs on our branch: title_memory_remapped(at, end - at) after a successful VirtualAlloc2.

    Repro: memory_allocated_again_is_taken_again_once_reported (watch.rs tests)
    /// Memory freed while a tracker holds it and allocated again at the same
    /// address (the title's `VirtualFree`, which we do not see, then
    /// `XMemVirtualAlloc`, which reports what it allocates as remapped): the
    /// new memory has no guard, so a write there does not fault. Reported, it
    /// is taken again and guarded again, so a later write counts; unreported,
    /// the write is missed.
    #[test]
    fn memory_allocated_again_is_taken_again_once_reported() {
        for report in [false, true] {
            // Another test may allocate at the address between the free and
            // the new allocation: then tried again elsewhere.
            let (p, t) = (0..8)
                .find_map(|_| {
                    let p = pool(1);
                    let t = track_copy(p, PAGE, true).expect("pool memory is tracked");
                    assert_eq!(t.take(p, p + PAGE), [(p, p + PAGE)]);
                    free(p);
                    // SAFETY: a fresh allocation where ours was, freed below.
                    let again = unsafe {
                        VirtualAlloc(p as *const _, PAGE, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE)
                    } as usize;
                    if again == p {
                        return Some((p, t));
                    }
                    if again != 0 {
                        free(again);
                    }
                    None
                })
                .expect("an address allocated again");
            if report {
                title_memory_remapped(p, PAGE);
            }
            // SAFETY: our new allocation, read-write: no fault.
            unsafe { ((p + 8) as *mut u8).write_volatile(7) };
            if !report {
                assert!(t.take(p, p + PAGE).is_empty(), "unreported, the write is missed");
                drop(t);
                free(p);
                continue;
            }
            assert_eq!(t.take(p, p + PAGE), [(p, p + PAGE)], "the new memory is taken");
            assert!(t.clean());
            // SAFETY: as above, guarded again by the take: the handler opens it.
            unsafe { ((p + 9) as *mut u8).write_volatile(8) };
            assert!(t.changed(p / PAGE), "a later write counts");
            drop(t);
            free(p);
        }
    }
    
  2. Skips are not visible. Remap skips in copy_back_marked and copy_back_page are counted as "the title wrote it" (MarkedKept, or the once-logged warning), and the snapshot-path skip is not counted at all. A title run therefore cannot tell how often this happens. Our branch counts every skip and prints the total on the diagnostics copy line (N copy-back pages left alone for a remap (in all)), plus one log line the first time.

The six-page test used for the table (pages_remapped_while_shaders_write_keep_the_new_memory, shadow.rs tests; needs the small host::tests::no_submission helper so parallel tests do not take its marks)
/// Ported from fork mem/remap-epochs 6ce84a1c (P-E), adapted to #2612's
/// signatures (no submission epoch; no skip counter). A page the runtime
/// remaps while shaders write its copy (another thread, during the GPU's
/// run) keeps the new memory's bytes, whichever copy-back would have put
/// the shaders' there: a declared range's snapshot, a marked page whose
/// bytes the title's first write saved, a page at a computed address.
/// Pages the title only wrote, or nobody, get the shaders' byte as
/// before; a submission beginning after the remap writes back as usual.
/// Every case is checked and the failures listed together.
#[test]
fn pages_remapped_while_shaders_write_keep_the_new_memory() {
    use crate::watch::title_memory_remapped;
    // Nothing else takes the marks set below.
    let _one = crate::host::tests::no_submission();
    let p = crate::watch::tests::pool(6);
    let len = 6 * PAGE;
    register(p, p as u64, len as u64);
    let (Some(copy), Some(b)) = (find(p as u64, len as u64), bitmap(false)) else {
        unregister(p, p as u64);
        return; // no host GPU here
    };
    let base = copy.marks.expect("tracked memory gets mark bits") as usize;
    // SAFETY: a byte of our pool.
    let read = |at: usize| unsafe { ((p + at) as *const u8).read_volatile() };
    // The title writes a byte; with `remap`, the runtime then reports its
    // page as mapped anew. From another thread, as the title's.
    let title = |at: usize, value: u8, remap: bool| {
        std::thread::scope(|s| {
            s.spawn(|| {
                // SAFETY: a byte of our pool (a guard fault marks it).
                unsafe { ((p + at) as *mut u8).write_volatile(value) };
                if remap {
                    title_memory_remapped((p + at) & !(PAGE - 1), PAGE);
                }
            });
        });
    };
    let mut failed: Vec<String> = Vec::new();
    fn check(failed: &mut Vec<String>, case: &str, got: u8, want: u8) {
        if got != want {
            failed.push(format!("{case}: byte {got:#x}, expected {want:#x}"));
        }
    }
    copy.update(p, len);
    // Pages 0-1 declared (a snapshot), 2-3 marked (armed), 4-5 neither
    // (written at computed addresses).
    copy.writing(p, 2 * PAGE, false);
    copy.writing(p + 2 * PAGE, 2 * PAGE, true);
    // The shaders write a byte in each page.
    for k in 0..6 {
        copy.write_host((p + k * PAGE + 10) as u64, &[0xa0 + k as u8]);
    }
    // Meanwhile the title writes the same byte of each page but page 4,
    // and pages 1, 3 and 5 are remapped after (page 3 is armed: its
    // bytes from before the title's write are saved).
    for k in [0, 1, 2, 3, 5] {
        title(k * PAGE + 10, 0x50 + k as u8, k % 2 == 1);
    }
    let bits = b.data as *mut u32;
    for n in [base + 2, base + 3] {
        // SAFETY: a dword of the mapped bitmap.
        unsafe { *bits.add(n / 32) |= 1 << (n % 32) };
    }
    copy_back_marks(&[], false);
    copy.copy_back(p, 2 * PAGE);
    copy.copy_back(p + 2 * PAGE, 2 * PAGE);
    let page4 = copy.copy_back_page(p + 4 * PAGE);
    let page5 = copy.copy_back_page(p + 5 * PAGE);
    if page4 != PAGE {
        failed.push(format!("computed address, nobody wrote: copy_back_page returned {page4}, expected {PAGE}"));
    }
    if page5 != 0 {
        failed.push(format!("computed address, remapped: copy_back_page returned {page5}, expected 0"));
    }
    check(&mut failed, "snapshot path, title wrote (control)", read(10), 0xa0);
    check(&mut failed, "snapshot path, remapped", read(PAGE + 10), 0x51);
    check(&mut failed, "marked page, title wrote (control)", read(2 * PAGE + 10), 0xa2);
    check(&mut failed, "marked page with saved bytes, remapped", read(3 * PAGE + 10), 0x53);
    check(&mut failed, "computed address, nobody wrote (control)", read(4 * PAGE + 10), 0xa4);
    check(&mut failed, "computed address, remapped", read(5 * PAGE + 10), 0x55);
    // The copy takes the new memory at its next refresh.
    let refreshed = copy.update(p, len);
    if refreshed < 3 * PAGE {
        failed.push(format!("next refresh copied {refreshed} bytes, expected at least {}", 3 * PAGE));
    }
    check(&mut failed, "next refresh takes the new memory", copy.read_host((p + PAGE + 8) as u64, 1)[0].to_le_bytes()[2], 0x51);
    // A submission beginning after the remap writes back as usual.
    copy.writing(p, 2 * PAGE, false);
    copy.write_host((p + PAGE + 10) as u64, &[0xee]);
    copy.copy_back(p, 2 * PAGE);
    check(&mut failed, "a submission after the remap", read(PAGE + 10), 0xee);
    unregister(p, p as u64);
    assert!(failed.is_empty(), "{}", failed.join("; "));
}

Our commit is on fork r4tedx/VIctory, branch mem/remap-epochs, 6ce84a1c ("GPU: copy-backs skip pages remapped since their submission; new title memory is reported to the watch"). You are welcome to take any of it into #2612:

  • the XMemVirtualAlloc report;
  • the skip counter;
  • the two tests above, and no_submission (which also lets the two existing marked-page tests hold the submission lock while they set marks).

If you take them, please keep the credit our commit gives: the #1633 finding, and @⁠alessiodeia's rule from #2283 that every path removing a mapped view must move the epoch.

The title was not used in these tests.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 21:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7175658585) Thanks for this. We had been writing the same fix (per-page remap state checked by every copy-back) and will not open a competing PR. We ran #2612's head (d687c71f) on WARP with our own tests ported onto it, changing none of its code. Results below. **What it covers.** We checked each case with a test where another thread writes a byte and then reports the page through `title_memory_remapped` while the copy-back is pending: | case | result on d687c71f | |---|---| | declared range, snapshot path (`copy_back`) | covered: the remapped page keeps the new memory (passed) | | marked page whose bytes the title's first write saved (`copy_back_marks` → `copy_back_marked`) | covered: the remapped page keeps the new memory (passed) | | page at a computed address (`copy_back_page`) | covered: `copy_back_page` returns 0 and leaves the page alone (passed) | | controls: pages the title only wrote, or nobody wrote, still get the shaders' bytes | unchanged: all three get the shaders' bytes (passed) | | the next refresh takes the new memory | yes (passed) | | a submission that begins after the remap writes back as usual | yes (passed) | | #2612's own tests (`cargo test -p victory-gpu --features diagnostics --lib`, WARP) | all pass: 206 passed, 0 failed, 1 ignored (a release benchmark), with our two ported tests included | The mapping lock around `XMemMapPhysicalPages` and `map_alias` also closes the window between `MapViewOfFile3` and the report. Our version left that window open as a documented shortcut, so #2612 is the stronger of the two there. **What it leaves out.** 1. **`XMemVirtualAlloc` does not report new memory.** Suppose the title frees memory a copy holds with the host's `VirtualFree` (VIctory does not see that call) and then allocates at the same address with `XMemVirtualAlloc`. The tracker still holds the page as taken and guarded, but the new memory has no guard, so title writes there do not fault and are never copied. This is the same "remapped under a tracker" class, reached through allocation instead of a page mapping. On d687c71f, the test below shows the write is missed while unreported (passed: the unreported case asserts the miss). With the one-line report our branch adds to `XMemVirtualAlloc`, it is taken again and guarded again (passed; here the test makes the report itself, as `XMemVirtualAlloc` would). The change is in `crates/victory-hle/src/modules/xmem.rs` on our branch: `title_memory_remapped(at, end - at)` after a successful `VirtualAlloc2`. <details><summary>Repro: <code>memory_allocated_again_is_taken_again_once_reported</code> (watch.rs tests)</summary> ```rust /// Memory freed while a tracker holds it and allocated again at the same /// address (the title's `VirtualFree`, which we do not see, then /// `XMemVirtualAlloc`, which reports what it allocates as remapped): the /// new memory has no guard, so a write there does not fault. Reported, it /// is taken again and guarded again, so a later write counts; unreported, /// the write is missed. #[test] fn memory_allocated_again_is_taken_again_once_reported() { for report in [false, true] { // Another test may allocate at the address between the free and // the new allocation: then tried again elsewhere. let (p, t) = (0..8) .find_map(|_| { let p = pool(1); let t = track_copy(p, PAGE, true).expect("pool memory is tracked"); assert_eq!(t.take(p, p + PAGE), [(p, p + PAGE)]); free(p); // SAFETY: a fresh allocation where ours was, freed below. let again = unsafe { VirtualAlloc(p as *const _, PAGE, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE) } as usize; if again == p { return Some((p, t)); } if again != 0 { free(again); } None }) .expect("an address allocated again"); if report { title_memory_remapped(p, PAGE); } // SAFETY: our new allocation, read-write: no fault. unsafe { ((p + 8) as *mut u8).write_volatile(7) }; if !report { assert!(t.take(p, p + PAGE).is_empty(), "unreported, the write is missed"); drop(t); free(p); continue; } assert_eq!(t.take(p, p + PAGE), [(p, p + PAGE)], "the new memory is taken"); assert!(t.clean()); // SAFETY: as above, guarded again by the take: the handler opens it. unsafe { ((p + 9) as *mut u8).write_volatile(8) }; assert!(t.changed(p / PAGE), "a later write counts"); drop(t); free(p); } } ``` </details> 2. **Skips are not visible.** Remap skips in `copy_back_marked` and `copy_back_page` are counted as "the title wrote it" (`MarkedKept`, or the once-logged warning), and the snapshot-path skip is not counted at all. A title run therefore cannot tell how often this happens. Our branch counts every skip and prints the total on the diagnostics copy line (`N copy-back pages left alone for a remap (in all)`), plus one log line the first time. <details><summary>The six-page test used for the table (<code>pages_remapped_while_shaders_write_keep_the_new_memory</code>, shadow.rs tests; needs the small <code>host::tests::no_submission</code> helper so parallel tests do not take its marks)</summary> ```rust /// Ported from fork mem/remap-epochs 6ce84a1c (P-E), adapted to #2612's /// signatures (no submission epoch; no skip counter). A page the runtime /// remaps while shaders write its copy (another thread, during the GPU's /// run) keeps the new memory's bytes, whichever copy-back would have put /// the shaders' there: a declared range's snapshot, a marked page whose /// bytes the title's first write saved, a page at a computed address. /// Pages the title only wrote, or nobody, get the shaders' byte as /// before; a submission beginning after the remap writes back as usual. /// Every case is checked and the failures listed together. #[test] fn pages_remapped_while_shaders_write_keep_the_new_memory() { use crate::watch::title_memory_remapped; // Nothing else takes the marks set below. let _one = crate::host::tests::no_submission(); let p = crate::watch::tests::pool(6); let len = 6 * PAGE; register(p, p as u64, len as u64); let (Some(copy), Some(b)) = (find(p as u64, len as u64), bitmap(false)) else { unregister(p, p as u64); return; // no host GPU here }; let base = copy.marks.expect("tracked memory gets mark bits") as usize; // SAFETY: a byte of our pool. let read = |at: usize| unsafe { ((p + at) as *const u8).read_volatile() }; // The title writes a byte; with `remap`, the runtime then reports its // page as mapped anew. From another thread, as the title's. let title = |at: usize, value: u8, remap: bool| { std::thread::scope(|s| { s.spawn(|| { // SAFETY: a byte of our pool (a guard fault marks it). unsafe { ((p + at) as *mut u8).write_volatile(value) }; if remap { title_memory_remapped((p + at) & !(PAGE - 1), PAGE); } }); }); }; let mut failed: Vec<String> = Vec::new(); fn check(failed: &mut Vec<String>, case: &str, got: u8, want: u8) { if got != want { failed.push(format!("{case}: byte {got:#x}, expected {want:#x}")); } } copy.update(p, len); // Pages 0-1 declared (a snapshot), 2-3 marked (armed), 4-5 neither // (written at computed addresses). copy.writing(p, 2 * PAGE, false); copy.writing(p + 2 * PAGE, 2 * PAGE, true); // The shaders write a byte in each page. for k in 0..6 { copy.write_host((p + k * PAGE + 10) as u64, &[0xa0 + k as u8]); } // Meanwhile the title writes the same byte of each page but page 4, // and pages 1, 3 and 5 are remapped after (page 3 is armed: its // bytes from before the title's write are saved). for k in [0, 1, 2, 3, 5] { title(k * PAGE + 10, 0x50 + k as u8, k % 2 == 1); } let bits = b.data as *mut u32; for n in [base + 2, base + 3] { // SAFETY: a dword of the mapped bitmap. unsafe { *bits.add(n / 32) |= 1 << (n % 32) }; } copy_back_marks(&[], false); copy.copy_back(p, 2 * PAGE); copy.copy_back(p + 2 * PAGE, 2 * PAGE); let page4 = copy.copy_back_page(p + 4 * PAGE); let page5 = copy.copy_back_page(p + 5 * PAGE); if page4 != PAGE { failed.push(format!("computed address, nobody wrote: copy_back_page returned {page4}, expected {PAGE}")); } if page5 != 0 { failed.push(format!("computed address, remapped: copy_back_page returned {page5}, expected 0")); } check(&mut failed, "snapshot path, title wrote (control)", read(10), 0xa0); check(&mut failed, "snapshot path, remapped", read(PAGE + 10), 0x51); check(&mut failed, "marked page, title wrote (control)", read(2 * PAGE + 10), 0xa2); check(&mut failed, "marked page with saved bytes, remapped", read(3 * PAGE + 10), 0x53); check(&mut failed, "computed address, nobody wrote (control)", read(4 * PAGE + 10), 0xa4); check(&mut failed, "computed address, remapped", read(5 * PAGE + 10), 0x55); // The copy takes the new memory at its next refresh. let refreshed = copy.update(p, len); if refreshed < 3 * PAGE { failed.push(format!("next refresh copied {refreshed} bytes, expected at least {}", 3 * PAGE)); } check(&mut failed, "next refresh takes the new memory", copy.read_host((p + PAGE + 8) as u64, 1)[0].to_le_bytes()[2], 0x51); // A submission beginning after the remap writes back as usual. copy.writing(p, 2 * PAGE, false); copy.write_host((p + PAGE + 10) as u64, &[0xee]); copy.copy_back(p, 2 * PAGE); check(&mut failed, "a submission after the remap", read(PAGE + 10), 0xee); unregister(p, p as u64); assert!(failed.is_empty(), "{}", failed.join("; ")); } ``` </details> Our commit is on fork `r4tedx/VIctory`, branch `mem/remap-epochs`, 6ce84a1c ("GPU: copy-backs skip pages remapped since their submission; new title memory is reported to the watch"). You are welcome to take any of it into #2612: - the `XMemVirtualAlloc` report; - the skip counter; - the two tests above, and `no_submission` (which also lets the two existing marked-page tests hold the submission lock while they set marks). If you take them, please keep the credit our commit gives: the #1633 finding, and @⁠alessiodeia's rule from #2283 that every path removing a mapped view must move the epoch. The title was not used in these tests. AI-assisted
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:15 UTC · original · edited 2026-11-26 05:38 UTC

Automated triage for the maintainers.

Merge candidate. This closes a real race: a copy-back writing the GPU's stale bytes over title memory that was remapped while a submission was pending. It does this through watch::write_back (recheck of was_remapped under the MAPPING lock), Tracked::taken filtering remapped pages, and a title_memory_remapping() guard held in XMemMapPhysicalPages, map_alias and Upload::drop across the unmap and the report. The pause-and-remap tests in shadow.rs exercise both copy-back paths.

On your reply: both requested changes are in 8103a00. Shadow::copy_back_or_not calls main's merge_writeback again and gates only the write on write_back. Otherwise it matches main: written and synced on a successful write, synced without a write unless the page was remapped. Tracked::taken and watch::write_back now document that they lock MAPPING non-reentrantly and must not be reached while a Remapping guard is held.

For the maintainer: as commenters note, a free followed by reuse that is never reported to title_memory_remapped (XMemFreeDefault, XMemVirtualAlloc) is still open. It is addressed separately by #2824 and offered as commits on r4tedx's fork. This PR is the base those build on, and #3036 targets the same defect with weaker coverage.

CI: running at the time of this triage (check in progress on 8103a00). The previous head passed.

Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7176128510) · edited 2026-11-26 05:38 UTC <!-- victory-triage v1 head=8103a00e02590bc753a6be317e8a6be0d6cccaf7 verdict=merge-candidate at=2026-11-26T05:38:27Z --> Automated triage for the maintainers. **Merge candidate.** This closes a real race: a copy-back writing the GPU's stale bytes over title memory that was remapped while a submission was pending. It does this through `watch::write_back` (recheck of `was_remapped` under the `MAPPING` lock), `Tracked::taken` filtering remapped pages, and a `title_memory_remapping()` guard held in `XMemMapPhysicalPages`, `map_alias` and `Upload::drop` across the unmap and the report. The pause-and-remap tests in `shadow.rs` exercise both copy-back paths. On your reply: both requested changes are in `8103a00`. `Shadow::copy_back_or_not` calls main's `merge_writeback` again and gates only the write on `write_back`. Otherwise it matches main: written and synced on a successful write, synced without a write unless the page was remapped. `Tracked::taken` and `watch::write_back` now document that they lock `MAPPING` non-reentrantly and must not be reached while a `Remapping` guard is held. For the maintainer: as commenters note, a free followed by reuse that is never reported to `title_memory_remapped` (`XMemFreeDefault`, `XMemVirtualAlloc`) is still open. It is addressed separately by #2824 and offered as commits on r4tedx's fork. This PR is the base those build on, and #3036 targets the same defect with weaker coverage. CI: running at the time of this triage (`check` in progress on `8103a00`). The previous head passed. Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠pawrenity on GitHub · 2026-11-26 04:41 UTC · original

I compared this PR with #3036 (same defect, FIND-14) on an RTX 4070: #3036. In short, this PR is the stronger base. It tracks remaps per page and rechecks under the remap lock, and it passes the remap and release-without-free cases that #3036 fails. A free followed by reuse that is never reported to title_memory_remapped still writes stale bytes on all three copy-back paths. From reading, XMemFreeDefault and XMemVirtualAlloc don't report; having them report would close that through this PR's existing check, though I haven't tested that.

AI-assisted (Claude Code).

**@⁠pawrenity** on GitHub · 2026-11-26 04:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7182818069) I compared this PR with #3036 (same defect, FIND-14) on an RTX 4070: https://git.gtahub.st/github/Marvisak--VIctory/pulls/3036. In short, this PR is the stronger base. It tracks remaps per page and rechecks under the remap lock, and it passes the remap and release-without-free cases that #3036 fails. A free followed by reuse that is never reported to `title_memory_remapped` still writes stale bytes on all three copy-back paths. From reading, `XMemFreeDefault` and `XMemVirtualAlloc` don't report; having them report would close that through this PR's existing check, though I haven't tested that. AI-assisted (Claude Code).
Author
Owner

@⁠pawrenity on GitHub · 2026-11-26 04:45 UTC · original

Follow-up to my comparison above: the "free followed by reuse that is never reported" gap is the subject of open PR #2824. It makes XMemFreeDefault's 32-bit branch release through a new victory_gpu::release_title_allocation that clears stale guarded pages and reports the remap, and XMemAllocDefault reports new 32-bit allocations. With #2824, an XMemFree-then-reuse goes through this PR's remap check. The 64-bit heap branch rightly reports nothing: heap memory has no trackers, and its pages are shared with live neighbours. What stays open after both, from reading only: a range from XMemVirtualAlloc that the title releases with the host's own VirtualFree, which xmem never sees (a hook like #2921's would be needed). So the FIND-14 set looks like #2612 + #2824, with #3036's test carried over.

AI-assisted (Claude Code).

**@⁠pawrenity** on GitHub · 2026-11-26 04:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7182871903) Follow-up to my comparison above: the "free followed by reuse that is never reported" gap is the subject of open PR #2824. It makes `XMemFreeDefault`'s 32-bit branch release through a new `victory_gpu::release_title_allocation` that clears stale guarded pages and reports the remap, and `XMemAllocDefault` reports new 32-bit allocations. With #2824, an `XMemFree`-then-reuse goes through this PR's remap check. The 64-bit heap branch rightly reports nothing: heap memory has no trackers, and its pages are shared with live neighbours. What stays open after both, from reading only: a range from `XMemVirtualAlloc` that the title releases with the host's own `VirtualFree`, which xmem never sees (a hook like #2921's would be needed). So the FIND-14 set looks like #2612 + #2824, with #3036's test carried over. AI-assisted (Claude Code).
Author
Owner

@⁠ashrafsdrop on GitHub · 2026-11-26 04:49 UTC · original

Addressed the triage feedback in e35dc8b:

  1. Restored merge_writeback: Shadow::copy_back_or_not now calls merge_writeback(title, host, old) directly, gating the write_mapped write on watch::write_back.
  2. Documented non-reentrant lock invariant: Added doc comments to Tracked::taken and watch::write_back stating that both lock MAPPING non-reentrantly and must not be called while holding a Remapping guard.

Verification

  • cargo test -p victory-gpu --lib watch: 16 passed, 0 failed
  • cargo test -p victory-gpu --lib shadow: 16 passed, 0 failed
  • cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings: clean
  • cargo run -p xtask -- policy: asset policy: 191 files ok
**@⁠ashrafsdrop** on GitHub · 2026-11-26 04:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7182938881) Addressed the triage feedback in [`e35dc8b`](https://github.com/ashrafsdrop/VIctory/commit/e35dc8b): 1. **Restored `merge_writeback`**: `Shadow::copy_back_or_not` now calls `merge_writeback(title, host, old)` directly, gating the `write_mapped` write on `watch::write_back`. 2. **Documented non-reentrant lock invariant**: Added doc comments to `Tracked::taken` and `watch::write_back` stating that both lock `MAPPING` non-reentrantly and must not be called while holding a `Remapping` guard. ### Verification - `cargo test -p victory-gpu --lib watch`: 16 passed, 0 failed - `cargo test -p victory-gpu --lib shadow`: 16 passed, 0 failed - `cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings`: clean - `cargo run -p xtask -- policy`: asset policy: 191 files ok
Author
Owner

@⁠r4tedx on GitHub · 2026-11-26 05:02 UTC · original

Thanks @⁠pawrenity for the side-by-side with #3036. It pins down the remaining gap: a free followed by reuse that nobody reports.

The free path that needed a report is XMemFreeDefault (xmem.rs:334). It is reached directly, or through XMemFree when the title has no allocation hook, and committed resources free their memory through it too. Neither of its two paths reported anything:

  • the heap path's freed block can come back from the next XMemAllocDefault;
  • the 32-bit reservation can come back from the next XMemVirtualAlloc.

The other paths need no change, or cannot get one. XMemFreePhysicalPages never hands pages out again, and unmap already reports. The host's VirtualFree / NtFreeVirtualMemory and a title's own allocator hook are not seen.

Offer: fork r4tedx/VIctory, branch mem/2612-free-report, two commits on your head 8a998fcf (they also merge cleanly onto 8103a00e, your merge_writeback restore):

  1. e23b47ae: XMemFreeDefault calls title_memory_remapped before it frees, under title_memory_remapping() (as Upload::drop does). It reports the 32-bit reservation whole. For a heap block it reports only the host pages the block fills, so live neighbours on its edge pages keep their copy-backs and frees inside one page cost nothing. Tests:
    • freed_memory_is_reported_to_the_gpu_side (xmem) checks the ranges reported.
    • memory_freed_and_allocated_again_keeps_the_new_bytes_once_reported (shadow) is your R1–R3 in one test: snapshot, marked and computed-address pages, freed and allocated again at the same address. Reported, all three keep the title's 0xEE. Unreported, all three get the shaders' 0x99 (the test's control).
    • With the report removed, both tests fail.
  2. c9feb1d4: the XMemVirtualAlloc report from our earlier offer, with its test.

Results on WARP (--features diagnostics, --test-threads 1): victory-gpu lib 254 passed, 0 failed, 1 ignored; victory-hle xmem 15 passed; clippy -D warnings clean with and without diagnostics.

Credit runs both ways. #2612's per-page check and mapping lock do the work; these commits only give them two more reports. If you take them, please keep the credit from our earlier P-E offer: the #1633 finding, and @⁠alessiodeia's rule from #2283 that every path that removes mapped memory must move the epoch.

The title was not used in these tests.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-26 05:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7183130752) Thanks @⁠pawrenity for the side-by-side with #3036. It pins down the remaining gap: a free followed by reuse that nobody reports. **The free path that needed a report is `XMemFreeDefault`** (`xmem.rs:334`). It is reached directly, or through `XMemFree` when the title has no allocation hook, and committed resources free their memory through it too. Neither of its two paths reported anything: - the heap path's freed block can come back from the next `XMemAllocDefault`; - the 32-bit reservation can come back from the next `XMemVirtualAlloc`. The other paths need no change, or cannot get one. `XMemFreePhysicalPages` never hands pages out again, and `unmap` already reports. The host's `VirtualFree` / `NtFreeVirtualMemory` and a title's own allocator hook are not seen. **Offer: fork `r4tedx/VIctory`, branch `mem/2612-free-report`**, two commits on your head 8a998fcf (they also merge cleanly onto 8103a00e, your `merge_writeback` restore): 1. `e23b47ae`: `XMemFreeDefault` calls `title_memory_remapped` before it frees, under `title_memory_remapping()` (as `Upload::drop` does). It reports the 32-bit reservation whole. For a heap block it reports only the host pages the block fills, so live neighbours on its edge pages keep their copy-backs and frees inside one page cost nothing. Tests: - `freed_memory_is_reported_to_the_gpu_side` (xmem) checks the ranges reported. - `memory_freed_and_allocated_again_keeps_the_new_bytes_once_reported` (shadow) is your R1–R3 in one test: snapshot, marked and computed-address pages, freed and allocated again at the same address. Reported, all three keep the title's `0xEE`. Unreported, all three get the shaders' `0x99` (the test's control). - With the report removed, both tests fail. 2. `c9feb1d4`: the `XMemVirtualAlloc` report from our earlier offer, with its test. Results on WARP (`--features diagnostics`, `--test-threads 1`): victory-gpu lib 254 passed, 0 failed, 1 ignored; victory-hle xmem 15 passed; clippy `-D warnings` clean with and without `diagnostics`. Credit runs both ways. #2612's per-page check and mapping lock do the work; these commits only give them two more reports. If you take them, please keep the credit from our earlier P-E offer: the #1633 finding, and @⁠alessiodeia's rule from #2283 that every path that removes mapped memory must move the epoch. The title was not used in these tests. AI-assisted
Author
Owner

@⁠ashrafsdrop on GitHub · 2026-11-26 05:17 UTC · original · edited 2026-11-26 05:25 UTC

Thanks @⁠r4tedx and @⁠pawrenity. Cherry-picked both commits cleanly onto the PR branch:

  1. cd60351 (e23b47a): XMemFreeDefault reports freed memory under title_memory_remapping() before release, including the xmem range check and shadow remap-after-free regression test.
  2. 540d2d4 (c9feb1d): XMemVirtualAlloc reports allocated virtual ranges so trackers and guards reset.

Full credit preserved: author attribution retained on both commits, crediting the #1633 finding, and @⁠alessiodeia's rule from #2283 that every path that removes mapped memory must move the epoch.

Local verification:

  • cargo test -p victory-hle xmem: 15 passed, 0 failed.
  • cargo test -p victory-gpu --lib shadow: 17 passed, 0 failed.
  • cargo clippy -p victory-gpu -p victory-hle --all-targets --locked -- -D warnings: clean.
  • cargo run -p xtask -- policy: 191 files ok.
**@⁠ashrafsdrop** on GitHub · 2026-11-26 05:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7183349816) · edited 2026-11-26 05:25 UTC Thanks @⁠r4tedx and @⁠pawrenity. Cherry-picked both commits cleanly onto the PR branch: 1. `cd60351` (`e23b47a`): `XMemFreeDefault` reports freed memory under `title_memory_remapping()` before release, including the xmem range check and shadow remap-after-free regression test. 2. `540d2d4` (`c9feb1d`): `XMemVirtualAlloc` reports allocated virtual ranges so trackers and guards reset. Full credit preserved: author attribution retained on both commits, crediting the #1633 finding, and @⁠alessiodeia's rule from #2283 that every path that removes mapped memory must move the epoch. Local verification: - `cargo test -p victory-hle xmem`: 15 passed, 0 failed. - `cargo test -p victory-gpu --lib shadow`: 17 passed, 0 failed. - `cargo clippy -p victory-gpu -p victory-hle --all-targets --locked -- -D warnings`: clean. - `cargo run -p xtask -- policy`: 191 files ok.
Author
Owner

@⁠HoLa-Lee on GitHub · 2026-11-26 06:19 UTC · original

A test this PR does not have, and that fails on it: the release-and-re-take case.

title_memory_remapped covers the reported remaps. It does not cover the title
releasing a range and taking the same addresses again - which is what watch.rs
calls out ("memory freed and allocated again while a tracker holds it is not
seen"). I wrote the deterministic test for it while working FIND-14, and it fails
on this PR's head:

# on 4f47bdc, with the test below added to shadow.rs's test module
cargo test -p victory-gpu --lib --profile diag --features diagnostics \
  -- --exact shadow::tests::a_pending_copy_back_does_not_write_into_memory_the_title_took_back
left: 153   (0x99 - what the shader wrote for a submission that is over)
right: 238  (0xEE - what the title's next use of the address held)

What it does: register a page of title memory, take the submission's snapshot,
let a shader write one byte into the copy, then unregister + VirtualFree the
range, take the same addresses again with VirtualAlloc filled with 0xEE, and
run the copy-back. No game, no GPU work beyond the register, and it observes only
when the allocator hands the same address back (it says so and returns when it
does not).

Two things I am not saying: that this is the same report as FIND-14's
remap case (it is a different trigger), or that this PR is wrong. This PR is the
right shape - it hooks the runtime's own signal instead of guessing - and the
suggestion is only that the same treatment is needed on the free side:
Memory's Drop (committed resources and heaps) and the upload block's Drop
before VirtualFree are where the addresses really go away, which is also what
@⁠Machad3x describes in #3036.

The test is yours to take as-is or to adapt; I am closing #3036 and not pushing a
second fix for the same finding. If you would rather I open it as a separate
"test only" PR against main so it can land beside yours, say which and I will.

**@⁠HoLa-Lee** on GitHub · 2026-11-26 06:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7184310591) **A test this PR does not have, and that fails on it: the release-and-re-take case.** `title_memory_remapped` covers the reported remaps. It does not cover the title **releasing** a range and taking the same addresses again - which is what `watch.rs` calls out ("memory freed and allocated again while a tracker holds it is not seen"). I wrote the deterministic test for it while working FIND-14, and it fails on this PR's head: ``` # on 4f47bdc, with the test below added to shadow.rs's test module cargo test -p victory-gpu --lib --profile diag --features diagnostics \ -- --exact shadow::tests::a_pending_copy_back_does_not_write_into_memory_the_title_took_back left: 153 (0x99 - what the shader wrote for a submission that is over) right: 238 (0xEE - what the title's next use of the address held) ``` What it does: register a page of title memory, take the submission's snapshot, let a shader write one byte into the copy, then `unregister` + `VirtualFree` the range, take the same addresses again with `VirtualAlloc` filled with `0xEE`, and run the copy-back. No game, no GPU work beyond the register, and it observes only when the allocator hands the same address back (it says so and returns when it does not). Two things I am **not** saying: that this is the same report as FIND-14's remap case (it is a different trigger), or that this PR is wrong. This PR is the right shape - it hooks the runtime's own signal instead of guessing - and the suggestion is only that the same treatment is needed on the free side: `Memory`'s `Drop` (committed resources and heaps) and the upload block's `Drop` before `VirtualFree` are where the addresses really go away, which is also what @⁠Machad3x describes in #3036. The test is yours to take as-is or to adapt; I am closing #3036 and not pushing a second fix for the same finding. If you would rather I open it as a separate "test only" PR against `main` so it can land beside yours, say which and I will.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-26 06:36 UTC · original

Thanks @⁠HoLa-Lee for the test. It caught a mistake of ours.

Our earlier comment was wrong. We wrote that committed resources free their memory through XMemFreeDefault, and that its heap-block report covers them. Neither is right:

  • Where the memory goes back (on 4f47bdc). Memory's Drop (resource.rs:688) goes through XMemFree → XMemFreeDefault only for a committed resource served by the runtime's allocator, and only when the title has no allocation hook. Heaps (resource.rs:728), descriptor heaps (descriptor.rs:768) and the fallback path free with dealloc directly (resource.rs:693). The upload block's Drop already reports before its VirtualFree (list.rs:1308).
  • Why a report there does nothing. That memory is all host heap, and the watch tracks only the runtime's write-watched pools and page views (watch.rs, runtime_pages). No tracker holds heap memory, so title_memory_remapped records nothing for it, and the copy-back has nothing to check.
    • The heap-block report in our XMemFreeDefault commit (bea9ae4f here) therefore reaches no copy.
    • We ported your test with the range freed through Memory's Drop (a 1 MiB block, so the heap gives it back to the system and the same address can be taken again), and added a report in that Drop. It still gets 153.

What does pass. Your test as written frees with the host's bare VirtualFree and VirtualAlloc, which nothing in VIctory sees, and it fails on our branch too (153). When the addresses are taken back through XMemVirtualAlloc, which reports what it allocates (4f47bdc), the copy-back leaves the new memory alone (238).

Branch mem/2612-free-report-2 on fork r4tedx/VIctory, on your head 4f47bdc:

  • 36541fab: XMemFreeDefault reports only its 32-bit blocks, which XMemVirtualAlloc write-watches. The heap-block report goes, and its doc states the heap gap.
  • 6641ced0: your test, credited, with the addresses taken back through XMemVirtualAlloc's report.

Results on WARP (--features diagnostics, --test-threads 1): victory-gpu lib 255 passed, 0 failed, 1 ignored; victory-hle xmem 15 passed; clippy -D warnings clean with and without diagnostics.

Closing the heap case needs remap state that copies without a tracker can check, and it has to reach copies that are already unregistered but still held by pending lists. We can write that if you want it here or as a follow-up.

The title was not used in these tests.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-26 06:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7184603905) Thanks @⁠HoLa-Lee for the test. It caught a mistake of ours. **Our earlier comment was wrong.** We wrote that committed resources free their memory through `XMemFreeDefault`, and that its heap-block report covers them. Neither is right: - **Where the memory goes back (on 4f47bdc).** `Memory`'s `Drop` (`resource.rs:688`) goes through `XMemFree` → `XMemFreeDefault` only for a committed resource served by the runtime's allocator, and only when the title has no allocation hook. Heaps (`resource.rs:728`), descriptor heaps (`descriptor.rs:768`) and the fallback path free with `dealloc` directly (`resource.rs:693`). The upload block's `Drop` already reports before its `VirtualFree` (`list.rs:1308`). - **Why a report there does nothing.** That memory is all host heap, and the watch tracks only the runtime's write-watched pools and page views (`watch.rs`, `runtime_pages`). No tracker holds heap memory, so `title_memory_remapped` records nothing for it, and the copy-back has nothing to check. - The heap-block report in our `XMemFreeDefault` commit (bea9ae4f here) therefore reaches no copy. - We ported your test with the range freed through `Memory`'s `Drop` (a 1 MiB block, so the heap gives it back to the system and the same address can be taken again), and added a report in that `Drop`. It still gets `153`. **What does pass.** Your test as written frees with the host's bare `VirtualFree` and `VirtualAlloc`, which nothing in VIctory sees, and it fails on our branch too (`153`). When the addresses are taken back through `XMemVirtualAlloc`, which reports what it allocates (4f47bdc), the copy-back leaves the new memory alone (`238`). **Branch `mem/2612-free-report-2`** on fork `r4tedx/VIctory`, on your head 4f47bdc: - `36541fab`: `XMemFreeDefault` reports only its 32-bit blocks, which `XMemVirtualAlloc` write-watches. The heap-block report goes, and its doc states the heap gap. - `6641ced0`: your test, credited, with the addresses taken back through `XMemVirtualAlloc`'s report. Results on WARP (`--features diagnostics`, `--test-threads 1`): victory-gpu lib 255 passed, 0 failed, 1 ignored; victory-hle xmem 15 passed; clippy `-D warnings` clean with and without `diagnostics`. Closing the heap case needs remap state that copies without a tracker can check, and it has to reach copies that are already unregistered but still held by pending lists. We can write that if you want it here or as a follow-up. The title was not used in these tests. AI-assisted
Author
Owner

@⁠HoLa-Lee on GitHub · 2026-11-26 06:47 UTC · original

As offered above, the test now exists as its own PR so it can land beside yours rather than only in a comment: #3077 (test only, #[ignore]d, +60 lines in shadow.rs's test module, no production change).

It is the _pending_copy_back_does_not_write_into_memory_the_title_took_back test verbatim, and it fails on this PR's head 4f47bdc the same way it fails on main - ␀x99 landing in the ␀xEE the title's next allocation holds. Whoever adds the free-side hook (as @⁠Machad3x describes) deletes the #[ignore] and it turns green.

Nothing to do on your side unless you want the file: if you would rather carry the test inside #2612, say so and I will close #3077 - the fix belongs there either way.

**@⁠HoLa-Lee** on GitHub · 2026-11-26 06:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7184785243) As offered above, the test now exists as its own PR so it can land beside yours rather than only in a comment: **https://git.gtahub.st/github/Marvisak--VIctory/pulls/3077** (test only, #[ignore]d, +60 lines in shadow.rs's test module, no production change). It is the _pending_copy_back_does_not_write_into_memory_the_title_took_back test verbatim, and it fails on this PR's head 4f47bdc the same way it fails on main - ␀x99 landing in the ␀xEE the title's next allocation holds. Whoever adds the free-side hook (as @⁠Machad3x describes) deletes the #[ignore] and it turns green. Nothing to do on your side unless you want the file: if you would rather carry the test inside #2612, say so and I will close #3077 - the fix belongs there either way.
Author
Owner

@⁠alessiodeia on GitHub · 2026-11-26 12:27 UTC · original

Thanks @⁠r4tedx and @⁠ashrafsdrop for carrying the #2283 rule over, and for keeping the credit.

A coordination note, since this PR and #2283 touch the same spot. Each merges cleanly onto current main on its own. Together they conflict in two trivial places:

  • the pub use watch::{…} list in lib.rs;
  • the lines next to title_memory_remapped in watch.rs, where #2283 adds REMAP_EPOCH and title_memory_unmapped.

Whichever of the two lands second, I'll rebase #2283 on top. If this one goes in first, the result is consistent by construction. #2283 moves the epoch inside title_memory_remapped, so the new XMemFreeDefault and XMemVirtualAlloc reports move it too, with no extra change.

On "after the release" for those two new paths: #2283 caches a range as committed only when it consists entirely of MEM_MAPPED views. Memory freed through XMemFreeDefault or newly allocated by XMemVirtualAlloc is private memory, so it is never cached and is asked again on every refresh. Your report before the release is therefore enough for #2283. The second bump after the operation, like title_memory_unmapped after UnmapViewOfFile2, is needed only where a mapped view goes away.

**@⁠alessiodeia** on GitHub · 2026-11-26 12:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7192021298) Thanks @⁠r4tedx and @⁠ashrafsdrop for carrying the #2283 rule over, and for keeping the credit. A coordination note, since this PR and #2283 touch the same spot. Each merges cleanly onto current `main` on its own. Together they conflict in two trivial places: - the `pub use watch::{…}` list in `lib.rs`; - the lines next to `title_memory_remapped` in `watch.rs`, where #2283 adds `REMAP_EPOCH` and `title_memory_unmapped`. Whichever of the two lands second, I'll rebase #2283 on top. If this one goes in first, the result is consistent by construction. #2283 moves the epoch inside `title_memory_remapped`, so the new `XMemFreeDefault` and `XMemVirtualAlloc` reports move it too, with no extra change. On "after the release" for those two new paths: #2283 caches a range as committed only when it consists entirely of `MEM_MAPPED` views. Memory freed through `XMemFreeDefault` or newly allocated by `XMemVirtualAlloc` is private memory, so it is never cached and is asked again on every refresh. Your report before the release is therefore enough for #2283. The second bump after the operation, like `title_memory_unmapped` after `UnmapViewOfFile2`, is needed only where a mapped view goes away.
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 16:57 UTC · original · requested changes

In copy_back_or_not, was_remapped can return false and the page can then be remapped before write_mapped. The write still targets the same virtual address, so it can land in the replacement mapping.

copy_back_marked has a similar window. t.saved() takes ownership of the old snapshot. Once that happens, a remap that clears the tracker can’t invalidate the snapshot already in use.

Could the final copy-back write and the actual mapping change share synchronization? A regression test that pauses copy-back after the check, remaps the page, then resumes would exercise the window the current tests miss.

Static review only.

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-25 16:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#pullrequestreview-6061618718) · **requested changes** In `copy_back_or_not`, `was_remapped` can return false and the page can then be remapped before `write_mapped`. The write still targets the same virtual address, so it can land in the replacement mapping. `copy_back_marked` has a similar window. `t.saved()` takes ownership of the old snapshot. Once that happens, a remap that clears the tracker can’t invalidate the snapshot already in use. Could the final copy-back write and the actual mapping change share synchronization? A regression test that pauses copy-back after the check, remaps the page, then resumes would exercise the window the current tests miss. Static review only. *AI-assisted with Codex.*
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 17:07 UTC · original · approved these changes

**@⁠DrDarkDK** on GitHub · 2026-11-25 17:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#pullrequestreview-6061765888) · **approved these changes**
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 14:28 UTC · original · requested changes

Reviewed 4f47bdcf109aa9e38576e4a684ea6e8dc0aab040 (base 63bcca43c6a0) and tested on Windows 11 x64 (NVIDIA GeForce RTX 5090 + Microsoft WARP, VICTORY_D3D12_DEBUG=1, Rust 1.98.1).

The lock ordering (Host::submitted -> Shadow::before -> MAPPING -> GUARDS -> Changed.{0,1} and PHYSICAL -> MAPPING -> GUARDS -> Changed.{0,1}), !Send Remapping guard, and #[cfg(windows)] module scoping for xmem all look sound, and the existing tests pass (victory-hle xmem::: 15/15; victory-gpu watch:: shadow:: list::: 37/37 on RTX 5090, RTX 5090 + Debug Layer, and WARP + diagnostics + Debug Layer; clippy clean on default and --all-features).

However, there is a blocking correctness regression on valid copy-backs after a prior remap, plus two issues in xmem.rs that should be cleaned up before merge:

1. Blocking: Stale Saved::remapped silently drops valid partial-page unmarked GPU copy-backs after a prior remap (crates/victory-gpu/src/watch.rs:120,167,566,893,913, crates/victory-gpu/src/shadow.rs:444-450,460)

title_memory_remapped records page in Saved::remapped unconditionally—even when no submission is pending—and Saved::remapped is only cleared by whole-page Changed::taken(page) or end-of-submission Tracked::disarm().

In production, unmarked declared UAV paths (draw.rs:216-221 root UAVs, draw.rs:882-885 title-memory root UAVs, and draw.rs:1904-1912 unmarked descriptor-table UAVs) refresh and snapshot their exact (address, len) rather than expanding to page_range. When a 64 KiB page inside a persistent tracked Shadow (e.g., a GPU heap) is remapped before submission S1 starts (via XMemMapPhysicalPages, map_alias, or XMemVirtualAlloc), and S1 writes a sub-64 KiB or unaligned range inside that page:

  1. copy.update(p + 0x1000, 0x1000) copies the fresh post-remap title bytes into the shadow buffer, but Tracked::take_split leaves whole empty for the partial page, so Changed::taken is not called and Saved::remapped still retains p / PAGE.
  2. copy.writing(p + 0x1000, 0x1000, false) snapshots the fresh post-remap bytes into self.before, and the GPU writes valid output (with zero remaps during S1).
  3. copy.copy_back(p + 0x1000, 0x1000) hits t.was_remapped((start + at) / PAGE) at shadow.rs:447 (and watch::write_back at watch.rs:899) and returns 0, silently discarding S1's valid GPU writes.

Deterministic reproducer verified on both RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1):

let p = crate::watch::tests::pool(2);
let len = 2 * PAGE;
register(p, p as u64, len as u64);
let copy = find(p as u64, len as u64).unwrap();
copy.update(p, len);

// Remap happens BEFORE S1 starts, then title initializes [p + 0x1000, p + 0x2000).
crate::watch::title_memory_remapped(p, PAGE);
unsafe { ((p + 0x1000) as *mut u8).write_bytes(0x11, 0x1000) };

// S1: unmarked declared partial-page UAV (no remap occurs during S1).
copy.update(p + 0x1000, 0x1000);
copy.writing(p + 0x1000, 0x1000, false);
copy.write_host((p + 0x1000) as u64, &[0xCC]);
let written = copy.copy_back(p + 0x1000, 0x1000);
let got = unsafe { ((p + 0x1000) as *const u8).read_volatile() };
  • origin/main (63bcca43): copied=4096 written=4096 title_byte=0xcc (both RTX 5090 and WARP).
  • PR #2612 (4f47bdcf): copied=4096 written=0 title_byte=0x11 (both RTX 5090 and WARP — valid GPU write completely dropped).

Scoping remap invalidation to remaps that occur after the refresh/snapshot begins (for example, tracking a per-page or global remap epoch captured before copying/snapshotting and comparing it under MAPPING in write_back / taken, rather than a sticky pre-submission BTreeSet only cleared on whole-page taken) fixes this cleanly without reopening the in-flight remap window.

2. XMemFreeDefault heap-block branch mixes HOST_PAGE = 4 KiB with watch::PAGE = 64 KiB (crates/victory-hle/src/modules/xmem.rs:364-376,383)

xmem.rs:383 defines const HOST_PAGE: usize = 4 << 10; with the comment "the GPU side's unit of change tracking", whereas watch::PAGE is 64 << 10 (64 KiB) and title_memory_remapped rounds [at, at + len) outward to 64 KiB pages. As noted earlier in the thread, std::alloc heap allocations are untracked MEM_COMMIT | MEM_PRIVATE memory anyway—so this branch takes the global MAPPING and GUARDS locks across dealloc() on every >= 8 KiB heap free for no benefit, and if a tracker ever did span a page via runtime_pages's reserved-region shortcut, freeing a 4–8 KiB heap block would wrongly mark the entire enclosing 64 KiB page (and any live neighbors in it) remapped. Removing the non-32-bit heap-block report and keeping only the write-watched 32-bit reservation path avoids both issues.

3. Minor race window in XMemVirtualAlloc (crates/victory-hle/src/modules/xmem.rs:175-181)

Unlike XMemFreeDefault, Upload::drop, XMemMapPhysicalPages, and map_alias, XMemVirtualAlloc calls title_memory_remapped after VirtualAlloc2 without holding title_memory_remapping() across the allocation and notification. If the title freed a range via unintercepted VirtualFree and immediately re-allocated the same address via XMemVirtualAlloc, a pending copy-back can write stale GPU bytes into the newly zero-initialized pages between VirtualAlloc2 and title_memory_remapped before XMemVirtualAlloc returns.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 14:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#pullrequestreview-6075833255) · **requested changes** Reviewed `4f47bdcf109aa9e38576e4a684ea6e8dc0aab040` (base `63bcca43c6a0`) and tested on Windows 11 x64 (NVIDIA GeForce RTX 5090 + Microsoft WARP, `VICTORY_D3D12_DEBUG=1`, Rust `1.98.1`). The lock ordering (`Host::submitted -> Shadow::before -> MAPPING -> GUARDS -> Changed.{0,1}` and `PHYSICAL -> MAPPING -> GUARDS -> Changed.{0,1}`), `!Send` `Remapping` guard, and `#[cfg(windows)]` module scoping for `xmem` all look sound, and the existing tests pass (`victory-hle` `xmem::`: 15/15; `victory-gpu` `watch:: shadow:: list::`: 37/37 on RTX 5090, RTX 5090 + Debug Layer, and WARP + `diagnostics` + Debug Layer; clippy clean on default and `--all-features`). However, there is a **blocking correctness regression** on valid copy-backs after a prior remap, plus two issues in `xmem.rs` that should be cleaned up before merge: ### 1. Blocking: Stale `Saved::remapped` silently drops valid partial-page unmarked GPU copy-backs after a prior remap (`crates/victory-gpu/src/watch.rs:120,167,566,893,913`, `crates/victory-gpu/src/shadow.rs:444-450,460`) `title_memory_remapped` records `page` in `Saved::remapped` unconditionally—even when no submission is pending—and `Saved::remapped` is only cleared by whole-page `Changed::taken(page)` or end-of-submission `Tracked::disarm()`. In production, unmarked declared UAV paths (`draw.rs:216-221` root UAVs, `draw.rs:882-885` title-memory root UAVs, and `draw.rs:1904-1912` unmarked descriptor-table UAVs) refresh and snapshot their exact `(address, len)` rather than expanding to `page_range`. When a 64 KiB page inside a persistent tracked `Shadow` (e.g., a GPU heap) is remapped **before** submission `S1` starts (via `XMemMapPhysicalPages`, `map_alias`, or `XMemVirtualAlloc`), and `S1` writes a sub-64 KiB or unaligned range inside that page: 1. `copy.update(p + 0x1000, 0x1000)` copies the fresh post-remap title bytes into the shadow buffer, but `Tracked::take_split` leaves `whole` empty for the partial page, so `Changed::taken` is **not** called and `Saved::remapped` still retains `p / PAGE`. 2. `copy.writing(p + 0x1000, 0x1000, false)` snapshots the fresh post-remap bytes into `self.before`, and the GPU writes valid output (with zero remaps during `S1`). 3. `copy.copy_back(p + 0x1000, 0x1000)` hits `t.was_remapped((start + at) / PAGE)` at `shadow.rs:447` (and `watch::write_back` at `watch.rs:899`) and returns `0`, silently discarding `S1`'s valid GPU writes. **Deterministic reproducer verified on both RTX 5090 and WARP (`VICTORY_D3D12_DEBUG=1`):** ```rust let p = crate::watch::tests::pool(2); let len = 2 * PAGE; register(p, p as u64, len as u64); let copy = find(p as u64, len as u64).unwrap(); copy.update(p, len); // Remap happens BEFORE S1 starts, then title initializes [p + 0x1000, p + 0x2000). crate::watch::title_memory_remapped(p, PAGE); unsafe { ((p + 0x1000) as *mut u8).write_bytes(0x11, 0x1000) }; // S1: unmarked declared partial-page UAV (no remap occurs during S1). copy.update(p + 0x1000, 0x1000); copy.writing(p + 0x1000, 0x1000, false); copy.write_host((p + 0x1000) as u64, &[0xCC]); let written = copy.copy_back(p + 0x1000, 0x1000); let got = unsafe { ((p + 0x1000) as *const u8).read_volatile() }; ``` - `origin/main` (`63bcca43`): `copied=4096 written=4096 title_byte=0xcc` (both RTX 5090 and WARP). - PR `#2612` (`4f47bdcf`): `copied=4096 written=0 title_byte=0x11` (both RTX 5090 and WARP — valid GPU write completely dropped). Scoping remap invalidation to remaps that occur *after* the refresh/snapshot begins (for example, tracking a per-page or global remap epoch captured before copying/snapshotting and comparing it under `MAPPING` in `write_back` / `taken`, rather than a sticky pre-submission `BTreeSet` only cleared on whole-page `taken`) fixes this cleanly without reopening the in-flight remap window. ### 2. `XMemFreeDefault` heap-block branch mixes `HOST_PAGE = 4 KiB` with `watch::PAGE = 64 KiB` (`crates/victory-hle/src/modules/xmem.rs:364-376,383`) `xmem.rs:383` defines `const HOST_PAGE: usize = 4 << 10;` with the comment *"the GPU side's unit of change tracking"*, whereas `watch::PAGE` is `64 << 10` (64 KiB) and `title_memory_remapped` rounds `[at, at + len)` outward to 64 KiB pages. As noted earlier in the thread, `std::alloc` heap allocations are untracked `MEM_COMMIT | MEM_PRIVATE` memory anyway—so this branch takes the global `MAPPING` and `GUARDS` locks across `dealloc()` on every `>= 8 KiB` heap free for no benefit, and if a tracker ever did span a page via `runtime_pages`'s reserved-region shortcut, freeing a 4–8 KiB heap block would wrongly mark the entire enclosing 64 KiB page (and any live neighbors in it) remapped. Removing the non-32-bit heap-block report and keeping only the write-watched 32-bit reservation path avoids both issues. ### 3. Minor race window in `XMemVirtualAlloc` (`crates/victory-hle/src/modules/xmem.rs:175-181`) Unlike `XMemFreeDefault`, `Upload::drop`, `XMemMapPhysicalPages`, and `map_alias`, `XMemVirtualAlloc` calls `title_memory_remapped` after `VirtualAlloc2` without holding `title_memory_remapping()` across the allocation and notification. If the title freed a range via unintercepted `VirtualFree` and immediately re-allocated the same address via `XMemVirtualAlloc`, a pending copy-back can write stale GPU bytes into the newly zero-initialized pages between `VirtualAlloc2` and `title_memory_remapped` before `XMemVirtualAlloc` returns.
A prior remap occurring before a submission starts must not drop valid
partial-page unmarked GPU copy-backs (e.g. root UAVs) whose ranges do
not span whole 64 KiB pages and thus never take Changed::taken. Track an
atomic REMAP_EPOCH counter in watch.rs, map remapped pages to the epoch
at which they were remapped, and capture the current epoch at snapshot
time in Shadow::writing and Shadow::update. write_back and Tracked::taken
only skip pages remapped since that snapshot epoch, keeping valid GPU writes
intact after prior remaps while preserving synchronization against concurrent
remaps.

In xmem.rs, remove the 4 KiB heap-block reporting loop in XMemFreeDefault
(host heap memory is untracked MEM_PRIVATE memory) and hold
victory_gpu::title_memory_remapping() across VirtualAlloc2 and
title_memory_remapped in XMemVirtualAlloc.

Added unit test in shadow.rs:
shadow::tests::unmarked_partial_page_copy_back_after_prior_remap_keeps_gpu_bytes
Author
Owner

@⁠ashrafsdrop on GitHub · 2026-11-26 15:33 UTC · original

Addressed in c697424 — excellent review and catch on the partial-page UAV window, @⁠fuzeofficlal.

Changes

  1. Epoch-scoped remap invalidation (crates/victory-gpu/src/watch.rs, crates/victory-gpu/src/shadow.rs):
    • Added an atomic REMAP_EPOCH counter in watch.rs.
    • title_memory_remapped increments the epoch under title_memory_remapping(), and Saved::remapped records page -> remap_epoch (HashMap<usize, u64>).
    • Shadow::writing records the current epoch alongside snapshot segments (start, bytes, epoch), and Shadow tracks refreshed_epoch from Shadow::update.
    • Tracked::was_remapped_since(page, since_epoch) checks if a remap happened after that snapshot/refresh epoch. watch::write_back and Tracked::taken re-verify under MAPPING using the captured epoch, so prior remaps no longer drop subsequent valid partial-page copy-backs while concurrent remaps remain strictly synchronized.
  2. Removed heap-block report from XMemFreeDefault (crates/victory-hle/src/modules/xmem.rs):
    • Dropped the 4 KiB host heap loop in XMemFreeDefault and updated tests to reflect only the write-watched 32-bit reservation path.
  3. Protected XMemVirtualAlloc allocation window (crates/victory-hle/src/modules/xmem.rs):
    • Held let _remap = victory_gpu::title_memory_remapping(); across both allocate and title_memory_remapped.
  4. Regression test added:
    • shadow::tests::unmarked_partial_page_copy_back_after_prior_remap_keeps_gpu_bytes: reproduces the unmarked partial-page UAV write after a prior remap, verifying written == 4096 and title_byte == 0xCC.

Verification

  • cargo test -p victory-gpu --lib watch — 17 passed, 0 failed
  • cargo test -p victory-gpu --lib shadow — 18 passed, 0 failed
  • cargo test -p victory-hle xmem — 15 passed, 0 failed
  • cargo clippy -p victory-gpu -p victory-hle --all-targets --all-features -- -D warnings — clean
  • cargo run -p xtask -- policy — 191 files ok
  • git diff --check — clean
**@⁠ashrafsdrop** on GitHub · 2026-11-26 15:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7196433285) Addressed in [`c697424`](https://github.com/Marvisak/VIctory/commit/c697424762e8e8be3a9ac12c976488dcf2fcdf1b) — excellent review and catch on the partial-page UAV window, @⁠fuzeofficlal. ### Changes 1. **Epoch-scoped remap invalidation (`crates/victory-gpu/src/watch.rs`, `crates/victory-gpu/src/shadow.rs`):** - Added an atomic `REMAP_EPOCH` counter in `watch.rs`. - `title_memory_remapped` increments the epoch under `title_memory_remapping()`, and `Saved::remapped` records `page -> remap_epoch` (`HashMap<usize, u64>`). - `Shadow::writing` records the current epoch alongside snapshot segments `(start, bytes, epoch)`, and `Shadow` tracks `refreshed_epoch` from `Shadow::update`. - `Tracked::was_remapped_since(page, since_epoch)` checks if a remap happened after that snapshot/refresh epoch. `watch::write_back` and `Tracked::taken` re-verify under `MAPPING` using the captured epoch, so prior remaps no longer drop subsequent valid partial-page copy-backs while concurrent remaps remain strictly synchronized. 2. **Removed heap-block report from `XMemFreeDefault` (`crates/victory-hle/src/modules/xmem.rs`):** - Dropped the 4 KiB host heap loop in `XMemFreeDefault` and updated tests to reflect only the write-watched 32-bit reservation path. 3. **Protected `XMemVirtualAlloc` allocation window (`crates/victory-hle/src/modules/xmem.rs`):** - Held `let _remap = victory_gpu::title_memory_remapping();` across both `allocate` and `title_memory_remapped`. 4. **Regression test added:** - `shadow::tests::unmarked_partial_page_copy_back_after_prior_remap_keeps_gpu_bytes`: reproduces the unmarked partial-page UAV write after a prior remap, verifying `written == 4096` and `title_byte == 0xCC`. ### Verification - `cargo test -p victory-gpu --lib watch` — 17 passed, 0 failed - `cargo test -p victory-gpu --lib shadow` — 18 passed, 0 failed - `cargo test -p victory-hle xmem` — 15 passed, 0 failed - `cargo clippy -p victory-gpu -p victory-hle --all-targets --all-features -- -D warnings` — clean - `cargo run -p xtask -- policy` — 191 files ok - `git diff --check` — clean
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 15:54 UTC · original · requested changes

Re-reviewed c697424762e8e8be3a9ac12c976488dcf2fcdf1b on Windows 11 x64 (NVIDIA GeForce RTX 5090 + Microsoft WARP, VICTORY_D3D12_DEBUG=1, Rust 1.98.1).

The three items from the previous pass are cleanly resolved:

  • The Wave 26 prior-remap partial-page UAV repro now succeeds (copied=4096 written=4096 title_byte=0xcc on both RTX 5090 and WARP, matching the new unmarked_partial_page_copy_back_after_prior_remap_keeps_gpu_bytes test).
  • The 4 KiB heap-block branch in XMemFreeDefault is removed and documented as a shortcut:, and XMemVirtualAlloc holds title_memory_remapping() across allocation and notification (crates/victory-hle/src/modules/xmem.rs:156).
  • All existing checks pass (xtask policy: 191 files ok; clippy default & --all-features clean; victory-hle xmem::: 15/15; victory-gpu watch:: shadow:: list::: 38/38 on both RTX 5090 + Debug Layer and WARP + diagnostics + Debug Layer).

However, the new epoch tracking in Shadow::writing introduces two blocking regressions where stale GPU bytes overwrite a remapped page (both of which safely preserved 0x22 on the previous head 4f47bdcf):

1. Blocking: Merging adjacent/overlapping snapshot segments in Shadow::writing discards the earlier segment's epoch (crates/victory-gpu/src/shadow.rs:351,372,379)

When Shadow::writing merges touching or overlapping ranges:

**@⁠fuzeofficlal** on GitHub · 2026-11-26 15:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#pullrequestreview-6077100566) · **requested changes** Re-reviewed `c697424762e8e8be3a9ac12c976488dcf2fcdf1b` on Windows 11 x64 (NVIDIA GeForce RTX 5090 + Microsoft WARP, `VICTORY_D3D12_DEBUG=1`, Rust `1.98.1`). The three items from the previous pass are cleanly resolved: - The Wave 26 prior-remap partial-page UAV repro now succeeds (`copied=4096 written=4096 title_byte=0xcc` on both RTX 5090 and WARP, matching the new `unmarked_partial_page_copy_back_after_prior_remap_keeps_gpu_bytes` test). - The 4 KiB heap-block branch in `XMemFreeDefault` is removed and documented as a `shortcut:`, and `XMemVirtualAlloc` holds `title_memory_remapping()` across allocation and notification (`crates/victory-hle/src/modules/xmem.rs:156`). - All existing checks pass (`xtask policy`: `191 files ok`; `clippy` default & `--all-features` clean; `victory-hle` `xmem::`: `15/15`; `victory-gpu` `watch:: shadow:: list::`: `38/38` on both RTX 5090 + Debug Layer and WARP + `diagnostics` + Debug Layer). However, the new epoch tracking in `Shadow::writing` introduces **two blocking regressions** where stale GPU bytes overwrite a remapped page (both of which safely preserved `0x22` on the previous head `4f47bdcf`): ### 1. Blocking: Merging adjacent/overlapping snapshot segments in `Shadow::writing` discards the earlier segment's epoch (`crates/victory-gpu/src/shadow.rs:351,372,379`) When `Shadow::writing` merges touching or overlapping ranges:
Author
Owner

@⁠ashrafsdrop on GitHub · 2026-11-26 16:14 UTC · original

Addressed in 72a7197 — sharp catch on the merge and sampling windows, @⁠fuzeofficlal.

  1. Epoch Retention on Segment Merge (crates/victory-gpu/src/shadow.rs):
    • When Shadow::writing merges adjacent or touching segments (first..last), it takes the minimum epoch among all drained segments via .fold(refreshed_epoch, u64::min), preserving the earliest snapshot epoch across the combined range.
  2. Anchored Snapshot Epoch:
    • Shadow::writing now initializes its base epoch from self.refreshed_epoch.load(Ordering::Acquire) rather than current_epoch(). Since self.data holds bytes from refreshed_epoch, any remap occurring after update but before writing is caught by was_remapped_since.
  3. Regression Tests Added:
    • shadow::tests::merging_overlapping_snapshot_segments_preserves_earlier_epoch (exercises merge discarding earlier remap).
    • shadow::tests::remap_between_update_and_writing_preserves_new_title_bytes (exercises remap between update and writing).

Verification:

  • cargo test -p victory-gpu --lib shadow: 20 passed, 0 failed
  • cargo test -p victory-gpu --lib watch: 17 passed, 0 failed
  • cargo test -p victory-hle xmem: 15 passed, 0 failed
  • cargo clippy -p victory-gpu -p victory-hle --all-targets --all-features -- -D warnings: clean
  • cargo run -p xtask -- policy: 191 files ok
  • git diff --check: clean
**@⁠ashrafsdrop** on GitHub · 2026-11-26 16:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7197382149) Addressed in [72a7197](https://github.com/ashrafsdrop/VIctory/commit/72a7197) — sharp catch on the merge and sampling windows, @⁠fuzeofficlal. 1. **Epoch Retention on Segment Merge (`crates/victory-gpu/src/shadow.rs`)**: - When `Shadow::writing` merges adjacent or touching segments (`first..last`), it takes the minimum epoch among all drained segments via `.fold(refreshed_epoch, u64::min)`, preserving the earliest snapshot epoch across the combined range. 2. **Anchored Snapshot Epoch**: - `Shadow::writing` now initializes its base epoch from `self.refreshed_epoch.load(Ordering::Acquire)` rather than `current_epoch()`. Since `self.data` holds bytes from `refreshed_epoch`, any remap occurring after `update` but before `writing` is caught by `was_remapped_since`. 3. **Regression Tests Added**: - `shadow::tests::merging_overlapping_snapshot_segments_preserves_earlier_epoch` (exercises merge discarding earlier remap). - `shadow::tests::remap_between_update_and_writing_preserves_new_title_bytes` (exercises remap between `update` and `writing`). Verification: - `cargo test -p victory-gpu --lib shadow`: 20 passed, 0 failed - `cargo test -p victory-gpu --lib watch`: 17 passed, 0 failed - `cargo test -p victory-hle xmem`: 15 passed, 0 failed - `cargo clippy -p victory-gpu -p victory-hle --all-targets --all-features -- -D warnings`: clean - `cargo run -p xtask -- policy`: 191 files ok - `git diff --check`: clean
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 16:20 UTC · original · approved these changes

Re-reviewed 72a719727c27eff7ce5ff02b623b9c772762b412 on Windows 11 x64 (NVIDIA GeForce RTX 5090 + Microsoft WARP, VICTORY_D3D12_DEBUG=1, Rust 1.98.1).

Both blocking regressions from c6974247 are cleanly fixed:

  • crates/victory-gpu/src/shadow.rs:351, :364: Shadow::writing now anchors new snapshot segments to self.refreshed_epoch.load(Ordering::Acquire) rather than current_epoch() and folds merged segments with u64::min, closing both the update -> remap -> writing window and the touching/overlapping segment-merge epoch clobber, backed by the two new regression tests (merging_overlapping_snapshot_segments_preserves_earlier_epoch and remap_between_update_and_writing_preserves_new_title_bytes).
  • Non-blocking follow-up note: Shadow::refreshed_epoch is still shared across all pages of a Shadow, so if a future refinement wants per-page isolation when one page is served from Batch::current while another page in the same Shadow calls update(), switching to per-page refresh epochs can tighten that narrow case too.

Verification

  • cargo run -p xtask -- policy (191 files ok)
  • cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings (default & --all-features)
  • cargo test -p victory-hle --lib -- modules::xmem::: 15/15 passed
  • victory-gpu watch:: shadow:: list:: with VICTORY_D3D12_DEBUG=1: 40/40 passed on RTX 5090; 40/40 passed (--features diagnostics) on WARP.
  • Re-ran all four earlier reproducers on both RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1): prior-remap partial-page unmarked UAV (written=4096, 0xcc), touching-page merge across remap (written=0, 0x22), same-page sub-page merge across remap (written=0, 0x22), and remap between update and writing (written=0, 0x22) — all four passed cleanly.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 16:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#pullrequestreview-6077453285) · **approved these changes** Re-reviewed `72a719727c27eff7ce5ff02b623b9c772762b412` on Windows 11 x64 (NVIDIA GeForce RTX 5090 + Microsoft WARP, `VICTORY_D3D12_DEBUG=1`, Rust `1.98.1`). Both blocking regressions from `c6974247` are cleanly fixed: - `crates/victory-gpu/src/shadow.rs:351`, `:364`: `Shadow::writing` now anchors new snapshot segments to `self.refreshed_epoch.load(Ordering::Acquire)` rather than `current_epoch()` and folds merged segments with `u64::min`, closing both the `update -> remap -> writing` window and the touching/overlapping segment-merge epoch clobber, backed by the two new regression tests (`merging_overlapping_snapshot_segments_preserves_earlier_epoch` and `remap_between_update_and_writing_preserves_new_title_bytes`). - Non-blocking follow-up note: `Shadow::refreshed_epoch` is still shared across all pages of a `Shadow`, so if a future refinement wants per-page isolation when one page is served from `Batch::current` while another page in the same `Shadow` calls `update()`, switching to per-page refresh epochs can tighten that narrow case too. ### Verification - `cargo run -p xtask -- policy` (`191 files ok`) - `cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings` (default & `--all-features`) - `cargo test -p victory-hle --lib -- modules::xmem::`: **15/15 passed** - `victory-gpu` `watch:: shadow:: list::` with `VICTORY_D3D12_DEBUG=1`: **40/40 passed** on RTX 5090; **40/40 passed** (`--features diagnostics`) on WARP. - Re-ran all four earlier reproducers on both RTX 5090 and WARP (`VICTORY_D3D12_DEBUG=1`): prior-remap partial-page unmarked UAV (`written=4096, 0xcc`), touching-page merge across remap (`written=0, 0x22`), same-page sub-page merge across remap (`written=0, 0x22`), and remap between `update` and `writing` (`written=0, 0x22`) — all four passed cleanly.
Author
Owner

@⁠pickles976 on GitHub · 2026-11-26 18:44 UTC · original

Independent Wine verification of updated production head 72a719727c27eff7ce5ff02b623b9c772762b412: 9 targeted shadow lifecycle tests passed, 0 failed/ignored, 0.75 s after fresh 9.16 s compilation from the selected worktree.

Environment: Linux, Wine 11.0, Rust 1.98.1 Windows MSVC target, 16 GiB RAM, physical NVIDIA GeForce RTX 4060 Laptop GPU / driver 590.48.1, DXVK_CONFIG='dxgi.hideNvidiaGpu = False'. vkd3d-proton 3.2.0 2576c0b4adfae4a+ is our diagnostic-relaxed build, not stock certification. Single test thread, 9 GiB memory / 512 MiB swap cgroup limits, 180 s timeout.

Only local changes: replace the nine selected fixtures' no-host early returns with panics (including required mark bitmap where used). Production code unchanged. The log identifies the real NVIDIA adapter; missing host buffers cannot silently pass these runs.

cargo test --locked --target x86_64-pc-windows-msvc -p victory-gpu --features diagnostics --lib -- \
  shadow::tests::remapping_ \
  memory_freed_and_allocated_again_keeps_the_new_bytes_once_reported \
  copy_back_write_waits_for_in_flight_remapping_guard \
  unmarked_partial_page_copy_back_after_prior_remap_keeps_gpu_bytes \
  merging_overlapping_snapshot_segments_preserves_earlier_epoch \
  remap_between_update_and_writing_preserves_new_title_bytes \
  --nocapture --test-threads=1

The four remapping_ cases, reported free/reallocation, mapping-lock exclusion, partial-page write after an earlier remap, merged snapshot epoch, and remap between update and writing all passed. In particular, the latest three epoch regressions now pass on this Wine/NVIDIA host, supplementing the existing native-Windows feedback.

Scope: real D3D12-backed shadow allocations plus Win32 tracking/copy-back semantics. These tests inject bytes into host copies; this is not shader-dispatch, gameplay, or memory-peak proof. No old failure was rerun merely to reconfirm it, and there is no new matched-parent performance comparison. This does not certify every resource release path or imply that an unreported release/re-take is protected; the separate free-side notification coverage discussed in #3077 still needs its own evidence.

Maintainer suggestion: retain the new epoch fixtures and make host availability explicit in hardware CI, so an adapter/allocation failure cannot masquerade as passing remap coverage. The current local nine-line fail-closed strengthening can be reproduced without changing production behavior.

Local log: .compat-runtime/logs/verify-pr2612-evening-wine-remap.log. No title launch or game assets. AI-assisted verification/source review (OpenAI GPT-6 Astra).

**@⁠pickles976** on GitHub · 2026-11-26 18:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2612#issuecomment-7200807237) Independent Wine verification of updated production head `72a719727c27eff7ce5ff02b623b9c772762b412`: **9 targeted shadow lifecycle tests passed, 0 failed/ignored**, 0.75 s after fresh 9.16 s compilation from the selected worktree. Environment: Linux, Wine 11.0, Rust 1.98.1 Windows MSVC target, 16 GiB RAM, physical NVIDIA GeForce RTX 4060 Laptop GPU / driver 590.48.1, `DXVK_CONFIG='dxgi.hideNvidiaGpu = False'`. vkd3d-proton 3.2.0 `2576c0b4adfae4a+` is our **diagnostic-relaxed** build, not stock certification. Single test thread, 9 GiB memory / 512 MiB swap cgroup limits, 180 s timeout. Only local changes: replace the nine selected fixtures' no-host early returns with panics (including required mark bitmap where used). Production code unchanged. The log identifies the real NVIDIA adapter; missing host buffers cannot silently pass these runs. ```text cargo test --locked --target x86_64-pc-windows-msvc -p victory-gpu --features diagnostics --lib -- \ shadow::tests::remapping_ \ memory_freed_and_allocated_again_keeps_the_new_bytes_once_reported \ copy_back_write_waits_for_in_flight_remapping_guard \ unmarked_partial_page_copy_back_after_prior_remap_keeps_gpu_bytes \ merging_overlapping_snapshot_segments_preserves_earlier_epoch \ remap_between_update_and_writing_preserves_new_title_bytes \ --nocapture --test-threads=1 ``` The four `remapping_` cases, reported free/reallocation, mapping-lock exclusion, **partial-page write after an earlier remap**, **merged snapshot epoch**, and **remap between update and writing** all passed. In particular, the latest three epoch regressions now pass on this Wine/NVIDIA host, supplementing the existing native-Windows feedback. Scope: real D3D12-backed shadow allocations plus Win32 tracking/copy-back semantics. These tests inject bytes into host copies; this is **not shader-dispatch, gameplay, or memory-peak proof**. No old failure was rerun merely to reconfirm it, and there is no new matched-parent performance comparison. This does not certify every resource release path or imply that an unreported release/re-take is protected; the separate free-side notification coverage discussed in #3077 still needs its own evidence. Maintainer suggestion: retain the new epoch fixtures and make host availability explicit in hardware CI, so an adapter/allocation failure cannot masquerade as passing remap coverage. The current local nine-line fail-closed strengthening can be reproduced without changing production behavior. Local log: `.compat-runtime/logs/verify-pr2612-evening-wine-remap.log`. No title launch or game assets. AI-assisted verification/source review (OpenAI GPT-6 Astra).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2612/head:github-bot/gh-2612'
git switch 'github-bot/gh-2612'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2612'
git switch 'github-bot/gh-2612'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2612'
git switch 'github-bot/gh-2612'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2612'
git switch 'main'
git merge --squash 'github-bot/gh-2612'
git switch 'main'
git merge --ff-only 'github-bot/gh-2612'
git switch 'main'
git merge 'github-bot/gh-2612'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2612
No description provided.