From 4b37878cdaa103cb8b0fe882474cd5961baafafe Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sat, 14 Nov 2026 00:22:06 -0800 Subject: [PATCH] RUNTIME 2265: staging queue grows its command-buffer ring to 128 rather than wait on the host past 8 A staging submission that found its queue's 8 command buffers all pending waited on the host for the oldest, under the staging lock, on whichever thread submitted: the scheduler's among them, inside a batch's submission (flush_staging), which held every queue's submissions until the staging queue ran. On a device whose staging queue is of compute work that can be as long as the program's kernels run. Now the staging queue makes another command buffer instead, up to 128 (MOST), and frees those past the 8 it keeps once the host saw their submissions complete, at the next submission. Past 128 it waits as before. The fill queue keeps its 8: its batches submit only after they found room. The doc comment says why 128 and what it costs (ANV below Xe-HP: a 64 KiB binding-table block per command buffer, 8 MiB at the cap). Counted: WorkCounts::staging_buffers_grown (made past the 8) and staging_buffer_waits (host waits for a command buffer to come free, either queue), classified as submission work in the conformance cost table. Tests: a unit test of the ring's choice (reuse the oldest complete, free the other complete ones past 8, grow below the most, wait at it), and a device test that holds 20 staging submissions on the GPU and checks every round's command buffer is submitted meanwhile with no host wait, then that the ring is back to 8 after one more round. The device test passes trivially on a device without a staging queue (lavapipe). RUNTIME_VERSION 2265: staging submissions no longer wait on the host for a command buffer below 128 pending. Verified (gbkern, at ffd3a51a79 on c796a88d6a): clippy x3, rustdoc, unit 29/29, api_signatures/api_surface 15/15, lavapipe 4/4, RTX 5080 4/4 (20 staging submissions held, 12 command buffers made past 8, 0 host waits, back to 8 after). --- crates/metal2vulkan-conformance/src/cost.rs | 5 +- .../src/device/staging.rs | 223 +++++++++++++++--- .../src/tests/staging_waits.rs | 172 ++++++++++++++ .../metal2vulkan-runtime/src/work_counts.rs | 27 +++ crates/metal2vulkan/src/cache/mod.rs | 2 +- crates/metal2vulkan/tests/api_signatures.tsv | 2 + 6 files changed, 400 insertions(+), 31 deletions(-) diff --git a/crates/metal2vulkan-conformance/src/cost.rs b/crates/metal2vulkan-conformance/src/cost.rs index bf2c3990e..4684de2ed 100644 --- a/crates/metal2vulkan-conformance/src/cost.rs +++ b/crates/metal2vulkan-conformance/src/cost.rs @@ -897,7 +897,7 @@ const TRANSLATION: [&str; 21] = [ /// The name prefixes that put a count in [`Region::Submission`]: the commit path, our own other /// threads and the GPU. -const SUBMISSION: [&str; 57] = [ +const SUBMISSION: [&str; 58] = [ "commands_recorded.", "command_buffers_", "command_pools_made", @@ -913,6 +913,9 @@ const SUBMISSION: [&str; 57] = [ // batches' GPU waits for them: work a burst of calls left to a later submission. "staging_flushes", "staging_gpu_waits", + // The staging queue's command buffers made past those it keeps, and the waits on the host + // for one to come free. + "staging_buffer", // The fill queue's submissions: a batch's new buffers' fills on a copy engine, before it; // and the batches' GPU waits for them. "fill_queue_submissions", diff --git a/crates/metal2vulkan-runtime/src/device/staging.rs b/crates/metal2vulkan-runtime/src/device/staging.rs index bd573a615..453bd7859 100644 --- a/crates/metal2vulkan-runtime/src/device/staging.rs +++ b/crates/metal2vulkan-runtime/src/device/staging.rs @@ -46,8 +46,10 @@ //! batch waited for it (`command_buffer/submit.rs`): the copies it made are visible to the //! commands after that wait, in submission order there, which never waits for work of the //! program's. A submission is not waited for -//! before the next one is recorded: its command buffer is one of up to [`BUFFERS`], each reused -//! once the host saw the value it signalled reached. +//! before the next one is recorded: its command buffer is one whose last submission the host saw +//! complete, else a new one, up to [`MOST`] (those past [`BUFFERS`] freed once the host saw them +//! complete: `WorkCounts::staging_buffers_grown`); only past [`MOST`] does a submission wait on +//! the host for the oldest (`WorkCounts::staging_buffer_waits`). //! - **Who uses it.** A texture made to copy through it (`texture/staging_copy.rs`) has its first //! move and zeros, and its `replace_region` copies, queued for the next submission here, which //! carries them all ([`StagingLock::submit`]): the next batch or internal submission of the @@ -148,10 +150,34 @@ pub(crate) const FILL_QUEUE_LEAST: u64 = 1 << 20; /// How long one wait for a staging submission lasts before it is repeated. const WAIT_SLICE: Duration = Duration::from_millis(100); -/// The most command buffers the staging queue records into: past them, a submission waits on the -/// host for the oldest one's before it records (the module docs). +/// The command buffers the staging queue keeps, and the most the fill queue records into: past +/// them, the staging queue makes more, up to [`MOST`], and frees each once the host saw its +/// submission complete (the module docs). pub(crate) const BUFFERS: usize = 8; +/// The most command buffers the staging queue records into at once: past them, a submission waits +/// on the host for the oldest one's before it records (the module docs). +/// +/// - **Why it grows.** That wait holds whichever thread submits, with the staging lock: a host +/// call's, or the scheduler's in the middle of a batch's submission (`flush_staging`, +/// `command_buffer/submit.rs`), which holds every queue's submissions meanwhile +/// (`scheduler/mod.rs`). On a device whose staging queue is of compute work, its submissions may +/// wait behind kernels that fill the compute units for as long as those run (the module docs): +/// with a ring of [`BUFFERS`] alone, a ninth flush while eight were pending held its thread +/// until the oldest completed. +/// - **Why 128.** It keeps what a burst holds bounded: sixteen times [`BUFFERS`], room for 120 +/// staging submissions more than the kept ring while the staging queue runs behind the +/// program's work, each one flush of the copies host calls queued before a batch or internal +/// submission, or a host call's own (a `get_bytes`, a `VkImage` handed out). Past it, a +/// submission waits as before. +/// - **What it costs.** The driver's memory for each command buffer past [`BUFFERS`], until the +/// host saw its submission complete and the next submission freed it. ANV on GPUs without +/// extended bindless (below Xe-HP) takes a 64 KiB block of its binding-table pool for each +/// command buffer whose commands use one, until it is reset or freed (Mesa, +/// `anv_cmd_buffer_new_binding_table_block`, `anv_state_pools_init_indirect_descriptors`): 8 MiB +/// at the cap. +const MOST: usize = 128; + /// What a queue of this module's is for (the module docs). #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(super) enum Role { @@ -161,6 +187,18 @@ pub(super) enum Role { Fills, } +impl Role { + /// The most command buffers the queue records into at once: [`MOST`] on the staging queue; + /// [`BUFFERS`] on the fill queue, where a batch submits only after it found one free or room + /// for another ([`Device::fill_queue_has_room`]) and otherwise keeps its fills at its start. + fn most(self) -> usize { + match self { + Role::Staging => MOST, + Role::Fills => BUFFERS, + } + } +} + /// The staging queue, or the fill queue, and its objects. pub(super) struct StagingQueue { role: Role, @@ -490,34 +528,92 @@ impl StagingLock<'_> { } } -/// The index of a command buffer of `made`, `staging`'s, no submission holds: one whose last -/// submission the host saw complete, else a new one while there are fewer than [`BUFFERS`], else -/// the oldest, once a wait on the host saw its value reached. +/// Which command buffer of a queue's a submission records into ([`take`]). +#[derive(Debug, PartialEq, Eq)] +enum Take { + /// The one at `at`, whose last submission the host saw complete, once those at `freed` were + /// freed (their indexes before that). + Free { at: usize, freed: Vec }, + /// A new one. + New, + /// The one at this index, the oldest, once a wait on the host saw its value reached. + Oldest(usize), +} + +/// The choice of [`free_buffer`], from `values`, the value the last submission of each of a +/// queue's command buffers signals (0: none), `seen`, the value through which the host saw the +/// queue's timeline complete, and `most`, the most command buffers the queue records into +/// ([`Role::most`]): the oldest the host saw complete, with the others it saw complete past the +/// first [`BUFFERS`] to free; else a new one while there are fewer than `most`; else the oldest, +/// after a wait. +fn take(values: &[u64], seen: u64, most: usize) -> Take { + let Some(oldest) = (0..values.len()).min_by_key(|&at| values[at]) else { + return Take::New; + }; + if values[oldest] <= seen { + let freed = (0..values.len()) + .filter(|&at| at != oldest && values[at] <= seen) + .take(values.len().saturating_sub(BUFFERS)) + .collect(); + return Take::Free { at: oldest, freed }; + } + match values.len() < most { + true => Take::New, + false => Take::Oldest(oldest), + } +} + +/// The index of a command buffer of `made`, `staging`'s, no submission holds, as [`take`] chooses +/// once a wait of no time asked whether the oldest one's submission completed. fn free_buffer(device: &Device, staging: &StagingQueue, made: &mut Made) -> Result { - let seen = staging.done.value(); - let oldest = (made.buffers.iter().enumerate()) - .min_by_key(|(_, &(_, value))| value) - .map(|(at, &(_, value))| (at, value)); - if let Some((at, value)) = oldest { - if value <= seen || reached(device, staging, value, 0)? { - return Ok(at); + let shared = device.shared(); + let values: Vec = (made.buffers.iter()).map(|&(_, value)| value).collect(); + let oldest = values.iter().copied().min(); + if let Some(value) = oldest.filter(|&value| value > staging.done.value()) { + // Noted where the host saw it reached. + reached(device, staging, value, 0)?; + } + match take(&values, staging.done.value(), staging.role.most()) { + Take::Free { at, freed } => { + if !freed.is_empty() { + let buffers: Vec = + freed.iter().map(|&other| made.buffers[other].0).collect(); + // SAFETY: the host saw the last submission of each complete, and the staging + // lock holds their pool. + unsafe { + release::object( + shared.vk(), + release::PoolBuffers { + pool: made.pool, + buffers: &buffers, + trim: false, + }, + ) + }; + made.buffers.retain(|(buffer, _)| !buffers.contains(buffer)); + } + Ok(at - freed.iter().filter(|&&other| other < at).count()) + } + Take::New => { + if made.buffers.len() >= BUFFERS { + shared.counts.staging_buffer_grown(); + } + let allocate = vk::CommandBufferAllocateInfo::default() + .command_pool(made.pool) + .level(vk::CommandBufferLevel::PRIMARY) + .command_buffer_count(1); + let buffer = device.allocate_command_buffers(&allocate)?[0]; + made.buffers.push((buffer, 0)); + Ok(made.buffers.len() - 1) + } + Take::Oldest(at) => { + shared.counts.staging_buffer_wait(); + let value = made.buffers[at].1; + // A watched submission's wait is counted apart (`slow_submissions.rs`). + slow_submissions::waited(Wait::StagingBuffer, || wait_for(device, staging, value))?; + Ok(at) } } - if made.buffers.len() < BUFFERS { - let allocate = vk::CommandBufferAllocateInfo::default() - .command_pool(made.pool) - .level(vk::CommandBufferLevel::PRIMARY) - .command_buffer_count(1); - let buffer = device.allocate_command_buffers(&allocate)?[0]; - made.buffers.push((buffer, 0)); - return Ok(made.buffers.len() - 1); - } - let Some((at, value)) = oldest else { - unreachable!("BUFFERS command buffers are made"); - }; - // A watched submission's wait is counted apart (`slow_submissions.rs`). - slow_submissions::waited(Wait::StagingBuffer, || wait_for(device, staging, value))?; - Ok(at) } /// Whether the host saw `staging`'s timeline, made, reach `value` within `timeout` nanoseconds @@ -578,6 +674,15 @@ impl Device { pub(crate) fn fill_queue_family(&self) -> Option<(u32, vk::QueueFlags)> { (self.shared().fill_queue.as_ref()).map(|queue| (queue.family, queue.flags)) } + + /// How many command buffers the staging queue holds now, and how many it keeps once the host + /// saw their submissions complete ([`BUFFERS`]); `None` on a device without one. + pub(crate) fn staging_buffers(&self) -> Option<(usize, usize)> { + let staging = self.shared().staging.as_ref()?; + let objects = lock(&staging.objects); + let made = objects.made.as_ref().map_or(0, |made| made.buffers.len()); + Some((made, BUFFERS)) + } } impl Device { @@ -808,3 +913,63 @@ fn pending(device: &Device, staging: &StagingQueue) -> Option<(vk::Semaphore, u6 _ => Some((timeline, submitted)), } } + +#[cfg(test)] +mod tests { + use super::{take, Take, BUFFERS, MOST}; + + /// The submission takes the oldest command buffer the host saw complete, a never-submitted one + /// (value 0) among them; else a new one below the queue's most; else waits for the oldest. + #[test] + fn a_submission_takes_a_free_command_buffer_else_a_new_one_below_the_most_else_waits() { + assert_eq!(take(&[], 0, MOST), Take::New); + assert_eq!( + take(&[5, 3, 4], 4, MOST), + Take::Free { + at: 1, + freed: vec![] + } + ); + assert_eq!( + take(&[2, 0], 1, MOST), + Take::Free { + at: 1, + freed: vec![] + } + ); + let pending: Vec = (1..=BUFFERS as u64).collect(); + assert_eq!(take(&pending, 0, MOST), Take::New); + assert_eq!(take(&pending, 0, BUFFERS), Take::Oldest(0)); + let full: Vec = (1..=MOST as u64).rev().collect(); + assert_eq!(take(&full, 0, MOST), Take::Oldest(MOST - 1)); + } + + /// Past [`BUFFERS`], the command buffers the host saw complete besides the one taken are + /// freed, down to [`BUFFERS`] and never one still pending. + #[test] + fn the_command_buffers_past_the_kept_ones_are_freed_once_complete() { + let grown: Vec = (1..=BUFFERS as u64 + 4).collect(); + assert_eq!( + take(&grown, BUFFERS as u64 + 4, MOST), + Take::Free { + at: 0, + freed: vec![1, 2, 3, 4] + } + ); + assert_eq!( + take(&grown, 2, MOST), + Take::Free { + at: 0, + freed: vec![1] + } + ); + let kept: Vec = (1..=BUFFERS as u64).collect(); + assert_eq!( + take(&kept, BUFFERS as u64, MOST), + Take::Free { + at: 0, + freed: vec![] + } + ); + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/staging_waits.rs b/crates/metal2vulkan-runtime/src/tests/staging_waits.rs index 8615e3834..ad57dc398 100644 --- a/crates/metal2vulkan-runtime/src/tests/staging_waits.rs +++ b/crates/metal2vulkan-runtime/src/tests/staging_waits.rs @@ -7,6 +7,11 @@ //! before the first batch is submitted, and then no batch waits for it: the runtime lane's //! `staging_batches` runs the same calls that way. //! +//! More staging submissions than the staging queue keeps command buffers for, all held on the GPU +//! the same way, record into new ones (`device/staging.rs`, `MOST`): no submission waits on the +//! host for one to come free, so every batch after them is submitted while they are held, and +//! once they complete, the next submission frees those past the kept ones. +//! //! A device test: compiled only under the GPU safety cfgs (`m2v_gpu`, `m2v_cpu_icd`), on the kind //! of device the cfg selects. A device with no staging queue, or whose `Managed` textures copy on //! the host, says so and passes. @@ -173,3 +178,170 @@ fn batches_submitted_while_a_staging_copy_runs_follow_the_first_one_s_wait() { batches after it none (internal submissions wait for it themselves): {waits} waits" ); } + +/// The rounds of a `replace_region` and a command buffer that reads it, each round's copy carried +/// by a staging submission of its own, all held: more than twice the command buffers the staging +/// queue keeps (`device/staging.rs`, `BUFFERS`). +const ROUNDS: u64 = 20; + +/// How long the test gives each round's command buffer to be submitted while the staging +/// submissions are held, before it lets them go and fails. +const SUBMITTED_WITHIN: Duration = Duration::from_secs(5); + +/// [`ROUNDS`] rounds on one queue, each a `replace_region` of a square of a `Managed` texture, +/// queued for the staging queue, then a command buffer that blits that square into a buffer of its +/// own, whose submission carries the copy in a staging submission of its own (the round waits for +/// it to be submitted); every staging submission held on the GPU until the last round's command +/// buffer was submitted. Each submission past the kept command buffers made a new one instead of +/// waiting on the host for the oldest (a wait the hold would keep until the test let go), so every +/// round's command buffer was submitted with them all held. Once they completed, one more +/// round's staging submission freed those past the kept ones. Each blit reads its round's bytes. +#[test] +fn staging_submissions_past_the_kept_command_buffers_make_more_rather_than_wait_on_the_host() { + let device = device(); + let name = device.name().to_owned(); + let Some((_, kept)) = device.staging_buffers() else { + eprintln!("STAGING-RING {name}: no staging queue; nothing to test"); + return; + }; + let raw = device.shared().vk(); + let mut kind = vk::SemaphoreTypeCreateInfo::default() + .semaphore_type(vk::SemaphoreType::TIMELINE) + .initial_value(0); + let info = vk::SemaphoreCreateInfo::default().push_next(&mut kind); + // SAFETY: the device is live and enables `timelineSemaphore`; `info` is live for the call. + let hold = unsafe { raw.create_semaphore(&info, None) }.unwrap(); + let queue = device.new_command_queue().unwrap(); + let mut descriptor = TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, SIDE, SIDE, false); + descriptor.usage = TextureUsage::SHADER_READ; + descriptor.resource_options = ResourceOptions::new( + StorageMode::Managed, + CpuCacheMode::DefaultCache, + HazardTrackingMode::Default, + ); + let texture = device.new_texture(&descriptor).unwrap(); + let outs: Vec<_> = (0..ROUNDS) + .map(|_| (device.new_buffer(4 * SQUARE * SQUARE, ResourceOptions::shared())).unwrap()) + .collect(); + let squares: Vec<(u64, u64)> = (0..ROUNDS) + .map(|at| (SQUARE * (at % 8), SQUARE * (at / 8))) + .collect(); + let bytes = |round: u64| -> Vec { + (0..4 * SQUARE * SQUARE) + .map(|i| ((i * 7 + 3 + round * 31) % 251) as u8) + .collect() + }; + // A round: its bytes written into its square, then a blit of the square into `out`, committed. + let blit_round = |round: u64, (x, y): (u64, u64), out| { + let square = Region::new_2d(x, y, SQUARE, SQUARE); + (texture.replace_region(square, 0, 0, &bytes(round), 4 * SQUARE, 0)).unwrap(); + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + blit.copy_from_texture_to_buffer( + &texture, + 0, + 0, + Origin::new(x, y, 0), + Size::new(SQUARE, SQUARE, 1), + out, + 0, + 4 * SQUARE, + 0, + BlitOption::None, + ) + .unwrap(); + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer + }; + device.hold_staging_submissions(Some((hold, 1))); + let before = device.work_counts(); + let mut last = None; + for (round, (out, &square)) in (0..ROUNDS).zip(outs.iter().zip(&squares)) { + let command_buffer = blit_round(round, square, out); + let deadline = Instant::now() + SUBMITTED_WITHIN; + while command_buffer.status() == CommandBufferStatus::Committed && Instant::now() < deadline + { + std::thread::sleep(Duration::from_millis(1)); + } + let status = command_buffer.status(); + last = Some((round, status, command_buffer)); + if status == CommandBufferStatus::Committed { + break; + } + } + let Some((rounds, held, last)) = last else { + unreachable!("ROUNDS rounds ran"); + }; + let rounds = rounds + 1; + let submitted = device.work_counts(); + let grown_to = device.staging_buffers().map_or(0, |(made, _)| made); + let signal = vk::SemaphoreSignalInfo::default().semaphore(hold).value(1); + // SAFETY: a host signal of the test's timeline, above its value. + unsafe { raw.signal_semaphore(&signal) }.unwrap(); + last.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(last.status(), CommandBufferStatus::Completed, "{name}"); + device.hold_staging_submissions(None); + for (round, (out, _)) in (0..rounds).zip(outs.iter().zip(&squares)) { + let want = bytes(round); + let contents = out.contents().unwrap(); + // SAFETY: the buffer's bytes, which no command buffer uses now. + let got = unsafe { std::slice::from_raw_parts(contents.as_ptr(), want.len()) }; + assert!( + got == want, + "{name}: round {round}'s blit reads its call's bytes" + ); + } + // The host sees the held submissions complete, so the next one frees those past the kept. + assert_eq!(device.staging_wait(), None, "{name}"); + let again = blit_round(ROUNDS, squares[0], &outs[0]); + again.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(again.status(), CommandBufferStatus::Completed, "{name}"); + let contents = outs[0].contents().unwrap(); + let want = bytes(ROUNDS); + // SAFETY: the buffer's bytes, which no command buffer uses now. + let got = unsafe { std::slice::from_raw_parts(contents.as_ptr(), want.len()) }; + assert!( + got == want, + "{name}: the round after reads its call's bytes" + ); + let after = device.work_counts(); + let settled = device.staging_buffers().map_or(0, |(made, _)| made); + // SAFETY: the staging submissions that waited for the timeline completed, and those after + // them wait for it no more. + unsafe { raw.destroy_semaphore(hold, None) }; + let staged = submitted.staging_submissions - before.staging_submissions; + let queued = submitted.staging_copies_queued - before.staging_copies_queued; + let grown = after.staging_buffers_grown - before.staging_buffers_grown; + let waits = after.staging_buffer_waits - before.staging_buffer_waits; + eprintln!( + "STAGING-RING {name}: {queued} copies queued, {staged} staging submissions held (round \ + {rounds} of {ROUNDS}'s command buffer {held:?}); {grown} command buffers made past the \ + {kept} kept ({grown_to} held at the last round), {waits} waits on the host for one; \ + {settled} kept after the round after" + ); + if queued == 0 { + eprintln!("STAGING-RING {name}: `Managed` textures copy on the host here; nothing more"); + return; + } + assert_eq!( + (rounds, held), + (ROUNDS, CommandBufferStatus::Scheduled), + "{name}: every round's command buffer was submitted while the staging submissions were \ + held" + ); + assert!( + staged >= ROUNDS, + "{name}: each round's copy went in a staging submission of its own: {staged}" + ); + assert_eq!(waits, 0, "{name}: no staging submission waited on the host"); + assert!( + grown as usize >= staged as usize - kept && grown_to > kept, + "{name}: the staging submissions past the {kept} kept command buffers made more: {grown} \ + made, {grown_to} held" + ); + assert_eq!( + settled, kept, + "{name}: those past the kept were freed once complete" + ); +} diff --git a/crates/metal2vulkan-runtime/src/work_counts.rs b/crates/metal2vulkan-runtime/src/work_counts.rs index 918158b84..74ebaabdb 100644 --- a/crates/metal2vulkan-runtime/src/work_counts.rs +++ b/crates/metal2vulkan-runtime/src/work_counts.rs @@ -382,6 +382,8 @@ pub(crate) struct Counters { staging_moves_queued: AtomicU64, staging_flushes: AtomicU64, staging_gpu_waits: AtomicU64, + staging_buffers_grown: AtomicU64, + staging_buffer_waits: AtomicU64, fill_queue_submissions: AtomicU64, fill_queue_waits: AtomicU64, fill_queue_waits_unused: AtomicU64, @@ -3631,6 +3633,18 @@ impl Counters { self.staging_gpu_waits.fetch_add(1, Ordering::Relaxed); } + /// A submission on the staging queue found its kept command buffers all pending and made + /// another (`device/staging.rs`). + pub(crate) fn staging_buffer_grown(&self) { + self.staging_buffers_grown.fetch_add(1, Ordering::Relaxed); + } + + /// A submission on the staging queue or the fill queue waited on the host for one of its + /// command buffers to come free (`device/staging.rs`). + pub(crate) fn staging_buffer_wait(&self) { + self.staging_buffer_waits.fetch_add(1, Ordering::Relaxed); + } + /// A submission on the fill queue was made (`device/staging.rs`). pub(crate) fn fill_queue_submission(&self) { self.fill_queue_submissions.fetch_add(1, Ordering::Relaxed); @@ -7690,6 +7704,17 @@ pub struct WorkCounts { /// the host: of the batches, at most one per `VkQueue` per staging submission, as every later /// batch there follows its wait (`command_buffer/submit.rs`). pub staging_gpu_waits: u64, + /// Command buffers the staging queue made past the 8 it keeps, because every one of its + /// command buffers was pending as a submission there was recorded (`device/staging.rs`): at + /// most 128 at once, each freed once the host saw its submission complete. A burst of staging + /// submissions the queue had not run, as behind the program's kernels on a queue of compute + /// work. + pub staging_buffers_grown: u64, + /// Submissions on the staging queue, or the fill queue, that waited on the host for one of the + /// queue's command buffers to come free (`device/staging.rs`): on the staging queue, past 128 + /// pending; on the fill queue, past 8, where another submission took the room a batch found. + /// The wait holds the thread that submits, the scheduler's among them. + pub staging_buffer_waits: u64, /// Submissions on the device's fill queue, a copy engine's (`device/staging.rs`): each a /// batch's new buffers' fills (zeros, staged bytes, `Managed` buffers' copies in after /// `did_modify_range`), made there before the batch, which waits for it, rather than at the @@ -10866,6 +10891,8 @@ impl Device { staging_moves_queued: counters.staging_moves_queued.load(Ordering::Relaxed), staging_flushes: counters.staging_flushes.load(Ordering::Relaxed), staging_gpu_waits: counters.staging_gpu_waits.load(Ordering::Relaxed), + staging_buffers_grown: counters.staging_buffers_grown.load(Ordering::Relaxed), + staging_buffer_waits: counters.staging_buffer_waits.load(Ordering::Relaxed), fill_queue_submissions: counters.fill_queue_submissions.load(Ordering::Relaxed), fill_queue_waits: counters.fill_queue_waits.load(Ordering::Relaxed), fill_queue_waits_unused: counters.fill_queue_waits_unused.load(Ordering::Relaxed), diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 9565a72ce..c4d1abee4 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 522; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 2264; +pub const RUNTIME_VERSION: u32 = 2265; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index a2b87724e..bb2af0044 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -3566,6 +3566,8 @@ field metal2vulkan-runtime::WorkCounts.stage_entries_shared pub stage_entries_sh field metal2vulkan-runtime::WorkCounts.stage_entries_specialized pub stage_entries_specialized: u64 field metal2vulkan-runtime::WorkCounts.stage_tables_read pub stage_tables_read: u64 field metal2vulkan-runtime::WorkCounts.stage_tables_read_in_part pub stage_tables_read_in_part: u64 +field metal2vulkan-runtime::WorkCounts.staging_buffer_waits pub staging_buffer_waits: u64 +field metal2vulkan-runtime::WorkCounts.staging_buffers_grown pub staging_buffers_grown: u64 field metal2vulkan-runtime::WorkCounts.staging_copies_queued pub staging_copies_queued: u64 field metal2vulkan-runtime::WorkCounts.staging_flushes pub staging_flushes: u64 field metal2vulkan-runtime::WorkCounts.staging_gpu_waits pub staging_gpu_waits: u64