Commit f98a2005 authored by Lachlan Ford's avatar Lachlan Ford Committed by Commit Bot

Updated the OpenXR spec from 1.0.5 to 1.0.11

Updated the OpenXR spec which changes the way extension methods are
queried. I separated the extension support enumeration and method
querying.

Updating the spec retains backwards and forward compatibility with
apps as that is mediated through the loader which is unchanged.
Extension lookup is now dynamic, and after this change, we can
implement AR features on OpenXR (e.g. hand tracking, anchors etc.)

Change-Id: I8a4ae718ca244c91b85e02f9441525a9b1416b58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2406701Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarRafael Cintron <rafael.cintron@microsoft.com>
Commit-Queue: Lachlan Ford <laford@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#816823}
parent e88ad0e4
......@@ -1244,7 +1244,7 @@ deps = {
Var('chromium_git') + '/openscreen' + '@' + 'a3f46f23c52688cc3c0de927b7fb8a86ff9e8dff',
'src/third_party/openxr/src': {
'url': Var('chromium_git') + '/external/github.com/KhronosGroup/OpenXR-SDK' + '@' + '9e97b73e7dd2bfc07745489d728f6a36665c648f',
'url': Var('chromium_git') + '/external/github.com/KhronosGroup/OpenXR-SDK' + '@' + 'e3a4e41d61544d8e2eba73f00da99b6818ec472b',
'condition': 'checkout_openxr',
},
......
......@@ -383,6 +383,7 @@ config("cfi_linker") {
# tests with the full browser.
config("delayloads") {
ldflags = [
"/DELAYLOAD:api-ms-win-core-path-l1-1-0.dll",
"/DELAYLOAD:api-ms-win-core-winrt-error-l1-1-0.dll",
"/DELAYLOAD:api-ms-win-core-winrt-l1-1-0.dll",
"/DELAYLOAD:api-ms-win-core-winrt-string-l1-1-0.dll",
......
......@@ -229,9 +229,10 @@ if (enable_vr) {
"openxr/openxr_api_wrapper.h",
"openxr/openxr_controller.cc",
"openxr/openxr_controller.h",
"openxr/openxr_defs.h",
"openxr/openxr_device.cc",
"openxr/openxr_device.h",
"openxr/openxr_extension_helper.cc",
"openxr/openxr_extension_helper.h",
"openxr/openxr_input_helper.cc",
"openxr/openxr_input_helper.h",
"openxr/openxr_interaction_profiles.h",
......@@ -321,7 +322,8 @@ if (enable_openxr) {
include_dirs = [ "//third_party/openxr/src/include" ]
sources = [
"openxr/openxr_defs.h",
"openxr/openxr_extension_helper.cc",
"openxr/openxr_extension_helper.h",
"openxr/openxr_util.cc",
"openxr/openxr_util.h",
"openxr/test/fake_openxr_impl_api.cc",
......
......@@ -271,7 +271,8 @@ bool OpenXrApiWrapper::UpdateAndGetSessionEnded() {
// objects that may have been created before the failure.
XrResult OpenXrApiWrapper::InitSession(
const Microsoft::WRL::ComPtr<ID3D11Device>& d3d_device,
std::unique_ptr<OpenXRInputHelper>* input_helper) {
std::unique_ptr<OpenXRInputHelper>* input_helper,
const OpenXrExtensionHelper& extension_helper) {
DCHECK(d3d_device.Get());
DCHECK(IsInitialized());
......@@ -286,14 +287,13 @@ XrResult OpenXrApiWrapper::InitSession(
CreateSpace(XR_REFERENCE_SPACE_TYPE_STAGE, &stage_space_);
UpdateStageBounds();
OpenXrExtensionHelper extension_helper;
if (extension_helper.ExtensionSupported(
if (extension_helper.ExtensionEnumeration()->ExtensionSupported(
XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME)) {
RETURN_IF_XR_FAILED(
CreateSpace(XR_REFERENCE_SPACE_TYPE_UNBOUNDED_MSFT, &unbounded_space_));
}
RETURN_IF_XR_FAILED(CreateGamepadHelper(input_helper));
RETURN_IF_XR_FAILED(CreateGamepadHelper(input_helper, extension_helper));
// Since the objects in these arrays are used on every frame,
// we don't want to create and destroy these objects every frame,
......@@ -395,12 +395,13 @@ XrResult OpenXrApiWrapper::CreateSpace(XrReferenceSpaceType type,
}
XrResult OpenXrApiWrapper::CreateGamepadHelper(
std::unique_ptr<OpenXRInputHelper>* input_helper) {
std::unique_ptr<OpenXRInputHelper>* input_helper,
const OpenXrExtensionHelper& extension_helper) {
DCHECK(HasSession());
DCHECK(HasSpace(XR_REFERENCE_SPACE_TYPE_LOCAL));
return OpenXRInputHelper::CreateOpenXRInputHelper(instance_, session_,
local_space_, input_helper);
return OpenXRInputHelper::CreateOpenXRInputHelper(
instance_, extension_helper, session_, local_space_, input_helper);
}
XrResult OpenXrApiWrapper::BeginSession() {
......@@ -620,13 +621,20 @@ void OpenXrApiWrapper::GetHeadFromEyes(XrView* left, XrView* right) const {
*right = head_from_eye_views_[1];
}
XrResult OpenXrApiWrapper::GetLuid(LUID* luid) const {
XrResult OpenXrApiWrapper::GetLuid(
LUID* luid,
const OpenXrExtensionHelper& extension_helper) const {
DCHECK(IsInitialized());
if (extension_helper.ExtensionMethods().xrGetD3D11GraphicsRequirementsKHR ==
nullptr)
return XR_ERROR_FUNCTION_UNSUPPORTED;
XrGraphicsRequirementsD3D11KHR graphics_requirements = {
XR_TYPE_GRAPHICS_REQUIREMENTS_D3D11_KHR};
RETURN_IF_XR_FAILED(xrGetD3D11GraphicsRequirementsKHR(
instance_, system_, &graphics_requirements));
RETURN_IF_XR_FAILED(
extension_helper.ExtensionMethods().xrGetD3D11GraphicsRequirementsKHR(
instance_, system_, &graphics_requirements));
luid->LowPart = graphics_requirements.adapterLuid.LowPart;
luid->HighPart = graphics_requirements.adapterLuid.HighPart;
......
......@@ -47,7 +47,8 @@ class OpenXrApiWrapper {
bool UpdateAndGetSessionEnded();
XrResult InitSession(const Microsoft::WRL::ComPtr<ID3D11Device>& d3d_device,
std::unique_ptr<OpenXRInputHelper>* input_helper);
std::unique_ptr<OpenXRInputHelper>* input_helper,
const OpenXrExtensionHelper& extension_helper);
XrResult BeginFrame(Microsoft::WRL::ComPtr<ID3D11Texture2D>* texture);
XrResult EndFrame();
......@@ -60,7 +61,8 @@ class OpenXrApiWrapper {
gfx::Size GetViewSize() const;
XrTime GetPredictedDisplayTime() const;
XrResult GetLuid(LUID* luid) const;
XrResult GetLuid(LUID* luid,
const OpenXrExtensionHelper& extension_helper) const;
bool GetStageParameters(XrExtent2Df* stage_bounds,
gfx::Transform* local_from_stage);
void RegisterInteractionProfileChangeCallback(
......@@ -89,8 +91,8 @@ class OpenXrApiWrapper {
const Microsoft::WRL::ComPtr<ID3D11Device>& d3d_device);
XrResult CreateSwapchain();
XrResult CreateSpace(XrReferenceSpaceType type, XrSpace* space);
XrResult CreateGamepadHelper(
std::unique_ptr<OpenXRInputHelper>* input_helper);
XrResult CreateGamepadHelper(std::unique_ptr<OpenXRInputHelper>* input_helper,
const OpenXrExtensionHelper& extension_helper);
XrResult BeginSession();
XrResult UpdateProjectionLayers();
......
......@@ -143,8 +143,9 @@ XrResult OpenXrController::SuggestBindings(
const bool extension_required =
interaction_profile.required_extension != nullptr;
if (extension_required) {
const bool extension_enabled = extension_helper.ExtensionSupported(
interaction_profile.required_extension);
const bool extension_enabled =
extension_helper.ExtensionEnumeration()->ExtensionSupported(
interaction_profile.required_extension);
if (!extension_enabled) {
continue;
}
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_VR_OPENXR_OPENXR_DEFS_H_
#define DEVICE_VR_OPENXR_OPENXR_DEFS_H_
namespace device {
constexpr char kWin32AppcontainerCompatibleExtensionName[] =
"XR_EXT_win32_appcontainer_compatible";
constexpr char kExtSamsungOdysseyControllerExtensionName[] =
"XR_EXT_samsung_odyssey_controller";
constexpr char kExtHPMixedRealityControllerExtensionName[] =
"XR_EXT_hp_mixed_reality_controller";
} // namespace device
#endif // DEVICE_VR_OPENXR_OPENXR_DEFS_H_
......@@ -58,12 +58,13 @@ mojom::VRDisplayInfoPtr CreateFakeVRDisplayInfo() {
OpenXrDevice::OpenXrDevice(OpenXrStatics* openxr_statics)
: VRDeviceBase(device::mojom::XRDeviceId::OPENXR_DEVICE_ID),
instance_(openxr_statics->GetXrInstance()),
extension_helper_(instance_, openxr_statics->GetExtensionEnumeration()),
weak_ptr_factory_(this) {
mojom::VRDisplayInfoPtr display_info = CreateFakeVRDisplayInfo();
SetVRDisplayInfo(std::move(display_info));
SetArBlendModeSupported(IsArBlendModeSupported(openxr_statics));
#if defined(OS_WIN)
SetLuid(openxr_statics->GetLuid());
SetLuid(openxr_statics->GetLuid(extension_helper_));
#endif
}
......@@ -86,7 +87,7 @@ void OpenXrDevice::EnsureRenderLoop() {
auto on_info_changed = base::BindRepeating(&OpenXrDevice::SetVRDisplayInfo,
weak_ptr_factory_.GetWeakPtr());
render_loop_ = std::make_unique<OpenXrRenderLoop>(
std::move(on_info_changed), instance_);
std::move(on_info_changed), instance_, extension_helper_);
}
}
......
......@@ -8,6 +8,7 @@
#include <memory>
#include "base/macros.h"
#include "device/vr/openxr/openxr_util.h"
#include "device/vr/public/mojom/vr_service.mojom.h"
#include "device/vr/vr_device_base.h"
#include "device/vr/vr_export.h"
......@@ -53,6 +54,7 @@ class DEVICE_VR_EXPORT OpenXrDevice
bool IsArBlendModeSupported(OpenXrStatics* openxr_statics);
XrInstance instance_;
OpenXrExtensionHelper extension_helper_;
std::unique_ptr<OpenXrRenderLoop> render_loop_;
mojo::Receiver<mojom::XRSessionController> exclusive_controller_receiver_{
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/vr/openxr/openxr_extension_helper.h"
namespace device {
OpenXrExtensionEnumeration::OpenXrExtensionEnumeration() {
uint32_t extension_count;
if (XR_SUCCEEDED(xrEnumerateInstanceExtensionProperties(
nullptr, 0, &extension_count, nullptr))) {
extension_properties_.resize(extension_count,
{XR_TYPE_EXTENSION_PROPERTIES});
xrEnumerateInstanceExtensionProperties(nullptr, extension_count,
&extension_count,
extension_properties_.data());
}
}
OpenXrExtensionEnumeration::~OpenXrExtensionEnumeration() = default;
bool OpenXrExtensionEnumeration::ExtensionSupported(
const char* extension_name) const {
return std::find_if(
extension_properties_.begin(), extension_properties_.end(),
[&extension_name](const XrExtensionProperties& properties) {
return strcmp(properties.extensionName, extension_name) == 0;
}) != extension_properties_.end();
}
OpenXrExtensionHelper::~OpenXrExtensionHelper() = default;
OpenXrExtensionHelper::OpenXrExtensionHelper(
XrInstance instance,
const OpenXrExtensionEnumeration* const extension_enumeration)
: extension_enumeration_(extension_enumeration) {
// Failure results in a nullptr
(void)xrGetInstanceProcAddr(
instance, "xrGetD3D11GraphicsRequirementsKHR",
reinterpret_cast<PFN_xrVoidFunction*>(
const_cast<PFN_xrGetD3D11GraphicsRequirementsKHR*>(
&extension_methods_.xrGetD3D11GraphicsRequirementsKHR)));
}
} // namespace device
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_VR_OPENXR_OPENXR_EXTENSION_HELPER_H_
#define DEVICE_VR_OPENXR_OPENXR_EXTENSION_HELPER_H_
#include <d3d11.h>
#include <vector>
#include "base/logging.h"
#include "third_party/openxr/src/include/openxr/openxr.h"
#include "third_party/openxr/src/include/openxr/openxr_platform.h"
namespace device {
struct OpenXrExtensionMethods {
PFN_xrGetD3D11GraphicsRequirementsKHR xrGetD3D11GraphicsRequirementsKHR{
nullptr};
};
class OpenXrExtensionEnumeration {
public:
OpenXrExtensionEnumeration();
~OpenXrExtensionEnumeration();
bool ExtensionSupported(const char* extension_name) const;
private:
std::vector<XrExtensionProperties> extension_properties_;
};
class OpenXrExtensionHelper {
public:
OpenXrExtensionHelper(
XrInstance instance,
const OpenXrExtensionEnumeration* const extension_enumeration);
~OpenXrExtensionHelper();
const OpenXrExtensionEnumeration* ExtensionEnumeration() const {
return extension_enumeration_;
}
const OpenXrExtensionMethods& ExtensionMethods() const {
return extension_methods_;
}
private:
const OpenXrExtensionMethods extension_methods_;
const OpenXrExtensionEnumeration* const extension_enumeration_;
};
} // namespace device
#endif // DEVICE_VR_OPENXR_OPENXR_EXTENSION_HELPER_H_
......@@ -96,13 +96,14 @@ base::Optional<Gamepad> GetXrStandardGamepad(
XrResult OpenXRInputHelper::CreateOpenXRInputHelper(
XrInstance instance,
const OpenXrExtensionHelper& extension_helper,
XrSession session,
XrSpace local_space,
std::unique_ptr<OpenXRInputHelper>* helper) {
std::unique_ptr<OpenXRInputHelper> new_helper =
std::make_unique<OpenXRInputHelper>(session, local_space);
RETURN_IF_XR_FAILED(new_helper->Initialize(instance));
RETURN_IF_XR_FAILED(new_helper->Initialize(instance, extension_helper));
*helper = std::move(new_helper);
return XR_SUCCESS;
}
......@@ -114,7 +115,9 @@ OpenXRInputHelper::OpenXRInputHelper(XrSession session, XrSpace local_space)
OpenXRInputHelper::~OpenXRInputHelper() = default;
XrResult OpenXRInputHelper::Initialize(XrInstance instance) {
XrResult OpenXRInputHelper::Initialize(
XrInstance instance,
const OpenXrExtensionHelper& extension_helper) {
RETURN_IF_XR_FAILED(path_helper_->Initialize(instance));
// This map is used to store bindings for different kinds of interaction
......@@ -122,7 +125,6 @@ XrResult OpenXRInputHelper::Initialize(XrInstance instance) {
// on availability.
std::map<XrPath, std::vector<XrActionSuggestedBinding>> bindings;
OpenXrExtensionHelper extension_helper;
for (size_t i = 0; i < controller_states_.size(); i++) {
RETURN_IF_XR_FAILED(controller_states_[i].controller.Initialize(
static_cast<OpenXrHandednessType>(i), instance, session_,
......
......@@ -13,6 +13,7 @@
#include "device/vr/openxr/openxr_controller.h"
#include "device/vr/openxr/openxr_interaction_profiles.h"
#include "device/vr/openxr/openxr_util.h"
namespace device {
......@@ -20,6 +21,7 @@ class OpenXRInputHelper {
public:
static XrResult CreateOpenXRInputHelper(
XrInstance instance,
const OpenXrExtensionHelper& extension_helper,
XrSession session,
XrSpace local_space,
std::unique_ptr<OpenXRInputHelper>* helper);
......@@ -38,7 +40,8 @@ class OpenXRInputHelper {
private:
base::Optional<Gamepad> GetWebXRGamepad(const OpenXrController& controller);
XrResult Initialize(XrInstance instance);
XrResult Initialize(XrInstance instance,
const OpenXrExtensionHelper& extension_helper);
XrResult SyncActions(XrTime predicted_display_time);
......
......@@ -7,7 +7,6 @@
#include "base/stl_util.h"
#include "device/gamepad/public/cpp/gamepad.h"
#include "device/vr/openxr/openxr_defs.h"
#include "third_party/openxr/src/include/openxr/openxr.h"
namespace device {
......@@ -370,7 +369,7 @@ constexpr OpenXrControllerInteractionProfile kHTCViveInteractionProfile = {
constexpr OpenXrControllerInteractionProfile kSamsungOdysseyInteractionProfile =
{OpenXrInteractionProfileType::kSamsungOdyssey,
"/interaction_profiles/samsung/odyssey_controller",
kExtSamsungOdysseyControllerExtensionName,
XR_EXT_SAMSUNG_ODYSSEY_CONTROLLER_EXTENSION_NAME,
GamepadMapping::kXrStandard,
kSamsungOdysseyInputProfiles,
base::size(kSamsungOdysseyInputProfiles),
......@@ -384,7 +383,7 @@ constexpr OpenXrControllerInteractionProfile kSamsungOdysseyInteractionProfile =
constexpr OpenXrControllerInteractionProfile kHPReverbG2InteractionProfile = {
OpenXrInteractionProfileType::kHPReverbG2,
"/interaction_profiles/hp/mixed_reality_controller",
kExtHPMixedRealityControllerExtensionName,
XR_EXT_HP_MIXED_REALITY_CONTROLLER_EXTENSION_NAME,
GamepadMapping::kXrStandard,
kHPReverbG2InputProfiles,
base::size(kHPReverbG2InputProfiles),
......
......@@ -17,9 +17,11 @@ namespace device {
OpenXrRenderLoop::OpenXrRenderLoop(
base::RepeatingCallback<void(mojom::VRDisplayInfoPtr)>
on_display_info_changed,
XrInstance instance)
XrInstance instance,
const OpenXrExtensionHelper& extension_helper)
: XRCompositorCommon(),
instance_(instance),
extension_helper_(extension_helper),
on_display_info_changed_(std::move(on_display_info_changed)) {
DCHECK(instance_ != XR_NULL_HANDLE);
}
......@@ -91,11 +93,11 @@ bool OpenXrRenderLoop::StartRuntime() {
texture_helper_.SetUseBGRA(true);
LUID luid;
if (XR_FAILED(openxr->GetLuid(&luid)) ||
if (XR_FAILED(openxr->GetLuid(&luid, extension_helper_)) ||
!texture_helper_.SetAdapterLUID(luid) ||
!texture_helper_.EnsureInitialized() ||
XR_FAILED(
openxr->InitSession(texture_helper_.GetDevice(), &input_helper_))) {
XR_FAILED(openxr->InitSession(texture_helper_.GetDevice(), &input_helper_,
extension_helper_))) {
texture_helper_.Reset();
return false;
}
......
......@@ -10,6 +10,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "device/vr/openxr/openxr_util.h"
#include "device/vr/windows/compositor_base.h"
#include "third_party/openxr/src/include/openxr/openxr.h"
......@@ -24,7 +25,8 @@ class OpenXrRenderLoop : public XRCompositorCommon {
public:
OpenXrRenderLoop(base::RepeatingCallback<void(mojom::VRDisplayInfoPtr)>
on_display_info_changed,
XrInstance instance);
XrInstance instance,
const OpenXrExtensionHelper& extension_helper_);
~OpenXrRenderLoop() override;
private:
......@@ -53,6 +55,7 @@ class OpenXrRenderLoop : public XRCompositorCommon {
// Owned by OpenXrStatics
XrInstance instance_;
const OpenXrExtensionHelper& extension_helper_;
std::unique_ptr<OpenXrApiWrapper> openxr_;
std::unique_ptr<OpenXRInputHelper> input_helper_;
......
......@@ -17,7 +17,8 @@ OpenXrStatics::~OpenXrStatics() {
}
XrInstance OpenXrStatics::GetXrInstance() {
if (instance_ == XR_NULL_HANDLE && XR_FAILED(CreateInstance(&instance_))) {
if (instance_ == XR_NULL_HANDLE &&
XR_FAILED(CreateInstance(&instance_, extension_enumeration_))) {
return XR_NULL_HANDLE;
}
return instance_;
......@@ -39,7 +40,7 @@ bool OpenXrStatics::IsApiAvailable() {
#if defined(OS_WIN)
// Returns the LUID of the adapter the OpenXR runtime is on. Returns {0, 0} if
// the LUID could not be determined.
LUID OpenXrStatics::GetLuid() {
LUID OpenXrStatics::GetLuid(const OpenXrExtensionHelper& extension_helper) {
if (GetXrInstance() == XR_NULL_HANDLE)
return {0, 0};
......@@ -47,10 +48,15 @@ LUID OpenXrStatics::GetLuid() {
if (XR_FAILED(GetSystem(instance_, &system)))
return {0, 0};
if (extension_helper.ExtensionMethods().xrGetD3D11GraphicsRequirementsKHR ==
nullptr)
return {0, 0};
XrGraphicsRequirementsD3D11KHR graphics_requirements = {
XR_TYPE_GRAPHICS_REQUIREMENTS_D3D11_KHR};
if (XR_FAILED(xrGetD3D11GraphicsRequirementsKHR(instance_, system,
&graphics_requirements)))
if (XR_FAILED(
extension_helper.ExtensionMethods().xrGetD3D11GraphicsRequirementsKHR(
instance_, system, &graphics_requirements)))
return {0, 0};
return graphics_requirements.adapterLuid;
......
......@@ -9,6 +9,7 @@
#include <memory>
#include "build/build_config.h"
#include "device/vr/openxr/openxr_util.h"
#include "device/vr/vr_export.h"
#include "third_party/openxr/src/include/openxr/openxr.h"
#include "third_party/openxr/src/include/openxr/openxr_platform.h"
......@@ -22,17 +23,22 @@ class DEVICE_VR_EXPORT OpenXrStatics {
OpenXrStatics();
~OpenXrStatics();
const OpenXrExtensionEnumeration* GetExtensionEnumeration() const {
return &extension_enumeration_;
}
XrInstance GetXrInstance();
bool IsHardwareAvailable();
bool IsApiAvailable();
#if defined(OS_WIN)
LUID GetLuid();
LUID GetLuid(const OpenXrExtensionHelper& extension_helper);
#endif
private:
XrInstance instance_;
OpenXrExtensionEnumeration extension_enumeration_;
};
} // namespace device
......
......@@ -3,11 +3,8 @@
// found in the LICENSE file.
#include "device/vr/openxr/openxr_util.h"
#include "device/vr/openxr/openxr_defs.h"
#include <d3d11.h>
#include <string>
#include <vector>
#include "base/check_op.h"
#include "base/stl_util.h"
......@@ -15,7 +12,6 @@
#include "base/win/scoped_handle.h"
#include "build/build_config.h"
#include "components/version_info/version_info.h"
#include "third_party/openxr/src/include/openxr/openxr_platform.h"
namespace device {
......@@ -56,30 +52,9 @@ bool IsRunningInWin32AppContainer() {
}
#endif
OpenXrExtensionHelper::OpenXrExtensionHelper() {
uint32_t extension_count;
if (XR_SUCCEEDED(xrEnumerateInstanceExtensionProperties(
nullptr, 0, &extension_count, nullptr))) {
extension_properties_.resize(extension_count,
{XR_TYPE_EXTENSION_PROPERTIES});
xrEnumerateInstanceExtensionProperties(nullptr, extension_count,
&extension_count,
extension_properties_.data());
}
}
OpenXrExtensionHelper::~OpenXrExtensionHelper() = default;
bool OpenXrExtensionHelper::ExtensionSupported(
const char* extension_name) const {
return std::find_if(
extension_properties_.begin(), extension_properties_.end(),
[&extension_name](const XrExtensionProperties& properties) {
return strcmp(properties.extensionName, extension_name) == 0;
}) != extension_properties_.end();
}
XrResult CreateInstance(XrInstance* instance) {
XrResult CreateInstance(
XrInstance* instance,
const OpenXrExtensionEnumeration& extension_enumeration) {
XrInstanceCreateInfo instance_create_info = {XR_TYPE_INSTANCE_CREATE_INFO};
std::string application_name = version_info::GetProductName() + " " +
......@@ -121,15 +96,14 @@ XrResult CreateInstance(XrInstance* instance) {
// Add the win32 app container compatible extension to our list of
// extensions. If this runtime does not support execution in an app
// container environment, one of xrCreateInstance or xrGetSystem will fail.
extensions.push_back(kWin32AppcontainerCompatibleExtensionName);
extensions.push_back(XR_EXT_WIN32_APPCONTAINER_COMPATIBLE_EXTENSION_NAME);
}
// XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME, is required for optional
// functionality (unbounded reference spaces) and thus only requested if it is
// available.
OpenXrExtensionHelper extension_helper;
const bool unboundedSpaceExtensionSupported =
extension_helper.ExtensionSupported(
extension_enumeration.ExtensionSupported(
XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME);
if (unboundedSpaceExtensionSupported) {
extensions.push_back(XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME);
......@@ -138,17 +112,17 @@ XrResult CreateInstance(XrInstance* instance) {
// Input extensions. These enable interaction profiles not defined in the core
// spec
const bool samsungInteractionProfileExtensionSupported =
extension_helper.ExtensionSupported(
kExtSamsungOdysseyControllerExtensionName);
extension_enumeration.ExtensionSupported(
XR_EXT_SAMSUNG_ODYSSEY_CONTROLLER_EXTENSION_NAME);
if (samsungInteractionProfileExtensionSupported) {
extensions.push_back(kExtSamsungOdysseyControllerExtensionName);
extensions.push_back(XR_EXT_SAMSUNG_ODYSSEY_CONTROLLER_EXTENSION_NAME);
}
const bool hpControllerExtensionSupported =
extension_helper.ExtensionSupported(
kExtHPMixedRealityControllerExtensionName);
extension_enumeration.ExtensionSupported(
XR_EXT_HP_MIXED_REALITY_CONTROLLER_EXTENSION_NAME);
if (hpControllerExtensionSupported) {
extensions.push_back(kExtHPMixedRealityControllerExtensionName);
extensions.push_back(XR_EXT_HP_MIXED_REALITY_CONTROLLER_EXTENSION_NAME);
}
instance_create_info.enabledExtensionCount =
......
......@@ -5,23 +5,15 @@
#ifndef DEVICE_VR_OPENXR_OPENXR_UTIL_H_
#define DEVICE_VR_OPENXR_OPENXR_UTIL_H_
#include <d3d11.h>
#include <vector>
#include "base/logging.h"
#include "device/vr/openxr/openxr_extension_helper.h"
#include "third_party/openxr/src/include/openxr/openxr.h"
#include "third_party/openxr/src/include/openxr/openxr_platform.h"
namespace device {
class OpenXrExtensionHelper {
public:
OpenXrExtensionHelper();
~OpenXrExtensionHelper();
bool ExtensionSupported(const char* extension_name) const;
private:
std::vector<XrExtensionProperties> extension_properties_;
};
// These macros aren't common in Chromium and generally discouraged, so define
// all OpenXR helper macros here so they can be kept track of. This file
// should not be included outside of device/vr/openxr.
......@@ -58,7 +50,9 @@ XrPosef PoseIdentity();
XrResult GetSystem(XrInstance instance, XrSystemId* system);
XrResult CreateInstance(XrInstance* instance);
XrResult CreateInstance(
XrInstance* instance,
const OpenXrExtensionEnumeration& extension_enumeration);
std::vector<XrEnvironmentBlendMode> GetSupportedBlendModes(XrInstance instance,
XrSystemId system);
......
......@@ -16,6 +16,8 @@ namespace {
OpenXrTestHelper g_test_helper;
} // namespace
// Extension methods
// Mock implementations of openxr runtime.dll APIs.
// Please add new APIs in alphabetical order.
......@@ -903,3 +905,100 @@ XrResult xrWaitSwapchainImage(XrSwapchain swapchain,
return XR_SUCCESS;
}
// Getter for extension methods. Casts the correct function dynamically based on
// the method name provided.
// Please add new OpenXR APIs below in alphabetical order.
XrResult XRAPI_PTR xrGetInstanceProcAddr(XrInstance instance,
const char* name,
PFN_xrVoidFunction* function) {
if (strcmp(name, "xrAcquireSwapchainImage") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrAcquireSwapchainImage);
} else if (strcmp(name, "xrAttachSessionActionSets") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrAttachSessionActionSets);
} else if (strcmp(name, "xrBeginFrame") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrBeginFrame);
} else if (strcmp(name, "xrBeginSession") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrBeginSession);
} else if (strcmp(name, "xrCreateAction") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateAction);
} else if (strcmp(name, "xrCreateActionSet") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateActionSet);
} else if (strcmp(name, "xrCreateActionSpace") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateActionSpace);
} else if (strcmp(name, "xrCreateInstance") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateInstance);
} else if (strcmp(name, "xrCreateReferenceSpace") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateReferenceSpace);
} else if (strcmp(name, "xrCreateSession") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateSession);
} else if (strcmp(name, "xrCreateSwapchain") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateSwapchain);
} else if (strcmp(name, "xrDestroyActionSet") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrDestroyActionSet);
} else if (strcmp(name, "xrDestroyInstance") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrDestroyInstance);
} else if (strcmp(name, "xrDestroySpace") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrDestroySpace);
} else if (strcmp(name, "xrEndFrame") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrEndFrame);
} else if (strcmp(name, "xrEndSession") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrEndSession);
} else if (strcmp(name, "xrEnumerateEnvironmentBlendModes") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrEnumerateEnvironmentBlendModes);
} else if (strcmp(name, "xrEnumerateInstanceExtensionProperties") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(
xrEnumerateInstanceExtensionProperties);
} else if (strcmp(name, "xrEnumerateSwapchainImages") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrEnumerateSwapchainImages);
} else if (strcmp(name, "xrEnumerateViewConfigurationViews") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrEnumerateViewConfigurationViews);
} else if (strcmp(name, "xrGetD3D11GraphicsRequirementsKHR") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrGetD3D11GraphicsRequirementsKHR);
} else if (strcmp(name, "xrGetActionStateFloat") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrGetActionStateFloat);
} else if (strcmp(name, "xrGetActionStateBoolean") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrGetActionStateBoolean);
} else if (strcmp(name, "xrGetActionStateVector2f") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrGetActionStateVector2f);
} else if (strcmp(name, "xrGetActionStatePose") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrGetActionStatePose);
} else if (strcmp(name, "xrGetCurrentInteractionProfile") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrGetCurrentInteractionProfile);
} else if (strcmp(name, "xrGetReferenceSpaceBoundsRect") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrGetReferenceSpaceBoundsRect);
} else if (strcmp(name, "xrGetSystem") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrGetSystem);
} else if (strcmp(name, "xrLocateSpace") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrLocateSpace);
} else if (strcmp(name, "xrLocateViews") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrLocateViews);
} else if (strcmp(name, "xrPollEvent") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrPollEvent);
} else if (strcmp(name, "xrReleaseSwapchainImage") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrReleaseSwapchainImage);
} else if (strcmp(name, "xrSuggestInteractionProfileBindings") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(
xrSuggestInteractionProfileBindings);
} else if (strcmp(name, "xrStringToPath") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrStringToPath);
} else if (strcmp(name, "xrPathToString") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrPathToString);
} else if (strcmp(name, "xrSyncActions") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrSyncActions);
} else if (strcmp(name, "xrWaitFrame") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrWaitFrame);
} else if (strcmp(name, "xrWaitSwapchainImage") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrWaitSwapchainImage);
} else {
return XR_ERROR_FUNCTION_UNSUPPORTED;
}
return XR_SUCCESS;
}
\ No newline at end of file
......@@ -17,110 +17,19 @@
// only be used to call the fake OpenXR APIs defined in
// fake_openxr_impl_api.cc.
// Please add new OpenXR APIs below in alphabetical order.
XrResult XRAPI_PTR GetInstanceProcAddress(XrInstance instance,
const char* name,
PFN_xrVoidFunction* function) {
if (strcmp(name, "xrAcquireSwapchainImage") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrAcquireSwapchainImage);
} else if (strcmp(name, "xrAttachSessionActionSets") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrAttachSessionActionSets);
} else if (strcmp(name, "xrBeginFrame") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrBeginFrame);
} else if (strcmp(name, "xrBeginSession") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrBeginSession);
} else if (strcmp(name, "xrCreateAction") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateAction);
} else if (strcmp(name, "xrCreateActionSet") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateActionSet);
} else if (strcmp(name, "xrCreateActionSpace") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateActionSpace);
} else if (strcmp(name, "xrCreateInstance") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateInstance);
} else if (strcmp(name, "xrCreateReferenceSpace") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateReferenceSpace);
} else if (strcmp(name, "xrCreateSession") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateSession);
} else if (strcmp(name, "xrCreateSwapchain") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrCreateSwapchain);
} else if (strcmp(name, "xrDestroyActionSet") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrDestroyActionSet);
} else if (strcmp(name, "xrDestroyInstance") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrDestroyInstance);
} else if (strcmp(name, "xrDestroySpace") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrDestroySpace);
} else if (strcmp(name, "xrEndFrame") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrEndFrame);
} else if (strcmp(name, "xrEndSession") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrEndSession);
} else if (strcmp(name, "xrEnumerateEnvironmentBlendModes") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrEnumerateEnvironmentBlendModes);
} else if (strcmp(name, "xrEnumerateInstanceExtensionProperties") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(
xrEnumerateInstanceExtensionProperties);
} else if (strcmp(name, "xrEnumerateSwapchainImages") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrEnumerateSwapchainImages);
} else if (strcmp(name, "xrEnumerateViewConfigurationViews") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrEnumerateViewConfigurationViews);
} else if (strcmp(name, "xrGetD3D11GraphicsRequirementsKHR") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrGetD3D11GraphicsRequirementsKHR);
} else if (strcmp(name, "xrGetActionStateFloat") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrGetActionStateFloat);
} else if (strcmp(name, "xrGetActionStateBoolean") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrGetActionStateBoolean);
} else if (strcmp(name, "xrGetActionStateVector2f") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrGetActionStateVector2f);
} else if (strcmp(name, "xrGetActionStatePose") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrGetActionStatePose);
} else if (strcmp(name, "xrGetCurrentInteractionProfile") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrGetCurrentInteractionProfile);
} else if (strcmp(name, "xrGetReferenceSpaceBoundsRect") == 0) {
*function =
reinterpret_cast<PFN_xrVoidFunction>(xrGetReferenceSpaceBoundsRect);
} else if (strcmp(name, "xrGetSystem") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrGetSystem);
} else if (strcmp(name, "xrLocateSpace") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrLocateSpace);
} else if (strcmp(name, "xrLocateViews") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrLocateViews);
} else if (strcmp(name, "xrPollEvent") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrPollEvent);
} else if (strcmp(name, "xrReleaseSwapchainImage") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrReleaseSwapchainImage);
} else if (strcmp(name, "xrSuggestInteractionProfileBindings") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(
xrSuggestInteractionProfileBindings);
} else if (strcmp(name, "xrStringToPath") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrStringToPath);
} else if (strcmp(name, "xrPathToString") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrPathToString);
} else if (strcmp(name, "xrSyncActions") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrSyncActions);
} else if (strcmp(name, "xrWaitFrame") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrWaitFrame);
} else if (strcmp(name, "xrWaitSwapchainImage") == 0) {
*function = reinterpret_cast<PFN_xrVoidFunction>(xrWaitSwapchainImage);
} else {
return XR_ERROR_FUNCTION_UNSUPPORTED;
}
return XR_SUCCESS;
}
XrResult XRAPI_PTR xrGetInstanceProcAddr(XrInstance instance,
const char* name,
PFN_xrVoidFunction* function);
// The single exported function in fake OpenXR Runtime DLL which the OpenXR
// loader calls for negotiation. GetInstanceProcAddress is returned to the
// loader calls for negotiation. xrGetInstanceProcAddr is returned to the
// loader, which is then used by the loader to call OpenXR APIs.
XrResult __stdcall xrNegotiateLoaderRuntimeInterface(
const XrNegotiateLoaderInfo* loaderInfo,
XrNegotiateRuntimeRequest* runtimeRequest) {
runtimeRequest->runtimeInterfaceVersion = 1;
runtimeRequest->runtimeApiVersion = XR_MAKE_VERSION(1, 0, 1);
runtimeRequest->getInstanceProcAddr = GetInstanceProcAddress;
runtimeRequest->runtimeApiVersion = XR_CURRENT_API_VERSION;
runtimeRequest->getInstanceProcAddr = xrGetInstanceProcAddr;
return XR_SUCCESS;
}
......
......@@ -17,7 +17,6 @@
#include "base/optional.h"
#include "base/stl_util.h"
#include "base/synchronization/lock.h"
#include "device/vr/openxr/openxr_defs.h"
#include "device/vr/test/test_hook.h"
#include "third_party/openxr/src/include/openxr/openxr.h"
#include "third_party/openxr/src/include/openxr/openxr_platform.h"
......@@ -130,7 +129,7 @@ class OpenXrTestHelper : public device::ServiceTestHook {
// Properties of the mock OpenXR runtime that do not change are created
static constexpr const char* const kExtensions[] = {
XR_KHR_D3D11_ENABLE_EXTENSION_NAME,
device::kWin32AppcontainerCompatibleExtensionName};
XR_EXT_WIN32_APPCONTAINER_COMPATIBLE_EXTENSION_NAME};
static constexpr uint32_t kDimension = 128;
static constexpr uint32_t kSwapCount = 1;
static constexpr uint32_t kMinSwapchainBuffering = 3;
......
......@@ -24,7 +24,6 @@ if (enable_openxr) {
"src/src/common/extra_algorithms.h",
"src/src/common/filesystem_utils.cpp",
"src/src/common/filesystem_utils.hpp",
"src/src/common/hex_and_handles.cpp",
"src/src/common/hex_and_handles.h",
"src/src/common/loader_interfaces.h",
"src/src/common/object_info.cpp",
......@@ -59,6 +58,10 @@ if (enable_openxr) {
"src/src",
]
if (is_win) {
libs = [ "Pathcch.lib" ]
}
deps = [ "//third_party/jsoncpp" ]
public_configs = [ ":config" ]
......@@ -73,6 +76,7 @@ if (enable_openxr) {
"-Wno-microsoft-cast",
"-Wno-microsoft-include",
"-Wno-unused-function",
"-Wno-extra-semi",
]
}
......
Name: OpenXR SDK
Short Name: OpenXR
URL: https://github.com/KhronosGroup/OpenXR-SDK
Version: 1.0.5sd
Revision: 9e97b73e7dd2bfc07745489d728f6a36665c648f
Version: 1.0.11sd
Revision: e3a4e41d61544d8e2eba73f00da99b6818ec472b
License: Apache 2.0
License File: src/LICENSE
Security Critical: yes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment