diff --git a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs index 5417f9aed..dc62749c9 100644 --- a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs +++ b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs @@ -2928,6 +2928,14 @@ impl CommandBuffer { self.0.footprint(index) } + /// Whether the device's scheduler began submitting its first batch, noted before the driver's + /// submission is called, where `kernel_start_time` shows 0 until its kernel end is known, + /// after that call returned: a device test's (`tests::queue_share_device`). + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + pub(crate) fn submission_began(&self) -> bool { + self.0.kernel.start() != 0 + } + /// The bytes its upload arena's regions took: a device test's measure (`tests::rerun_arenas`). #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] pub(crate) fn upload_bytes(&self) -> u64 { @@ -4931,6 +4939,27 @@ impl CommandBufferShared { self.queue.unshared() && self.device.holds_back_for_unshared(self.queue.vk_queue()) } + /// The index of its `VkQueue` where its queue is unshared: its commit counts there as posted + /// to the scheduler's inbox, then as taken into the order (`SlotShare::unshared_commits`). + pub(crate) fn unshared_vk_queue(&self) -> Option { + self.queue.unshared().then(|| self.queue.vk_queue()) + } + + /// Where a batch of it is held back from its `VkQueue` for an unshared queue there + /// ([`held_for_unshared`](Self::held_for_unshared)'s conditions), that `VkQueue`'s unshared + /// commits posted to the scheduler's inbox and taken into its order so far + /// (`unshared_hold::behind_commits`); `None` where none is held back. + pub(crate) fn unshared_commits(&self) -> Option<(u64, u64)> { + if self.queue.unshared() || self.device.is_lost() { + return None; + } + let index = self.queue.vk_queue(); + if !self.device.holds_back_for_unshared(index) { + return None; + } + Some(self.device.shared().queues[index].share.unshared_commits()) + } + /// This thread doing the command buffer's work until the guard goes /// ([`CommandBuffer::notices_for`]). pub(super) fn notices_for(&self) -> NoticesFor { diff --git a/crates/metal2vulkan-runtime/src/queue_share.rs b/crates/metal2vulkan-runtime/src/queue_share.rs index d4b9f7ce1..afb576f0f 100644 --- a/crates/metal2vulkan-runtime/src/queue_share.rs +++ b/crates/metal2vulkan-runtime/src/queue_share.rs @@ -145,6 +145,11 @@ pub(crate) struct SlotShare { /// The host time (`gpu_time::host_nanos`) one of them last committed a command buffer; 0 /// before the first (`unshared_hold.rs`, `unshared_hold::active`). unshared_commit: AtomicU64, + /// Their commits posted to the scheduler's inbox (`Scheduler::commit`), and those a pass took + /// into its order since (`scheduler/mod.rs`'s `take_in`): `unshared_hold.rs`'s commits not + /// yet taken in. + unshared_posted: AtomicU64, + unshared_taken: AtomicU64, } impl SlotShare { @@ -214,6 +219,25 @@ impl SlotShare { self.unshared_commit.load(Ordering::Relaxed) } + /// An unshared command queue it holds posted a commit to the scheduler's inbox, before the + /// commit is there. + pub(crate) fn posted_unshared(&self) { + self.unshared_posted.fetch_add(1, Ordering::SeqCst); + } + + /// A pass took a commit [`posted_unshared`](Self::posted_unshared) counted into the + /// scheduler's order. + pub(crate) fn took_in_unshared(&self) { + self.unshared_taken.fetch_add(1, Ordering::SeqCst); + } + + /// The commits of the unshared command queues it holds posted to the scheduler's inbox and + /// taken into its order so far, the taken read first, so never above the posted. + pub(crate) fn unshared_commits(&self) -> (u64, u64) { + let taken = self.unshared_taken.load(Ordering::SeqCst); + (self.unshared_posted.load(Ordering::SeqCst), taken) + } + /// Whether another command queue holds it beside the one unshared queue that took it. pub(crate) fn held_beside_unshared(&self) -> bool { self.homes.load(Ordering::SeqCst) > 0 || self.unshared.load(Ordering::SeqCst) > 1 diff --git a/crates/metal2vulkan-runtime/src/scheduler/mod.rs b/crates/metal2vulkan-runtime/src/scheduler/mod.rs index afa7f6f39..1d0b580cd 100644 --- a/crates/metal2vulkan-runtime/src/scheduler/mod.rs +++ b/crates/metal2vulkan-runtime/src/scheduler/mod.rs @@ -711,11 +711,14 @@ impl Sleep { } } -/// A commit not yet taken into the order: the command buffer, its logical queue, its batches. +/// A commit not yet taken into the order: the command buffer, its logical queue, its batches, and, +/// where its queue is unshared, the index of the `VkQueue` whose unshared commits its post counted +/// (`SlotShare::unshared_commits`), which its taking in counts too. struct Committed { buffer: Hold, queue: u64, batches: Vec, + unshared: Option, } /// A committed batch not yet submitted. @@ -750,6 +753,10 @@ struct Held { /// The host nanoseconds at the first look of the scheduler's that found it held /// ([`held_for`](Self::held_for)), until it goes ([`hold_ended`](Self::hold_ended)). held_since: Option, + /// Where its `VkQueue` holds other queues' work back for an unshared queue, the unshared + /// commits posted there at the first look that found its room: those not yet taken in hold it + /// (`unshared_hold::behind_commits`). + unshared_noted: Option, } impl Held { @@ -900,10 +907,20 @@ impl Scheduler { hand: Hand, ) { let shared = &*self.shared; + // An unshared queue's commit counts as posted before it is in the inbox, so a pass that + // finds another queue's batch's room meanwhile holds it until a pass took this one in + // (`unshared_hold.rs`, "Commits not yet taken in"). + let unshared = buffer.unshared_vk_queue(); + if let Some(index) = unshared { + buffer.device().shared().queues[index] + .share + .posted_unshared(); + } let committed = Committed { buffer: buffer.hold(), queue, batches, + unshared, }; buffer.device().shared().counts.commit_handed_off(); if hand == Hand::Pass { @@ -1539,8 +1556,14 @@ fn take_in(state: &mut State, commits: &mut Vec, spent: &mut Spent) - buffer, queue, batches, + unshared, } in commits.drain(..) { + if let Some(index) = unshared { + buffer.device().shared().queues[index] + .share + .took_in_unshared(); + } let count = batches.len(); let State { order, binary, .. } = &mut *state; let held = batches.into_iter().enumerate().map(|(index, batch)| Held { @@ -1557,6 +1580,7 @@ fn take_in(state: &mut State, commits: &mut Vec, spent: &mut Spent) - hastened: false, counted_held: false, held_since: None, + unshared_noted: None, }); // Where the device notes queue times, a command buffer committed to an empty line is // its head as it is taken in. @@ -1799,6 +1823,16 @@ fn submit_ready( isolating = true; return None; } + // Its room came, but an unshared queue's commit there posted before it did is not in + // the order yet: the pass that takes it in, which the passer makes before it sleeps, + // sends that one first (`unshared_hold.rs`, "Commits not yet taken in"). + if let Some(commits) = held.buffer.unshared_commits() { + if crate::unshared_hold::behind_commits(&mut held.unshared_noted, commits) { + held.held_for(HeldFor::UnsharedIsolation); + (held.buffer.device().shared().counts).head_held_for_unshared_commits(); + return None; + } + } waits }); if let Some(at) = unshared_wake { @@ -2329,8 +2363,11 @@ fn plain( } }; // One held back for an unshared queue is the scheduler thread's to hold, and to wait for its - // room (`unshared_hold.rs`). - theirs && held.buffer.held_for_unshared().is_none() + // room (`unshared_hold.rs`), as is one an unshared queue's commit not yet taken in may hold + // (its passes note the commits it waits behind). + theirs + && held.buffer.held_for_unshared().is_none() + && (held.buffer.unshared_commits()).is_none_or(|(posted, taken)| taken >= posted) } /// The checks of the first line head in commit order whose checks a committing thread may run diff --git a/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs b/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs index d1e544fe4..19d28871d 100644 --- a/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs +++ b/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs @@ -44,6 +44,11 @@ //! and the unshared queue's first command buffer, committed once the second went, runs before //! the third: behind the idle budget and one batch, not all three. Every device, a `VkQueue` //! shared on purpose (`PerQueue`, the round robin wrapped). +//! - **Commits not yet taken in** (`unshared_hold.rs`). A scheduler pass takes commits in at its +//! start, the test's scheduler pausing after each submission: the unshared queue's command +//! buffer committed during the pass that submits another queue's first goes before that +//! queue's next, whose room came in that pass, and the unshared queue's next commit, posted +//! after that room came, does not hold it. //! //! Where the device does not share (`PerQueue`, its check found no idling, or it has no two //! `VkQueue`s of one family: MoltenVK, RADV, lavapipe) each test asserts that no queue moves, and @@ -53,11 +58,15 @@ //! safety cfgs (`m2v_gpu`, `m2v_cpu_icd`). use super::blit_holds::Scratch; +use crate::command_buffer::completion::trace; +use crate::tests::SETTLE; use crate::{ Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, Device, DeviceKind, DeviceOptions, ResourceOptions, ShaderCacheOptions, WorkCounts, }; -use metal2vulkan::device::{DevicePolicy, QueueSharingPolicy, UnsharedIsolationPolicy}; +use metal2vulkan::device::{ + CompletionPolicy, DevicePolicy, QueueSharingPolicy, UnsharedIsolationPolicy, +}; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::{mpsc, Arc, Mutex}; use std::time::{Duration, Instant}; @@ -1389,3 +1398,108 @@ fn a_late_pass_sends_an_unshared_queue_s_command_buffer_before_work_let_go_with_ ); assert!(run.held > 0, "a long one was held"); } + +/// How long the scheduler pauses after each `vkQueueSubmit` returned in +/// [`an_unshared_commit_posted_during_a_pass_goes_before_work_let_go_after_it`]: the test's thread +/// commits within it, on a loaded host too. +const PASS_PAUSE: Duration = Duration::from_millis(250); + +/// Lets the scheduler go on without pausing as it drops, a failing test's unwinding too. +struct NoPause; + +impl Drop for NoPause { + fn drop(&mut self) { + trace::pause_after_submit(None); + } +} + +/// Under `Bounded`, a scheduler pass takes commits in at its start (`scheduler/inbox.rs`), so an +/// unshared queue's commit posted during a pass waits for the next one. Another queue's batch +/// whose room comes during that pass is held until a pass took the commit in, and that pass sends +/// the unshared one first (`unshared_hold.rs`, "Commits not yet taken in"); a commit posted after +/// its room came never holds it. The scheduler pauses [`PASS_PAUSE`] each time a `vkQueueSubmit` +/// returned (`trace::pause_after_submit`, a scheduler thread the host preempted there), and the +/// test commits during those pauses: the application's `first` and `next` during its `earlier` +/// one's, the unshared queue's `drawn` during `first`'s, and its `later` during `drawn`'s. Each +/// batch goes alone (`CompletionPolicy::Exact`), so each takes its own pause. Without the hold, +/// `next` goes in the pass that submitted `first`, before `drawn`; a hold that waited for every +/// commit not taken in would hold `next` behind `later` too, and behind every commit of a +/// compositor that posts during each pass. +#[test] +fn an_unshared_commit_posted_during_a_pass_goes_before_work_let_go_after_it() { + let scratch = Scratch::new("unshared-hold-untaken"); + let mut options = options(&scratch, QueueSharingPolicy::PerQueue); + options.policy.unshared_isolation = UnsharedIsolationPolicy::Bounded; + options.policy.completion = CompletionPolicy::Exact; + let device = Device::system_default_with(&options).unwrap(); + assert!(device.settle_queue_switch_check(WAIT), "the check settles"); + assert!( + device.settle_submit_checks(SETTLE), + "the submission checks never answered" + ); + println!("device: {}", device.name()); + let app = device.new_command_queue().unwrap(); + let unshared = beside(&app, &|| device.new_command_queue_unshared(64).unwrap()); + let target = device.new_buffer(4096, ResourceOptions::private()).unwrap(); + let small = device.new_buffer(4096, ResourceOptions::private()).unwrap(); + let fill = |queue: &CommandQueue, buffer: &Buffer| { + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + blit.fill_buffer(buffer, 0..256, 1).unwrap(); + blit.end_encoding().unwrap(); + command_buffer + }; + // The application's expected run a small fill's (`unshared_hold::Expected`), so its batches + // find their room at once; and the unshared queue's first command buffer run. + for (queue, buffer) in [(&app, &target), (&app, &target), (&unshared, &small)] { + let command_buffer = fill(queue, buffer); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + } + let began = |command_buffer: &CommandBuffer, what: &str| { + let start = Instant::now(); + while !command_buffer.submission_began() { + assert!(start.elapsed() < WAIT, "{what}'s submission never began"); + std::thread::sleep(Duration::from_millis(1)); + } + }; + let before = device.work_counts(); + trace::pause_after_submit(Some(PASS_PAUSE)); + let no_pause = NoPause; + let earlier = fill(&app, &target); + earlier.commit().unwrap(); + began(&earlier, "earlier"); + let (first, next) = (fill(&app, &target), fill(&app, &target)); + first.commit().unwrap(); + next.commit().unwrap(); + began(&first, "first"); + let drawn = fill(&unshared, &small); + drawn.commit().unwrap(); + began(&drawn, "drawn"); + let later = fill(&unshared, &small); + later.commit().unwrap(); + let all = [&earlier, &first, &next, &drawn, &later]; + for command_buffer in all { + command_buffer.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(command_buffer.status(), CommandBufferStatus::Completed); + } + drop(no_pause); + let after = device.work_counts(); + let held = after.heads_held_for_unshared_commits - before.heads_held_for_unshared_commits; + let base = earlier.kernel_start_time(); + let [_, first, next, drawn, later] = + all.map(|command_buffer| (command_buffer.kernel_start_time() - base) * 1e3); + println!( + "kernel starts from the earlier one's: first {first:.1}, next {next:.1}, drawn \ + {drawn:.1}, later {later:.1} ms; {held} looks held for an unshared commit not taken in" + ); + assert!( + drawn < next, + "the unshared one went before the batch whose room came after its commit" + ); + assert!( + next < later, + "a commit posted after that room came did not hold the batch" + ); + assert!(held > 0, "a look held it for the unshared commit"); +} diff --git a/crates/metal2vulkan-runtime/src/tests/unshared_hold.rs b/crates/metal2vulkan-runtime/src/tests/unshared_hold.rs index 8440484fe..1b355861d 100644 --- a/crates/metal2vulkan-runtime/src/tests/unshared_hold.rs +++ b/crates/metal2vulkan-runtime/src/tests/unshared_hold.rs @@ -19,8 +19,13 @@ //! application's three 30 ms command buffers committed at once hold the third back until the //! work left falls under 16 ms, so a compositor's first command buffer after its quiet stretch //! waits behind about 16 ms plus one batch, not all three. +//! - **Commits not yet taken in.** A batch whose room came is held while an unshared queue's commit +//! posted before that is not taken into the scheduler's order, and goes once it is, whatever +//! was posted since: a compositor posting during every pass holds it for one pass at most. -use crate::unshared_hold::{active, Expected, Flies, Flight, Room, ACTIVE, BUDGET, IDLE_BUDGET}; +use crate::unshared_hold::{ + active, behind_commits, Expected, Flies, Flight, Room, ACTIVE, BUDGET, IDLE_BUDGET, +}; use std::sync::Arc; const MS: u64 = 1_000_000; @@ -361,3 +366,33 @@ fn a_quiet_compositor_s_first_command_buffer_waits_behind_the_idle_budget_and_on "the compositor active again: until the second has under 2 ms left" ); } + +/// A batch whose room came with every unshared commit taken in goes, and is not held by one +/// posted later; one whose room came with commits not taken in waits for those alone, however +/// many are posted while it waits. +#[test] +fn a_batch_waits_for_the_unshared_commits_posted_before_its_room_came_alone() { + let mut noted = None; + assert!(!behind_commits(&mut noted, (2, 2)), "every commit taken in"); + assert_eq!(noted, Some(2)); + assert!( + !behind_commits(&mut noted, (5, 2)), + "commits posted after its room came never hold it" + ); + + let mut noted = None; + assert!( + behind_commits(&mut noted, (3, 2)), + "a commit posted before its room came is not taken in" + ); + assert_eq!(noted, Some(3)); + assert!( + behind_commits(&mut noted, (4, 2)), + "still not taken in, another posted meanwhile" + ); + assert!( + !behind_commits(&mut noted, (5, 3)), + "the pass that took it in lets it go, the commits posted during that pass aside" + ); + assert_eq!(noted, Some(3), "noted once"); +} diff --git a/crates/metal2vulkan-runtime/src/unshared_hold.rs b/crates/metal2vulkan-runtime/src/unshared_hold.rs index f5a7a9786..f2d209de4 100644 --- a/crates/metal2vulkan-runtime/src/unshared_hold.rs +++ b/crates/metal2vulkan-runtime/src/unshared_hold.rs @@ -59,6 +59,19 @@ //! command buffer ready together on its `VkQueue` sends the unshared one first //! (`scheduler/order.rs`, "Heads put first"): a pass the host ran late, after the room came, //! would otherwise put the whole batch ahead of it. +//! - **Commits not yet taken in.** A pass takes the scheduler's inbox in once, at its start, then +//! submits one batch after another (about 0.3 ms each on the Radeon 780M), so an unshared +//! queue's commit posted meanwhile waits in the inbox until the pass ends, where "Heads put +//! first" cannot see it. A batch whose room comes during that pass is held while an unshared +//! queue's commit on its `VkQueue` posted before its room came is not yet in the order +//! ([`behind_commits`], `SlotShare::unshared_commits`); the pass that takes the commit in, which +//! the passer makes before it sleeps, sends the unshared one first where it is ready, and the +//! held batch next. Commits posted after its room came never hold it, so a compositor committing +//! during every pass holds it for one pass at most. Without the hold, beside a guest compositor +//! on the Radeon 780M, an application's batch let go during such a pass went in ahead of the +//! frame's command buffers in 106 to 129 of about 611 frames a 12 s walk, and those were 7 to 23 +//! of the 9 to 27 frames answered more than a refresh after their take. Counted: +//! `WorkCounts::heads_held_for_unshared_commits`. //! - **What it costs.** A batch longer than its queue's recent ones still holds the unshared //! queue's command buffer for its whole length: one command buffer's batch is one submission, //! which the GPU runs to its end. The next batch goes in about [`BUDGET`] before the one ahead @@ -96,6 +109,14 @@ pub(crate) const IDLE_BUDGET: u64 = 16_000_000; /// unshared queue's presenting is the program's. pub(crate) const ACTIVE: u64 = 50_000_000; +/// Whether a batch whose room came is held behind an unshared queue's commit not yet in the +/// scheduler's order (the module docs), its `VkQueue`'s unshared commits posted and taken in so +/// far being `posted` and `taken`: `noted` keeps the commits posted at the first look that found +/// its room, those it waits behind; any posted later never hold it. +pub(crate) fn behind_commits(noted: &mut Option, (posted, taken): (u64, u64)) -> bool { + taken < *noted.get_or_insert(posted) +} + /// A command queue's expected run of one batch (the module docs), in nanoseconds; 0 before the /// first is seen. #[derive(Debug, Default)] diff --git a/crates/metal2vulkan-runtime/src/work_counts.rs b/crates/metal2vulkan-runtime/src/work_counts.rs index de9c84b32..91226c3c3 100644 --- a/crates/metal2vulkan-runtime/src/work_counts.rs +++ b/crates/metal2vulkan-runtime/src/work_counts.rs @@ -294,6 +294,7 @@ pub(crate) struct Counters { heads_held_for: [AtomicU64; HeldFor::COUNT], heads_waiting_at_their_gate: AtomicU64, heads_let_go_unshared_idle: AtomicU64, + heads_held_for_unshared_commits: AtomicU64, host_step_gates_narrowed: AtomicU64, heads_awaiting_check_signals: AtomicU64, batches_held_past_a_look: AtomicU64, @@ -3451,6 +3452,13 @@ impl Counters { .fetch_add(1, Ordering::Relaxed); } + /// A look held a head whose room had come behind an unshared queue's commit on its `VkQueue` + /// not yet taken into the scheduler's order (`unshared_hold.rs`, "Commits not yet taken in"). + pub(crate) fn head_held_for_unshared_commits(&self) { + self.heads_held_for_unshared_commits + .fetch_add(1, Ordering::Relaxed); + } + /// A batch a look had found held went (submitted, or held in a group) `nanos` nanoseconds /// after the first look that found it held (`scheduler/mod.rs`). pub(crate) fn batch_hold_ended(&self, nanos: u64) { @@ -7236,7 +7244,9 @@ pub struct WorkCounts { /// queues' expected GPU work was in flight there (`unshared_hold.rs`, /// `UnsharedIsolationPolicy::Bounded`): the unshared queue's next command buffer goes in /// behind about one batch of theirs. While no unshared queue there committed a command - /// buffer within the last 50 ms, 16 ms or more (`heads_let_go_unshared_idle`). + /// buffer within the last 50 ms, 16 ms or more (`heads_let_go_unshared_idle`). With them, the + /// looks that held one behind an unshared queue's commit there not yet taken into the + /// scheduler's order (`heads_held_for_unshared_commits`). pub heads_held_for_unshared_isolation: u64, /// Heads a look let go with 2 ms or more of other queues' expected GPU work in flight on /// their `VkQueue`, which would hold them for an unshared queue there @@ -7246,6 +7256,13 @@ pub struct WorkCounts { /// queue's first command buffer after such a stretch goes in behind about that and one /// batch, and the 2 ms bound applies from its commit on. pub heads_let_go_unshared_idle: u64, + /// Of `heads_held_for_unshared_isolation`, the looks that held a head whose room on its + /// `VkQueue` had come behind an unshared queue's commit there not yet taken into the + /// scheduler's order, posted before that room came (`unshared_hold.rs`): a scheduler pass + /// takes its commits in at its start, so one posted during the pass waits for the next, which + /// sends the unshared queue's command buffer first and the held head next. Commits posted + /// after its room came never hold it. + pub heads_held_for_unshared_commits: u64, /// Times a look left a head that needs a host step waiting at its gate: the step reads what /// the GPU may write, so it waits until the batches that last wrote what it reads completed /// (`host_step_gates_narrowed`), or else until every `VkQueue` completed what was submitted to @@ -11172,6 +11189,9 @@ impl Device { heads_held_for_earlier_commits: held_for(HeldFor::EarlierCommit), heads_held_for_unshared_isolation: held_for(HeldFor::UnsharedIsolation), heads_let_go_unshared_idle: counters.heads_let_go_unshared_idle.load(Ordering::Relaxed), + heads_held_for_unshared_commits: counters + .heads_held_for_unshared_commits + .load(Ordering::Relaxed), heads_waiting_at_their_gate: counters .heads_waiting_at_their_gate .load(Ordering::Relaxed), diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index c5935a412..5719d9f38 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 = 2299; +pub const RUNTIME_VERSION: u32 = 2300; /// 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 47d68ca3e..93bb995a8 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -3054,6 +3054,7 @@ field metal2vulkan-runtime::WorkCounts.heads_held_for_earlier_commits pub heads_ field metal2vulkan-runtime::WorkCounts.heads_held_for_event_values pub heads_held_for_event_values: u64 field metal2vulkan-runtime::WorkCounts.heads_held_for_host_steps pub heads_held_for_host_steps: u64 field metal2vulkan-runtime::WorkCounts.heads_held_for_reencodes pub heads_held_for_reencodes: u64 +field metal2vulkan-runtime::WorkCounts.heads_held_for_unshared_commits pub heads_held_for_unshared_commits: u64 field metal2vulkan-runtime::WorkCounts.heads_held_for_unshared_isolation pub heads_held_for_unshared_isolation: u64 field metal2vulkan-runtime::WorkCounts.heads_let_go_unshared_idle pub heads_let_go_unshared_idle: u64 field metal2vulkan-runtime::WorkCounts.heads_waiting_at_their_gate pub heads_waiting_at_their_gate: u64 diff --git a/docs/API.md b/docs/API.md index d3aafb3d2..b900fd7b8 100644 --- a/docs/API.md +++ b/docs/API.md @@ -282,7 +282,10 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`: in time, and the unshared queue's command buffer waits behind about one batch of theirs: the whole of one, however long, as a submission runs to its end. A scheduler pass that finds a held batch let go and the unshared queue's command buffer ready together (a pass the host ran late) - sends the unshared one first. The 2 ms holds while an unshared queue there committed a command + sends the unshared one first, and a batch whose room comes during a pass waits while the + unshared queue's commit, posted before that, is not yet taken in by a pass + (`WorkCounts::heads_held_for_unshared_commits`); commits posted after its room came never hold + it. The 2 ms holds while an unshared queue there committed a command buffer within the last 50 ms, so a compositor drawing 20 frames a second or more (a 24-frame video's, a 30-frame game's) keeps it; while none has, the budget is 16 ms: an application keeping less queued beside a quiet compositor is not held, and the compositor's first command diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index 92f6ffdd6..1656ae5c5 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -129,7 +129,13 @@ known. The rest of the differences are docs/API.md section 9's precision notes. at once by a longer one and halved toward a shorter one; a batch of a queue with no run seen yet holds the others back until it completes. So a compositor's command buffer waits behind about one batch of an application's, as Metal runs it beside the application's work, and the next - batch goes in before the one ahead ends. Two budgets (`unshared_hold.rs`): `BUDGET`, 2 ms, while + batch goes in before the one ahead ends. A scheduler pass takes commits in at its start, so a + batch whose room comes during a pass waits while a compositor's commit there posted before + that is not yet taken in: the next pass sends the compositor's command buffer first and the + batch next, and commits posted after its room came never hold it + (`WorkCounts::heads_held_for_unshared_commits`). Without that, beside a guest compositor on the + Radeon 780M, 7 to 23 of the 9 to 27 frames a 12 s walk answered more than a refresh late had a + batch let go during such a pass ahead of them. Two budgets (`unshared_hold.rs`): `BUDGET`, 2 ms, while an unshared queue there committed a command buffer within the last 50 ms (`ACTIVE`: a compositor drawing 20 frames a second or more, a 30-frame game's or a 24-frame video's, keeps it, where one refresh at 50 Hz would not); `IDLE_BUDGET`, 16 ms (the owner's line for an intolerable wait),