Page MenuHome

enable X11-EGL context for OpenXR
ClosedPublic

Authored by Christian Rauch (christian.rauch) on Jun 17 2021, 12:00 AM.

Details

Summary

Previously, the OpenXR support would assume a GLX context on X11. Hence, building with WITH_XR_OPENXR and WITH_GL_EGL (e.g. make ninja lite BUILD_CMAKE_ARGS="-DWITH_GL_EGL=ON -DWITH_XR_OPENXR=ON") would fail.

This patch adds support for X11-EGL contexts via XrGraphicsBindingEGLMNDX. Since I don't own a VR or AR device, I cannot test this myself. At least, this removes build errors when EGL is enabled.

Diff Detail

Repository
rB Blender
Branch
x11_egl
Build Status
Buildable 15345
Build 15345: arc lint + arc unit

Event Timeline

Christian Rauch (christian.rauch) created this revision.
intern/ghost/intern/GHOST_IXrGraphicsBinding.h
33–39

Simpler:

#if defined(WITH_GL_EGL)
    XrGraphicsBindingOpenGLXlibKHR glx;
#elif defined(WITH_GHOST_X11)
    XrGraphicsBindingEGLMNDX egl;
intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
34–36

Don't include things that are not needed:

#if defined(WITH_GL_EGL)
#  include "GHOST_ContextEGL.h"
#elif defined(WITH_GHOST_X11)
#  include "GHOST_ContextGLX.h"
#elif defined(WIN32)
...
112–122

Consistency with other conditions:

#if defined(WITH_GL_EGL)
...
#elif defined(WITH_GHOST_X11)
...
117

I think that & should be left out?

From what I can tell it expects a function pointer, not a pointer to a function pointer.

It's a bit confusing since this is a function pointer to a function that returns a function pointer.

120

This seems to be missing oxr_binding.egl.next = NULL.

It's missing also for other platforms which may mean it's zero initialized elsewhere. But I couldn't find that.

intern/ghost/intern/GHOST_Xr_openxr_includes.h
45–51

Don't include this if EGL is used.

Maybe some package will even leave it out when GLEW is compiled for EGL.

55

It's not clear to me which problem this fixes, is this still needed?

Christian Rauch (christian.rauch) marked 6 inline comments as done.

enable extensions

Christian Rauch (christian.rauch) marked an inline comment as done.

header include fix

With the Monado runtime (https://monado.freedesktop.org/getting-started.html#deb) I now get as far as where the OpenGL and OpenXR extensions are checked.

On my setup, this eventually fails with:

 INFO [xrt_gfx_provider_create_gl_egl] Extension availability:
 INFO [xrt_gfx_provider_create_gl_egl]   - GL_EXT_memory_object: false
 INFO [xrt_gfx_provider_create_gl_egl]   - GL_EXT_memory_object_fd: false
 INFO [xrt_gfx_provider_create_gl_egl]   - GL_EXT_memory_object_win32: false
 INFO [xrt_gfx_provider_create_gl_egl]   - GL_OES_EGL_image_external: false
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_ANDROID_get_native_client_buffer: false
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_ANDROID_native_fence_sync: true
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_EXT_image_dma_buf_import_modifiers: true
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_KHR_fence_sync: true
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_KHR_image: true
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_KHR_image_base: true
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_KHR_reusable_sync: true
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_KHR_wait_sync: true
 INFO [xrt_gfx_provider_create_gl_egl] Using EGL_Image swapchain implementation
ERROR [client_gl_eglimage_swapchain_create] eglCreateImageKHR failed
XR_ERROR_RUNTIME_FAILURE in xrCreateSwapchain: Failed to create swapchain
Error: 	Failed to create OpenXR swapchain.
	OpenXR error value: -2

With GLX, this fails with:

ERROR [client_gl_xlib_compositor_create] client_gl_xlib_compositor_create - Required OpenGL extension GL_EXT_memory_object not available
XR_ERROR_INITIALIZATION_FAILED in xrCreateSession: Failed to create an xlib client compositor
Error: 	Failed to create VR session. The OpenXR runtime may have additional requirements for the graphics driver that are not met. Other causes are possible too however.
Tip: The --debug-xr command line option for Blender might allow the runtime to output detailed error information to the command line.
	OpenXR error value: -6

For now, I assume that the missing extension GL_EXT_memory_object is also the reason that the EGL swapchain cannot be created.

If anybody has a working VR setup with X11-GLX, I would appreciate s/he could also test this with X11-EGL.

intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
112–122

I think the #if defined(WITH_GHOST_X11) has to stay there, because I guess we only want to use XrGraphicsBindingEGLMNDX for X11-EGL. The Wayland backend would use XrGraphicsBindingOpenGLWaylandKHR.

120

Yes, I think pointers are always initialised to NULL / nullptr.

intern/ghost/intern/GHOST_Xr_openxr_includes.h
55

Yes, but I don't really know why.

I took this from: https://gitlab.freedesktop.org/monado/monado/-/blob/2b996f30/src/xrt/include/xrt/xrt_openxr_includes.h#L36-37

If someone can point me to an alternative source where PFNEGLGETPROCADDRESSPROC is defined, I am happy to replace this manual typedef.

I got this running on an Nvidia card:

When building with EGL support (make ninja lite BUILD_CMAKE_ARGS="-DWITH_XR_OPENXR=ON -DWITH_GL_EGL=ON"), you should see OpenXR debug output (--debug-xr) like:

Enabling OpenXR Extension: XR_KHR_opengl_enable
Enabling OpenXR Extension: XR_MNDX_egl_enable
Enabling OpenXR Extension: XR_EXT_debug_utils
Connected to OpenXR runtime: Monado(XRT) by Collabora et al 'GIT-NOTFOUND' (Version 21.0.0)
OpenXR Debug Message:
Completed loader terminator
OpenXR Debug Message:
Completed loader trampoline
 INFO [xrt_gfx_provider_create_gl_egl] Extension availability:
 INFO [xrt_gfx_provider_create_gl_egl]   - GL_EXT_memory_object: true
 INFO [xrt_gfx_provider_create_gl_egl]   - GL_EXT_memory_object_fd: true
 INFO [xrt_gfx_provider_create_gl_egl]   - GL_EXT_memory_object_win32: false
 INFO [xrt_gfx_provider_create_gl_egl]   - GL_OES_EGL_image_external: false
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_ANDROID_get_native_client_buffer: false
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_ANDROID_native_fence_sync: false
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_EXT_image_dma_buf_import_modifiers: true
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_KHR_fence_sync: true
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_KHR_image: true
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_KHR_image_base: true
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_KHR_reusable_sync: true
 INFO [xrt_gfx_provider_create_gl_egl]   - EGL_KHR_wait_sync: true
 INFO [xrt_gfx_provider_create_gl_egl] Using GL memory object swapchain implementation
EGL Version 1.5

Looks good from my side, mainly needs Julian to approve this I think.

@Brecht Van Lommel (brecht) @Julian Eisel (Severin) Can I please get a quick update if this can be merged or if there is something blocking? I need this merged to continue with the Wayland backend.

Since this is not changing existing XR code and so not likely to break anything, it's ok to commit it.

This revision is now accepted and ready to land.Jun 22 2021, 6:23 PM

Since this is not changing existing XR code and so not likely to break anything, it's ok to commit it.

Thanks. This has been merged now via commit 0732a9f1b292edfea6270c23466a40c69b0f99ac.