Measure dispatches after one useResources in host_ab's encode workload

The steps this packet landed as, in order:
- Take the compute dispatch memo while the encoder's residency is unchanged
- Start a shared event listener's thread at its first notification
- Add a command buffer's scheduled event signal (encodeSignalEventScheduled:value:)
- Count the scheduler's passes, and measure signals, bursts and moving offsets in host_ab
- Hash the pipeline memos with the runtime's key hasher
- Let a dispatch take what its pipeline state last planned for the same shape
- Drop two casts clippy flags in completion_here's scheduled signal check
- State host_ab's dispatches taken as settled and as planned before

Content: the tree of `development` at f9d39326a3, unchanged.
This commit is contained in:
Anees Iqbal committed 2026-10-26 13:19:05 +02:00
1 parent 328f69c087
commit 27ad7597c1
23 files changed
+1581 -199

No files matched your search

@@ -61,7 +61,7 @@ use super::error::{
FailedPipeline, MeshRecordsOverflow, PipelineCreationCause, Problem,
TessellationRecordsOverflow, TimedOut,
};
use super::event::{EventRef, EventShared};
use super::event::{EventRef, EventShared, SharedEvent};
use super::execution::Execution;
use super::exit_guard::{self, Call};
use super::function_table::TableSnapshot;
@@ -500,6 +500,9 @@ pub(super) struct State {
pub(super) prefix: Option<vk::CommandBuffer>,
/// The encoders split at the event and binary semaphore waits and signals.
batches: Batches<Arc<EventShared>, vk::Semaphore>,
/// Its scheduled signals, in the order encoded
/// ([`CommandBuffer::encode_signal_event_scheduled`]).
scheduled_signals: Vec<(Arc<EventShared>, u64)>,
scheduled: VecDeque<Handler>,
/// Its submission handlers ([`CommandBuffer::add_submission_handler`]): run on the thread
/// that takes its last batch for its queue (submits it, or holds it in a group), before its
@@ -1527,6 +1530,7 @@ impl CommandBuffer {
folds: Vec::new(),
prefix: None,
batches: Batches::default(),
scheduled_signals: Vec::new(),
scheduled: VecDeque::new(),
submission: VecDeque::new(),
submitting: false,
@@ -1853,6 +1857,41 @@ impl CommandBuffer {
})
}
/// `encodeSignalEventScheduled:value:`, private: once the command buffer is scheduled, the
/// event's value becomes at least `value`, set as [`SharedEvent::set_signaled_value`] sets it:
/// before its status reads `Scheduled`, before any of its scheduled handlers runs (one added
/// before this call too) and before [`wait_until_scheduled`](Self::wait_until_scheduled)
/// returns, as Metal's (an M3 Max, macOS 27.0.1); several in the order encoded. No handler
/// thread is woken for it: a command buffer whose transition to `Scheduled` has nothing else
/// to run makes it on the thread that submitted its last batch. One that fails before it is
/// scheduled sets nothing, as it runs no scheduled handler.
///
/// Called once the command buffer is committed, it does nothing, as Metal's (measured before
/// and after the command buffer was scheduled). Refused while an encoder is open (Metal
/// asserts), after an abandoned encoder, and for another device's event, as
/// [`encode_signal_event`](Self::encode_signal_event) is. Metal ends the process for an
/// `MTLEvent`, which this call does not take.
pub fn encode_signal_event_scheduled(
&self,
event: &SharedEvent,
value: u64,
) -> Result<(), Error> {
const CALL: &str = "encode_signal_event_scheduled";
let event = EventRef::Shared(event);
let event = event.shared();
if !event.device().same(&self.0.device) {
return Err(invalid(CALL, Problem::ForeignObject));
}
self.settle_end();
let mut state = self.state();
match state.refusal() {
None => state.scheduled_signals.push((Arc::clone(event), value)),
Some(Problem::AlreadyCommitted) => {}
Some(problem) => return Err(invalid(CALL, problem)),
}
Ok(())
}
/// `encodeWaitForEvent:value:`: the work encoded after it starts once the event's value
/// reached `value`. Refused as [`CommandBuffer::encode_signal_event`] is.
pub fn encode_wait_for_event(&self, event: EventRef<'_>, value: u64) -> Result<(), Error> {
@@ -3453,10 +3492,12 @@ impl CommandBufferShared {
}
/// The scheduler submitted the last batch, or held it in a group (`group.rs`): in the queue's
/// context, once the submitting thread ran its submission handlers, become `Scheduled`, then run the scheduled handlers on
/// context, once the submitting thread ran its submission handlers, set the scheduled signals'
/// values, in the order encoded, then become `Scheduled`, then run the scheduled handlers on
/// this thread, in the order added, then let `wait_until_scheduled` return. Metal's status
/// reads `Scheduled` just before its first scheduled handler starts, and its wait returns
/// once the last returned (an M4, macOS 27.0.1).
/// once the last returned (an M4, macOS 27.0.1); its scheduled signals' values show before
/// its status reads `Scheduled` (an M3 Max, macOS 27.0.1).
fn run_scheduled(self: &Arc<Self>) {
{
let mut state = lock(&self.state);
@@ -3474,6 +3515,16 @@ impl CommandBufferShared {
.0;
state.parked -= 1;
}
if !state.scheduled_signals.is_empty() {
// Set without the command buffer's lock: a set wakes the scheduler, whose lock
// comes first.
let signals = std::mem::take(&mut state.scheduled_signals);
drop(state);
for (event, value) in signals {
event.set(value);
}
state = lock(&self.state);
}
state.status = CommandBufferStatus::Scheduled;
self.answer(&state);
}