GPU writes through a slot-133 buffer land in its old frames after a remap (measured on RTX 5070) #4

Closed
opened 2026-11-27 03:13:18 +00:00 by github-bot · 2 comments
Owner

@⁠marquezinii on GitHub · 2026-11-24 17:33 UTC · original

The current blocker is a GPU pass writing INT_MAX-like values into a game heap object. One writer the store trace cannot see: GPU writes through a slot-133 buffer whose pages the game has remapped since the buffer was made.

physical-memory.md already notes the limit: a buffer placed over the frames mapped at creation keeps them after XMemMapPhysicalPages, the scatter variant or CopyPageMappingsBatchX remaps the address. I checked what that does to writes on an RTX 5070 (driver 621.40), through the shim the way the game uses it:

  1. a CPU range and its GPU-only alias (the streaming pattern), frame A mapped in the CPU range
  2. slot 133 creates a buffer at the alias address
  3. the game maps frame B at that address, then maps frame A into another range
  4. CopyBufferRegion writes a marker into the buffer

The marker shows up in the other range. The buffer's own address (now frame B) still reads 0. The translated programs' address map goes through views of the same buffer, so their stores behave the same way.

So once a frame moves away from under a buffer and gets reused, every GPU write through that buffer lands in whatever now owns the frame. --trace-pool-stores logs such a store at the buffer's console address, not at the address it actually changes, so the trace would point away from the victim.

This only matters if the corrupted object sits in xmem frames: the 0x380 streaming pool or the 0x280 GPU pool. Memory from plain VirtualAlloc (the 2.2 GiB heap) is never remapped. I don't have a dump, so I can't tell whether the story load remaps pages under live buffers. A boot can tell, though. I have a branch with an always-on check (StaleGpuPages). It hooks every frame change in XMemPhysicalMemory.MapOne and logs two kinds of [gpu pages] line:

  • a remap or unmap under an address-table buffer, with the GPU and CPU addresses and the frame the buffer still holds
  • that frame mapped again elsewhere, with the address the buffer's writes now land at

It also prints totals at powers of two. It reads the address table only: no new flags, and nothing changes in what the GPU does. Branch: https://github.com/marquezinii/five-star-recomp/tree/loader/stale-gpu-pages (one commit, a WARP-safe test in the loader tests, docs line in physical-memory.md). I can open it as a PR if you want it.

If the counts are non-zero during the story load, here is a direction for the fix, which I haven't implemented:

  • Point remapped pages' address-map entries at views over the section that holds the new frame. One placed buffer per section, made once. The map is already per 64 KiB page, and pointer accesses look up the page they touch.
  • Look up V# accesses by base + offset rather than by the base's page. Today the offset is added linearly inside the base's view, which is right only while the pages stay where they were when the buffer was made.

Desktop views and copies on the game's resource objects would still use the creation-time frames. That part needs a different answer (re-placing the run buffers on remap, for example).

Checked: dotnet build and dotnet test on the branch (Windows, RTX 5070). 617 passed, 0 failed; the skipped tests need a dump or a full-wave GPU.

**@⁠marquezinii** on GitHub · 2026-11-24 17:33 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/issues/4) The current blocker is a GPU pass writing INT_MAX-like values into a game heap object. One writer the store trace cannot see: GPU writes through a slot-133 buffer whose pages the game has remapped since the buffer was made. physical-memory.md already notes the limit: a buffer placed over the frames mapped at creation keeps them after `XMemMapPhysicalPages`, the scatter variant or `CopyPageMappingsBatchX` remaps the address. I checked what that does to writes on an RTX 5070 (driver 621.40), through the shim the way the game uses it: 1. a CPU range and its GPU-only alias (the streaming pattern), frame A mapped in the CPU range 2. slot 133 creates a buffer at the alias address 3. the game maps frame B at that address, then maps frame A into another range 4. CopyBufferRegion writes a marker into the buffer The marker shows up in the other range. The buffer's own address (now frame B) still reads 0. The translated programs' address map goes through views of the same buffer, so their stores behave the same way. So once a frame moves away from under a buffer and gets reused, every GPU write through that buffer lands in whatever now owns the frame. `--trace-pool-stores` logs such a store at the buffer's console address, not at the address it actually changes, so the trace would point away from the victim. This only matters if the corrupted object sits in xmem frames: the 0x380 streaming pool or the 0x280 GPU pool. Memory from plain VirtualAlloc (the 2.2 GiB heap) is never remapped. I don't have a dump, so I can't tell whether the story load remaps pages under live buffers. A boot can tell, though. I have a branch with an always-on check (`StaleGpuPages`). It hooks every frame change in `XMemPhysicalMemory.MapOne` and logs two kinds of `[gpu pages]` line: - a remap or unmap under an address-table buffer, with the GPU and CPU addresses and the frame the buffer still holds - that frame mapped again elsewhere, with the address the buffer's writes now land at It also prints totals at powers of two. It reads the address table only: no new flags, and nothing changes in what the GPU does. Branch: https://github.com/marquezinii/five-star-recomp/tree/loader/stale-gpu-pages (one commit, a WARP-safe test in the loader tests, docs line in physical-memory.md). I can open it as a PR if you want it. If the counts are non-zero during the story load, here is a direction for the fix, which I haven't implemented: - Point remapped pages' address-map entries at views over the section that holds the new frame. One placed buffer per section, made once. The map is already per 64 KiB page, and pointer accesses look up the page they touch. - Look up V# accesses by `base + offset` rather than by the base's page. Today the offset is added linearly inside the base's view, which is right only while the pages stay where they were when the buffer was made. Desktop views and copies on the game's resource objects would still use the creation-time frames. That part needs a different answer (re-placing the run buffers on remap, for example). Checked: `dotnet build` and `dotnet test` on the branch (Windows, RTX 5070). 617 passed, 0 failed; the skipped tests need a dump or a full-wave GPU.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:13:18 +00:00
Author
Owner

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

PR is welcome

**@⁠ThatRecompDev** on GitHub · 2026-11-24 17:38 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/issues/4#issuecomment-7139488382) PR is welcome
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 17:49 UTC · original

I'm working on the fix described above: address-map entries that follow remaps (views over the section of the new frame) and V# accesses looked up by base + offset. It may also bear on the loops that run to the guard: a program reading a remapped page gets the old frame's data. I'll open a PR with WARP tests when it's ready.

**@⁠marquezinii** on GitHub · 2026-11-24 17:49 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/issues/4#issuecomment-7139749219) I'm working on the fix described above: address-map entries that follow remaps (views over the section of the new frame) and V# accesses looked up by base + offset. It may also bear on the loops that run to the guard: a program reading a remapped page gets the old frame's data. I'll open a PR with WARP tests when it's ready.
This discussion has been locked. Commenting is limited to contributors.
No description provided.