Loader: report pages remapped under GPU buffers that keep their old frames #5

Manually merged
github merged 1 commit from gh-pr/5/head into gh-pr/5/base 2026-11-27 03:13:21 +00:00
Owner

@⁠marquezinii on GitHub · 2026-11-24 17:42 UTC · original
marquezinii:loader/stale-gpu-pages → main · +267 −5 · 7 files · 1 commits · merged 2026-11-24 17:45 UTC

The check from #4. A slot-133 buffer keeps the frames that were mapped when it was made. When the game later remaps or unmaps a page under it, the CPU sees the new frame and the GPU keeps the old one. Once that frame is mapped somewhere else, GPU writes through the buffer change the memory there, and --trace-pool-stores logs them at the buffer's address, not at the address they actually change.

What changed:

  • XMemPhysicalMemory.MapOne reports every frame change (address, previous frame, new frame) to an observer.

  • A CPU reservation now knows its GPU-only alias (XMemReservation.GpuAlias).

  • StaleGpuPages (always on) looks the page up in the address table, under its CPU address and under its alias. For each buffer page it keeps the frame the buffer was placed over, and it ignores buffers that were never over pages (committed fallbacks). It logs [gpu pages] for:

    • a remap or unmap under a buffer: GPU and CPU addresses, and the frame the buffer still reaches
    • that frame mapped again at another address: the address the buffer's writes now land at

    The first 16 of each are logged in full, then totals at every power of two. It reads the address table only; nothing changes for the GPU.

This should tell in one boot whether the fixed-size pool object with INT_MAX-like values sits in a frame that a live buffer still holds.

Checked on Windows with an RTX 5070 (driver 621.40): dotnet build with no warnings and dotnet test with 617 passed and 0 failed (the skips need a dump or a full-wave GPU). The new test, D3D12XStaleGpuPageTests, places a buffer at a GPU-only alias, remaps the CPU page twice and maps the first frame into another range. It then checks both log lines and that a CopyBufferRegion into the buffer lands in the other range. No game files were involved.

Part of #4; the fix itself stays open there.

**@⁠marquezinii** on GitHub · 2026-11-24 17:42 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/5) `marquezinii:loader/stale-gpu-pages` → `main` · +267 −5 · 7 files · 1 commits · merged 2026-11-24 17:45 UTC The check from #4. A slot-133 buffer keeps the frames that were mapped when it was made. When the game later remaps or unmaps a page under it, the CPU sees the new frame and the GPU keeps the old one. Once that frame is mapped somewhere else, GPU writes through the buffer change the memory there, and `--trace-pool-stores` logs them at the buffer's address, not at the address they actually change. What changed: - `XMemPhysicalMemory.MapOne` reports every frame change (address, previous frame, new frame) to an observer. - A CPU reservation now knows its GPU-only alias (`XMemReservation.GpuAlias`). - `StaleGpuPages` (always on) looks the page up in the address table, under its CPU address and under its alias. For each buffer page it keeps the frame the buffer was placed over, and it ignores buffers that were never over pages (committed fallbacks). It logs `[gpu pages]` for: - a remap or unmap under a buffer: GPU and CPU addresses, and the frame the buffer still reaches - that frame mapped again at another address: the address the buffer's writes now land at The first 16 of each are logged in full, then totals at every power of two. It reads the address table only; nothing changes for the GPU. This should tell in one boot whether the fixed-size pool object with INT_MAX-like values sits in a frame that a live buffer still holds. Checked on Windows with an RTX 5070 (driver 621.40): `dotnet build` with no warnings and `dotnet test` with 617 passed and 0 failed (the skips need a dump or a full-wave GPU). The new test, `D3D12XStaleGpuPageTests`, places a buffer at a GPU-only alias, remaps the CPU page twice and maps the first frame into another range. It then checks both log lines and that a CopyBufferRegion into the buffer lands in the other range. No game files were involved. Part of #4; the fix itself stays open there.
A slot-133 buffer is placed over the frames mapped when it is made. When the
game later remaps or unmaps a page under it (XMemMapPhysicalPages, scatter,
CopyPageMappingsBatchX), the CPU sees the new frame and the GPU keeps the old
one; once that frame is mapped at another address, GPU writes through the
buffer change the memory there. Log both with the addresses and frames, and
count them.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:13:19 +00:00
github manually merged commit fad0b7fdef into gh-pr/5/base 2026-11-27 03:13:21 +00:00
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-24 17:46 UTC · original

Merged, thanks! Clean change, and the test pins the behaviour nicely.

For context on #4: the INT_MAX-like heap faults turned out to come from a translator bug rather than stale frames. On wave64, an integer read of a register that is also the high half of a lane mask written on another code path was read as the mask, which sent CS_Prop_BatchCull's instance-count atomics to the start of the transient pool. With that fixed, the story load ran past 200 s without corruption. Your check stays useful though: it tells us in one boot whether the game remaps pages under live buffers, and #4 stays open for the actual fix.

**@⁠ThatRecompDev** on GitHub · 2026-11-24 17:46 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/5#issuecomment-7139674905) Merged, thanks! Clean change, and the test pins the behaviour nicely. For context on #4: the INT_MAX-like heap faults turned out to come from a translator bug rather than stale frames. On wave64, an integer read of a register that is also the high half of a lane mask written on another code path was read as the mask, which sent CS_Prop_BatchCull's instance-count atomics to the start of the transient pool. With that fixed, the story load ran past 200 s without corruption. Your check stays useful though: it tells us in one boot whether the game remaps pages under live buffers, and #4 stays open for the actual fix.
This discussion has been locked. Commenting is limited to contributors.
No description provided.