diff --git a/crates/metal2vulkan-runtime/src/kept.rs b/crates/metal2vulkan-runtime/src/kept.rs index 9c83df254..045f8c907 100644 --- a/crates/metal2vulkan-runtime/src/kept.rs +++ b/crates/metal2vulkan-runtime/src/kept.rs @@ -230,13 +230,15 @@ impl DerefMut for Objects { /// The lists of each kind a recording keeps. #[derive(Default)] pub(crate) struct ByKind { + /// Its pieces' kernels (`crate::piece::Kernels`), each the content of a state `pipelines` + /// keeps, held with no count: emptied before `pipelines` is, as it is dropped first, so no + /// copy outlives its state. + pub(crate) kernels: Kernels, pub(crate) buffers: Kept, pub(crate) textures: Kept, pub(crate) samplers: Kept, pub(crate) pipelines: Kept, pub(crate) render_pipelines: Kept, - /// Its pieces' kernels, of the states `pipelines` keeps (`crate::piece::Kernels`). - pub(crate) kernels: Kernels, } impl ByKind { @@ -262,15 +264,15 @@ impl ByKind { /// Releases every object, keeping each list's capacity, within [`KEPT_BOUND`], for the next /// recording. pub(crate) fn clear(&mut self) { + match self.kernels.capacity() > KEPT_BOUND { + true => self.kernels = Kernels::new(), + false => self.kernels.clear(), + } self.buffers.clear(); self.textures.clear(); self.samplers.clear(); self.pipelines.clear(); self.render_pipelines.clear(); - match self.kernels.capacity() > KEPT_BOUND { - true => self.kernels = Kernels::new(), - false => self.kernels.clear(), - } } } diff --git a/crates/metal2vulkan-runtime/src/piece.rs b/crates/metal2vulkan-runtime/src/piece.rs index 7008be965..e25e76b75 100644 --- a/crates/metal2vulkan-runtime/src/piece.rs +++ b/crates/metal2vulkan-runtime/src/piece.rs @@ -140,8 +140,11 @@ impl Work { if self.kernels.is_empty() { self.kernels = list.len()..list.len(); } - // SAFETY: the command buffer keeps the state `kernel` is of until it retires, - // after the list's last use (`crate::command::retire`). + // SAFETY: `kernel` is the content of the state the encoder bound, which the + // command buffer's kept objects hold, counted (`Building::lend_pipeline`), in + // `pipelines`; `list` is the same objects' `kernels`, emptied before `pipelines` + // releases anything, and dropped first (`ByKind`). The copy is read only through + // `list` (`Work::ran`), so never after its state is released. let compiled = unsafe { kernel.uncounted() }; list.push(Kernel { compiled, groups }); self.kernels.end = list.len();