RUNTIME 2293: blit encoders fold into the shared VkCommandBuffer as compute encoders do
A command buffer that mixes compute and blit encoders (the image workloads:
Photo Filter, HDR, RAW) began a VkCommandBuffer for every blit encoder, which
also ended the compute encoders' fold: dispatch_chain's blits shape (200
one-dispatch compute encoders each followed by a blit copy) went to the queue
as 799 VkCommandBuffers in one vkQueueSubmit (542 begun) on lavapipe, against 1
for compute encoders alone. On ANV each begin costs 16-20 us of host time.
A blit encoder now joins the group of encoders its command buffer's tail holds
by the rules compute encoders follow (encoder_fold.rs): same batch, the earlier
member one part with no segment, no fence update and nothing failing, no
command predication yet, the encoder trail off, protection options 0; a
compute encoder joins where the group's compute encoders are of its dispatch
type (Joining::{Compute, Blit}). Blit commands take the per-command FoldOrder
barrier through track(). What differs for blits:
- Blit encoders now always log their calls (replay.rs), as compute encoders
do, so a failure that splits a mixed group encodes its running members
again apart.
- A blit encoder ends a unit of command predication, so a group can hold two
units' compute encoders: an unbalanced record whose left-out work begins
past the group's first encoder (State::left_out_from, set by
leave_out_ended) now splits the group at the commit as a partial failure
does, the shared VkCommandBuffer never submitted. split_failure and the
rebind's encoded_together take one check, State::encodes_again_apart: no
predication, a non-compute encoder, or Predication::alone. A rebind in a
command buffer that used predication now encodes a group again where each
member is alone, where before it refused (EncodedUseRebound).
- An encoder whose part writes an ASTC carrier (its second twin's decode goes
after the part) or notes an Overwrite (judged by its part's summary, which
a group widens) ends its group. A folded blit's Overwrite goes to the
group's first part only where every earlier member is a blit encoder that
named nothing of the texture (Fold::overwrites_join), which is what
first_overwrites decided before folding.
- Spares tests that need one VkCommandBuffer per blit encoder update a fence
in each.
Tests (tests::encoder_fold): a compute/blit/compute chain is one
VkCommandBuffer with every copy and read right; an event signal, a dispatch
type change across a blit, predication, a whole-texture overwrite and an ASTC
carrier write each end a group; failures inside a mixed group run exactly
the encoders they leave; an unbalanced End past a group's first encoder
splits it; a rebind encodes a group again in a predicated command buffer.
Also: dispatch_chain gains the `blits` shape (a blit copy after each one-dispatch compute encoder)
and the `copies` shape (a command buffer of blit encoders only).
Verified (blitfold, msi lavapipe): m3-max-29164 at 5845456c61: clippy (runtime, cfg m2v_cpu_icd,
all targets/features, -D warnings) 0; 185/185 including the encoder_fold tests and
a_rebind_encodes_a_group_again_in_a_command_buffer_of_command_predication (the narrowed refusal:
words right, reencodes_refused 0; REFUSALS.md regenerated, unchanged). A/B m3-max-29165 (own target
dirs, md5 c2157758 base 45fdc3e601 / a2214763 tip, ABAB): VkCommandBuffers begun/submitted per Metal
CB, 200 dispatches: blits 542/799 -> 1/1, copies 271/399 -> 1/1, encoders 1/1 -> 1/1; lavapipe GPU
us a dispatch blits 54.98 -> 37.35, copies 9.25 -> 2.36, encoders unchanged; host thread CPU blits
~-1.1 us a dispatch, copies even (logging ~+300 ns a blit encoder paid back by no new
VkCommandBuffer and a shorter commit). No WorkCounts field or Degradation kind. Negative control,
lint in the other configurations and the suites run after landing.
This commit is contained in:
1 parent
8783a6a8fe
commit
12cd9c6f79
15 files changed
+1064
-200
No files matched your search
@@ -58,12 +58,13 @@
|
||||
//! and it keeps the run's scratch after its own merge where a later pass went on over it, a
|
||||
//! linear attachment's run's box copied in again first (`State::replaying_keeps`, recorded by
|
||||
//! `EncoderCore::finish_replay`). Its run's other passes are not encoded again.
|
||||
//! - **Groups whole.** The compute encoders of a group recorded into one `VkCommandBuffer`
|
||||
//! (`encoder_fold.rs`) are encoded again together: a rebind that moves one encodes each again,
|
||||
//! into `VkCommandBuffer`s of its own, and puts them in their places together, or puts none
|
||||
//! where one of them kept no log, is refused or does not fit its place.
|
||||
//! - **Groups whole.** The compute and blit encoders of a group recorded into one
|
||||
//! `VkCommandBuffer` (`encoder_fold.rs`) are encoded again together: a rebind that moves one
|
||||
//! encodes each again, into `VkCommandBuffer`s of its own, and puts them in their places
|
||||
//! together, or puts none where one of them kept no log, is refused or does not fit its place.
|
||||
//! - **Split at the commit.** A commit whose failure fails some of a group's encoders and not the
|
||||
//! others (`encoder_fold.rs`'s **Failed**) marks the command buffer as a rebind does, and its
|
||||
//! others, or after a command-predication record left out the work of some of them
|
||||
//! (`encoder_fold.rs`'s **Failed**), marks the command buffer as a rebind does, and its
|
||||
//! own call encodes the group's encoders that run again, each into `VkCommandBuffer`s of its
|
||||
//! own, before the scheduler sees its batches; where one cannot be encoded again or does not
|
||||
//! fit its place, those encoders run nothing after all (`State::fail_unsplit`), as the whole
|
||||
@@ -182,8 +183,8 @@ impl CommandBufferShared {
|
||||
let handle = CommandBuffer(Arc::clone(self));
|
||||
// The encoders encoded again, whose segments the encoding again recorded.
|
||||
let mut spliced = Vec::new();
|
||||
// Each unit's encoders are encoded again before any takes its place: a group of compute
|
||||
// encoders recorded into one `VkCommandBuffer` takes its places whole or not at all
|
||||
// Each unit's encoders are encoded again before any takes its place: a group of encoders
|
||||
// recorded into one `VkCommandBuffer` takes its places whole or not at all
|
||||
// (`encoder_fold.rs`).
|
||||
for (split, unit) in units {
|
||||
let members: Vec<usize> = unit.iter().map(|(at, _)| *at).collect();
|
||||
@@ -453,9 +454,9 @@ impl CommandBufferShared {
|
||||
/// work than its encoding again's.
|
||||
const UNFIT: &str = "its place holds other parts or work than its encoding again's";
|
||||
|
||||
/// Why an encoder of a group of compute encoders recorded into one `VkCommandBuffer` keeps its
|
||||
/// first recording where the group cannot be encoded again whole (`encoder_fold.rs`).
|
||||
const TOGETHER: &str = "it records into one VkCommandBuffer with compute encoders around it, \
|
||||
/// Why an encoder of a group of compute and blit encoders recorded into one `VkCommandBuffer`
|
||||
/// keeps its first recording where the group cannot be encoded again whole (`encoder_fold.rs`).
|
||||
const TOGETHER: &str = "it records into one VkCommandBuffer with encoders around it, \
|
||||
which are not all encoded again";
|
||||
|
||||
/// An ended encoder encoded again, for its place ([`State::splice_replay`]).
|
||||
@@ -492,11 +493,12 @@ impl State {
|
||||
}
|
||||
|
||||
/// The units the rebind's turn encodes again of `moved`, the ended encoders it moved, with
|
||||
/// their logs, in order: each encoder alone, but an encoder of a group of compute encoders
|
||||
/// recorded into one `VkCommandBuffer` with every encoder of its group (`encoder_fold.rs`),
|
||||
/// whose shared recording none may leave alone. A group one of whose encoders kept no log, or
|
||||
/// of a command buffer that used command predication, is encoded again by none: its moved
|
||||
/// encoders keep their first recording, the refusal noted and counted.
|
||||
/// their logs, in order: each encoder alone, but an encoder of a group of compute and blit
|
||||
/// encoders recorded into one `VkCommandBuffer` with every encoder of its group
|
||||
/// (`encoder_fold.rs`), whose shared recording none may leave alone. A group one of whose
|
||||
/// encoders kept no log, or cannot be encoded again apart in its command buffer's command
|
||||
/// predication (`State::encodes_again_apart`), is encoded again by none: its moved encoders
|
||||
/// keep their first recording, the refusal noted and counted.
|
||||
pub(super) fn encoded_together(
|
||||
&mut self,
|
||||
moved: Vec<(usize, Arc<Replay>)>,
|
||||
@@ -519,7 +521,8 @@ impl State {
|
||||
Some((member, Arc::clone(log)))
|
||||
})
|
||||
.collect();
|
||||
match logs.filter(|_| !self.predicated) {
|
||||
let apart = (group.clone()).all(|member| self.encodes_again_apart(member));
|
||||
match logs.filter(|_| apart) {
|
||||
Some(unit) => units.push(unit),
|
||||
None => {
|
||||
for record in &mut self.ended[group] {
|
||||
|
||||
Reference in new issue
Block a user