From 05ce4db691989607fe2f65215c9572b047f33d58 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Tue, 17 Nov 2026 19:54:09 -0800 Subject: [PATCH] rt: Fence, MTLFence, whose updates and waits on compute and blit encoders record nothing A command buffer's encoders run in order and a queue's command buffers in commit order, each encoder's writes reaching the commands after it through the barrier at its end or its segment's end, so a wait after an update already sees them. A fence keeps the first queue whose encoder uses it; a use on another queue is Gap::FenceOtherQueue, as Metal's fence orders one queue and MTLEvent orders queues. Another device's fence is Refusal::OtherDevice. Test: every_device_orders_a_wait_after_an_update_and_records_nothing_for_either fills a buffer in one command buffer and updates the fence from a blit and a compute encoder, waits in a second committed before the first completes and copies the buffer out, and counts the same submissions, barriers, bytes copied and passes with the fence calls as without; a second queue's compute and blit encoders get the gap. REFUSALS.md and api_signatures.tsv regenerated. --- crates/metal2vulkan-rt/README.md | 9 ++ crates/metal2vulkan-rt/src/blit.rs | 21 +++ crates/metal2vulkan-rt/src/command.rs | 5 + crates/metal2vulkan-rt/src/encoder.rs | 21 +++ crates/metal2vulkan-rt/src/error.rs | 7 + crates/metal2vulkan-rt/src/fence.rs | 60 +++++++ crates/metal2vulkan-rt/src/lib.rs | 2 + crates/metal2vulkan-rt/src/tests/fence.rs | 159 +++++++++++++++++++ crates/metal2vulkan-rt/src/tests/mod.rs | 1 + crates/metal2vulkan/tests/api_signatures.tsv | 7 + docs/REFUSALS.md | 6 +- 11 files changed, 296 insertions(+), 2 deletions(-) create mode 100644 crates/metal2vulkan-rt/src/fence.rs create mode 100644 crates/metal2vulkan-rt/src/tests/fence.rs diff --git a/crates/metal2vulkan-rt/README.md b/crates/metal2vulkan-rt/README.md index 763564367..a0be09b34 100644 --- a/crates/metal2vulkan-rt/README.md +++ b/crates/metal2vulkan-rt/README.md @@ -439,6 +439,12 @@ made, with no lock, and never rewritten for layouts. `signaled_value` is the higher of the semaphore and the floor. `notify_listener` runs its listener on the completion thread when the value is reached, at a signal in the middle of a command buffer as well as at its end; `wait_until_signaled_value` wakes then too. +- `Fence` is `MTLFence`, and `update_fence` and `wait_for_fence` on compute and blit encoders are + `updateFence:` and `waitForFence:`. They record nothing: a command buffer's encoders run in + their order and a queue's command buffers in their commit order, and each encoder's writes reach + the commands after it through the barrier at its end or at its segment's end, so a wait after an + update already sees them. Work with no fence between it is ordered as well, where Metal may run + it at once. A fence keeps the first queue whose encoder uses it. - `CommandQueue::abandon` ends every command buffer of the queue held at an event wait or not yet scheduled with `NotRun` and runs its handlers, as a Mac drops a dead process's held work, each retiring in the queue's order. Segments already submitted still complete, and so does a group @@ -489,6 +495,9 @@ that touch blocks first. resource IDs it made up, with no fault. The consumer treats every byte on the device as guest-writable and keeps nothing there that it parses or trusts. - Presenting (the binary semaphore a command buffer signals for a present) comes with presenting. +- A fence orders the encoders of one queue: an encoder of another queue that updates or waits on + it is refused (`Gap::FenceOtherQueue`), as Metal's fence orders one queue and `MTLEvent` orders + queues. - An indirect dispatch's threadgroup counts are the GPU's to read, so a count above the device's `maxComputeWorkGroupCount` is not refused; Vulkan leaves such a dispatch undefined. A direct dispatch past it is split into dispatches of at most that many, each told its first diff --git a/crates/metal2vulkan-rt/src/blit.rs b/crates/metal2vulkan-rt/src/blit.rs index b714eb015..287c19b25 100644 --- a/crates/metal2vulkan-rt/src/blit.rs +++ b/crates/metal2vulkan-rt/src/blit.rs @@ -27,6 +27,7 @@ use crate::command::{Building, CommandBuffer}; use crate::counters::Metric; use crate::encoder::Resource; use crate::error::{Error, Gap, Refusal}; +use crate::fence::Fence; use crate::record::{memory_barrier, Reach}; use crate::texture::{place, BytesPlace, CopyUnit, Placed, Region, Texture, TextureDescriptor}; use ash::vk; @@ -521,6 +522,26 @@ impl BlitCommandEncoder { Ok(()) } + /// `updateFence:`: encoders that wait on `fence` after this one see what this encoder and the + /// ones before it wrote. It records nothing ([`Fence`]): each copy's own barrier already + /// reaches them. + /// + /// Err: [`Refusal::OtherDevice`] for another device's fence; [`Gap::FenceOtherQueue`] for a + /// fence another queue used first. + pub fn update_fence(&mut self, fence: &Fence) -> Result<(), Error> { + let core = Arc::clone(self.building().device.core()); + fence.used_on(&core, self.command_buffer.queue()) + } + + /// `waitForFence:`: this encoder sees what the encoders up to `fence`'s last update wrote. It + /// records nothing ([`Fence`]): each copy's barrier before it already orders them. + /// + /// Err: as [`update_fence`](Self::update_fence). + pub fn wait_for_fence(&mut self, fence: &Fence) -> Result<(), Error> { + let core = Arc::clone(self.building().device.core()); + fence.used_on(&core, self.command_buffer.queue()) + } + /// `endEncoding`. Each copy ordered itself, so the encoder owes no barrier. pub fn end_encoding(mut self) { self.end(); diff --git a/crates/metal2vulkan-rt/src/command.rs b/crates/metal2vulkan-rt/src/command.rs index c51b8d107..a117518fe 100644 --- a/crates/metal2vulkan-rt/src/command.rs +++ b/crates/metal2vulkan-rt/src/command.rs @@ -457,6 +457,11 @@ impl CommandBuffer { } } + /// Its queue. + pub(crate) fn queue(&self) -> &Arc { + &self.inner.queue + } + /// Whether the command buffer is `queue`'s. pub(crate) fn is_of(&self, queue: &QueueInner) -> bool { self.inner.queue.is(queue) diff --git a/crates/metal2vulkan-rt/src/encoder.rs b/crates/metal2vulkan-rt/src/encoder.rs index eb7022b0e..0700def7c 100644 --- a/crates/metal2vulkan-rt/src/encoder.rs +++ b/crates/metal2vulkan-rt/src/encoder.rs @@ -4,6 +4,7 @@ use crate::buffer::Buffer; use crate::command::{Building, CommandBuffer}; use crate::counters::Metric; use crate::error::{Error, Gap, Limit, Refusal}; +use crate::fence::Fence; use crate::hazard::Access; use crate::pipeline::{ ComputePipelineState, FieldValue, Form, Interface, Kernel, Place, Variant, PUSH_BYTES, @@ -418,6 +419,26 @@ impl ComputeCommandEncoder { self.building().owe(); } + /// `updateFence:`: encoders that wait on `fence` after this one see what this encoder and the + /// ones before it wrote. It records nothing ([`Fence`]): its barrier at the end already + /// reaches them. + /// + /// Err: [`Refusal::OtherDevice`] for another device's fence; [`Gap::FenceOtherQueue`] for a + /// fence another queue used first. + pub fn update_fence(&mut self, fence: &Fence) -> Result<(), Error> { + let core = Arc::clone(self.building().device.core()); + fence.used_on(&core, self.command_buffer.queue()) + } + + /// `waitForFence:`: this encoder sees what the encoders up to `fence`'s last update wrote. It + /// records nothing ([`Fence`]): the barrier before its first dispatch already orders them. + /// + /// Err: as [`update_fence`](Self::update_fence). + pub fn wait_for_fence(&mut self, fence: &Fence) -> Result<(), Error> { + let core = Arc::clone(self.building().device.core()); + fence.used_on(&core, self.command_buffer.queue()) + } + /// `dispatchThreadgroups:threadsPerThreadgroup:`. /// /// A count above the device's `maxComputeWorkGroupCount` is split into dispatches within it, diff --git a/crates/metal2vulkan-rt/src/error.rs b/crates/metal2vulkan-rt/src/error.rs index 65d519089..a79d15b88 100644 --- a/crates/metal2vulkan-rt/src/error.rs +++ b/crates/metal2vulkan-rt/src/error.rs @@ -656,6 +656,12 @@ pub enum Gap { /// The byte after its last. end: u64, }, + /// A [`Fence`](crate::Fence) updated or waited on by an encoder of a queue other than the first + /// that used it: the runtime orders the encoders of one queue, so a fence would order nothing + /// across two. Metal's fence orders the encoders of one queue; `MTLEvent` orders queues. + /// + /// Basis: ours (a fence is built for one queue; the replay streams use each on one queue). + FenceOtherQueue, /// [`Texture::new_texture_view`](crate::Texture::new_texture_view) of a kind Metal makes and /// the runtime does not build: what `kind` names. /// @@ -1079,6 +1085,7 @@ impl fmt::Display for Gap { f, "a fill of {start}..{end}, not whole 4-byte words, is not built" ), + Gap::FenceOtherQueue => f.write_str("a fence used on a second queue is not built"), Gap::TextureView { kind } => write!(f, "a texture view that changes {kind:?} is not built"), } } diff --git a/crates/metal2vulkan-rt/src/fence.rs b/crates/metal2vulkan-rt/src/fence.rs new file mode 100644 index 000000000..0e22ca179 --- /dev/null +++ b/crates/metal2vulkan-rt/src/fence.rs @@ -0,0 +1,60 @@ +//! Fences: Metal's order between one queue's encoders, which the runtime's commit order and +//! barriers already give, so a fence records no device work. + +use crate::device::{Core, Device}; +use crate::error::{Error, Gap, Refusal}; +use crate::queue::QueueInner; +use std::sync::{Arc, OnceLock, Weak}; + +/// `MTLFence`: the encoders that wait on it after an update see what the encoders up to the +/// update wrote. +/// +/// The runtime records nothing for a fence. A command buffer's encoders run in their order and a +/// queue's command buffers in their commit order, each encoder's writes reaching the commands +/// after it through the barrier at its end or at its segment's end, so a wait after an update +/// already sees them. What differs: work with no fence between it is ordered too, where Metal may +/// run it at once (an empty dispatch committed after a busy one runs beside it on an M3 Max, probe +/// `empty_command_buffer_times.m`). Metal's fence orders encoders of one queue (`MTLEvent` orders +/// queues): the fence keeps the first queue whose encoder uses it, and a use on another queue is +/// [`Gap::FenceOtherQueue`]. A cheap handle: clones share one fence. It does not hold the device. +#[derive(Clone)] +pub struct Fence { + inner: Arc, +} + +/// The fence itself: its device and the first queue that used it, each held by a weak reference +/// that keeps its address from being reused, so a comparison by address is sound. +struct FenceInner { + core: Weak, + queue: OnceLock>, +} + +impl Device { + /// `newFence`. It makes no Vulkan object ([`Fence`]). + pub fn new_fence(&self) -> Fence { + Fence { + inner: Arc::new(FenceInner { + core: Arc::downgrade(self.core()), + queue: OnceLock::new(), + }), + } + } +} + +impl Fence { + /// An encoder of `queue`, on the device of `core`, updates or waits on the fence: the fence + /// keeps the queue if it is the first. + /// + /// Err: [`Refusal::OtherDevice`] for another device's fence; [`Gap::FenceOtherQueue`] for a + /// fence another queue used first. + pub(crate) fn used_on(&self, core: &Arc, queue: &Arc) -> Result<(), Error> { + if !std::ptr::eq(Weak::as_ptr(&self.inner.core), Arc::as_ptr(core)) { + return Err(Error::Refused(Refusal::OtherDevice)); + } + let first = self.inner.queue.get_or_init(|| Arc::downgrade(queue)); + match std::ptr::eq(Weak::as_ptr(first), Arc::as_ptr(queue)) { + true => Ok(()), + false => Err(Error::Unsupported(Gap::FenceOtherQueue)), + } + } +} diff --git a/crates/metal2vulkan-rt/src/lib.rs b/crates/metal2vulkan-rt/src/lib.rs index c0bbedc88..ccae7f2e8 100644 --- a/crates/metal2vulkan-rt/src/lib.rs +++ b/crates/metal2vulkan-rt/src/lib.rs @@ -20,6 +20,7 @@ mod encoder; mod error; mod event; mod extension; +mod fence; mod fill; pub mod floor; mod hazard; @@ -51,6 +52,7 @@ pub use encoder::{ComputeCommandEncoder, DispatchType, Resource, ResourceUsage}; pub use error::{Error, Gap, Limit, Refusal, TextureViewKind}; pub use event::{Event, SharedEvent}; pub use extension::{ConsumerFeature, DeviceExtension}; +pub use fence::Fence; pub use instance::{Instance, PhysicalDevice}; pub use memory::{BlockId, BlockInfo, BlockMappings, MemoryClass, BLOCK_LEN}; /// `MTLLibrary`: the translator's, read from AIR or a metallib. diff --git a/crates/metal2vulkan-rt/src/tests/fence.rs b/crates/metal2vulkan-rt/src/tests/fence.rs new file mode 100644 index 000000000..b06297ba6 --- /dev/null +++ b/crates/metal2vulkan-rt/src/tests/fence.rs @@ -0,0 +1,159 @@ +//! Fences, under a device cfg on every device of the cfg's kind: an encoder waiting on a fence +//! after another command buffer's encoder updated it sees that command buffer's writes, and the +//! fence calls of a compute and a blit encoder record no device work (the same submissions, +//! barriers, bytes copied and passes as the same work without them). A fence keeps the first queue +//! that uses it: a use on another queue is `Gap::FenceOtherQueue`. + +#[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod on_device { + use crate::tests::blit::on_device::settled; + use crate::tests::command::on_device::{each_device, finished}; + use crate::{ + BufferLayout, CommandBuffer, CommandQueue, Device, DispatchType, Error, Fence, Gap, + MemoryClass, Metrics, PixelFormat, TextureDescriptor, TexturePlace, TextureType, + TextureUsage, + }; + + /// `command_buffer` committed and complete with no error. + fn run(name: &str, command_buffer: &CommandBuffer) { + command_buffer.commit().expect("a commit"); + finished(name, command_buffer); + assert_eq!(command_buffer.error(), None, "{name}"); + } + + /// The submissions, barriers, bytes copied and passes from `before` to `after`. + fn delta(before: &Metrics, after: &Metrics) -> [u64; 4] { + [ + after.submissions - before.submissions, + after.barriers - before.barriers, + after.bytes_copied - before.bytes_copied, + after.passes - before.passes, + ] + } + + #[test] + fn every_device_orders_a_wait_after_an_update_and_records_nothing_for_either() { + each_device("fences", |name, _, device| { + let block = (device.take_block(MemoryClass::Shared, 4096)) + .expect("a Shared block") + .id; + let filled = (device.new_buffer(block, 0, 64, false)).expect("a buffer"); + let out = (device.new_buffer(block, 256, 64, false)).expect("a buffer"); + let mut d = TextureDescriptor::new(TextureType::Type2D, PixelFormat::RGBA8Unorm, 4, 4); + d.usage = TextureUsage::RENDER_TARGET; + let texture = device.new_texture(&d, None).expect("a texture"); + let queue = device.new_command_queue(4).expect("a queue"); + let layout = BufferLayout { + offset: 0, + bytes_per_row: 16, + bytes_per_image: 0, + }; + let counters = device.counters(); + // The first command buffer fills `filled` and updates the fence from a blit and a + // compute encoder; the second waits on it from both, then copies `filled` through the + // texture into `out`. Both are committed before either completes. + let pair = |value: u8, fence: Option<&Fence>| { + let first = queue.command_buffer().expect("a command buffer"); + let mut blit = first.blit_command_encoder().expect("an encoder"); + blit.fill_buffer(&filled, 0..64, value).expect("a fill"); + if let Some(fence) = fence { + blit.update_fence(fence).expect("an update"); + } + blit.end_encoding(); + let mut compute = + (first.compute_command_encoder(DispatchType::Serial)).expect("an encoder"); + if let Some(fence) = fence { + compute.update_fence(fence).expect("an update"); + } + compute.end_encoding(); + let second = queue.command_buffer().expect("a command buffer"); + let mut compute = + (second.compute_command_encoder(DispatchType::Serial)).expect("an encoder"); + if let Some(fence) = fence { + compute.wait_for_fence(fence).expect("a wait"); + } + compute.end_encoding(); + let mut blit = second.blit_command_encoder().expect("an encoder"); + if let Some(fence) = fence { + blit.wait_for_fence(fence).expect("a wait"); + } + let size = [4, 4, 1]; + (blit.copy_from_buffer(&filled, layout, size, &texture, TexturePlace::default())) + .expect("a copy"); + (blit.copy_from_texture_to_buffer( + &texture, + TexturePlace::default(), + size, + &out, + layout, + )) + .expect("a copy"); + blit.end_encoding(); + first.commit().expect("a commit"); + run(name, &second); + finished(name, &first); + assert_eq!(first.error(), None, "{name}"); + }; + // Once to move the texture home, outside the counts. + pair(1, None); + let fence = device.new_fence(); + settled(&device); + let before = counters.metrics(); + pair(0x5a, Some(&fence)); + let with = delta(&before, &counters.metrics()); + let contents = out.contents().expect("a Shared buffer"); + // SAFETY: the command buffer that wrote the buffer completed, and its writes reach + // the host. + let bytes = unsafe { std::slice::from_raw_parts(contents.as_ptr(), 64) }; + assert!( + bytes.iter().all(|&b| b == 0x5a), + "{name}: the wait sees the fill" + ); + settled(&device); + let before = counters.metrics(); + pair(0x5b, None); + let without = delta(&before, &counters.metrics()); + assert_eq!( + with, without, + "{name}: submissions, barriers, bytes copied and passes with the fence and without" + ); + other_queue(name, &device, &queue); + }); + } + + /// A fence `queue` used first refuses another queue's encoders; one another queue used first + /// is that queue's. + fn other_queue(name: &str, device: &Device, queue: &CommandQueue) { + let fence = device.new_fence(); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut blit = command_buffer.blit_command_encoder().expect("an encoder"); + blit.update_fence(&fence).expect("the first queue's update"); + blit.end_encoding(); + run(name, &command_buffer); + let second = device.new_command_queue(1).expect("a queue"); + let command_buffer = second.command_buffer().expect("a command buffer"); + let mut compute = + (command_buffer.compute_command_encoder(DispatchType::Serial)).expect("an encoder"); + assert!( + matches!( + compute.wait_for_fence(&fence), + Err(Error::Unsupported(Gap::FenceOtherQueue)) + ), + "{name}: a compute encoder of a second queue" + ); + compute.end_encoding(); + let mut blit = command_buffer.blit_command_encoder().expect("an encoder"); + assert!( + matches!( + blit.update_fence(&fence), + Err(Error::Unsupported(Gap::FenceOtherQueue)) + ), + "{name}: a blit encoder of a second queue" + ); + let own = device.new_fence(); + blit.update_fence(&own) + .expect("a fence the second queue used first"); + blit.end_encoding(); + run(name, &command_buffer); + } +} diff --git a/crates/metal2vulkan-rt/src/tests/mod.rs b/crates/metal2vulkan-rt/src/tests/mod.rs index 3c1ccfce2..1524680b1 100644 --- a/crates/metal2vulkan-rt/src/tests/mod.rs +++ b/crates/metal2vulkan-rt/src/tests/mod.rs @@ -4,6 +4,7 @@ mod cache; mod command; mod compute; mod device; +mod fence; mod floor; mod hazard; mod heap; diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 80b0f5000..6ee6bf145 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -9252,6 +9252,8 @@ method metal2vulkan-rt::BlitCommandEncoder::copy_from_texture_to_buffer pub fn c method metal2vulkan-rt::BlitCommandEncoder::end_encoding pub fn end_encoding(mut self) method metal2vulkan-rt::BlitCommandEncoder::fill_buffer pub fn fill_buffer(&mut self, buffer: &Buffer, range: Range, value: u8) -> Result<(), Error> method metal2vulkan-rt::BlitCommandEncoder::synchronize_resource pub fn synchronize_resource(&mut self, resource: Resource<'_>) -> Result<(), Error> +method metal2vulkan-rt::BlitCommandEncoder::update_fence pub fn update_fence(&mut self, fence: &Fence) -> Result<(), Error> +method metal2vulkan-rt::BlitCommandEncoder::wait_for_fence pub fn wait_for_fence(&mut self, fence: &Fence) -> Result<(), Error> method metal2vulkan-rt::BlockId::get pub fn get(self) -> u32 method metal2vulkan-rt::Buffer::block pub fn block(&self) -> BlockId method metal2vulkan-rt::Buffer::contents pub fn contents(&self) -> Option> @@ -9292,7 +9294,9 @@ method metal2vulkan-rt::ComputeCommandEncoder::set_compute_pipeline_state pub fn method metal2vulkan-rt::ComputeCommandEncoder::set_sampler_state pub fn set_sampler_state(&mut self, sampler: Option<&SamplerState>, index: u32) -> Result<(), Error> method metal2vulkan-rt::ComputeCommandEncoder::set_texture pub fn set_texture(&mut self, texture: Option<&Texture>, index: u32) -> Result<(), Error> method metal2vulkan-rt::ComputeCommandEncoder::set_threadgroup_memory_length pub fn set_threadgroup_memory_length(&mut self, length: u32, index: u32) -> Result<(), Error> +method metal2vulkan-rt::ComputeCommandEncoder::update_fence pub fn update_fence(&mut self, fence: &Fence) -> Result<(), Error> method metal2vulkan-rt::ComputeCommandEncoder::use_resource pub fn use_resource(&mut self, resource: Resource<'_>, usage: ResourceUsage) -> Result<(), Error> +method metal2vulkan-rt::ComputeCommandEncoder::wait_for_fence pub fn wait_for_fence(&mut self, fence: &Fence) -> Result<(), Error> method metal2vulkan-rt::ComputePipelineDescriptor::lowering_inputs pub fn lowering_inputs(&self) -> LoweringInputs method metal2vulkan-rt::ComputePipelineDescriptor::new pub fn new(kernel: StageSource) -> ComputePipelineDescriptor method metal2vulkan-rt::ComputePipelineDescriptor::reflection pub fn reflection(&self, budget: &crate::Budget) -> Result @@ -9314,6 +9318,7 @@ method metal2vulkan-rt::Device::new pub fn new(physical: &PhysicalDevice, option method metal2vulkan-rt::Device::new_buffer pub fn new_buffer(&self, block: BlockId, offset: u64, length: u64, zeroed: bool) -> Result method metal2vulkan-rt::Device::new_command_queue pub fn new_command_queue(&self, max_command_buffer_count: u32) -> Result method metal2vulkan-rt::Device::new_event pub fn new_event(&self) -> Result +method metal2vulkan-rt::Device::new_fence pub fn new_fence(&self) -> Fence method metal2vulkan-rt::Device::new_heap_texture pub fn new_heap_texture(&self, descriptor: &TextureDescriptor, index: Option, heap: HeapRange, offset: u64) -> Result method metal2vulkan-rt::Device::new_managed_buffer pub fn new_managed_buffer(&self, block: BlockId, offset: u64, length: u64, copied: u64) -> Result method metal2vulkan-rt::Device::new_managed_texture pub fn new_managed_texture(&self, descriptor: &TextureDescriptor, index: Option, bytes: &Buffer, places: &[BytesPlace]) -> Result @@ -11410,6 +11415,7 @@ struct metal2vulkan-rt::Device #[derive(Clone)] pub struct Device struct metal2vulkan-rt::DeviceExtension #[derive(Clone)] pub struct DeviceExtension struct metal2vulkan-rt::DeviceOptions #[derive(Clone, Default)] #[non_exhaustive] pub struct DeviceOptions struct metal2vulkan-rt::Event #[derive(Clone)] pub struct Event +struct metal2vulkan-rt::Fence #[derive(Clone)] pub struct Fence struct metal2vulkan-rt::FunctionDescriptor #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub struct FunctionDescriptor struct metal2vulkan-rt::Gauges #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] pub struct Gauges struct metal2vulkan-rt::HeapRange #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct HeapRange @@ -13320,6 +13326,7 @@ variant metal2vulkan-rt::Error::Unsupported Unsupported(Gap) variant metal2vulkan-rt::Error::Vulkan Vulkan { call: &'static str, result: vk::Result } variant metal2vulkan-rt::Gap::BufferCopyAlignment BufferCopyAlignment { pixel_format: PixelFormat, offset: u64, bytes_per_row: u64, bytes_per_image: u64 } variant metal2vulkan-rt::Gap::CubicSampler CubicSampler +variant metal2vulkan-rt::Gap::FenceOtherQueue FenceOtherQueue variant metal2vulkan-rt::Gap::FillAlignment FillAlignment { start: u64, end: u64 } variant metal2vulkan-rt::Gap::FloatDepthUpload FloatDepthUpload { pixel_format: PixelFormat } variant metal2vulkan-rt::Gap::HeapTexture HeapTexture { pixel_format: PixelFormat } diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 6511409ac..1bb2cf081 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -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 and a pipeline belong to the `VkDevice` that made them | 13: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-rt/src/blit.rs (copy_from_texture)` (+10) | `-` | +| `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 and a pipeline belong to the `VkDevice` that made them | 14: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-rt/src/blit.rs (copy_from_texture)` (+11) | `-` | | `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)` | `-` | @@ -689,6 +689,7 @@ Columns: | `HeapTexture` | A heap texture the runtime does not place (`Device::new_heap_texture` and `Device::heap_texture_size_and_align`) | every device (a public call's own check of its arguments) | `ours`: heap textures are built for Private heaps of placeable images | 2: `crates/metal2vulkan-rt/src/texture.rs (heap_fit)`, `crates/metal2vulkan-rt/src/texture.rs (new_heap_texture)` | `-` | | `BufferCopyAlignment` | `BlitCommandEncoder::copy_from_buffer` or `BlitCommandEncoder::copy_from_texture_to_buffer` whose bytes no copy command in the floor addresses,... | every device (a public call's own check of its arguments) | `ours`: Vulkan 1.3 places a copy's rows in a buffer by a count of texels from an aligned offset; each is built when a replay stream makes one | 1: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)` | `-` | | `FillAlignment` | `BlitCommandEncoder::fill_buffer` of a range that does not start and end on whole 4-byte words of the bytes shaders reach, which Metal fills byte... | every device (a public call's own check of its arguments) | `ours`: `vkCmdFillBuffer` writes whole words; a byte fill is built when a replay stream makes one | 1: `crates/metal2vulkan-rt/src/blit.rs (fill_range)` | `-` | +| `FenceOtherQueue` | A `Fence` updated or waited on by an encoder of a queue other than the first that used it | every device (a public call's own check of its arguments) | `ours`: a fence is built for one queue; the replay streams use each on one queue | 1: `crates/metal2vulkan-rt/src/fence.rs (used_on)` | `-` | | `TextureView` | `Texture::new_texture_view` of a kind Metal makes and the runtime does not build | every device (a public call's own check of its arguments) | `ours`: the replay streams' views that compute binds are same-format views of every slice, 2D views of one slice of a 2D array, and level subranges; each other kind is built when a replay stream binds one | 1: `crates/metal2vulkan-rt/src/texture.rs (new_texture_view)` | `-` | ## Appendix: every site @@ -1185,7 +1186,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/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/texture.rs (new_managed_texture)` +- `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/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)` @@ -1244,5 +1245,6 @@ Each refusal's sites, with the function that builds it. - `rt:Gap::HeapTexture`: `crates/metal2vulkan-rt/src/texture.rs (heap_fit)`; `crates/metal2vulkan-rt/src/texture.rs (new_heap_texture)` - `rt:Gap::BufferCopyAlignment`: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)` - `rt:Gap::FillAlignment`: `crates/metal2vulkan-rt/src/blit.rs (fill_range)` +- `rt:Gap::FenceOtherQueue`: `crates/metal2vulkan-rt/src/fence.rs (used_on)` - `rt:Gap::TextureView`: `crates/metal2vulkan-rt/src/texture.rs (new_texture_view)`