From a754cacc7f762345877cc2c994ca68cdb712712e Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Wed, 19 Oct 2022 00:53:30 +0200 Subject: [PATCH] mac-virtualcam: Use IOSurfaceLock on Intel-based Macs only Apple Silicon-based Macs have a unified memory architecture, as such an IOSurface will always be available in memory accessible to the CPU and GPU (and an off-load of the IOSurface will not take place). eGPUs are not supported on Apple Silicon-based Macs either, so an IOSurface lock to ensure data is copied back to CPU memory is not necessary. --- .../src/dal-plugin/OBSDALMachClient.mm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/mac-virtualcam/src/dal-plugin/OBSDALMachClient.mm b/plugins/mac-virtualcam/src/dal-plugin/OBSDALMachClient.mm index c6c0cde2a..9514eee9f 100644 --- a/plugins/mac-virtualcam/src/dal-plugin/OBSDALMachClient.mm +++ b/plugins/mac-virtualcam/src/dal-plugin/OBSDALMachClient.mm @@ -10,7 +10,6 @@ #import "Logging.h" @interface OBSDALMachClient () { - uint32_t _seed; NSPort *_receivePort; } @end @@ -123,11 +122,20 @@ return; } - IOSurfaceLock(surface, 0, &_seed); + /* + * IOSurfaceLocks are only necessary on non Apple Silicon devices, as those have + * unified memory. On Intel machines, the lock ensures that the IOSurface is copied back + * from GPU memory to CPU memory so we can process the pixel buffer. + */ +#ifndef __aarch64__ + IOSurfaceLock(surface, kIOSurfaceLockReadOnly, NULL); +#endif CVPixelBufferRef frame; CVPixelBufferCreateWithIOSurface(kCFAllocatorDefault, surface, NULL, &frame); - IOSurfaceUnlock(surface, 0, &_seed); +#ifndef __aarch64__ + IOSurfaceUnlock(surface, kIOSurfaceLockReadOnly, NULL); +#endif CFRelease(surface); uint64_t timestamp;