Commit Graph

1118 Commits

Author SHA1 Message Date
9da604f3f5 d3d12: the GPU address arena binds its memory in 2 MiB blocks as allocations need it (RT-MEMORY-BREAKDOWN-AND-SPARSE-ARENA)
The arena was one allocation of its whole size, made at start: with LEONIDA_ARENA_MB=4095 a world run used about
0.8 GB of it (peak end about 1 GB) and held 4 GiB of Resizable BAR memory. Where the device can, the arena is now a
sparse buffer: LEONIDA_ARENA_MB bounds the address range, and memory is bound as it is used.

- src/arena_backing.h (new): the backing units. A unit is one VkDeviceMemory, mapped once, bound over whole 2 MiB
  blocks. An allocation no larger than a block stays inside one block; a larger one takes whole blocks of its own
  (the free-block map's keep-out, footprint and alignment). A unit is bound before the first allocation in it is
  handed out, and when its last allocation is released it is pending with the release's retire ticket; it is unbound
  and freed only once completed_retire_ticket() has reached that ticket. An allocation in a pending block revives it.
- The CPU reaches the arena through one accessor, DeviceState::arena_host(offset, bytes): one table read, null with a
  rate-limited line for a range without memory. Callers that name an offset they do not hold (write_arena_value,
  read_arena, the fsdraw probe) use ArenaBacking::with_host under its shared lock; copy_destination and
  known_view_heap use offset_of. arena.mapped is gone, so every former `arena.mapped + offset` was converted.
- Binds go to a queue nothing else uses (pick_arena_bind_queue: RADV's sparse-only family, or a sparse family with
  a queue to spare) and are waited for there, so a bind never sits behind a submission that waits for a fence the
  CPU signals later. The device asks for that queue at creation.
- Unbinding is safe because: arena_release records submitted_retire_ticket() + 1 (as defer_destroy), so the
  submission being recorded is covered too; reclaim_arena() runs at the start of ExecuteCommandLists, reads
  completed_retire_ticket() before taking the arena lock, and unbinds only units whose ticket has completed; the
  table entries are cleared under the exclusive lock before the memory is freed. An unbound range reads as zero
  (residencyNonResidentStrict is required), never a fault.
- A D3D12 heap in the arena lends its unit's memory (at the heap's place in the unit) to reserved resources' tiles;
  Heap::offset() keeps the arena VA.
- Without sparse buffers, strict residency, a sparse address space as large as the arena, or a queue to spare
  (llvmpipe), one allocation backs the whole arena as before, through the same accessors. No new setting.
- The arena line at release gains `GPU address arena: bound N MiB now (peak P, U units of 2 MiB blocks, sparse)`;
  the mem-probe breakdown's arena `bound` is the bound bytes.

