diff --git a/crates/metal2vulkan-rt/README.md b/crates/metal2vulkan-rt/README.md index fd566726e..f3b8221b5 100644 --- a/crates/metal2vulkan-rt/README.md +++ b/crates/metal2vulkan-rt/README.md @@ -185,8 +185,9 @@ in its memory. The next commit of a command buffer with commands, on any queue, takes the bytes of every range named since: on the committing thread, before `commit` returns, it copies each once into a 64 MiB staging ring of the Shared type, and the copies from the ring into the device copies go - ahead of that command buffer's commands, after every earlier command on the device. So the - bytes are taken at the commit; Metal takes them shortly after, before the command buffer is + ahead of that command buffer's commands, after every earlier command on the device, which the + barrier ending each earlier command buffer orders; the copies record one barrier, after them. So + the bytes are taken at the commit; Metal takes them shortly after, before the command buffer is scheduled. A write or a `did_modify_range` made while a command buffer runs does not reach it. Commits take turns while they copy, so command buffers keep the order of their captures. A commit that finds the ring full waits for its oldest copy's submission to complete. Where that diff --git a/crates/metal2vulkan-rt/src/capture.rs b/crates/metal2vulkan-rt/src/capture.rs index 2020e8156..c598d9ae5 100644 --- a/crates/metal2vulkan-rt/src/capture.rs +++ b/crates/metal2vulkan-rt/src/capture.rs @@ -7,8 +7,10 @@ //! the command buffers keep the order of their captures. The copies into the device copies, and //! then into the images of the textures over the ranges in images of their own //! (`crate::over::ManagedOvers`), are recorded into command buffers of their own, [`CopyIn`]s, -//! which go ahead of the command buffer's own commands in queue order, each after a barrier that -//! puts every earlier command on the queue first. So a command buffer reads the bytes as they were +//! which go ahead of the command buffer's own commands in queue order. A copy-in records no barrier +//! before its copies: the one that ends every earlier segment, upload, fill and copy-in on the queue +//! puts every earlier command first, as it does for a segment (`record::end`). So a command buffer +//! reads the bytes as they were //! at its commit, and a write after the commit reaches none committed before it. Metal takes them //! shortly after the commit, before the command buffer is scheduled, and a write or a //! `didModifyRange:` made while the command buffer runs does not reach it. @@ -207,7 +209,8 @@ pub(crate) struct Chunk { impl Chunk { /// A copy-in's command buffer, recording, after the copies back `backs` (the first of a - /// capture's), or a barrier that puts every earlier command first. + /// capture's). It begins with no barrier of its own: the one ending each earlier command + /// buffer on the queue puts every earlier command first (`record::end`). /// /// Err: [`Error::Vulkan`] where a command pool or buffer cannot be made. pub(crate) fn begin(core: &Core, backs: Vec) -> Result { @@ -223,14 +226,8 @@ impl Chunk { let copies: Vec = backs.iter().map(|(_, copy, _)| *copy).collect(); // SAFETY: the command buffer is recording, and only this thread has it; each image is in // its home layout between commands, and the copy-in holds it. - unsafe { - match copies.is_empty() { - true => { - record::barrier(device, command, Reach::Commands); - core.counters.count(Metric::Barriers); - } - false => over::record_side(device, command, &copies, false, &core.counters), - } + if !copies.is_empty() { + unsafe { over::record_side(device, command, &copies, false, &core.counters) }; } Ok(Chunk { recorder, diff --git a/crates/metal2vulkan-rt/src/tests/managed.rs b/crates/metal2vulkan-rt/src/tests/managed.rs index cab1e9524..6c2af5968 100644 --- a/crates/metal2vulkan-rt/src/tests/managed.rs +++ b/crates/metal2vulkan-rt/src/tests/managed.rs @@ -2,8 +2,8 @@ //! every device of the cfg's kind, in the form Vulkan's device type picks: with a device copy //! where the device is neither integrated nor a CPU, the copy holds the consumer's first bytes and //! zeros after them, a changed range reaches it at the next commit and a range not marked changed -//! does not, and a change submits nothing; without one, shaders read the consumer's bytes as they -//! are. A command buffer reads the bytes of its commit, not those written and named after it +//! does not, a change submits nothing, and the copy-in at a commit adds one barrier; without one, +//! shaders read the consumer's bytes as they are. A command buffer reads the bytes of its commit, not those written and named after it //! while it waits, where there is a device copy; a write after the range is named and before the //! commit is seen. Three rings' worth named with nothing held streams through the ring alone; //! more than a ring behind a command buffer held on the host takes staging of its own, which it @@ -146,10 +146,23 @@ pub(crate) mod on_device { if !copied { expected[20_000..20_100].fill(0x5A); } + let before = counters.metrics().barriers; assert!( device_bytes(&device, &managed, &into, LEN) == expected, "{name}: the bytes after the changes (device copy: {copied})" ); + let named = counters.metrics().barriers - before; + assert!( + device_bytes(&device, &managed, &into, LEN) == expected, + "{name}: the bytes with nothing named (device copy: {copied})" + ); + // The copy-in adds one barrier, after its copies: the one ending each earlier command + // buffer on the queue orders it after them. + assert_eq!( + named - (counters.metrics().barriers - before - named), + u64::from(copied), + "{name}: the barriers a copy-in adds (device copy: {copied})" + ); // A change only names its range: nothing is submitted until a commit. let before = counters.metrics().submissions;