Commit Graph

19 Commits

Author SHA1 Message Date
3ef235a681 d3d12/vulkan: rebind released sparse pages to shared zero page on AMD proprietary 2026-11-29 10:40:34 -05:00
70ea06a50b runtime: Round 10 WS2 — shared Cell::known_* cache, TitleHeap changed() scoping, 64-tile bridging, fused AVX2 copy_and_sum_256 & filter/collect cuts
- Move title_memory_map::changed() into TitleHeap::hooks.commit/decommit and !from_mirror_heap in free_title_block()
- Share Cell::known_* across CellGuard & TitleTextureCells (no PAGE_READONLY no-guard cache; MEM_RESERVE intra-pass in TitleTextureCells, cross-pass in CellGuard; seed on xmem::map_view)
- Persist TitleTextureCells VQ cache across outer batches; bridge across run_already_armed_ tiles with uniform restore[0..15] up to kMaxBridgeGap=64
- Persist 1024-entry local_mirror per ConsoleHeap*, flush Phase A/B disjointly, handle !base V#s in Phase A, skip redundant WC BAR writes for waiting T#s
- Fused SEH-safe AVX2/SSE2 guarded::copy_and_sum_256(), kMaxWorkers=8, single-reader title_write_watch::ask() fast path preserving mark() entries

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-28 05:38:11 -05:00
84c7f469e6 runtime: Round 9 WS1 — CellGuard/reopen fast paths, WC streaming copy, 16 KiB strips, 7-part mirror split & coalescer tuning
- CellGuard::arm_batch(): zero-syscall all_armed + outside-s.mutex title_frames table-backed skip, MEM_RESERVE/PAGE_READONLY VQ cache with explicit cached_state, kMaxBridgeGap=32 (pin-guarded), disarm_batch/set_hot_batch for policy_.frame()
- geometry_writes::reopen(): range-scoped title_memory_map::changes_since() fast path with VirtualProtect(old) rollback
- TitleMirror::upload(): WC-aware copy_guarded_host(..., true) (MOVNTDQA), kStripBytes=16 KiB (64-piece strip mask), ~50 us WorkerPool spin, per-Unit sums slab
- 7-part refresh_page_mirror() sub-split telemetry (lock/feed/collect/arm/upload/filter/other + arm/upload breakdowns)
- watch_batch() in page_mirror_resolve_locked(), defer_fill=true only in page_mirror_chunk(), VulkanContext::cached_completed_retire_ticket(), pass_seq after write_back_titles()

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-28 04:42:01 -05:00
f913286051 runtime: Round 8 WS1 — PageMirror batching, direct page table, L1-strip AVX2 hashing, sub-page readback & heap WC buffering
- CellGuard::arm_batch(): per-batch sync_known_protect, range-scoped changes_since(), gap-bridging (<=8 cold tiles, pin-guarded), reopen() fast-path via Cell::armed_map_gen
- shadow_keep::sum_of_batch_256() hoisted AVX2/SSE2/scalar batch hash + 4 KiB L1-hot strips in TitleMirror::upload() & prehash_readback_slice()
- TitleWritePolicy PageRef active lists (no frame_hot) + TitleMirror 2-level per-chunk direct page table + has_pending() fast-path + refs>1 alias handoff
- Feed coalescing + watch_batch/unwatch_batch in refresh_page_mirror()
- Sub-page 256B-aligned vkCmdCopyBuffer readback, page_mirror_buffer resolve_cache, OutScratchGuard WC buffering in apply_in_place_changes/finish_in_place, lock-free reclaim_arena/update_address_guard

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-28 03:31:04 -05:00
aff99e069a runtime: parallel Phase-A heap filter, single-lock unwatch, fault VirtualQuery skip, and 64 MiB copy-queue readback
Cuts PageMirror refresh, write-fault, unwatch, and GPU write-back overhead:
- d3d12_vulkan_device.cpp / title_mirror.h / console_heap_slot_records.h: hoists 1024-entry FilterPageCache across upload(), buffers filtered slots in 64 KiB host scratch with coalesced WC BAR flushes, parallelizes pure read-only Phase A heap filtering across WorkerPool with sequential Phase B under page_mirror.mutex, and adds none->none / idempotent place() fast paths.
- title_mirror_hot_cold.h / title_geometry_watch.h / xmem.cpp: fixes HotColdTracking::unwatch() triple-lock/bogus-WriteQueue bug with single-lock geometry_writes::release(addr, was_hot), skips redundant 2nd VirtualQuery in notify(Event::fault), and passes ranged changed(start, end) from xmem.cpp.
- d3d12_vulkan_device.cpp / title_mirror.h: raises kReadbackPages to 1024 (64 MiB), routes readback copies onto info.copy_queues, bypasses kernel_writes::write() on xmem scratch frames (frame != page_va), batches begin_write/end_write per ordinary page, and lowers whole_title_ok threshold to 2.

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-28 02:08:11 -05:00
3007ae0d35 runtime: unlocked parallel readback pre-hashing, piece-level skip masks, and single-map CellGuard
Eliminates the async readback page_mirror.mutex convoy and serial fallback, and reduces page-mirror refresh cost:
- title_mirror.h / d3d12_vulkan_device.cpp: lifts WorkerPool for lock-free Phase 1 prehash_readback_slice() outside page_mirror.mutex and single-call Phase 2 write_back_prehashed() under lock (256-page slice: 0.11 ms unlocked, 0.03 ms locked), eliminating the 256x serial single-page fallback and merge_ranges() storm.
- Scopes readback invalidation to readback_slice_frames with per-frame 256-bit readback_slice_skip_masks populated from TitleMirror::upload(on_changed), preventing hot-page retry loops while preserving CPU-wins conflict semantics.
- Coalesces contiguous GPU write-back runs, batches deferred map() initial fills in parallel upload(), and replaces fed_now unordered_set with a flat sorted vector.
- title_mirror_hot_cold.h: consolidates CellGuard maps into a single TrackedCell map and adds a changes_since()-invalidated known_protect cache to halve cold re-arm VirtualQuery syscalls.

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-28 01:04:24 -05:00
ecbdb30d10 runtime: AVX2/SSE2 shadow_keep::sum_of, parallel TitleMirror pool, and batched CellGuard arming
Speeds up shadow page hashing, TitleMirror upload/write-back, and guard re-arming:
- shadow_keep::sum_of: 4x256-bit AVX2 (#if defined(__AVX2__)) and 4x128-bit SSE2 fast paths with portable scalar fallback (2.52x single-core AVX2 speedup).
- TitleMirror: lazy 6-worker thread pool with exception-safe teardown and RAII join guard parallelizing upload() and write_back_batch() for >=16 homes/jobs (4.76x upload, 6.08x write-back) while preserving exact serial aliasing semantics.
- CellGuard::arm_batch(): 1024-page contiguous runs, pin-batching outside mutex, and generation-guarded VirtualQuery cache.

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-28 00:01:22 -05:00
65acf73246 runtime: remove frame-hot mirror over-copying and measure write-back CPU time
Promoting 1x/frame pages to unguarded hot caused HotColdTracking to copy
~5,000+ pages on every submission (~50 GiB/10 s) and dirtied all textures
sharing those tiles (~119 ms/sub). Restore the submission-hot (6/8)
policy where unguarded copies beat fault+copy cost, and accumulate actual
CPU+wait time in AsyncReadback::cpu_ms instead of async wall-clock span.

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-27 23:24:53 -05:00
e9bd907508 runtime: add ReplayStateCache and two-tier frame-hot TitleWritePolicy
Cache bound pipelines, descriptor sets, dynamic graphics state, and dirty
push-constant sub-ranges across command lists in emit_commands() (with
invalidation across internal compute helpers and rendering boundaries),
and restore the two-tier submission-hot + presented-frame-hot policy in
TitleWritePolicy/HotColdTracking wired to present_serial.

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-27 22:29:42 -05:00
072327cfad runtime: tighten TitleMirror/GeometryViews lifetime guards and PR hygiene
Guard GeometryViews retirement with command_list_epochs, defer TitleMirror
freed-home ticket stamping until flush + note_mirror_bind under submit_mutex_
(including TitleImageUpload submits), fix queue lock ordering and lock-free
wait_submitted, remove dead helpers and process labels, and scrub game shader
identifiers from docs/design.md.

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-27 21:13:23 -05:00
8133156843 d3d12: 256B TitleMirror piece-hash skip and 16 MiB chunked texture watch index
AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-27 19:08:19 -05:00
34173ab04b runtime: Stage 4 same-queue submit merge, async geometry epoch, and O(1) floor 2026-11-27 17:53:44 -05: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
37fcb9f7c0 Runtime: two-tier mirror hot/cold policy, batched guards, fast fill & filter_pieces hook
- TitleWritePolicy (runtime/src/title_write_policy.h): lower submission-hot
  threshold (kPromote 6 -> 3 of 8), add O(active) present_frame() frame-hot
  tier (kFramePromote = 3 of 4, kFrameProbe = 16, unguarded on low-sub frames
  <= 4 subs/frame and guarded on high-sub frames so mid-frame CPU writes are
  never missed and 1-write/frame pages never copy 30x/frame), and sort/batch
  page arms via optional Guard::arm_batch().
- HotColdTracking (runtime/src/title_mirror_hot_cold.h): expose on_present(),
  coalesce contiguous 64 KiB VirtualProtect re-arms in CellGuard::arm_batch(),
  and route MEM_WRITE_WATCH pages through title_write_watch::ask() with zero
  guard faults or hot_tiles conflicts.
- TitleMirror (runtime/src/title_mirror.h): add optional TitleMirrorHooks::
  filter_pieces hook passing fill_scratch_ and the 256-bit changed-piece mask
  from fill() (eliminating duplicate 64 KiB guarded copies), and coalesce
  contiguous changed pieces into single WC-friendly memcpy bursts while
  preserving exact home.sums conflict detection.
- TitleHeap (runtime/src/title_heap.h): add portable reserve() helper for
  MEM_WRITE_WATCH with silent fallback and write_watched() tracking.
- Tests: add unit tests in title_write_policy_test.cpp,
  title_mirror_hooks_test.cpp, and title_heap_test.cpp.

AI-assisted: Antigravity (Gemini 4 Neon)
2026-11-27 10:52:32 -05:00
0ae59b2423 Fix TitleMirror write-back remap corruption and harden TitleHeap
- TitleMirror (runtime/src/title_mirror.h):
  - Add has_pending(va) and skip pages with unflushed pending_ binds in
    homes_in(), homes_in_ranges(), write_back(), and write_back_batch() so
    write-back never copies stale/unbound sparse chunk bindings over live CPU
    memory.
  - Pass each page's physical frame address (mapped->second + k * kPiece) to
    the write-back callback instead of its virtual address so concurrent CPU
    remaps cannot receive a previous mapping's bytes.
  - Replace the unconditional O(homes_.size()) refilter scan at the end of
    write_back() with an O(changed) local list of touched aliased homes.
  - Add HomeRef, homes_in_ranges(), and write_back_batch() for batched
    multi-range GPU readback with concurrent-remap frame validation.
  - Copy a full 64 KiB page in one hooks_.copy call inside fill() via a
    reusable member scratch buffer, falling back to 256-byte pieces only if
    the whole-page copy fails.
- TitleHeap (runtime/src/title_heap.h):
  - Add a per-span live-slot occupancy bitmap so release() rejects small-block
    double-frees without duplicating the freelist, and size_of()/release()
    reject freed slots, interior pointers, and unused span tails.
- Unit tests (title_mirror_hooks_test, title_heap_test):
  - Add regressions covering pending_ skip, physical-frame destination,
    O(changed) refilter scaling over 10k+ homes, 1-shot fill + per-piece
    fallback, batched multi-range coalescing/conflicts/remap skip, and
    TitleHeap double-free / interior-pointer / tail-slot rejection.

AI-assisted: Antigravity, Gemini 4 Neon
2026-11-27 09:36:10 -05: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
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
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
b4a6c3673a page mirror: a range's pages bound at a second address, and a filter on the fill path (for heaps read in place)
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>
2026-11-27 05:16:43 -05:00