MTLRenderCommandEncoder in ARView postProcess

Hi, I need to render thousands of simple shapes in our AR experience. I'm using ARView to render 3D models, handling raycast, lighting etc. and I'm looking for a correct way to "inject" Metal code in to ARView.

I implemented rendering code inside ARView's renderCallbacks.postProcess:

let blitEncoder = context.commandBuffer.makeBlitCommandEncoder()
blitEncoder?.copy(from: context.sourceColorTexture, to: context.targetColorTexture)
blitEncoder?.endEncoding()

let renderDescriptor = MTLRenderPassDescriptor()
...
...
let commandEncoder = context.commandBuffer.makeRenderCommandEncoder(descriptor: renderDescriptor)!
...
...
commandEncoder.drawPrimitives(type: .triangleStrip, vertexStart: 0, vertexCount: count)
commandEncoder.endEncoding()

This solution seems to works for me but sometimes some strange things happens, like camera image reneded by blitEncoder starts to jitter or FPS drops to 20 and sametimes it just works fine.

Question 1: Is my solution correct way to draw simple shapes in ARView? Question 2: What can cause those problems during rendering?

Thanks :)

Accepted Reply

During "Metal lab" with Apple, Metal engineer told me that it is ok

Replies

During "Metal lab" with Apple, Metal engineer told me that it is ok