在单个MTLRenderCommandEncoder中使用多个渲染管道:如何同步MTLBuffer? [英] Using multiple render pipelines in a single MTLRenderCommandEncoder: How to Synchronize MTLBuffer?

查看:385
本文介绍了在单个MTLRenderCommandEncoder中使用多个渲染管道:如何同步MTLBuffer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Central Issue
I have two render pipelines in one single render command encoder. The first pipeline writes to a buffer which is used in the second pipeline. This does not seem to work and I expect it to be a synchronization problem. When I use one separate render command encoder for each render pipeline I get the desired result. Can this be solved with one single render command encoder or do I need two separate encoders to synchronize the buffer?

以下是更具体的情况:
第一个管道是非光栅化管道,仅运行顶点着色器以输出到存储MTLDrawPrimitivesIndirectArgumentsMTLBuffer,用于第二个管道的drawPrimitives调用,如下所示:

Here is the more specific case:
The first pipeline is a non-rasterizing pipeline only running a vertex shader to output to a MTLBuffer storing MTLDrawPrimitivesIndirectArguments to use for the drawPrimitives call for the second pipeline, which looks like this:

// 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?

How can I make sure that the indirectArgumentsBuffer has been written to by the first pipeline when issuing a call to drawPrimitives for the second pipeline, which uses and needs the contents of indirectArgumentsBuffer?

推荐答案

我相信您需要使用单独的编码器.在此版本中(有点过时) -DontLinkElementID_74"rel =" nofollow noreferrer>有关函数写入的文档,只有原子操作会为绘制调用之间共享的缓冲区进行同步.

I believe you need to use separate encoders. In this (somewhat dated) documentation about function writes, only atomic operations are synchronized for buffers shared between draw calls.

这篇关于在单个MTLRenderCommandEncoder中使用多个渲染管道:如何同步MTLBuffer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