RUNTIME 2275: the unshared hold's budget is 2 ms only while the unshared queue committed within 50 ms, else 16 ms
The unshared-isolation hold kept other queues' batches to about 2 ms of expected work ahead of an unshared (compositor) queue on the same VkQueue at all times. On the 780M that stretched Super Resolution's command buffers (reims gbo-780m A/B with isolation Off: SR 27.78 -> 24.78 s; 5772 holds). Now the 2 ms budget applies only while an unshared queue on that VkQueue committed within the last 50 ms; otherwise the budget is 16 ms (the intolerable-wait line), so a quiet compositor's first frame waits at most about 16 ms plus one batch. - SlotShare::unshared_committed: one relaxed atomic store per VkQueue at the commit call. - Flight::ahead takes the budget; Flight::room returns Room::Idle where only the 16 ms budget let a batch go; batches enter the flight either way, so the 2 ms bound is exact from the compositor's next commit. - WorkCounts::heads_let_go_unshared_idle (new). No new Degradation kind, no refusal change. - docs: FAST-PATHS unshared-isolation row (both budgets, reasons, trade, a replay over reims's hold-off trace: SR at 2 ms would hold 3,168 of 6,855 CBs, at 16 ms 0), API.md, the UnsharedIsolationPolicy::Bounded and new_command_queue_unshared docs. - queue_share_device: the held-work runs settle their queue's expected run before measuring. Verified (isohold): lavapipe m3-max-28760 at 337f244d25: unshared_hold, queue_share_device, scheduler_held_wakes 28/28; quiet compositor: second long CB let go 13.5 ms before the first ended, the compositor's CB ran between the second and third; active compositor: ran before the second long CB (Off: after the third). Negative control (window check removed) m3-max-28762: CONTROL_EXIT=100 (device test + 2 unit tests fail). The SR A/B on a 780M is owed. Clippy and the suites run after landing.
This commit is contained in:
1 parent
49d0f2a71c
commit
3b2443c8fe
13 files changed
+467
-81
No files matched your search
@@ -3668,11 +3668,19 @@ impl CommandBuffer {
|
||||
failure: Option<CommitFailure>,
|
||||
hand: Hand,
|
||||
) -> Result<(), Error> {
|
||||
let shared = self.0.device.shared();
|
||||
// An unshared queue's commit holds other queues' batches back from its `VkQueue` for a
|
||||
// while (`unshared_hold.rs`), from before its own batches reach the scheduler.
|
||||
if self.0.queue.unshared() {
|
||||
shared.queues[self.0.queue.vk_queue()]
|
||||
.share
|
||||
.unshared_committed();
|
||||
}
|
||||
// The bytes of the ranges `did_modify_range` noted of the buffers this command buffer may
|
||||
// use, as the host copies hold them now, for its submission that may use them, or a later
|
||||
// commit's, never an earlier one's (`managed.rs`); and its commit's stamp, which bounds
|
||||
// the uploads its batches take.
|
||||
let modified = &self.0.device.shared().modified;
|
||||
let modified = &shared.modified;
|
||||
let commit = modified.take_at_commit(|wanted, count| self.may_use(wanted, count));
|
||||
self.state().commit = commit;
|
||||
// Left to wait for the last render encoder's end, where its call left it to the device's
|
||||
@@ -4868,7 +4876,9 @@ impl CommandBufferShared {
|
||||
/// queue there (`unshared_hold.rs`): that `VkQueue`'s index, the value of the oldest batch in
|
||||
/// flight there the host has not seen complete, and in how many nanoseconds the work left
|
||||
/// ahead there falls under the budget where it does before that batch completes; `None` where
|
||||
/// it may go, as on a lost device, whose submissions fail at once.
|
||||
/// it may go, as on a lost device, whose submissions fail at once. The budget is 2 ms while an
|
||||
/// unshared queue there committed within `unshared_hold::ACTIVE`, else 16 ms (counted where
|
||||
/// only that let it go).
|
||||
pub(crate) fn held_for_unshared(&self) -> Option<(usize, u64, Option<u64>)> {
|
||||
if self.queue.unshared() || self.device.is_lost() {
|
||||
return None;
|
||||
@@ -4877,9 +4887,16 @@ impl CommandBufferShared {
|
||||
if !self.device.holds_back_for_unshared(index) {
|
||||
return None;
|
||||
}
|
||||
let slot = &self.device.shared().queues[index];
|
||||
match slot.waits.hold_ahead(|| slot.completed_value()) {
|
||||
let shared = self.device.shared();
|
||||
let slot = &shared.queues[index];
|
||||
let now = crate::gpu_time::host_nanos();
|
||||
let active = crate::unshared_hold::active(slot.share.unshared_commit(), now);
|
||||
match slot.waits.hold_ahead(|| slot.completed_value(), active) {
|
||||
crate::unshared_hold::Room::Go => None,
|
||||
crate::unshared_hold::Room::Idle => {
|
||||
shared.counts.head_let_go_unshared_idle();
|
||||
None
|
||||
}
|
||||
crate::unshared_hold::Room::Hold { after, through } => Some((index, through, after)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,7 +507,10 @@ impl Device {
|
||||
/// (the default) the other queues' batches are held back from that `VkQueue` while 2 ms or
|
||||
/// more of their expected GPU work is in flight there, so its command buffers wait behind
|
||||
/// about one batch of theirs, the whole of one longer than its queue's recent ones, where
|
||||
/// Metal runs a compositor's beside them. Under
|
||||
/// Metal runs a compositor's beside them. That 2 ms holds while it committed a command buffer
|
||||
/// within the last 50 ms; while it has not, 16 ms does, so its first command buffer after
|
||||
/// such a stretch waits behind at most about 16 ms of their work and one batch, the next ones
|
||||
/// behind about one (`WorkCounts::heads_let_go_unshared_idle`). Under
|
||||
/// [`Off`](metal2vulkan::device::UnsharedIsolationPolicy::Off) they wait behind every batch
|
||||
/// submitted before them there.
|
||||
///
|
||||
|
||||
@@ -142,6 +142,9 @@ pub(crate) struct SlotShare {
|
||||
long: AtomicUsize,
|
||||
/// The unshared command queues it holds.
|
||||
unshared: AtomicUsize,
|
||||
/// 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,
|
||||
}
|
||||
|
||||
impl SlotShare {
|
||||
@@ -198,6 +201,19 @@ impl SlotShare {
|
||||
self.unshared.fetch_sub(1, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
/// An unshared command queue it holds committed a command buffer: other queues' batches are
|
||||
/// held back from it for [`unshared_hold::ACTIVE`](crate::unshared_hold::ACTIVE) from now.
|
||||
pub(crate) fn unshared_committed(&self) {
|
||||
let now = crate::gpu_time::host_nanos().max(1);
|
||||
self.unshared_commit.store(now, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// The host time an unshared command queue it holds last committed a command buffer; 0
|
||||
/// before the first.
|
||||
pub(crate) fn unshared_commit(&self) -> u64 {
|
||||
self.unshared_commit.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// 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
|
||||
|
||||
@@ -199,12 +199,17 @@ impl QueueWaits {
|
||||
}
|
||||
|
||||
/// Whether another command queue's batch may go to this `VkQueue` now, held against its
|
||||
/// flight (`unshared_hold.rs`), the batches at or below `completed` (the value the host saw
|
||||
/// the timeline reach, read under this lock) counted as left: a completion publishes its value
|
||||
/// before it takes this lock to take them out ([`completed`](Self::completed)).
|
||||
pub(crate) fn hold_ahead(&self, completed: impl FnOnce() -> u64) -> crate::unshared_hold::Room {
|
||||
/// flight (`unshared_hold.rs`) under the budget of an unshared queue there `active` or not,
|
||||
/// the batches at or below `completed` (the value the host saw the timeline reach, read under
|
||||
/// this lock) counted as left: a completion publishes its value before it takes this lock to
|
||||
/// take them out ([`completed`](Self::completed)).
|
||||
pub(crate) fn hold_ahead(
|
||||
&self,
|
||||
completed: impl FnOnce() -> u64,
|
||||
active: bool,
|
||||
) -> crate::unshared_hold::Room {
|
||||
let ahead = lock(&self.0);
|
||||
let ran = crate::gpu_time::host_nanos().saturating_sub(ahead.head_from);
|
||||
ahead.flight.ahead(ran, completed())
|
||||
ahead.flight.room(ran, completed(), active)
|
||||
}
|
||||
}
|
||||
@@ -32,13 +32,18 @@
|
||||
//! application's queue went long, the compositor's 99th percentile over 2 s stays under 5 ms
|
||||
//! with at most one stall over 10 ms; on an unshared queue, from the start, with none.
|
||||
//! - **Other queues' work held back** (`unshared_hold.rs`). On a `VkQueue` an unshared queue
|
||||
//! shares with another queue, three long command buffers of that queue committed at once:
|
||||
//! under `UnsharedIsolationPolicy::Bounded` the second is held until the first is nearly done,
|
||||
//! so the unshared queue's command buffer committed meanwhile runs before it; under `Off` all
|
||||
//! three go at once and it runs after the third. A pass that finds the second let go and the
|
||||
//! unshared queue's command buffer ready together (the scheduler's thread late, held off by the
|
||||
//! test) sends the unshared one first. Every device, a `VkQueue` shared on purpose (`PerQueue`,
|
||||
//! the round robin wrapped).
|
||||
//! shares with another queue, three long command buffers of that queue committed at once, the
|
||||
//! unshared queue having committed just before (a compositor drawing): under
|
||||
//! `UnsharedIsolationPolicy::Bounded` the second is held until the first is nearly done, so the
|
||||
//! unshared queue's command buffer committed meanwhile runs before it; under `Off` all three go
|
||||
//! at once and it runs after the third. A pass that finds the second let go and the unshared
|
||||
//! queue's command buffer ready together (the scheduler's thread late, held off by the test)
|
||||
//! sends the unshared one first. With the unshared queue quiet for longer than
|
||||
//! `unshared_hold::ACTIVE` before, the second goes once the first has under 16 ms left (long
|
||||
//! before it ends, where 2 ms would hold it, `heads_let_go_unshared_idle`), the third is held,
|
||||
//! 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).
|
||||
//!
|
||||
//! 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
|
||||
@@ -1055,11 +1060,29 @@ struct HeldRun {
|
||||
short: (f64, f64),
|
||||
/// The host time the unshared one's commit returned.
|
||||
committed: f64,
|
||||
/// The second long one's kernel start time: when a pass took it to submit.
|
||||
let_go: f64,
|
||||
/// The long ones' kernel start times: when a pass took each to submit.
|
||||
let_go: [f64; 3],
|
||||
/// The looks that held a head back for the unshared queue
|
||||
/// (`WorkCounts::heads_held_for_unshared_isolation`).
|
||||
held: u64,
|
||||
/// The looks that let a head go under the idle budget where the active one would hold it
|
||||
/// (`WorkCounts::heads_let_go_unshared_idle`).
|
||||
let_go_idle: u64,
|
||||
/// The application queue's expected run as the long ones were committed, in milliseconds.
|
||||
expected: f64,
|
||||
}
|
||||
|
||||
/// What the unshared queue did before a [`HeldWork`] run's long command buffers.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum Compositor {
|
||||
/// It committed a small command buffer just before them, as a compositor drawing does: the
|
||||
/// 2 ms budget holds them back. Its command buffer of the run is committed once the first
|
||||
/// long one is scheduled.
|
||||
Active,
|
||||
/// It committed nothing for longer than `unshared_hold::ACTIVE` before them: the 16 ms
|
||||
/// budget holds them back. Its command buffer of the run, its first after the quiet stretch,
|
||||
/// is committed once the second long one is scheduled.
|
||||
Quiet,
|
||||
}
|
||||
|
||||
impl HeldWork {
|
||||
@@ -1072,6 +1095,15 @@ impl HeldWork {
|
||||
.unwrap();
|
||||
let small = device.new_buffer(4096, ResourceOptions::private()).unwrap();
|
||||
let fills = long_fills(&app, &big);
|
||||
// The calibration's first command buffer ran far longer than one of `fills` (on lavapipe
|
||||
// its expected run stayed past the first's end at the next ones' commit), and a queue's
|
||||
// expected run halves toward a shorter one (`unshared_hold::Expected`): ten run alone take
|
||||
// it to within a thousandth of that excess of a long one's.
|
||||
for _ in 0..10 {
|
||||
let command_buffer = long(&app, &big, fills);
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
}
|
||||
HeldWork {
|
||||
device,
|
||||
app,
|
||||
@@ -1082,15 +1114,48 @@ impl HeldWork {
|
||||
}
|
||||
}
|
||||
|
||||
/// A long command buffer run alone (its queue's expected run a long one's), then three
|
||||
/// committed at once, the first scheduled, then the unshared queue's small one committed.
|
||||
/// Where `late`, it is committed while the test holds the scheduler's lock
|
||||
/// (`Scheduler::under_lock`), kept until the first long one completed: the pass that takes it
|
||||
/// in finds the second let go too, as the pass of a scheduler thread the host ran late does.
|
||||
fn run(&self, late: bool) -> HeldRun {
|
||||
/// The unshared queue's small command buffer.
|
||||
fn small(&self) -> CommandBuffer {
|
||||
let command_buffer = self.unshared.command_buffer().unwrap();
|
||||
let mut blit = command_buffer.blit_command_encoder().unwrap();
|
||||
blit.fill_buffer(&self.small, 0..256, 1).unwrap();
|
||||
blit.end_encoding().unwrap();
|
||||
command_buffer
|
||||
}
|
||||
|
||||
/// A long command buffer run alone (its queue's expected run a long one's), then, as
|
||||
/// `compositor` says, three committed at once and the unshared queue's small one committed
|
||||
/// once the first (`Active`) or second (`Quiet`) is scheduled. Where `late`, it is committed
|
||||
/// while the test holds the scheduler's lock (`Scheduler::under_lock`), kept until the first
|
||||
/// long one completed: the pass that takes it in finds the second let go too, as the pass of
|
||||
/// a scheduler thread the host ran late does.
|
||||
fn run(&self, late: bool, compositor: Compositor) -> HeldRun {
|
||||
let warm = long(&self.app, &self.big, self.fills);
|
||||
warm.commit().unwrap();
|
||||
warm.wait_until_completed_for(WAIT).unwrap();
|
||||
let share = &self.device.shared().queues[self.unshared.vk_queue_sharing().0].share;
|
||||
let active =
|
||||
|| crate::unshared_hold::active(share.unshared_commit(), crate::gpu_time::host_nanos());
|
||||
let drawing = match compositor {
|
||||
Compositor::Active => {
|
||||
let drawing = self.small();
|
||||
drawing.commit().unwrap();
|
||||
Some(drawing)
|
||||
}
|
||||
Compositor::Quiet => {
|
||||
let began = Instant::now();
|
||||
while active() {
|
||||
assert!(
|
||||
began.elapsed() < WAIT,
|
||||
"the unshared queue never went quiet"
|
||||
);
|
||||
std::thread::sleep(Duration::from_millis(5));
|
||||
}
|
||||
None
|
||||
}
|
||||
};
|
||||
assert_eq!(active(), compositor == Compositor::Active);
|
||||
let expected = self.app.serving().expected().nanos().unwrap_or(0) as f64 / 1e6;
|
||||
let before = self.device.work_counts();
|
||||
let longs: Vec<CommandBuffer> = (0..3)
|
||||
.map(|_| {
|
||||
@@ -1099,11 +1164,11 @@ impl HeldWork {
|
||||
command_buffer
|
||||
})
|
||||
.collect();
|
||||
longs[0].wait_until_scheduled().unwrap();
|
||||
let short = self.unshared.command_buffer().unwrap();
|
||||
let mut blit = short.blit_command_encoder().unwrap();
|
||||
blit.fill_buffer(&self.small, 0..256, 1).unwrap();
|
||||
blit.end_encoding().unwrap();
|
||||
match compositor {
|
||||
Compositor::Active => longs[0].wait_until_scheduled().unwrap(),
|
||||
Compositor::Quiet => longs[1].wait_until_scheduled().unwrap(),
|
||||
}
|
||||
let short = self.small();
|
||||
let (short, committed) = match late {
|
||||
false => {
|
||||
short.commit().unwrap();
|
||||
@@ -1112,7 +1177,7 @@ impl HeldWork {
|
||||
true => self.commit_late(short, &longs[0]),
|
||||
};
|
||||
short.wait_until_completed_for(WAIT).unwrap();
|
||||
for command_buffer in &longs {
|
||||
for command_buffer in longs.iter().chain(&drawing) {
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
}
|
||||
let after = self.device.work_counts();
|
||||
@@ -1124,9 +1189,15 @@ impl HeldWork {
|
||||
longs: [times(&longs[0]), times(&longs[1]), times(&longs[2])],
|
||||
short: times(&short),
|
||||
committed,
|
||||
let_go: longs[1].kernel_start_time(),
|
||||
let_go: [
|
||||
longs[0].kernel_start_time(),
|
||||
longs[1].kernel_start_time(),
|
||||
longs[2].kernel_start_time(),
|
||||
],
|
||||
held: after.heads_held_for_unshared_isolation
|
||||
- before.heads_held_for_unshared_isolation,
|
||||
let_go_idle: after.heads_let_go_unshared_idle - before.heads_let_go_unshared_idle,
|
||||
expected,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1165,8 +1236,9 @@ impl HeldRun {
|
||||
let (ss, se) = self.short;
|
||||
println!(
|
||||
"{label}: long ones {:.1}-{:.1}, {:.1}-{:.1}, {:.1}-{:.1} ms, the unshared one \
|
||||
{:.1}-{:.1} ms, committed at {:.1} ms, the second let go at {:.1} ms; GPU idle \
|
||||
between the long ones {:.2} and {:.2} ms; {} looks held",
|
||||
{:.1}-{:.1} ms, committed at {:.1} ms, the second let go at {:.1} ms, the third at \
|
||||
{:.1} ms; GPU idle between the long ones {:.2} and {:.2} ms; {} looks held, {} let \
|
||||
go under the idle budget; their queue's expected run {:.1} ms",
|
||||
0.0,
|
||||
(e0 - s0) * 1e3,
|
||||
(s1 - s0) * 1e3,
|
||||
@@ -1176,11 +1248,14 @@ impl HeldRun {
|
||||
(ss - s0) * 1e3,
|
||||
(se - s0) * 1e3,
|
||||
(self.committed - s0) * 1e3,
|
||||
(self.let_go - s0) * 1e3,
|
||||
(self.let_go[1] - s0) * 1e3,
|
||||
(self.let_go[2] - s0) * 1e3,
|
||||
// The unshared one ends the first gap only where it ran in it.
|
||||
(s1 - if se <= s1 { e0.max(se) } else { e0 }) * 1e3,
|
||||
(s2 - e1) * 1e3,
|
||||
self.held,
|
||||
self.let_go_idle,
|
||||
self.expected,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1188,6 +1263,11 @@ impl HeldRun {
|
||||
fn ahead_of_the_second(&self) -> bool {
|
||||
self.short.1 <= self.longs[1].0 + 0.001
|
||||
}
|
||||
|
||||
/// The unshared one ran before the third long one.
|
||||
fn ahead_of_the_third(&self) -> bool {
|
||||
self.short.1 <= self.longs[2].0 + 0.001
|
||||
}
|
||||
}
|
||||
|
||||
/// The runs [`an_unshared_queue_s_command_buffer_goes_ahead_of_other_queues_held_work`] makes
|
||||
@@ -1219,18 +1299,19 @@ fn an_unshared_queue_s_command_buffer_goes_ahead_of_other_queues_held_work() {
|
||||
match isolation {
|
||||
UnsharedIsolationPolicy::Bounded => {
|
||||
let run = (0..HELD_RUNS)
|
||||
.map(|_| work.run(false))
|
||||
.map(|_| work.run(false, Compositor::Active))
|
||||
.inspect(|run| run.print("Bounded"))
|
||||
.find(|run| run.committed < run.let_go)
|
||||
.find(|run| run.committed < run.let_go[1])
|
||||
.expect("a run committed the unshared one before the second was let go");
|
||||
assert!(
|
||||
run.ahead_of_the_second(),
|
||||
"the unshared one ran before the second"
|
||||
);
|
||||
assert!(run.held > 0, "a long one was held");
|
||||
assert_eq!(run.let_go_idle, 0, "none let go under the idle budget");
|
||||
}
|
||||
_ => {
|
||||
let run = work.run(false);
|
||||
let run = work.run(false, Compositor::Active);
|
||||
run.print("Off");
|
||||
assert!(
|
||||
run.short.1 >= run.longs[2].1 - 0.001,
|
||||
@@ -1245,11 +1326,45 @@ fn an_unshared_queue_s_command_buffer_goes_ahead_of_other_queues_held_work() {
|
||||
);
|
||||
}
|
||||
assert_eq!(run.held, 0, "none held");
|
||||
assert_eq!(run.let_go_idle, 0, "none let go under the idle budget");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Under `Bounded`, beside an unshared queue quiet for longer than `unshared_hold::ACTIVE`, three
|
||||
/// long command buffers of about 30 ms committed at once go under the 16 ms budget
|
||||
/// (`unshared_hold::IDLE_BUDGET`): the second once the first has under 16 ms left, so more than
|
||||
/// 7 ms before the first ends, where the 2 ms budget lets it go about 2 ms before
|
||||
/// (`heads_let_go_unshared_idle` counts it), and the third is held. The unshared queue's first
|
||||
/// command buffer after its quiet stretch, committed once the second went, runs behind the first
|
||||
/// and second and before the third: behind at most the idle budget's work and one batch, not all
|
||||
/// three. A run whose unshared command buffer was committed only after the third was let go (the
|
||||
/// test's thread late on a loaded host) shows nothing of the bound, and is made again, up to
|
||||
/// [`HELD_RUNS`] runs.
|
||||
#[test]
|
||||
fn a_quiet_unshared_queue_s_first_command_buffer_waits_behind_the_idle_budget_and_one_batch() {
|
||||
let scratch = Scratch::new("unshared-hold-quiet");
|
||||
let work = HeldWork::new(&scratch, UnsharedIsolationPolicy::Bounded);
|
||||
let run = (0..HELD_RUNS)
|
||||
.map(|_| work.run(false, Compositor::Quiet))
|
||||
.inspect(|run| run.print("Bounded, quiet"))
|
||||
.find(|run| run.committed < run.let_go[2])
|
||||
.expect("a run committed the unshared one before the third was let go");
|
||||
let early = run.longs[0].1 - run.let_go[1];
|
||||
assert!(
|
||||
early > 0.007,
|
||||
"the second was let go {:.2} ms before the first ended, not under the idle budget",
|
||||
early * 1e3
|
||||
);
|
||||
assert!(run.let_go_idle > 0, "a head let go under the idle budget");
|
||||
assert!(run.held > 0, "the idle budget held a long one");
|
||||
assert!(
|
||||
run.ahead_of_the_third(),
|
||||
"the unshared one ran before the third"
|
||||
);
|
||||
}
|
||||
|
||||
/// Under `Bounded`, a pass that finds the unshared queue's command buffer ready together with the
|
||||
/// second long one, which the hold let go meanwhile, sends the unshared one first
|
||||
/// (`scheduler/order.rs`): its commit made while the test holds the scheduler's lock, kept until
|
||||
@@ -1259,10 +1374,10 @@ fn an_unshared_queue_s_command_buffer_goes_ahead_of_other_queues_held_work() {
|
||||
fn a_late_pass_sends_an_unshared_queue_s_command_buffer_before_work_let_go_with_it() {
|
||||
let scratch = Scratch::new("unshared-hold-late");
|
||||
let work = HeldWork::new(&scratch, UnsharedIsolationPolicy::Bounded);
|
||||
let run = work.run(true);
|
||||
let run = work.run(true, Compositor::Active);
|
||||
run.print("Bounded, a late pass");
|
||||
assert!(
|
||||
run.committed < run.let_go,
|
||||
run.committed < run.let_go[1],
|
||||
"the second was let go after the commit"
|
||||
);
|
||||
assert!(
|
||||
|
||||
@@ -11,8 +11,16 @@
|
||||
//! under the budget; a batch whose completion was published counts as left before it leaves; a
|
||||
//! run several batches complete in is shared among the other queues' batches, an unshared
|
||||
//! queue's taking none.
|
||||
//! - **Two budgets.** An unshared queue is active while its last commit is less than `ACTIVE`
|
||||
//! (50 ms) old, a commit stored after the time was read among them, and not once it is `ACTIVE`
|
||||
//! old or where none was made. While it is, the budget is 2 ms; while not, 16 ms: Geekbench 7's
|
||||
//! Super Resolution iteration on the Radeon 780M (four command buffers committed at once, at
|
||||
//! most 6.5 ms queued ahead of one) is never held, where the 2 ms budget holds it; and an
|
||||
//! 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.
|
||||
|
||||
use crate::unshared_hold::{Expected, Flies, Flight, Room, BUDGET};
|
||||
use crate::unshared_hold::{active, Expected, Flies, Flight, Room, ACTIVE, BUDGET, IDLE_BUDGET};
|
||||
use std::sync::Arc;
|
||||
|
||||
const MS: u64 = 1_000_000;
|
||||
@@ -36,20 +44,24 @@ fn a_queue_with_no_run_seen_has_no_expected_run() {
|
||||
fn a_batch_of_unknown_length_holds_the_next_back_until_it_completes() {
|
||||
let app = Arc::new(Expected::default());
|
||||
let mut flight = Flight::default();
|
||||
assert_eq!(flight.ahead(0, 0), Room::Go, "the first goes");
|
||||
assert_eq!(flight.ahead(0, 0, BUDGET), Room::Go, "the first goes");
|
||||
flight.taken(1, Flies::Other(&app));
|
||||
let first = Room::Hold {
|
||||
after: None,
|
||||
through: 1,
|
||||
};
|
||||
assert_eq!(flight.ahead(0, 0), first);
|
||||
assert_eq!(flight.ahead(500 * MS, 0), first, "however long it has run");
|
||||
assert_eq!(flight.ahead(0, 0, BUDGET), first);
|
||||
assert_eq!(
|
||||
flight.ahead(500 * MS, 0, BUDGET),
|
||||
first,
|
||||
"however long it has run"
|
||||
);
|
||||
flight.completed(1, 30 * MS);
|
||||
assert_eq!(app.nanos(), Some(30 * MS));
|
||||
assert_eq!(flight.ahead(0, 0), Room::Go);
|
||||
assert_eq!(flight.ahead(0, 0, BUDGET), Room::Go);
|
||||
flight.taken(2, Flies::Other(&app));
|
||||
assert_eq!(
|
||||
flight.ahead(0, 0),
|
||||
flight.ahead(0, 0, BUDGET),
|
||||
Room::Hold {
|
||||
after: Some(28 * MS + 1),
|
||||
through: 2
|
||||
@@ -86,7 +98,7 @@ fn a_queue_whose_batches_got_short_is_let_ahead_again_within_five_of_them() {
|
||||
value += 1;
|
||||
flight.taken(value, Flies::Other(&app));
|
||||
// Another of its batches is ready as this one starts.
|
||||
if flight.ahead(0, 0) == Room::Go {
|
||||
if flight.ahead(0, 0, BUDGET) == Room::Go {
|
||||
break;
|
||||
}
|
||||
flight.completed(value, MS);
|
||||
@@ -110,7 +122,7 @@ fn an_unshared_queue_s_batches_count_no_work_ahead() {
|
||||
for value in 1..=8 {
|
||||
flight.taken(value, Flies::Unshared);
|
||||
}
|
||||
assert_eq!(flight.ahead(0, 0), Room::Go);
|
||||
assert_eq!(flight.ahead(0, 0, BUDGET), Room::Go);
|
||||
flight.taken(9, Flies::Not);
|
||||
assert_eq!(flight.len(), 8, "a batch that flies not is not kept");
|
||||
}
|
||||
@@ -122,36 +134,36 @@ fn a_batch_goes_while_less_than_the_budget_is_left_ahead() {
|
||||
flight.taken(1, Flies::Other(&app));
|
||||
// 30 ms left at its start: held until 28 ms of it ran, or its completion.
|
||||
assert_eq!(
|
||||
flight.ahead(0, 0),
|
||||
flight.ahead(0, 0, BUDGET),
|
||||
Room::Hold {
|
||||
after: Some(28 * MS + 1),
|
||||
through: 1
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
flight.ahead(10 * MS, 0),
|
||||
flight.ahead(10 * MS, 0, BUDGET),
|
||||
Room::Hold {
|
||||
after: Some(18 * MS + 1),
|
||||
through: 1
|
||||
}
|
||||
);
|
||||
assert_eq!(flight.ahead(28 * MS + 1, 0), Room::Go);
|
||||
assert_eq!(flight.ahead(28 * MS + 1, 0, BUDGET), Room::Go);
|
||||
// The next one went: 30 ms more ahead, which the oldest's run left does not cover.
|
||||
flight.taken(2, Flies::Other(&app));
|
||||
let both = Room::Hold {
|
||||
after: None,
|
||||
through: 1,
|
||||
};
|
||||
assert_eq!(flight.ahead(29 * MS, 0), both);
|
||||
assert_eq!(flight.ahead(29 * MS, 0, BUDGET), both);
|
||||
// An overrun counts the oldest's expected run alone.
|
||||
assert_eq!(flight.ahead(90 * MS, 0), both);
|
||||
assert_eq!(flight.ahead(90 * MS, 0, BUDGET), both);
|
||||
flight.completed(1, 31 * MS);
|
||||
assert_eq!(
|
||||
app.nanos(),
|
||||
Some(31 * MS),
|
||||
"its run raised the queue's expected one"
|
||||
);
|
||||
assert_eq!(flight.ahead(29 * MS + 1, 0), Room::Go);
|
||||
assert_eq!(flight.ahead(29 * MS + 1, 0, BUDGET), Room::Go);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -172,10 +184,10 @@ fn a_run_several_batches_complete_in_is_shared_among_the_other_queues_batches()
|
||||
assert_eq!(second.nanos(), Some(4 * MS + MS / 2));
|
||||
assert_eq!(flight.len(), 1, "the fourth is still in flight");
|
||||
// Its own expected run was taken at its submission: 1 ms, under the budget.
|
||||
assert_eq!(flight.ahead(0, 0), Room::Go);
|
||||
assert_eq!(flight.ahead(0, 0, BUDGET), Room::Go);
|
||||
flight.completed(4, MS);
|
||||
assert_eq!(flight.len(), 0);
|
||||
assert_eq!(flight.ahead(0, 0), Room::Go);
|
||||
assert_eq!(flight.ahead(0, 0, BUDGET), Room::Go);
|
||||
}
|
||||
|
||||
/// An application's 30 ms batch and the compositor's light one behind it, seen complete together:
|
||||
@@ -191,7 +203,7 @@ fn an_unshared_batch_seen_complete_with_another_queue_s_leaves_it_the_whole_run(
|
||||
assert_eq!(app.nanos(), Some(30 * MS));
|
||||
flight.taken(3, Flies::Other(&app));
|
||||
assert_eq!(
|
||||
flight.ahead(14 * MS, 0),
|
||||
flight.ahead(14 * MS, 0, BUDGET),
|
||||
Room::Hold {
|
||||
after: Some(14 * MS + 1),
|
||||
through: 3
|
||||
@@ -214,25 +226,138 @@ fn a_batch_whose_completion_was_published_counts_as_left_before_it_leaves() {
|
||||
let mut flight = Flight::default();
|
||||
flight.taken(1, Flies::Other(&app));
|
||||
assert_eq!(
|
||||
flight.ahead(0, 0),
|
||||
flight.ahead(0, 0, BUDGET),
|
||||
Room::Hold {
|
||||
after: None,
|
||||
through: 1
|
||||
}
|
||||
);
|
||||
assert_eq!(flight.ahead(0, 1), Room::Go, "published, not yet out");
|
||||
assert_eq!(
|
||||
flight.ahead(0, 1, BUDGET),
|
||||
Room::Go,
|
||||
"published, not yet out"
|
||||
);
|
||||
let long = queue(30 * MS);
|
||||
let mut flight = Flight::default();
|
||||
flight.taken(1, Flies::Other(&long));
|
||||
flight.taken(2, Flies::Other(&long));
|
||||
assert_eq!(
|
||||
flight.ahead(20 * MS, 1),
|
||||
flight.ahead(20 * MS, 1, BUDGET),
|
||||
Room::Hold {
|
||||
after: Some(28 * MS + 1),
|
||||
through: 2
|
||||
},
|
||||
"the second's run counts from the first's completion, not the first's run"
|
||||
);
|
||||
assert_eq!(flight.ahead(0, 2), Room::Go);
|
||||
assert_eq!(flight.ahead(0, 2, BUDGET), Room::Go);
|
||||
assert_eq!(flight.len(), 2, "neither left");
|
||||
}
|
||||
|
||||
/// An unshared queue is active while its last commit is less than `ACTIVE` old, not after, nor
|
||||
/// before its first commit.
|
||||
#[test]
|
||||
fn an_unshared_queue_is_active_for_the_window_after_its_commit() {
|
||||
let now = 1_000 * MS;
|
||||
assert!(active(now, now), "committed just now");
|
||||
assert!(active(now - ACTIVE + 1, now), "within the window");
|
||||
assert!(
|
||||
active(now + MS, now),
|
||||
"a commit stored after the time was read"
|
||||
);
|
||||
assert!(!active(now - ACTIVE, now), "the window's end");
|
||||
assert!(!active(now - 10 * ACTIVE, now), "long quiet");
|
||||
assert!(!active(0, now), "never committed");
|
||||
assert_eq!(ACTIVE, 50 * MS);
|
||||
}
|
||||
|
||||
/// Geekbench 7's Super Resolution on the Radeon 780M with no hold (reims's perfscout4, gbo-780m):
|
||||
/// each iteration commits four command buffers at once, of 1.7, 1.7, 2.5 and 4.2 ms on the GPU,
|
||||
/// at most 6.48 ms queued ahead of one; its queue's expected run is its longest's, 4.2 ms, raised
|
||||
/// at once by each iteration's last. Beside a compositor quiet for longer than `ACTIVE`, none of
|
||||
/// them waits (the last goes with 12.6 ms costed ahead, under 16 ms); within `ACTIVE` of its
|
||||
/// commit, the 2 ms budget holds the second until the first nearly ends.
|
||||
#[test]
|
||||
fn super_resolution_s_iterations_are_never_held_beside_a_quiet_compositor() {
|
||||
let sr = queue(4_200_000);
|
||||
let now = 1_000 * MS;
|
||||
for (last, quiet) in [(0, true), (now - ACTIVE, true), (now - MS, false)] {
|
||||
let mut flight = Flight::default();
|
||||
flight.taken(1, Flies::Unshared);
|
||||
for value in 2..=5 {
|
||||
let room = flight.room(0, 1, active(last, now));
|
||||
match (quiet, value) {
|
||||
(_, 2) => assert_eq!(room, Room::Go, "the first goes"),
|
||||
(true, _) => assert_eq!(room, Room::Idle, "batch {value} goes, quiet"),
|
||||
(false, _) => {
|
||||
assert!(
|
||||
matches!(room, Room::Hold { .. }),
|
||||
"batch {value} held, active"
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
flight.taken(value, Flies::Other(&sr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An application commits three 30 ms command buffers at once beside a compositor quiet for
|
||||
/// longer than `ACTIVE`: the second goes once the first has under 16 ms left (where 2 ms would
|
||||
/// hold it), the third once the second has, so a compositor's first command buffer after its
|
||||
/// quiet stretch waits behind at most 16 ms of work plus one batch, not all three. Its commit
|
||||
/// makes the budget 2 ms again: the third then goes once the second has under 2 ms left.
|
||||
#[test]
|
||||
fn a_quiet_compositor_s_first_command_buffer_waits_behind_the_idle_budget_and_one_batch() {
|
||||
let long = queue(30 * MS);
|
||||
let now = 1_000 * MS;
|
||||
let quiet = active(now - ACTIVE, now);
|
||||
let mut flight = Flight::default();
|
||||
assert_eq!(flight.room(0, 0, quiet), Room::Go, "the first goes");
|
||||
flight.taken(1, Flies::Other(&long));
|
||||
assert_eq!(
|
||||
flight.room(0, 0, quiet),
|
||||
Room::Hold {
|
||||
after: Some(30 * MS - IDLE_BUDGET + 1),
|
||||
through: 1
|
||||
},
|
||||
"the second waits until the first has under 16 ms left"
|
||||
);
|
||||
assert_eq!(
|
||||
flight.room(30 * MS - IDLE_BUDGET, 0, quiet),
|
||||
Room::Hold {
|
||||
after: Some(1),
|
||||
through: 1
|
||||
},
|
||||
"16 ms left"
|
||||
);
|
||||
assert_eq!(
|
||||
flight.room(30 * MS - IDLE_BUDGET + 1, 0, quiet),
|
||||
Room::Idle,
|
||||
"under 16 ms left: it goes, where 2 ms would hold it"
|
||||
);
|
||||
flight.taken(2, Flies::Other(&long));
|
||||
assert_eq!(
|
||||
flight.room(30 * MS - IDLE_BUDGET + 1, 0, quiet),
|
||||
Room::Hold {
|
||||
after: None,
|
||||
through: 1
|
||||
},
|
||||
"the third waits for the first's completion: over 16 ms is left until then"
|
||||
);
|
||||
assert_eq!(
|
||||
flight.room(0, 1, quiet),
|
||||
Room::Hold {
|
||||
after: Some(30 * MS - IDLE_BUDGET + 1),
|
||||
through: 2
|
||||
},
|
||||
"then until the second has under 16 ms left"
|
||||
);
|
||||
assert_eq!(
|
||||
flight.room(0, 1, active(now, now)),
|
||||
Room::Hold {
|
||||
after: Some(30 * MS - BUDGET + 1),
|
||||
through: 2
|
||||
},
|
||||
"the compositor active again: until the second has under 2 ms left"
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Other command queues' work held back from a `VkQueue` an unshared queue shares with them
|
||||
//! (`UnsharedIsolationPolicy::Bounded`, the default): only about [`BUDGET`] of their expected GPU
|
||||
//! work is submitted ahead of the unshared queue's next command buffer.
|
||||
//! work is submitted ahead of the unshared queue's next command buffer, or [`IDLE_BUDGET`] while
|
||||
//! it is quiet.
|
||||
//!
|
||||
//! - **Why.** A `VkQueue` runs its submissions in order. On a device whose graphics family has
|
||||
//! one queue (RADV, ANV, lavapipe), every command queue submits to it,
|
||||
@@ -15,7 +16,20 @@
|
||||
//! queue holds (`SlotShare::unshared`), on a device whose policy is `Bounded`. Where an unshared
|
||||
//! queue has a `VkQueue` of its own, no other command queue's batch goes there, and nothing is
|
||||
//! held.
|
||||
//! - **The bound.** Such a batch, otherwise ready, is submitted only while less than [`BUDGET`] of
|
||||
//! - **Two budgets.** While an unshared queue there committed a command buffer within [`ACTIVE`]
|
||||
//! (50 ms; `SlotShare::unshared_committed`, one atomic store at the commit call), the bound
|
||||
//! below is [`BUDGET`] (2 ms). Otherwise it is [`IDLE_BUDGET`] (16 ms): a compositor gone quiet
|
||||
//! (a still screen, a guest window not redrawn) holds back only an application that keeps 16 ms
|
||||
//! or more of expected work queued, and that one still has 16 ms queued as its next batch goes
|
||||
//! (`WorkCounts::heads_let_go_unshared_idle` counts the heads the 2 ms bound would have held).
|
||||
//! The trade: the unshared queue's first command buffer after such a stretch goes in behind
|
||||
//! every batch submitted before its commit, at most about 16 ms of expected work plus the last
|
||||
//! batch let go; the 2 ms bound applies from that commit on. The batches stay in the [`Flight`]
|
||||
//! either way. A batch already held as the 50 ms run out goes at the next look, which its gate
|
||||
//! (the oldest batch's completion) or its time brings, as before; one of the unshared queue's
|
||||
//! own command buffers that waits past [`ACTIVE`] after its commit (on an event, a host step)
|
||||
//! goes in behind what the 16 ms bound let go meanwhile.
|
||||
//! - **The bound.** Such a batch, otherwise ready, is submitted only while less than the budget of
|
||||
//! expected GPU work of other queues' batches is left in flight on its `VkQueue` ([`Flight`]):
|
||||
//! the expected runs of the batches submitted there and not seen complete, less what the oldest
|
||||
//! one has run since it became the oldest, up to its own expected run. So an unshared queue's
|
||||
@@ -60,10 +74,28 @@ use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// The expected GPU work of other queues' batches, in nanoseconds, below which another of their
|
||||
/// batches is submitted to a `VkQueue` an unshared queue holds: 2 ms, the length past which a
|
||||
/// command buffer marks its queue long where queues share `VkQueue`s (`queue_share::LONG_HEAD`).
|
||||
/// batches is submitted to a `VkQueue` an unshared queue holds, while one there committed within
|
||||
/// [`ACTIVE`]: 2 ms, the length past which a command buffer marks its queue long where queues
|
||||
/// share `VkQueue`s (`queue_share::LONG_HEAD`).
|
||||
pub(crate) const BUDGET: u64 = 2_000_000;
|
||||
|
||||
/// The budget, in nanoseconds, while no unshared queue there committed within [`ACTIVE`]: 16 ms,
|
||||
/// the owner's line for an intolerable wait. The unshared queue's first command buffer after a
|
||||
/// quiet stretch waits behind at most about this much expected work plus the last batch let go
|
||||
/// (one batch, which runs to its end); an application that keeps less queued is not held at all
|
||||
/// (Geekbench 7's Super Resolution on the Radeon 780M kept at most 6.48 ms queued ahead of a
|
||||
/// batch, with no hold), and one that keeps more still has 16 ms queued as its next batch goes.
|
||||
pub(crate) const IDLE_BUDGET: u64 = 16_000_000;
|
||||
|
||||
/// How long, in nanoseconds, an unshared queue's commit keeps the hold on its `VkQueue` (the
|
||||
/// module docs): 50 ms. A compositor commits when what it shows changed, so its commits follow its
|
||||
/// content: every refresh on a busy screen, but 33.3 ms apart for a game capped at 30 frames a
|
||||
/// second and 41.7 ms for a 24-frame video. 50 ms keeps the hold on between such commits; one
|
||||
/// refresh of a 50 Hz display (20 ms) would leave a 30-frame game's compositor behind all of the
|
||||
/// game's queued work, the case the hold exists for. The runtime knows no refresh rate: the
|
||||
/// unshared queue's presenting is the program's.
|
||||
pub(crate) const ACTIVE: u64 = 50_000_000;
|
||||
|
||||
/// A command queue's expected run of one batch (the module docs), in nanoseconds; 0 before the
|
||||
/// first is seen.
|
||||
#[derive(Debug, Default)]
|
||||
@@ -131,13 +163,23 @@ pub(crate) struct Flight {
|
||||
/// Whether a batch may go to a `VkQueue` now ([`Flight::ahead`]).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum Room {
|
||||
/// Less than [`BUDGET`] of other queues' expected work is left in flight.
|
||||
/// Less than the budget of other queues' expected work is left in flight.
|
||||
Go,
|
||||
/// [`BUDGET`] or more, or a batch of unknown length is in flight: held until the oldest batch
|
||||
/// The budget or more, or a batch of unknown length is in flight: held until the oldest batch
|
||||
/// in flight, of value `through`, completes, or, where only the budget holds it, until `after`
|
||||
/// nanoseconds from now, where the oldest batch's expected run brings the work left under the
|
||||
/// budget then.
|
||||
Hold { after: Option<u64>, through: u64 },
|
||||
/// Goes under [`IDLE_BUDGET`] where [`BUDGET`] would hold it: no unshared queue there
|
||||
/// committed within [`ACTIVE`] ([`Flight::room`]).
|
||||
Idle,
|
||||
}
|
||||
|
||||
/// Whether an unshared queue of a `VkQueue` that last committed at `last` (`gpu_time::host_nanos`;
|
||||
/// 0 where none has) is active when the host's time is `now`: that commit is less than [`ACTIVE`]
|
||||
/// old, one stored after `now` was read none old.
|
||||
pub(crate) fn active(last: u64, now: u64) -> bool {
|
||||
last != 0 && now.saturating_sub(last) < ACTIVE
|
||||
}
|
||||
|
||||
impl Flight {
|
||||
@@ -184,13 +226,26 @@ impl Flight {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether another queue's batch may go now, the oldest batch in flight having run `ran`
|
||||
/// nanoseconds since it became so (the module docs), the host having seen the timeline reach
|
||||
/// `completed`. A batch at or below `completed` counts as left: its completion was published
|
||||
/// before it takes it out ([`Flight::completed`]), so the answer follows the published value
|
||||
/// alone, which a held batch's gate is read against. The oldest batch past it became so at
|
||||
/// that completion, so none of its run counts yet.
|
||||
pub(crate) fn ahead(&self, ran: u64, completed: u64) -> Room {
|
||||
/// Whether another queue's batch may go now, under [`BUDGET`] where an unshared queue there
|
||||
/// is `active` ([`active`]), else under [`IDLE_BUDGET`], [`Room::Idle`] where only that let it
|
||||
/// go; [`ahead`](Self::ahead)'s other arguments.
|
||||
pub(crate) fn room(&self, ran: u64, completed: u64, active: bool) -> Room {
|
||||
if active {
|
||||
return self.ahead(ran, completed, BUDGET);
|
||||
}
|
||||
match self.ahead(ran, completed, IDLE_BUDGET) {
|
||||
Room::Go if self.ahead(ran, completed, BUDGET) != Room::Go => Room::Idle,
|
||||
room => room,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether another queue's batch may go now under `budget`, the oldest batch in flight having
|
||||
/// run `ran` nanoseconds since it became so (the module docs), the host having seen the
|
||||
/// timeline reach `completed`. A batch at or below `completed` counts as left: its completion
|
||||
/// was published before it takes it out ([`Flight::completed`]), so the answer follows the
|
||||
/// published value alone, which a held batch's gate is read against. The oldest batch past
|
||||
/// it became so at that completion, so none of its run counts yet.
|
||||
pub(crate) fn ahead(&self, ran: u64, completed: u64, budget: u64) -> Room {
|
||||
let left_already = self
|
||||
.batches
|
||||
.iter()
|
||||
@@ -218,10 +273,10 @@ impl Flight {
|
||||
_ => 0,
|
||||
};
|
||||
let left = self.expected - gone_expected - credit;
|
||||
if left < BUDGET {
|
||||
if left < budget {
|
||||
return Room::Go;
|
||||
}
|
||||
let over = left - BUDGET + 1;
|
||||
let over = left - budget + 1;
|
||||
let after = (oldest.expected - credit >= over).then_some(over);
|
||||
Room::Hold { after, through }
|
||||
}
|
||||
|
||||
@@ -286,6 +286,7 @@ pub(crate) struct Counters {
|
||||
/// By `HeldFor`, in its order: the looks that found a line's head held for each reason.
|
||||
heads_held_for: [AtomicU64; HeldFor::COUNT],
|
||||
heads_waiting_at_their_gate: AtomicU64,
|
||||
heads_let_go_unshared_idle: AtomicU64,
|
||||
host_step_gates_narrowed: AtomicU64,
|
||||
heads_awaiting_check_signals: AtomicU64,
|
||||
batches_held_past_a_look: AtomicU64,
|
||||
@@ -3362,6 +3363,14 @@ impl Counters {
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// A look let a head go under `unshared_hold::IDLE_BUDGET` that `unshared_hold::BUDGET`
|
||||
/// would hold back: no unshared queue on its `VkQueue` committed within
|
||||
/// `unshared_hold::ACTIVE`.
|
||||
pub(crate) fn head_let_go_unshared_idle(&self) {
|
||||
self.heads_let_go_unshared_idle
|
||||
.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) {
|
||||
@@ -7063,8 +7072,17 @@ pub struct WorkCounts {
|
||||
/// `Device::new_command_queue_unshared` shares with theirs, because 2 ms or more of other
|
||||
/// 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.
|
||||
/// 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`).
|
||||
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
|
||||
/// (`heads_held_for_unshared_isolation`), because no unshared queue there committed a command
|
||||
/// buffer within the last 50 ms and less than 16 ms was in flight (`unshared_hold.rs`'s idle
|
||||
/// budget): a compositor gone quiet holds back only work queued 16 ms deep. The unshared
|
||||
/// 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,
|
||||
/// 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
|
||||
@@ -10912,6 +10930,7 @@ impl Device {
|
||||
heads_held_for_event_values: held_for(HeldFor::EventValue),
|
||||
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_waiting_at_their_gate: counters
|
||||
.heads_waiting_at_their_gate
|
||||
.load(Ordering::Relaxed),
|
||||
|
||||
Vendored
+1
-1
@@ -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 = 2274;
|
||||
pub const RUNTIME_VERSION: u32 = 2275;
|
||||
|
||||
/// 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
|
||||
|
||||
@@ -651,7 +651,11 @@ pub enum UnsharedIsolationPolicy {
|
||||
/// other is submitted until it completes. The next batch is submitted before the one ahead
|
||||
/// ends, so the GPU is not left idle between them where the host's scheduler thread runs in
|
||||
/// time; a batch longer than its command queue's recent ones still holds the unshared queue
|
||||
/// for its whole length, as one command buffer is one submission.
|
||||
/// for its whole length, as one command buffer is one submission. The 2 ms holds while an
|
||||
/// unshared queue there committed a command buffer within the last 50 ms; while none has,
|
||||
/// 16 ms does, so a compositor's first command buffer after a quiet stretch waits behind at
|
||||
/// most about 16 ms of the other queues' expected work and one batch, and an application
|
||||
/// that keeps less queued beside a quiet compositor is not held.
|
||||
#[default]
|
||||
Bounded,
|
||||
/// Every ready batch is submitted at once: an unshared queue's command buffer waits behind
|
||||
|
||||
@@ -3041,6 +3041,7 @@ field metal2vulkan-runtime::WorkCounts.heads_held_for_event_values pub heads_hel
|
||||
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_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
|
||||
field metal2vulkan-runtime::WorkCounts.heap_arrays_copied pub heap_arrays_copied: u64
|
||||
field metal2vulkan-runtime::WorkCounts.heap_sample_move_images_lent pub heap_sample_move_images_lent: u64
|
||||
|
||||
|
Can't render this file because it is too large.
|
+8
-1
@@ -282,7 +282,14 @@ 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. Beside an application keeping three
|
||||
sends the unshared one first. 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
|
||||
buffer after its quiet stretch waits behind at most about 16 ms of the other queues' expected
|
||||
work and one batch, the 2 ms applying from that commit on
|
||||
(`WorkCounts::heads_let_go_unshared_idle` counts the heads the 16 ms let go where 2 ms would
|
||||
hold them). Beside an application keeping three
|
||||
30 ms command buffers in flight, a compositor's median wait fell from 75 to 17.5 ms on the Iris
|
||||
Xe and from 71-84 to 18 ms on the Radeon 780M, with no throughput lost on a quiet host; under
|
||||
the host's CPU load the GPU idles more (docs/FAST-PATHS.md has the numbers). Counted:
|
||||
|
||||
+20
-1
@@ -129,7 +129,26 @@ 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. `unshared_isolation = UnsharedIsolationPolicy::Off`
|
||||
batch goes in before the one ahead ends. 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),
|
||||
while none has. Beside a quiet compositor, an application keeping less than 16 ms of expected
|
||||
work queued is not held (`WorkCounts::heads_let_go_unshared_idle` counts the heads 2 ms would
|
||||
have held): Geekbench 7's Super Resolution on the Radeon 780M (RADV) kept at most 6.48 ms
|
||||
queued ahead of a batch with no hold (a batch's submission to its GPU start 1.41 ms at the
|
||||
median, 4.68 ms at the 90th percentile, 3,920 command buffers; reims's perfscout4, gbo-780m),
|
||||
and the hold's costing replayed over that trace (each batch at its queue's expected run as it
|
||||
went, the oldest credited its run) put 8.34 ms in flight at the 90th percentile of its 6,855
|
||||
submissions and 14.73 ms at most: the 16 ms budget holds none of them where 2 ms holds 3,168
|
||||
(Face Tracking 7 of 1,892 against 607, Background Blur none of 1,998 against 644); a queue's
|
||||
first batch, of unknown length, still holds the next until it completes. One keeping more
|
||||
still has 16 ms queued as its next batch goes. The trade: the
|
||||
compositor's first command buffer after a quiet stretch goes in behind the work already
|
||||
submitted, at most about 16 ms of expected work and the last batch let go (beside an
|
||||
application keeping three 30 ms command buffers in flight, the first's last 16 ms and the
|
||||
second, where `Off` puts all three ahead: about 75 ms at the median below), and the 2 ms bound
|
||||
applies from its commit on, to the next ones. `unshared_isolation = UnsharedIsolationPolicy::Off`
|
||||
submits every ready batch at once: peak rate with no hold, the unshared queue's command buffer
|
||||
behind every batch submitted before it. Not an accuracy choice: it trades the other queues'
|
||||
submission ahead for the unshared queue's wait. The runtime's choice: no pipeline differs.
|
||||
|
||||
Reference in new issue
Block a user