/// A list of Vulkan semaphores to wait for or signal. /// /// This represents a list of binary or timeline semaphores, together /// with values for the timeline semaphores, and stage masks, if these /// are used for waiting. /// /// This type ensures that the array of semaphores to be signaled /// stays aligned with the array of values for timeline semaphores /// appearing in that list. The [`add_to_submit`] method prepares the /// `vkQueueSubmit` arguments appropriately for whatever semaphores we /// actually have. /// /// [`add_to_submit`]: SemaphoreList::add_to_submit #[derive(Debug)] pubstruct SemaphoreList { /// Mode of the semaphore list. Used for validation.
mode: SemaphoreListMode,
/// Semaphores to use. /// /// This can be a mix of binary and timeline semaphores.
semaphores: Vec<vk::Semaphore>,
/// Values for the timeline semaphores. /// /// If no timeline semaphores are present in [`semaphores`], this /// is empty. If any timeline semaphores are present, then this /// has the same length as [`semaphores`], with dummy !0 values /// in the elements corresponding to binary semaphores, since /// Vulkan ignores these. /// /// [`semaphores`]: Self::semaphores
values: Vec<u64>,
/// Stage masks for wait semaphores. /// /// This is only used if `mode` is `Wait`. pub stage_masks: Vec<vk::PipelineStageFlags>,
}
/// Add this list to the semaphores to be signalled by a `vkQueueSubmit` call. /// /// - Set `submit_info`'s `pSignalSemaphores` list to this list's /// semaphores. /// /// - If this list contains any timeline semaphores, then initialize /// `timeline_info`, set its `pSignalSemaphoreValues` to this /// list's values, and add it to `submit_info`s extension chain. /// /// Return the revised `submit_info` value. pubfn add_to_submit<'info, 'semaphores: 'info>(
wait_semaphores: &'semaphores mut Self,
signal_semaphores: &'semaphores mut Self,
submit_info: vk::SubmitInfo<'info>,
timeline_info: &'info mut MaybeUninit<vk::TimelineSemaphoreSubmitInfo<'info>>,
) -> vk::SubmitInfo<'info> {
wait_semaphores.check();
signal_semaphores.check();
if uses_timeline {
submit_info = submit_info.push_next(timeline_info);
}
submit_info
}
/// Add a semaphore to be signaled. Panics if this is a list of semaphores to wait. pubfn push_signal(&mutself, semaphore: SemaphoreType) {
assert!(matches!(self.mode, SemaphoreListMode::Signal)); self.push_inner(semaphore);
}
/// Add a semaphore to be waited for. Panics if this is a list of semaphores to signal. pubfn push_wait(&mutself, semaphore: SemaphoreType, stage: vk::PipelineStageFlags) {
assert!(matches!(self.mode, SemaphoreListMode::Wait));
fn push_inner(&mutself, semaphore: SemaphoreType) { match semaphore {
SemaphoreType::Binary(semaphore) => { self.semaphores.push(semaphore); // Push a dummy value if necessary. if !self.values.is_empty() { self.values.push(!0);
}
}
SemaphoreType::Timeline(semaphore, value) => { // We may be the first timeline semaphore, ensure that the values // array is filled with dummy values for existing binary semaphores. self.pad_values(); self.semaphores.push(semaphore); self.values.push(value);
}
}
self.check();
}
/// Remove all entries matching `semaphore` from the list. Returns `true` /// if anything was removed. pubfn remove(&mutself, semaphore: vk::Semaphore) -> bool { letmut removed = false; letmut i = 0; while i < self.semaphores.len() { ifself.semaphores[i] == semaphore { self.semaphores.swap_remove(i); if !self.values.is_empty() { self.values.swap_remove(i);
} if !self.stage_masks.is_empty() { self.stage_masks.swap_remove(i);
}
removed = true;
} else {
i += 1;
}
} self.check();
removed
}
// If we're about to receive values, ensure we're aligned first. if !other.values.is_empty() { self.pad_values();
} self.semaphores.append(&mut other.semaphores); self.values.append(&mut other.values); // If we had values, but `other` did not, re-align. if !self.values.is_empty() { self.pad_values();
} self.stage_masks.append(&mut other.stage_masks); self.check();
}
/// Pad `self.values` with dummy values for binary semaphores, /// in preparation for adding a timeline semaphore value. /// /// This is a no-op if we already have values. fn pad_values(&mutself) { self.values.resize(self.semaphores.len(), !0);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.