d3d12, xmem: remap release and console heap mirror only on request (RT-GEOMETRY-REMAP-AND-HEAP-MIRROR-OPT-IN) #2356

Merged
aslan2142 merged 3 commits from upstream-pr/2356 into main 2026-11-26 15:30:54 +00:00
aslan2142 commented 2026-11-26 15:06:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-26T15:06:44Z.


Fixes two regressions that #2350 brought in. Since then, a world run loses the device within about a minute. Both features responsible are now off unless asked for:

  • LEONIDA_GEOMETRY_REMAP_RELEASE=1 turns on retiring geometry copies when pages are remapped.
  • LEONIDA_HEAP_MIRROR=1 turns on the host-RAM mirror of a console heap's copy.

Claimed in the coordination issue as: RT-GEOMETRY-REMAP-AND-HEAP-MIRROR-OPT-IN

What regressed

World runs on merged main (RX 7900 XTX, RADV, Wine, the same settings otherwise):

Run Remap release Heap mirror Result
1 on (default) on (default) GPU page fault on a TCP read and a lost device about 40 s into the world; 15010 copies evicted by then
2 off on (default) No evictions and no page fault, but a library compute program on the direct queue hung about a minute in; ring timeout, lost device
3 off off More than five minutes in the world with no fault or hang; it stopped at the title's own breakpoint, where the build before #2350 also stopped
  • The build before #2350, with the same settings and the same other PRs, had evicted 0 and no fault.

Why: remap release

  • #2350 (commit 36771ec53) made a remap of physical pages (XMemMapPhysicalPages with pages, the scatter call, CopyPageMappingsBatchX) retire the geometry copies over every page that gets another frame.
  • A remap leaves the address valid on the console. The title keeps using every descriptor and list that names it.
  • Some of what names a copy's address is not rewritten when the copy is retired:
    • A root view is resolved when its list is recorded (d3d12_com.cpp, GraphicsCommandList::address). A list recorded before the retirement but executed in an ExecuteCommandLists that starts after it is not one of the replays kAfterExecutes waits for, so it reads the freed copy.
    • A placed buffer view written outside a console heap keeps the copy's address for as long as the descriptor lives.
  • In run 1 the faulting address is outside the GPU address arena, among the 4 MiB blocks that hold title buffer copies. A geometry block is destroyed once its last view has been reaped.

Why: heap mirror

  • Not known yet. The mirror (commit 746059011) is what the filtered release sweep (LEONIDA_CONSOLE_RELEASE_FILTER=1) reads to decide which V# slots still name a released buffer.
  • Hypothesis, not proven: if the mirror and the copy ever differ, the sweep skips a slot it should fix. A V# would then keep naming memory that was released and reused, and a shader reading garbage there can loop instead of faulting.
  • The code reviewed so far writes the copy and the mirror together through write() and zero(). I found no write that bypasses them.
  • Next step: a run with LEONIDA_HEAP_MIRROR=1 LEONIDA_HEAP_MIRROR_CHECK=1, which logs every slot where the mirror and the copy differ.

The fix

  • remap_releases_enabled() in xmem.cpp returns true only when LEONIDA_GEOMETRY_REMAP_RELEASE is 1. The value is read once, and a test seam, rt::xmem::reload_remap_release_setting(), reads it again. With it off, copies follow the new pages through the refresh, as they did before #2350. Freeing, decommitting and unmapping pages still retire copies.
  • heap_mirror_enabled() in d3d12_vulkan_device.cpp returns true only when LEONIDA_HEAP_MIRROR is 1. With it off, the sweep reads the copy itself, as it did before the mirror.
  • runtime/README.md, docs/d3d12_vulkan.md and src/console_heap_copy.h give both defaults and why.
  • Follow-ups:
    • Making remap release safe means keeping a copy until no recorded list or written descriptor can still name it.
    • Finding out why the mirror hangs the GPU.

Tests

  • xmem_test (test_remap_releases): a remap releases nothing when the variable is unset or 0; the existing checks run with 1.
  • d3d12_console_heap_mirror_test expects a mirror only with LEONIDA_HEAP_MIRROR=1:
    • d3d12_console_heap_mirror sets 1, with LEONIDA_HEAP_MIRROR_CHECK=1.
    • d3d12_console_heap_mirror_off sets 0.
    • New: d3d12_console_heap_mirror_default, with the variable unset.
  • On main's runtime, the new default checks in both tests fail.
  • Linux runtime build and ctest on llvmpipe: 112/112 pass.
  • Windows suite under Wine (clang-cl cross-build), integrated RDNA2 GPU on RADV, compared with the same main:
    • No test went from pass to fail; the only change is the new d3d12_console_heap_mirror_default, which passes.
    • An earlier version read the remap variable at every remap. In two full runs it failed the split race check in xmem_test, which main passed twice. Reading the value once fixed that: two full runs since with no change.
  • tests/test_docs_env_vars.py, tests/test_ci_registration.py and scripts/check_no_game_data.py on the changed files: pass.

