objective-c - 在单个 MTLRenderCommandEncoder : How to Synchronize MTLBuffer? 中使用多个渲染管道

标签 objective-c swift metal

中心刊
我在一个渲染命令编码器中有两个渲染管道。第一个管道写入在第二个管道中使用的缓冲区。这似乎不起作用,我希望这是一个同步问题。当我为每个渲染管道使用一个单独的渲染命令编码器时,我得到了想要的结果。这可以用一个单一的渲染命令编码器来解决,还是我需要两个单独的编码器来同步缓冲区?

这是更具体的案例:
第一个管道是非光栅化管道,仅运行顶点着色器以输出到 MTLBuffer收纳MTLDrawPrimitivesIndirectArguments用于 drawPrimitives调用第二个管道,如下所示:

// renderCommandEncoder is MTLRenderCommandEncoder
// firstPipelineState and secondPipelineState are two different MTLRenderPipelineState
// indirectArgumentsBuffer is a MTLBuffer containing MTLDrawPrimitivesIndirectArguments
// numberOfVertices is number of vertices suited for first pipeline

// first pipeline
renderCommandEncoder.setRenderPipelineState(firstPipelineState)
renderCommandEncoder.setVertexBuffer(indirectArgumentsBuffer, offset: 0, index: 0)
renderCommandEncoder.drawPrimitives(type: .point, vertexStart: 0, vertexCount: numberOfVertices)

// second pipeline
renderCommandEncoder.setRenderPipelineState(secondPipelineState)
renderCommandEncoder.setVertexBuffer(secondPipelineBuffer, offset: 0, index: 0)
renderCommandEncoder.drawPrimitives(type: .point, indirectBuffer: indirectArgumentsBuffer, indirectBufferOffset: 0)

renderCommandEncoder.endEncoding()

我如何确保 indirectArgumentsBuffer在发出对 drawPrimitives 的调用时已被第一个管道写入对于第二个管道,它使用并需要 indirectArgumentsBuffer 的内容?

最佳答案

我相信您需要使用单独的编码器。在这个(有点过时)documentation about function writes ,对于绘制调用之间共享的缓冲区,只有原子操作是同步的。

关于objective-c - 在单个 MTLRenderCommandEncoder : How to Synchronize MTLBuffer? 中使用多个渲染管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60063522/

相关文章:

ios - 找不到 Metal iOS 的资源

objective-c - 以编程方式编辑 SQLite 数据库中的数据

objective-c - 可变数组中的 NSNumber=0

swift - 用户类设计

ios - 如何在方向更改时正确处理 UICollectionViewLayout 的 itemSize

ios - 如何在具有相同Apple ID的多个设备的用户中找出 "Sign in with Apple"?

ios - UILabel 根据要显示的文本自动调整大小

ios - 在 ScrollView 上使用 UIDynamicAnimator?

ios - 使用 Metal 在 iOS 中扭曲 View

graphics - 什么是 Metal 中的 colorAttachment[n]?