Multithreading w/CVMetalTextureCacheCreateTextureFromImage

In my MTKView render loop, I'm implementing a triple-buffering scheme which transitions between two videos (so, dual triple-buffering). This is done with a dispatch_semaphore_create(3);
As the CVPixelBuffer frames are arriving from my pair of AVPlayers, I convert them to MTLTextures with CVMetalTextureCacheCreateTextureFromImage.


I'm currently including the underlying CVMetalTextureCacheRef cache to the transitional buffers. So, there are 6 such caches that i rotate through.


Is this necessary? Overkill?


Is a call to CVMetalTextureCacheCreateTextureFromImage thread-safe? If not, a thought I had was to enclose the call to itin a dispatch_sync handler and grab the resulting texture, and have only one such cache on the MTKView.

I generally use just a single metal cache object and always grab the textures from the cache on the video reading thread. The images have a lifetime of 1 second by default (I think), so if you're holding on to the texture for less than that, you should be OK.

Thanks. I've implemented only one cache on the view, rather than stringing along rotating caches.

Multithreading w/CVMetalTextureCacheCreateTextureFromImage
 
 
Q