Was told that all metal command buffers should be committed on the main thread.
How would I go about handling parallel command execution and triple buffering of data if it could block the main thread (and we can't have it block the main thread)?
How could I adapt the code below?
How would I go about handling parallel command execution and triple buffering of data if it could block the main thread (and we can't have it block the main thread)?
How could I adapt the code below?
Code Block Swift _ = semaphore.wait(timeout: DispatchTime.distantFuture) autoreleasepool { let commandBuffer = commandQueue.makeCommandBuffer() let dispatchGroup = DispatchGroup() do { /* repeat this block for every render pass needed */ dispatchGroup.enter() metalQueue.async { /* perform render commands */ if commandBuffer == finalScreenBuffer { commandBuffer.addCompletedHandler { _ in semaphore.signal() } } commandBuffer.commit dispatchGroup.leave() } } _ = dispatchGroup.wait(timeout: DispatchTime.distantFuture) commandBuffer.waitUntilScheduled() /* view is an MTKView with presentsWithTransaction set to true */ view.currentDrawable.present() } bufferIndex = (bufferIndex + 1) % 3