IOSurface vs. IOSurfaceRef on Catalyst

I have an IOSurface and I want to turn that into a CIImage. However, the constructor of CIImage takes a IOSurfaceRef instead of a IOSurface.

On most platforms, this is not an issue because the two types are toll-free bridgeable... except for Mac Catalyst, where this fails.

I observed the same back in Xcode 13 on macOS. But there I could force-cast the IOSurface to a IOSurfaceRef:

let image = CIImage(ioSurface: surface as! IOSurfaceRef)

This cast fails at runtime on Catalyst.

I found that unsafeBitCast(surface, to: IOSurfaceRef.self) actually works on Catalyst, but it feels very wrong.

Am I missing something? Why aren't the types bridgeable on Catalyst?

Also, there should ideally be an init for CIImage that takes an IOSurface instead of a ref.

This seems like a bug to me – could you please file? A small sample demonstrating the issue would help track it down quickly.

It turns out that the issue is only occurring when there is also a CIContext being initialized in the same file (it doesn’t matter where in the file).

As soon as I remove the CIContext, the compiler doesn't complain anymore about the cast to IOSurfaceRef (doesn't even need to be a force-cast), and there is also no runtime error.

IOSurface vs. IOSurfaceRef on Catalyst
 
 
Q