diff --git a/crates/metal2vulkan-runtime/src/command.rs b/crates/metal2vulkan-runtime/src/command.rs index 9579c5ad2..09f67860d 100644 --- a/crates/metal2vulkan-runtime/src/command.rs +++ b/crates/metal2vulkan-runtime/src/command.rs @@ -638,8 +638,9 @@ impl CommandBuffer { /// `vkQueueSubmit2`, and is not yet in flight for the completion thread. In the handler the /// command buffer's status is /// [`CommandBufferStatus::Scheduled`] and its kernel times are set, and it runs before the - /// command buffer's completed handlers. Its queue's later submissions wait while it runs, and - /// it may run while another command buffer's completed handler runs on the completion thread. + /// command buffer's completed handlers. The device has one submit thread, so its later + /// submissions, of every queue, wait while it runs, and it may run while another command + /// buffer's completed handler runs on the completion thread. /// /// A scheduled handler may read the command buffer's status and times, enqueue command /// buffers, make objects that take no upload, and do the consumer's own work. Each call that @@ -647,7 +648,8 @@ impl CommandBuffer { /// [`commit`](Self::commit), the waits, the uploads and readbacks, and the objects that take /// an upload. [`Device::quiesce`](crate::Device::quiesce) answers false in it, and a device /// whose last handle drops in it ends once the handler returns, as in a completed handler. - /// Metal runs a scheduled handler on a thread of its own, where those calls run. + /// Those calls are refused because the handler runs on the submit thread, the one they would + /// wait for. /// /// Err: [`Refusal::Committed`]. pub fn add_scheduled_handler( @@ -661,9 +663,10 @@ impl CommandBuffer { } /// `addCompletedHandler:`: runs on the completion thread once the command buffer has - /// completed or ended, after its scheduled handlers. The completion thread runs the device's - /// completed handlers and listeners in turn, so a wait in one for what that thread has not - /// yet done is [`Refusal::WaitOnOwnThread`], and one already met answers at once. + /// completed or ended, after its scheduled handlers. The device has one completion thread, + /// which runs the completed handlers and listeners of all its queues in turn, so a wait in one + /// for what that thread has not yet done is [`Refusal::WaitOnOwnThread`], and one already met + /// answers at once. /// /// Err: [`Refusal::Committed`]. pub fn add_completed_handler( @@ -843,7 +846,14 @@ impl CommandBuffer { /// 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, 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). + /// one it is called from among them). Elsewhere it waits for the command buffer's completed + /// handlers to return, as Metal's does: on an Apple M3 Max (macOS 27.0.1, job m3-max-75735), a + /// thread that held a lock across the commit and `waitUntilCompleted`, with the command + /// buffer's completed handler taking that lock, did not return within 10 s, and the same + /// program without the handler's lock ended in 15 to 69 ms. They run on the device's one + /// completion thread, which runs every queue's completed handlers and listeners in turn: a + /// handler or listener of any queue that runs before them and waits for a lock this call's + /// thread holds never lets the call return. /// /// 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. diff --git a/crates/metal2vulkan-runtime/src/device.rs b/crates/metal2vulkan-runtime/src/device.rs index 464b1b97a..125d78ad5 100644 --- a/crates/metal2vulkan-runtime/src/device.rs +++ b/crates/metal2vulkan-runtime/src/device.rs @@ -59,8 +59,12 @@ use std::time::{Duration, Instant}; /// retires the rest as the GPU completes it; the threads are joined; then every allocation is /// freed, after [`BlockMappings::unmap`] for each the consumer mapped, and the /// `VkDevice` is destroyed; every gauge reads zero only then. A last handle dropped on the -/// consumer's thread tears the device down in that drop. Where the last handle drops in a handler -/// or a listener, the reaper runs the teardown once the handler returns, and the consumer calls +/// consumer's thread tears the device down in that drop, and so the drop waits, with no deadline, +/// for every scheduled and completed handler of a command buffer still to retire, every listener +/// whose value is reached before the threads end, and every [`BlockMappings`] hook or import +/// release the block-maker thread runs, to return: a handler, listener or hook that waits for a +/// lock the dropping thread holds never lets the drop return. Where the last handle drops in a +/// handler or a listener, the reaper runs the teardown once the handler returns, and the consumer calls /// [`Instance::wait_until_devices_torn_down`](crate::Instance::wait_until_devices_torn_down) /// before it drops its instance or exits. Nothing relies on a static destructor or an `atexit` /// handler: the consumer drops every handle before the process exits, or, where a handle is still