Runtime: a command marks its Managed-over writes and takes their copies back in its own segment, after its command buffer begins
A command encoded right after encodeSignalEvent marked what it did to textures over a Managed buffer's device copy (managed_reach, wrote_managed, wrote_texture_managed) in the segment the signal ends, before ordered_command split the recording there. That segment goes in a submission of its own ahead of the command's, so on a device with two copies a write's copy in was taken before the write ran and never after it (a fill of the buffer, then every later reader of the texture read the bytes from before the fill), and a texture write's copy back was made before the write. And managed_reach took the copy back owed by a write earlier in the command buffer before managed_backs began the command buffer, so a begin that failed dropped it for good. Building::open_segment makes the current segment the command's (a new one past a signal) and begins its command buffer, with what is owed left owed. The blit copies, fill, mipmap chain and synchronize, and the dispatch, call it before their first mark; a render pass's begin marks its attachments after its ordered_command instead, so whether it opens its command buffer, which spares its first barrier, is read as before. No public change and no new form.
This commit is contained in:
1 parent
6bc41c8b94
commit
7adf1d6603
4 files changed
+41
-2
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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<vk::CommandBuffer, Error> {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in new issue
Block a user