//! The indirect dispatches' recording of an execution on the GPU alone (`gpu_execute.rs`), on //! every device the generated-commands path does not take: core Vulkan 1.2, MoltenVK's among //! them. //! //! - **What runs.** After the replay's preprocess (`bind::replay_preprocess`) and its barrier, per //! command of the range in order: a compute barrier before each but the first //! (`Barrier::between_dispatches`), where the execution's order needs it (`gpu_execute.rs`), then //! per variant, in the variants' order, its pipeline, its //! push bytes naming the command's slot table (`ReplayLayout::table_offset`), its region record //! (`ReplayLayout::region_offset`) and the command buffer's status words, and one //! `vkCmdDispatchIndirect` of the arguments the preprocess wrote for the command and the variant //! (`ReplayLayout::argument_offset`): the command's group count for the variant of the state its //! record names, zero for every other variant and for a command that runs nothing. So a command //! runs at most one variant, the one its record names, as Metal's command runs its state; no //! Vulkan pipeline is chosen from GPU data, and nothing is guessed. //! - **Cost.** Commands times variants indirect dispatches (at most `gpu_execute::MAX_DISPATCHES`) //! and a barrier per command. MoltenVK 1.4.1 (an M3 Max on macOS 27) encodes each indirect //! dispatch as a Metal one whatever its group count, which its GPU runs in about 3.3 us, and ends //! its Metal compute encoder at each barrier (argument buffers and residency sets in use, its //! `MVKCmdPipelineBarrier::encode`), about 20 us of the GPU's time more. //! - **Pipelines.** Each variant's `VkPipeline` of its one region, made once and kept with the //! variant (`Variant::region_pipeline`); its layout holds no descriptor binding (an empty set at //! most, which nothing binds), and its push bytes are all it reads besides memory by device //! address ([`Template::of`]). use super::binding::PushWrite; use super::degradation::BoundFormats; use super::encoder::EncoderCore; use super::error::{internal, Error}; use super::gpu_execute::{Prepared, Scratch}; use super::pipeline::VariantObjects; use super::resource::ResourceKey; use super::tracker::{Barrier, Use}; use ash::vk; use metal2vulkan::bind::{IndirectArgs, PushHole, ReplayPreprocess}; use std::sync::Arc; use std::time::Duration; /// What a dispatch's push bytes take per command. #[derive(Clone, Copy, PartialEq, Eq)] enum Hole { /// The command's slot table. Table, /// The command's region record. Region, /// The command buffer's status words. Status, } /// A variant's push bytes as its dispatches write them: its push writes, and where in them each /// command's slot table, region record and the status words go (a write's index, the bytes into /// it, and what goes there). #[derive(Clone)] pub(super) struct Template { writes: Vec, holes: Vec<(usize, usize, Hole)>, } impl Template { /// The template of `p`'s variant: `None` where its commands are not one region whose group /// count the replay's arguments give, with no root table and no clamp, whose every hole one of /// its push writes of the hole's stages covers and is the command's slot table, region record /// or the status words, or where its pipeline layout holds a descriptor binding: the host step /// remains for it. An empty set is bound by none: Vulkan asks a bound set only "for each set n /// that is statically used by a bound shader" (VUID-vkCmdDispatch-None-08600), and a set of no /// binding cannot be. pub(super) fn of(p: &Prepared) -> Option