Metal API on visionOS?

Is it possible to use the Metal API on vision Pro? I noticed that using MTKView in my visionOS app is not recognized, and also noticed other forum posts from months ago saying that MTKView is not yet supported. If it is still not an option, if and when will it be supported? Also wondering about metal-cpp support as well, since my app involves integrating an existing C++ library with visionOS (see here: https://github.com/MinVR/MinVR). Is this possible?

The Metal API and metal-cpp are supported, however with some significant caveats:

  • Metal can only be used for writing fully immersive applications. In short, applications that take over all drawing, and do not exist in the mixed space or overlayed on to the real world. This can be useful for games or full experiences.
  • MTKView is not supported for immersive applications. Instead you must use the CompositorServices API and CompositorLayer view type to perform custom drawing using your render loop.
  • There are additional steps needed that are unique to visionOS, such as foveated rendering, head tracking...etc. Some of these are non-trivial, which can make adoption difficult.
  • VisionOS is less forgiving about maintaining frame rates. If you don't update, draw and present your frames quickly enough you will drop frames, and provide a poor experience for users.

I'd recommend starting with this video from WWDC '23, as it provides a good overview of what needs to be done: https://developer.apple.com/wwdc23/10089.

In the context of an ImmersiveSpace, I agree with much of Matt's post (thanks Matt!).

Having said that, there is an opportunity to clarify a couple of things here:

Is it possible to use the Metal API on vision Pro?

Yes, regardless of the SwiftUI.Scene type presented, you can use Metal API to render on visionOS.

  • If you want to render an ImmersiveSpace entirely with Metal, use CompositorServices for presentation.
  • If you want to render to a flat view in a window entirely with Metal, use CAMetalLayer for presentation.

MTKView is not supported for immersive applications.

MTKView is not available on visionOS in any context, as mentioned above, if you want to render to a flat view in a window entirely with Metal, use CAMetalLayer for presentation. Though it does not have a visionOS target, this sample project is highly relevant for creating a CAMetalLayer backed view: Creating a Custom Metal View

I think it would be great for a future OS version to find a way to extend Metal custom renderers to passthrough mode. Specifically the mode with one application — not shared space — for simplicity and sandboxing from other apps. This would allow for many shader effects that are impossible with just surface shaders. Note—without asking for access to the camera. Just some way to take advantage of occlusion and seeing the real world automatically. I imagine you’d need to disable pixel readback or opaquely insert the privacy-restricted textures.

Metal API on visionOS?
 
 
Q