diff --git a/crates/metal2vulkan-conformance/known-gaps-rt.tsv b/crates/metal2vulkan-conformance/known-gaps-rt.tsv index 4179b523e..ec994d84f 100644 --- a/crates/metal2vulkan-conformance/known-gaps-rt.tsv +++ b/crates/metal2vulkan-conformance/known-gaps-rt.tsv @@ -75,6 +75,7 @@ command-buffer-facts * refused case/facts/queue-label-is-its-own/0 Err(TheConsum command-buffer-facts * refused case/facts/queue-label-is-its-own/1 Err(TheConsumers("a queue's label and a command buffer's device and commandQueue never reach the GPU: metal2vulkan-rt leaves them to its consumer")) The consumer's, not a gap: a queue's label and a command buffer's `device` and `commandQueue` are the consumer's own objects and never reach the GPU, so metal2vulkan-rt holds none of them and its consumer answers them from its own. command-buffer-facts * refused case/facts/resource-state-encoder-opened Err(Unavailable({call: "resource_state_command_encoder"})) A typed refusal, as the sparse family's: metal2vulkan-rt has no resource-state command encoder (`resourceStateCommandEncoder`), which maps sparse textures alone. It waits on a replay stream that uses one. format-footprints-plain-stragglers * refused case/MTLPixelFormatBGRA4Unorm/CubeArray/64x64x1/levels-1/samples-1/slices-2/usage-0x1/shared/size-and-align Err(Error::Unsupported("cube array textures are not built")) refused: no stream uses it yet (cube census m3-max-48683/48687/48688/48720: ten streams, no cube array texture or view). A cube array texture, which no replay stream makes or views. +handler-waits-completed-until-completed * divergent case/addCompletedHandler/waitUntilCompleted Metal did not return from this call, and we answered it: Ok An accepted difference: Apple documents waitUntilCompleted as "Blocks the current thread until the GPU finishes executing the command buffer and all of its completion handlers." Called from the command buffer's own completed handler, Metal never returns; rt answers at once because the buffer is complete. heap-sizes-formats-without-textures * refused case/MTLPixelFormatAnyDepth/CubeArray/64x64x1/levels-1/samples-1/slices-2/usage-0x1/private/makes-texture Err(Error::Unsupported("cube array textures are not built")) refused: no stream uses it yet (cube census m3-max-48683/48687/48688/48720: ten streams, no cube array texture or view). A cube array texture, which no replay stream makes or views. heap-sizes-formats-without-textures * refused case/MTLPixelFormatAnyDepth/CubeArray/64x64x1/levels-1/samples-1/slices-2/usage-0x1/private/size-and-align Err(Error::Unsupported("cube array textures are not built")) refused: no stream uses it yet (cube census m3-max-48683/48687/48688/48720: ten streams, no cube array texture or view). A cube array texture, which no replay stream makes or views. heap-sizes-formats-without-textures * refused case/MTLPixelFormatAnyDepth/CubeArray/64x64x1/levels-1/samples-1/slices-2/usage-0x1/shared/makes-texture Err(Error::Unsupported("cube array textures are not built")) refused: no stream uses it yet (cube census m3-max-48683/48687/48688/48720: ten streams, no cube array texture or view). A cube array texture, which no replay stream makes or views. diff --git a/crates/metal2vulkan-conformance/src/rt_side.rs b/crates/metal2vulkan-conformance/src/rt_side.rs index 32d6dd19f..2ff6b5737 100644 --- a/crates/metal2vulkan-conformance/src/rt_side.rs +++ b/crates/metal2vulkan-conformance/src/rt_side.rs @@ -53,6 +53,9 @@ const WAIT: Duration = Duration::from_secs(60); /// The bytes the command-buffer facts' one blit fills, as the other sides fill. const TIMED_BYTES: usize = 256; +/// The bytes the command buffer of a handler's own wait fills, as the old runtime's side fills. +const HANDLER_FILL: usize = 64; + /// Why the command-buffer facts' queue label and getters are not this side's to answer. const THE_CONSUMERS: &str = "a queue's label and a command buffer's device and commandQueue \ never reach the GPU: metal2vulkan-rt leaves them to its consumer"; @@ -1277,6 +1280,47 @@ impl Side for RtSide<'_> { .without_resource_state_encoder(Failure::unavailable("resource_state_command_encoder"))) } + /// A wait made from a command buffer's own handler, as the old runtime's side makes it: a + /// command buffer with one small fill, whose handler `wait.from` names makes the wait + /// `wait.wait` names on that same command buffer, and sends back what the wait answered. Both + /// waits here are bounded, so a wait the runtime neither refused nor returned from is recorded + /// as never returning instead of hanging the suite: the handler would still be inside it and + /// the command buffer would never complete. + fn handler_wait(&mut self, wait: crate::handler_waits::OwnWait) -> Answer { + use crate::handler_waits::{HandlerKind, WaitKind}; + let of_rt = |error: rt::Error| Failure::of_rt(&error); + let filled = self.buffer(&[0u8; HANDLER_FILL])?; + let target = self.held(filled)?.clone(); + let queue = self.queue()?.clone(); + let command_buffer = queue.command_buffer().map_err(of_rt)?; + let mut blit = command_buffer.blit_command_encoder().map_err(of_rt)?; + (blit.fill_buffer(&target, 0..HANDLER_FILL as u64, 0x11)).map_err(of_rt)?; + blit.end_encoding(); + let (sender, answer) = mpsc::channel(); + let kind = wait.wait; + let handler = move |own: &rt::CommandBuffer| { + let answered = match kind { + WaitKind::UntilCompleted => own.wait_until_completed(), + WaitKind::UntilScheduled => own.wait_until_scheduled(), + }; + let _ = sender.send(answered.err().map(|error| Failure::of_rt(&error))); + }; + match wait.from { + HandlerKind::Scheduled => command_buffer.add_scheduled_handler(handler), + HandlerKind::Completed => command_buffer.add_completed_handler(handler), + } + .map_err(of_rt)?; + command_buffer.commit().map_err(of_rt)?; + if waited_for(&command_buffer, WAIT).is_none() { + return Ok(Value::Nothing(Negative::NeverReturned)); + } + match answer.recv_timeout(WAIT) { + Ok(None) => Ok(Value::ok(Value::Absent)), + Ok(Some(failure)) => Err(failure), + Err(_) => Ok(Value::Nothing(Negative::NeverReturned)), + } + } + fn empty_command_buffers(&mut self) -> Answer { let of_rt = |error: rt::Error| Failure::of_rt(&error); let order: Arc>> = Arc::default(); diff --git a/crates/metal2vulkan-rt/src/command.rs b/crates/metal2vulkan-rt/src/command.rs index 6f38abbe4..6550efade 100644 --- a/crates/metal2vulkan-rt/src/command.rs +++ b/crates/metal2vulkan-rt/src/command.rs @@ -570,7 +570,9 @@ impl CommandBuffer { /// handlers have run. A command buffer held in a group goes at once, as /// [`CommandQueue::send_now`](crate::CommandQueue::send_now) sends it. In a completed handler /// or a listener of its device, on the completion thread, which runs the handlers: at once - /// for one completed or ended, its own handler's command buffer among them. + /// for one completed or ended, its own handler's command buffer among them, where Metal's + /// call never returns (Metal's wait is for the command buffer's completion handlers too, the + /// one it is called from among them). /// /// Err: [`Refusal::InScheduledHandler`] in a scheduled handler; [`Refusal::WaitOnOwnThread`] /// in a completed handler or a listener of its device for one not yet completed or ended.