Metal: Wait for GPU on device destruction

This commit is contained in:
Corentin Wallez 2017-07-17 17:14:35 -04:00 committed by Corentin Wallez
parent 134e08005a
commit d8e1a25cbc
1 changed files with 13 additions and 0 deletions

View File

@ -26,6 +26,8 @@
#include "backend/metal/ShaderModuleMTL.h" #include "backend/metal/ShaderModuleMTL.h"
#include "backend/metal/TextureMTL.h" #include "backend/metal/TextureMTL.h"
#include <unistd.h>
namespace backend { namespace backend {
namespace metal { namespace metal {
nxtProcTable GetNonValidatingProcs(); nxtProcTable GetNonValidatingProcs();
@ -58,6 +60,17 @@ namespace metal {
} }
Device::~Device() { 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 release];
pendingCommands = nil; pendingCommands = nil;