Title: [265137] trunk/Source/WebCore
Revision
265137
Author
[email protected]
Date
2020-07-31 02:00:54 -0700 (Fri, 31 Jul 2020)

Log Message

[WebXR] Retrieve supported reference spaces from actual XR systems
https://bugs.webkit.org/show_bug.cgi?id=214187

Reviewed by Carlos Garcia Campos.

Each XR system supports a set of reference spaces which are used by WebXR to stablish
a spatial relationship with user's physical environment. The list of supported reference
spaces determine whether or not a session request succeeds or not, as it will refuse to
start a session with an unsupported reference space.

So far, no reference spaces were retrieved from the actual devices. This patch adds the
required OpenXR machinery to retrieve them. In particular, we have to create a XrSession
(although we don't have to start it) in order to retrieve the reference spaces. Since we
don't need it to show content to the user we can create it in headless mode and then discard
it afterwards when no longer needed.

* Modules/webxr/WebXRSession.cpp:
(WebCore::WebXRSession::WebXRSession): Clarify a comment. Also s/TODO/FIXME/g.
* platform/xr/openxr/PlatformXROpenXR.cpp:
(PlatformXR::isExtensionSupported): New method to check whether a specific extension
is supported.
(PlatformXR::Instance::Impl::checkInstanceExtensionProperties const): renamed from
enumerateInstanceExtensionProperties(). Returns whether or not the call succeeded.
(PlatformXR::Instance::Impl::Impl): Pass the list of enabled extensions to the instance.
(PlatformXR::Instance::enumerateImmersiveXRDevices): Log the systems found.
(PlatformXR::OpenXRDevice::OpenXRDevice):
(PlatformXR::OpenXRDevice::enumerateReferenceSpaces const): New method to list the
supported reference spaces by the XR system.
(PlatformXR::OpenXRDevice::collectSupportedSessionModes): Store reference spaces as
enabled features for supported modes.
(PlatformXR::OpenXRDevice::collectConfigurationViews): Renamed from
enumerateConfigurationViews().
(PlatformXR::Instance::Impl::enumerateInstanceExtensionProperties const): Deleted.
(PlatformXR::OpenXRDevice::enumerateConfigurationViews): Deleted.
* platform/xr/openxr/PlatformXROpenXR.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (265136 => 265137)


--- trunk/Source/WebCore/ChangeLog	2020-07-31 07:45:16 UTC (rev 265136)
+++ trunk/Source/WebCore/ChangeLog	2020-07-31 09:00:54 UTC (rev 265137)
@@ -1,3 +1,41 @@
+2020-07-10  Sergio Villar Senin  <[email protected]>
+
+        [WebXR] Retrieve supported reference spaces from actual XR systems
+        https://bugs.webkit.org/show_bug.cgi?id=214187
+
+        Reviewed by Carlos Garcia Campos.
+
+        Each XR system supports a set of reference spaces which are used by WebXR to stablish
+        a spatial relationship with user's physical environment. The list of supported reference
+        spaces determine whether or not a session request succeeds or not, as it will refuse to
+        start a session with an unsupported reference space.
+
+        So far, no reference spaces were retrieved from the actual devices. This patch adds the
+        required OpenXR machinery to retrieve them. In particular, we have to create a XrSession
+        (although we don't have to start it) in order to retrieve the reference spaces. Since we
+        don't need it to show content to the user we can create it in headless mode and then discard
+        it afterwards when no longer needed.
+
+        * Modules/webxr/WebXRSession.cpp:
+        (WebCore::WebXRSession::WebXRSession): Clarify a comment. Also s/TODO/FIXME/g.
+        * platform/xr/openxr/PlatformXROpenXR.cpp:
+        (PlatformXR::isExtensionSupported): New method to check whether a specific extension
+        is supported.
+        (PlatformXR::Instance::Impl::checkInstanceExtensionProperties const): renamed from
+        enumerateInstanceExtensionProperties(). Returns whether or not the call succeeded.
+        (PlatformXR::Instance::Impl::Impl): Pass the list of enabled extensions to the instance.
+        (PlatformXR::Instance::enumerateImmersiveXRDevices): Log the systems found.
+        (PlatformXR::OpenXRDevice::OpenXRDevice):
+        (PlatformXR::OpenXRDevice::enumerateReferenceSpaces const): New method to list the
+        supported reference spaces by the XR system.
+        (PlatformXR::OpenXRDevice::collectSupportedSessionModes): Store reference spaces as
+        enabled features for supported modes.
+        (PlatformXR::OpenXRDevice::collectConfigurationViews): Renamed from
+        enumerateConfigurationViews().
+        (PlatformXR::Instance::Impl::enumerateInstanceExtensionProperties const): Deleted.
+        (PlatformXR::OpenXRDevice::enumerateConfigurationViews): Deleted.
+        * platform/xr/openxr/PlatformXROpenXR.h:
+
 2020-07-31  Youenn Fablet  <[email protected]>
 
         Add LibWebRTCAudioModule logging

Modified: trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp (265136 => 265137)


--- trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp	2020-07-31 07:45:16 UTC (rev 265136)
+++ trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp	2020-07-31 09:00:54 UTC (rev 265137)
@@ -52,10 +52,8 @@
     , m_activeRenderState(WebXRRenderState::create(mode))
     , m_animationTimer(*this, &WebXRSession::animationTimerFired)
 {
-    // TODO: If no other features of the user agent have done so already,
-    // perform the necessary platform-specific steps to initialize the device's
-    // tracking and rendering capabilities, including showing any necessary
-    // instructions to the user.
+    // FIXME: If no other features of the user agent have done so already, perform the necessary platform-specific steps to
+    // initialize the device's tracking and rendering capabilities, including showing any necessary instructions to the user.
     suspendIfNeeded();
 }
 

Modified: trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp (265136 => 265137)


--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp	2020-07-31 07:45:16 UTC (rev 265136)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp	2020-07-31 09:00:54 UTC (rev 265137)
@@ -24,6 +24,7 @@
 
 #include "Logging.h"
 #if USE_OPENXR
+#include <openxr/openxr_platform.h>
 #include <wtf/Optional.h>
 #include <wtf/text/StringConcatenateNumbers.h>
 #include <wtf/text/WTFString.h>
@@ -55,10 +56,10 @@
     return makeString("<unknown ", int(value), ">");
 }
 
-#define RETURN_IF_FAILED(result, call, instance)                                                    \
+#define RETURN_IF_FAILED(result, call, instance, ...)                                               \
     if (XR_FAILED(result)) {                                                                        \
-        LOG(XR, "%s %s: %s\n", __func__, call, resultToString(result, instance).utf8().data()); \
-        return;                                                                                     \
+        LOG(XR, "%s %s: %s\n", __func__, call, resultToString(result, instance).utf8().data());     \
+        return __VA_ARGS__;                                                                         \
     }                                                                                               \
 
 #endif // USE_OPENXR
@@ -76,7 +77,7 @@
 private:
 #if USE_OPENXR
     void enumerateApiLayerProperties() const;
-    void enumerateInstanceExtensionProperties() const;
+    bool checkInstanceExtensionProperties() const;
 
     XrInstance m_instance { XR_NULL_HANDLE };
 #endif // USE_OPENXR
@@ -107,14 +108,23 @@
     LOG(XR, "xrEnumerateApiLayerProperties(): %zu properties\n", properties.size());
 }
 
