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

Manually merged
github merged 2 commits from github-bot/gh-2356 into main 2026-11-26 15:33:57 +00:00 AGit
Owner

@⁠aslan2142 on GitHub · 2026-11-26 15:06 UTC · original
aslan2142:geometry-remap-release-opt-in → main · +74 −23 · 9 files · 3 commits · merged 2026-11-26 15:30 UTC

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)

**@⁠aslan2142** on GitHub · 2026-11-26 15:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2356) `aslan2142:geometry-remap-release-opt-in` → `main` · +74 −23 · 9 files · 3 commits · merged 2026-11-26 15:30 UTC 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://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ## 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)
Since #2350 a remap of physical pages that gives a page another frame retired the geometry copies over it, on by
default. In the first world run of that main on an RX 7900 XTX (RADV) the copies were retired by the thousand
(evicted 15010 in about 40 s) and the run ended in a GPUVM page fault (TCP read) and a lost device; the same build
settings without it ran eight minutes with evicted 0 and no fault.

A remap leaves the address valid on the console, so the title keeps using what names it, and not everything that
names a copy's address is rewritten when the copy goes:

- a root view is resolved while its list is recorded (d3d12_com.cpp, GraphicsCommandList::address); a list recorded
  before the retirement and executed in an ExecuteCommandLists begun after it is not among the replays the
  retirement waits for (kAfterExecutes covers only those in progress), so it reads the freed copy;
- a placed buffer view written outside a console heap carries the copy's address for as long as the descriptor lives.

The remap release is now off unless the variable is 1, read at every remap; the copies follow the new pages through
the refresh, as before #2350. Freeing, decommitting and unmapping still retire copies.

Tests: xmem_test test_remap_releases checks that a remap releases nothing by default and with 0, then the existing
checks with 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GetEnvironmentVariableA at every remap ran under g_phys_mutex in every scatter call; with it, xmem_test's split race
("the reader of the views' last pages never faults or misreads") failed in two full Wine runs in a row, where main
passed it twice. The value is cached as before #2350's default changed; rt::xmem::reload_remap_release_setting lets
test_remap_releases switch it. Two full runs since: no change against main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:09:47 +00:00
github manually merged commit 2467916120 into main 2026-11-26 15:33:57 +00:00
github-bot changed title from xmem: a remap retires geometry copies only with LEONIDA_GEOMETRY_REMAP_RELEASE=1 (RT-GEOMETRY-REMAP-RELEASE-OPT-IN) to d3d12, xmem: remap release and console heap mirror only on request (RT-GEOMETRY-REMAP-AND-HEAP-MIRROR-OPT-IN) 2026-11-26 15:33:57 +00:00
Author
Owner

@⁠HasiKe on GitHub · 2026-11-26 18:51 UTC · original

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: #1608 (my latest finding there). AI-assisted (Claude Code).

**@⁠HasiKe** on GitHub · 2026-11-26 18:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2356#issuecomment-7200925939) 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://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 (my latest finding there). AI-assisted (Claude Code).
This discussion has been locked. Commenting is limited to contributors.
No description provided.