diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index 55699d3a2..e629dc6fd 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -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::() <= 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::() <= 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, /// The pass's instances before the current one, which the draws record into. earlier: Vec, /// 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>, /// 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, + /// again. Boxed where it is taken (`SpareLogs::render`), the box its end hands the command + /// buffer (`Replay::Render`). + log: Option>, /// 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, inline: Option, residency: Residency, - log: Option, + log: Option>, grouped: Option>, } @@ -2049,7 +2058,7 @@ impl Opening { rate_map: Option, inline: Option, residency: Residency, - log: Option, + log: Option>, grouped: Option>, ) -> 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 { + fn assemble(core: Box, draws: vk::CommandBuffer, opening: Opening) -> Box { 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); diff --git a/crates/metal2vulkan-runtime/src/render/color_groups.rs b/crates/metal2vulkan-runtime/src/render/color_groups.rs index ee732edce..3037a2af2 100644 --- a/crates/metal2vulkan-runtime/src/render/color_groups.rs +++ b/crates/metal2vulkan-runtime/src/render/color_groups.rs @@ -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, pub(super) residency: Residency, - pub(super) log: Option, + pub(super) log: Option>, pub(super) later: Option>, } @@ -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, later: &Later, log: Option<&RenderLog>, - ) -> Result { + ) -> Result, 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, later: &Later, group: u32, log: &RenderLog, diff --git a/crates/metal2vulkan-runtime/src/render/executions.rs b/crates/metal2vulkan-runtime/src/render/executions.rs index 7b29a244c..8cb9fafd3 100644 --- a/crates/metal2vulkan-runtime/src/render/executions.rs +++ b/crates/metal2vulkan-runtime/src/render/executions.rs @@ -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` diff --git a/crates/metal2vulkan-runtime/src/render/executions/gpu.rs b/crates/metal2vulkan-runtime/src/render/executions/gpu.rs index 3a225490b..f7981f802 100644 --- a/crates/metal2vulkan-runtime/src/render/executions/gpu.rs +++ b/crates/metal2vulkan-runtime/src/render/executions/gpu.rs @@ -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 diff --git a/crates/metal2vulkan-runtime/src/render/executions/kept.rs b/crates/metal2vulkan-runtime/src/render/executions/kept.rs index 0b591debd..3407c6257 100644 --- a/crates/metal2vulkan-runtime/src/render/executions/kept.rs +++ b/crates/metal2vulkan-runtime/src/render/executions/kept.rs @@ -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, diff --git a/crates/metal2vulkan-runtime/src/replay.rs b/crates/metal2vulkan-runtime/src/replay.rs index 8e72264a6..9fb227c76 100644 --- a/crates/metal2vulkan-runtime/src/replay.rs +++ b/crates/metal2vulkan-runtime/src/replay.rs @@ -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 { + Box::new(RenderLog::new(descriptor, screen, self.render.take())) } /// Clear `replay` and keep it for a next encoder, where its room is small enough