Tests: arena_backing_test (CPU, fake driver): placement never crosses a unit, binds shared per block, unbinding
waits for the ticket, revival, a random workload whose bound bytes equal the blocks live allocations touch, bind
failure, the one-allocation arena, the bind queue choice. arena_sparse_gpu_test (a real device, 77 without sparse
binding): a 256 MiB arena with 40 MiB allocated has 44 MiB bound; CPU writes are what the GPU reads; released blocks
stay bound while a submission that reads them is in flight and are unbound (reading zero) once it completes; a bind
made while the work queue is blocked completes. Both are new (fail to build on main).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 16:44:41 -05:00
627163c8eb Merge pull request #2407 from aslan2142/vsharp-slot-records
d3d12: console heap slots record what their V#s resolved to; a release re-fixes only the slots naming it (RT-VSHARP-SLOT-RECORDS)
2026-11-26 22:41:53 +01:00
20c46b646c Merge pull request #2406 from aslan2142/bindless-dimension-limits
bindless: size every sampled dimension alike and name a full array as its own refusal (RT-BINDLESS-DIMENSION-LIMITS)
2026-11-26 22:41:22 +01:00
b6873ce3dc Merge branch 'bindless-dimension-limits' into descriptor-refill 2026-11-26 16:39:14 -05:00
be1b4da8a2 Merge branch 'vsharp-slot-records' into descriptor-refill 2026-11-26 16:39:14 -05:00
0894ecd174 d3d12: the title write-back asks the write watch first and copies back only the bytes a copy changed
write_back_titles() runs at the start of the shadow refresh, before ShadowPages::refresh() asks the write watch,
so a hot page still carried kClean from the last asking and the title's writes since then were copied over
with the older copy. write_back() now asks first (the asking moves into ask_written_locked(), shared with
refresh()), holds pages whose mapping changed, that a kernel write may be filling, or that xmem aliases, and
copies back only the 256-byte pieces where a copy differs from the title's bytes: a read-only binding writes
nothing and its pages stay guarded, and of two copies of the same bytes only the one that differs is written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 22:06:10 +01:00
5d30fcdad3 Merge remote-tracking branch 'upstream/main' into d3d-sample-positions
# Conflicts:
#	runtime/src/vulkan_replay.h
2026-11-26 20:57:16 +00:00
7d5d820779 bindless: size every sampled dimension alike and name a full array as its own refusal (RT-BINDLESS-DIMENSION-LIMITS)
World runs fill one bindless image array a few minutes in: `a bindless image array is full; dimension 3: 4096
indices, 4092 T#s of 4090 textures`. Dimension 3 is 1D (ImageDimension: 2D, 2D array, 3D, 1D). From then on every
new 1D T# reads the fallback's zeros, and the console heaps count it as "no view for the T#'s format or range",
which went from 2-28 a window to over 4000.

Nothing leaks: the 4096 indices are the fallback, 4092 entries of image_entries and 3 replaced views, every one
held by a texture the runtime still has registered, and a texture's indices go back when it goes (forget_image,
the deferred bindless_slot release, remove_image). The cause is the size: size_bindings grew 2D images to 65536
but 3D and 1D only to 4096 and 2D arrays to 16384, constants that guessed how many textures of each dimension a
title keeps, whatever the device holds (RADV allows 8388606 sampled images, llvmpipe 1015808).

