Try to request OpenXR 1.1
This commit is contained in:
+68
-59
@@ -26,7 +26,6 @@
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utils/contains.h"
|
||||
#include "utils/files.h"
|
||||
#include "utils/named_thread.h"
|
||||
#include "vk/check.h"
|
||||
#include "wifi_lock.h"
|
||||
#include "xr/actionset.h"
|
||||
@@ -51,6 +50,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "utils/named_thread.h"
|
||||
#include <android/native_activity.h>
|
||||
#include <sys/system_properties.h>
|
||||
|
||||
@@ -66,15 +66,16 @@ struct interaction_profile
|
||||
{
|
||||
std::string profile_name;
|
||||
std::vector<std::string> required_extensions;
|
||||
XrVersion min_version = XR_MAKE_VERSION(1, 0, 0);
|
||||
XrVersion max_version = XR_MAKE_VERSION(2, 0, 0); // exclusive
|
||||
std::vector<std::string> input_sources;
|
||||
bool available;
|
||||
};
|
||||
|
||||
static std::vector<interaction_profile> interaction_profiles{
|
||||
interaction_profile{
|
||||
"/interaction_profiles/khr/simple_controller",
|
||||
{},
|
||||
{
|
||||
.profile_name = "/interaction_profiles/khr/simple_controller",
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
|
||||
@@ -90,11 +91,11 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
"/user/hand/right/input/menu/click",
|
||||
"/user/hand/right/input/select/click",
|
||||
|
||||
}},
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
"/interaction_profiles/oculus/touch_controller",
|
||||
{},
|
||||
{
|
||||
.profile_name = "/interaction_profiles/oculus/touch_controller",
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
|
||||
@@ -129,11 +130,13 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
"/user/hand/right/input/thumbstick/click",
|
||||
"/user/hand/right/input/thumbstick/touch",
|
||||
"/user/hand/right/input/thumbrest/touch",
|
||||
}},
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
"/interaction_profiles/facebook/touch_controller_pro",
|
||||
{"XR_FB_touch_controller_pro"},
|
||||
{
|
||||
.profile_name = "/interaction_profiles/facebook/touch_controller_pro",
|
||||
.required_extensions = {"XR_FB_touch_controller_pro"},
|
||||
.max_version = XR_MAKE_VERSION(1, 1, 0),
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/left/output/haptic_trigger_fb",
|
||||
"/user/hand/left/output/haptic_thumb_fb",
|
||||
@@ -184,11 +187,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
"/user/hand/right/input/trigger/slide_fb",
|
||||
"/user/hand/right/input/trigger/proximity_fb",
|
||||
"/user/hand/right/input/thumb_fb/proximity_fb",
|
||||
}},
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
"/interaction_profiles/meta/touch_pro_controller",
|
||||
{"XR_VERSION_1_1"},
|
||||
{
|
||||
.profile_name = "/interaction_profiles/meta/touch_pro_controller",
|
||||
.min_version = XR_MAKE_VERSION(1, 1, 0),
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/left/output/haptic_trigger",
|
||||
"/user/hand/left/output/haptic_thumb",
|
||||
@@ -239,12 +243,13 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
"/user/hand/right/input/thumbrest/touch",
|
||||
"/user/hand/right/input/thumbrest/force",
|
||||
"/user/hand/right/input/stylus/force",
|
||||
|
||||
}},
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
"/interaction_profiles/meta/touch_controller_plus",
|
||||
{"XR_META_touch_controller_plus"},
|
||||
{
|
||||
.profile_name = "/interaction_profiles/meta/touch_controller_plus",
|
||||
.required_extensions = {"XR_META_touch_controller_plus"},
|
||||
.max_version = XR_MAKE_VERSION(1, 1, 0),
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
|
||||
@@ -288,11 +293,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
"/user/hand/right/input/trigger/slide_meta",
|
||||
"/user/hand/right/input/trigger/force",
|
||||
|
||||
}},
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
"/interaction_profiles/meta/touch_plus_controller",
|
||||
{"XR_VERSION_1_1"},
|
||||
{
|
||||
.profile_name = "/interaction_profiles/meta/touch_plus_controller",
|
||||
.min_version = XR_MAKE_VERSION(1, 1, 0),
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
|
||||
@@ -338,11 +344,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
"/user/hand/right/input/thumbstick/touch",
|
||||
"/user/hand/right/input/thumbrest/touch",
|
||||
|
||||
}},
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
"/interaction_profiles/bytedance/pico_neo3_controller",
|
||||
{"XR_BD_controller_interaction"},
|
||||
{
|
||||
.profile_name = "/interaction_profiles/bytedance/pico_neo3_controller",
|
||||
.required_extensions = {"XR_BD_controller_interaction"},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
|
||||
@@ -380,11 +387,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
"/user/hand/right/input/thumbstick/click",
|
||||
"/user/hand/right/input/thumbstick/touch",
|
||||
|
||||
}},
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
"/interaction_profiles/bytedance/pico4_controller",
|
||||
{"XR_BD_controller_interaction"},
|
||||
{
|
||||
.profile_name = "/interaction_profiles/bytedance/pico4_controller",
|
||||
.required_extensions = {"XR_BD_controller_interaction"},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
|
||||
@@ -422,11 +430,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
"/user/hand/right/input/thumbstick/touch",
|
||||
"/user/hand/right/input/squeeze/click",
|
||||
"/user/hand/right/input/squeeze/value",
|
||||
}},
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
"/interaction_profiles/bytedance/pico4s_controller",
|
||||
{"XR_BD_controller_interaction"},
|
||||
{
|
||||
.profile_name = "/interaction_profiles/bytedance/pico4s_controller",
|
||||
.required_extensions = {"XR_BD_controller_interaction"},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
|
||||
@@ -464,11 +473,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
"/user/hand/right/input/thumbstick/touch",
|
||||
"/user/hand/right/input/squeeze/click",
|
||||
"/user/hand/right/input/squeeze/value",
|
||||
}},
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
"/interaction_profiles/htc/vive_focus3_controller",
|
||||
{"XR_HTC_vive_focus3_controller_interaction"},
|
||||
{
|
||||
.profile_name = "/interaction_profiles/htc/vive_focus3_controller",
|
||||
.required_extensions = {"XR_HTC_vive_focus3_controller_interaction"},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
|
||||
@@ -505,18 +515,19 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
"/user/hand/right/input/thumbstick/click",
|
||||
"/user/hand/right/input/thumbstick/touch",
|
||||
"/user/hand/right/input/thumbrest/touch",
|
||||
}},
|
||||
interaction_profile{
|
||||
"/interaction_profiles/htc/vive_xr_tracker",
|
||||
{"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"},
|
||||
{},
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
"/interaction_profiles/ext/eye_gaze_interaction",
|
||||
{"XR_EXT_eye_gaze_interaction"},
|
||||
{
|
||||
.profile_name = "/interaction_profiles/htc/vive_xr_tracker",
|
||||
.required_extensions = {"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"},
|
||||
},
|
||||
interaction_profile{
|
||||
.profile_name = "/interaction_profiles/ext/eye_gaze_interaction",
|
||||
.required_extensions = {"XR_EXT_eye_gaze_interaction"},
|
||||
.input_sources = {
|
||||
"/user/eyes_ext/input/gaze_ext/pose",
|
||||
}},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static const std::pair<std::string_view, XrActionType> action_suffixes[] =
|
||||
@@ -910,12 +921,13 @@ void application::initialize_actions()
|
||||
|
||||
std::unordered_map<std::string, std::vector<XrActionSuggestedBinding>> suggested_bindings;
|
||||
|
||||
XrVersion api_version = xr_instance.get_api_version();
|
||||
// Build the list of all possible input sources, without duplicates,
|
||||
// checking which profiles are supported by the runtime
|
||||
std::vector<std::string> sources;
|
||||
for (auto & profile: interaction_profiles)
|
||||
{
|
||||
profile.available = utils::contains_all(xr_extensions, profile.required_extensions);
|
||||
profile.available = utils::contains_all(xr_extensions, profile.required_extensions) and profile.min_version <= api_version and profile.max_version > api_version;
|
||||
|
||||
if (!profile.available)
|
||||
continue;
|
||||
@@ -1080,13 +1092,7 @@ void application::initialize()
|
||||
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME);
|
||||
|
||||
for (const auto & i: interaction_profiles)
|
||||
{
|
||||
for (const auto & j: i.required_extensions)
|
||||
{
|
||||
if (not j.starts_with("XR_VERSION"))
|
||||
opt_extensions.push_back(j);
|
||||
}
|
||||
}
|
||||
opt_extensions.insert(opt_extensions.end(), i.required_extensions.begin(), i.required_extensions.end());
|
||||
|
||||
for (const auto & i: xr::instance::extensions())
|
||||
{
|
||||
@@ -1107,7 +1113,10 @@ void application::initialize()
|
||||
xr_instance = xr::instance(app_info.name, extensions);
|
||||
#endif
|
||||
|
||||
spdlog::info("Created OpenXR instance, runtime {}, version {}", xr_instance.get_runtime_name(), xr_instance.get_runtime_version());
|
||||
spdlog::info("Created OpenXR instance, runtime {}, version {}, API version {}",
|
||||
xr_instance.get_runtime_name(),
|
||||
xr_instance.get_runtime_version(),
|
||||
xr::to_string(xr_instance.get_api_version()));
|
||||
|
||||
xr_system_id = xr::system(xr_instance, app_info.formfactor);
|
||||
spdlog::info("Created OpenXR system for form factor {}", xr::to_string(app_info.formfactor));
|
||||
|
||||
+21
-3
@@ -40,6 +40,26 @@ static XrBool32 debug_callback(
|
||||
return XR_FALSE;
|
||||
}
|
||||
|
||||
static std::pair<XrVersion, XrInstance> create_instance(XrInstanceCreateInfo & info)
|
||||
{
|
||||
XrResult res;
|
||||
for (XrVersion version: {
|
||||
XR_API_VERSION_1_1,
|
||||
XR_API_VERSION_1_0,
|
||||
})
|
||||
{
|
||||
info.applicationInfo.apiVersion = version;
|
||||
XrInstance inst;
|
||||
res = xrCreateInstance(&info, &inst);
|
||||
if (XR_SUCCEEDED(res))
|
||||
return {version, inst};
|
||||
spdlog::info("Failed to create OpenXR instance version {}: {}",
|
||||
xr::to_string(version),
|
||||
xr::to_string(res));
|
||||
}
|
||||
throw std::system_error(res, xr::error_category(), "Failed to create OpenXR instance");
|
||||
}
|
||||
|
||||
#if defined(XR_USE_PLATFORM_ANDROID)
|
||||
xr::instance::instance(std::string_view application_name, void * applicationVM, void * applicationActivity, std::vector<const char *> extensions)
|
||||
#else
|
||||
@@ -122,7 +142,6 @@ xr::instance::instance(std::string_view application_name, std::vector<const char
|
||||
|
||||
XrInstanceCreateInfo create_info{
|
||||
.type = XR_TYPE_INSTANCE_CREATE_INFO,
|
||||
.applicationInfo = {.apiVersion = XR_MAKE_VERSION(1, 0, 0)},
|
||||
.enabledApiLayerCount = (uint32_t)layers.size(),
|
||||
.enabledApiLayerNames = layers.data(),
|
||||
.enabledExtensionCount = (uint32_t)extensions.size(),
|
||||
@@ -139,8 +158,7 @@ xr::instance::instance(std::string_view application_name, std::vector<const char
|
||||
create_info.next = &instanceCreateInfoAndroid;
|
||||
#endif
|
||||
|
||||
CHECK_XR(xrCreateInstance(&create_info, &id));
|
||||
assert(id != XR_NULL_HANDLE);
|
||||
std::tie(api_version, id) = create_instance(create_info);
|
||||
|
||||
if (debug_utils_found)
|
||||
{
|
||||
|
||||
@@ -49,6 +49,7 @@ class instance : public utils::handle<XrInstance, xrDestroyInstance>
|
||||
std::string runtime_version;
|
||||
std::string runtime_name;
|
||||
std::unordered_map<std::string, uint32_t> loaded_extensions;
|
||||
XrVersion api_version;
|
||||
|
||||
public:
|
||||
#if defined(XR_USE_PLATFORM_ANDROID)
|
||||
@@ -70,6 +71,11 @@ public:
|
||||
return runtime_name;
|
||||
}
|
||||
|
||||
XrVersion get_api_version() const
|
||||
{
|
||||
return api_version;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
F get_proc(const char * name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user