Not tested

  • No game run on this branch's build yet. Runs 2 and 3 set the variables on main, which is equivalent.
  • llvmpipe was not run under Wine.
  • No MSVC build: CI covers it.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5512463448 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2356). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-26T15:06:44Z. --- Fixes two regressions that #2350 brought in. Since then, a world run loses the device within about a minute. Both features responsible are now off unless asked for: - `LEONIDA_GEOMETRY_REMAP_RELEASE=1` turns on retiring geometry copies when pages are remapped. - `LEONIDA_HEAP_MIRROR=1` turns on the host-RAM mirror of a console heap's copy. Claimed in the coordination issue as: [RT-GEOMETRY-REMAP-AND-HEAP-MIRROR-OPT-IN](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7196359300) ## What regressed World runs on merged `main` (RX 7900 XTX, RADV, Wine, the same settings otherwise): | Run | Remap release | Heap mirror | Result | | --- | --- | --- | --- | | 1 | on (default) | on (default) | GPU page fault on a TCP read and a lost device about 40 s into the world; 15010 copies evicted by then | | 2 | off | on (default) | No evictions and no page fault, but a library compute program on the direct queue hung about a minute in; ring timeout, lost device | | 3 | off | off | More than five minutes in the world with no fault or hang; it stopped at the title's own breakpoint, where the build before #2350 also stopped | - The build before #2350, with the same settings and the same other PRs, had `evicted 0` and no fault. ## Why: remap release - #2350 (commit `36771ec53`) made a remap of physical pages (`XMemMapPhysicalPages` with pages, the scatter call, `CopyPageMappingsBatchX`) retire the geometry copies over every page that gets another frame. - A remap leaves the address valid on the console. The title keeps using every descriptor and list that names it. - Some of what names a copy's address is not rewritten when the copy is retired: - A root view is resolved when its list is recorded (`d3d12_com.cpp`, `GraphicsCommandList::address`). A list recorded before the retirement but executed in an `ExecuteCommandLists` that starts after it is not one of the replays `kAfterExecutes` waits for, so it reads the freed copy. - A placed buffer view written outside a console heap keeps the copy's address for as long as the descriptor lives. - In run 1 the faulting address is outside the GPU address arena, among the 4 MiB blocks that hold title buffer copies. A geometry block is destroyed once its last view has been reaped. ## Why: heap mirror - Not known yet. The mirror (commit `746059011`) is what the filtered release sweep (`LEONIDA_CONSOLE_RELEASE_FILTER=1`) reads to decide which V# slots still name a released buffer. - Hypothesis, not proven: if the mirror and the copy ever differ, the sweep skips a slot it should fix. A V# would then keep naming memory that was released and reused, and a shader reading garbage there can loop instead of faulting. - The code reviewed so far writes the copy and the mirror together through `write()` and `zero()`. I found no write that bypasses them. - Next step: a run with `LEONIDA_HEAP_MIRROR=1 LEONIDA_HEAP_MIRROR_CHECK=1`, which logs every slot where the mirror and the copy differ. ## The fix - `remap_releases_enabled()` in `xmem.cpp` returns true only when `LEONIDA_GEOMETRY_REMAP_RELEASE` is `1`. The value is read once, and a test seam, `rt::xmem::reload_remap_release_setting()`, reads it again. With it off, copies follow the new pages through the refresh, as they did before #2350. Freeing, decommitting and unmapping pages still retire copies. - `heap_mirror_enabled()` in `d3d12_vulkan_device.cpp` returns true only when `LEONIDA_HEAP_MIRROR` is `1`. With it off, the sweep reads the copy itself, as it did before the mirror. - `runtime/README.md`, `docs/d3d12_vulkan.md` and `src/console_heap_copy.h` give both defaults and why. - Follow-ups: - Making remap release safe means keeping a copy until no recorded list or written descriptor can still name it. - Finding out why the mirror hangs the GPU. ## Tests - `xmem_test` (`test_remap_releases`): a remap releases nothing when the variable is unset or `0`; the existing checks run with `1`. - `d3d12_console_heap_mirror_test` expects a mirror only with `LEONIDA_HEAP_MIRROR=1`: - `d3d12_console_heap_mirror` sets `1`, with `LEONIDA_HEAP_MIRROR_CHECK=1`. - `d3d12_console_heap_mirror_off` sets `0`. - New: `d3d12_console_heap_mirror_default`, with the variable unset. - On `main`'s runtime, the new default checks in both tests fail. - Linux runtime build and `ctest` on llvmpipe: 112/112 pass. - Windows suite under Wine (clang-cl cross-build), integrated RDNA2 GPU on RADV, compared with the same `main`: - No test went from pass to fail; the only change is the new `d3d12_console_heap_mirror_default`, which passes. - An earlier version read the remap variable at every remap. In two full runs it failed the split race check in `xmem_test`, which `main` passed twice. Reading the value once fixed that: two full runs since with no change. - `tests/test_docs_env_vars.py`, `tests/test_ci_registration.py` and `scripts/check_no_game_data.py` on the changed files: pass. ## Not tested - No game run on this branch's build yet. Runs 2 and 3 set the variables on `main`, which is equivalent. - llvmpipe was not run under Wine. - No MSVC build: CI covers it. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)
HasiKe commented 2026-11-26 18:51:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by HasiKe on 2026-11-26T18:51:20Z.


Measured on NVIDIA after this merged: with both switches unset (the new defaults), the title crashes on the CPU at 80-160 s on an RTX 2070 SUPER (616.56), in 4 of 5 boots. With LEONIDA_GEOMETRY_REMAP_RELEASE=1 it crashes in 1 of 3, and with both set to 1 in 0 of 3. The bisect and the tables are in #1608: https://github.com/ubiquitarianism/leonida/issues/1608 (my latest finding there). AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7200925939 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2356#issuecomment-7200925939). Originally posted by [HasiKe](https://github.com/HasiKe) on 2026-11-26T18:51:20Z. --- Measured on NVIDIA after this merged: with both switches unset (the new defaults), the title crashes on the CPU at 80-160 s on an RTX 2070 SUPER (616.56), in 4 of 5 boots. With `LEONIDA_GEOMETRY_REMAP_RELEASE=1` it crashes in 1 of 3, and with both set to `1` in 0 of 3. The bisect and the tables are in #1608: https://github.com/ubiquitarianism/leonida/issues/1608 (my latest finding there). AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2356
No description provided.