-void Instance::Impl::enumerateInstanceExtensionProperties() const
+static bool isExtensionSupported(const char* extensionName, Vector<XrExtensionProperties>& instanceExtensionProperties)
 {
+    auto position = instanceExtensionProperties.findMatching([extensionName](auto& property) {
+        return !strcmp(property.extensionName, extensionName);
+    });
+    return position != notFound;
+}
+
+bool Instance::Impl::checkInstanceExtensionProperties() const
+{
     uint32_t propertyCountOutput { 0 };
     XrResult result = xrEnumerateInstanceExtensionProperties(nullptr, 0, &propertyCountOutput, nullptr);
-    RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties()", m_instance);
+    RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties", m_instance, false);
+
     if (!propertyCountOutput) {
         LOG(XR, "xrEnumerateInstanceExtensionProperties(): no properties\n");
-        return;
+        return false;
     }
 
     Vector<XrExtensionProperties> properties(propertyCountOutput,
@@ -127,14 +137,18 @@
 
     uint32_t propertyCountWritten { 0 };
     result = xrEnumerateInstanceExtensionProperties(nullptr, propertyCountOutput, &propertyCountWritten, properties.data());
-    RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties()", m_instance);
+    RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties", m_instance, false);
 #if !LOG_DISABLED
     LOG(XR, "xrEnumerateInstanceExtensionProperties(): %zu extension properties\n", properties.size());
-    for (auto& property : properties) {
-        LOG(XR, "  extension '%s', version %u\n",
-            property.extensionName, property.extensionVersion);
+    for (auto& property : properties)
+        LOG(XR, "  extension '%s', version %u\n", property.extensionName, property.extensionVersion);
+#endif
+    if (!isExtensionSupported(XR_MND_HEADLESS_EXTENSION_NAME, properties)) {
+        LOG(XR, "Required extension %s not supported", XR_MND_HEADLESS_EXTENSION_NAME);
+        return false;
     }
-#endif
+
+    return true;
 }
 #endif // USE_OPENXR
 
@@ -144,11 +158,17 @@
     LOG(XR, "OpenXR: initializing\n");
 
     enumerateApiLayerProperties();
-    enumerateInstanceExtensionProperties();
 
+    if (!checkInstanceExtensionProperties())
+        return;
+
     static const char* s_applicationName = "WebXR (WebKit)";
     static const uint32_t s_applicationVersion = 1;
 
+    const char* const enabledExtensions[] = {
+        XR_MND_HEADLESS_EXTENSION_NAME,
+    };
+
     auto createInfo = createStructure<XrInstanceCreateInfo, XR_TYPE_INSTANCE_CREATE_INFO>();
     createInfo.createFlags = 0;
     std::memcpy(createInfo.applicationInfo.applicationName, s_applicationName, XR_MAX_APPLICATION_NAME_SIZE);
@@ -155,7 +175,8 @@
     createInfo.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
     createInfo.applicationInfo.applicationVersion = s_applicationVersion;
     createInfo.enabledApiLayerCount = 0;
-    createInfo.enabledExtensionCount = 0;
+    createInfo.enabledExtensionCount = WTF_ARRAY_LENGTH(enabledExtensions);
+    createInfo.enabledExtensionNames = enabledExtensions;
 
     XrInstance instance;
     XrResult result = xrCreateInstance(&createInfo, &instance);
@@ -204,6 +225,13 @@
     XrResult result = xrGetSystem(m_impl->xrInstance(), &systemGetInfo, &systemId);
     RETURN_IF_FAILED(result, "xrGetSystem", m_impl->xrInstance());
 
+#if !LOG_DISABLED
+    auto systemProperties = createStructure<XrSystemProperties, XR_TYPE_SYSTEM_PROPERTIES>();
+    result = xrGetSystemProperties(m_impl->xrInstance(), systemId, &systemProperties);
+    if (result == XR_SUCCESS)
+        LOG(XR, "Found XRSystem %lu: \"%s\", vendor ID %d\n", systemProperties.systemId, systemProperties.systemName, systemProperties.vendorId);
+#endif
+
     m_immersiveXRDevices.append(makeUnique<OpenXRDevice>(systemId, m_impl->xrInstance()));
 #endif // USE_OPENXR
 }
@@ -221,9 +249,48 @@
         LOG(XR, "xrGetSystemProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
 
     collectSupportedSessionModes();
-    enumerateConfigurationViews();
+    collectConfigurationViews();
 }
 
+Device::ListOfEnabledFeatures OpenXRDevice::enumerateReferenceSpaces(XrSession& session) const
+{
+    uint32_t referenceSpacesCount;
+    auto result = xrEnumerateReferenceSpaces(session, 0, &referenceSpacesCount, nullptr);
+    RETURN_IF_FAILED(result, "xrEnumerateReferenceSpaces", m_instance, { });
+
+    Vector<XrReferenceSpaceType> referenceSpaces(referenceSpacesCount);
+    referenceSpaces.fill(XR_REFERENCE_SPACE_TYPE_VIEW, referenceSpacesCount);
+    result = xrEnumerateReferenceSpaces(session, referenceSpacesCount, &referenceSpacesCount, referenceSpaces.data());
+    RETURN_IF_FAILED(result, "xrEnumerateReferenceSpaces", m_instance, { });
+
+    ListOfEnabledFeatures enabledFeatures;
+    for (auto& referenceSpace : referenceSpaces) {
+        switch (referenceSpace) {
+        case XR_REFERENCE_SPACE_TYPE_VIEW:
+            enabledFeatures.append(ReferenceSpaceType::Viewer);
+            LOG(XR, "\tDevice supports VIEW reference space");
+            break;
+        case XR_REFERENCE_SPACE_TYPE_LOCAL:
+            enabledFeatures.append(ReferenceSpaceType::Local);
+            LOG(XR, "\tDevice supports LOCAL reference space");
+            break;
+        case XR_REFERENCE_SPACE_TYPE_STAGE:
+            enabledFeatures.append(ReferenceSpaceType::LocalFloor);
+            enabledFeatures.append(ReferenceSpaceType::BoundedFloor);
+            LOG(XR, "\tDevice supports STAGE reference space");
+            break;
+        case XR_REFERENCE_SPACE_TYPE_UNBOUNDED_MSFT:
+            enabledFeatures.append(ReferenceSpaceType::Unbounded);
+            LOG(XR, "\tDevice supports UNBOUNDED reference space");
+            break;
+        default:
+            continue;
+        }
+    }
+
+    return enabledFeatures;
+}
+
 void OpenXRDevice::collectSupportedSessionModes()
 {
     uint32_t viewConfigurationCount;
@@ -234,6 +301,15 @@
     result = xrEnumerateViewConfigurations(m_instance, m_systemId, viewConfigurationCount, &viewConfigurationCount, viewConfigurations);
     RETURN_IF_FAILED(result, "xrEnumerateViewConfigurations", m_instance);
 
+    // Retrieving the supported reference spaces requires an initialized session. There is no need to initialize all the graphics
+    // stuff so we'll use a headless session that will be discarded after getting the info we need.
+    auto sessionCreateInfo = createStructure<XrSessionCreateInfo, XR_TYPE_SESSION_CREATE_INFO>();
+    sessionCreateInfo.systemId = m_systemId;
+    XrSession ephemeralSession;
+    result = xrCreateSession(m_instance, &sessionCreateInfo, &ephemeralSession);
+    RETURN_IF_FAILED(result, "xrCreateSession", m_instance);
+
+    ListOfEnabledFeatures features = enumerateReferenceSpaces(ephemeralSession);
     for (uint32_t i = 0; i < viewConfigurationCount; ++i) {
         auto viewConfigurationProperties = createStructure<XrViewConfigurationProperties, XR_TYPE_VIEW_CONFIGURATION_PROPERTIES>();
         result = xrGetViewConfigurationProperties(m_instance, m_systemId, viewConfigurations[i], &viewConfigurationProperties);
@@ -244,10 +320,10 @@
         auto configType = viewConfigurationProperties.viewConfigurationType;
         switch (configType) {
         case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO:
-            setEnabledFeatures(SessionMode::Inline, { });
+            setEnabledFeatures(SessionMode::Inline, features);
             break;
         case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO:
-            setEnabledFeatures(SessionMode::ImmersiveVr, { });
+            setEnabledFeatures(SessionMode::ImmersiveVr, features);
             break;
         default:
             continue;
@@ -254,9 +330,10 @@
         };
         m_viewConfigurationProperties.add(configType, WTFMove(viewConfigurationProperties));
     }
+    xrDestroySession(ephemeralSession);
 }
 
-void OpenXRDevice::enumerateConfigurationViews()
+void OpenXRDevice::collectConfigurationViews()
 {
     for (auto& config : m_viewConfigurationProperties.values()) {
         uint32_t viewCount;
@@ -290,7 +367,6 @@
     return Device::recommendedResolution(mode);
 }
 
-
 #endif // USE_OPENXR
 
 } // namespace PlatformXR

Modified: trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h (265136 => 265137)


--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h	2020-07-31 07:45:16 UTC (rev 265136)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h	2020-07-31 09:00:54 UTC (rev 265137)
@@ -47,8 +47,10 @@
     XrSystemId xrSystemId() const { return m_systemId; }
 private:
     void collectSupportedSessionModes();
-    void enumerateConfigurationViews();
+    void collectConfigurationViews();
 
+    ListOfEnabledFeatures enumerateReferenceSpaces(XrSession&) const;
+
     WebCore::IntSize recommendedResolution(SessionMode) final;
 
     using ViewConfigurationPropertiesMap = HashMap<XrViewConfigurationType, XrViewConfigurationProperties, IntHash<XrViewConfigurationType>, WTF::StrongEnumHashTraits<XrViewConfigurationType>>;
@@ -58,6 +60,7 @@
 
     XrSystemId m_systemId;
     XrInstance m_instance;
+    XrSession m_session;
 };
 
 } // namespace PlatformXR
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to