Changeset 273549 in webkit
- Timestamp:
- Feb 26, 2021 3:53:07 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ChangeLog
r273545 r273549 1 2021-02-26 Imanol Fernandez <ifernandez@igalia.com> 2 3 Implement OpenXR port graphics binding 4 https://bugs.webkit.org/show_bug.cgi?id=222173 5 6 Reviewed by Sergio Villar Senin. 7 8 Enable OpenXR defines required for EGL graphics binding. 9 10 * Source/cmake/OptionsWPE.cmake: 11 1 12 2021-02-26 Carlos Garcia Campos <cgarcia@igalia.com> 2 13 -
trunk/Source/WebCore/ChangeLog
r273545 r273549 1 2021-02-26 Imanol Fernandez <ifernandez@igalia.com> 2 3 Implement OpenXR port graphics binding 4 https://bugs.webkit.org/show_bug.cgi?id=222173 5 6 Reviewed by Sergio Villar Senin. 7 8 This patch implements the graphics binding required to initialize OpenXR sessions 9 with tracking and rendering support. The current implementation was using a headless 10 OpenXR session which is not valid for tracking. 11 12 The headless session was used to avoid allocating the graphics resources during WebXR 13 device enumeration. The problem is that it can't be converted later to a valid session for 14 tracking, and the global XrInstance needs to be recreated. This patch implements a new approach 15 to keep the delayed graphics initialization without using the headless session. 16 17 * platform/graphics/egl/GLContextEGL.cpp: Add EGLConfig argument to create methods 18 (WebCore::GLContextEGL::createWindowContext): 19 (WebCore::GLContextEGL::createPbufferContext): 20 (WebCore::GLContextEGL::createSurfacelessContext): 21 (WebCore::GLContextEGL::GLContextEGL): 22 * platform/graphics/egl/GLContextEGL.h: Add EGLConfig member 23 * platform/graphics/egl/GLContextEGLLibWPE.cpp: initialize m_config 24 (WebCore::GLContextEGL::GLContextEGL): 25 (WebCore::GLContextEGL::createWPEContext): 26 * platform/graphics/egl/GLContextEGLWayland.cpp: initialize m_config 27 (WebCore::GLContextEGL::GLContextEGL): 28 (WebCore::GLContextEGL::createWaylandContext): 29 * platform/graphics/egl/GLContextEGLX11.cpp: initialize m_config 30 (WebCore::GLContextEGL::GLContextEGL): 31 (WebCore::GLContextEGL::createPixmapContext): 32 33 * platform/xr/openxr/OpenXRExtensions.cpp: Add OpenXRExtensionMethods 34 (PlatformXR::OpenXRExtensions::loadMethods): 35 * platform/xr/openxr/OpenXRExtensions.h: 36 37 * platform/xr/openxr/OpenXRInstance.cpp: Enable graphics related extensions instead of XR_MND_HEADLESS_EXTENSION 38 (PlatformXR::Instance::Impl::Impl): 39 40 * platform/xr/openxr/OpenXRUtils.h: Forward declare symbols required by openxr_platform. 41 42 * platform/xr/openxr/PlatformXROpenXR.cpp: 43 (PlatformXR::OpenXRDevice::initializeTrackingAndRendering): Setup XrGraphicsBindingEGLMNDX 44 (PlatformXR::OpenXRDevice::collectEnabledFeatures): Alternative solution to enumerateReferenceSpaces() 45 (PlatformXR::OpenXRDevice::collectSupportedSessionModes): 46 (PlatformXR::OpenXRDevice::resetSession): deallocate graphic resources 47 * platform/xr/openxr/PlatformXROpenXR.h: 48 1 49 2021-02-26 Carlos Garcia Campos <cgarcia@igalia.com> 2 50 -
trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp
r270477 r273549 205 205 } 206 206 207 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, WindowSurface));207 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, config, WindowSurface)); 208 208 } 209 209 … … 231 231 } 232 232 233 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, PbufferSurface));233 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, config, PbufferSurface)); 234 234 } 235 235 … … 260 260 } 261 261 262 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, EGL_NO_SURFACE, Surfaceless));262 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, EGL_NO_SURFACE, config, Surfaceless)); 263 263 } 264 264 … … 354 354 } 355 355 356 GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, EGL SurfaceType type)356 GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, EGLConfig config, EGLSurfaceType type) 357 357 : GLContext(display) 358 358 , m_context(context) 359 359 , m_surface(surface) 360 , m_config(config) 360 361 , m_type(type) 361 362 { -
trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.h
r270477 r273549 53 53 static const char* lastErrorString(); 54 54 55 EGLConfig config() const { return m_config; } 56 55 57 virtual ~GLContextEGL(); 56 58 … … 72 74 enum EGLSurfaceType { PbufferSurface, WindowSurface, PixmapSurface, Surfaceless }; 73 75 74 GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, EGL SurfaceType);76 GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, EGLConfig, EGLSurfaceType); 75 77 #if PLATFORM(X11) 76 GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, XUniquePixmap&&);78 GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, EGLConfig, XUniquePixmap&&); 77 79 #endif 78 80 #if PLATFORM(WAYLAND) 79 GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, WlUniquePtr<struct wl_surface>&&, struct wl_egl_window*);81 GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, EGLConfig, WlUniquePtr<struct wl_surface>&&, struct wl_egl_window*); 80 82 void destroyWaylandWindow(); 81 83 #endif 82 84 #if USE(WPE_RENDERER) 83 GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, struct wpe_renderer_backend_egl_offscreen_target*);85 GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, EGLConfig, struct wpe_renderer_backend_egl_offscreen_target*); 84 86 void destroyWPETarget(); 85 87 #endif … … 105 107 EGLContext m_context { nullptr }; 106 108 EGLSurface m_surface { nullptr }; 109 EGLConfig m_config { nullptr }; 107 110 EGLSurfaceType m_type; 108 111 #if PLATFORM(X11) -
trunk/Source/WebCore/platform/graphics/egl/GLContextEGLLibWPE.cpp
r245807 r273549 41 41 namespace WebCore { 42 42 43 GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, struct wpe_renderer_backend_egl_offscreen_target* target)43 GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, EGLConfig config, struct wpe_renderer_backend_egl_offscreen_target* target) 44 44 : GLContext(display) 45 45 , m_context(context) 46 46 , m_surface(surface) 47 , m_config(config) 47 48 , m_type(WindowSurface) 48 49 , m_wpeTarget(target) … … 90 91 } 91 92 92 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, target));93 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, config, target)); 93 94 } 94 95 -
trunk/Source/WebCore/platform/graphics/egl/GLContextEGLWayland.cpp
r229663 r273549 30 30 namespace WebCore { 31 31 32 GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, WlUniquePtr<struct wl_surface>&& wlSurface, struct wl_egl_window* wlWindow)32 GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, EGLConfig config, WlUniquePtr<struct wl_surface>&& wlSurface, struct wl_egl_window* wlWindow) 33 33 : GLContext(display) 34 34 , m_context(context) 35 35 , m_surface(surface) 36 , m_config(config) 36 37 , m_type(WindowSurface) 37 38 , m_wlSurface(WTFMove(wlSurface)) … … 70 71 } 71 72 72 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, WTFMove(wlSurface), window));73 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, config, WTFMove(wlSurface), window)); 73 74 } 74 75 -
trunk/Source/WebCore/platform/graphics/egl/GLContextEGLX11.cpp
r229663 r273549 29 29 namespace WebCore { 30 30 31 GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, XUniquePixmap&& pixmap)31 GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, EGLConfig config, XUniquePixmap&& pixmap) 32 32 : GLContext(display) 33 33 , m_context(context) 34 34 , m_surface(surface) 35 , m_config(config) 35 36 , m_type(PixmapSurface) 36 37 , m_pixmap(WTFMove(pixmap)) … … 91 92 } 92 93 93 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, WTFMove(pixmap)));94 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, config, WTFMove(pixmap))); 94 95 } 95 96 -
trunk/Source/WebCore/platform/xr/openxr/OpenXRExtensions.cpp
r273382 r273549 55 55 } 56 56 57 void OpenXRExtensions::loadMethods(XrInstance instance) 58 { 59 #if USE(EGL) 60 m_methods.getProcAddressFunc = eglGetProcAddress; 61 #endif 62 xrGetInstanceProcAddr(instance, "xrGetOpenGLGraphicsRequirementsKHR", reinterpret_cast<PFN_xrVoidFunction*>(&m_methods.xrGetOpenGLGraphicsRequirementsKHR)); 63 } 64 57 65 bool OpenXRExtensions::isExtensionSupported(const char* name) const 58 66 { -
trunk/Source/WebCore/platform/xr/openxr/OpenXRExtensions.h
r273382 r273549 29 29 namespace PlatformXR { 30 30 31 struct OpenXRExtensionMethods { 32 PFNEGLGETPROCADDRESSPROC getProcAddressFunc { nullptr }; 33 PFN_xrGetOpenGLGraphicsRequirementsKHR xrGetOpenGLGraphicsRequirementsKHR { nullptr }; 34 }; 35 31 36 class OpenXRExtensions final { 32 37 WTF_MAKE_FAST_ALLOCATED; … … 36 41 OpenXRExtensions(Vector<XrExtensionProperties>&&); 37 42 43 void loadMethods(XrInstance); 38 44 bool isExtensionSupported(const char*) const; 45 const OpenXRExtensionMethods& methods() const { return m_methods; } 39 46 40 47 private: 41 48 Vector<XrExtensionProperties> m_extensions; 49 OpenXRExtensionMethods m_methods; 42 50 }; 43 51 -
trunk/Source/WebCore/platform/xr/openxr/OpenXRInstance.cpp
r273382 r273549 57 57 return; 58 58 59 if (!m_extensions->isExtensionSupported(XR_MND_HEADLESS_EXTENSION_NAME)) {60 LOG(XR, "Required extension %s not supported", XR_MND_HEADLESS_EXTENSION_NAME);61 return;62 }63 64 59 static const char* s_applicationName = "WebXR (WebKit)"; 65 60 static const uint32_t s_applicationVersion = 1; 66 61 67 62 const char* const enabledExtensions[] = { 68 XR_MND_HEADLESS_EXTENSION_NAME 63 XR_KHR_OPENGL_ENABLE_EXTENSION_NAME, 64 XR_MNDX_EGL_ENABLE_EXTENSION_NAME 69 65 }; 70 66 … … 82 78 if (m_instance == XR_NULL_HANDLE) 83 79 return; 80 81 m_extensions->loadMethods(m_instance); 84 82 85 83 LOG(XR, "xrCreateInstance(): using instance %p\n", m_instance); -
trunk/Source/WebCore/platform/xr/openxr/OpenXRUtils.h
r273382 r273549 22 22 #if ENABLE(WEBXR) && USE(OPENXR) 23 23 24 #if USE(EGL) 25 // EGL symbols required by openxr_platform.h 26 #if USE(LIBEPOXY) 27 #define __GBM__ 1 28 #include "EpoxyEGL.h" 29 #else 30 #if PLATFORM(WAYLAND) 31 #include <wayland-egl.h> 32 #endif 33 #include <EGL/egl.h> 34 #endif 35 36 #endif // USE(EGL) 37 24 38 #include "Logging.h" 25 39 #include "PlatformXR.h" 26 40 #include <openxr/openxr.h> 41 #include <openxr/openxr_platform.h> 27 42 28 43 #include <wtf/text/StringConcatenateNumbers.h> -
trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp
r273382 r273549 82 82 ASSERT(m_instance != XR_NULL_HANDLE); 83 83 ASSERT(m_session == XR_NULL_HANDLE); 84 ASSERT(m_extensions.methods().xrGetOpenGLGraphicsRequirementsKHR); 84 85 85 86 m_currentViewConfigurationType = toXrViewConfigurationType(mode); 86 87 ASSERT(m_configurationViews.contains(m_currentViewConfigurationType)); 88 89 // https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/xrGetOpenGLGraphicsRequirementsKHR.html 90 // OpenXR requires to call xrGetOpenGLGraphicsRequirementsKHR before creating a session. 91 auto requirements = createStructure<XrGraphicsRequirementsOpenGLKHR, XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR>(); 92 auto result = m_extensions.methods().xrGetOpenGLGraphicsRequirementsKHR(m_instance, m_systemId, &requirements); 93 RETURN_IF_FAILED(result, "xrGetOpenGLGraphicsRequirementsKHR", m_instance); 94 95 m_graphicsBinding = createStructure<XrGraphicsBindingEGLMNDX, XR_TYPE_GRAPHICS_BINDING_EGL_MNDX>(); 96 m_egl = GLContextEGL::createSharingContext(PlatformDisplay::sharedDisplay()); 97 if (!m_egl) { 98 LOG(XR, "Failed to create EGL context"); 99 return; 100 } 101 102 auto& context = static_cast<GLContext&>(*m_egl); 103 context.makeContextCurrent(); 104 105 m_graphicsBinding.display = PlatformDisplay::sharedDisplay().eglDisplay(); 106 m_graphicsBinding.context = context.platformContext(); 107 m_graphicsBinding.config = m_egl->config(); 108 m_graphicsBinding.getProcAddress = m_extensions.methods().getProcAddressFunc; 87 109 88 110 // Create the session. 89 111 auto sessionCreateInfo = createStructure<XrSessionCreateInfo, XR_TYPE_SESSION_CREATE_INFO>(); 90 112 sessionCreateInfo.systemId = m_systemId; 91 92 auto result = xrCreateSession(m_instance, &sessionCreateInfo, &m_session); 113 sessionCreateInfo.next = &m_graphicsBinding; 114 115 result = xrCreateSession(m_instance, &sessionCreateInfo, &m_session); 93 116 RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties", m_instance); 94 117 … … 221 244 } 222 245 223 Device::ListOfEnabledFeatures OpenXRDevice::enumerateReferenceSpaces(XrSession session) const 224 { 225 uint32_t referenceSpacesCount; 226 auto result = xrEnumerateReferenceSpaces(session, 0, &referenceSpacesCount, nullptr); 227 RETURN_IF_FAILED(result, "xrEnumerateReferenceSpaces", m_instance, { }); 228 229 Vector<XrReferenceSpaceType> referenceSpaces(referenceSpacesCount); 230 referenceSpaces.fill(XR_REFERENCE_SPACE_TYPE_VIEW, referenceSpacesCount); 231 result = xrEnumerateReferenceSpaces(session, referenceSpacesCount, &referenceSpacesCount, referenceSpaces.data()); 232 RETURN_IF_FAILED(result, "xrEnumerateReferenceSpaces", m_instance, { }); 233 234 ListOfEnabledFeatures enabledFeatures; 235 for (auto& referenceSpace : referenceSpaces) { 236 switch (referenceSpace) { 237 case XR_REFERENCE_SPACE_TYPE_VIEW: 238 enabledFeatures.append(ReferenceSpaceType::Viewer); 239 LOG(XR, "\tDevice supports VIEW reference space"); 240 break; 241 case XR_REFERENCE_SPACE_TYPE_LOCAL: 242 enabledFeatures.append(ReferenceSpaceType::Local); 243 LOG(XR, "\tDevice supports LOCAL reference space"); 244 break; 245 case XR_REFERENCE_SPACE_TYPE_STAGE: 246 enabledFeatures.append(ReferenceSpaceType::LocalFloor); 247 enabledFeatures.append(ReferenceSpaceType::BoundedFloor); 248 LOG(XR, "\tDevice supports STAGE reference space"); 249 break; 250 case XR_REFERENCE_SPACE_TYPE_UNBOUNDED_MSFT: 251 enabledFeatures.append(ReferenceSpaceType::Unbounded); 252 LOG(XR, "\tDevice supports UNBOUNDED reference space"); 253 break; 254 default: 255 continue; 256 } 257 } 258 259 return enabledFeatures; 246 Device::ListOfEnabledFeatures OpenXRDevice::collectEnabledFeatures() 247 { 248 Device::ListOfEnabledFeatures features; 249 250 // https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/XrReferenceSpaceType.html 251 // OpenXR runtimes must support Viewer and Local spaces. 252 features.append(ReferenceSpaceType::Viewer); 253 features.append(ReferenceSpaceType::Local); 254 255 // Mark LocalFloor as supported regardless if XR_REFERENCE_SPACE_TYPE_STAGE is available. 256 // The spec uses a estimated height if we don't provide a floor transform in frameData. 257 features.append(ReferenceSpaceType::LocalFloor); 258 259 // FIXME: Enable BoundedFloor when we implement xrGetReferenceSpaceBoundsRect and the related bits in the DOM. 260 // enabledFeatures.append(ReferenceSpaceType::BoundedFloor); 261 262 if (m_extensions.isExtensionSupported(XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME)) 263 features.append(ReferenceSpaceType::Unbounded); 264 265 return features; 260 266 } 261 267 … … 271 277 RETURN_IF_FAILED(result, "xrEnumerateViewConfigurations", m_instance); 272 278 273 // Retrieving the supported reference spaces requires an initialized session. There is no need to initialize all the graphics 274 // stuff so we'll use a headless session that will be discarded after getting the info we need. 275 auto sessionCreateInfo = createStructure<XrSessionCreateInfo, XR_TYPE_SESSION_CREATE_INFO>(); 276 sessionCreateInfo.systemId = m_systemId; 277 XrSession ephemeralSession; 278 result = xrCreateSession(m_instance, &sessionCreateInfo, &ephemeralSession); 279 RETURN_IF_FAILED(result, "xrCreateSession", m_instance); 280 281 ListOfEnabledFeatures features = enumerateReferenceSpaces(ephemeralSession); 279 ListOfEnabledFeatures features = collectEnabledFeatures(); 282 280 for (uint32_t i = 0; i < viewConfigurationCount; ++i) { 283 281 auto viewConfigurationProperties = createStructure<XrViewConfigurationProperties, XR_TYPE_VIEW_CONFIGURATION_PROPERTIES>(); … … 300 298 m_viewConfigurationProperties.add(configType, WTFMove(viewConfigurationProperties)); 301 299 } 302 xrDestroySession(ephemeralSession);303 300 } 304 301 … … 417 414 } 418 415 m_sessionState = XR_SESSION_STATE_UNKNOWN; 416 417 // deallocate graphic resources 418 m_egl.reset(); 419 419 } 420 420 -
trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h
r273382 r273549 22 22 #if ENABLE(WEBXR) && USE(OPENXR) 23 23 24 #include "GLContextEGL.h" 24 25 #include "OpenXRUtils.h" 25 26 #include "PlatformXR.h" … … 59 60 60 61 // Custom methods 61 ListOfEnabledFeatures enumerateReferenceSpaces(XrSession) const;62 ListOfEnabledFeatures collectEnabledFeatures(); 62 63 void collectSupportedSessionModes(); 63 64 void collectConfigurationViews(); … … 76 77 XrSession m_session { XR_NULL_HANDLE }; 77 78 XrSessionState m_sessionState { XR_SESSION_STATE_UNKNOWN }; 79 XrGraphicsBindingEGLMNDX m_graphicsBinding; 80 std::unique_ptr<WebCore::GLContextEGL> m_egl; 78 81 79 82 using ViewConfigurationPropertiesMap = HashMap<XrViewConfigurationType, XrViewConfigurationProperties, IntHash<XrViewConfigurationType>, WTF::StrongEnumHashTraits<XrViewConfigurationType>>; -
trunk/Source/cmake/OptionsWPE.cmake
r273545 r273549 197 197 endif () 198 198 SET_AND_EXPOSE_TO_BUILD(USE_OPENXR ${OpenXR_FOUND}) 199 SET_AND_EXPOSE_TO_BUILD(XR_USE_PLATFORM_EGL TRUE) 200 SET_AND_EXPOSE_TO_BUILD(XR_USE_GRAPHICS_API_OPENGL TRUE) 199 201 endif () 200 202
Note: See TracChangeset
for help on using the changeset viewer.