Second review on #2412:
- enter_submit no longer switches to the held limit for good once it sees a create of a kind that holds
submissions: each pass checks held_blocking(). With one in the driver the held limit applies on its own (also when
it is under the plain limit) and the budget is off; without, the plain limit and budget apply, so a submission
goes ahead at the plain limit once the holding create left while a create of a kind with no verdict stays. The
"reached the limit, but ..." notice comes once per wait, and the wait wakes when a holding create leaves.
- SubmitTurn passes `probe` into enter_submit: a present or wait never goes ahead at the probe budget, only at the
limit.
- VulkanPresenter::submit's turn does not probe (it covers the startup frame's fence wait and the present); the
nested queue_submit turn still probes the vkQueueSubmit alone.
- submit_mutex_test: gate_second_review covers the four cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
title_mirror.h: a filtered page's sums per 256-byte piece are of the title's bytes (title compared with title); the
filter runs after that compare, only when a piece changed or the home is fresh, and writes the home. write_back skips
a filtered home, so page_mirror_write_back takes TitleMirror::write_back as is. A home leaving its filter is copied
whole once.
The T# index word (tsharp_index_word) is written by finish_in_place into the home's dword 6 once the T# is bound; the
filter leaves 0 (the fallback) there meanwhile, so the title's own dword 6 is never read as an index. Copy-path heaps
keep fix_console_slot's write. d3d12_heap_in_place_test checks a T# slot reads the tag and index while the title's
bytes keep their dword 6; title_mirror_hooks_test checks write-back skips filtered homes and the filter is not called
again for unchanged title bytes. set_tsharp_index_words_for_test for the test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the mirror's steps B and C (title memory resolved to heap_base + its address, ordinary memory mirrored when a
reader names it, the write-back of GPU stores from the homes, a separate bind flush), the in-place filter changes:
- Lock order console_heap_mutex, then page_mirror.mutex, then slot_change_mutex. vsharp_address's mirror path takes
the mirror's lock under console_heap_mutex now, so the filter, which runs inside the mirror's fills, takes no other
lock of ours: the in-place heaps' filter state is under the mirror's lock (page_mirror.in_place), and the mirror's
refresh no longer takes console_heap_mutex. Under the lock the filter does only reachability (arena, a buffer of
ours, or the mirror through page_mirror_resolve_locked, which names ordinary memory as any reader does), nulls and
the list of what is left: a V# the mirror does not hold and a T# to bind are finished in the heap's refresh
(finish_in_place), outside the mirror's lock, and written into the home unless the title rewrote the slot since.
The change list is taken under the mirror's lock when a heap is read in place, so the entries it has not read stay.
- No write-back from a heap read in place: page_mirror_write_back skips filtered pages (TitleMirror::filtered_at), as
their homes hold the filtered slots, not the title's bytes.
- The heap's pages are named to the mirror when the heap is made (ordinary memory is mirrored then), after its
filter range and its second binding are set. The binds go in flush_page_mirror's batch.
d3d12_heap_in_place_test also checks that a GPU store into the heap's pages is not copied back over the title's
bytes; title_mirror_hooks_test checks filtered_at.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- CreateKind, CreateInfo and GateAhead move out of SubmitMutex to namespace scope (CompileGateKind,
CompileGateCreate, CompileGateAhead), with using aliases so SubmitMutex::CreateInfo and the rest still work:
clang and GCC reject a `= {}` default argument of a nested class with default member initializers inside the
enclosing class (review on #2412).
- LEONIDA_COMPILE_GATE unset is the classic gate again, as on main: compute creates only, no limit, no probes;
graphics creates do not pass it. The adaptive gate is LEONIDA_COMPILE_GATE=adaptive: on a driver that holds
submissions (630.20) its first probe of a kind enters the driver after the 2.5 s probe budget and loses the
device if that create stays 10 s more, which the classic gate waits out. `1` and `0` are unchanged.
- submit_mutex_test: a classic-gate case (a graphics create holds nothing back, a 3 s compute create is waited out
with no verdict), the adaptive cases opt into graphics gating; passes unset, with `adaptive` and with `1`.
- README rows and docs/d3d12_vulkan.md say so; the "held verdict 2 s into the probe" wording is corrected (it comes
when the probe returns, and the probe holds the submit lock until then).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The XMemAlloc heap (src/title_heap.h) is the runtime's own over a 32 GiB reservation that xmem places in the
mirror's range. It does not use RtlCreateHeap over a given base, which faults under Wine. Size classes of 64 bytes up
to 1 KiB, then powers of two up to 32 KiB, in 1 MiB spans. Larger blocks are runs of 64 KiB pages, committed when
handed out and decommitted when freed. Freed blocks are kept on lists outside the title's memory, and one lock covers
every call. Committed pages are fed to the mirror as they are committed, so a pointer the title writes into a block
reads the block's bytes without anything naming the range first. The title sees the same as before: 64-byte
alignment, size 0 as 1 byte, and XMemFree of a block from either entry point. When the range is full, blocks come
from the host's heap as before. With LEONIDA_TITLE_HEAP=0 they come from the CRT.
Pages written on both sides: each home keeps a 64-bit sum per 256-byte piece of what both sides last agreed on.
- An upload copies only the pieces the title changed, so a piece only the GPU wrote keeps the GPU's bytes.
- Write-back copies only the pieces the GPU changed while the title's piece still matches the sum.
- A piece both sides changed keeps the title's bytes and is counted.
The mirror's 10 s line gives uploaded and written-back KiB per submission and per frame, and the count of pieces
written on both sides.
Tests:
- title_heap: classes, large blocks, and 20000 random allocations and frees checked against a reference.
- d3d12_page_mirror part 7: one page, the GPU writes piece A and the title piece B in one window, and both survive.
- d3d12_page_mirror part 8: the GPU reads XMemAlloc blocks through pointers nothing named, and a freed large block
reads zero.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When every page of a console CBV/SRV/UAV heap lies in the page mirror (a reservation xmem placed in its range),
add_heap_in_place gives it no copy and no page tracker of its own. 25,865 of the corpus's 26,503 shaders keep 32 bits
of a descriptor-table pointer, so the heap's pages are bound a second time into the arena below 4 GiB
(TitleMirror::alias, same bind batches and wait as the mirror's), at a range of whole arena blocks with no arena
memory behind it (arena_reserve_unbacked); the null slots after the heap are that range's rest, unbound, reading
zero. Table pointers go there as before (console_heap_ranges).
The mirror fills the pages' home through filter_heap_page (TitleMirror::filter_range): the title's page is only
read; a slot whose bytes changed since it was last filtered, or that a change touched (the records' change list,
applied at the mirror's refresh before the written pages are filled, filtered straight into the home), is fixed as a
copied slot was, into the home: a V# whose base lies in the arena, the mirror or a buffer of ours stays as the title
wrote it (reachable_as_written, no record); another V# is resolved as before (an interim until every title allocation
is in the mirror) or written with no base and no records and waits; a T# is bound as before [TSHARP-INDEX: its
bindless index in the entry]; other words are null. A GPU write-back is never taken from these pages: the mirror has
none, and no window is made for them.
A heap the mirror does not hold (a device without the mirror, memory outside its range) is copied as before. New
log line per in-place heap: pages filtered and slots changed per submission and per frame, the ms, and the V#
halves read as the title wrote them. arena_gpu_read reads the arena with the GPU after the mirror's last bind
(tests).
Test: d3d12_heap_in_place_test (Wine, iGPU): a heap in physical pages of an XMemVirtualAlloc reservation; the GPU
reads, below 4 GiB, a V# into nobody's memory and a data word null and V#s into the arena and the mirror as written,
while the title's bytes stay as written byte for byte; a rewrite through the title's own view reaches the GPU at the
next refresh, filtered, and the title keeps what it wrote; the null slots read zero. It fails on the copy path. Linux
ctest 123/123.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The title writes the same words into thousands of slots of its console
descriptor heap, many of them data that reads as a V# into title memory
with no copy, and each fix_vsharp of those costs VirtualQuery calls: a
third of the submitting thread's time after the story load under Wine.
refresh_console_heap now keeps fix_vsharp's answers for the pass over the
copied slots and, separately, for the pass over the slots the changes
since the last submission touch, and drops them after each.
Retail boot, Proton, RTX 3090, 900 s: heap refresh after the story load
107.8 -> 18.8 ms a submission (max 5,332 -> 1,109), submissions after it
1,977 -> 2,527.
AI-assisted; tested under WineHQ 11.22 and GE-Proton11-14 on an RTX 3090
(NVIDIA 590.48.01).
Unlocking a mutex on another thread is undefined; MSVC's runtime throws, and under
Wine the test stopped on msvcp140's missing _Throw_Cpp_error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Step C, with the previous WIP commit.
- Resource::create_mirror_buffer: a slot-133 buffer over title memory the mirror holds in one chunk is bound to that
chunk at heap_base + its title address: no import, no shadow, no per-submission walk or guard of its own. Its GPU VA
is the title address; V#s and root views naming it keep that address. Title windows and stream-pool extents are not
made for mirrored memory (resolve_title_memory answers the mirror first, since step B).
- Write-back (DeviceState::page_mirror_write_back, from write_back_titles after the reaching submission retired): the
256-byte pieces whose home differs from the title's page are written back through kernel_writes, on pages nothing
wrote since they were last armed (TitleMirrorTracking::unwritten); a page written on both sides keeps the title's
bytes, which are uploaded over the home before the next submission. Ranges are noted (note_title_write, with its
caps) where a V#, a writable geometry range, a title-memory resolution or a BVH range is answered by the mirror.
- The mirror's tracking is HotColdTracking (src/title_mirror_hot_cold.h); it now answers unwritten() for cold pages
from the version its guard was armed at (an additive change to that file and to the interface, default false).
- Homes go to device-local memory while VK_EXT_memory_budget keeps 1.5 GiB (or an eighth of the budget) for the
title's textures and render targets after a unit, to host memory otherwise, decided per 32 MiB unit and logged when
it switches; the mirror's line and the mem-probe item count units of each kind.
- The mirror's line adds hot and cold pages, write faults, hot and cold copies, and KiB uploaded a submission and a
frame.
Not moved: the XMemAlloc heap (HeapCreate places it). RtlCreateHeap over a reservation in the mirror's range faults
under Wine (it writes the reserved base), so it stays outside the mirror; slot-133 buffers there keep their shadows.
Tests: d3d12_page_mirror_test (Wine, iGPU): a slot-133 buffer over mirrored memory has the title's address as its GPU
VA and is no shadow; a GPU write into its home goes back to the title's page (one 256-byte piece), a page written on
both sides keeps the title's write. Linux ctest (llvmpipe) 122/122; xmem_test OK.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The demanded job leaves the running list only after its function returns,
so has_compile_waiter() could still see it right after the log said it had
finished (1 failure in 10 runs). Found while merging this into #2275.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v_dot4_i32_i8, v_dot4c_i32_i8, v_dot4_u32_u8 and v_dot4c_u32_u8 become one
OpSDot / OpUDot on the packed bytes plus OpIAdd for the addend, and
OpSDotAccSat / OpUDotAccSat under clamp (both saturate the addend plus the
exact sum, as the hardware does). op_sel halves are put together into one
dword first. RADV did not re-form v_dot4 from the old expansion (four
extracts, multiplies and adds each), which made the FidelityFX upscaler
passes ALU bound.
--integer-dot-fallback keeps the expansion for a device without
shaderIntegerDotProduct (required by Vulkan 1.3): vk_subgroup_info.py
reports integer_dot_product and make_game.py turns the flag on where it is
false. The runtime and vk_pipeline_check enable the feature where the
device has it; the interpreters of the semantic tests run the new ops.
Tested: tests/semantic/test_packed_dot4.py (new fixtures), the translator
suite, tools/dot_diff.py on the four ops, a wave32 GPU program on the
Radeon iGPU (gfx1036) and the RX 7900 XTX against the gfx1036-measured
words, RADV statistics of the upscaler passes (docs/design.md row).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cs_pk_mul_lo_const runs 32 lanes that each store 16 bytes, 128 words, but
run_gpu_tests.py and check.py ran it without VKC_OUT_WORDS, so
vk_compute_test gave it the default 64 and lanes 16-31 wrote past the
buffer through its device address (GPU-AV:
VUID-RuntimeSpirv-PhysicalStorageBuffer64-11819). Both runners now pass
VKC_OUT_WORDS=128 (check.PK_MUL_LO_ENV), and the fixture's Run line
says so.
run_gpu_tests.py's dump rows (the bounds group, cs_heap_init,
cs_user_sgprs) showed the printed words whenever there were any. A run
that printed the right words and then exited non-zero (validation
errors) was a FAIL that showed only the expected words. dump_result now
reports "exit N: <output>" for a non-zero exit.
Found by kevincommits in the coordination issue (#1608).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Step B. Where the page mirror holds a title range, every reader takes the title's address as its shader VA (heap_base +
address is the mirror's chunk), so no geometry copy, pool extent or title buffer is made for it:
- vsharp_address (title memory, after the alias table: slot-133 buffers keep their shadows until step C),
geometry_va, resolve_title_memory (before pool extents and windows), copy_title_range, make_title_buffer (vertex and
index views), device_reachable;
- VulkanContext::buffer_at falls back to the mirror (set_mirror_buffer): a vertex, index, copy or indirect binding of a
mirrored title address is its chunk and offset, cut at the chunk's end (counted).
Ordinary memory is mirrored when a reader first names it (page_mirror_resolve: each page its own home, watched, then
filled; at most 256 MiB not yet mirrored at once, else the old backing), and leaves on release or decommit
(geometry_writes::note_released). xmem also places the title's own VirtualAlloc reservations in the mirror's range, and
records which reservations are ordinary memory. The binds go in one batch at the end of the before-execute hook
(flush_page_mirror), after every reader of the submission has named what it reads.
The geometry copies remain only for title memory outside the mirror (the XMemAlloc heap) and on devices without the
mirror (llvmpipe). The mem-probe breakdown line has a "page mirror" item: units allocated, homes bound, pages
mirrored, chunks; the mirror's line counts ranges resolved, refused, ordinary pages mirrored and released, and
bindings cut; the console heap line counts V#s resolved into the mirror.
Not here: write-back of GPU writes into mirrored pages to the title's pages. The geometry copies these readers used
had none either (only slot-133 shadows do, and they stay until step C), so nothing is lost; the per-page rule for
pages dirty on both sides comes with step C.
Tests: d3d12_page_mirror_test (Wine, iGPU): committed XMemVirtualAlloc memory named by a constant-buffer view keeps the
title address as its V# base, the GPU reads it and a later title write there; a binding of it, and of a GPU-only pool
page, is served by the mirror's chunk; a page named on its own is mirrored. memory_breakdown_test: the new item.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On the console a texture access loads the T# and samples. Translated shaders hashed the eight T# words and probed up
to eight slots of the descriptor table for every access: 62 lookups and 19,714 RADV instructions in the tiled-lighting
pixel shader (3,080 in the native program).
The layer now writes the index into dword 6 of every T# in the heaps shaders read, as TAG 0xA [31:28] | storage kind
[27:23] | sampled kind [22:16] | index [15:0] (gfx10_descriptors.h, tsharp_index_word): the console resource heap
copies (fix_console_slot, again whenever the texture at the T#'s address comes, goes or is replaced) and its own
shader-visible heaps (write_image_descriptor, refreshed for bound tables by scan_title_table). The title's bytes and
the T#'s table key keep the title's dword 6.
The translator (tools/descriptor_sources.py, Gen.tsharp_index_sgpr) follows the SGPR dataflow and takes the index from
dword 6, with no lookup, for every T# whose dword 6 it traces to a heap slot (an s_load from a 32-bit descriptor-table
or heap pointer in user data); index 0 unless the word has the tag and dword 3 names an image. Other T#s are looked up
and prefer a tagged word. S#s keep the lookup (sampler heaps are read in place; 40% are literals).
Over the 1.0.2.1 corpus (tools/descriptor_source_census.py) 438,353 of 439,415 T# operands (99.76%) take the word and
17,432 of 17,540 modules keep no T# lookup; no scalar instruction reads dword 5-7 of a heap T#. RADV on an RX 7900 XTX,
lighting shader: instructions 19,714 -> 17,568, latency 73,690 -> 32,458, inverse throughput 16,453 -> 7,468.
Modules record "tsharp_index": "dword6"; the runtime writes the word when the library's modules read it, so packs
translated before keep working as they did. LEONIDA_CONSOLE_HEAP_GPU's pass copies T#s as written, so such a library's
console heaps are fixed on the CPU.
Tests: tests/semantic/test_tsharp_index_word.py (interpreter and dataflow), gfx10_descriptors_test, shader_library_test;
ps_texture_sample and ps_table_fetch now load their T# through a table pointer and vk_texture_test writes the word
(integrated GPU, RADV).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With LEONIDA_COMPILE_THREADS=1 (the layout of main: one general worker and
the graphics-only one) next_locked did not look at the owner, so two variants
of one graphics PSO could build at once, one on each worker. A last Release
meanwhile hands the PSO's deletion to the running build it finds first
(after_running), and that worker deleted the PSO while the other was still
in build() on it. The single-worker selection now skips a job whose PSO has
a build running, as the pool already did.
New test in d3d12_compile_pool_test: two graphics variants of one PSO with
one worker plus the graphics worker; the second must not start while the
first runs, another PSO's build still uses the free worker, and a last
Release runs after the first build with the second dropped. It fails
without the fix.
Docs: the heavy count also bounds LEONIDA_SERIAL_BIG_COMPILES=0 on the
workers; only compute creates pass the compile gate.
Found by qhukz13 in review of #2233.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two always-on lines every LEONIDA_SUBMIT_FRAME_SECONDS (10 by default, 0
off), from the counters the phase line already keeps and a few more:
[rt] submit frame: frames presented and, per frame, the submissions by
queue kind and the milliseconds the title's threads spent in the layer:
the existing phases counted per frame instead of per submission, plus
what the phase line leaves out - ExecuteCommandLists outside the phases
(list unwrapping, the console's list-value waits and writes, the queue
lock), the queues' Signal and Wait, and the present. Inside those, the
vkQueueSubmit calls and waits for contended submission-path locks are
given apart. Then the window's worst frame and the time of our own
threads per frame: the submit worker (LEONIDA_SUBMIT_ASYNC), the texture
read threads and filler, the console heap resolver, the geometry
refresher, the list values' pump and releaser, the fence callbacks.
[rt] submit floor: how many submissions changed nothing (no heap slot or
page, shadow page, geometry, texture fill or pipeline build), their
average and least cost and their phases, against all submissions.
Title calls are timed once, at their outermost entry, less the phases
inside them; a WorkerScope marks our own threads so their phases are not
counted as the title's. A frame ends at each present the presenter takes.
submit_frame_test checks a scripted run on the CPU (frame sums, title and
own threads, worst frame, floor) and, with a Vulkan device, that the floor
of 20 empty submissions through VulkanQueue sums to exactly what the
phase totals grew by.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two additive hooks in src/title_mirror.h for console descriptor heaps read in place; nothing changes for a mirror
that uses neither.
- alias(lo, hi, buffer, offset) / unalias(lo): the pages of [lo, hi) are also bound into `buffer` at offset +
(va - lo), follow their remaps and unmaps, and go in the same bind batches as the chunk binds, so the one wait
(VulkanContext::note_mirror_bind) orders a reader of either address. A heap uses it to be read below 4 GiB of the
arena, where 32-bit descriptor-table pointers reach. Pages not mapped stay unbound there and read zero.
- filter_range(lo, hi) / unfilter_range(lo) and TitleMirrorHooks::filter: the home of a page in a filtered range is
filled through the filter (the title's bytes in, what the GPU reads into the home), fresh when the home is made or
its filter changes, not fresh on a refill after a write (the home then holds the filter's last output). The
title's bytes are never written: the filter writes the home only, which is the mirror's own GPU memory. A home
shown at a filtered and an unfiltered address holds the filtered bytes; when the filtered address goes it is filled
as a copy again. home_bytes(va) gives a mapped page's home for writing one changed slot between fills. The
counters count filtered fills.
Test: title_mirror_hooks_test (no GPU, fake handles): binds into the second buffer with the chunk binds, after a
map, a remap and an unmap, and none after unalias; filtered fills fresh and not, a copy outside the range, a home
shown twice, refiltering a mapped page, unfiltering, and the title's bytes unchanged. vk_title_mirror_test passes
as before (Ryzen 9 7950X3D iGPU, RADV, Mesa 26.3.1, under validation).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25,865 of the corpus's 26,503 shaders keep only the low 32 bits of a descriptor-table pointer (docs/d3d12_vulkan.md,
"Descriptor-table high-dword truncation"), so a console heap whose pages live in the page mirror at heap_base + the
title's address (tens of TiB up) must also be readable at heap_base + an offset below 4 GiB: in the sparse arena.
The mechanism is a second sparse bind of the same home. On a real device, with no shader: one VkDeviceMemory bound
into two sparse aliased buffers shows the same bytes through both, for CPU writes into the home and GPU writes through
either buffer; the arena pages after the heap, with nothing bound, read zero (the null-slot guard needs no memory);
unbinding the mirror's view leaves the arena's. Skips (77) without sparse aliased buffers with strict residency.
Ryzen 9 7950X3D iGPU, RADV, Mesa 26.3.1: passes, 0 validation errors; llvmpipe skips (no strict residency).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HotColdTracking (src/title_mirror_hot_cold.h) implements TitleMirrorTracking (watch, unwatch, collect) over the
geometry watch's cells with TitleWritePolicy, so it can replace GuardTracking with no change in the mirror:
collect() returns the pages written since the last collect, each armed again first, and every time the pages
written so often that they are left writable. One collect is one interval of the policy's history.
A hot page's probe is now armed at the collect after it is asked for and judged on the interval after that;
judged on the interval of the arming itself, a page written every interval looked quiet and was turned cold
(seven promotions and six demotions of one page in 200 intervals). Test title_mirror_hot_cold (Windows, real
guards and a handler that does what the layer's does first): the page written every interval stops faulting
(12 faults in 200 intervals, the warm-up and the probes), the page written every 10th faults 19 times, and the
copy the collects name equals the memory after every collect.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
guard_fault_bench (Windows, prints a table): VirtualProtect per call and per page from 4 KiB to 4 MiB, one write
fault through a minimal handler and through the geometry watch's cells on one thread and on eight, re-arming a
tile, GetWriteWatch on private memory and on a section view, and Linux's soft-dirty bits through Z:\proc\self.
Under Wine on this machine: a fault 2-2.5 us, a tile re-armed 3 us, VirtualProtect 1.3 us for 4 KiB and 8 us for
4 MiB in one call against about 1 us a page one call at a time; GetWriteWatch works on private memory (37 of 37
pages) and not on a section view (error 87, as on Windows); soft-dirty bits read back clear (not usable here).
The geometry watch's cells reopened a faulted tile page by page, a VirtualQuery and a VirtualProtect each (16 us
a fault): reopen() now does one query and one protect per region of equal protection (5.3 us; 5.8 us of wall
time a fault with eight threads faulting, from 24).
TitleWritePolicy (src/title_write_policy.h, portable): pages written in most intervals are left writable and
copied at every collect, the others guarded and copied once a write faults; a page is armed before it is named,
so a write during the copy is in the next collect; hot pages are probed (guarded for one interval) every 32. Test
title_write_policy: scripted (hot stops faulting, cold faults once an interval, a quiet hot page turns cold) and
randomised against a byte-exact reference, writes during the copy and refused guards included.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A V# or 64-bit pointer the title writes into its own memory names a title address, and the translated shaders read
heap_base + sext48(address). Nothing was there: run 63 lost the device on such a V# into the stream pool's GPU-only
window, which read zeros before step 2. The mirror puts the title's bytes there.
- src/title_mirror_space.h: xmem places every XMemVirtualAlloc reservation the title lets it place (address null) in
[16 TiB, 48 TiB), handed out in order at reservation time, so no title pointer ever holds an old address. RADV makes
sparse buffers at a chosen address only in its top 64 TiB, where heap_base (the sparse arena) is; heap_base + an
address there stays inside it. A reservation the range cannot take is placed by the host, as before.
- src/title_mirror.h (TitleMirror, Vulkan through hooks): 2 GiB sparse chunks at heap_base + title address
(bufferDeviceAddressCaptureReplay), one home per physical page (64 KiB of a 32 MiB host-visible unit), every page
that shows a physical page bound to its one home (aliases share bytes and GPU writes; a remap is a rebind), the binds
of a submission in one batch (the last bind of a page wins), homes freed after the retire ticket.
- src/title_frames.h Feed/Attach, xmem: every change of what a page of the range shows (host views in note_mapping,
table pages in note_table_page), in order, with the physical page's scratch bytes; attaching feeds the pages mapped
now under g_phys_mutex.
- src/title_mirror_tracking.h: the dirty set behind a small interface (watch, unwatch, collect: re-armed before the
caller copies), with GuardTracking (a geometry-watch cell guard per page) until a measured policy replaces it.
- DeviceState::create_page_mirror / refresh_page_mirror (first in the before-execute hook): chunks for new
reservations, the feed bound, written pages filled again once, the batch on the arena's bind queue signalling a
timeline value; VulkanContext::note_mirror_bind makes every queue's next submission wait for it (the ordering rule).
Off, with one line saying why, without capture-replay addresses, aliased strict sparse buffers, the bind queue, a
sparse arena, signed V# offsets, xmem or the write-fault handler (llvmpipe), or with LEONIDA_PAGE_MIRROR=0.
page_mirror_covers / page_mirror_address for the readers that move onto it. A log line every 10 s.
Tests: vk_title_mirror_test (native and under Wine, Raphael iGPU and RX 7900 XTX): a title-written V# read from a buffer
and dereferenced as the translated shaders do reaches its page, an alias the same, an unbound page reads zero; a remap,
a write (one upload for two aliases) and an unmap reach the next dispatch that waits for the batch; a home is freed only
after its ticket. d3d12_page_mirror_test (Wine, the game's device over xmem's pages): after slot-31 copies the GPU-only
page, its twin and the title's view hold the bytes at heap_base + address; a title write through its view reaches them
with one upload; a remap is a rebind with no host remap; an unmapped page reads zero. xmem_test: reservations land in
the range, the pair still pairs, the feed reports attach, host maps, table copies and unmaps in order, nothing after
detaching. Linux ctest (llvmpipe) 121/121.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Raphael iGPU, RADV, natively: a 3 GiB sparse buffer asked for at 0xffffffb4a0000000, 0xffffffb8a0000000 or
0xffffffff00000000 is made exactly there; one asked for below 0xffffc00000000000 is made 0x400000000000 higher
(RADV's sparse range is the top 64 TiB), and 0xffff800100000000 is refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The heap phase in the 3D opening of one world run: fixing slots 6.4-7.5 ms a submission for about 2,000 changed
V# halves; the V# resolution counters there are device-wide (2,904 resolutions a submission against 1,340 changed
halves) and say nothing about the heap.
A resolved record is fixed again by every release or removal of its range or its copy, so while it stands, a
resolution of the same exact range made the same way gives its answer: a rewritten half now takes it from a current
record of its range (ConsoleHeapSlotRecords::answer, the resolved records kept by whether they asked for a geometry
copy, as the waiting ones), after the changes noted since are applied, as for waiting answers. Nothing else of a
resolution is lost: a window's write-back is noted per submission and an unchanged slot is not resolved again
either.
New per-heap line every log window: halves answered by a resolved record and by a waiting one, halves resolved anew
with their time, the classes of those that resolved to nothing (a copy not backed, an arena offset, bit 47, no copy
asked, not title memory, past its range, a buffer's, private pages, no room, pool alias, other; geometry_va reports
why it gave no copy), the longest refresh with its parts (pages, changes, slots), and the waits for the heap lock,
which the heaps phase of the submit counters includes.
Test: in the 400 random rounds half the writes take a record's answer, resolved or waiting, each checked against a
resolution at that moment (a copy that skips applying the changes noted since fails). Linux ctest 120/120.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ms_w64x_wave_loops: each wave loops while a wave-wide count is not 0, 5 iterations in wave 0 and 9 in
wave 1, so under --wave64-emulate the waves reach different numbers of workgroup barriers. Written after
stalls were reported with the serial form on an RTX 2070 SUPER (issue 1608). On an RTX 4080 (NVIDIA
621.24) it draws 4096/4096 pixels exact side by side and in series; that does not explain the stalls.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A measurement for the page mirror's layout, not a ctest: a 3 GiB sparse buffer and a 256 MiB pool, binds of 1 to
4,096 64 KiB pages with scattered or ordered memory, unbinds, one page at many offsets, and a remap load of 63
calls of 32 pages. Raphael iGPU (RADV, Mesa 26.3.1), natively: the call returns in microseconds, the binds complete
at about 43 us per page with scattered memory and 21 us per page with memory in order (no coalescing), unbinds about
21 us per page; 2,016 scattered pages took 105 ms.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#1920 stops a new pool extent at the next mapping in either view and, in
d78b0e90a, refuses a mapping shorter than the request: such a request
gets a zero-size view (loads 0, stores dropped). That keeps the views from
reaching past their copies, which the first version of this fix did not,
but a refusal is a regression for requests main served: a V# or a root
view (64 KiB, kRootViewBytes) that crosses from one extent into the next,
or starts inside one and ends past it. Stream-pool extents sit next to
each other, so these are common. Retail runs (local, RTX 5080): our
first version, which gave such requests a short mapping, crashed in the
title in one run (m176); with one mapping over the request instead, runs
m177-m179 ran without one. The crash's cause was not established.
At #1920's two refusals of a request longer than what would serve it
(the extent clipped by clip_title_pool_extent, or the mapping holding its
first byte), resolve_pool_memory now tries, after #1920's reuse,
cover_pool_request: one mapping over the request and every window it
reaches, each whole, in both views (title_pool_cover). It is entered with
the new TitleVaAliases::replace_twin, since add_twin refuses an overlap;
the windows it replaces are retired at the next submission like any
window nothing answers from (previous commit), and their bytes are not
charged to the budget twice meanwhile. With a range in the way that is not
a window (a slot-133 buffer, a geometry copy), or pages that are not
readable, #1920's refusal stands. #1920's own refusal when the window
cannot be made or entered is unchanged.
TitleVaAliases::resolve and resolve_title_memory already ask again for a
range that ends before the view (#1920); vsharp_address did not, so a
V# whose base lies in a short range was refused without asking: it now
asks resolve_title_memory first.
Tests: #1920's pass unchanged (their seam cases cross a range that is
not a window, which still gets a zero-size view). title_window_plan: the
cover takes a window whole in both views, refuses a buffer in the way and
past the cap, and replace_twin enters it where add_twin refuses.
d3d12_title_window_orphans: a 64 KiB CBV across two extents' seam gets
one 448 KiB mapping, a valid V# and the right words on the GPU, and the two
extents are retired at the next submission; without the cover its V# base
is 0.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
On top of #1920, which keeps stream-pool extents inside the free span in
both views and makes TitleVaAliases::add_twin refuse an overlap. Other
ranges still replace a window's ranges whole by design: a slot-133 buffer
the title places over the window's pages, a BVH input's exact copy, an
upload alias. The window was then left in title_windows and pool_spans,
refreshed at every submission and charged to LEONIDA_TITLE_WINDOWS_MB, with
nothing left to reach it. A retail run showed most of the windows' memory
growth to be such orphans; the title released none of the windows' pages,
so retiring a window with its pages never fired.
A window no range answers from any more is retired after the next
submission's refresh: the alias table's listener records removed ranges'
copies, and the touched windows TitleVaAliases::answers_into finds
unreached leave pool_spans and the budget at once.
Its memory is freed only once nothing can still reach it. A command list
resolves its root views when they are recorded (GraphicsCommandList::
address), so a list recorded before the retirement and executed, or
executed again, after it still names the window; so does the copy of the
lists a held batch (a Wait before its Signal) or the async worker keeps.
Each backend CommandList, and each copy, now carries the epoch its
recording began in (src/command_list_epochs.h); a retired window takes its
ticket only once no list older than its retirement is alive and the
replays in progress then have recorded their submissions, and is freed
when that ticket has completed.
Until then the copy stays a target of its pages' tracker, still
refreshed, and what the GPU wrote in it goes back to the title's pages:
with its submissions' write-back, and once more when it is freed. The
second is needed because a list's ranges are noted when it is recorded,
so a held batch's can go back, tagged with a later submission's ticket,
before the batch has run. A retired copy goes back only where no live copy
changed the bytes, and every copy is compared, 256 bytes at a time, with
the title's bytes as they were before any copy went back: a copy that
still held them used to overwrite another's result when it came later in
the tracker.
Tests: d3d12_title_window_orphans. A window a slot-133 buffer replaced is
retired, its bytes returned and its memory freed. A writing batch held on
a fence on another queue, recorded before the next submission's refresh
retires its window, keeps the window alive past a completed submission,
and once it has run and its list is reset, its 64 words reach the title's
pages and the window is freed. Without the retirement the window stays
(3 -> 3 windows); without the list epochs it is freed while the held batch
still names it; without the last copy back 0 of 64 words arrive.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
Run 62 died on a write to a title page left read-only with no guard to answer for it ("stray read-only title
page ... no guard owns it"). TitleVirtualProtect passed the title's call straight through: over a page one of
our guards (a slot-133 shadow's, or a geometry-watch cell, which the title texture watch now arms over all
watched texture memory) had made read-only, the call returned that read-only protection in `old`, and its
Event::replaced made the cell forget the page. A title that saves `old` and sets it back later then made the
page read-only for good, with no owner, and its next write faulted.
The call now runs under a kernel-write pin over the range (kernel_writes::begin_write, as ReadFile does): our
guards come off first and no refresh puts one back until it returns, so `old` is the title's own protection.
Test: d3d12_xmem_placed's "title VirtualProtect over a guard" (an armed cell, the title's VirtualProtect to
read-write and back to what it reported, then a write); it fails without this (`old` is PAGE_READONLY).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found by two world runs on the step-2 build (60, 61) that lost the device at the start of the 3D opening with a GPU
read of a garbage address, deterministic, where a run without step 2 (62) went past it.
map_table_page returned early when the table page already held the copy's page number. A number is not a page of
memory: XMemFreePhysicalPages puts the slot on g_free_slots and the next XMemAllocatePhysicalPages takes it back
first, naming a page of a new section. A stream pool's pages are freed and allocated again while the title keeps the
table entries, so the next copy of the same number left the table page on the freed page's frame (its entry holds
that section alive), and the readers of the GPU-only page and its CPU twin got the freed page's old bytes. Before
step 2 the twin was a host view, and map_page maps the number's current page every time, so the readers followed;
the GPU-only page had no readers.
The early return now also requires the frame the entry holds to be the number's current page (section and offset).
Test: xmem_test test_copy_page_mappings_reused_number: copy a page onto a paired GPU-only page, free it, allocate
again (the same number, asserted), map and fill it, copy again: the GPU-only page and its twin read the new page.
It failed before the change ("the table pages read the new page behind the number, not the freed one") and passes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DadaCap identified the short-mapping case in the review of PR #1920. Reuse and allocation now require full coverage, preserving both live aliases when a request spans a boundary.