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 36771ec53):
- 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 746059011):
- 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 (dc9ef1a0b).
- 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>
The mirror (746059011, in #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 #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>
A title sizes the read buffer as the sum of sizeof(XGameSaveBlob), the data and
the name with its NUL for each blob. The shim required the 8-byte aligned layout
and refused such a buffer with E_GS_PROVIDED_BUFFER_TOO_SMALL. The minimum (and
the async result size) is now the unpadded sum; the blobs are packed aligned
when the buffer has room for that and back to back otherwise.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Head 5fa864e53. The conflict in the title-window members keeps #2129's write-back state and the comment of the geometry copies' retirement.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Head 2769c5a73. The conflict in fix_console_slots keeps #2162's buffer V# exception and the heap mirror's heap.copy.zero().
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Head a42bffdc3. The conflict in docs/d3d12_vulkan.md keeps main's session-cache cap (#1886) and #1914's heavy cache text.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A console heap whose GPU copy is an import of the title's pages is read at heap_base + shader_va like a
buffer, but no gpu_backing names it, so the guard refused every descriptor-table load from it: a 38 MB
imported heap read past a 2 GiB arena turned one compute program's table loads into tens of millions of
refusals that read 0. update_address_guard now collects each heap's bytes and null guard outside the arena
(under console_heap_mutex, before guard.mutex) and rebuilds the table when those ranges change. With it,
the run that refused them shows no refusals in the same phase.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
--address-guard modules now store a module id with each refused access, in the header word that was
reserved (+28): FNV-1a of the translated file's stem, fixed at translation time. The runtime's refusal line
names the last refusing module next to its offset, so refusals can be traced to a program without a GPU
capture. The guard's tests pass unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The arena keeps [0x70000, 0x80000) for the guard header and its two sinks (in the null region when
LEONIDA_ARENA_NULL_MB makes one). The page table is a host-visible buffer of its own; the header holds
its address minus heap_base, the arena's size and the magic, written last. Before each submission,
after the heap refresh, the windows and the geometry copies, update_address_guard makes the table say
exactly what is backed outside the arena: gpu_backings, the geometry copies' blocks and the separate
window buffers, the same set as the console heap pass's backed table but without its 100 ms limit.
Only changed words are written, level 2 before level 1; a chunk keeps its block for good; past 62
blocks a chunk passes unchecked, which is logged. Refusals the shaders count are logged at most once
a second with the last refused offset.
src/address_guard.h holds the format and the table (address_guard_test); docs/d3d12_vulkan.md 3.3
"Address guard" the design, the cost per access and what is and is not covered.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every Gen.host_addr access (buffer, global_, scalar and BVH loads, stores and atomics) calls one
%guard_fn with its sign-extended 48-bit heap offset, kind and span. Below the arena's size it passes
after a compare; elsewhere the 4 KiB pages of its first and last byte are looked up in a two-level
page table (level 1 by offset bits 47..32, level 2 one bit per page). A refused load reads the zero
area, a refused store or atomic the dump area (an atomic returns 0), and the refusal is counted in
the guard header. Without the header's magic every access passes; without the flag the module is
unchanged byte for byte.
tools/address_guard.py is the Python reference of the table and the check. cs_address_guard is the
fixture of the translator test and of scripts/run_address_guard_gpu_test.py, which runs it on a heap
where every address it touches is real memory, so no run can fault.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TitleBufferWindows::system_memory_types falls back to every allowed type, the BAR included, when its device has no
memory properties; the assert keeps DeviceState from silently losing them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Geometry copies held 4.4-6 GB of VRAM in world runs and were never evicted: a view retired only when its range was
freed, decommitted or unmapped, and the title streams by remapping the frames of its pools.
- LEONIDA_GEOMETRY_HOST (unset by default): 1 puts the copies in system memory outside VRAM, write-back where the
device offers a cached host type; 2 write-combined. The memory type is picked among the host-visible types that are
not device-local (memory_type_order alone would give the BAR first); a device with none keeps its types. Logged once
and in the geometry buffers line.
- LEONIDA_GEOMETRY_REMAP_RELEASE (on by default, 0 off): XMemMapPhysicalPages with pages, the scatter call and
CopyPageMappingsBatchX report the pages whose frame changed (or went) as released (xmem's RemapReleases, collected
under the fault lock, reported after it), so GeometryViews retires the copies over them through #2094's
drain_released and kAfterExecutes reaping. A page mapped again to its own frame is no change.
- A retired view is copied once more from its pages when they are readable: a list recorded before a remap that took
the view's address reads the new bytes, as the refresh this replaces would have given it.
- A stream-pool extent backed by a retired copy leaves pool_spans (it was kept for the device's life).
- A full release queue joins touching ranges before it collapses into one covering range.
Tests: geometry_views_test cases 14-16, xmem_test test_remap_releases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A local tool for headless runs, whose private display passes no keyboard input to Wine: every line
appended to the file names one button of the script's table and becomes a press at once, held like a
scripted press (300 ms and six readings, at most 5 s), so a run can be driven step by step from the shell
while its screenshots are read. The file is read again at most every 250 ms. Off by default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An experiment for descriptors the title builds from AllocateUploadMemory pointers (the console's memory is
unified, so the CPU pointer is also its GPU address): each upload chunk's CPU range is entered as an alias
of the chunk's console VA (device address minus heap_base), so the in-place V# rewrite before each
submission reaches the chunk instead of writing an empty V#. Removed with the upload state. Off by default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A diagnostic for descriptors that hold pool offsets: each upload chunk (CPU base, device address, size) and
the first 96, then every 8192nd, AllocateUploadMemory result as an offset into its chunk, to match with the
addresses in the title's T#s and V#s. Off by default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A console resource heap's translated copy lies in the GPU address arena when the
import of host memory is not used, and the arena prefers DEVICE_LOCAL |
HOST_VISIBLE memory (ReBAR): the filtered release sweep
(LEONIDA_CONSOLE_RELEASE_FILTER=1) read words 0-2 of both V# halves of every
live slot from it, uncached across PCIe, 0.9-1.0 s a rescan in game runs.
ConsoleHeap::copy is now a leonida::ConsoleHeapCopy (src/console_heap_copy.h):
the copy plus an optional host-RAM mirror of the heap's bytes. Every CPU write
goes through write()/zero(), which write both; CPU reads use view(). The raw
pointer is no longer reachable by accident, so a missed write site does not
compile. No mirror for a copy in an import of host memory, for a sampler heap,
with LEONIDA_HEAP_MIRROR=0, or once the LEONIDA_CONSOLE_HEAP_GPU pass writes
the copy (dropped at attach).
LEONIDA_HEAP_MIRROR_CHECK=1 compares the mirror with the copy at every release
sweep and logs the first differing slots and a count per heap log line.
The sweep over 536k live slots of an 18 MiB heap with the mirror: about 5 ms
(console_heap_copy_test, host RAM). Tests: console_heap_copy (portable) and
d3d12_console_heap_mirror (first refresh, title writes and zeroes, a filtered
release sweep; again with LEONIDA_HEAP_MIRROR=0).
AI-assisted (Claude Code, Claude Opus 5.5).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two more diagnostics for the world's missing data: the buffer V#s fix_vsharp writes empty because nothing
backs their base, by distinct base and by 4 GiB range, and the raw words of the first unknown T#s, so the
address bits can be checked against the decoder. Off by default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A diagnostic for the world's missing textures: each distinct base address a title-written T# names with no
texture there is logged once (format, type, the SW_MODE bits, size, mips, layers, and whether it is title
memory), with a summary by shape every 8192 lookups. Off by default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The clamp cut a garbage draw count to 2^24 vertices and charged it against the
list's 2^27-unit budget. Only records whose words are all 0xFFFFFFFF were
treated as unfilled. A slot with a garbage count but other words set therefore
cost 2^24 units, so eight such records used up the budget and every real draw
after them in the list ran empty.
A census in codec-d/cool_fox's fork of VIctory found 90 records of 2^24
vertices in one list, and that fork treats 2^23 vertices an instance or more as
unfilled. Here such a record now runs empty, keeps its locations and charges
nothing. Draws under 2^23 are unchanged.
indirect_clamp_test: the old garbage cases now expect an empty record. New
cases check the 2^23 edge and 16 garbage counts ahead of a real draw, which ran
empty with the old shader and runs with this one. The list-budget case uses a
real 2^22 x 16 draw. indirect_clamp_spv.h was regenerated with glslangValidator
15.1.0 (-V --target-env vulkan1.2 -Os).
Tested: full ctest (108 tests) on Linux with Mesa lavapipe (llvmpipe, LLVM 19.1.7).
Changes made by Claude Code (AI-assisted).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
Review follow-up (MoonEyes): the InputScript help in boot.ps1 now says
each press is held 300 ms and that button@seconds:hold holds it longer.
The header comment in gameinput_script.h is wrapped at 120 like the rest
of the file. Comments only; no code change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tested on main a73a57e13: Wine suite (clang-cl + xwin, RDNA2 iGPU, RADV) 412 pass / 22 fail / 39 skip on main and on main + #1886, 0 changes; Linux portable ctest 108/108; the new over_save_limit cases fail on main and pass here. Review points addressed in 66e96ccea. Windows CI cancelled; linux-gpu-tools CI failed at Build (log not available yet; the same job also fails on #1914, and it builds locally). AI-assisted (Claude Code, Claude Opus 5.5 review, Claude Fable 5.2).