Skip to content

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 into
ProjectLeonida:mainfrom
aslan2142:geometry-remap-release-opt-in
Nov 26, 2026
Merged

aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
aslan2142:geometry-remap-release-opt-in

Conversation

@aslan2142

@aslan2142 aslan2142 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

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

Why: remap release

  • [integration] RT-LINUX-AMD-WORLD: what drew the world on Linux/AMD, with eleven runtime PRs, docs for running per GPU #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 [integration] RT-LINUX-AMD-WORLD: what drew the world on Linux/AMD, with eleven runtime PRs, docs for running per GPU #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 and others added 3 commits November 26, 2026 09:57
…P_RELEASE=1

Since ProjectLeonida#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 ProjectLeonida#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 <noreply@anthropic.com>
…ead it again

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 ProjectLeonida#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 <noreply@anthropic.com>
…OR=1

The mirror (7460590, in ProjectLeonida#2350) was on by default. World runs on merged main on an RX 7900 XTX (RADV), the same
settings otherwise:

- remap release on, mirror on: GPU page fault and a lost device about 40 s into the world;
- remap release off, mirror on: no evictions and no page fault, but a hang in a library compute program on the
  direct queue about a minute in, a ring timeout and a lost device;
- both off: past five minutes in the world with no fault or hang, ending where the build before ProjectLeonida#2350 ended, on the
  title's own breakpoint.

Why the mirror hangs the GPU is not known. It is off unless the variable is 1; the release sweep then reads the copy,
as before the mirror.

Tests: d3d12_console_heap_mirror sets LEONIDA_HEAP_MIRROR=1; a new ctest entry, d3d12_console_heap_mirror_default,
runs the same program without the variable and expects no mirror (it fails on main).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aslan2142 aslan2142 changed the title xmem: a remap retires geometry copies only with LEONIDA_GEOMETRY_REMAP_RELEASE=1 (RT-GEOMETRY-REMAP-RELEASE-OPT-IN) d3d12, xmem: remap release and console heap mirror only on request (RT-GEOMETRY-REMAP-AND-HEAP-MIRROR-OPT-IN) Nov 26, 2026
@aslan2142
aslan2142 merged commit 2467916 into ProjectLeonida:main Nov 26, 2026
2 of 5 checks passed
@aslan2142
aslan2142 deleted the geometry-remap-release-opt-in branch November 26, 2026 15:37
aslan2142 added a commit that referenced this pull request Nov 26, 2026
Both came in with #2350 as additions on top of stopgap mechanisms, broke world runs (remap release: a GPUVM page
fault and a lost device; the mirror: a GPU hang) and were made opt-in by #2356. They go completely; with both
variables unset, main behaves as before.

Remap release (LEONIDA_GEOMETRY_REMAP_RELEASE, from 36771ec):
- xmem.cpp: RemapReleases, remap_releases_enabled() and the page recording in unmap_range_locked; the four call
  sites (XMemMapPhysicalPages, the scatter call, both copy_page_mappings).
- xmem.h/xmem.cpp: the test seam rt::xmem::reload_remap_release_setting().
- xmem_test: test_remap_releases (and the title_geometry_watch.h include only it used).
- README row, the docs/d3d12_vulkan.md paragraph; comments that named it.

Console heap mirror (LEONIDA_HEAP_MIRROR, LEONIDA_HEAP_MIRROR_CHECK, from 7460590):
- src/console_heap_copy.h goes. ConsoleHeap::copy is a plain std::uint8_t* again, written with memcpy/memset as
  before the mirror, including the zeroing site that #2350's merge of #2162 resolved as heap.copy.zero(); the
  compute-input probe reads it directly again. Without the mirror, view() was the copy itself, so nothing changes.
- heap_mirror_enabled(), heap_mirror_check_enabled(), check_console_heap_mirror(), the per-heap check counters and
  log line, and the test API console_heap_mirror_mismatches() (d3d12_com.h).
- Tests console_heap_copy, d3d12_console_heap_mirror, _off and _default with their CMake entries; README rows and
  the docs/d3d12_vulkan.md sentences.

Kept, because other paths use them or main's behaviour with the variable unset depends on them:
- LEONIDA_GEOMETRY_HOST and its DeviceState memory-type assert (dc9ef1a).
- The final copy at retirement (GeometryViews::retire_range's final_copy, "copied at retirement" in the geometry
  buffers line): XMemFree of a title heap block (free_title_block) reports a release while the block's memory stays
  committed and readable, so that copy is still made without remap release. Comments now say that instead of
  naming remaps; geometry_views_test case 15 stays.
- forget_pool_span and "retired with their copy" in the title memory line: any retirement (free, decommit, unmap)
  feeds it.
- The release queue's joining of touching ranges (title_geometry_watch.h): unmaps report page runs too;
  geometry_views_test case 16 stays.
- LEONIDA_CONSOLE_RELEASE_FILTER, which predates the mirror; its sweep reads the copy again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HasiKe

HasiKe commented Nov 26, 2026

Copy link
Copy Markdown

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants