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

Closed
opened 2026-11-26 21:20:58 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2356
Author: @aslan2142
Created: 11/26/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: geometry-remap-release-opt-in


📝 Commits (3)

  • 1f7cbef xmem: a remap retires geometry copies only with LEONIDA_GEOMETRY_REMAP_RELEASE=1
  • 4a6a8a6 xmem: read LEONIDA_GEOMETRY_REMAP_RELEASE once, with a test seam to read it again
  • 248b58c d3d12: the console heap's host-RAM mirror only with LEONIDA_HEAP_MIRROR=1

📊 Changes

9 files changed (+74 additions, -23 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+17 -6)
📝 runtime/CMakeLists.txt (+5 -1)
📝 runtime/README.md (+2 -2)
📝 runtime/shims/d3d12_vulkan_device.cpp (+4 -3)
📝 runtime/shims/xmem.cpp (+16 -6)
📝 runtime/shims/xmem.h (+2 -0)
📝 runtime/src/console_heap_copy.h (+2 -1)
📝 runtime/test/d3d12_console_heap_mirror_test.cpp (+5 -4)
📝 runtime/test/xmem_test.cpp (+21 -0)

📄 Description

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)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2356 **Author:** [@aslan2142](https://github.com/aslan2142) **Created:** 11/26/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `geometry-remap-release-opt-in` --- ### 📝 Commits (3) - [`1f7cbef`](https://github.com/ubiquitarianism/leonida/commit/1f7cbeff9a0461c037287e83297e9add75d2646a) xmem: a remap retires geometry copies only with LEONIDA_GEOMETRY_REMAP_RELEASE=1 - [`4a6a8a6`](https://github.com/ubiquitarianism/leonida/commit/4a6a8a633e71ceb5af7afbaadcf9ad2e4ba9a377) xmem: read LEONIDA_GEOMETRY_REMAP_RELEASE once, with a test seam to read it again - [`248b58c`](https://github.com/ubiquitarianism/leonida/commit/248b58c42d2cc5bbdb9aaf81ed122a379926d518) d3d12: the console heap's host-RAM mirror only with LEONIDA_HEAP_MIRROR=1 ### 📊 Changes **9 files changed** (+74 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+17 -6) 📝 `runtime/CMakeLists.txt` (+5 -1) 📝 `runtime/README.md` (+2 -2) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+4 -3) 📝 `runtime/shims/xmem.cpp` (+16 -6) 📝 `runtime/shims/xmem.h` (+2 -0) 📝 `runtime/src/console_heap_copy.h` (+2 -1) 📝 `runtime/test/d3d12_console_heap_mirror_test.cpp` (+5 -4) 📝 `runtime/test/xmem_test.cpp` (+21 -0) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:20:58 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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
starred/leonida#2359
No description provided.