Hold a render encoder's current instance in its lowering's box: a pass open makes no box of it
1aaf95c79f boxed the current instance (1656 bytes) so that the encoder's moves at its pass end carried a pointer. That made one more allocation at every pass open, on every device: runtime_lane::frame_costs::a_frame_s_pass_opens_allocate_within_their_bound measured 6.00 a pass open on the M3 (bound 5.5) and 5.00 on NVIDIA (bound 4.5). The instance now sits unboxed in the RenderLowering, which is already boxed once where it is built. end_pass lists the pass's instances in the earlier instances' vector, the current one pushed last, in place of a vector of boxes; a split still boxes the new instance it hands back (Next::New) and unboxes it into its place. OPEN_ALLOCATIONS' doc says where the instance lives. Not done: keeping the emptied instance box in the draw room. end_pass moves the first instance's pieces, earlier steps, shape, positions and kept commands out to the pass's steps, so keeping its box would need placeholder moves or a change to how long the steps live. Verified: builds (cargo check, all features); the frame_costs lane runs next on MoltenVK. (cherry picked from commit e4fb5fcd47c4a3bd97e1ef9a021d3c466291ac19) (cherry picked from commit 15c0626814a8e8e75c30c105c1a69f7f8dd3ea0e)
This commit is contained in:
1 parent
d6302220bf
commit
01f40bb3f4
5 files changed
+21
-26
No files matched your search
@@ -1383,9 +1383,9 @@ pub(crate) struct RenderLowering {
|
||||
core: EncoderCore,
|
||||
/// The pass's instances before the current one, which the draws record into.
|
||||
earlier: Vec<Instance>,
|
||||
/// The instance the draws record into, in a box: the encoder moves as its pass ends, and
|
||||
/// the instance with it by its box (`end_pass`).
|
||||
current: Box<Instance>,
|
||||
/// The instance the draws record into, in the encoder's box, which its open makes once
|
||||
/// (`assemble`): no box of its own to make at each open.
|
||||
current: Instance,
|
||||
/// Versioned, as the state and the amplification are: a draw's shape is derived from them
|
||||
/// (`render/draw_shape.rs`).
|
||||
layout: Versioned<PassLayout>,
|
||||
@@ -1993,7 +1993,7 @@ impl RenderLowering {
|
||||
Box::new(RenderLowering {
|
||||
core,
|
||||
earlier: Vec::new(),
|
||||
current: Box::new(Instance {
|
||||
current: Instance {
|
||||
draws,
|
||||
shape: Versioned::new(shape.clone()),
|
||||
compatible: Arc::clone(&compatible),
|
||||
@@ -2021,7 +2021,7 @@ impl RenderLowering {
|
||||
planned: false,
|
||||
feedback: Feedback::NONE,
|
||||
storage_colors: 0,
|
||||
}),
|
||||
},
|
||||
state: Versioned::new(EncoderState::metal_defaults(area)),
|
||||
scissors: ScissorRects::metal_default(area),
|
||||
render_target_array_length,
|
||||
@@ -4095,10 +4095,8 @@ impl RenderLowering {
|
||||
// The bind state its last draw left, which the device's next render encoder starts from
|
||||
// (`live_bind.rs`): no draw holds it once the encoder ends.
|
||||
core.device().shared().live_binds.give(live);
|
||||
// The pass's instances in order, each by a box: the current one's, and the earlier ones'
|
||||
// (a pass split) each moved into one.
|
||||
let mut instances = Vec::with_capacity(earlier.len() + 1);
|
||||
instances.extend(earlier.into_iter().map(Box::new));
|
||||
// The pass's instances in order: the earlier ones (a pass split), then the current one.
|
||||
let mut instances = earlier;
|
||||
instances.push(current);
|
||||
// The first instance's render pass and framebuffer, where it recorded inline in the
|
||||
// command buffer the encoder holds for the pass (`render/inline_first.rs`), and the
|
||||
@@ -5279,7 +5277,7 @@ impl RenderLowering {
|
||||
shadows: gathered,
|
||||
drawn: instance_drawn,
|
||||
..
|
||||
} = *instance;
|
||||
} = instance;
|
||||
if index == 0 {
|
||||
first_gathered = Some((gathered, instance_drawn));
|
||||
}
|
||||
@@ -6080,7 +6078,7 @@ impl RenderLowering {
|
||||
let viewed = self
|
||||
.earlier
|
||||
.iter()
|
||||
.chain([&*self.current])
|
||||
.chain([&self.current])
|
||||
.any(|i| i.reformats.iter().any(|r| r.index == index as usize));
|
||||
if copies.is_some() && viewed {
|
||||
return Err(Error::NotImplemented(RuntimeGap::Render));
|
||||
@@ -6448,15 +6446,15 @@ impl RenderLowering {
|
||||
(false, false) => cause,
|
||||
};
|
||||
self.core.device().shared().counts.instance_split(cause);
|
||||
let previous = std::mem::replace(&mut self.current, instance);
|
||||
self.earlier.push(*previous);
|
||||
let previous = std::mem::replace(&mut self.current, *instance);
|
||||
self.earlier.push(previous);
|
||||
self.barrier_splits += usize::from(self.barrier);
|
||||
if self.barrier {
|
||||
self.reload_at.insert(self.earlier.len());
|
||||
}
|
||||
} else {
|
||||
// It takes the place of the current one, whose draws it records again.
|
||||
let mut instance = instance;
|
||||
let mut instance = *instance;
|
||||
instance.drawn.join(&self.current.drawn);
|
||||
let replaced = std::mem::replace(&mut self.current, instance);
|
||||
self.end_unrun(&replaced);
|
||||
@@ -6697,7 +6695,7 @@ impl RenderLowering {
|
||||
&& self
|
||||
.earlier
|
||||
.iter()
|
||||
.chain([&*self.current])
|
||||
.chain([&self.current])
|
||||
.any(|instance| instance.reformats.iter().any(|r| r.copies))
|
||||
}
|
||||
|
||||
|
||||
@@ -2251,7 +2251,7 @@ impl RenderExecution {
|
||||
// begun against a pass compatible with it: a pass of one subpass ignores its resolves.
|
||||
let ending = PassShape::of(pass)?;
|
||||
let mut runs = Vec::with_capacity(earlier.len() + 1);
|
||||
for run in earlier.into_iter().chain([*current]) {
|
||||
for run in earlier.into_iter().chain([current]) {
|
||||
let other =
|
||||
(*run.shape != snapshot.shape || run.views != ViewSetup::default()).then(|| {
|
||||
let mut shape = run.shape.clone();
|
||||
@@ -2324,7 +2324,7 @@ impl RenderExecution {
|
||||
RenderLowering {
|
||||
core,
|
||||
earlier: Vec::new(),
|
||||
current: Box::new(Instance {
|
||||
current: Instance {
|
||||
draws,
|
||||
shape: Versioned::new(snapshot.shape.clone()),
|
||||
compatible: Arc::clone(&snapshot.compatible),
|
||||
@@ -2358,7 +2358,7 @@ impl RenderExecution {
|
||||
planned: false,
|
||||
feedback: Feedback::NONE,
|
||||
storage_colors: 0,
|
||||
}),
|
||||
},
|
||||
layout: Versioned::new(layout),
|
||||
passes: vec![(snapshot.shape.clone(), Arc::clone(&snapshot.compatible))],
|
||||
render_target_array_length: snapshot.render_target_array_length,
|
||||
|
||||
@@ -180,7 +180,7 @@ impl RenderLowering {
|
||||
};
|
||||
let previous_layout = stood.map(|layout| std::mem::replace(&mut *self.layout, *layout));
|
||||
self.kept_attachments = None;
|
||||
let mut previous = std::mem::replace(&mut self.current, instance);
|
||||
let mut previous = std::mem::replace(&mut self.current, *instance);
|
||||
let mut again = Ok(());
|
||||
if let Some(draws) = previous.rerecord.as_mut() {
|
||||
for kept in draws.iter_mut() {
|
||||
|
||||
@@ -38,11 +38,7 @@ use crate::render_values::{LoadAction, StoreAction};
|
||||
/// module docs): `called` false (no draw call), `instances` one that nothing recorded into, and its
|
||||
/// attachments' load and store actions as settled (an unknown store made `DontCare`) keeping every
|
||||
/// texel, no depth written with a NaN before it.
|
||||
pub(super) fn changes_nothing(
|
||||
layout: &PassLayout,
|
||||
called: bool,
|
||||
instances: &[Box<Instance>],
|
||||
) -> bool {
|
||||
pub(super) fn changes_nothing(layout: &PassLayout, called: bool, instances: &[Instance]) -> bool {
|
||||
let keeps = |load: LoadAction, store: StoreAction| {
|
||||
matches!(load, LoadAction::Load | LoadAction::DontCare)
|
||||
&& matches!(store, StoreAction::Store | StoreAction::DontCare)
|
||||
|
||||
@@ -308,8 +308,9 @@ const DRAW_ALLOCATIONS_DEBUG: f64 = 20.0;
|
||||
/// platforms: its shape's lists (`color_list.rs`), its encoder's default viewport and scissor
|
||||
/// rectangle (`render_state::ViewportList`), its attachments' extents and its tracker's first part
|
||||
/// (`tracker::EncoderUses`) are held in place, and its lowering is boxed once where it is built
|
||||
/// (`render.rs`), which the encoder then moves as a pointer. Measured: 4.00 on lavapipe in a build
|
||||
/// with debug assertions; 5.00 on the M3 Max through MoltenVK.
|
||||
/// (`render.rs`), its current instance inside that box, which the encoder then moves as a pointer.
|
||||
/// Measured: 4.00 on lavapipe in a build with debug assertions; 5.00 on the M3 Max through
|
||||
/// MoltenVK.
|
||||
#[cfg(not(m2v_system_alloc))]
|
||||
const OPEN_ALLOCATIONS: f64 = 4.5;
|
||||
/// The most allocations a frame's pass end (`end_encoding`) makes on the encoding thread on
|
||||
|
||||
Reference in new issue
Block a user