RUNTIME 2303: a committing or waiting thread's pass leaves other queues' batches behind an unshared head it cannot send
A thread about to block (Scheduler::submit_before_waiting) or one that just committed with
commit_and_submit (Scheduler::submit_at_commit) takes the inbox in and submits only the batches
that need nothing of the scheduler's thread (submit_plain_ready, plain_ready). take_in counts
the unshared commit taken, so RUNTIME 2300's gate in plain() lets other queues' batches through;
Order::next puts the unshared queue's head first but skips any head `ready` refuses and goes on
to the next. So where that head is ready for the scheduler's own look but not plain for this
pass (a submission or scheduled handler for a waiting thread, a host step already recorded, a
switch of storage forms riding on it), another queue's batch on its VkQueue whose room had come
was submitted ahead of it, where the scheduler's pass sends the unshared one first
("Heads put first").
The rule: such a pass notes the VkQueue of an unshared head it leaves that the scheduler's look
would find ready (first_for_the_thread: nothing of submit_ready's holds, every event value
reached), and leaves the other queues' batches held back there to the scheduler's thread too
(left_behind_unshared), which its caller already wakes for what it left: that thread's next pass
sends the unshared one first and them next. Bound: one wake and one pass of that thread. An
unshared head not ready for that thread either holds nothing, as its own pass lets the batch go
then. submit_ready's five holds move into holds_back(), shared by both, with the same order and
the same counts; CommandBufferShared::held_back_on() factors what held_for_unshared and
unshared_commits both tested. No switch, no counter, no public item, no Degradation kind.
Not covered, a known limit now written in unshared_hold.rs ("Deferred commits"): a commit left
to the lowering thread under RenderLoweringPolicy::Worker; counting it posted at the call would
hold other queues' batches through the lowering backlog, leaving the GPU idle.
Tests (queue_share_device, lavapipe): a waiting thread's pass with the scheduler's thread held in
a submission handler (waiter_submits::Held, now shared) takes in an application's fill and an
unshared fill with a scheduled handler; a committing thread's pass (commit_and_submit, default
Grouped completion: the fill goes alone where the device groups) takes in an application's fill
while the unshared queue's dispatch waits with its host step recorded (the pool's making held,
the steps' thread held at new trace points Step and Stepped while the scheduler's thread is held
in a submission handler). Each asserts that the pass ran and that the unshared one began first.
Docs: unshared_hold.rs ("Passes of other threads", "Deferred commits"), FAST-PATHS unshared
isolation row, submit_plain_ready.
Verified (msi lavapipe, m3-max-29578 at 258953844d): clippy plain and --cfg m2v_cpu_icd 0;
91/91 of unshared_hold, queue_share, queue_share_device, scheduler, scheduler_held_wakes,
scheduler_wakes, inbox, waiter_submits, commit_and_submit, hold_sites, dispatch_pending.
Both new tests: passes 1, batches the pass submitted 0, the other queue's buffer began
0.100/0.108 ms after the unshared one. Negative control m3-max-29586 (rule off): both fail,
the pass submitted 1 and the other buffer began 0.35/0.34 ms before the unshared one.
This commit is contained in:
1 parent
2216540a68
commit
2818c1fcd0
9 files changed
+313
-43
No files matched your search
@@ -1658,10 +1658,16 @@ pub(crate) mod trace {
|
||||
/// The thread submitting a batch, as its submission enters its first work's take
|
||||
/// (`submit.rs`, `slow_submissions.rs`).
|
||||
FirstWork,
|
||||
/// A steps' thread, before it records the host step handed to it
|
||||
/// (`scheduler/steps.rs`).
|
||||
Step,
|
||||
/// A steps' thread, once it recorded a host step, ended it and woke the scheduler's
|
||||
/// thread (`scheduler/steps.rs`).
|
||||
Stepped,
|
||||
}
|
||||
|
||||
/// Of each [`Point`]: whether a test holds threads there, and whether one reached it since.
|
||||
static POINTS: Mutex<[(bool, bool); 6]> = Mutex::new([(false, false); 6]);
|
||||
static POINTS: Mutex<[(bool, bool); 8]> = Mutex::new([(false, false); 8]);
|
||||
static POINTS_CHANGED: std::sync::Condvar = std::sync::Condvar::new();
|
||||
|
||||
/// Hold every thread that reaches `point` from now on, until [`release`].
|
||||
|
||||
@@ -4916,13 +4916,7 @@ impl CommandBufferShared {
|
||||
/// 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;
|
||||
}
|
||||
let index = self.queue.vk_queue();
|
||||
if !self.device.holds_back_for_unshared(index) {
|
||||
return None;
|
||||
}
|
||||
let index = self.held_back_on()?;
|
||||
let shared = self.device.shared();
|
||||
let slot = &shared.queues[index];
|
||||
let now = crate::gpu_time::host_nanos();
|
||||
@@ -4955,14 +4949,20 @@ impl CommandBufferShared {
|
||||
/// 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)> {
|
||||
let index = self.held_back_on()?;
|
||||
Some(self.device.shared().queues[index].share.unshared_commits())
|
||||
}
|
||||
|
||||
/// The index of its `VkQueue` where its batches are held back there for an unshared queue
|
||||
/// (`unshared_hold.rs`): its own queue is not unshared, the device is not lost, and an
|
||||
/// unshared queue holds that `VkQueue` under `UnsharedIsolationPolicy::Bounded`; `None`
|
||||
/// elsewhere.
|
||||
pub(crate) fn held_back_on(&self) -> Option<usize> {
|
||||
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())
|
||||
self.device.holds_back_for_unshared(index).then_some(index)
|
||||
}
|
||||
|
||||
/// This thread doing the command buffer's work until the guard goes
|
||||
|
||||
@@ -1784,30 +1784,8 @@ fn submit_ready(
|
||||
let (mut unshared_wake, mut isolating) = (None, false);
|
||||
let behind = |order: &Order<Held>, sequence| is_behind(order, binary, &mut memo, sequence);
|
||||
let next = state.order.next(goes_first, behind, |held| {
|
||||
if !binary.ready(&held.binary_needs) {
|
||||
held.held_for(HeldFor::BinarySemaphore);
|
||||
return None;
|
||||
}
|
||||
// The submission of its event group waits while a rebind encodes encoders of it again
|
||||
// (`command_buffer/reencode.rs`).
|
||||
if held.buffer.reencode_pending() {
|
||||
held.held_for(HeldFor::Reencoding);
|
||||
return None;
|
||||
}
|
||||
// Held for a decoded twin's CPU decode it may read: any batch, while an untracked
|
||||
// texture's is left.
|
||||
if untracked_decodes > 0 || (!decodes.is_empty() && reads_decoding(held, decodes)) {
|
||||
held.held_for(HeldFor::Decode);
|
||||
return None;
|
||||
}
|
||||
// Held for its host step.
|
||||
if held.segments && held.buffer.needs_host_step(held.index) {
|
||||
held.held_for(HeldFor::HostStep);
|
||||
return None;
|
||||
}
|
||||
// Held for its submission checks.
|
||||
if held.checked && held.buffer.needs_check(held.index) {
|
||||
held.held_for(HeldFor::Check);
|
||||
if let Some(reason) = holds_back(held, binary, decodes, untracked_decodes) {
|
||||
held.held_for(reason);
|
||||
return None;
|
||||
}
|
||||
let waits = event_waits(held);
|
||||
@@ -1986,6 +1964,40 @@ fn submit_ready(
|
||||
}
|
||||
}
|
||||
|
||||
/// What holds `held`, a line's head, back from a look of the scheduler's thread before its event
|
||||
/// waits and its room on an unshared queue's `VkQueue` ([`submit_ready`]); `None` where nothing
|
||||
/// does. A pass of another thread asks it of an unshared queue's head it leaves
|
||||
/// ([`first_for_the_thread`]).
|
||||
fn holds_back(
|
||||
held: &Held,
|
||||
binary: &BinarySignals<vk::Semaphore>,
|
||||
decodes: &BTreeMap<ResourceKey, usize>,
|
||||
untracked_decodes: usize,
|
||||
) -> Option<HeldFor> {
|
||||
if !binary.ready(&held.binary_needs) {
|
||||
return Some(HeldFor::BinarySemaphore);
|
||||
}
|
||||
// The submission of its event group waits while a rebind encodes encoders of it again
|
||||
// (`command_buffer/reencode.rs`).
|
||||
if held.buffer.reencode_pending() {
|
||||
return Some(HeldFor::Reencoding);
|
||||
}
|
||||
// Held for a decoded twin's CPU decode it may read: any batch, while an untracked texture's
|
||||
// is left.
|
||||
if untracked_decodes > 0 || (!decodes.is_empty() && reads_decoding(held, decodes)) {
|
||||
return Some(HeldFor::Decode);
|
||||
}
|
||||
// Held for its host step.
|
||||
if held.segments && held.buffer.needs_host_step(held.index) {
|
||||
return Some(HeldFor::HostStep);
|
||||
}
|
||||
// Held for its submission checks.
|
||||
if held.checked && held.buffer.needs_check(held.index) {
|
||||
return Some(HeldFor::Check);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Whether a pass asks `held` before the heads committed before it ([`Order::next`]'s `first`):
|
||||
/// an unshared queue's batch on a `VkQueue` whose other queues' work is held back for it
|
||||
/// (`unshared_hold.rs`), so a pass that finds that work let go and it ready together sends it
|
||||
@@ -2118,6 +2130,14 @@ impl AtCommit {
|
||||
/// queue but one whose footprint runs in commit order with it while it keeps its place, as in the
|
||||
/// thread's own pass. How many it submitted, and how many of them alone ([`Plain`]).
|
||||
///
|
||||
/// **It sends no batch ahead of an unshared queue's head that the thread would send first.** The
|
||||
/// order puts an unshared queue's head first ([`goes_first`]) only where `ready` takes it; where
|
||||
/// this pass leaves such a head that the thread's own look would find ready
|
||||
/// ([`first_for_the_thread`]), it leaves the other queues' batches held back on that head's
|
||||
/// `VkQueue` to the thread too ([`left_behind_unshared`]), whose next pass, which the caller
|
||||
/// wakes it for, sends the unshared one first and them next (`unshared_hold.rs`, "Passes of other
|
||||
/// threads").
|
||||
///
|
||||
/// **It touches none of the thread's own state.** [`Awaits`] is what the thread's last pass left
|
||||
/// it asleep on, its `vkWaitSemaphores` among them, and [`Left`] is the work that pass handed it:
|
||||
/// a waiting thread that cleared the first would leave the thread asleep with work ready, and one
|
||||
@@ -2146,10 +2166,22 @@ fn submit_plain_ready(
|
||||
} = &mut *state;
|
||||
let (binary, decodes, untracked) = (&*binary, &*decodes, *untracked_decodes);
|
||||
let mut memo = Behind::default();
|
||||
// The `VkQueue`s of the unshared queues' heads this look leaves that the thread's own
|
||||
// look would send first: other queues' batches there are left to the thread too.
|
||||
let mut first_left = Vec::new();
|
||||
order.next(
|
||||
goes_first,
|
||||
|order, sequence| is_behind(order, binary, &mut memo, sequence),
|
||||
|held| plain_ready(held, binary, decodes, untracked, passer),
|
||||
|held| {
|
||||
if left_behind_unshared(held, &first_left) {
|
||||
return None;
|
||||
}
|
||||
let waits = plain_ready(held, binary, decodes, untracked, passer);
|
||||
if waits.is_none() && first_for_the_thread(held, binary, decodes, untracked) {
|
||||
first_left.extend(held.buffer.unshared_vk_queue());
|
||||
}
|
||||
waits
|
||||
},
|
||||
)
|
||||
};
|
||||
let Some((queue, sequence, mut held, waits)) = taken else {
|
||||
@@ -2258,6 +2290,31 @@ fn submit_plain_ready(
|
||||
submitted
|
||||
}
|
||||
|
||||
/// Whether `held`, a line's head that [`submit_plain_ready`] leaves, is an unshared queue's that
|
||||
/// the scheduler's thread's own look would send first ([`goes_first`]): nothing holds it back
|
||||
/// from that look ([`holds_back`]) and every event value it waits for is reached, though the
|
||||
/// pass of a thread other than the scheduler's leaves it (its submission or scheduled handlers
|
||||
/// for a thread about to block, its host step recorded, a switch of storage forms riding on it).
|
||||
fn first_for_the_thread(
|
||||
held: &Held,
|
||||
binary: &BinarySignals<vk::Semaphore>,
|
||||
decodes: &BTreeMap<ResourceKey, usize>,
|
||||
untracked_decodes: usize,
|
||||
) -> bool {
|
||||
goes_first(held)
|
||||
&& holds_back(held, binary, decodes, untracked_decodes).is_none()
|
||||
&& events_reachable(held)
|
||||
}
|
||||
|
||||
/// Whether [`submit_plain_ready`] leaves `held` to the scheduler's thread for an unshared queue's
|
||||
/// head it left on its `VkQueue` (`first_left`, those heads' `VkQueue`s,
|
||||
/// [`first_for_the_thread`]): another queue's batch held back there (`unshared_hold.rs`), which
|
||||
/// that thread's next pass sends after the unshared one.
|
||||
fn left_behind_unshared(held: &Held, first_left: &[usize]) -> bool {
|
||||
!first_left.is_empty()
|
||||
&& (held.buffer.held_back_on()).is_some_and(|index| first_left.contains(&index))
|
||||
}
|
||||
|
||||
/// What [`submit_plain_ready`] submitted.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
struct Plain {
|
||||
|
||||
@@ -133,6 +133,8 @@ fn record_steps(shared: &SchedulerShared, first: bool) {
|
||||
/// thread, before the command buffer is let go of; false, with nothing recorded, once the process
|
||||
/// is exiting.
|
||||
fn record(shared: &SchedulerShared, work: Work) -> bool {
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
super::trace::at(super::trace::Point::Step);
|
||||
let Some(busy) = exit_guard::enter() else {
|
||||
return false;
|
||||
};
|
||||
@@ -156,6 +158,8 @@ fn record(shared: &SchedulerShared, work: Work) -> bool {
|
||||
if !stopping {
|
||||
shared.wake_thread(Woken::Host, shared.nudge.get());
|
||||
}
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
super::trace::at(super::trace::Point::Stepped);
|
||||
// Out of the section: it may be the command buffer's last reference.
|
||||
drop(work);
|
||||
true
|
||||
|
||||
@@ -49,6 +49,12 @@
|
||||
//! 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.
|
||||
//! - **Passes of other threads** (`unshared_hold.rs`). A thread about to block, and a committing
|
||||
//! thread (`commit_and_submit`), each pass for itself with the scheduler's thread held in a
|
||||
//! submission handler, and take in an application's command buffer beside the unshared queue's
|
||||
//! head, which that pass may not submit (a scheduled handler; a host step recorded, the steps'
|
||||
//! thread held at trace points): the unshared one goes first, as the scheduler's own pass sends
|
||||
//! 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
|
||||
@@ -58,14 +64,16 @@
|
||||
//! safety cfgs (`m2v_gpu`, `m2v_cpu_icd`).
|
||||
|
||||
use super::blit_holds::Scratch;
|
||||
use super::dispatch_pending::{self, Buffers, Grid};
|
||||
use super::waiter_submits::Held as HeldThread;
|
||||
use crate::command_buffer::completion::trace;
|
||||
use crate::tests::SETTLE;
|
||||
use crate::{
|
||||
Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, Device, DeviceKind, DeviceOptions,
|
||||
ResourceOptions, ShaderCacheOptions, WorkCounts,
|
||||
ResourceOptions, ShaderCacheOptions, Size, WorkCounts,
|
||||
};
|
||||
use metal2vulkan::device::{
|
||||
CompletionPolicy, DevicePolicy, QueueSharingPolicy, UnsharedIsolationPolicy,
|
||||
CompletionPolicy, DevicePolicy, PipelineWaitPolicy, QueueSharingPolicy, UnsharedIsolationPolicy,
|
||||
};
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use std::sync::{mpsc, Arc, Mutex};
|
||||
@@ -1535,3 +1543,170 @@ fn an_unshared_commit_posted_during_a_pass_goes_before_work_let_go_after_it() {
|
||||
);
|
||||
assert!(held > 0, "a look held it for the unshared commit");
|
||||
}
|
||||
|
||||
/// The threads one threadgroup of the held dispatch runs in
|
||||
/// [`a_committing_thread_s_pass_leaves_work_behind_an_unshared_head_with_its_step_recorded`].
|
||||
const STEP_THREADS: u64 = 64;
|
||||
|
||||
/// A device for [`unshared_went_first`]'s tests: `PerQueue` (no queue moves), the unshared hold
|
||||
/// `Bounded`, `completion` its completion policy, every call waiting for a pipeline still being
|
||||
/// made until it is made (`PipelineWaitPolicy::Exact`: a bound passed would drop a dispatch whose
|
||||
/// making a test holds); with an application's queue and an unshared queue on its `VkQueue`, each
|
||||
/// queue's expected run a small fill's (`unshared_hold::Expected`), so the application's batches
|
||||
/// find their room at once.
|
||||
fn beside_unshared(
|
||||
scratch: &Scratch,
|
||||
completion: CompletionPolicy,
|
||||
) -> (Device, CommandQueue, CommandQueue) {
|
||||
let mut options = options(scratch, QueueSharingPolicy::PerQueue);
|
||||
options.policy.unshared_isolation = UnsharedIsolationPolicy::Bounded;
|
||||
options.policy.completion = completion;
|
||||
options.policy.pipeline_waits = PipelineWaitPolicy::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 scratch = device.new_buffer(4096, ResourceOptions::private()).unwrap();
|
||||
for queue in [&app, &app, &unshared] {
|
||||
let command_buffer = small_fill(queue, &scratch);
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
}
|
||||
(device, app, unshared)
|
||||
}
|
||||
|
||||
/// A command buffer of `queue` that fills `buffer`'s first 256 bytes.
|
||||
fn small_fill(queue: &CommandQueue, buffer: &Buffer) -> CommandBuffer {
|
||||
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
|
||||
}
|
||||
|
||||
/// Both completed, the unshared queue's command buffer `drawn` began before another queue's
|
||||
/// `other` (their kernel starts, the scheduler's calls of their first submissions).
|
||||
fn unshared_went_first(leg: &str, drawn: &CommandBuffer, other: &CommandBuffer) {
|
||||
for command_buffer in [drawn, other] {
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(
|
||||
command_buffer.status(),
|
||||
CommandBufferStatus::Completed,
|
||||
"{leg}: {:?}",
|
||||
command_buffer.error()
|
||||
);
|
||||
}
|
||||
let ahead = (other.kernel_start_time() - drawn.kernel_start_time()) * 1e3;
|
||||
println!("{leg}: the other queue's command buffer began {ahead:.3} ms after the unshared one");
|
||||
assert!(
|
||||
ahead > 0.0,
|
||||
"{leg}: another queue's batch went ahead of the unshared queue's head, which the \
|
||||
scheduler's pass sends first"
|
||||
);
|
||||
}
|
||||
|
||||
/// Lets go of the threads held at the steps' trace points as it drops, a failing test's
|
||||
/// unwinding too.
|
||||
struct StepsLetGo;
|
||||
|
||||
impl Drop for StepsLetGo {
|
||||
fn drop(&mut self) {
|
||||
trace::release(trace::Point::Step);
|
||||
trace::release(trace::Point::Stepped);
|
||||
}
|
||||
}
|
||||
|
||||
/// A thread about to block passes for itself (`Scheduler::submit_before_waiting`) with the
|
||||
/// scheduler's thread held in a submission handler (`waiter_submits::Held`), and takes in an
|
||||
/// application's command buffer and, committed after it, the unshared queue's, which has a
|
||||
/// scheduled handler: such a pass never submits that one, where the scheduler's own pass would
|
||||
/// send it first (`order.rs`, "Heads put first"). So the waiting thread's pass leaves the
|
||||
/// application's to the scheduler's thread too, whose next pass sends the unshared one first
|
||||
/// (`unshared_hold.rs`, "Passes of other threads"). Under `CompletionPolicy::Exact`, where a
|
||||
/// waiting thread's pass submits any queue's batch on every driver; without the rule it submits
|
||||
/// the application's, ahead of the unshared one.
|
||||
#[test]
|
||||
fn a_waiting_thread_s_pass_leaves_work_behind_an_unshared_head_it_cannot_send() {
|
||||
let scratch = Scratch::new("unshared-hold-waiter");
|
||||
let (device, app, unshared) = beside_unshared(&scratch, CompletionPolicy::Exact);
|
||||
let [target, small, holder] =
|
||||
[(); 3].map(|()| (device.new_buffer(4096, ResourceOptions::private())).unwrap());
|
||||
let held = HeldThread::new(&app, &holder);
|
||||
let other = small_fill(&app, &target);
|
||||
other.commit().unwrap();
|
||||
let drawn = small_fill(&unshared, &small);
|
||||
drawn
|
||||
.add_scheduled_handler(Box::new(|_: &CommandBuffer| {}))
|
||||
.unwrap();
|
||||
drawn.commit().unwrap();
|
||||
let before = device.work_counts();
|
||||
// Completed or not, the pass was made.
|
||||
let _ = other.wait_until_completed_for(Duration::ZERO);
|
||||
let after = device.work_counts();
|
||||
drop(held);
|
||||
let passes = after.scheduler_passes_by_waiters - before.scheduler_passes_by_waiters;
|
||||
let submitted = after.batches_submitted_by_waiters - before.batches_submitted_by_waiters;
|
||||
println!("the waiting thread's passes {passes}, batches it submitted {submitted}");
|
||||
assert_eq!(passes, 1, "the waiting thread passed for the commits");
|
||||
unshared_went_first("a waiting thread's pass", &drawn, &other);
|
||||
}
|
||||
|
||||
/// A committing thread's own pass (`CommandBuffer::commit_and_submit`) takes in an application's
|
||||
/// command buffer while the unshared queue's head waits in the order with its host step recorded
|
||||
/// (a dispatch whose pipeline's making the device's pool held, `pool::held`), which such a pass
|
||||
/// never submits, where the scheduler's own pass would send it first: the steps' thread is held
|
||||
/// before the step (`trace::Point::Step`) while the scheduler's thread is held in a submission
|
||||
/// handler, its pass finding the dispatch stepping, then let go to record it. So the committing
|
||||
/// thread's pass leaves the application's command buffer to the scheduler's thread too
|
||||
/// (`unshared_hold.rs`, "Passes of other threads"). Under the default `CompletionPolicy`: where
|
||||
/// the device's batches group, the committing thread's pass sends the application's batch alone,
|
||||
/// its `VkQueue` running at most one earlier submission; without the rule it sends it ahead of
|
||||
/// the dispatch.
|
||||
#[test]
|
||||
fn a_committing_thread_s_pass_leaves_work_behind_an_unshared_head_with_its_step_recorded() {
|
||||
let scratch = Scratch::new("unshared-hold-committer");
|
||||
let (device, app, unshared) = beside_unshared(&scratch, CompletionPolicy::default());
|
||||
let state = dispatch_pending::state(&device);
|
||||
let buffers = Buffers::new(&device);
|
||||
let [target, holder] =
|
||||
[(); 2].map(|()| (device.new_buffer(4096, ResourceOptions::private())).unwrap());
|
||||
let let_go = StepsLetGo;
|
||||
let making = crate::pipeline::pool::held::hold();
|
||||
let grid = Grid::One(Size::new(STEP_THREADS, 1, 1));
|
||||
let drawn = dispatch_pending::dispatch(&unshared, &state, &buffers, grid);
|
||||
drawn.commit().unwrap();
|
||||
trace::hold_at(trace::Point::Step);
|
||||
drop(making);
|
||||
assert!(
|
||||
trace::reached(trace::Point::Step, WAIT),
|
||||
"the dispatch's host step was never handed over"
|
||||
);
|
||||
let held = HeldThread::new(&app, &holder);
|
||||
trace::hold_at(trace::Point::Stepped);
|
||||
trace::release(trace::Point::Step);
|
||||
assert!(
|
||||
trace::reached(trace::Point::Stepped, WAIT),
|
||||
"the dispatch's host step was never recorded"
|
||||
);
|
||||
trace::release(trace::Point::Stepped);
|
||||
let before = device.work_counts();
|
||||
let other = small_fill(&app, &target);
|
||||
other.commit_and_submit().unwrap();
|
||||
let after = device.work_counts();
|
||||
drop(held);
|
||||
drop(let_go);
|
||||
let passes = after.scheduler_passes_at_commit - before.scheduler_passes_at_commit;
|
||||
let submitted = after.batches_submitted_at_commit - before.batches_submitted_at_commit;
|
||||
println!("the committing thread's passes {passes}, batches it submitted {submitted}");
|
||||
assert_eq!(passes, 1, "the committing thread passed for its commit");
|
||||
unshared_went_first("a committing thread's pass", &drawn, &other);
|
||||
assert!(
|
||||
buffers.written(STEP_THREADS),
|
||||
"the dispatch did not write what Metal's writes"
|
||||
);
|
||||
}
|
||||
@@ -87,7 +87,7 @@ fn device(cache: &Path, completion: CompletionPolicy) -> Device {
|
||||
/// every commit made meanwhile (`CommandBuffer::add_submission_handler`). While it is held, a
|
||||
/// commit is taken in only by a thread about to block for it. Dropping it lets the handler return
|
||||
/// and waits until its command buffer completed.
|
||||
struct Held {
|
||||
pub(super) struct Held {
|
||||
command_buffer: CommandBuffer,
|
||||
release: Option<mpsc::Sender<()>>,
|
||||
}
|
||||
@@ -95,7 +95,7 @@ struct Held {
|
||||
impl Held {
|
||||
/// Hold the thread: commit a fill of `scratch` on `side` whose submission handler says it
|
||||
/// began, and then waits until it is let go; return once it began.
|
||||
fn new(side: &CommandQueue, scratch: &Buffer) -> Held {
|
||||
pub(super) fn new(side: &CommandQueue, scratch: &Buffer) -> Held {
|
||||
let command_buffer = side.command_buffer().unwrap();
|
||||
let mut blit = command_buffer.blit_command_encoder().unwrap();
|
||||
blit.fill_buffer(scratch, 0..16, 0).unwrap();
|
||||
|
||||
@@ -72,6 +72,27 @@
|
||||
//! 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`.
|
||||
//! - **Passes of other threads.** A thread about to block, and a thread that just committed with
|
||||
//! `CommandBuffer::commit_and_submit`, pass for themselves, and submit only the batches that
|
||||
//! need nothing of the scheduler's thread (`scheduler/mod.rs`'s `submit_plain_ready`). Where
|
||||
//! such a pass leaves an unshared queue's head that the scheduler's own look would find ready
|
||||
//! and send first (one with a submission or scheduled handler, for a thread about to block; one
|
||||
//! whose host step is recorded; one a switch of storage forms rides on), it leaves the other
|
||||
//! queues' batches held back on that head's `VkQueue` to the scheduler's thread too, which it
|
||||
//! wakes: that thread's next pass sends the unshared one first and them next. They wait for that
|
||||
//! wake and pass, no more. An unshared head the scheduler's thread would not find ready either
|
||||
//! (an event value not reached, a host step not recorded, its checks) leaves them to the pass,
|
||||
//! as that thread's own pass lets them go then. Without the rule such a pass sent another
|
||||
//! queue's batch ahead of the unshared one (`tests::queue_share_device`).
|
||||
//! - **Deferred commits** (a known limit). Under `RenderLoweringPolicy::Worker`, an unshared
|
||||
//! queue's commit left to the device's lowering thread (`render/queued_commits.rs`) counts as
|
||||
//! posted only once its own work ran and its batches reach the scheduler, so a batch whose room
|
||||
//! comes while that lowering runs goes ahead of it. Counting the commit as posted at its call
|
||||
//! would hold such a batch through the lowering of every commit queued before it, which run in
|
||||
//! commit order across all queues on one runner: the program's encoders still to lower, not one
|
||||
//! pass. With less than the budget of other queues' work left on the GPU as the room came, the
|
||||
//! GPU would wait for up to that backlog, less about 2 ms, each time the compositor committed
|
||||
//! behind one. The default `RenderLoweringPolicy::AtCall` defers no commit.
|
||||
//! - **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
|
||||
|
||||
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 = 2302;
|
||||
pub const RUNTIME_VERSION: u32 = 2303;
|
||||
|
||||
/// 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
|
||||
|
||||
+8
-1
@@ -135,7 +135,14 @@ known. The rest of the differences are docs/API.md section 9's precision notes.
|
||||
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
|
||||
batch let go during such a pass ahead of them. A thread about to block, or one that just
|
||||
committed with `commit_and_submit`, passes for itself and submits only batches that need
|
||||
nothing of the scheduler's thread; where it leaves a compositor's command buffer that the
|
||||
scheduler's thread would send first (a scheduled or submission handler for a thread about to
|
||||
block, a host step recorded), it leaves the other queues' batches on that `VkQueue` to that
|
||||
thread too, which then sends the compositor's first: they wait for one wake and pass of it.
|
||||
Under `RenderLoweringPolicy::Worker` a compositor's commit left to the lowering thread holds no
|
||||
batch until its work ran (`unshared_hold.rs`, "Deferred commits"). 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),
|
||||
|
||||
Reference in new issue
Block a user