Hand a render encoder's core and log on in boxes through its end
A render encoder's end passed its 1280-byte core by value at every step: out of the lowering, into `color_groups::Ended`, out of the `Result`, through `later_groups` and into `end_with_replay`. Its log (328 bytes, `Option<RenderLog>`) went the same way, and was boxed only at the end for `Replay::Render`. The lowering now holds the core in a box made as the encoder opens, and the log in the box `SpareLogs::render` makes, which the end hands to `Replay::Render` as it is. An ended pass is 264 bytes instead of 1856, and the lowering 8688 instead of 10280. An execution's replaying encoder boxes the core it is handed and gives it back unboxed, so the execution paths keep their by-value core. Check: a compile-time bound on `color_groups::Ended`'s size (320 bytes; 1856 before). Verified: release builds of the validation lib (x86_64, --cfg m2v_gpu) at 335c0ef7f7 and with this change, every memcpy/memmove call in the open and end functions listed by objdump: the end_encoding's copies of 1280, 1160, 328 and 320 bytes, later_groups' two of 1280, assemble's of 1280 and open_render's two of 328 are gone; assemble's whole-lowering copy shrinks from 10280 to 8688 bytes. (cherry picked from commit 4c885033bb5ee41f768fedaca34d4ba29efbcff1) (cherry picked from commit cee784906833a3a7e6713e15971b39dc03404062)
This commit is contained in:
1 parent
cd994fe39f
commit
6647aa1e91
6 files changed
+34
-24
No files matched your search
@@ -1403,6 +1403,11 @@ pub struct RenderCommandEncoder {
|
||||
// of it, so it holds its lowering in a box: the lowering's state is thousands of bytes.
|
||||
const _: () = assert!(std::mem::size_of::<RenderCommandEncoder>() <= 128);
|
||||
|
||||
// An ended pass goes on by value through each step of its end and its later color groups'
|
||||
// passes (`color_groups::Ended`): its core and its log in their boxes, so those moves copy no core
|
||||
// state (the core's is more than a thousand bytes).
|
||||
const _: () = assert!(std::mem::size_of::<color_groups::Ended>() <= 320);
|
||||
|
||||
impl std::fmt::Debug for RenderCommandEncoder {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("RenderCommandEncoder")
|
||||
@@ -1415,7 +1420,10 @@ impl std::fmt::Debug for RenderCommandEncoder {
|
||||
/// A render encoder's lowering ([`RenderCommandEncoder`]): the encoder's state, which each of its
|
||||
/// calls runs on.
|
||||
pub(crate) struct RenderLowering {
|
||||
core: EncoderCore,
|
||||
/// In a box of its own, made as the encoder opens: its pass's end hands it on through each
|
||||
/// step of the end (`color_groups::Ended`, the later color groups' passes), and those moves
|
||||
/// copy a pointer, not the core's state.
|
||||
core: Box<EncoderCore>,
|
||||
/// The pass's instances before the current one, which the draws record into.
|
||||
earlier: Vec<Instance>,
|
||||
/// The instance the draws record into, in the encoder's box, which its open makes once
|
||||
@@ -1638,8 +1646,9 @@ pub(crate) struct RenderLowering {
|
||||
live: Arc<Mutex<LiveBind>>,
|
||||
/// Its pass's descriptor and its calls so far, where the device had a buffer over host pages
|
||||
/// as it opened (`render/replay.rs`): `None` where it logs nothing, as when it is encoded
|
||||
/// again.
|
||||
log: Option<RenderLog>,
|
||||
/// again. Boxed where it is taken (`SpareLogs::render`), the box its end hands the command
|
||||
/// buffer (`Replay::Render`).
|
||||
log: Option<Box<RenderLog>>,
|
||||
/// The variants, plans and specializations of its draws under which the bound values'
|
||||
/// notices were quiet (`Device::degrade_bound_values`).
|
||||
quiet_bound_values: QuietKept,
|
||||
@@ -1963,10 +1972,10 @@ impl CommandBuffer {
|
||||
false => self.begin_draws(&compatible)?,
|
||||
};
|
||||
// A refusal past here leaves the secondary command buffer unused, freed with the pool.
|
||||
let mut core = match again {
|
||||
let mut core = Box::new(match again {
|
||||
None => EncoderCore::open(self, CALL, EncoderKind::Render, false)?,
|
||||
Some(_) => EncoderCore::replaying(self, false)?,
|
||||
};
|
||||
});
|
||||
if let Some(pass) = &rate_map {
|
||||
let (map, state) = pass.taken();
|
||||
core.take_rate_map(map, state);
|
||||
@@ -2033,7 +2042,7 @@ struct Opening {
|
||||
extended_written: BTreeSet<u32>,
|
||||
inline: Option<bool>,
|
||||
residency: Residency,
|
||||
log: Option<RenderLog>,
|
||||
log: Option<Box<RenderLog>>,
|
||||
grouped: Option<Box<color_groups::Grouped>>,
|
||||
}
|
||||
|
||||
@@ -2049,7 +2058,7 @@ impl Opening {
|
||||
rate_map: Option<RateMappedPass>,
|
||||
inline: Option<bool>,
|
||||
residency: Residency,
|
||||
log: Option<RenderLog>,
|
||||
log: Option<Box<RenderLog>>,
|
||||
grouped: Option<Box<color_groups::Grouped>>,
|
||||
) -> Opening {
|
||||
Opening {
|
||||
@@ -2075,7 +2084,7 @@ impl Opening {
|
||||
impl RenderLowering {
|
||||
/// An encoder over `core` of the pass `opening` describes, its first instance's draws
|
||||
/// recording into `draws` (null where it records inline), made in its box.
|
||||
fn assemble(core: EncoderCore, draws: vk::CommandBuffer, opening: Opening) -> Box<Self> {
|
||||
fn assemble(core: Box<EncoderCore>, draws: vk::CommandBuffer, opening: Opening) -> Box<Self> {
|
||||
let Opening {
|
||||
layout,
|
||||
render_target_array_length,
|
||||
@@ -4084,7 +4093,7 @@ impl RenderLowering {
|
||||
later,
|
||||
} = self.end_pass()?;
|
||||
if let Some(later) = later {
|
||||
core = color_groups::Ended::later_groups(core, &later, log.as_ref())?;
|
||||
core = color_groups::Ended::later_groups(core, &later, log.as_deref())?;
|
||||
}
|
||||
// A notice of a kind the device refuses while lowering, announced by the end of an encoder
|
||||
// that logged its calls, refuses the end (`render/deferral.rs`).
|
||||
@@ -4095,7 +4104,7 @@ impl RenderLowering {
|
||||
core.end_with_replay(
|
||||
EncoderKind::Render,
|
||||
Some(residency),
|
||||
log.map(|log| Replay::Render(Box::new(log))),
|
||||
log.map(Replay::Render),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4110,7 +4119,7 @@ impl RenderLowering {
|
||||
later,
|
||||
} = self.end_pass()?;
|
||||
if let Some(later) = later {
|
||||
core = color_groups::Ended::later_groups(core, &later, log.as_ref())?;
|
||||
core = color_groups::Ended::later_groups(core, &later, log.as_deref())?;
|
||||
}
|
||||
// Its log goes before what it recorded is placed, as it went once its groups were drawn.
|
||||
drop(log);
|
||||
|
||||
@@ -415,9 +415,9 @@ fn twin(
|
||||
/// An ended pass of a render encoder: its core, what it made resident, its log, and what its
|
||||
/// later color groups draw.
|
||||
pub(super) struct Ended {
|
||||
pub(super) core: EncoderCore,
|
||||
pub(super) core: Box<EncoderCore>,
|
||||
pub(super) residency: Residency,
|
||||
pub(super) log: Option<RenderLog>,
|
||||
pub(super) log: Option<Box<RenderLog>>,
|
||||
pub(super) later: Option<Box<Later>>,
|
||||
}
|
||||
|
||||
@@ -426,10 +426,10 @@ impl Ended {
|
||||
/// from the first group's `log`: the core they leave. A pass of one group has none
|
||||
/// (`later` `None`), and its end calls nothing here.
|
||||
pub(super) fn later_groups(
|
||||
mut core: EncoderCore,
|
||||
mut core: Box<EncoderCore>,
|
||||
later: &Later,
|
||||
log: Option<&RenderLog>,
|
||||
) -> Result<EncoderCore, Error> {
|
||||
) -> Result<Box<EncoderCore>, Error> {
|
||||
let log = log.ok_or_else(|| internal("a pass of several color groups without its log"))?;
|
||||
for group in 1..later.group.groups() {
|
||||
let mut encoder = RenderLowering::later_group(core, later, group, log)?;
|
||||
@@ -451,7 +451,7 @@ impl RenderLowering {
|
||||
/// The encoder of later group `group` of the pass `later` and `log` describe, over `core`
|
||||
/// (the module docs).
|
||||
fn later_group(
|
||||
core: EncoderCore,
|
||||
core: Box<EncoderCore>,
|
||||
later: &Later,
|
||||
group: u32,
|
||||
log: &RenderLog,
|
||||
|
||||
@@ -2412,7 +2412,7 @@ impl RenderExecution {
|
||||
unsafe { core.command_buffer().end_raw(*raw) }.map_err(vulkan)?;
|
||||
}
|
||||
Ok(Recorded {
|
||||
core,
|
||||
core: *core,
|
||||
runs,
|
||||
storage: PassStorage {
|
||||
tile_memory: tile_memory.into_buffer(),
|
||||
@@ -2440,7 +2440,7 @@ impl RenderExecution {
|
||||
let mut shadows = InstanceShadows::default();
|
||||
shadows.add(&self.shadows, &[]);
|
||||
RenderLowering {
|
||||
core,
|
||||
core: Box::new(core),
|
||||
earlier: Vec::new(),
|
||||
current: Instance {
|
||||
draws,
|
||||
@@ -2624,7 +2624,7 @@ impl RenderExecution {
|
||||
encoder.settle_draws(pipeline, made);
|
||||
}
|
||||
let RenderLowering { core, .. } = encoder;
|
||||
core
|
||||
*core
|
||||
}
|
||||
|
||||
/// What its check, if any, may see among commands whose records may hold `written`
|
||||
|
||||
@@ -361,7 +361,7 @@ impl RenderExecution {
|
||||
Ok(Err(cause)) => Err(cause),
|
||||
Err(error) => Err(HostStepCause::Refused(error.to_string())),
|
||||
};
|
||||
(core, form)
|
||||
(*core, form)
|
||||
}
|
||||
|
||||
/// What the buffer's records may hold, the primitive type and the range of an execution that
|
||||
|
||||
@@ -961,7 +961,7 @@ impl RenderExecution {
|
||||
unreadable,
|
||||
resident_again,
|
||||
};
|
||||
Ok((core, carried))
|
||||
Ok((*core, carried))
|
||||
}
|
||||
|
||||
/// The addresses `commands` name (their buffers', where the buffer does not inherit them,
|
||||
|
||||
@@ -551,13 +551,14 @@ impl SpareLogs {
|
||||
}
|
||||
|
||||
/// The log of a pass `descriptor` opens, over a rasterization-rate map of `screen` pixels
|
||||
/// where it has one: in a kept one's room, or a new one.
|
||||
/// where it has one: in a kept one's room, or a new one. Boxed, as its encoder holds it and
|
||||
/// its end hands it on (`Replay::Render`).
|
||||
pub(super) fn render(
|
||||
&self,
|
||||
descriptor: &RenderPassDescriptor,
|
||||
screen: Option<[u32; 2]>,
|
||||
) -> RenderLog {
|
||||
RenderLog::new(descriptor, screen, self.render.take())
|
||||
) -> Box<RenderLog> {
|
||||
Box::new(RenderLog::new(descriptor, screen, self.render.take()))
|
||||
}
|
||||
|
||||
/// Clear `replay` and keep it for a next encoder, where its room is small enough
|
||||
|
||||
Reference in new issue
Block a user