Commit Graph

5 Commits

Author SHA1 Message Date
2e00ea6c13 runtime: track active async, executing, and GPU queue progress for list-value gates
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).
2026-11-27 11:37:59 -05:00
50c5eddcd2 runtime: unlock VulkanQueue state_mutex_ across execution, coalesce ready batches, zero-copy CommandList
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).
2026-11-27 10:59:34 -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
c1f573212b submit_frame_test: the contended lock is taken and released on its holder's thread
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>
2026-11-27 05:59:18 -05:00
adc74d5d65 runtime: per-frame CPU line and the floor of an unchanged submission, beside the submit phases line
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>
2026-11-27 05:19:48 -05:00