Commit Graph

1118 Commits

Author SHA1 Message Date
6014cb1c84 Merge #1851 into consolidate/eight-gb-world 2026-11-27 22:16:27 +01:00
00f317f0c7 Merge #2166 into consolidate/eight-gb-world 2026-11-27 22:16:26 +01:00
c20733f622 Merge #2020 into consolidate/eight-gb-world 2026-11-27 22:16:26 +01:00
5e8d3349c8 Merge origin/main into window-retire-on-1920
submit_write keeps main's second root UAV (va2) and our wait flag: (s, va, va2 = 0, wait = true); the two callers that only execute pass va2 = 0 explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwSKP7weM2P7sk5skto
2026-11-27 19:25:41 +01:00
fdd58296f7 d3d12: fix console heap in-place filtering and TitleMirror home.sums sync
Root-cause fixes for four audited bugs in console heap in-place filtering
and TitleMirror:

1. finish_in_place() not_tsharp zeroing & record clear:
   Check gfx10::is_image(words) and TitleImage::not_tsharp in
   finish_in_place(), zeroing w[0..3] and clearing heap.records on
   (w[3] >> 30) slots with d.texture == Records::none (matching
   fix_console_slot) so non-T# overwrites of deferred slots never leak
   raw words into home[slot] or leave stale texture records.

2. Record-answered / batch_answers mirror write-back tracking:
   Call note_title_write(base, span) outside page_mirror.mutex when
   apply_answer() (in finish_in_place) or answered_by_record() (in
   fix_vsharp) returns a mirror-resolved identity target
   (to == base && base >= arena.size), matching vsharp_address path 6.

3. reachable_as_written() & filter_slot_locked() semantic parity:
   - Reject base == 0 in reachable_as_written(), check encodable() +
     gpu_backings + geometry.lookup, and accept bit-47 base | ~mask
     direct backings even when signed_vsharp_offsets() is off (matching
     vsharp_address:4367, 4392). Track non-sparse direct backings as
     Records::resolved so target_gone re-filters them if freed.
   - Keep O(1) permanent rejection (Records::none) only for null base,
     unbacked bit-47, and out-of-arena-span offsets (base < arena.size
     not in title_memory, aliases, or stream-pool GPU views).
   - For unresolvable base >= arena.size halves (not in title_memory
     within span, no alias, no stream-pool GPU view), null in O(1) and
     record Records::waiting directly without deferring so a later
     SlotChange::source_added still wakes and re-filters them.

4. TitleMirror single-snapshot home/sums/copy sync:
   Unify home, home.sums[], and filtered copy updates through a single
   fill_scratch_ snapshot across map() (initial aliased fill & alias
   handoff), make_copy(), and finish_write_back(), preserving GPU-only
   pieces on existing homes so A -> B -> A writes never leave stale
   filtered copies and avoiding duplicate guarded copies.

Tests:
- title_mirror_hooks_test: added make_copy_aba_staleness (make_copy,
  alias handoff, finish_write_back A->B->A) and updated
  filter_pieces_mask_and_scratch for unified single-copy initial map.
- console_heap_slot_records_test: added waiting_source_added_and_tsharp_clear.
- d3d12_heap_in_place_test: added deterministic finish_in_place not_tsharp
  zeroing and late-alias wake-up regressions.

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-27 13:22:49 -05:00
4442c5b646 runtime: restore kPromote=6/8, drop frame_hot over-copying, and wire region-batched MEM_WRITE_WATCH
- TitleWritePolicy (runtime/src/title_write_policy.h): restore kPromote = 6
  (of kHistory = 8) and cleanly remove the frame_hot / present_frame() tier
  and its dead fields/counters so 1/frame pages never trigger per-submission
  over-copying or copies on empty submissions. Keep O(dirty + hot + recent)
  active lists and sorted Guard::arm_batch() batching.
- HotColdTracking (runtime/src/title_mirror_hot_cold.h) & d3d12_vulkan_device.cpp:
  remove the dead on_present() / last_present_serial hook (coordinated with
  gate-async-fixer) and unused write_watched_* getters, and cache
  region-batched MEM_WRITE_WATCH runs (bridging verified MEM_COMMIT gaps <=
  1 MiB, capped at 64 MiB per GetWriteWatch call, never bridging uncommitted
  holes, with O(1) unordered_set dirty filtering and conservative dirty
  recording + split-retry on mid-run refusal so no journaled write is lost)
  so steady-state collect() runs in O(regions + dirty) without walking
  ww_pages_.
