Metal recording - distortion/static effect in video

I'm working on a project where I'm using Metal to draw an overlay on top of live video. After getting everything up and running I'm running into issues with the output. Please see linked video for an example. This is just with drawing the CMSamplebuffer into a Metal Texture and then back into a CVPixelbuffer and writing to file. Very new to Metal in general and having a hard time narrowing down where the problem lies.

As for process, I'm rendering the sample buffer into an offscreen texture using drawPrimitives of a MTLCommandEncoder. Happy to provide more information as need.

Code Block https://youtu.be/I9ZLxuZDyS8


Had an epiphany that turned out correct. The problem is I was accessing the texture I was writing into from a separate thread. My guess is on certain frames it was accessing it in the middle of a render pass. Solved the issue by creating another texture, blitting the result of my command buffer upon completion and passing it back to the other thread.
Metal recording - distortion/static effect in video
 
 
Q