Changeset 265137 in webkit


Ignore:
Timestamp:
Jul 31, 2020 2:00:54 AM (4 years ago)
Author:
svillar@igalia.com
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:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r265135 r265137  
     12020-07-10  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [WebXR] Retrieve supported reference spaces from actual XR systems
     4        https://bugs.webkit.org/show_bug.cgi?id=214187
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Each XR system supports a set of reference spaces which are used by WebXR to stablish
     9        a spatial relationship with user's physical environment. The list of supported reference
     10        spaces determine whether or not a session request succeeds or not, as it will refuse to
     11        start a session with an unsupported reference space.
     12
     13        So far, no reference spaces were retrieved from the actual devices. This patch adds the
     14        required OpenXR machinery to retrieve them. In particular, we have to create a XrSession
     15        (although we don't have to start it) in order to retrieve the reference spaces. Since we
     16        don't need it to show content to the user we can create it in headless mode and then discard
     17        it afterwards when no longer needed.
     18
     19        * Modules/webxr/WebXRSession.cpp:
     20        (WebCore::WebXRSession::WebXRSession): Clarify a comment. Also s/TODO/FIXME/g.
     21        * platform/xr/openxr/PlatformXROpenXR.cpp:
     22        (PlatformXR::isExtensionSupported): New method to check whether a specific extension
     23        is supported.
     24        (PlatformXR::Instance::Impl::checkInstanceExtensionProperties const): renamed from
     25        enumerateInstanceExtensionProperties(). Returns whether or not the call succeeded.
     26        (PlatformXR::Instance::Impl::Impl): Pass the list of enabled extensions to the instance.
     27        (PlatformXR::Instance::enumerateImmersiveXRDevices): Log the systems found.
     28        (PlatformXR::OpenXRDevice::OpenXRDevice):
     29        (PlatformXR::OpenXRDevice::enumerateReferenceSpaces const): New method to list the
     30        supported reference spaces by the XR system.
     31        (PlatformXR::OpenXRDevice::collectSupportedSessionModes): Store reference spaces as
     32        enabled features for supported modes.
     33        (PlatformXR::OpenXRDevice::collectConfigurationViews): Renamed from
     34        enumerateConfigurationViews().
     35        (PlatformXR::Instance::Impl::enumerateInstanceExtensionProperties const): Deleted.
     36        (PlatformXR::OpenXRDevice::enumerateConfigurationViews): Deleted.
     37        * platform/xr/openxr/PlatformXROpenXR.h:
     38
    1392020-07-31  Youenn Fablet  <youenn@apple.com>
    240
  • trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp

    r264215 r265137  
    5353    , m_animationTimer(*this, &WebXRSession::animationTimerFired)
    5454{
    55     // TODO: If no other features of the user agent have done so already,
    56     // perform the necessary platform-specific steps to initialize the device's
    57     // tracking and rendering capabilities, including showing any necessary
    58     // instructions to the user.
     55    // FIXME: If no other features of the user agent have done so already, perform the necessary platform-specific steps to
     56    // initialize the device's tracking and rendering capabilities, including showing any necessary instructions to the user.
    5957    suspendIfNeeded();
    6058}
  • trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp

    r264568 r265137  
    2525#include "Logging.h"
    2626#if USE_OPENXR
     27#include <openxr/openxr_platform.h>
    2728#include <wtf/Optional.h>
    2829#include <wtf/text/StringConcatenateNumbers.h>
     
    5657}
    5758
    58 #define RETURN_IF_FAILED(result, call, instance)                                                    \
     59#define RETURN_IF_FAILED(result, call, instance, ...)                                               \
    5960    if (XR_FAILED(result)) {                                                                        \
    60         LOG(XR, "%s %s: %s\n", __func__, call, resultToString(result, instance).utf8().data()); \
    61         return;                                                                                     \
     61        LOG(XR, "%s %s: %s\n", __func__, call, resultToString(result, instance).utf8().data());     \
     62        return __VA_ARGS__;                                                                         \
    6263    }                                                                                               \
    6364
     
    7778#if USE_OPENXR
    7879    void enumerateApiLayerProperties() const;
    79     void enumerateInstanceExtensionProperties() const;
     80    bool checkInstanceExtensionProperties() const;
    8081
    8182    XrInstance m_instance { XR_NULL_HANDLE };
     
    108109}
    109110
    110 void Instance::Impl::enumerateInstanceExtensionProperties() const
     111static bool isExtensionSupported(const char* extensionName, Vector<XrExtensionProperties>& instanceExtensionProperties)
     112{
     113    auto position = instanceExtensionProperties.findMatching([extensionName](auto& property) {
     114        return !strcmp(property.extensionName, extensionName);
     115    });
     116    return position != notFound;
     117}
     118
     119bool Instance::Impl::checkInstanceExtensionProperties() const
    111120{
    112121    uint32_t propertyCountOutput { 0 };
    113122    XrResult result = xrEnumerateInstanceExtensionProperties(nullptr, 0, &propertyCountOutput, nullptr);
    114     RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties()", m_instance);
     123    RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties", m_instance, false);
     124
    115125    if (!propertyCountOutput) {
    116126        LOG(XR, "xrEnumerateInstanceExtensionProperties(): no properties\n");
    117         return;
     127        return false;
    118128    }
    119129
     
    128138    uint32_t propertyCountWritten { 0 };
    129139    result = xrEnumerateInstanceExtensionProperties(nullptr, propertyCountOutput, &propertyCountWritten, properties.data());
    130     RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties()", m_instance);
     140    RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties", m_instance, false);
    131141#if !LOG_DISABLED
    132142    LOG(XR, "xrEnumerateInstanceExtensionProperties(): %zu extension properties\n", properties.size());
    133     for (auto& property : properties) {
    134         LOG(XR, "  extension '%s', version %u\n",
    135             property.extensionName, property.extensionVersion);
    136     }
     143    for (auto& property : properties)
     144        LOG(XR, "  extension '%s', version %u\n", property.extensionName, property.extensionVersion);
    137145#endif
     146    if (!isExtensionSupported(XR_MND_HEADLESS_EXTENSION_NAME, properties)) {
     147        LOG(XR, "Required extension %s not supported", XR_MND_HEADLESS_EXTENSION_NAME);
     148        return false;
     149    }
     150
     151    return true;
    138152}
    139153#endif // USE_OPENXR
     
    145159
    146160    enumerateApiLayerProperties();
    147     enumerateInstanceExtensionProperties();
     161
     162    if (!checkInstanceExtensionProperties())
     163        return;
    148164
    149165    static const char* s_applicationName = "WebXR (WebKit)";
    150166    static const uint32_t s_applicationVersion = 1;
     167
     168    const char* const enabledExtensions[] = {
     169        XR_MND_HEADLESS_EXTENSION_NAME,
     170    };
    151171
    152172    auto createInfo = createStructure<XrInstanceCreateInfo, XR_TYPE_INSTANCE_CREATE_INFO>();
     
    156176    createInfo.applicationInfo.applicationVersion = s_applicationVersion;
    157177    createInfo.enabledApiLayerCount = 0;
    158     createInfo.enabledExtensionCount = 0;
     178    createInfo.enabledExtensionCount = WTF_ARRAY_LENGTH(enabledExtensions);
     179    createInfo.enabledExtensionNames = enabledExtensions;
    159180
    160181    XrInstance instance;
     
    205226    RETURN_IF_FAILED(result, "xrGetSystem", m_impl->xrInstance());
    206227
     228#if !LOG_DISABLED
     229    auto systemProperties = createStructure<XrSystemProperties, XR_TYPE_SYSTEM_PROPERTIES>();
     230    result = xrGetSystemProperties(m_impl->xrInstance(), systemId, &systemProperties);
     231    if (result == XR_SUCCESS)
     232        LOG(XR, "Found XRSystem %lu: \"%s\", vendor ID %d\n", systemProperties.systemId, systemProperties.systemName, systemProperties.vendorId);
     233#endif
     234
    207235    m_immersiveXRDevices.append(makeUnique<OpenXRDevice>(systemId, m_impl->xrInstance()));
    208236#endif // USE_OPENXR
     
    222250
    223251    collectSupportedSessionModes();
    224     enumerateConfigurationViews();
     252    collectConfigurationViews();
     253}
     254
     255Device::ListOfEnabledFeatures OpenXRDevice::enumerateReferenceSpaces(XrSession& session) const
     256{
     257    uint32_t referenceSpacesCount;
     258    auto result = xrEnumerateReferenceSpaces(session, 0, &referenceSpacesCount, nullptr);
     259    RETURN_IF_FAILED(result, "xrEnumerateReferenceSpaces", m_instance, { });
     260
     261    Vector<XrReferenceSpaceType> referenceSpaces(referenceSpacesCount);
     262    referenceSpaces.fill(XR_REFERENCE_SPACE_TYPE_VIEW, referenceSpacesCount);
     263    result = xrEnumerateReferenceSpaces(session, referenceSpacesCount, &referenceSpacesCount, referenceSpaces.data());
     264    RETURN_IF_FAILED(result, "xrEnumerateReferenceSpaces", m_instance, { });
     265
     266    ListOfEnabledFeatures enabledFeatures;
     267    for (auto& referenceSpace : referenceSpaces) {
     268        switch (referenceSpace) {
     269        case XR_REFERENCE_SPACE_TYPE_VIEW:
     270            enabledFeatures.append(ReferenceSpaceType::Viewer);
     271            LOG(XR, "\tDevice supports VIEW reference space");
     272            break;
     273        case XR_REFERENCE_SPACE_TYPE_LOCAL:
     274            enabledFeatures.append(ReferenceSpaceType::Local);
     275            LOG(XR, "\tDevice supports LOCAL reference space");
     276            break;
     277        case XR_REFERENCE_SPACE_TYPE_STAGE:
     278            enabledFeatures.append(ReferenceSpaceType::LocalFloor);
     279            enabledFeatures.append(ReferenceSpaceType::BoundedFloor);
     280            LOG(XR, "\tDevice supports STAGE reference space");
     281            break;
     282        case XR_REFERENCE_SPACE_TYPE_UNBOUNDED_MSFT:
     283            enabledFeatures.append(ReferenceSpaceType::Unbounded);
     284            LOG(XR, "\tDevice supports UNBOUNDED reference space");
     285            break;
     286        default:
     287            continue;
     288        }
     289    }
     290
     291    return enabledFeatures;
    225292}
    226293
     
    235302    RETURN_IF_FAILED(result, "xrEnumerateViewConfigurations", m_instance);
    236303
     304    // Retrieving the supported reference spaces requires an initialized session. There is no need to initialize all the graphics
     305    // stuff so we'll use a headless session that will be discarded after getting the info we need.
     306    auto sessionCreateInfo = createStructure<XrSessionCreateInfo, XR_TYPE_SESSION_CREATE_INFO>();
     307    sessionCreateInfo.systemId = m_systemId;
     308    XrSession ephemeralSession;
     309    result = xrCreateSession(m_instance, &sessionCreateInfo, &ephemeralSession);
     310    RETURN_IF_FAILED(result, "xrCreateSession", m_instance);
     311
     312    ListOfEnabledFeatures features = enumerateReferenceSpaces(ephemeralSession);
    237313    for (uint32_t i = 0; i < viewConfigurationCount; ++i) {
    238314        auto viewConfigurationProperties = createStructure<XrViewConfigurationProperties, XR_TYPE_VIEW_CONFIGURATION_PROPERTIES>();
     
    245321        switch (configType) {
    246322        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO:
    247             setEnabledFeatures(SessionMode::Inline, { });
     323            setEnabledFeatures(SessionMode::Inline, features);
    248324            break;
    249325        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO:
    250             setEnabledFeatures(SessionMode::ImmersiveVr, { });
     326            setEnabledFeatures(SessionMode::ImmersiveVr, features);
    251327            break;
    252328        default:
     
    255331        m_viewConfigurationProperties.add(configType, WTFMove(viewConfigurationProperties));
    256332    }
    257 }
    258 
    259 void OpenXRDevice::enumerateConfigurationViews()
     333    xrDestroySession(ephemeralSession);
     334}
     335
     336void OpenXRDevice::collectConfigurationViews()
    260337{
    261338    for (auto& config : m_viewConfigurationProperties.values()) {
     
    291368}
    292369
    293 
    294370#endif // USE_OPENXR
    295371
  • trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h

    r264215 r265137  
    4848private:
    4949    void collectSupportedSessionModes();
    50     void enumerateConfigurationViews();
     50    void collectConfigurationViews();
     51
     52    ListOfEnabledFeatures enumerateReferenceSpaces(XrSession&) const;
    5153
    5254    WebCore::IntSize recommendedResolution(SessionMode) final;
     
    5961    XrSystemId m_systemId;
    6062    XrInstance m_instance;
     63    XrSession m_session;
    6164};
    6265
Note: See TracChangeset for help on using the changeset viewer.