diff --git a/crates/metal2vulkan-runtime/src/blit.rs b/crates/metal2vulkan-runtime/src/blit.rs index efa344c8b..4254b7d12 100644 --- a/crates/metal2vulkan-runtime/src/blit.rs +++ b/crates/metal2vulkan-runtime/src/blit.rs @@ -222,6 +222,8 @@ impl BlitCommandEncoder { let pixel_format = sides.0.descriptor.pixel_format; return Err(Error::Unsupported(Gap::OverlappingCopy { pixel_format })); } + // The copy's segment marks what it does, in a new one past a signal. + building.open_segment()?; building.keep_texture(source); building.keep_texture(destination); building.wrote_texture_managed(destination); @@ -462,6 +464,9 @@ impl BlitCommandEncoder { else { return Ok(()); }; + // The copy's segment marks what it does and takes the copies back owed to it, in a new + // one past a signal. + building.open_segment()?; building.keep(source); building.keep(destination); // The textures over either device copy go back to it first; the destination's owe their @@ -572,6 +577,9 @@ impl BlitCommandEncoder { ) -> Result<(), Error> { let (core, building) = self.parts(); let vk_buffer = buffer.device_range().0; + // The copies' segment marks what they do and takes the copies back owed to them, in a new + // one past a signal. + building.open_segment()?; building.keep_texture(texture); building.keep(buffer); // The device copy's textures' copies back go first; a copy into the buffer owes them @@ -729,6 +737,9 @@ impl BlitCommandEncoder { } let (vk_buffer, base) = buffer.device_range(); let (offset, length) = fill_range(base, buffer.length(), range)?; + // The fill's segment marks what it does and takes the copies back owed to it, in a new + // one past a signal. + building.open_segment()?; building.keep(buffer); let mut backs = Vec::new(); building.managed_reach(buffer, &mut backs); @@ -890,6 +901,8 @@ impl BlitCommandEncoder { { return Err(Error::Unsupported(Gap::MipmapFilter { pixel_format })); } + // The chain's segment marks what it does, in a new one past a signal. + building.open_segment()?; building.keep_texture(texture); building.wrote_texture_managed(texture); // Its levels past the first are written: a heap texture an alias's write left stale @@ -1130,6 +1143,9 @@ impl BlitCommandEncoder { dst_offset, size: length, }; + // The copy's segment marks what it reaches and takes the copies back owed to it, in a + // new one past a signal. + building.open_segment()?; building.keep(buffer); // The textures over the device copy go back to it first (`crate::over`). let mut backs = Vec::new(); diff --git a/crates/metal2vulkan-runtime/src/command.rs b/crates/metal2vulkan-runtime/src/command.rs index 0e47c31a3..b996f4f23 100644 --- a/crates/metal2vulkan-runtime/src/command.rs +++ b/crates/metal2vulkan-runtime/src/command.rs @@ -1277,6 +1277,22 @@ impl Building { Ok(command) } + /// Makes the current segment the next command's, a new one where the last signals, and + /// begins its command buffer where it has none, what is owed left owed: called before a + /// command marks what it does in its segment ([`managed_reach`], [`wrote_managed`], + /// [`wrote_texture_managed`]), so the marks are those of the segment that runs it, and a + /// command buffer that cannot begin fails the command before it marks or takes anything. + /// + /// Err: [`Error::Vulkan`] where the command buffer cannot record. + /// + /// [`managed_reach`]: Self::managed_reach + /// [`wrote_managed`]: Self::wrote_managed + /// [`wrote_texture_managed`]: Self::wrote_texture_managed + pub(crate) fn open_segment(&mut self) -> Result<(), Error> { + self.current()?; + Ok(()) + } + /// The current segment's command buffer, begun where it has none. Commands after a signal go /// in a new segment. fn current(&mut self) -> Result { diff --git a/crates/metal2vulkan-runtime/src/encoder.rs b/crates/metal2vulkan-runtime/src/encoder.rs index 8956eb18f..20e05fc25 100644 --- a/crates/metal2vulkan-runtime/src/encoder.rs +++ b/crates/metal2vulkan-runtime/src/encoder.rs @@ -1300,6 +1300,9 @@ impl ComputeCommandEncoder { }; let wrote = { let building = recording(&mut self.building); + // The dispatch's segment marks what it does and takes the copies back owed to it, in + // a new one past a signal. + building.open_segment()?; // Heap textures it writes that an alias's write left stale move from undefined first // (`crate::alias`). if building.aliased() { diff --git a/crates/metal2vulkan-runtime/src/render_encoder.rs b/crates/metal2vulkan-runtime/src/render_encoder.rs index cdccc209c..5cda73d4a 100644 --- a/crates/metal2vulkan-runtime/src/render_encoder.rs +++ b/crates/metal2vulkan-runtime/src/render_encoder.rs @@ -930,12 +930,10 @@ fn begin( }; for t in pass.targets() { building.keep_texture(&t.texture); - building.wrote_texture_managed(&t.texture); } if pass.resolving { for r in pass.resolves() { building.keep_texture(&r.texture); - building.wrote_texture_managed(&r.texture); } } // Kept as Metal's pass holds it; its writes are the encoder's, at its first mode and its end. @@ -955,6 +953,12 @@ fn begin( building.overs_before(overs(), false)?; let opens = building.opens_command_buffer(); let command = building.ordered_command()?; + // The attachments and resolve textures the pass writes, marked after `ordered_command`, which + // may have split the recording at a signal: the marks are the pass's own segment's + // (`crate::over::ManagedOvers`). + for texture in (pass.targets().map(|t| &t.texture)).chain(resolves().map(|r| &r.texture)) { + building.wrote_texture_managed(texture); + } // Marked after `ordered_command`, as a blit's copy marks it: the host reads a texture over a // Shared buffer's bytes in the buffer. let host_reads = pass.targets().any(|t| t.texture.host_reads())