How to use fence for indirect draws?

Hi, I met a problem about fences. My render steps are like the following:

[ComputeEncoder]

  1. Generate indirect buffer B.
  2. updateFence F.

[RenderEncoder]

  1. waitForFence F. // which stage?
  2. drawPrimitives with indirect buffer B.

But to call waitForFence I need to pass beforeStages, the only choices for this param are MTLRenderStageVertex orMTLRenderStageFragment. There is no stage for indirect draw like vulkan's VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT.

I tried to use MTLRenderStageVertex but it didn't work. What is the correct way to wait for a fence in this scenario?

Thanks.

Also notice that the indirect buffer B is created from a MTLHeap, so the automatic resource tracking is disabled, I have to sync manually using MTLFences.

Hi atyuwen, you seem to be approaching this in the correct way. Metal doesn't have an explicit stage for indirect-command-buffer consumption like Vulkan does. That said, waiting before MTLRenderStageVertex will indeed wait before ICB consumption.

As long as your encoders are committed to the same MTLCommandQueue, and they are in the correct, sequential order, then what you are doing should work. I would double-check if your usage of the fence F is correct.

How to use fence for indirect draws?
 
 
Q