Let a new texture register while a batch is replayed or submitted, waiting for no submission

A batch's submission takes the new resources' first work (FirstMoves::take), which holds the
device's place in the submissions' order until its vkQueueSubmit returns, and every registration
of a new resource (a texture's, buffer's, fill's, bytes' or texels' first move, as a Shared or
Private texture is made) waited for that order, so that no texture's heap set elements were
written between a batch's take and its submission. Two things made a texture's making wait long
inside that span: the batch's deferred command buffers were replayed after the take, and
MoltenVK encodes a command buffer's Metal commands inside vkQueueSubmit on the calling thread (5
to 32 ms for 4096 to 65536 fills on the M3 Max). In the consumer's guest on the Iris Xe with
deferred recording, the guest's task thread blocked 1311 ms over 110 such waits (about 17 ms a
frame). Metal's makes wait for no submission.

Now:
- A batch's deferred command buffers replay before the take (crate::recorder::resolve on each,
  waiting for a replay in progress), with no lock a registration takes; their handles stay as
  encoded until the vkQueueSubmit, which finds them replayed. Only the barrier command buffers
  the submission records after the take replay inside the order. What replays, and the commands,
  are unchanged.
- On a device whose heap sets take writes while a command buffer that binds them is pending
  (descriptorBindingUpdateUnusedWhilePending: every committed profile but the Vulkan 1.2
  floor's), a batch holds the texture slots' writes over that span instead
  (FirstMoves::take_holding, heap_sets::hold): elements asked meanwhile are written in order as
  the hold ends, before the batch's place in the order goes, and a registration takes no place.
  A device without the feature keeps its registrations ordered (FirstMoves::ordered).
- New WorkCounts fields: heap_slot_writes_deferred (the writes a hold deferred) and
  registrations_waited (registrations that found a submission holding the order and waited for
  it, counted only where registrations are ordered).
- Docs: texture/first_move.rs's order, heap_sets.rs, and the lane's module docs.

Verified, as the commits state:
- runtime_lane::first_use::a_new_texture_waits_for_no_submission_s_replay times a Private
  texture's making (a Shared one moves on the host where VK_EXT_host_image_copy exists and never
  waited) and now asserts the making added no wait for a place, printing its time. On the 780M
  and RX 7900 XTX (RADV) it took 0.04 to 0.19 ms while the command buffer was scheduled 58 to 64
  ms after its commit; with the replay moved back after the take it took 56 to 60 ms.
- On the M3 Max through MoltenVK (60 makings after commits of 4096 to 65536 fills): before the
  slot-write hold 20 makings waited for the order, up to 13.0 ms; with it none waited, the
  slowest taking 0.158 ms.
- The FirstMoves unit tests, among them a registration that waits for no submission where batches
  hold the slots and one that waits where registrations are ordered, and the count's tests:
  first_move, heap_sets and exit_guard tests, 62 passed.
- runtime_lane::first_use's 11 tests on the UHD 770 and lavapipe. Beside 128 busy threads and as
  8 parallel copies, on lavapipe and the UHD 770, every run passed with 0 waits for a place
  (183 makings, the longest 0.55 ms on lavapipe and 0.23 ms on ANV); the earlier time-ratio
  failures were the host's load and the validation layer's lock, not a wait of the runtime's.
- clippy plain, --cfg m2v_gpu and --cfg m2v_cpu_icd; Rustdoc -D warnings.
This commit is contained in:
Anees Iqbal committed 2026-10-19 00:16:00 +03:00
1 parent 1ef457d88b
commit aa2be705d5
7 files changed
+378 -35

No files matched your search

@@ -522,6 +522,18 @@ impl CommandBufferShared {
exit_uses.push(image.transition_use());
}
}
// Its encoders' deferred command buffers replayed now, where the recorder's thread has
// not yet (`recorder`), waiting for a replay in progress: before the first work's take,
// which holds the submissions' order until the submission is made, and which a new
// resource's registration waits for where registrations wait for their place
// (`texture/first_move.rs`). A texture made meanwhile so waits for no replay. Each keeps
// its handle as encoded until the submission (below), which finds it replayed.
for buffer in encoders.iter().flat_map(|recorded| &recorded.raws) {
// SAFETY: each ended, and its command buffer committed; inside the scheduler's
// section.
unsafe { crate::recorder::resolve(raw, *buffer) }
.map_err(|error| recording_error(device, crate::error::vulkan(error)))?;
}
// The new resources' first work, before every command (`texture/first_move.rs`), given
// back if the submission is not made. A batch's commands may reach every texture
// unnamed, so it takes every move, those of images bound to host pages among them, whose
@@ -837,6 +849,10 @@ impl CommandBufferShared {
true => (&signal_semaphores[..], &signal_values[..]),
false => (&[][..], &[][..]),
};
// Its deferred command buffers go as their replays (`recorder`), after every check above
// that compares them as encoded: its encoders', replayed before the first work's take
// (above); the barriers recorded since, replayed here where the recorder's thread has
// not yet reached them.
for buffer in work.iter_mut() {
// SAFETY: each ended, and its command buffer committed; inside the scheduler's
// section.