From f5d4397e5c4f6b644e0dbae453605fc68e46327d Mon Sep 17 00:00:00 2001 From: Awni Hannun Date: Wed, 8 Oct 2025 11:23:46 -0700 Subject: [PATCH] Fix fast synch when fence is waited before a command buffer is created (#2657) --- mlx/backend/metal/device.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mlx/backend/metal/device.cpp b/mlx/backend/metal/device.cpp index 352958a89..5f2bb73d3 100644 --- a/mlx/backend/metal/device.cpp +++ b/mlx/backend/metal/device.cpp @@ -471,6 +471,10 @@ void Device::end_encoding(int index) { CommandEncoder& Device::get_command_encoder(int index) { auto& stream = get_stream_(index); if (stream.encoder == nullptr) { + // Ensure there is an active command buffer + if (stream.buffer == nullptr) { + get_command_buffer(index); + } stream.encoder = std::make_unique(stream); stream.fence = std::make_shared(device_->newFence()); }