From 8954df63ef7cb056935bcfd59b0171340c146db0 Mon Sep 17 00:00:00 2001 From: Jason Fielder Date: Mon, 3 Apr 2023 08:53:42 +0200 Subject: [PATCH] Fix #106431: Resolve Metal workload dependency Splitting workload dependency chains such that they only exist within the context of a single frame. Dependencies are required to ensure sequential command buffer submissions execute in order, but the additional dependencies between frames could incur GPU timeouts, if a signal was delayed. This could be triggered by both CPU/GPU cycles texture updates and Viewport Compositor operations. Should also resolve #106401 Authored by Apple: Michael Parkin-White Pull Request: https://projects.blender.org/blender/blender/pulls/106443 --- source/blender/gpu/metal/mtl_context.mm | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/source/blender/gpu/metal/mtl_context.mm b/source/blender/gpu/metal/mtl_context.mm index 8b7f4539a71..63f8aaa50f4 100644 --- a/source/blender/gpu/metal/mtl_context.mm +++ b/source/blender/gpu/metal/mtl_context.mm @@ -2138,9 +2138,13 @@ void present(MTLRenderPassDescriptor *blit_descriptor, MTLCommandBufferManager::num_active_cmd_bufs++; if (MTLCommandBufferManager::sync_event != nil) { - /* Ensure command buffer ordering. */ - [cmdbuf encodeWaitForEvent:MTLCommandBufferManager::sync_event - value:MTLCommandBufferManager::event_signal_val]; + /* Release synchronization primitive for current frame to avoid cross-frame dependencies. + * We require MTLEvents to ensure correct ordering of workload submissions within a frame, + * however, we should not create long chains of dependencies spanning several drawables as any + * temporary stalls can then trigger erroneous GPU timeouts in non-dependent submsisions. */ + [MTLCommandBufferManager::sync_event release]; + MTLCommandBufferManager::sync_event = nil; + MTLCommandBufferManager::event_signal_val = 0; } /* Do Present Call and final Blit to MTLDrawable. */ @@ -2192,17 +2196,6 @@ void present(MTLRenderPassDescriptor *blit_descriptor, perf_max_drawables); }]; - if (MTLCommandBufferManager::sync_event == nil) { - MTLCommandBufferManager::sync_event = [ctx->device newEvent]; - BLI_assert(MTLCommandBufferManager::sync_event); - [MTLCommandBufferManager::sync_event retain]; - } - BLI_assert(MTLCommandBufferManager::sync_event != nil); - - MTLCommandBufferManager::event_signal_val++; - [cmdbuf encodeSignalEvent:MTLCommandBufferManager::sync_event - value:MTLCommandBufferManager::event_signal_val]; - [cmdbuf commit]; /* When debugging, fetch advanced command buffer errors. */