Only suggest bindings for interaction profiles that are supported by the runtime
This commit is contained in:
+84
-34
@@ -28,6 +28,9 @@
|
||||
#include "vk/vk.h"
|
||||
#include "xr/xr.h"
|
||||
#include <algorithm>
|
||||
#include "utils/contains.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <vk_mem_alloc.h>
|
||||
@@ -51,12 +54,19 @@
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
using action_bindings = std::vector<std::string>;
|
||||
using suggested_binding = std::pair<std::string, action_bindings>;
|
||||
|
||||
static inline const std::vector<suggested_binding> suggested_bindings{
|
||||
struct suggested_binding
|
||||
{
|
||||
std::string profile_name;
|
||||
std::vector<std::string> required_extensions;
|
||||
std::vector<std::string> paths;
|
||||
bool available;
|
||||
};
|
||||
|
||||
static std::vector<suggested_binding> suggested_bindings{
|
||||
suggested_binding{
|
||||
"/interaction_profiles/oculus/touch_controller",
|
||||
{},
|
||||
{
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
@@ -95,6 +105,7 @@ static inline const std::vector<suggested_binding> suggested_bindings{
|
||||
}},
|
||||
suggested_binding{
|
||||
"/interaction_profiles/khr/simple_controller",
|
||||
{},
|
||||
{
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
@@ -114,6 +125,7 @@ static inline const std::vector<suggested_binding> suggested_bindings{
|
||||
}},
|
||||
suggested_binding{
|
||||
"/interaction_profiles/bytedance/pico_neo3_controller",
|
||||
{ "XR_BD_controller_interaction" },
|
||||
{
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
@@ -155,6 +167,7 @@ static inline const std::vector<suggested_binding> suggested_bindings{
|
||||
}},
|
||||
suggested_binding{
|
||||
"/interaction_profiles/bytedance/pico4_controller",
|
||||
{ "XR_BD_controller_interaction" },
|
||||
{
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
@@ -196,13 +209,28 @@ static inline const std::vector<suggested_binding> suggested_bindings{
|
||||
|
||||
static const std::pair<std::string_view, XrActionType> action_suffixes[] =
|
||||
{
|
||||
{"/haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||
{"/pose", XR_ACTION_TYPE_POSE_INPUT},
|
||||
{"/click", XR_ACTION_TYPE_BOOLEAN_INPUT},
|
||||
{"/touch", XR_ACTION_TYPE_BOOLEAN_INPUT},
|
||||
{"/value", XR_ACTION_TYPE_FLOAT_INPUT},
|
||||
// clang-format off
|
||||
// From OpenXR spec 1.0.33, §6.3.2 Input subpaths
|
||||
|
||||
// Standard components
|
||||
{"/click", XR_ACTION_TYPE_BOOLEAN_INPUT},
|
||||
{"/touch", XR_ACTION_TYPE_BOOLEAN_INPUT},
|
||||
{"/force", XR_ACTION_TYPE_FLOAT_INPUT},
|
||||
{"/value", XR_ACTION_TYPE_FLOAT_INPUT},
|
||||
{"/x", XR_ACTION_TYPE_FLOAT_INPUT},
|
||||
{"/y", XR_ACTION_TYPE_FLOAT_INPUT},
|
||||
{"/twist", XR_ACTION_TYPE_FLOAT_INPUT},
|
||||
{"/pose", XR_ACTION_TYPE_POSE_INPUT},
|
||||
|
||||
// Standard 2D identifier, can be used without the /x and /y cmoponents
|
||||
{"/trackpad", XR_ACTION_TYPE_VECTOR2F_INPUT},
|
||||
{"/thumbstick", XR_ACTION_TYPE_VECTOR2F_INPUT},
|
||||
{"/trackpad", XR_ACTION_TYPE_VECTOR2F_INPUT},
|
||||
{"/joystick", XR_ACTION_TYPE_VECTOR2F_INPUT},
|
||||
{"/trackball", XR_ACTION_TYPE_VECTOR2F_INPUT},
|
||||
|
||||
// Output paths
|
||||
{"/haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
static XrActionType guess_action_type(const std::string & name)
|
||||
@@ -492,11 +520,16 @@ void application::initialize_actions()
|
||||
|
||||
// Build the list of all possible actions, without duplicates
|
||||
std::vector<std::string> actions_path;
|
||||
for(const auto & [profile_name, bindings]: suggested_bindings)
|
||||
for(auto & suggested_binding: suggested_bindings)
|
||||
{
|
||||
for(const std::string& action_path: bindings)
|
||||
suggested_binding.available = utils::contains_all(xr_extensions, suggested_binding.required_extensions);
|
||||
|
||||
if (!suggested_binding.available)
|
||||
continue;
|
||||
|
||||
for(const std::string& action_path: suggested_binding.paths)
|
||||
{
|
||||
if (std::find(actions_path.begin(), actions_path.end(), action_path) == actions_path.end())
|
||||
if (!utils::contains(actions_path, action_path))
|
||||
actions_path.push_back(action_path);
|
||||
}
|
||||
}
|
||||
@@ -531,26 +564,23 @@ void application::initialize_actions()
|
||||
}
|
||||
|
||||
// Suggest bindings for all supported controllers
|
||||
for (const auto & [profile_name, bindings]: suggested_bindings)
|
||||
for (const auto & suggested_binding: suggested_bindings)
|
||||
{
|
||||
if (!suggested_binding.available)
|
||||
{
|
||||
spdlog::info("Skipping interaction profile {}", suggested_binding.profile_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<XrActionSuggestedBinding> xr_bindings;
|
||||
|
||||
for (const auto & name: bindings)
|
||||
for (const auto & name: suggested_binding.paths)
|
||||
{
|
||||
xr_bindings.push_back({actions_by_name[name], string_to_path(name)});
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
xr_instance.suggest_bindings(profile_name, xr_bindings);
|
||||
}
|
||||
catch(std::system_error& e)
|
||||
{
|
||||
if (e.code().category() == xr::error_category() && e.code().value() == XR_ERROR_PATH_UNSUPPORTED)
|
||||
spdlog::debug("Ignoring unsupported interaction profile: {}", profile_name);
|
||||
else
|
||||
throw;
|
||||
}
|
||||
spdlog::info("Suggesting bindings for interaction profile {}", suggested_binding.profile_name);
|
||||
xr_instance.suggest_bindings(suggested_binding.profile_name, xr_bindings);
|
||||
}
|
||||
|
||||
xr_session.attach_actionsets({xr_actionset});
|
||||
@@ -560,14 +590,34 @@ void application::initialize()
|
||||
{
|
||||
// LogLayersAndExtensions
|
||||
assert(!xr_instance);
|
||||
std::vector<const char *> extensions{XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME /*, XR_KHR_COMPOSITION_LAYER_COLOR_SCALE_BIAS_EXTENSION_NAME*/};
|
||||
xr_extensions.clear();
|
||||
|
||||
for (XrExtensionProperties & i: xr::instance::extensions())
|
||||
// Required extensions
|
||||
xr_extensions.push_back(XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME);
|
||||
|
||||
// Optional extensions
|
||||
std::vector<std::string> opt_extensions;
|
||||
opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_COLOR_SCALE_BIAS_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME);
|
||||
|
||||
for(const auto& i:suggested_bindings)
|
||||
{
|
||||
if (!strcmp(i.extensionName, XR_KHR_COMPOSITION_LAYER_COLOR_SCALE_BIAS_EXTENSION_NAME))
|
||||
extensions.push_back(XR_KHR_COMPOSITION_LAYER_COLOR_SCALE_BIAS_EXTENSION_NAME);
|
||||
if (!strcmp(i.extensionName, XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME))
|
||||
extensions.push_back(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME);
|
||||
for(const auto& j: i.required_extensions)
|
||||
{
|
||||
opt_extensions.push_back(j);
|
||||
}
|
||||
}
|
||||
|
||||
for(const auto& i: xr::instance::extensions())
|
||||
{
|
||||
if (utils::contains(opt_extensions, i.extensionName))
|
||||
xr_extensions.push_back(i.extensionName);
|
||||
}
|
||||
|
||||
std::vector<const char *> extensions;
|
||||
for(const auto& i: xr_extensions)
|
||||
{
|
||||
extensions.push_back(i.c_str());
|
||||
}
|
||||
|
||||
#ifdef XR_USE_PLATFORM_ANDROID
|
||||
@@ -1062,12 +1112,12 @@ void application::interaction_profile_changed()
|
||||
|
||||
spdlog::info("Current interaction profile for {}: {}", device, current_profile);
|
||||
|
||||
for(const auto& [profile, actions_name]: suggested_bindings)
|
||||
for(const auto& binding: suggested_bindings)
|
||||
{
|
||||
if (profile != current_profile)
|
||||
if (binding.profile_name != current_profile)
|
||||
continue;
|
||||
|
||||
for(const std::string& action_name: actions_name)
|
||||
for(const std::string& action_name: binding.paths)
|
||||
{
|
||||
if (!action_name.starts_with(device))
|
||||
continue;
|
||||
|
||||
@@ -115,6 +115,7 @@ class application : public singleton<application>
|
||||
bool session_focused = false;
|
||||
bool session_visible = false;
|
||||
bool debug_extensions_found = false;
|
||||
std::vector<std::string> xr_extensions;
|
||||
std::atomic<bool> exit_requested = false;
|
||||
|
||||
std::string server_address;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
|
||||
template<typename Rng, typename T>
|
||||
bool contains(Rng&& range, const T& value)
|
||||
{
|
||||
auto it = std::find(range.begin(), range.end(), value);
|
||||
|
||||
return it != range.end();
|
||||
}
|
||||
|
||||
// Check if all values of range2 are in range1
|
||||
template<typename Rng1, typename Rng2>
|
||||
bool contains_all(Rng1&& range1, Rng2&& range2)
|
||||
{
|
||||
for(const auto& i: range2)
|
||||
{
|
||||
if (!contains(range1, i))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user