Add debug options:

- Log driver version when starting
- Add debug menu to offset the controller mesh positions/orientations in the lobby
This commit is contained in:
Guillaume Meunier
2024-11-01 14:13:58 +01:00
parent d96f7f07a1
commit 33bde8be57
14 changed files with 1443 additions and 53 deletions
+1
View File
@@ -45,6 +45,7 @@ option(WIVRN_FEATURE_STEAMVR_LIGHTHOUSE "Enable SteamVR Lighthouse driver" OFF)
option(WIVRN_CHECK_CAPSYSNICE "Check if CAP_SYS_NICE is available at startup" ON)
option(WIVRN_SHOW_IMGUI_DEMO_WINDOW "Show the Dear ImGui demo window in the client" OFF)
option(WIVRN_CLIENT_DEBUG_MENU "Enable the debug menu in the client" OFF)
option(WIVRN_OPENXR_INSTALL_ABSOLUTE_RUNTIME_PATH OFF)
Binary file not shown.
+26 -2
View File
@@ -359,6 +359,28 @@ VkBool32 application::vulkan_debug_report_callback(
return VK_FALSE;
}
std::string parse_driver_sersion(const vk::PhysicalDeviceProperties & p)
{
// See https://github.com/SaschaWillems/vulkan.gpuinfo.org/blob/1e6ca6e3c0763daabd6a101b860ab4354a07f5d3/functions.php#L294
switch (p.vendorID)
{
case 0x10de: // nvidia
return fmt::format(
"{}.{}.{}.{}",
(p.driverVersion >> 22) & 0x3ff,
(p.driverVersion >> 14) & 0xff,
(p.driverVersion >> 6) & 0xff,
p.driverVersion & 0x3f);
default:
return fmt::format(
"{}.{}.{}",
VK_VERSION_MAJOR(p.driverVersion),
VK_VERSION_MINOR(p.driverVersion),
VK_VERSION_PATCH(p.driverVersion));
}
}
void application::initialize_vulkan()
{
auto graphics_requirements = xr_system_id.graphics_requirements();
@@ -493,8 +515,10 @@ void application::initialize_vulkan()
vk_device_extensions.push_back(it->data());
}
vk::PhysicalDeviceProperties prop = vk_physical_device.getProperties();
spdlog::info("Initializing Vulkan with device {}", prop.deviceName.data());
spdlog::info("Initializing Vulkan with device {}", physical_device_properties.deviceName.data());
spdlog::info(" Vendor ID: 0x{:04x}", physical_device_properties.vendorID);
spdlog::info(" Device ID: 0x{:04x}", physical_device_properties.deviceID);
spdlog::info(" Driver version: {}", parse_driver_sersion(physical_device_properties));
std::vector<vk::QueueFamilyProperties> queue_properties = vk_physical_device.getQueueFamilyProperties();
+36
View File
@@ -233,6 +233,42 @@ std::string controller_name()
__builtin_unreachable();
}
std::pair<glm::vec3, glm::quat> controller_offset(std::string_view profile, xr::spaces space)
{
if (profile == "oculus-touch-v2")
switch (space)
{
case xr::spaces::grip_left:
case xr::spaces::grip_right:
return {{0, -0.006, -0.025}, glm::angleAxis(glm::radians(-15.f), glm::vec3{1, 0, 0})};
case xr::spaces::aim_left:
return {{-0.010, 0, 0.025}, {1, 0, 0, 0}};
case xr::spaces::aim_right:
return {{0.010, 0, 0.025}, {1, 0, 0, 0}};
default:
break;
}
else if (profile == "htc-vive-focus-3")
switch (space)
{
case xr::spaces::grip_left:
case xr::spaces::grip_right:
return {{0, 0.007, -0.030}, {1, 0, 0, 0}};
case xr::spaces::aim_left:
case xr::spaces::aim_right:
return {{0, -0.025, 0.005}, {1, 0, 0, 0}};
default:
break;
}
return {{0, 0, 0}, {1, 0, 0, 0}};
}
std::string controller_ray_model_name()
{
switch (guess_model())
+6 -1
View File
@@ -18,8 +18,12 @@
*/
#pragma once
#include <openxr/openxr.h>
#include "xr/space.h"
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <string>
#include <utility>
#include <openxr/openxr.h>
enum class model
{
@@ -54,3 +58,4 @@ const char * permission_name(feature f);
std::string controller_name();
std::string controller_ray_model_name();
std::pair<glm::vec3, glm::quat> controller_offset(std::string_view profile, xr::spaces space);
+2 -2
View File
@@ -653,8 +653,8 @@ std::vector<imgui_context::controller_state> imgui_context::read_controllers_sta
if (auto location = application::locate_controller(ctrl.aim, world, display_time))
{
new_state.active = true;
new_state.aim_position = location->first;
new_state.aim_orientation = location->second;
new_state.aim_position = location->first + glm::mat3_cast(location->second * ctrl.offset.second) * ctrl.offset.first;
new_state.aim_orientation = location->second * ctrl.offset.second;
if (ctrl.trigger)
{
+2
View File
@@ -60,6 +60,8 @@ public:
struct controller
{
XrSpace aim;
std::pair<glm::vec3, glm::quat> offset;
XrAction trigger; // XR_ACTION_TYPE_FLOAT_INPUT
XrAction squeeze; // XR_ACTION_TYPE_FLOAT_INPUT
XrAction scroll; // XR_ACTION_TYPE_VECTOR2F_INPUT
+20 -13
View File
@@ -212,15 +212,15 @@ input_profile::input_profile(const std::filesystem::path & json_profile, scene_l
node_handle root_node = scene_controllers.new_node();
root_node->name = layout;
XrSpace space;
xr::spaces space;
if (layout == "left")
space = application::space(xr::spaces::grip_left);
space = xr::spaces::grip_left;
else if (layout == "right")
space = application::space(xr::spaces::grip_right);
space = xr::spaces::grip_right;
else if (layout == "left_aim")
space = application::space(xr::spaces::aim_left);
space = xr::spaces::aim_left;
else if (layout == "right_aim")
space = application::space(xr::spaces::aim_right);
space = xr::spaces::aim_right;
else
continue;
@@ -231,11 +231,11 @@ input_profile::input_profile(const std::filesystem::path & json_profile, scene_l
for (simdjson::dom::key_value_pair layout: simdjson::dom::object(root["layouts"]))
{
XrSpace space;
xr::spaces space;
if (layout.key == "left")
space = application::space(xr::spaces::aim_left);
space = xr::spaces::aim_left;
else if (layout.key == "right")
space = application::space(xr::spaces::aim_right);
space = xr::spaces::aim_right;
else
continue;
@@ -304,6 +304,8 @@ input_profile::input_profile(const std::filesystem::path & json_profile, scene_l
response.target.node = scene_controllers.find_node(controller_root_node, json_response.target_node);
response.target.state = json_response.state;
}
offset.fill({{0, 0, 0}, {1, 0, 0, 0}});
}
static void apply_visual_response(node_handle node, std::pair<input_profile::node_state_transform, input_profile::node_state_transform> transforms, float value)
@@ -343,23 +345,28 @@ void input_profile::apply(XrSpace world_space, XrTime predicted_display_time, bo
{
for (auto && [space, node]: model_handles)
{
if ((space == application::space(xr::spaces::grip_left) or space == application::space(xr::spaces::aim_left)) and hide_left)
if ((space == xr::spaces::grip_left or space == xr::spaces::aim_left) and hide_left)
{
node->visible = false;
continue;
}
if ((space == application::space(xr::spaces::grip_right) or space == application::space(xr::spaces::aim_right)) and hide_right)
if ((space == xr::spaces::grip_right or space == xr::spaces::aim_right) and hide_right)
{
node->visible = false;
continue;
}
if (auto location = application::locate_controller(space, world_space, predicted_display_time); location)
if (auto location = application::locate_controller(application::space(space), world_space, predicted_display_time); location)
{
node->visible = true;
node->position = location->first;
node->orientation = location->second;
assert((int)space >= 0);
assert((int)space < offset.size());
auto & [p, q] = offset[space];
node->position = location->first + glm::mat3_cast(location->second * q) * p;
node->orientation = location->second * q;
}
else
{
+5 -1
View File
@@ -20,9 +20,11 @@
#include <filesystem>
#include <glm/glm.hpp>
#include <magic_enum_containers.hpp>
#include <render/scene_data.h>
#include <span>
#include <variant>
#include <xr/space.h>
#include <openxr/openxr.h>
struct input_profile
@@ -59,10 +61,12 @@ struct input_profile
std::string id;
std::vector<visual_response> responses;
std::vector<std::pair<XrSpace, node_handle>> model_handles;
std::vector<std::pair<xr::spaces, node_handle>> model_handles;
node_handle left_ray;
node_handle right_ray;
magic_enum::containers::array<xr::spaces, std::pair<glm::vec3, glm::quat>> offset;
input_profile(const std::filesystem::path & json_profile, scene_loader & loader, scene_data & scene_controllers, scene_data & scene_rays);
// application::poll_actions() must have been called before
+67 -34
View File
@@ -61,39 +61,6 @@ scenes::lobby::~lobby()
renderer->wait_idle();
}
static std::string choose_webxr_profile()
{
#ifndef __ANDROID__
const char * controller = std::getenv("WIVRN_CONTROLLER");
if (controller && strcmp(controller, ""))
return controller;
#endif
switch (guess_model())
{
case model::oculus_quest:
return "oculus-touch-v2";
case model::oculus_quest_2:
return "oculus-touch-v3";
case model::meta_quest_pro:
return "meta-quest-touch-pro";
case model::meta_quest_3:
return "meta-quest-touch-plus";
case model::pico_neo_3:
return "pico-neo3";
case model::pico_4:
return "pico-4";
case model::htc_vive_focus_3:
case model::htc_vive_xr_elite:
return "htc-vive-focus-3";
case model::lynx_r1:
case model::unknown:
return "generic-trigger-squeeze";
}
__builtin_unreachable();
}
static const std::array supported_color_formats = {
vk::Format::eR8G8B8A8Srgb,
vk::Format::eB8G8R8A8Srgb,
@@ -758,6 +725,41 @@ void scenes::lobby::render(const XrFrameState & frame_state)
}
}
#if WIVRN_CLIENT_DEBUG_MENU
if (display_debug_axes)
{
const xr::spaces left = display_grip_instead_of_aim ? xr::spaces::grip_left : xr::spaces::aim_left;
const xr::spaces right = display_grip_instead_of_aim ? xr::spaces::grip_right : xr::spaces::aim_right;
if (hide_left_controller)
xyz_axes_left_controller->visible = false;
else if (auto location = application::locate_controller(application::space(left), world_space, frame_state.predictedDisplayTime))
{
xyz_axes_left_controller->visible = true;
xyz_axes_left_controller->position = location->first;
xyz_axes_left_controller->orientation = location->second;
}
else
xyz_axes_left_controller->visible = false;
if (hide_right_controller)
xyz_axes_right_controller->visible = false;
else if (auto location = application::locate_controller(application::space(right), world_space, frame_state.predictedDisplayTime))
{
xyz_axes_right_controller->visible = true;
xyz_axes_right_controller->position = location->first;
xyz_axes_right_controller->orientation = location->second;
}
else
xyz_axes_right_controller->visible = false;
}
else
{
xyz_axes_left_controller->visible = false;
xyz_axes_right_controller->visible = false;
}
#endif
if (head_position && new_gui_position)
{
move_gui(head_position->first, *new_gui_position);
@@ -996,14 +998,43 @@ void scenes::lobby::on_focused()
controllers_scene.emplace();
scene_data & controllers_scene_data = composition_layer_depth_test_supported ? *lobby_scene : *controllers_scene;
auto profile = controller_name();
input = input_profile(
"controllers/" + choose_webxr_profile() + "/profile.json",
"controllers/" + profile + "/profile.json",
loader,
controllers_scene_data,
*controllers_scene);
spdlog::info("Loaded input profile {}", input->id);
for (auto i: {xr::spaces::aim_left, xr::spaces::aim_right, xr::spaces::grip_left, xr::spaces::grip_right})
{
auto [p, q] = input->offset[i] = controller_offset(controller_name(), i);
auto rot = glm::degrees(glm::eulerAngles(q));
spdlog::info("Initializing offset of space {} to ({}, {}, {}) mm, ({}, {}, {})°",
magic_enum::enum_name(i),
1000 * p.x,
1000 * p.y,
1000 * p.z,
rot.x,
rot.y,
rot.z);
}
#if WIVRN_CLIENT_DEBUG_MENU
offset_position = input->offset[xr::spaces::grip_left].first;
offset_orientation = glm::degrees(glm::eulerAngles(input->offset[xr::spaces::grip_left].second));
ray_offset = input->offset[xr::spaces::aim_left].first.z;
xyz_axes_left_controller = controllers_scene_data.new_node();
controllers_scene_data.import(loader("xyz-arrows.glb"), xyz_axes_left_controller);
xyz_axes_right_controller = controllers_scene_data.new_node();
controllers_scene_data.import(loader("xyz-arrows.glb"), xyz_axes_right_controller);
#endif
if (application::get_hand_tracking_supported())
{
left_hand.emplace("left-hand.glb", loader, controllers_scene_data);
@@ -1016,12 +1047,14 @@ void scenes::lobby::on_focused()
std::vector imgui_inputs{
imgui_context::controller{
.aim = get_action_space("left_aim"),
.offset = input->offset[xr::spaces::aim_left],
.trigger = get_action("left_trigger").first,
.squeeze = get_action("left_squeeze").first,
.scroll = get_action("left_scroll").first,
},
imgui_context::controller{
.aim = get_action_space("right_aim"),
.offset = input->offset[xr::spaces::aim_right],
.trigger = get_action("right_trigger").first,
.squeeze = get_action("right_squeeze").first,
.scroll = get_action("right_scroll").first,
+16
View File
@@ -26,6 +26,7 @@
#include "scenes/hand_model.h"
#include "scenes/lobby_keyboard.h"
#include "wifi_lock.h"
#include "wivrn_config.h"
#include "wivrn_discover.h"
#include <vulkan/vulkan_raii.hpp>
@@ -93,6 +94,17 @@ class lobby : public scene_impl<lobby>
xr::passthrough passthrough;
XrViewConfigurationView stream_view;
#if WIVRN_CLIENT_DEBUG_MENU
// GUI debug
node_handle xyz_axes_left_controller;
node_handle xyz_axes_right_controller;
bool display_debug_axes = false;
bool display_grip_instead_of_aim = false;
glm::vec3 offset_position{};
glm::vec3 offset_orientation{};
float ray_offset{};
#endif
void update_server_list();
std::vector<std::pair<int, XrCompositionLayerQuad>> draw_gui(XrTime predicted_display_time);
@@ -113,6 +125,9 @@ class lobby : public scene_impl<lobby>
{
server_list,
settings,
#if WIVRN_CLIENT_DEBUG_MENU
debug,
#endif
about,
licenses,
exit
@@ -129,6 +144,7 @@ class lobby : public scene_impl<lobby>
void gui_server_list();
void gui_new_server();
void gui_settings();
void gui_debug();
void gui_about();
void gui_licenses();
void gui_keyboard();
+91
View File
@@ -602,6 +602,68 @@ void scenes::lobby::gui_settings()
}
}
#if WIVRN_CLIENT_DEBUG_MENU
void scenes::lobby::gui_debug()
{
ImGui::GetIO().ConfigDragClickToInputText = true;
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20, 20));
ImGui::Checkbox("Display debug axes", &display_debug_axes);
vibrate_on_hover();
if (display_debug_axes)
{
ImGui::Checkbox("Display grip instead of aim", &display_grip_instead_of_aim);
vibrate_on_hover();
}
ImGui::SetNextItemWidth(140);
ImGui::DragFloat("##offset x", &offset_position.x, 0.0001);
vibrate_on_hover();
ImGui::SameLine();
ImGui::SetNextItemWidth(140);
ImGui::DragFloat("##offset y", &offset_position.y, 0.0001);
vibrate_on_hover();
ImGui::SameLine();
ImGui::SetNextItemWidth(140);
ImGui::DragFloat("Position", &offset_position.z, 0.0001);
vibrate_on_hover();
ImGui::SameLine();
if (ImGui::Button("Reset##position"))
offset_position = {0, 0, 0};
vibrate_on_hover();
ImGui::SetNextItemWidth(140);
ImGui::DragFloat("##offset roll", &offset_orientation.x, 0.01);
vibrate_on_hover();
ImGui::SameLine();
ImGui::SetNextItemWidth(140);
ImGui::DragFloat("##offset pitch", &offset_orientation.y, 0.01);
vibrate_on_hover();
ImGui::SameLine();
ImGui::SetNextItemWidth(140);
ImGui::DragFloat("Rotation", &offset_orientation.z, 0.01);
vibrate_on_hover();
ImGui::SameLine();
if (ImGui::Button("Reset##orientation"))
offset_orientation = {0, 0, 0};
vibrate_on_hover();
ImGui::SetNextItemWidth(140);
ImGui::DragFloat("Ray offset", &ray_offset, 0.0001);
vibrate_on_hover();
ImGui::PopStyleVar();
}
#endif
void scenes::lobby::gui_about()
{
ImGui::PushFont(imgui_ctx->large_font);
@@ -1194,6 +1256,12 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
gui_settings();
break;
#if WIVRN_CLIENT_DEBUG_MENU
case tab::debug:
gui_debug();
break;
#endif
case tab::about:
gui_about();
break;
@@ -1232,6 +1300,11 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), &current_tab, tab::settings, {TabWidth, 0});
vibrate_on_hover();
#if WIVRN_CLIENT_DEBUG_MENU
RadioButtonWithoutCheckBox(ICON_FA_BUG_SLASH " " + _("Debug"), &current_tab, tab::debug, {TabWidth, 0});
vibrate_on_hover();
#endif
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 3 * ImGui::GetCurrentContext()->FontSize - 6 * style.FramePadding.y - 2 * style.ItemSpacing.y - style.WindowPadding.y);
RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " " + _("About"), &current_tab, tab::about, {TabWidth, 0});
vibrate_on_hover();
@@ -1265,5 +1338,23 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
application::haptic_start(haptic_output[controller], XR_NULL_PATH, 10'000'000, 1000, 1);
}
#if WIVRN_CLIENT_DEBUG_MENU
{
input->offset[xr::spaces::grip_left].first = offset_position;
input->offset[xr::spaces::grip_right].first = offset_position;
glm::quat qx = glm::quat(std::cos(offset_orientation.x * M_PI / 360), sin(offset_orientation.x * M_PI / 360), 0, 0);
glm::quat qy = glm::quat(std::cos(offset_orientation.y * M_PI / 360), 0, sin(offset_orientation.y * M_PI / 360), 0);
glm::quat qz = glm::quat(std::cos(offset_orientation.z * M_PI / 360), 0, 0, sin(offset_orientation.z * M_PI / 360));
glm::quat q = qz * qy * qx;
input->offset[xr::spaces::grip_left].second = q;
input->offset[xr::spaces::grip_right].second = q;
input->offset[xr::spaces::aim_left].first.z = ray_offset;
input->offset[xr::spaces::aim_right].first.z = ray_offset;
}
#endif
return imgui_ctx->end_frame();
}
+1
View File
@@ -33,5 +33,6 @@
#cmakedefine01 WIVRN_FEATURE_SOLARXR
#cmakedefine01 WIVRN_SHOW_IMGUI_DEMO_WINDOW
#cmakedefine01 WIVRN_CLIENT_DEBUG_MENU
#define WIVRN_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
+1170
View File
File diff suppressed because it is too large Load Diff