I\'m recording the screen from my iPhone device to my Mac. As a preview layer I am collecting sample buffers directly from a AVCaptureVideoDataOutput, from whic
Another way to get from a CVPixelBufferRef to MetalTexture, you could go via a CIImage and use a CIContext with a Metal device (hopefully minimises getting the CPU involved with copying the pixel buffer);
Make sure your target metal texture is appropriately sized.
CIContext* ciContext = [CIContext contextWithMTLDevice:mtlDevice
options:[NSDictionary dictionaryWithObjectsAndKeys:@(NO),kCIContextUseSoftwareRenderer,nil]
];
id metalCommandBuffer=[mtlCommandQueue commandBufferWithUnretainedReferences];
CIImage* ciImage = [[CIImage alloc] initWithCVPixelBuffer:cvPixelBuffer];
[ciContext render:ciImage
toMTLTexture:metal_texture
commandBuffer:mtlCommandBuffer
bounds:[ciImage extent])
colorSpace:[ciImage colorSpace]];