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?

Post not yet marked as solved Up vote post of jahaskell53 Down vote post of jahaskell53
746 views

Replies

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.

  • Thanks for your response Matt. This is really helpful, and I have been able to find repositories that have already integrated Metal with visionOS, which I am modifying now. Thanks again!

  • Currently working on adding hand tracking support for the application using ARKit (right now just trying to print out hand coordinates), but I'm not sure how to simulate hand tracking on the visionOS simulator. Do you know if this is possible yet?

  • It's not I'm afraid.

Add a Comment

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

  • So, there's no way to render in 3D using Metal "inside of" (popping out of) a SwiftUI layout in a WindowGroup? (Is RealityView the only way to accomplish the 3d popup book effect?)

  • Hello @EthanLS , that is correct, please file an enhancement request for this functionality using Feedback Assistant.

Add a Comment

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.

Add a Comment