From d8e1a25cbc940da4137bba429f22fd4c82ce2573 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 17 Jul 2017 17:14:35 -0400 Subject: [PATCH] Metal: Wait for GPU on device destruction --- src/backend/metal/MetalBackend.mm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/backend/metal/MetalBackend.mm b/src/backend/metal/MetalBackend.mm index e6f6eda207..ac4f1ffd2f 100644 --- a/src/backend/metal/MetalBackend.mm +++ b/src/backend/metal/MetalBackend.mm @@ -26,6 +26,8 @@ #include "backend/metal/ShaderModuleMTL.h" #include "backend/metal/TextureMTL.h" +#include + namespace backend { namespace metal { nxtProcTable GetNonValidatingProcs(); @@ -58,6 +60,17 @@ namespace metal { } Device::~Device() { + // Wait for all commands to be finished so we can free resources + // SubmitPendingCommandBuffer may not increment the pendingCommandSerial if there + // are no pending commands, so we can't store the pendingSerial before + // SubmitPendingCommandBuffer then wait for it to be passed. Instead we submit and + // wait for the serial before the next pendingCommandSerial. + SubmitPendingCommandBuffer(); + while (finishedCommandSerial != pendingCommandSerial - 1) { + usleep(100); + } + Tick(); + [pendingCommands release]; pendingCommands = nil;