简体   繁体   English

iOS上的Metal:何时读取visibleResultBuffer?

[英]Metal on iOS: when to read visibilityResultBuffer?

According to Apple's documentation we can monitor samples that pass the depth and stencil tests with setVisibilityResultMode . 根据Apple的文档,我们可以使用setVisibilityResultMode监视通过深度和模板测试的样本。 The result will be written into visibilityResultBuffer . 结果将被写入visibilityResultBuffer However, I can't find any documentation about when I can access the visibilityResultBuffer to read the result. 但是,我找不到任何有关何时可以访问visibilityResultBuffer读取结果的文档。 Is there any callback that can notify me the result is ready? 是否有任何回调可以通知我结果已准备好? Where can I find more detailed documentation or example about metal's visibilityResultMode ? 在哪里可以找到有关金属的visibilityResultMode更详细的文档或示例?

It's safe to read visibility results on the CPU once the command buffer containing the draw calls you're testing for visibility completes. 一旦包含要测试可见性的绘制调用的命令缓冲区完成,就可以安全地读取CPU上的可见性结果。 You can add a completed handler block to the command buffer to get notified of this: 您可以将完整的处理程序块添加到命令缓冲区中,以获取有关以下内容的通知:

commandBuffer.addCompletedHandler { completedCommandBuffer in
    self.consumeVisibilityResults()
}

Remember to call addCompletedHandler(:) before you call commit on your command buffer. 在对命令缓冲区调用commit之前,请记住先调用addCompletedHandler(:)

Note that this handler will be called asynchronously, after the drawing for your current frame is done, so you won't be able to use the visibility results of one frame in that same frame. 请注意,在完成当前帧的绘制后,将异步调用此处理程序,因此您将无法使用同一帧中一帧的可见性结果。 For this reason, occlusion query-based visibility often has a frame or two of lag. 因此,基于遮挡查询的可见性通常具有一两个延迟帧。 You can read a good overview of this and related issues here . 您可以在此处阅读有关此问题和相关问题的完整概述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM