Runtime: a piece's kernel copies empty before the states that hold them release

The copies the pieces hold with no count live in the same kept objects as the
counted states they are of, and are emptied, and dropped, before those
states: every read of a copy (the rate update at retire) goes through that
list, so a read after the release finds an empty list and sets no rate, which
the pieces tests that assert a run sets its kernel's rate would report.
Verified: cargo fmt only.
This commit is contained in:
Anees Iqbal committed 2026-11-22 12:25:53 -08:00
1 parent eaba828dcd
commit 600b38fda7
2 files changed
+13 -8

No files matched your search

+8 -6
View File
@@ -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<Buffer>,
pub(crate) textures: Kept<Texture>,
pub(crate) samplers: Kept<SamplerState>,
pub(crate) pipelines: Kept<ComputePipelineState>,
pub(crate) render_pipelines: Kept<RenderPipelineState>,
/// 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(),
}
}
}
+5 -2
View File
@@ -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();