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).
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).
- 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
- 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)
- Replace TitleWritePolicy's O(N) std::map full scans in collect() and frame()
with unordered_map + O(1) swap-and-pop active vectors (hot_list_, dirty_list_,
history_active_), preserving promotion/demotion/probe/arm-failure semantics
and address-ordered collect() delivery (~0.001 ms/iter for 200k cold + 100 hot).
- Add writable flag (default true) to TitleVaAliases::resolve() plus optional
AccessResolver hook; call note_reached() iff writable && to != 0 so read-only
CBV/SRV root views do not queue GPU write-back for either aliases or mirrored
pages.
- Pass writable=false for root CBV/SRV and writable=true only for root UAVs in
d3d12_com.cpp; record explicit GPU buffer-write destinations (CopyBufferRegion,
CopyTiles, CopyTextureRegion to footprint, CopyResource buffer dst,
WriteBufferImmediate, AtomicCopyBuffer, ClearUnorderedAccessView buffer,
ResolveQueryData) and note them for write-back at ExecuteCommandLists.
- Add scale/correctness tests in title_write_policy_test.cpp and read-only vs
writable tests in title_va_alias_test.cpp.
AI-assisted: Antigravity (Gemini 4 Neon).
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>