- vulkan_bindless.h: one maximum (max_images, 65536) for the sampled array of every single-sample dimension, in
  place of max_2d_images, max_2d_array_images, max_3d_images and max_1d_images. The 2D-array, 3D and 1D arrays
  grow together after 2D and the storage arrays, so on a device whose limits stop growth earlier none of them is
  favoured. The bound is memory (each generation's pool holds every element): 325729 descriptors on an RTX 5070,
  10-20 MiB at 32-64 bytes a descriptor. The shaders declare runtime arrays, so no shader changes; the set layout
  changes, so compute pipelines get new journal names (hash_bindless_layout) and the pipeline cache is rebuilt.
- BindlessSet::image_refusal says why add_image returned 0: no array for the dimension, the array is full, or only
  its shorter storage range is.
- d3d12_vulkan_device.cpp: bind_image_locked and bind_image_views_locked report that reason; bind_title_image
  counts it ("the bindless array of the T#'s dimension is full", or "the bindless storage arrays of the T#'s
  dimension are full") instead of "no view for the T#'s format or range". The once-per-dimension line names the
  dimension, the storage range and how many of the textures holding indices are still registered at their address.
- docs/d3d12_vulkan.md: the sizes, and the new reason.

Tests: bindless_sizing_test checks RADV's and llvmpipe's limits (every sampled dimension at 65536; on main 1D and 3D
stop at 4096) and that the three dimensions share a short budget alike. vk_bindless_dimensions_test (new, GLSL
shader) sizes a set from the device, gives 5000 live 1D, 2D-array and 3D images an index each and reads every one
through its index, then fills the rest of the array: the next is refused as full, and removed indices come back at
once or, after an erased key, at the next flush. On main it fails at "1D: 4096 indices in the set".
vk_bindless_test's index-space case filled 1D expecting the first index to be 1, which held only while the 1D
array was as short as its storage arrays; it now checks every index once and that indices above the storage arrays
go first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 14:48:57 -05:00
84db5cd027 d3d12: console heap slots record what their V#s resolved to; a release re-fixes only the slots naming it (RT-VSHARP-SLOT-RECORDS)
After any arena release, title-window or geometry block destroyed, or alias change, the next submission walked
every live V# slot of the console heap (about 580,000 in world runs), reading each from the copy in ReBAR VRAM:
1.1-1.5 s a walk whatever the scene, about 2.9 s of a 4.6 s frame. It existed only because nothing recorded
which slot resolved into which backing.

Each V# half of a console resource heap's copy now has a record in host RAM (src/console_heap_slot_records.h):
the title's base and span, the device address its copy names, and whether it resolved or waits. Two indexes
(by base, by target; per power-of-two span class and 64 KiB-or-larger granule) find the halves near a range.
fix_console_slot, the only writer of a slot's copy, writes them; a zeroed range, a deferred slot and a
rewritten slot drop theirs; a destroyed heap takes them with it.

Releases (backing(), title_block_gone), alias ranges removed or replaced (TitleVaAliases tells its listeners
as it happens, forget_copy included) and additions (backings, alias ranges, title memory) go on an unbounded
per-device list. refresh_console_heaps takes it whole; every heap re-fixes exactly the slots it touches: a
release or removal every half naming the range, an addition the waiting halves over it. A new heap log line
gives the changes, slots looked at, slots fixed again and ms per submission.

Removed: the live_vsharps walk and its bitset (console_heap_vsharp_slots.h and its test), the release
generation checks (released_backings, TitleVaAliases::invalidations), LEONIDA_CONSOLE_RELEASE_FILTER, the
4,096-entry DescriptorRangeChanges ring with its full-sweep overflow and changed_ranges(), the empty-slot probe
and retry_unmapped_slots (unreachable: nothing set its flag). LEONIDA_CONSOLE_GPU_FILTER now defaults to unset
instead of the removed variable's value. The T# retries (retry_console_slots) stay.

Tests: console_heap_slot_records_test (portable): releasing a buffer 10 of 60,010 slots name looks at 10
entries and fixes 10 slots; an alias moved, removed and added back; overwritten and zeroed slots; partial
overlap; two slots on one backing; a buffer back; a refused alias copy backed later; a large span; a destroyed
heap; and 400 random rounds compared with a full re-resolution of every slot. d3d12_unmapped_vsharp_test now
expects all 128 waiting slots restored at the first submission after their alias comes (was: 16 by the probe in
64 submissions), none after it goes, and the slots naming a released buffer null. title_va_alias_test and
geometry_views_test check the listener in place of the ring.

Linux ctest 113/113; Windows suite under Wine (clang-cl, iGPU, RADV) equal to main 2d43417d4 test by test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 14:47:29 -05:00
aaff77b831 mem probe: a breakdown line of the runtime's Vulkan memory by consumer (RT-MEMORY-BREAKDOWN-AND-SPARSE-ARENA)
The `mem-probe t=` line sums our vkAllocateMemory bytes per memory type, but not who holds them: in a late world
run 7.5 GB of device-local memory and up to 1.2 GB of the Resizable BAR type could not be attributed. Every tick
now also prints

  [rt] mem-probe breakdown t=<s>: allocated N MiB = arena A (n) [reserved, bound, in use: buffers, descriptor
  heaps, shader code, heaps] + geometry copies + title windows and shadows + upload heaps + staging + texture
  blocks + sampled textures + render targets and depth + other; imported M MiB; not in the total: bindless
  tables, shader modules, pipelines and swapchain images

whose parts add up to the allocated bytes of the t= line. Diagnostic only: nothing changes what is allocated or
where, and with LEONIDA_MEM_PROBE unset nothing is installed.

- src/memory_breakdown.h (new, standard library only): the consumers, an Owner scope (thread-local) that names
  the allocations a thread makes while it lives, the tally and the line's text.
- src/mem_probe.h: the vkAllocateMemory wrapper records the thread's owner; vkCreateImage/vkDestroyImage/
  vkBindImageMemory are wrapped too, so memory nobody named that a dedicated image is bound to counts as a render
  target or depth buffer (attachment usage) or a sampled texture. Named blocks keep their name.
- Owner scopes at the allocation sites: the arena (create_arena), geometry copies (GeometryViews' pool), title
  windows outside the arena and slot-133 shadow buffers with their own memory, upload/readback heap buffers,
  texture staging and copy scratch, and the texture blocks (ImageMemory, TitleImagePool).
- The device adds the arena's reserved, bound and in-use bytes (by kind) and the bindless table bytes, read under
  the arena's and the descriptor locks; BindlessSet allocates through its own function table, so its bytes are
  shown beside the total, not in it.
- runtime/README.md: LEONIDA_MEM_PROBE's row names the three lines.

Test: memory_breakdown_test (CPU): the tally sums to the total with imported memory kept apart, owner scopes nest
and stay on their thread, image usage picks the kind, and the text lists every part. It does not build on main
(the header is new).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 14:31:34 -05:00
bbf861fbb4 Merge main into fix/depth16-quantise-fallback
runtime/CMakeLists.txt: main added the heavy_pipeline_cache, pipeline_cache_journal and compile_helper tests where this branch adds depth24_fragment; both sides are kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-26 13:17:55 -05:00
76109561f4 d3d12: --precompile-pipelines builds the skip-listed programs unless --skip-listed
LEONIDA_SKIP_COMPUTE is a play-time setting: the game drops the listed programs' dispatches. The precompile also
refused to build them, one "not built (LEONIDA_SKIP_COMPUTE)" line each and no override. Players run it with the
game's environment (docs/running.md), so their skip list kept those programs out of the journal for good, and a later
run without the list compiled them in the game.

- precompile_compute_pipelines builds every compute entry; with the list set it says how many entries it names.
  --skip-listed leaves them out on purpose, one line each.
- The last line counts the whole run: built (compiled, from a cache), journaled already, being built by another
  process, failed; left out: of those the list names, not buildable, filtered out (--filter, the size bounds and now
  --limit too).
- BuildHost::unbuildable no longer checks the list. The compile server checks it itself, as before: the game that
  starts it drops those dispatches.

Docs: running.md, linux_proton.md and d3d12_vulkan.md no longer give compile time as the reason for the skip list.
The 89-167 s per program came from wave64-emulated packs; with a native wave64 pack on an RX 7900 XTX (RADV, Mesa
26.3.1, Wine) all 721 library programs of 2 MiB or more built, 360 of them in 170 s on 32 threads, 2.5-32 s each, the
largest (13 MiB) in 28.5 s alone, at a peak of 14 GiB of RAM. Two world runs on that card with all of them journaled
and no skip list took them all from the journal and got no further than runs with the list (a stop with the GPU
idle at 404 s; an idle-queue device loss at about 214 s, which also happens with the list set). Their output is
not checked, so the docs keep the skip list and LEONIDA_RT_AS=off as the setting of our longest runs.

Test: precompile_skip_list (test/check_precompile_skip_list.cmake) precompiles two synthetic compute modules, one of
them listed, three times: with the list set both are built; with --skip-listed only the other one is, and the listed
one is named; a second run into the first journal finds both journaled. It fails on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 12:40:56 -05:00
b59ff42107 Merge main into shadow-keep-gpu-writes: main removed the console heap mirror test (#2370); the shadow_keep test stays
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
2026-11-26 17:54:55 +01:00
71f54be482 shadow keep: a newly filled target brings its pieces to the other targets and the sums (review by lixonik)
The sums stand for what every target holds. fill() gave a new target the title's current bytes while the sums kept
the bytes the other targets were refreshed with, so a title that wrote the old bytes back before the next refresh left
the new target behind (no piece differed from its sum). fill() now compares the filled range, widened to whole pieces,
with the sums as a refresh does: the pieces that differ are copied to every target over them and their sums updated.
New test d3d12_shadow_keep_refill (and _off with LEONIDA_SHADOW_KEEP=0): the reviewer's sequence, two overlapping
targets; it failed before this change (A held 1, B held 2) and passes now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
2026-11-26 17:41:55 +01:00
935a2cd5b6 Merge pull request #2222 from DadaCap/xdxr-update-source-check
xdxr: check the update source and bound the builder's reads (RT-XDXR-UPDATE-SOURCE-CHECK)
2026-11-26 17:41:06 +01:00
6b281fc25d Merge remote-tracking branch 'origin/main' into feat/pipeline-order-recorder
# Conflicts:
#	runtime/CMakeLists.txt
2026-11-26 17:16:30 +01:00
b0767fd657 d3d12, xmem: remove remap release and the console heap mirror
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>
2026-11-26 10:43:18 -05:00
248b58c42d d3d12: the console heap's host-RAM mirror only with LEONIDA_HEAP_MIRROR=1
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>
2026-11-26 10:28:43 -05:00
d6b97a97b5 Merge main into shadow-keep-gpu-writes: shadow_keep and console_heap_copy tests side by side in CMakeLists
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
2026-11-26 16:27:35 +01:00
dbe7cf36b4 Merge #2129 from star41905453-coder: a window's GPU writes go back to the title's pages (RT-TITLE-WINDOW-WRITE-BACK)
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>
2026-11-26 09:17:29 -05:00
6a405cdd48 Merge #2162 from abnalstlll-byte: never defer buffer V#s past the console-fix budget (RT-CONSOLE-FIX-NEVER-DEFER-BUFFER-VSHARP)
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>
2026-11-26 09:17:01 -05:00
062623063e Merge #2097 from Snooozs: a mesh PSO with conservative rasterization needs no topology type (RT-MESH-PSO-CONSERVATIVE-TOPOLOGY)
Head b986d274b.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 09:16:34 -05:00
f5f67b4a9d Merge #2240 from zmasi: sync TitleTexture readability against title_memory_map between passes (RT-TITLE-TEXTURE-MAP-GEN)
Head d088ea79b.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 09:16:27 -05:00
f5113e3da5 Merge #2195 from brandostrong: keep the ExecuteCommandLists serial stack out of TLS callbacks (RT-XMEM-STARTUP-FASTFAIL)
Head eaf0b8d0c.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 09:16:26 -05:00
32a04b17f9 Merge #1914 from kawaii-shakal: a pipeline cache for the offline cache's misses (RT-HEAVY-PIPELINE-CACHE)
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>
2026-11-26 09:16:06 -05:00
04b05c936f address guard: enter console descriptor heaps outside the arena as backed
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>
2026-11-26 09:07:55 -05:00
f2efa48480 address guard: a refusal records its module's id, and the runtime logs it
--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>
2026-11-26 09:07:54 -05:00
25621c61a0 d3d12: LEONIDA_ADDRESS_GUARD=1 keeps the guarded shaders' page table current
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>
2026-11-26 09:07:53 -05:00
dc9ef1a0b7 d3d12: assert DeviceState exposes the memory types LEONIDA_GEOMETRY_HOST picks from
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>
2026-11-26 09:07:51 -05:00
36771ec53d d3d12: geometry copies in system memory, and retired when the title remaps their pages
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>
2026-11-26 09:07:51 -05:00
7460590114 d3d12: host-RAM mirror of a console heap's copy for the release sweep
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>
2026-11-26 09:07:51 -05:00
cc0ae0b91f d3d12: LEONIDA_UNBACKED_VSHARP=1 lists empty V#s; the T# log prints raw words
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>
2026-11-26 09:07:51 -05:00
ee2cf5965b d3d12: LEONIDA_UNKNOWN_TSHARP=1 lists the T#s that name no texture
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>
2026-11-26 09:07:51 -05:00
73516a2902 Merge pull request #1886 from DadaCap/session-cache-limit
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).
2026-11-26 13:52:02 +01:00
4263427b46 Record the library entry of each compute pipeline in the order log
Add an E line after the P line of a compute pipeline.
It holds the FNV-1a 64 hash of the library entry name, not the name.
A reader from before E lines skips them, counted as lines not read.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-26 13:13:04 +01:00
6f2b52e563 d3d12: prewarm console streams kept for their first bind (on-demand)
With LEONIDA_PIPELINE_COMPILE=on-demand a console stream (device slot 86) is
only parsed when it is first bound, and create_graphics queued the prewarm
from there, so a planned pipeline got no lead at all. ecox982745 measured 0
of 8 planned builds before the first bind in that mode, 8 of 8 otherwise.

When the plan has the stream's pipeline, the parse is now queued as its first
prewarm job (at the rank of its first recorded variant, on a compile worker);
create_graphics then queues the variants as for any other PSO. A bind that
comes first waits for the parse through resolve_type's call_once, as it would
have parsed it itself.

d3d12_pipeline_workers_test gets a device case: a first device records the
order, then console-stream PSOs with an eight-entry plan must build those
eight before any command is recorded, with the ordinary stream and with
on-demand, and nothing without a plan. Without the fix the on-demand case
fails with 0 of 8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 06:00:01 -06:00
d864cab47e runtime: prewarm graphics pipelines in the order an earlier run asked for them (RT-PIPELINE-PREWARM-ORDER phase 2)
LEONIDA_PIPELINE_PREWARM_ORDER=<file> (or 1 for pipeline_order.log beside the
session cache) reads the order log #2220 records. Of the runs recorded on this
GPU, the one with the most records is used. When the title creates a PSO whose
description key is in it, each recorded graphics or mesh variant is queued on
the compile workers (#2233) as a warm-up at priority 1 + rank: after every
demanded build, one warm-up at a time, none while a demanded build runs.

Records are taken in order up to LEONIDA_PIPELINE_PREWARM_BUDGET_MS of recorded
build time (default 300000) and LEONIDA_PIPELINE_PREWARM_MAX_ENTRIES (4096).
Compute records are left to the compute warm-up and the offline precompiler.
A missing, garbled or other-GPU log is ignored with one message; damaged lines
and the E lines a v1 reader does not know are skipped.

New CPU test pipeline_prewarm: order kept, budget and entry limit, run
choice, a missing or garbled log, E lines, and on the compile workers the
recorded order and a demanded build overtaking the prewarms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 05:00:01 -06:00
6e9c33e079 Merge remote-tracking branch 'upstream/pr2220' into claude/pipeline-prewarm-order 2026-11-26 04:53:46 -06:00
d088ea79b8 Sync title texture readability with map journal between refresh passes
Between periodic refresh_title_textures passes, synchronous slot-70 view creation and the async fill worker checked TextureReadability with a constant generation, missing title_memory_map range changes since the last pass. Track the map generation on TextureReadability and consult title_memory_map::changes_since outside refresh passes so unmapped or decommitted pages defer before hashing and newly mapped pages publish immediately without waiting for a submission.

Also mark mix_words and hash_bytes LEONIDA_GUARDED_NO_BUILTIN using an unaligned 64-bit load so clang-cl cannot emit CRT memcpy calls inside the __try frame, and classify non-title read faults over unmapped title pages in xmem::physical_page_fault as FaultExit::passed_guarded.
2026-11-26 02:02:47 -08:00
49a0b69fcd d3d12: slot-133 shadows guard aliased title pages at every address instead of copying them each submission (RT-SHADOW-ALIAS-GUARD)
A page xmem maps at two addresses was copied whole at every refresh, since
a guard on one view doesn't fault a write through the other: about 1 GB a
submission after the story load on a retail boot. ShadowPages now arms the
geometry watch's cells of each aliased 64 KiB block at every address it is
mapped and copies a block only when a cell's version moved. xmem tells the
cells of a mapping change after updating the peers, and of list value
writes made through the section.

AI-assisted; tested under WineHQ 11.22 and GE-Proton11-14 on an RTX 3090
(NVIDIA 590.48.01).
2026-11-26 11:18:19 +02:00
a83f38508f d3d12: a pool of compile workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL)
With LEONIDA_ASYNC_PIPELINES=1 every demanded build, the compute warm-up and
the cache checkpoint ran on one general worker (plus a graphics-only one), so
one long driver compile held every pipeline a submission asked for behind it,
and their draws and dispatches were skipped meanwhile.

PipelineCompiler now runs LEONIDA_COMPILE_THREADS workers (half the logical
processors, 2 to 8). A worker takes the most urgent job it may:
- demanded builds first, in the order they came, then warm-ups by size, then
  the checkpoint, which waits until no worker compiles;
- large builds (compute over 128 KiB, graphics of 1 MiB or more) and warm-ups
  together take at most threads-1 workers, so one stays free for a small
  demanded build; at most LEONIDA_COMPILE_HEAVY_MAX large builds at once
  (default threads-1, 1 with LEONIDA_SERIAL_BIG_COMPILES=1), compute and
  graphics alike, each still within the memory gate;
- warm-ups run one at a time, and none starts while a demanded build runs:
  each holds the compile gate for its whole create, and a submission waits
  for every create in flight;
- one build of a PSO at a time, so after_running and the teardown rules hold.

LEONIDA_COMPILE_THREADS=1 keeps the layout before the pool. The design is
MoonEyes' (#2077), ported onto #2098's scheduler.

Tests: d3d12_compile_pool (CPU, jobs held at gates: settings, a long build
does not hold up a small demanded one, heavy count, free worker, warm-ups one
at a time and after demanded builds, order, one job per PSO, release/cancel/
stop_for_exit with jobs in flight), and d3d12_compile_teardown also with one
worker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 03:10:28 -06:00
77275065bc xdxr: check an update's source before refitting it; bound vertex reads by VertexCount
An update whose source is not a structure of this layout (one the title never
built, which D3D12 leaves undefined) made the refit follow its parent table
anywhere. MODE_CHECK now compares the copied header with the layout, and the
update records both tails: the refit runs when the check passes, a full build
when it fails. The refit walk follows only pointers to the layout's nodes.

A vertex index at or past the geometry's VertexCount is no longer read: its
triangle is inactive. XdxrTriangles carries vertex_count from the desc.

vk_xdxr_build_test: blas_vertex_count and eight update-source cases (zero,
random, another element count, garbage tree; large and small-sort).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwRYcpySx4P4ncQ3wD5
2026-11-26 07:50:38 +01:00
51174c6cd9 Merge upstream main into fault-address-owner
Keep address binding diagnostics alongside AMD markers and submit-lock tests.

Conflict resolution assisted by Codex.
2026-11-26 06:36:39 +00:00
c1a1f3dde4 Merge upstream main into d3d-sample-positions
Keep depth bounds and programmable sample locations in the same Vulkan pipeline.

Conflict resolution assisted by Codex.
2026-11-26 06:36:39 +00:00
5fa864e539 d3d12: bound the write-back queue and say when a batch goes back unfenced (RT-TITLE-WINDOW-WRITE-BACK)
A fenced batch waits for its submission's retire ticket. On a queue the layer
holds back (console ordering) the ticket is not ours, and in the worst case
nothing retires soon: the pending list would grow for the rest of the run.

Past 64 pending batches the oldest is now copied back without waiting, once
each, and the fact is logged once. Docs say so.
2026-11-26 06:07:50 +00:00
0babd17b8a Merge remote-tracking branch 'origin/main' into feat/pipeline-order-recorder
Conflicts: docs/d3d12_vulkan.md (main's shorter async paragraph, then the
order-log paragraph), runtime/CMakeLists.txt (both test blocks kept),
runtime/shims/d3d12_vulkan_device.cpp (both includes; build_compute now
reports ComputeBuild::ms to the recorder).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-26 06:53:15 +01:00
eaf0b8d0c2 d3d12: keep the replay serial stack a plain thread_local
861bb0546 added geometry_execute_serials() as a function-local
thread_local std::vector. A C++ thread_local with a destructor in
gta6rt.exe adds TLS callbacks to the image, which the loader's TLS
index-0 move must not have (pe_loader.cpp reserve_tls_index0; see
VulkanContext::stage_xdxr_table). With it the title's CRT startup hits
ucrtbase's one-shot _register_thread_local_exe_atexit_callback guard
and terminates: 0xC0000409 (info0=7) at ~1.6 s, before any D3D12 call.

Use a fixed aggregate instead: no destructor, no TLS callbacks, the same
per-thread LIFO, bounded at 32 replays with overflow reported once.

Tested: runtime builds; with LEONIDA_D3D12=vulkan the fix boots past
startup and submits, while 0b11d86bc exits 0xC0000409 at ~1.5 s.
NVIDIA RTX 4090, driver 616.64, Windows 11.

AI-assisted (Claude Code).

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-25 21:03:49 -08:00
e418c1e4b6 vulkan: AMD breadcrumbs name the dispatch that hung (LEONIDA_DEVICE_MARKERS)
On RADV a GPU hang ends in VK_ERROR_DEVICE_LOST with no checkpoints, so the
device-fault report lists the 64 dispatches in flight but cannot say which
one stopped the queue.

LEONIDA_DEVICE_MARKERS=1 (with LEONIDA_DEVICE_FAULT=1 or 2) enables
VK_AMD_buffer_marker where the device has it. Every dispatch the report
numbers writes its seq into its queue's slot of one persistent host-visible,
coherent buffer: at top of pipe before the dispatch (started) and at bottom
of pipe after it (finished), with vkCmdWriteBufferMarker2AMD. On a loss or a
stall report each queue's last finished and started seq are printed, and
the oldest started, unfinished dispatch is reported as the likely hang and
marked in the submitted-dispatch list. A history of the last 16,384
dispatches names it when it has left that list. The values are best-effort
after a loss, and the report says so.

The seq is now handed out when a dispatch is recorded, so the marker and
the list share one numbering; it counts every recorded dispatch, and the
list can show gaps where a submission recorded more than 64.

Cost with the switch on: two marker writes per dispatch and one history
entry; with it off nothing changes. Without the extension, or without
LEONIDA_DEVICE_FAULT, one "device-markers: unavailable" line is logged.

Tests: vulkan_device_markers (portable: numbering, marker writes, ring,
likely-hang verdicts, the 32-bit wrap) and vk_device_markers (a real device:
after the wait the started and finished markers equal the last seq; SKIP
without the extension).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 22:29:35 -05:00
b21b47b052 d3d12: no table keeps naming a destroyed title-window block
#2098's TitleBufferWindows::published_ and update_gpu_backed assumed blocks are
never destroyed: for_each_block fed every block made so far into the console
heap pass's backed table, and the table was rebuilt only when the published
count grew. With empty blocks now destroyed, a freed block stayed in the table,
and its "never of memory that is not there" contract broke.

- A destroyed block's published_ slot keeps its other fields; only its address
  (now atomic) goes to 0, and for_each_block and find_mapped skip it. A slot is
  never reused before release(), so a lock-free reader never sees one half
  rewritten.
- layout_generation() changes whenever a block is made or destroyed;
  update_gpu_backed uses it instead of the block count to see a change.
- destroy_block tells the device (DeviceState::title_block_gone): the block's
  span goes into released_ranges, as a released backing's does, so the backed
  table cuts it at once and the key entries and heap slots answering into it go
  at the next refresh. A block is destroyed only once its last range was freed,
  after the GPU work that used it completed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 21:30:07 -05:00
266f335dda d3d12: a retired geometry view invalidates the answers it made without an alias
forget_geometry_alias only removed the view's alias ranges. vsharp_address and
placed views take geometry_va() answers straight from GeometryViews, with no
alias entry, so a retirement left the console heap slots translated through
them, and the GPU key table's entries, pointing at the view after its reap.

TitleVaAliases::forget_copy records the retired view as a removal: its title
range (CPU address and GPU twin) goes into changed_ranges with an invalidations
bump, so the console heaps translate those slots again, and its shader VA into
take_removed, so the GPU key table drops answers into it. That is what remove()
does for a range that has an alias; recording the answers instead would cost a
table entry per answer on the hot path, while this costs one entry per
retirement. The retirement runs before refresh_shadows() (previous commit), so
the submission about to run already translates without the view.

pool_spans keeps a retired view's shader_va, but only for its statistics line;
nothing answers from it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 21:28:25 -05:00