Commit Graph

9 Commits

Author SHA1 Message Date
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
9e267665ca runtime: skip before_execute on staging queue and fix async submit coalescing barriers
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
b0419cefad runtime: preserve sync ExecuteCommandLists, drop unsafe batch coalescing, track active_seq_
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).
2026-11-27 13:19:48 -05:00
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