- TitleHeap (runtime/src/title_heap.h) & xmem.cpp: upgrade for_each_committed()
  to emit maximal coalesced committed extents (exact complement of free_runs_,
  O(free_runs_.size()) instead of scanning all 32k span slots, never spanning
  uncommitted holes) and wire MEM_WRITE_WATCH with silent MEM_RESERVE fallback
  + title_write_watch registration/marks in mirror_heap_ready() (never
  combined with MEM_LARGE_PAGES, MEM_PHYSICAL, or section views).
- Tests: update title_write_policy_test.cpp (kPromote = 6/8 and zero copies
  of 1/frame pages on empty submissions) and title_heap_test.cpp (coalesced
  for_each_committed() tracking around decommitted holes).

AI-assisted: Antigravity, Gemini 4 Neon
2026-11-27 11:44:26 -05:00
c0201a806b Merge pull request #2467 from OreoFR/rt-async-min-bytes-graphics
d3d12: LEONIDA_ASYNC_MIN_BYTES_GRAPHICS, a separate async threshold for graphics (RT-ASYNC-MIN-BYTES-GRAPHICS)
2026-11-27 17:26:46 +01:00
d7b81dd43b Merge upstream/main (with #2468) into rt-title-writeback-same-page-ranges
#2468 (RT-WRITEBACK-TILE-REOPEN) took write_back's per-page held decision
before the copies for one range. This branch takes it for all of a tracker's
ranges in one call, so the two are now one snapshot over every range, kept in
#2468's host-heap member held_pages_ (sized before lock_ is taken). Both tests
stay: d3d12_title_window_write_back_fault_tile and
d3d12_title_window_write_back_ranges; submit_write takes both va2 and base.

Also from lixonik's review: a run whose pages an earlier range already
reopened (none still kProtected) skips reopen_locked and its VirtualQuery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 10:08:23 -06:00
55bd6f4f1b Merge pull request #2468 from OreoFR/rt-writeback-tile-reopen
d3d12: a write-back's later runs in a tile its faulting copy reopened still go back (RT-WRITEBACK-TILE-REOPEN)
2026-11-27 17:01:56 +01:00
e83f9fdfad d3d12: wire TitleMirrorHooks::filter_pieces and HotColdTracking::on_present
- Hook filter_heap_page_pieces() into TitleMirrorHooks::filter_pieces so in-place console heap filtering reuses TitleMirror::fill()'s scratch buffer and scans only changed 256-byte pieces.
- Call HotColdTracking::on_present() from refresh_page_mirror() under page_mirror.mutex whenever submit_phases::totals().present_serial advances.

AI-assisted: Antigravity, Gemini 4 Neon
2026-11-27 10:53:38 -05:00
5543ba9f5f d3d12: eliminate orphan title windows, align mirror chunks, and speed up in-place heap filtering
Round 1A:
- Use VsharpPath::scratch for in-place console heaps in finish_in_place and fix_console_slot so they never allocate general-purpose title windows.
- Never fall through to make_title_window / ShadowPages in resolve_title_memory for addresses already covered by the page mirror.
- Guard vsharp_address's window-creation fallback with bytes <= kTitleWindowMax so oversized V# spans cannot allocate and reject orphan windows.
- Advance <= 2 GiB reservations in title_mirror_space::take past chunk boundaries so placed buffers stay within a single 2 GiB sparse chunk.
- Track arena-backed title windows and slot-133 shadows under ArenaUse::arena_window and report them in memory_breakdown.

Round 1C:
- Add re-entrancy-safe two-pass filter_heap_page_pieces() ready for TitleMirrorHooks::filter_pieces changed-piece mask.
- Reject guaranteed-unresolvable V# halves (null, unbacked bit-47, out-of-arena spans, non-title addresses without an alias) in O(1) inside filter_slot_locked without inserting into heap.records or deferring.
- Clear deferred slot records before finish_in_place and answer repeated V# halves from heap.records under page_mirror.mutex plus a per-batch dedup cache.

Tests:
- Added Linux unit tests in console_heap_slot_records_test (chunk alignment, arena window breakdown, deferred record clearing/answering).
- Added Wine regression tests in d3d12_heap_in_place_test and d3d12_page_mirror_test.

AI-assisted: Antigravity, Gemini 4 Neon
2026-11-27 10:51:23 -05:00
4392670a76 d3d12: a freed window's last bytes reach the live copies too (RT-TITLE-WINDOW-RETIRE)
retire_orphan_windows frees the retired windows whose submissions have
completed after this submission's refresh_shadows, and freeing writes
the window's copy back to the title's pages once more
(free_retired_shadow). The refresh had already copied those pages to
the live copies, so the slot-133 buffer that replaced the window read
the older bytes until the next submission.

Moving the free ahead of the refresh, as suggested, is not enough on
its own: the write-back opens the pages it writes, and the refresh's own
copy back of the live copies' batches (write_back_titles) then takes
those pages for ones the title wrote and drops the buffer's GPU results
there (measured with this test: with the free moved first, the words
written through the buffer did not all reach the pages). So the free stays after the refresh, and a
retired copy's bytes that go back are written into every other copy over
them that still held the title's older bytes, as the next refresh would;
a copy that changed a byte keeps its own. Under lock_, in place, no
allocation. The epoch/ticket gating (src/command_list_epochs.h,
stamp_retired_windows) is untouched.

d3d12_title_va_test --window-orphans: the submission that frees the
window reads the held words through the buffer placed over the ring.
With LEONIDA_TITLE_WRITEBACK=0 (d3d12_title_window_orphans_free) it read
0 of 64 before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
2026-11-27 16:38:53 +01:00
7afb87266f d3d12: a retired window's copy goes back byte by byte (RT-TITLE-WINDOW-RETIRE)
ShadowPages::write_back compared the copies in 256-byte pieces and kept
one flag per piece: once a live copy had changed any byte of it, a
retired window's copy was left out of the whole piece. A retired window
and the slot-133 buffer that replaced it can have written disjoint
bytes of one piece (the window [384, 512), the buffer [256, 384)), so
the window's bytes were dropped. The batch path (`only` null) had the
same flag (`live = live || pass == 0`).

The piece now keeps a fixed 256-entry mask on the stack (no heap under
lock_) of the bytes a live copy changed, set in the first pass; a
retired copy goes back on every byte it changed that no live copy did,
in runs. Copies are still compared against the title's bytes as they
were before any copy went back, and a live copy now writes only the
bytes it changed, so one live copy no longer writes the title's older
bytes over another's result in the same piece.

d3d12_title_va_test --window-orphans: the held submission writes through
the window from ring + 384, a later one through the buffer placed over
the ring from ring + 128, and all the held words must reach the title's
pages (32 of 64 did before). The ring is write-combined so the buffer is
a copy on every driver. New ctest entry d3d12_title_window_orphans_free
runs it with LEONIDA_TITLE_WRITEBACK=0, where the window's free is the
only way back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
2026-11-27 16:38:40 +01:00
e1f82510a0 d3d12: a pool cover replaces only the windows it planned to (RT-TITLE-WINDOW-RETIRE)
cover_pool_request planned its cover (title_pool_cover) under short
shared locks of the alias table, then made the mapping and entered it
with replace_twin, which erased every range in the span unconditionally.
A slot-133 buffer is entered (Resource::alias_title_va) without
title_window_mutex, so one placed in either view of the span in between
was erased with the windows. And replace_twin's result was ignored: the
cover was recorded in pool_spans and returned as made either way.

replace_twin now takes the caller's predicate and, under the same
unique lock as the replacement, refuses with nothing changed when a
range it would erase is not one the caller planned to replace. The
cover passes the windows its plan found. On refusal the window it made
is dropped at once (drop_title_window: nothing answered from it, so no
submission names it) and the request falls back to the zero-size view
as before. The same drop now follows add_twin's refusal in
resolve_pool_memory, which left its new window charged to the budget
and refreshed with nothing answering from it.

title_window_plan_test: a non-window range entered in the cover's span
(CPU view, then twin view) between title_pool_cover and replace_twin is
refused and left intact.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
2026-11-27 16:38:40 +01:00
6eb3727130 Key page_mirror.readback_invalidated by physical frame instead of VA
Aliased VAs (e.g. CPU and GPU stream-pool views) share one home keyed by
physical frame; keying readback_invalidated by std::uint8_t* frame catches
concurrent uploads/remaps through any alias while a readback copy is in flight.

AI-assisted: Antigravity (Gemini 4 Neon)
2026-11-27 09:44:57 -05:00
ace94aef23 Fix page mirror write-back ordering, batching, lock scope, and phase accounting
Run write_back_titles() first in before_execute_() before refresh_page_mirror()
and refresh_console_heaps(), never force-drain unretired batches, coalesce
intervals in note_title_write() and across retired batches, batch GPU readback
copies without holding page_mirror.mutex across vkWaitSemaphores, stop marking
read-only CBVs/SRVs writable, hoist page_mirror.mutex in finish_in_place(),
reuse filter_heap_page scratch, gate diagnostic VirtualQuery behind
LEONIDA_VSHARP_NOTHING_DETAIL=1, and attribute mirror refresh/flush/lock waits
to submit_phases.

AI-assisted: Antigravity (Gemini 4 Neon)
2026-11-27 09:41:01 -05:00
27c1673761 d3d12: every title write-back range on one guarded page goes back (RT-TITLE-WRITEBACK-SAME-PAGE-RANGES)
DeviceState::write_back_titles handed each finished range to
ShadowPages::write_back on its own. The first range that differed reopened
its guarded page (kProtected cleared), and every later disjoint range on that
page then read as written by the title and was dropped, though only the
write-back itself had written there.

Each shadow now takes all of its finished ranges in one call, sorted by
address, and decides which pages are held once for all of them, before the
first copy. The per-page decisions are allocated before the tracker's lock is
taken.

New test d3d12_title_window_write_back_ranges: 16 four-byte ranges 16 bytes
apart on one guarded page of a title window. On main 1/16 reach the page
(3/3 runs); with the fix 16/16, and the words between them keep the title's.

Found by 73N1X in #1608.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 08:34:01 -06:00
cd219e63bc Local test merge: heap pages hold the title's bytes in the mirror; the filtered descriptors live in a copy of their own at the table address (920173613, 3a4222e0f)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 08:49:43 -05:00
3a4222e0f1 heaps in place: fix_vsharp's null back as it was; the whole null only in the filtered copy
The copy path's null of an unbacked V# keeps word 3 (d3d12_title_va_test and d3d12_geometry_views check that), so
fix_vsharp nulls three words again; finish_in_place clears word 3 itself, so a half nothing holds is null whole in
an in-place heap's filtered copy, as the filter nulls it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 08:48:28 -05:00
4e87841d8a Merge remote-tracking branch 'upstream/main' into d3d-sample-positions
# Conflicts:
#	runtime/src/vulkan_replay.h
2026-11-27 13:43:58 +00:00
920173613c heaps in place: the title's bytes at the title's address, a filtered copy of each page at the table address
The title keeps plain data inline in its descriptor heap pages and points V#s at it. With one filtered home bound
at both addresses, the filter's output reached those V#s: four words a compute program reads as sizes looked like
a V# with a base nothing holds, three of them were nulled, the program read [0 0 0 720] and spun until the ring
timeout.

title_mirror.h: alias(lo, hi, buffer, offset) gives each page of the range a second home, the filtered copy, bound
at the alias in the same batches as the mirror's binds and filled by hooks.filter whenever the title's bytes change
(a piece's sum, or write-back); the page's own home is always the title's bytes. filter_range, unfilter_range and
filtered_at are gone; copy_bytes(va) is the copy the filter's caller writes slots into; unalias takes the ticket its
copies are freed after; write_back and homes_in take every home again.

The device writes slots into the copy (apply_in_place_changes, finish_in_place). An unreachable V# half is null
whole, all four words, in the filter and in fix_vsharp.

d3d12_heap_in_place_test: inline data after a table, a V# of the title pointing at it, and a rewrite on the same
page: the V# reads the title's four words, the table the filtered entries ([0 0 0 0] for the data), the title's
bytes unchanged; on the previous commit it read [0 0 0 720] at both addresses. A GPU store into the heap's page
now goes back to the title's bytes. title_mirror_hooks_test covers the alias's own homes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 08:43:30 -05:00
462de0e187 geometry watch: a page the mirror leaves writable is hot in its cell, written for every copy of it, and written once more when it turns cold (RT-TITLE-TEXTURE-WRITE-TRACKED)
Two trackers guarded the same 64 KiB pages through the same cells: the page mirror's HotColdTracking and the
title texture watch. When the mirror found a page hot it reopened the cell behind the other's back; the texture
watch then armed it again, so the page faulted at every write for one tracker while the other meant it to be
writable (two guards racing on one page), and when the mirror turned a hot page cold for a probe, a write made
while it was hot reached no other tracker at all (the video plane's write of that interval was never uploaded).

One owner of the guard now: the cell. An owner that leaves a page writable holds it hot (geometry_writes::
set_hot); a hot cell is not armed by anyone and hot_tiles() lists it, so the texture watch takes it as written
at every pass; when the last owner lets go, the cell counts as written once more for every subscriber.
HotColdTracking holds its hot pages that way and ignores its own hot-to-cold turn (a cell that has not moved
since it was armed was not written).

Also: the FSDRAW census reset the refresh line's passes, changed and filled counters, which then read 0 uploads.

Test: title_mirror_hot_cold now runs the texture watch over the same cells as the mirror's tracking: the plane
written every interval is named at every interval, probes included, and its page stops faulting once hot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 08:34:14 -05:00
d42c37335b d3d12: LEONIDA_ASYNC_MIN_BYTES_GRAPHICS, a separate async threshold for graphics (RT-ASYNC-MIN-BYTES-GRAPHICS)
With LEONIDA_ASYNC_PIPELINES=1, graphics and mesh pipelines (all their stages) now take
LEONIDA_ASYNC_MIN_BYTES_GRAPHICS when it is set, and LEONIDA_ASYNC_MIN_BYTES otherwise, so
nothing changes while it is unset. Compute keeps LEONIDA_ASYNC_MIN_BYTES. 0 makes every graphics
pipeline asynchronous. One startup line states both thresholds; text that is not a number is
ignored with a log line.

Thread dumps from a retail run showed the draw thread building lazy graphics variants under the
1 MiB threshold in place, 2.5-11 s each, back to back, with no present for about 100 s. A skipped
draw costs one draw. The image needs the small lighting and post compute programs, and those
are still built in place.

Tests: async_pipeline_size_test covers the per-kind decision and the unset fallback;
d3d12_pipeline_workers_test --async-graphics-zero / --async-graphics-unset (new ctests) hold
the compile worker with compute over its threshold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 14:24:29 +01:00
9e204412c8 Local test merge: what the host has at V# bases that resolve to nothing; per-slot compute input diagnostic for one program (d7baefce9)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 08:24:15 -05:00
f380834f90 d3d12: a write-back's later runs in a tile its faulting copy reopened still go back (RT-WRITEBACK-TILE-REOPEN)
ShadowPages::write_back decided page by page, inside its loop, whether a page's GPU result goes back. A copy
that faults on another guard (a geometry watch cell) makes the handler reopen the whole 64 KiB tile on the
write-back's own thread (reopen_range, under the lock #2418 lets it reuse), which clears kClean and kProtected
there. The runs after it in the tile then read as written by the title: their GPU results were dropped from
a batch already taken off the queue, and the next forward copy put the title's older bytes over them.

The decision is now taken for every page of the range before the first copy, into a host-heap vector the
tracker keeps. A page the title wrote before the write-back (not guarded and not clean after the asking)
is still held, so the title's words win as before.

Test: d3d12_title_window_write_back_fault_tile (d3d12_title_va_test --window-writeback-fault-tile), the
#2418 fault case with a second dispatch on the third page of the tile and a title write on the second.
Found by DadaCap's review of #2418.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 14:20:49 +01:00
d7baefce92 d3d12: name the memory a V# resolved to nothing names, and what one compute program's V#s read (RT-PAGE-MIRROR)
Run 64w2 hung in a min-pyramid dispatch whose loop bounds divide sizes from one constant buffer by divisors behind a
V# from its descriptor table. Its log cannot name that buffer: it has no record of the dispatch. The heap's line
counts V# halves resolved to nothing (not title memory 14378, bit 47 12312, arena offset 5506 in 10 s) but not where
their bases lie.

- Always on, the console heap's "resolved to nothing" line now splits the arena-offset and not-title-memory classes
  by what the host has at the base: image, mapped, private, reserved or free (one VirtualQuery per V# half that
  resolves to nothing).
- LEONIDA_COMPUTE_INPUTS (with LEONIDA_DEVICE_FAULT) knows the page mirror. The slot words of a heap read in place are
  read from its home, where the GPU reads them. A V# base is classed mirror-home or mirror-unbound before the older
  backings. Each V# prints the host's kind of memory at its base, the title's first 16 dwords there and whether the
  GPU-side bytes differ. A slot the layer turned to null prints the title's V#, where it lies and its bytes.
  LEONIDA_COMPUTE_INPUT_SLOTS takes runs such as 5/0-15.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 08:20:02 -05:00
d0636fc7af title textures: a retired slot-70 texture forgets its address only while it still owns it
A slot-133 texture placed where a slot-70 view had made a texture of the layer's takes the address over
(place_at_title_address); register_title_texture then retires the slot-70 entry, and retire_title_texture erased the
address from images_by_address unconditionally - the placed texture's key. Every T# naming that address found no
texture ("no texture at the T# address: title memory"), the texture was never named, so never filled, and the slot
read the fallback.

forget_image_of(address, owner) erases the address and its views only while `owner` is registered there, under one
descriptor_mutex hold; retire_title_texture and ~Resource use it (the latter checked in two steps before). The views
of the retired texture left when the address was taken over.

d3d12_heap_in_place_test: a slot-70 view, then a slot-133 texture at the same address in a reservation at 16 TiB and
up, named by a T# the title writes into a heap read in place: it binds with the tag and its index, reads the fallback
(index 0, the 1x1 zeros) when the texture goes, and binds again when a texture is placed there again. It failed
(index word 0) before the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 08:17:20 -05:00
d483077913 Merge main into claude/pipeline-prewarm-order
Resolve runtime/README.md conflict after #2220 and #2233 landed on main.
2026-11-27 08:11:54 -05:00
17d3af0b65 Merge pull request #2462 from OreoFR/rt-compile-gate-auto
compile gate: `auto` default, calibrated per driver at device creation (RT-COMPILE-GATE-AUTO)
2026-11-27 14:08:00 +01:00
c1148ff101 page mirror: the write-back copies homes out with the GPU instead of reading them over the bus (RT-PAGE-MIRROR)
Run 64w spent a constant 14.5 s in a submission's shadows phase whenever new V# ranges reached the write-back. A
console V# has no read/write bit, so each new range is noted as possibly written, up to the 64 MiB cap a submission.
page_mirror_write_back then summed every 256-byte piece of those homes on the CPU. The homes are in device-local,
host-visible memory, and an uncached CPU read over the bus costs about 1.7 us per 8 bytes: 64 MiB takes 14.5 s. It
was measured here at 1.6 s for 16 MiB on the RX 7900 XTX. The bind wait was not the cause: it is a GPU-side wait.

Now the homes of the mirrored pages in the range are copied by the GPU into a host-cached buffer, 16 MiB at a time,
on the device's staging queue. The copy waits for the mirror's last bind batch and signals a timeline semaphore of
its own. The merge then reads the copy (TitleMirror::homes_in, and write_back with a staged copy). Under the
mirror's lock nothing is filled between the copy and the merge. The CPU never reads a home now.

The mirror's 10 s line gives the write-back's calls, ms each, the GPU copy's share, the longest, and the MiB copied
out.

Test: d3d12_page_mirror part 9 runs the write-back over 64 MiB with one piece written by the GPU. That piece goes
back, and the call must take under a second. It took 10 ms here, and 6.3 s before the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 07:56:20 -05:00
8bab5f2811 Merge main into claude/rt-async-compile-pool and refresh compile-gate doc note
Resolve runtime/README.md conflict with #2220 (LEONIDA_PIPELINE_ORDER_LOG)
and note in docs/d3d12_vulkan.md that LEONIDA_COMPILE_GATE=adaptive and 1
gate graphics creates as well (#2412).
2026-11-27 07:50:01 -05:00
e31f50bbcc compile gate calibration: keep no unclear verdict, drain a timed-out fence
Review of #2462:
- An unclear calibration (a slow submission the create does not explain) is no
  longer written to compile_gate_calibration.txt, and an unclear line an
  earlier build wrote is not read as a cached verdict: the next launch measures
  again instead of staying classic until the driver changes
  (compile_gate_policy::cache_verdict, tested in compile_gate_policy_test).
- After a fence wait that fails, the fence and command pool are destroyed only
  once the pending submission's fence signals (up to 60 s); on a lost device or
  if it still has not, they are left alive. The verdict stays classic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 13:49:07 +01:00
6af3b1dac6 Merge remote-tracking branch 'origin/main' into rt-compile-gate-auto 2026-11-27 13:43:49 +01:00
690dea5193 Merge pull request #2220 from MoonEyes/feat/pipeline-order-recorder
runtime: record the order of first pipeline requests (LEONIDA_PIPELINE_ORDER_LOG=1, RT-PIPELINE-PREWARM-ORDER phase 1)
2026-11-27 13:43:04 +01:00
1d7c662b4b compile gate: auto default, calibrated at device creation
With LEONIDA_COMPILE_GATE unset or `auto`, the device measures the driver once
before the VulkanContext exists: a worker creates a synthetic compute pipeline
(SPIR-V written in code, new specialization seed each run, no pipeline cache)
while the queue gets empty submissions waited on a fence. Quick submissions with
the create still in the driver give the adaptive gate; a held one, a create too
fast to tell, an unexplained slow submission or any failure give classic. The
verdict is cached per vendor/device/driver/pipelineCacheUUID in
compile_gate_calibration.txt beside the pipeline cache;
LEONIDA_COMPILE_GATE_RECALIBRATE=1 measures again. Only the title process
calibrates; build hosts and tests keep classic. `classic`, `adaptive`, `1`, `0`
still force a mode.

Tests: compile_gate_policy_test (no GPU: settings, NVIDIA version decode,
verdicts, cache file, SPIR-V shape) and vk_compile_gate_calibration_test (GPU:
a verdict within 20 s, adaptive on NVIDIA 621.40).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 13:24:49 +01:00
8f59df0fb0 Merge remote-tracking branch 'upstream/main' into claude/rt-async-compile-pool
# Conflicts:
#	docs/d3d12_vulkan.md
2026-11-27 05:46:06 -06:00
b0712ff2ce Merge test/round2 into heaps-in-place: per-piece sums and the T# index word for heaps read in place
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>
2026-11-27 06:39:35 -05:00
3c9820f8da Local test merge: bindless index in dword 6 of heap T#s, read directly by placed operands (be3e9c142)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 06:27:01 -05:00
23c3341196 Merge branch 'test/round2' into heaps-in-place: heaps read in place under the mirror's B and C steps
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>
2026-11-27 06:21:29 -05:00
16245b98b2 Merge remote-tracking branch 'upstream/main' into claude/pipeline-prewarm-order
# Conflicts:
#	docs/d3d12_vulkan.md
2026-11-27 05:20:16 -06:00
ee81c0e4a0 compile gate: builds outside MSVC, and the classic gate stays the default
- 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>
2026-11-27 12:20:11 +01:00
5cf7f89886 page mirror: the XMemAlloc heap in the mirror's range; pages written on both sides merged at the 256-byte piece (RT-PAGE-MIRROR)
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>
2026-11-27 06:18:52 -05:00
74bfb7d070 Merge branch 'test/round2' into tsharp-index 2026-11-27 06:17:53 -05:00
26e0830184 descriptors: T# index word follows SGPR spills and VCC, deferred views and replaced entries; unknown-source T#s probe only without the word
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 06:17:16 -05:00
916868ebe0 Merge remote-tracking branch 'origin/main' into window-retire-on-1920
# Conflicts:
#	runtime/CMakeLists.txt
#	runtime/test/d3d12_title_va_test.cpp
2026-11-27 12:11:50 +01:00
c4261506b3 Merge remote-tracking branch 'upstream/pr2220' into claude/pipeline-prewarm-order
# Conflicts:
#	runtime/CMakeLists.txt
2026-11-27 05:11:17 -06:00
ba32cd6acf d3d12: a console resource heap the page mirror holds is read in place: no copy, its pages filtered as they are filled
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>
2026-11-27 06:05:33 -05:00
4aca5032f8 Merge branch 'claude/rt-async-compile-pool' into claude/pipeline-prewarm-order
# Conflicts:
#	runtime/CMakeLists.txt
#	runtime/README.md
2026-11-27 05:05:06 -06:00
054cbe0f3d Local test merge: geometry, slot-133 buffers, title windows and pool extents on the page mirror; hot/cold tracking; homes by memory budget (edb0f8502, 0cdc80d20)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 06:04:05 -05:00
2a191041ff d3d12: a console heap's V# words are fixed once a pass, not once a slot (RT-CONSOLE-VSHARP-MEMO)
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).
2026-11-27 13:01:19 +02:00