Keep a draw rebound's slot rebinds lists with its bind state, past its settle and encoder

7226 on the M3 read 2b2d3bf8d4 at 19.83 allocations a draw in debug and 8.00 in
release, against 19.21 and 7.38 before cut 4 (0f28b4b79e): the same +0.62 in
both, about 3.7 a pass of the frame's six draws. The lists lived in SettledHere,
which goes as its encoder ends (LiveBind::end_encoder forgets the settles), so
each pass's first draw rebound made them again. They now live in LiveBind beside
the settle (and in each set-aside state, swapped with it in select), so the
spare state the next encoder starts from carries their room; SettledHere keeps
only whether its plan's rebinds were made in them. took_place_of goes.

Verified: cargo fmt only locally; build, clippy and allocation numbers are potluck
jobs.

(cherry picked from commit 5e02b2812036f9af2fee8a8cd99603cabc1d06b1)
This commit is contained in:
Anees Iqbal committed 2026-11-07 23:25:48 -08:00
1 parent 973245f2c6
commit ba0641e4fe
3 files changed
+29 -30

No files matched your search

+24 -23
View File
@@ -65,8 +65,9 @@
//! no object (its bindings are values, and its tables' drawing state is held weakly), so a kept
//! one holds nothing alive; the next encoder's tables are new, with stamps of their own.
//! - **The draws' storage kept with it.** The vectors a draw fills and drops (its commands, push
//! writes, uses, descriptor writes, pushed set 0 and vertex buffers) are kept here too, each
//! draw's written over the last one's storage. Those hold values and raw handles, but for the
//! writes, uses, descriptor writes, pushed set 0 and vertex buffers, and a draw rebound's slot
//! rebinds, which outlast the settle they were made for) are kept here too, each draw's written
//! over the last one's storage. Those hold values and raw handles, but for the
//! descriptor writes, whose keepers hold samplers and function tables: those are emptied as
//! the draw is done with them ([`Emptied`]), so they hold nothing past it, as a new vector's did.
//! - **The resident textures' shadows listed once per change.** The shadows' copies of the
@@ -233,6 +234,10 @@ pub(super) struct LiveBind {
/// What the state's last recorded draw settled, while its encoder lasts ([`SettledHere`]):
/// set by a draw that recorded, in place of what the state kept.
pub(super) settled: Option<SettledHere>,
/// The lists the state's settles make their plans' slot rebinds in
/// ([`SettledHere::rebinds`]), kept with the state, so their room goes from one settle and
/// one encoder to the next.
pub(super) rebinds: SlotRebinds,
/// The last draw its encoder noted apart (`noted_apart.rs`), kept here so its storage goes
/// from one encoder to the next.
pub(super) noted: NotedApart,
@@ -317,20 +322,20 @@ struct SetAside {
listed_at: Option<u64>,
read_from: ReadFrom,
settled: Option<SettledHere>,
rebinds: SlotRebinds,
/// [`LiveBind::asides`] as it went aside.
at: u64,
}
/// What a recorded draw settled of its state's shape (`GraphicsState::settle_shape`): the variant
/// and plan, the program it ran (named without being held) and the buffer forms it took; the shape
/// is the state's kept one, compared by identity. With them, the plan's slot rebinds
/// (`BindingPlan::slot_rebinds`) of the slots the last draw rebound changed, and whether the plan
/// rebinds those slots so; `None` before one was made for this settle.
/// is the state's kept one, compared by identity. With them, whether the plan rebinds the slots
/// of the slot rebinds made in the state's lists ([`LiveBind::rebinds`]) for this settle; `None`
/// before any were made for it.
pub(super) struct SettledHere {
program: ProgramName,
forms: BufferForms,
settled: Settled,
rebinds: SlotRebinds,
made: Option<bool>,
}
@@ -346,34 +351,29 @@ impl SettledHere {
program: pipeline.program_name(),
forms,
settled,
rebinds: SlotRebinds::default(),
made: None,
}
}
/// Take the place of `replaced`, the state's settle before: the slot rebinds are made in its,
/// whose lists keep their room (`BindingPlan::slot_rebinds_into`), so the state's draws
/// rebound after a new settle allocate none for them where those lists had room. None is made
/// for this settle yet.
pub(super) fn took_place_of(&mut self, replaced: SettledHere) {
self.rebinds = replaced.rebinds;
self.made = None;
}
/// What the draw settled, and its plan's slot rebinds of `slots` (`None` where the plan reads
/// one of them some other way): made at the first draw rebound that changed those slots, in
/// place of those made before for other slots, and kept for each next one that changes the
/// same slots, as the plan is the same.
pub(super) fn rebinds(&mut self, slots: &[SlotRef]) -> (&Settled, Option<&SlotRebinds>) {
/// one of them some other way), in `lists`, the state's ([`LiveBind::rebinds`]): made there
/// at the first draw rebound that changed those slots (`BindingPlan::slot_rebinds_into`), in
/// place of those made before for other slots or settles, and kept for each next one that
/// changes the same slots, as the plan is the same.
pub(super) fn rebinds<'a>(
&'a mut self,
slots: &[SlotRef],
lists: &'a mut SlotRebinds,
) -> (&'a Settled, Option<&'a SlotRebinds>) {
let made = match self.made {
Some(made) if self.rebinds.slots() == slots => made,
Some(made) if lists.slots() == slots => made,
_ => {
let made = (self.settled.plan).slot_rebinds_into(slots, &mut self.rebinds);
let made = (self.settled.plan).slot_rebinds_into(slots, lists);
self.made = Some(made);
made
}
};
(&self.settled, made.then_some(&self.rebinds))
(&self.settled, made.then_some(lists))
}
}
@@ -553,6 +553,7 @@ impl LiveBind {
std::mem::swap(&mut self.listed_at, &mut aside.listed_at);
std::mem::swap(&mut self.read_from, &mut aside.read_from);
std::mem::swap(&mut self.settled, &mut aside.settled);
std::mem::swap(&mut self.rebinds, &mut aside.rebinds);
aside.at = self.asides;
}
+1 -4
View File
@@ -10788,10 +10788,7 @@ impl RenderLowering {
self.core.retain(function_tables);
}
if let Some(here) = settled_here {
let replaced = live.settled.replace(here);
if let (Some(replaced), Some(here)) = (replaced, live.settled.as_mut()) {
here.took_place_of(replaced);
}
live.settled = Some(here);
}
Ok(())
}
@@ -15,8 +15,9 @@
//! - **What it works out again.** Its commands, rebound at those slots
//! (`BindingPlan::rebind_draw_slots_into`: their descriptor ranges, push fields and vertex
//! buffers' offsets), by the plan's rebinds of them (`BindingPlan::slot_rebinds_into`), made
//! once for the kept draw, in the lists the state's settles before kept, and kept with it while
//! the draws change the same slots (`SettledHere::rebinds`);
//! once for the kept draw, in lists the state keeps from one settle and encoder to the next
//! (`LiveBind::rebinds`), and kept with it while the draws change the same slots
//! (`SettledHere::rebinds`);
//! set 0's writes of them with their dynamic offsets (`binding::rebind_into`:
//! a texture's view and a sampler state's `VkSampler` as every step makes them, through its
//! encoder's memo), and the set its encoder's last set or its command buffer's holds, else a new
@@ -445,7 +446,7 @@ impl RenderLowering {
let kept = settles_kept(self, live)
.then_some(live.settled.as_mut())
.flatten();
let (settled, rebinds) = kept?.rebinds(slots);
let (settled, rebinds) = kept?.rebinds(slots, &mut live.rebinds);
let Settled {
variant,
plan,