Support for Apple VisionOS ?

113 views
Skip to first unread message

Guillaume Chéreau

unread,
Aug 2, 2023, 11:35:40 AM8/2/23
to angleproject
Hello all,

I am wondering if there is a way to compile ANGLE for Apple VisionOS, for use on the Vision Pro Headset.  Do you think this is possible?

Regards,
G

Ken Russell

unread,
Aug 7, 2023, 9:02:33 PM8/7/23
to guillaum...@gmail.com, angleproject
Hi Guillaume,

It probably is possible - https://github.com/WebKit/WebKit is probably compiling its copy of Source/ThirdParty/ANGLE for VIsionOS - but you might be the first person on this mailing list to try. Let us know or file a bug if you run into any problems with ANGLE's Metal backend on VisionOS.

-Ken

 

--
You received this message because you are subscribed to the Google Groups "angleproject" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angleproject...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angleproject/ed5f407a-6e1f-46a6-8fb3-9a5c02563e1cn%40googlegroups.com.

Linfeng Li

unread,
Aug 8, 2023, 11:48:49 PM8/8/23
to angleproject
Yes it is possible to build angle for visionOS. I modified chromium/build so that it can add correct flags to build for visionOS simulator and it works for me (it will go through the iOS code path and I believe some version checks would need to be updated in code). And then use EGL APIs to get the EGLImage from the Metal drawable provided by CompositorServices to create OpenGL texture to render to.

Simulator Screenshot - Apple Vision Pro - 2023-08-09 at 11.40.19.png

Guillaume Chéreau

unread,
Aug 9, 2023, 5:54:13 AM8/9/23
to angleproject
Good to know!

I assume the simplest way to go about it would be to include all the needed ANGLE files directly in the project and compile it all as one unit?

Is there a sample code somewhere, (if possible something simpler than webkit), with some pointers about how to retrieve the EGLImage from a Metal drawable?

Regards,
-G

Linfeng Li

unread,
Aug 9, 2023, 10:11:55 AM8/9/23
to angleproject
You would need to know what files are included and the compiler flags Google's or WebKit's ANGLE uses, simply putting everything together under a Xcode project won't just work.

I forgot to ask if you want to use CompositorServices (full immersive app) or CALayer/CAMetalLayer (windowed app) in my last reply, but if you go for CALayer/CAMetalLayer it would be the same as on iOS

For CompositorService
1. you use `cp_drawable_get_color_texture` and `cp_drawable_get_depth_texture` (you would find it in Apple's sample code for using CompositorServices for building immersive apps) to get Metal textures
2. you call eglCreateImage to create EGLImage with the textures
3. With EGLImage you can get OpenGL textures with glEGLImageTargetTexture2DOES.
4. Create framebuffer with the textures as render targets
5. With the framebuffer bound you can make your OpenGL calls to draw

Guillaume Chéreau

unread,
Aug 9, 2023, 12:45:26 PM8/9/23
to angleproject
You would need to know what files are included and the compiler flags Google's or WebKit's ANGLE uses, simply putting everything together under a Xcode project won't just work.
Right, I'll check WebKit code a bit to see if I can figure out how they compile it.
 
I forgot to ask if you want to use CompositorServices (full immersive app) or CALayer/CAMetalLayer (windowed app) in my last reply
That would be a full immersive app.  For the moment I am just trying to figure out if using ANGLE makes sense or if I should bite the bullet and port the existing code to Metal.  Thanks a lot for the explanations about how to get the EGLImage from a cp_drawable_t, this was my main worry about this.  I'll try to see if I can make a proof of concept and I'll keep you posted.

Best regards,
-G

Guillaume Chéreau

unread,
Aug 24, 2023, 6:32:41 AM8/24/23
to angleproject
Thanks to your advices I was able to make it work more or less, using eglCreateImage and glEGLImageTargetTexture2DOES.

One thing I am not so sure about now is how to properly synchronize the ANGLE internal Metal command buffer with the one used by the headset.  It seems that the current Metal implementation in ANGLE does not have the GL_EXT_semaphore extension, so I cannot use that.  Does anybody know a workaround?  My code currently looks like this:

```
// 1. Create FBO from the passed cp_drawable_t:
color_texture = cp_drawable_get_color_texture(drawable, eye);
egl_image = eglCreateImage(
                egl_display, EGL_NO_CONTEXT, EGL_METAL_TEXTURE_ANGLE,
                color_texture, NULL);
glGenTextures(1, &gl_tex);
glBindTexture(GL_TEXTURE_2D, gl_tex);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, egl_image);
glGenFramebuffers(1, &gl_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, gl_fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                               GL_TEXTURE_2D, gl_tex, 0);

// 2. Do the OpenGL rendering
...

// 3. Delete used textures and fbo
glDeleteFramebuffers(1, &gl_fbo);
glDeleteTextures(1, &gl_tex);

// 4. Present and encode an empty command buffer to the drawable.
id<MTLCommandBuffer> command_buffer;
command_buffer = [engine->command_queue commandBuffer];
cp_drawable_encode_present(drawable, command_buffer);
[command_buffer commit];
```

The screen seems flicker from time to time, which I think comes from metal not properly waiting for ANGLE to finish before swapping the target buffer.

Regards,
G



Geoff Lang

unread,
Aug 24, 2023, 11:24:10 AM8/24/23
to guillaum...@gmail.com, angleproject
To make sure an IOSurface is synchronized before handing it off to the compositor or another Metal device, you need to wait until ANGLE's command buffers have been scheduled. We have an extension for that EGL_ANGLE_wait_until_work_scheduled. Just flush and call eglWaitUntilWorkScheduledANGLE before passing the IOSurface off to whatever consumes it.

We also have EGL_ANGLE_metal_shared_event_sync which allows using MTLSharedEvents to synchronize with other Metal devices.

--
You received this message because you are subscribed to the Google Groups "angleproject" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angleproject...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages