diff --git a/crates/metal2vulkan-rt/README.md b/crates/metal2vulkan-rt/README.md index 018135983..c5154db0c 100644 --- a/crates/metal2vulkan-rt/README.md +++ b/crates/metal2vulkan-rt/README.md @@ -700,6 +700,15 @@ that touch blocks first. shaders reach that is no multiple of a texel block's bytes, or of 4 for a depth or stencil aspect, and a row stride of no whole number of a compressed format's blocks; also what `replace_region` and `get_bytes` refuse (`Gap::TextureBytes`, and `Gap::FloatDepthUpload` into a texture). +- `copy_from_buffer_to_buffer` is `copyFromBuffer:sourceOffset:toBuffer:destinationOffset:size:`: + one `vkCmdCopyBuffer` region between the bytes shaders reach (a Managed buffer's device copy, + where the device keeps one), between the same two barriers as a fill, a copy into a Shared + buffer marking the segment as a copy into one does. A size of 0 copies nothing. Refused, as + Metal's validation stops them: a range past either buffer's end (`Refusal::BufferCopyRange`), + and on macOS an offset or a size that is not a multiple of 4 (`Refusal::BufferCopyUnaligned`). + Refused too: a source and a destination that share bytes, one buffer's overlapping ranges or + two buffers that overlap in one block (`Refusal::BufferCopyOverlap`), which `vkCmdCopyBuffer` + forbids and the runtime does not emulate. - `fill_buffer` is `fillBuffer:range:value:`: one `vkCmdFillBuffer` of the byte in each word, between the same two barriers, a fill of a Shared buffer marking the segment as a copy into one does. Refused (`Refusal::FillRange`), as Metal's validation stops them: an empty range and diff --git a/crates/metal2vulkan-rt/src/blit.rs b/crates/metal2vulkan-rt/src/blit.rs index 45776007d..06fb6086c 100644 --- a/crates/metal2vulkan-rt/src/blit.rs +++ b/crates/metal2vulkan-rt/src/blit.rs @@ -13,7 +13,8 @@ //! the region, between the same two barriers; the second also makes a write into the buffer //! visible to every later command, and to the host where the buffer is Shared. //! -//! A fill is one `vkCmdFillBuffer` between two barriers: the first after every earlier command, +//! A copy between buffers is one `vkCmdCopyBuffer` region between the bytes shaders reach, and a +//! fill one `vkCmdFillBuffer`, each between two barriers: the first after every earlier command, //! as a copy's, the second making its writes visible to every later command. //! //! A synchronize of a Managed buffer with a device copy is one `vkCmdCopyBuffer` of the copy into @@ -244,6 +245,84 @@ impl BlitCommandEncoder { self.buffer_copy(source, from, size, destination, layout, false) } + /// `copyFromBuffer:sourceOffset:toBuffer:destinationOffset:size:`: `size` bytes at + /// `source_offset` in `source` to `destination_offset` in `destination`, one + /// `vkCmdCopyBuffer` region between the bytes shaders reach (a Managed buffer's device copy, + /// where the device keeps one), between a fill's two barriers. A size of 0 copies nothing. The + /// command buffer keeps both buffers until it retires. + /// + /// Err: [`Refusal::OtherDevice`] for another device's buffer; [`Refusal::BufferCopyRange`] for + /// a range past either buffer's end; [`Refusal::BufferCopyUnaligned`] for an offset or a size + /// that is not a multiple of 4, as Metal's validation stops it on macOS; + /// [`Refusal::BufferCopyOverlap`] for a source and a destination that share bytes; + /// [`Error::Vulkan`] where the command buffer cannot record. + pub fn copy_from_buffer_to_buffer( + &mut self, + source: &Buffer, + source_offset: u64, + destination: &Buffer, + destination_offset: u64, + size: u64, + ) -> Result<(), Error> { + let building = self.building(); + let core = Arc::clone(building.device.core()); + if !source.is_of(&core) || !destination.is_of(&core) { + return Err(Error::Refused(Refusal::OtherDevice)); + } + // A Managed buffer's GPU side is its device copy, where it has one. + let span = |buffer: &Buffer| { + let (buffer_of, base) = buffer.device_range(); + Span { + buffer: buffer_of, + base, + len: buffer.length(), + } + }; + let (from, to) = (span(source), span(destination)); + let Some(region) = buffer_to_buffer(from, source_offset, to, destination_offset, size)? + else { + return Ok(()); + }; + building.keep(source); + building.keep(destination); + // The textures over either device copy go back to it first; the destination's owe their + // copies in (`crate::over::ManagedOvers`). + building.managed_backs(over::backs(source, None, true))?; + building.managed_backs(over::backs(destination, None, true))?; + building.wrote_managed(destination); + let overs = [ + (source.id(), Access::Read), + (destination.id(), Access::Write), + ]; + building.overs_before(&overs, false)?; + let command = building.ordered_command()?; + building.overs_after(&overs, false); + // Marked after `ordered_command`, as a copy into a buffer is. + if destination.is_shared() { + building.wrote_host(); + } + let earlier = [memory_barrier(Reach::Commands)]; + let written = [written()]; + let device = &core.device; + // SAFETY: the command buffer records outside any render pass and keeps both buffers until + // it retires; the region lies in each buffer's device range and its source and + // destination share no byte (`buffer_to_buffer`). + unsafe { + device.cmd_pipeline_barrier2( + command, + &vk::DependencyInfo::default().memory_barriers(&earlier), + ); + device.cmd_copy_buffer(command, from.buffer, to.buffer, &[region]); + device.cmd_pipeline_barrier2( + command, + &vk::DependencyInfo::default().memory_barriers(&written), + ); + } + core.counters.count(Metric::Barriers); + core.counters.count(Metric::Barriers); + Ok(()) + } + /// A copy of `size` texels at `at` in `texture` from or, not `into_image`, to `buffer`. fn buffer_copy( &mut self, @@ -650,6 +729,64 @@ pub(crate) fn fill_range(base: u64, len: u64, range: Range) -> Result<(u64, Ok((offset, length)) } +/// One buffer of a copy between buffers: the `VkBuffer` shaders reach it in, its offset there, +/// and its length. +#[derive(Clone, Copy)] +pub(crate) struct Span { + pub(crate) buffer: vk::Buffer, + pub(crate) base: u64, + pub(crate) len: u64, +} + +/// Checks a copy of `size` bytes from `source_offset` in `source` to `destination_offset` in +/// `destination`: the region of `vkCmdCopyBuffer` to record, `None` for a size of 0. +/// +/// Err: [`Refusal::BufferCopyRange`]; [`Refusal::BufferCopyUnaligned`]; +/// [`Refusal::BufferCopyOverlap`]. +pub(crate) fn buffer_to_buffer( + source: Span, + source_offset: u64, + destination: Span, + destination_offset: u64, + size: u64, +) -> Result, Error> { + for (span, offset) in [(source, source_offset), (destination, destination_offset)] { + if offset.checked_add(size).is_none_or(|end| end > span.len) { + return Err(Error::Refused(Refusal::BufferCopyRange { + offset, + size, + len: span.len, + })); + } + } + if source_offset % 4 != 0 || destination_offset % 4 != 0 || size % 4 != 0 { + return Err(Error::Refused(Refusal::BufferCopyUnaligned { + source_offset, + destination_offset, + size, + })); + } + if size == 0 { + return Ok(None); + } + let (from, to) = ( + source.base + source_offset, + destination.base + destination_offset, + ); + if source.buffer == destination.buffer && from < to + size && to < from + size { + return Err(Error::Refused(Refusal::BufferCopyOverlap { + source_offset, + destination_offset, + size, + })); + } + Ok(Some(vk::BufferCopy { + src_offset: from, + dst_offset: to, + size, + })) +} + /// A buffer's side of a copy: its offset in its block, its length, and where the region lies /// in it. #[derive(Clone, Copy)] diff --git a/crates/metal2vulkan-rt/src/error.rs b/crates/metal2vulkan-rt/src/error.rs index 431543b1a..3bfd2d3da 100644 --- a/crates/metal2vulkan-rt/src/error.rs +++ b/crates/metal2vulkan-rt/src/error.rs @@ -482,6 +482,45 @@ pub enum Refusal { /// The heap's bytes. heap_len: u64, }, + /// A copy between buffers + /// ([`BlitCommandEncoder::copy_from_buffer_to_buffer`](crate::BlitCommandEncoder::copy_from_buffer_to_buffer)) + /// whose range, `size` bytes from `offset`, leaves the source or the destination. + /// + /// Basis: metal-documented (Metal's validation stops a copy past either buffer's length). + BufferCopyRange { + /// The range's offset in the buffer it leaves. + offset: u64, + /// The bytes copied. + size: u64, + /// That buffer's length. + len: u64, + }, + /// A copy between buffers whose source offset, destination offset or size is not a multiple + /// of 4. + /// + /// Basis: metal-documented (`copyFromBuffer:sourceOffset:toBuffer:destinationOffset:size:`: + /// on macOS both offsets and the size are multiples of 4). + BufferCopyUnaligned { + /// The offset in the source. + source_offset: u64, + /// The offset in the destination. + destination_offset: u64, + /// The bytes copied. + size: u64, + }, + /// A copy between buffers whose source and destination share bytes: one buffer's + /// overlapping ranges, or two buffers that overlap in one block. + /// + /// Basis: ours (Metal states no result for such a copy, and `vkCmdCopyBuffer` reads no byte + /// it also writes, `VUID-vkCmdCopyBuffer-pRegions-00117`; the runtime does not emulate one). + BufferCopyOverlap { + /// The offset in the source. + source_offset: u64, + /// The offset in the destination. + destination_offset: u64, + /// The bytes copied. + size: u64, + }, } /// A Metal feature the runtime does not build yet, with what it was asked. Each is refused until a @@ -1061,6 +1100,26 @@ impl fmt::Display for Refusal { f, "a heap texture of {size} bytes aligned to {align} does not lie at offset {offset} of a heap of {heap_len} bytes" ), + Refusal::BufferCopyRange { offset, size, len } => write!( + f, + "a copy of {size} bytes at {offset} leaves a buffer of {len} bytes" + ), + Refusal::BufferCopyUnaligned { + source_offset, + destination_offset, + size, + } => write!( + f, + "a copy of {size} bytes from {source_offset} to {destination_offset} is not in multiples of 4" + ), + Refusal::BufferCopyOverlap { + source_offset, + destination_offset, + size, + } => write!( + f, + "a copy of {size} bytes from {source_offset} to {destination_offset} reads bytes it writes" + ), } } } diff --git a/crates/metal2vulkan-rt/src/tests/blit.rs b/crates/metal2vulkan-rt/src/tests/blit.rs index 815ae96a9..5c2477755 100644 --- a/crates/metal2vulkan-rt/src/tests/blit.rs +++ b/crates/metal2vulkan-rt/src/tests/blit.rs @@ -25,6 +25,14 @@ //! region kept and each result plain Metal's (job m3-max-43555); one copy into a Shared buffer //! alone is one submission and three barriers, the segment's end reaching the host, and copies //! no byte of the runtime's own. +//! - A copy between buffers takes ranges inside both buffers (`Refusal::BufferCopyRange`), both +//! offsets and the size multiples of 4 (`Refusal::BufferCopyUnaligned`), and a source and a +//! destination that share no byte (`Refusal::BufferCopyOverlap`), one buffer's ranges or two +//! buffers' in one block; a size of 0 copies nothing. Under a device cfg its bytes land where +//! it names, between two buffers of one block and within one buffer, everything around them +//! kept, at one submission and three barriers alone, copying no byte of the runtime's own; a +//! copy into a Managed buffer lands in the bytes shaders reach, which a synchronize brings to +//! the host. //! - A fill takes a range of whole words inside the buffer: an empty range or one past the end is //! `Refusal::FillRange`, one of no whole words `Gap::FillAlignment`. Under a device cfg its //! bytes are plain Metal's (probe `blit_fill_rules.m`, job m3-max-43571), at one submission and @@ -40,8 +48,8 @@ //! synchronized a device copy or a Managed texture. use crate::blit::{ - buffer_copy, fill_range, texture_copy, BufferCopy, BufferLayout, ImageCopy, Lies, Side, - TexturePlace, + buffer_copy, buffer_to_buffer, fill_range, texture_copy, BufferCopy, BufferLayout, ImageCopy, + Lies, Side, Span, TexturePlace, }; use crate::error::{Error, Gap, Refusal}; use crate::texture::{CopyUnit, Placed}; @@ -716,6 +724,121 @@ fn a_layout_metal_stops_is_refused_and_one_a_copy_command_cannot_address_is_a_ga )); } +#[test] +fn a_copy_between_buffers_takes_words_inside_both_that_share_no_byte() { + use ash::vk::Handle; + let one = vk::Buffer::from_raw(1); + let span = |buffer, base, len| Span { buffer, base, len }; + // Offsets in the device's buffer are each buffer's in its block plus its own. + let region = buffer_to_buffer( + span(one, 256, 64), + 8, + span(vk::Buffer::from_raw(2), 0, 32), + 4, + 16, + ) + .expect("a copy") + .expect("a region"); + assert_eq!( + (region.src_offset, region.dst_offset, region.size), + (264, 4, 16) + ); + // Two buffers of one block, side by side, and one buffer's two ranges, apart. + assert!( + buffer_to_buffer(span(one, 0, 64), 0, span(one, 64, 64), 0, 64).is_ok_and(|r| r.is_some()) + ); + assert!( + buffer_to_buffer(span(one, 0, 64), 0, span(one, 0, 64), 32, 32).is_ok_and(|r| r.is_some()) + ); + // A size of 0 copies nothing, wherever it is. + assert!(matches!( + buffer_to_buffer(span(one, 0, 64), 64, span(one, 0, 64), 0, 0), + Ok(None) + )); + let refused = |result: Result, Error>| match result { + Err(Error::Refused(refusal)) => refusal, + other => panic!("{:?}", other.map(|r| r.is_some())), + }; + for (offset, size) in [(60, 8), (68, 0), (u64::MAX - 3, 8)] { + assert_eq!( + refused(buffer_to_buffer( + span(one, 0, 64), + offset, + span(one, 128, 256), + 0, + size + )), + Refusal::BufferCopyRange { + offset, + size, + len: 64 + }, + "{offset} {size}" + ); + } + assert_eq!( + refused(buffer_to_buffer( + span(one, 0, 256), + 0, + span(one, 0, 64), + 60, + 8 + )), + Refusal::BufferCopyRange { + offset: 60, + size: 8, + len: 64 + }, + "the destination" + ); + for (from, to, size) in [(2, 0, 4), (0, 2, 4), (0, 0, 6)] { + assert_eq!( + refused(buffer_to_buffer( + span(one, 0, 64), + from, + span(vk::Buffer::from_raw(2), 0, 64), + to, + size + )), + Refusal::BufferCopyUnaligned { + source_offset: from, + destination_offset: to, + size + }, + "{from} {to} {size}" + ); + } + // One buffer's overlapping ranges, and two buffers of one block that overlap. + assert_eq!( + refused(buffer_to_buffer( + span(one, 0, 64), + 0, + span(one, 0, 64), + 16, + 32 + )), + Refusal::BufferCopyOverlap { + source_offset: 0, + destination_offset: 16, + size: 32 + } + ); + assert_eq!( + refused(buffer_to_buffer( + span(one, 32, 64), + 0, + span(one, 0, 64), + 0, + 64 + )), + Refusal::BufferCopyOverlap { + source_offset: 0, + destination_offset: 0, + size: 64 + } + ); +} + #[test] fn a_fill_takes_whole_words_of_a_range_inside_the_buffer() { // The range's offset is the buffer's in its block plus its own. @@ -1485,6 +1608,87 @@ pub(crate) mod on_device { }); } + /// A copy between two buffers of one block and one within a buffer land where they name, + /// everything around them kept, at one submission and three barriers alone, copying nothing + /// of the runtime's own; a copy into a Managed buffer lands in the bytes shaders reach, which a + /// synchronize brings to the host. + #[test] + fn every_device_copies_between_buffers() { + each_device("blit_buffer_to_buffer", |name, _, device| { + let block = (device.take_block(MemoryClass::Shared, 4096)).expect("a Shared block"); + let source = (device.new_buffer(block.id, 0, 256, true)).expect("a buffer"); + let destination = (device.new_buffer(block.id, 256, 256, true)).expect("a buffer"); + let (from, into) = (pattern(256, 31), pattern(256, 47)); + write(&source, &from); + write(&destination, &into); + let queue = device.new_command_queue(4).expect("a queue"); + let counters = device.counters(); + + // Between two buffers of one block, alone. + settled(&device); + let metrics = counters.metrics(); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut encoder = command_buffer.blit_command_encoder().expect("an encoder"); + encoder + .copy_from_buffer_to_buffer(&source, 16, &destination, 100, 64) + .unwrap_or_else(|error| panic!("{name}: {error}")); + encoder.end_encoding(); + run(name, &command_buffer); + let after = counters.metrics(); + assert_eq!( + ( + after.submissions - metrics.submissions, + after.barriers - metrics.barriers, + after.bytes_copied - metrics.bytes_copied, + after.passes - metrics.passes, + ), + (1, 3, 0, 1), + "{name}: submissions, barriers, bytes copied, passes" + ); + let mut want = into.clone(); + want[100..164].copy_from_slice(&from[16..80]); + assert_eq!(read(&destination), want, "{name}: between two buffers"); + assert_eq!(read(&source), from, "{name}: the source kept"); + + // Within one buffer, two ranges apart; a size of 0 records nothing more. + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut encoder = command_buffer.blit_command_encoder().expect("an encoder"); + encoder + .copy_from_buffer_to_buffer(&source, 0, &source, 128, 32) + .unwrap_or_else(|error| panic!("{name}: {error}")); + encoder + .copy_from_buffer_to_buffer(&source, 0, &source, 0, 0) + .unwrap_or_else(|error| panic!("{name}: {error}")); + encoder.end_encoding(); + run(name, &command_buffer); + let mut want = from.clone(); + want[128..160].copy_from_slice(&from[0..32]); + assert_eq!(read(&source), want, "{name}: within one buffer"); + + // Into a Managed buffer: its bytes shaders reach, brought to the host by a + // synchronize. + let copied = !device.core().shared_is_device_local(); + let managed = (device.new_managed_buffer(block.id, 512, 64, 64)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut encoder = command_buffer.blit_command_encoder().expect("an encoder"); + encoder + .copy_from_buffer_to_buffer(&destination, 0, &managed, 8, 32) + .unwrap_or_else(|error| panic!("{name}: {error}")); + encoder + .synchronize_resource(Resource::Buffer(&managed)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + encoder.end_encoding(); + run(name, &command_buffer); + let landed = read(&managed); + assert_eq!( + landed[8..40], + read(&destination)[0..32], + "{name}: into a Managed buffer (device copy: {copied})" + ); + }); + } + /// Returns once the pool holds a ready block of each class again: the block-maker thread /// makes one after a block is taken, a Private one zeroed in a submission of its own, which a /// count of a test's own work must not take in. diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 13f71781d..9db4f5833 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -9288,6 +9288,7 @@ method metal2vulkan-air::tensor_ops::OperandIndex::from_raw pub fn from_raw(raw: method metal2vulkan-air::tensor_ops::RunForm::arity pub fn arity(&self) -> usize method metal2vulkan-air::tensor_ops::RunForm::operand_args pub fn operand_args(&self) -> [usize; 3] method metal2vulkan-rt::BlitCommandEncoder::copy_from_buffer pub fn copy_from_buffer(&mut self, source: &Buffer, layout: BufferLayout, size: [u32; 3], destination: &Texture, to: TexturePlace) -> Result<(), Error> +method metal2vulkan-rt::BlitCommandEncoder::copy_from_buffer_to_buffer pub fn copy_from_buffer_to_buffer(&mut self, source: &Buffer, source_offset: u64, destination: &Buffer, destination_offset: u64, size: u64) -> Result<(), Error> method metal2vulkan-rt::BlitCommandEncoder::copy_from_texture pub fn copy_from_texture(&mut self, source: &Texture, from: TexturePlace, size: [u32; 3], destination: &Texture, to: TexturePlace) -> Result<(), Error> method metal2vulkan-rt::BlitCommandEncoder::copy_from_texture_to_buffer pub fn copy_from_texture_to_buffer(&mut self, source: &Texture, from: TexturePlace, size: [u32; 3], destination: &Buffer, layout: BufferLayout) -> Result<(), Error> method metal2vulkan-rt::BlitCommandEncoder::end_encoding pub fn end_encoding(mut self) @@ -13503,6 +13504,9 @@ variant metal2vulkan-rt::PrecisionNote::UnorderedFetchWithinDraw UnorderedFetchW variant metal2vulkan-rt::PrecisionNote::VertexSimdgroupGrouping VertexSimdgroupGrouping variant metal2vulkan-rt::PrecisionNote::ViewBaseTexelOffset ViewBaseTexelOffset variant metal2vulkan-rt::Refusal::BufferCopyLayout BufferCopyLayout { offset: u64, bytes_per_row: u64, bytes_per_image: u64, len: u64 } +variant metal2vulkan-rt::Refusal::BufferCopyOverlap BufferCopyOverlap { source_offset: u64, destination_offset: u64, size: u64 } +variant metal2vulkan-rt::Refusal::BufferCopyRange BufferCopyRange { offset: u64, size: u64, len: u64 } +variant metal2vulkan-rt::Refusal::BufferCopyUnaligned BufferCopyUnaligned { source_offset: u64, destination_offset: u64, size: u64 } variant metal2vulkan-rt::Refusal::BufferIndex BufferIndex { index: u32 } variant metal2vulkan-rt::Refusal::BufferPastBlock BufferPastBlock { offset: u64, length: u64, block_len: u64 } variant metal2vulkan-rt::Refusal::BufferTextureLayout BufferTextureLayout { offset: u64, bytes_per_row: u64, len: u64 } diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index d5e6bf692..b361b5af0 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -37,7 +37,7 @@ Columns: | What a call did wrong | 73 | 73 | 0 | 0 | 0 | 0 | 0 | | What a call did wrong, in detail | 174 | 157 | 0 | 0 | 0 | 0 | 0 | | Devices below the new runtime's floor | 8 | 8 | 0 | 0 | 0 | 0 | 0 | -| The new runtime's `Refusal` | 40 | 40 | 0 | 0 | 0 | 0 | 0 | +| The new runtime's `Refusal` | 43 | 43 | 0 | 0 | 0 | 0 | 0 | | The new runtime's `Limit` | 10 | 10 | 0 | 0 | 0 | 0 | 0 | | The new runtime's `Gap` | 18 | 18 | 0 | 0 | 0 | 0 | 0 | @@ -55,7 +55,7 @@ Columns: | What a call did wrong | 22 | 3 | 5 | 0 | 18 | 8 | 17 | 0 | | What a call did wrong, in detail | 60 | 26 | 23 | 0 | 39 | 26 | 0 | 0 | | Devices below the new runtime's floor | 0 | 0 | 0 | 8 | 0 | 0 | 0 | 0 | -| The new runtime's `Refusal` | 14 | 8 | 0 | 0 | 18 | 0 | 0 | 0 | +| The new runtime's `Refusal` | 14 | 10 | 0 | 0 | 19 | 0 | 0 | 0 | | The new runtime's `Limit` | 0 | 0 | 0 | 7 | 3 | 0 | 0 | 0 | | The new runtime's `Gap` | 0 | 0 | 0 | 0 | 18 | 0 | 0 | 0 | @@ -620,7 +620,7 @@ Columns: | `ManagedBlockNotShared` | A Managed buffer whose bytes are in a Private block (`Device::new_managed_buffer`) | every device (a public call's own check of its arguments) | `ours`: a Managed buffer's bytes are the consumer's, which it maps; a Private block has no mapping | 1: `crates/metal2vulkan-rt/src/buffer.rs (new_managed_buffer)` | `-` | | `ModifiedRange` | A changed range that leaves its buffer (`Buffer::did_modify_range`) | every device (a public call's own check of its arguments) | `ours`: the copy of such a range would write past the buffer's device copy | 1: `crates/metal2vulkan-rt/src/buffer.rs (did_modify_range)` | `-` | | `Committed` | A call on a command buffer already committed | every device (a public call's own check of its arguments) | `metal-documented`: Metal's validation asserts "commit an already committed command buffer", "Completed handler provided after commit call" and "Scheduled handler provided after commit call" | 1: `crates/metal2vulkan-rt/src/command.rs (open)` | `-` | -| `OtherDevice` | An event, a buffer, a texture or a pipeline state of another device in an encode call (`CommandBuffer::encode_wait_for_event`,... | every device (a public call's own check of its arguments) | `ours`: an event's semaphore, a buffer's block, a texture's image, a pipeline and a block belong to the `VkDevice` that made them | 15: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-rt/src/blit.rs (copy_from_texture)` (+12) | `-` | +| `OtherDevice` | An event, a buffer, a texture or a pipeline state of another device in an encode call (`CommandBuffer::encode_wait_for_event`,... | every device (a public call's own check of its arguments) | `ours`: an event's semaphore, a buffer's block, a texture's image, a pipeline and a block belong to the `VkDevice` that made them | 16: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-rt/src/blit.rs (copy_from_buffer_to_buffer)` (+13) | `-` | | `NoCommandBuffers` | A queue that may hold no command buffer (`Device::new_command_queue` with a count of 0) | every device (a public call's own check of its arguments) | `ours`: its first `commandBuffer` call would wait forever | 1: `crates/metal2vulkan-rt/src/queue.rs (new_command_queue)` | `-` | | `EncoderOpen` | A second encoder, an encode call, or a commit or enqueue, while an encoder of the command buffer is open | every device (a public call's own check of its arguments) | `metal-documented`: a command buffer has one active encoder at a time, ended by `endEncoding` before another is made or the command buffer is committed | 1: `crates/metal2vulkan-rt/src/command.rs (open)` | `-` | | `NoPipeline` | A dispatch with no pipeline state set | every device (a public call's own check of its arguments) | `metal-documented`: a compute dispatch needs a compute pipeline state set first | 1: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)` | `-` | @@ -654,6 +654,9 @@ Columns: | `ManagedTextureBytes` | A Managed texture's bytes the device cannot copy in place (`Device::new_managed_texture`) | every device (a public call's own check of its arguments) | `ours`: a buffer-to-image copy reads a place only so laid out, and the consumer's bytes are the place the copy reads | 5: `crates/metal2vulkan-rt/src/texture.rs (check_places)`, `crates/metal2vulkan-rt/src/texture.rs (named)` (+2) | `-` | | `BufferTextureLayout` | A texture over a buffer (`Buffer::new_texture`) whose rows are not a whole number of texels apart or are closer than a row, whose offset is not a... | every device (a public call's own check of its arguments) | `ours`: a linear image and a copy read rows whole texels apart from a texel's start, and texels past the buffer would lie in memory it does not hold | 1: `crates/metal2vulkan-rt/src/texture.rs (check_over)` | `-` | | `HeapTexturePlace` | A heap texture whose image does not lie in its heap (`Device::new_heap_texture`) | every device (a public call's own check of its arguments) | `ours`: an image bound past its heap's range would take memory the heap does not hold, and Vulkan binds an image only at its alignment | 1: `crates/metal2vulkan-rt/src/texture.rs (make)` | `-` | +| `BufferCopyRange` | A copy between buffers (`BlitCommandEncoder::copy_from_buffer_to_buffer`) whose range, `size` bytes from `offset`, leaves the source or the... | every device (a public call's own check of its arguments) | `metal-documented`: Metal's validation stops a copy past either buffer's length | 1: `crates/metal2vulkan-rt/src/blit.rs (buffer_to_buffer)` | `-` | +| `BufferCopyUnaligned` | A copy between buffers whose source offset, destination offset or size is not a multiple of 4 | every device (a public call's own check of its arguments) | `metal-documented`: `copyFromBuffer:sourceOffset:toBuffer:destinationOffset:size:`: on macOS both offsets and the size are multiples of 4 | 1: `crates/metal2vulkan-rt/src/blit.rs (buffer_to_buffer)` | `-` | +| `BufferCopyOverlap` | A copy between buffers whose source and destination share bytes | every device (a public call's own check of its arguments) | `ours`: Metal states no result for such a copy, and `vkCmdCopyBuffer` reads no byte it also writes, `VUID-vkCmdCopyBuffer-pRegions-00117`; the runtime does not emulate one | 1: `crates/metal2vulkan-rt/src/blit.rs (buffer_to_buffer)` | `-` | ## 12. The new runtime's `Limit` (`Error::Limit(Limit)`) @@ -1187,7 +1190,7 @@ Each refusal's sites, with the function that builds it. - `rt:Refusal::ManagedBlockNotShared`: `crates/metal2vulkan-rt/src/buffer.rs (new_managed_buffer)` - `rt:Refusal::ModifiedRange`: `crates/metal2vulkan-rt/src/buffer.rs (did_modify_range)` - `rt:Refusal::Committed`: `crates/metal2vulkan-rt/src/command.rs (open)` -- `rt:Refusal::OtherDevice`: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`; `crates/metal2vulkan-rt/src/blit.rs (copy_from_texture)`; `crates/metal2vulkan-rt/src/blit.rs (fill_buffer)`; `crates/metal2vulkan-rt/src/blit.rs (synchronize_resource)`; `crates/metal2vulkan-rt/src/command.rs (check)`; `crates/metal2vulkan-rt/src/device.rs (release_block)`; `crates/metal2vulkan-rt/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)`; `crates/metal2vulkan-rt/src/encoder.rs (set_buffer)`; `crates/metal2vulkan-rt/src/encoder.rs (set_compute_pipeline_state)`; `crates/metal2vulkan-rt/src/encoder.rs (set_sampler_state)`; `crates/metal2vulkan-rt/src/encoder.rs (set_texture)`; `crates/metal2vulkan-rt/src/encoder.rs (use_resource, 2 sites)`; `crates/metal2vulkan-rt/src/fence.rs (used_on)`; `crates/metal2vulkan-rt/src/texture.rs (new_managed_texture)` +- `rt:Refusal::OtherDevice`: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`; `crates/metal2vulkan-rt/src/blit.rs (copy_from_buffer_to_buffer)`; `crates/metal2vulkan-rt/src/blit.rs (copy_from_texture)`; `crates/metal2vulkan-rt/src/blit.rs (fill_buffer)`; `crates/metal2vulkan-rt/src/blit.rs (synchronize_resource)`; `crates/metal2vulkan-rt/src/command.rs (check)`; `crates/metal2vulkan-rt/src/device.rs (release_block)`; `crates/metal2vulkan-rt/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)`; `crates/metal2vulkan-rt/src/encoder.rs (set_buffer)`; `crates/metal2vulkan-rt/src/encoder.rs (set_compute_pipeline_state)`; `crates/metal2vulkan-rt/src/encoder.rs (set_sampler_state)`; `crates/metal2vulkan-rt/src/encoder.rs (set_texture)`; `crates/metal2vulkan-rt/src/encoder.rs (use_resource, 2 sites)`; `crates/metal2vulkan-rt/src/fence.rs (used_on)`; `crates/metal2vulkan-rt/src/texture.rs (new_managed_texture)` - `rt:Refusal::NoCommandBuffers`: `crates/metal2vulkan-rt/src/queue.rs (new_command_queue)` - `rt:Refusal::EncoderOpen`: `crates/metal2vulkan-rt/src/command.rs (open)` - `rt:Refusal::NoPipeline`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)` @@ -1221,6 +1224,9 @@ Each refusal's sites, with the function that builds it. - `rt:Refusal::ManagedTextureBytes`: `crates/metal2vulkan-rt/src/texture.rs (check_places)`; `crates/metal2vulkan-rt/src/texture.rs (named)`; `crates/metal2vulkan-rt/src/texture.rs (named_host)`; `crates/metal2vulkan-rt/src/texture.rs (upload_region, 2 sites)` - `rt:Refusal::BufferTextureLayout`: `crates/metal2vulkan-rt/src/texture.rs (check_over)` - `rt:Refusal::HeapTexturePlace`: `crates/metal2vulkan-rt/src/texture.rs (make)` +- `rt:Refusal::BufferCopyRange`: `crates/metal2vulkan-rt/src/blit.rs (buffer_to_buffer)` +- `rt:Refusal::BufferCopyUnaligned`: `crates/metal2vulkan-rt/src/blit.rs (buffer_to_buffer)` +- `rt:Refusal::BufferCopyOverlap`: `crates/metal2vulkan-rt/src/blit.rs (buffer_to_buffer)` - `rt:Limit::BlockLen`: `crates/metal2vulkan-rt/src/memory.rs (dedicated_len)` - `rt:Limit::BlockIds`: `crates/metal2vulkan-rt/src/memory.rs (number)` - `rt:Limit::ThreadgroupShape`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)`