Looking at the code provided by Apple for triple buffering of Metal buffer and texture resources, it seems very strange that the use of a semaphore could block the main thread in code like the following. This is from CPU and GPU Synchronization.
- (void)drawInMTKView:(nonnull MTKView *)view
{
dispatch_semaphore_t inFlightSemaphore = self.inFlightSemaphore;
dispatch_semaphore_wait(inFlightSemaphore, DISPATCH_TIME_FOREVER);
id <MTLCommandBuffer> commandBuffer = [mrc.commandQueue commandBuffer];
__block dispatch_semaphore_t block_sema = inFlightSemaphore;
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> buffer)
{
dispatch_semaphore_signal(block_sema);
}];
// Metal render commands
}
How would invoking dispatch_semaphore_wait() not block the main thread in a call to drawInMTKView?