Submissions count a batch's pending work from the completed value its plan took
command_buffer/submit.rs read each VkQueue's completed value once for the hazard tracker, whose plan of the batch orders after the work it has not seen complete, then read its own queue's value a second time for WorkCounts::batches_with_none_pending and kin. A completion seen between the two reads made the count say "nothing pending" of a batch the plan had ordered after work in flight, so bare_starts and batches_with_none_pending could disagree for the same batch. The count now comes from the tracker's own state: Tracker::pending_before(at), the batches of at's queue before it past the last value Tracker::completed took for that queue, the value the plan retires by. The second read is gone. Test: tests::tracker::a_batch_is_counted_pending_behind_exactly_the_work_its_plan_orders_after: a read after a write planned with the write's batch unseen has a barrier and counts it pending, and planned after its completion neither; another queue's completion and an older value leave the count as it was. (cherry picked from commit 4e4ea3cfa3d5412d14a2df75d8ccf60ae8440feb)
This commit is contained in:
1 parent
154d0e2734
commit
eb68e03449
4 files changed
+54
-6
No files matched your search
@@ -577,10 +577,11 @@ impl CommandBufferShared {
|
||||
reached.push((value > 0).then_some((vk_queue.timeline, value)));
|
||||
}
|
||||
reached.extend(device.own_completed());
|
||||
// The batches before it on its queue that the host has not seen complete: each took the
|
||||
// next value (`WorkCounts::batches_with_none_pending` and kin).
|
||||
let completed = shared.queues[queue].completed_value();
|
||||
(shared.counts).batch_submitted_behind(scheduler.values[queue].saturating_sub(completed));
|
||||
// The batches before it on its queue that the host has not seen complete, as of the value
|
||||
// the tracker just took, which its plan orders by: each took the next value
|
||||
// (`WorkCounts::batches_with_none_pending` and kin). A second read of the queue's value
|
||||
// could see a completion the plan did not.
|
||||
(shared.counts).batch_submitted_behind(scheduler.tracker.pending_before(at));
|
||||
// One a hang's thread made `Scheduled` early began then (`hang.rs`).
|
||||
if index == 0 && self.kernel.start() == 0 {
|
||||
self.kernel.begin();
|
||||
|
||||
@@ -860,6 +860,43 @@ fn the_state_retires_only_through_the_completed_value() {
|
||||
assert_eq!(queue.entries(), 0);
|
||||
}
|
||||
|
||||
/// A batch's count of the earlier batches of its `VkQueue` the host has not seen complete
|
||||
/// ([`Tracker::pending_before`], which `WorkCounts::batches_with_none_pending` and kin count) is
|
||||
/// the tracker's own, from the completed value its plan retires by: a read after the write of the
|
||||
/// batch before it has a barrier exactly where that batch is counted pending. A count from a
|
||||
/// later read of the queue's value could find that batch complete where the plan ordered after it.
|
||||
#[test]
|
||||
fn a_batch_is_counted_pending_behind_exactly_the_work_its_plan_orders_after() {
|
||||
let write = || one(&[writes(1, bytes(0..256), copy_write())]);
|
||||
let read = || one(&[reads(1, bytes(0..256), copy_read())]);
|
||||
for seen in [0, 1] {
|
||||
let mut queue = Tracker::default();
|
||||
assert_eq!(queue.pending_before(at(1)), 0);
|
||||
assert_eq!(commit(&mut queue, &[write()], 1), [None]);
|
||||
queue.completed(0, seen);
|
||||
let pending = queue.pending_before(at(2));
|
||||
let barriers = commit(&mut queue, &[read()], 2);
|
||||
let ordered = (seen == 0)
|
||||
.then(|| barrier(copy_write(), copy_read()))
|
||||
.flatten();
|
||||
assert_eq!(
|
||||
(pending, barriers),
|
||||
(1 - seen, vec![ordered]),
|
||||
"seen {seen}"
|
||||
);
|
||||
}
|
||||
// Another queue's completion, and an older value, leave a queue's count as it was.
|
||||
let mut queue = Tracker::default();
|
||||
for value in 1..=3 {
|
||||
assert_eq!(commit(&mut queue, &[read()], value), [None]);
|
||||
}
|
||||
queue.completed(0, 2);
|
||||
queue.completed(1, 3);
|
||||
queue.completed(0, 1);
|
||||
assert_eq!(queue.pending_before(at(4)), 1);
|
||||
assert_eq!(queue.pending_before(on(1, 4)), 0);
|
||||
}
|
||||
|
||||
/// A completion looks only at the resources its batches touched: a thousand batches in flight,
|
||||
/// each reading a resource of its own, and the first one's completion retires its resource alone.
|
||||
#[test]
|
||||
|
||||
@@ -2647,6 +2647,15 @@ impl<K: Copy + Ord + Hash> Tracker<K> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The batches of `at`'s `VkQueue` before it that the host had not seen complete as of the
|
||||
/// last [`Tracker::completed`] of that queue: the value a plan at `at` retires by, so a plan
|
||||
/// orders after the work of exactly these batches (`WorkCounts::batches_with_none_pending` and
|
||||
/// kin count them).
|
||||
pub(super) fn pending_before(&self, at: Point) -> u64 {
|
||||
let through = self.completed.get(at.queue).copied().unwrap_or(0);
|
||||
at.value.saturating_sub(1).saturating_sub(through)
|
||||
}
|
||||
|
||||
/// The barriers before the `encoders` of the batch submitted next, at `at`, and its waits.
|
||||
/// The state is unchanged; the plan's lists come from those plans applied before gave back.
|
||||
pub(super) fn plan<'a>(
|
||||
|
||||
@@ -5515,8 +5515,9 @@ pub struct WorkCounts {
|
||||
pub group_ends_held: u64,
|
||||
/// Batches submitted (each held in a group counted as it is held) while no earlier batch of
|
||||
/// their `VkQueue` was pending: every one submitted before them the host had seen complete
|
||||
/// (their queue's timeline at their values). With the three fields after this one, every
|
||||
/// batch, by how far its queue's work ran behind its submission.
|
||||
/// (their queue's timeline at their values), as of the completed value the hazard tracker took
|
||||
/// for their plan, so a batch counted here is planned after no work in flight. With the three
|
||||
/// fields after this one, every batch, by how far its queue's work ran behind its submission.
|
||||
pub batches_with_none_pending: u64,
|
||||
/// Batches submitted while one earlier batch of their `VkQueue` was pending.
|
||||
pub batches_with_one_pending: u64,
|
||||
|
||||
Reference in new issue
Block a user