Titles and d3d12_existing_heap rely on ExecuteCommandLists(empty) + Signal() as
a synchronization point that flushes pending streamed views and title textures.
AI-assisted: Antigravity (Gemini 4 Neon).
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).
Fix queue-sync bugs in VulkanQueue (runtime/src/vulkan_backend.h):
1. Synchronous execute_sync_impl(): when executing_ is active and this
batch is not blocked by an unmet Wait (blocked_by_wait_locked()), wait
on exec_cv_ with state_mutex_ unlocked instead of silently deferring
into held_. When !executing_ && !blocked_by_wait_locked(), take
executing_ and drain any already-ready held ops ahead of us first
(closing the gap between QueueHolds::signaled() and pump_ready()
reaching this queue), then hold behind a wait-blocked front if
must_hold() remains true or execute synchronously with before_execute_()
before returning. Wait, Signal, Marker, and genuinely wait-blocked
batches still enqueue under state_mutex_ without blocking on
before_execute_() or replay.
2. active_seq_ tracking: assign active_seq_ under state_mutex_ for direct
unheld execute_sync_impl(), signal_sync(), marker_sync(), update_tiles(),
and copy_tile_mappings(), clear active_seq_ before drain/release,
linearize oldest_held_seq() under state_mutex_, and flush
QueueHolds::pump_ready() after releasing state_mutex_ so after_held()
barriers never overtake active unheld submissions.
3. Remove unsafe cross-batch coalescing in drain_held_while_executing() and
async_worker() (along with batch_breaks, barrier_after,
run_single_held_batch, and run_coalesced_execute*) so every
ExecuteCommandLists runs its own before_execute_(), bindless_prepare_(),
prelude_record_(), and fault markers in strict FIFO order.
4. Fix stale prepared[] iteration in execute_now() statistics->mesh setup
by iterating only i < lists.size().
Update and expand submit_frame_test to cover sync exec_cv_ waiting,
unlocked wait-blocked enqueue, releaser-drain sync ordering, ready-front
drain while pump_mutex_ is held by another thread, active_seq_ protection
of after_held() across unheld execute() and signal(), per-batch FIFO
drain without coalescing, zero-copy CommandList Reset(), and QueueHolds
progress tracking.
Tested on Linux (AMD Ryzen 9 7950X3D iGPU, RADV RAPHAEL_MENDOCINO,
MESA_VK_DEVICE_SELECT=1002:164e!): 9/9 required queue ctest targets passed
(2.92s) plus 5/5 submit_frame_test stress runs.
AI-assisted: Antigravity (Gemini 4 Neon).
Fixes premature unmet release of console list-value gates at Present under
LEONIDA_SUBMIT_ASYNC and unlocked queue execution:
- QueueHolds (runtime/src/queue_holds.h): add process-wide queue_holds::any_progress()
backed by a lock-free active CPU/async work counter (WorkGuard / work_changed),
signaled_unpumped_ tracking across signaled() -> pump_ready(), and per-holder
lock-free has_pending_gpu_work() protected against detach() via holders_use_mutex_.
- VulkanQueue (runtime/src/vulkan_backend.h): account for queued async inbox calls,
active async_worker turns (through pump_ready()), pending release_requested_ flags
(with async_stop_ guard), synchronous/draining executing_ passes (through pump_ready()),
VulkanFence::signal() -> pump_ready(), and unretired GPU tickets (submitted_gpu_ vs
progress_ counter). Stop cross-queue release_ready() ping-pong by waking only when
held_front_seq_ != 0 and calling pump_ready() in async_worker() only when a call
ran or a held op was released.
- Pump::choose_release (runtime/shims/d3d12_xs_list_values.h): treat
leonida::queue_holds::any_progress() as active queue progress so held waits are
never broken unmet while a producer async worker, executing pass, or GPU submission
is still progressing; advance last_progress_ms_ so kStalledMs measures genuine quiet
time. Genuine deadlocks (cycles, idle queues + idle GPU at Present, stalled title)
still break cleanly.
- Tests: add CPU-only QueueHolds + list_value_progress tests in
list_value_progress_test.cpp and real VulkanQueue async-depth=4 + Present + busy
producer + genuine deadlock + synchronous executing_ tests in submit_frame_test.cpp.
AI-assisted: Antigravity, Gemini 4 Neon.
Tested on Linux (RADV RAPHAEL_MENDOCINO, MESA_VK_DEVICE_SELECT=1002:164e!):
8/8 passed (list_value_progress, submit_frame, vk_queue, vk_queue_query_sync,
vk_queue_constructor_oom, vk_fence_dispatcher_sync, vk_semaphore_lifetime,
vk_fence_lost_by_counter).
Round 1D runtime CPU optimization:
1. Split VulkanQueue state bookkeeping (state_mutex_, microsecond hold) from
execution serialization (executing_ + exec_cv_ + execution-local wait/pin
staging). Callers arriving while executing_ is active append to held_ in
strict FIFO order without blocking on before_execute_() or replay, and the
executing thread drains ready held work before releasing executing_.
2. Coalesce consecutive ready Deferred::Kind::batch ops in release_held() /
drain_held_while_executing() and consecutive Call::Kind::execute ops in
async_worker() (stopping on Signal, Wait, Marker, or Present after_held
barrier_after), inserting D3D12 inter-batch full memory barriers and
falling back to per-batch execution on validation failure.
3. Pass closed CommandList snapshots via std::shared_ptr<const CommandList>
from GraphicsCommandList to VulkanQueue (zero deep copies on submit;
Reset() reuses storage with an acquire fence when unique or allocates
fresh storage while in flight), and skip redundant visible_heaps
scan_title_table() recording for console descriptor heaps when table-scan
diagnostics are off.
4. Add unit tests in submit_frame_test covering unlocked before_execute_(),
strict FIFO order, held-batch coalescing and Signal/Wait splits, invalid
batch fallback, zero-copy Reset(), and async worker (depth=4) coalescing
with Present barrier ordering.
AI-assisted: Antigravity (Gemini 4 Neon).
Tested on Linux (RADV RAPHAEL_MENDOCINO): 15/15 queue/submit/replay ctest
targets pass (list_value_progress, vk_queue, vk_queue_query_sync,
submit_frame, vk_queue_constructor_oom, vk_semaphore_lifetime,
vk_fence_dispatcher_sync, vk_fence_lost_by_counter, vk_command_replay,
vk_predicated_copy, vk_predicate_capture, vk_overlapping_occlusion,
vk_host_at_aliasing, vk_host_texture_order).
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)
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>
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>