【发布时间】:2020-02-15 11:45:24
【问题描述】:
Metal Best Practices 建议对动态数据缓冲区使用三重缓冲。但是文档中提供的清单和 Xcode 生成的默认 Metal 示例正在阻塞等待 GPU 完成工作的每一帧:
- (void)render
{
// Wait until the inflight command buffer has completed its work
dispatch_semaphore_wait(_frameBoundarySemaphore, DISPATCH_TIME_FOREVER);
// TODO: Update dynamic buffers and send them to the GPU here !
__weak dispatch_semaphore_t semaphore = _frameBoundarySemaphore;
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> commandBuffer) {
// GPU work is complete
// Signal the semaphore to start the CPU work
dispatch_semaphore_signal(semaphore);
}];
// CPU work is complete
// Commit the command buffer and start the GPU work
[commandBuffer commit];
}
那么三重缓冲是如何改进这里的呢?
【问题讨论】: