From 7485cd0880b1b79b8c342f66133a57c619dd43fc Mon Sep 17 00:00:00 2001 From: Tool Man <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 09:58:06 -0400 Subject: [PATCH 01/42] Adding solarxr patches Remove potential statistics --- CMakeLists.txt | 2 +- client/CMakeLists.txt | 16 +- client/scenes/lobby.cpp | 13 +- images/wivrn-pride.svg | 622 -------------------------------- server/CMakeLists.txt | 1 + server/driver/wivrn_hmd.h | 16 +- server/driver/wivrn_session.cpp | 18 +- 7 files changed, 36 insertions(+), 652 deletions(-) delete mode 100644 images/wivrn-pride.svg diff --git a/CMakeLists.txt b/CMakeLists.txt index 98678d01..99ea34f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ set(OVR_COMPAT_SEARCH_PATH "/usr/local/lib/OpenComposite:/usr/lib/OpenComposite: option(WIVRN_FEATURE_DEBUG_GUI "Enable Monado debug GUI" OFF) option(WIVRN_FEATURE_RENDERDOC "Support renderdoc" OFF) -set(WIVRN_FEATURE_SOLARXR OFF) # Will be added back when merged in upstream Monado +option(WIVRN_FEATURE_SOLARXR "Enable SolarXR driver" OFF) option(WIVRN_FEATURE_STEAMVR_LIGHTHOUSE "Enable SteamVR Lighthouse driver" OFF) option(WIVRN_CHECK_CAPSYSNICE "Check if CAP_SYS_NICE is available at startup" ON) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 1e64e3b8..a56c9ed4 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -225,14 +225,8 @@ add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.png COMMAND ${RSVG_CONVERT} ${IMG_SRC_DIR}/wivrn.svg -w 540 -h 540 -o ${ASSETS_DIR}/wivrn.png ${RSVG_OPTS} DEPENDS ${IMG_SRC_DIR}/wivrn.svg ${WIVRN_CSS_ABS}) -add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn-pride.png - COMMAND ${RSVG_CONVERT} ${IMG_SRC_DIR}/wivrn-pride.svg -w 540 -h 540 -o ${ASSETS_DIR}/wivrn-pride.png ${RSVG_OPTS} - DEPENDS ${IMG_SRC_DIR}/wivrn-pride.svg ${WIVRN_CSS_ABS}) - add_custom_target(assets ALL DEPENDS - ${ASSETS_DIR}/wivrn.png - ${ASSETS_DIR}/wivrn-pride.png -) + ${ASSETS_DIR}/wivrn.png add_dependencies(wivrn assets) @@ -241,9 +235,6 @@ if(ANDROID) add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.ktx2 COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn.ktx2 ${ASSETS_DIR}/wivrn.png DEPENDS ${ASSETS_DIR}/wivrn.png) - add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn-pride.ktx2 - COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn-pride.ktx2 ${ASSETS_DIR}/wivrn-pride.png - DEPENDS ${ASSETS_DIR}/wivrn-pride.png) add_custom_command(OUTPUT ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2 COMMAND ${TOKTX} --encode astc --astc_blk_d 12x12 --astc_quality 100 --genmipmap ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2 ${AST_SRC_DIR}/WoodFloor051_1K-JPG_Color.jpg @@ -255,10 +246,9 @@ if(ANDROID) add_custom_target(assets-android ALL DEPENDS ${ASSETS_DIR}/wivrn.ktx2 - ${ASSETS_DIR}/wivrn-pride.ktx2 ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2 - ${ASSETS_DIR}/vr_splash.png - ) + ${ASSETS_DIR}/vr_splash.png) + add_dependencies(assets-android assets) add_dependencies(wivrn assets-android) endif() diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 44533091..9e8cd4d6 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -1168,9 +1168,20 @@ void scenes::lobby::on_focused() imgui_ctx.emplace(physical_device, device, queue_family_index, queue, imgui_inputs, swapchain_imgui, vps); + std::string image; + /* Could be used for more patriotics logos + auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); auto tm = std::localtime(&t); - std::string image = tm->tm_mon == 5 ? "wivrn-pride" : "wivrn"; + + switch (tm->tm_mon) + { + default: + image = "wivrn"; + break; + } + */ + image = "wivrn"; try { about_picture = imgui_ctx->load_texture(image + ".ktx2"); diff --git a/images/wivrn-pride.svg b/images/wivrn-pride.svg deleted file mode 100644 index 71c38d51..00000000 --- a/images/wivrn-pride.svg +++ /dev/null @@ -1,622 +0,0 @@ - - - -WiVRn Wyvern yippe and GayvrnWiVRn Wyvern yippe and Gayvrn1/25/25 and 5/12/25Yaya, y.a.y.a on Discord. diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index f0dfcc78..d1339974 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -16,6 +16,7 @@ set(XRT_BUILD_DRIVER_RIFT_S OFF) set(XRT_BUILD_DRIVER_ROKID OFF) set(XRT_BUILD_DRIVER_SIMULATED OFF) set(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE ${WIVRN_FEATURE_STEAMVR_LIGHTHOUSE}) +set(XRT_BUILD_DRIVER_SOLARXR ${WIVRN_FEATURE_SOLARXR}) set(XRT_BUILD_DRIVER_TWRAP OFF) set(XRT_BUILD_DRIVER_VF OFF) set(XRT_BUILD_DRIVER_VIVE OFF) diff --git a/server/driver/wivrn_hmd.h b/server/driver/wivrn_hmd.h index 006b85a7..77e7cc26 100644 --- a/server/driver/wivrn_hmd.h +++ b/server/driver/wivrn_hmd.h @@ -42,13 +42,6 @@ class wivrn_hmd : public xrt_device .name = XRT_INPUT_GENERIC_HEAD_POSE, }; xrt_hmd_parts hmd_parts{}; - xrt_tracking_origin tracking_origin{ - .name = "WiVRn origin", - .type = XRT_TRACKING_TYPE_OTHER, - .initial_offset = { - .orientation = {0, 0, 0, 1}, - }, - }; view_list views; std::array foveation_parameters{}; @@ -64,6 +57,15 @@ class wivrn_hmd : public xrt_device public: using base = xrt_device; + + xrt_tracking_origin tracking_origin{ + .name = "WiVRn origin", + .type = XRT_TRACKING_TYPE_OTHER, + .initial_offset = { + .orientation = {0, 0, 0, 1}, + }, + }; + wivrn_hmd(wivrn::wivrn_session * cnx, const from_headset::headset_info_packet & info); diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 65833517..66b3609f 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -52,7 +52,7 @@ #endif #if WIVRN_FEATURE_SOLARXR -#include "solarxr_device.h" +#include "solarxr_interface.h" #endif namespace wivrn @@ -215,15 +215,13 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection } #if WIVRN_FEATURE_SOLARXR - xrt_device * solar_devs[XRT_SYSTEM_MAX_DEVICES]; - uint32_t solar_devs_cap = XRT_SYSTEM_MAX_DEVICES - xdev_count; - uint32_t num_devs = solarxr_device_create_xdevs(&hmd, solar_devs, XRT_SYSTEM_MAX_DEVICES - xdev_count); - for (int i = 0; i < num_devs; i++) + uint32_t num_devs = solarxr_device_create_xdevs(&hmd.tracking_origin, &xdevs[xdev_count], ARRAY_SIZE(xdevs) - xdev_count); + if (num_devs != 0) { - xdevs[xdev_count++] = solar_devs[i]; - if (i == 0) - static_roles.body = solar_devs[i]; + static_roles.body = xdevs[xdev_count]; + solarxr_device_set_feeder_devices(static_roles.body, xdevs, xdev_count); } + xdev_count += num_devs; #endif if (roles.left >= 0) @@ -242,6 +240,10 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection wivrn_session::~wivrn_session() { +#if WIVRN_FEATURE_SOLARXR + solarxr_device_set_feeder_devices(static_roles.body, nullptr, 0); +#endif + for (size_t i = 0; i < ARRAY_SIZE(xdevs); i++) { xrt_device_destroy(&xdevs[i]); From d0250abbc9ec6766af850af21893e3e5d27c8698 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 23:00:09 -0400 Subject: [PATCH 02/42] Update CMakeLists.txt --- client/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index a56c9ed4..736dd541 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -226,7 +226,7 @@ add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.png DEPENDS ${IMG_SRC_DIR}/wivrn.svg ${WIVRN_CSS_ABS}) add_custom_target(assets ALL DEPENDS - ${ASSETS_DIR}/wivrn.png + ${ASSETS_DIR}/wivrn.png) add_dependencies(wivrn assets) From 6969e5f972c0b198d9e4c77a98fbd2b0d1f16b2b Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Fri, 16 May 2025 18:29:29 -0400 Subject: [PATCH 03/42] Update patches --- flatpak/io.github.wivrn.wivrn.yml.in | 4 + ...098-d-solarxr-Add-SolarXR-IPC-driver.patch | 2557 +++++++++++++++++ .../0099-t-common-Load-SolarXR-driver.patch | 292 ++ 3 files changed, 2853 insertions(+) create mode 100644 patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch create mode 100644 patches/monado/0099-t-common-Load-SolarXR-driver.patch diff --git a/flatpak/io.github.wivrn.wivrn.yml.in b/flatpak/io.github.wivrn.wivrn.yml.in index 85b17aed..737d1b04 100644 --- a/flatpak/io.github.wivrn.wivrn.yml.in +++ b/flatpak/io.github.wivrn.wivrn.yml.in @@ -28,6 +28,9 @@ finish-args: # Set the active OpenXR / OpenVR runtime - --filesystem=xdg-config/openxr:create - --filesystem=xdg-config/openvr:create + # SlimeVR + - --filesystem=xdg-run/SlimeVRInput + - --filesystem=xdg-run/SlimeVRRpc # Let outside application access the WiVRn socket - --filesystem=xdg-run/wivrn:create - --own-name=io.github.wivrn.Server @@ -371,6 +374,7 @@ modules: - -DWIVRN_USE_NVENC=ON - -DWIVRN_USE_VULKAN_ENCODE=ON - -DWIVRN_USE_PULSEAUDIO=OFF + - -DWIVRN_FEATURE_SOLARXR=ON - -DWIVRN_WERROR=ON - -DWIVRN_CHECK_CAPSYSNICE=OFF # Capabilities don't work inside flatpak - -DFETCHCONTENT_FULLY_DISCONNECTED=ON diff --git a/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch b/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch new file mode 100644 index 00000000..55bf4399 --- /dev/null +++ b/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch @@ -0,0 +1,2557 @@ +From 421b8e7288cfd03407bcdd0ab9a478e85592393b Mon Sep 17 00:00:00 2001 +From: rcelyte +Date: Mon, 17 Jun 2024 04:32:36 +0000 +Subject: [PATCH] d/solarxr: Add SolarXR IPC driver + +--- + CMakeLists.txt | 3 + + src/xrt/drivers/CMakeLists.txt | 16 + + src/xrt/drivers/solarxr/feeder.c | 252 +++++ + src/xrt/drivers/solarxr/feeder.h | 32 + + src/xrt/drivers/solarxr/ipc_message.h | 63 ++ + src/xrt/drivers/solarxr/ipc_socket.c | 237 ++++ + src/xrt/drivers/solarxr/ipc_socket.h | 44 + + src/xrt/drivers/solarxr/protocol.c | 374 +++++++ + src/xrt/drivers/solarxr/protocol.h | 245 ++++ + src/xrt/drivers/solarxr/solarxr_device.c | 1114 +++++++++++++++++++ + src/xrt/drivers/solarxr/solarxr_interface.h | 40 + + src/xrt/targets/common/CMakeLists.txt | 4 + + 12 files changed, 2424 insertions(+) + create mode 100644 src/xrt/drivers/solarxr/feeder.c + create mode 100644 src/xrt/drivers/solarxr/feeder.h + create mode 100644 src/xrt/drivers/solarxr/ipc_message.h + create mode 100644 src/xrt/drivers/solarxr/ipc_socket.c + create mode 100644 src/xrt/drivers/solarxr/ipc_socket.h + create mode 100644 src/xrt/drivers/solarxr/protocol.c + create mode 100644 src/xrt/drivers/solarxr/protocol.h + create mode 100644 src/xrt/drivers/solarxr/solarxr_device.c + create mode 100644 src/xrt/drivers/solarxr/solarxr_interface.h + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 3d4b6bad32..97ee76f9ca 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -343,6 +343,7 @@ option_with_deps(XRT_BUILD_DRIVER_VIVE "Enable driver for HTC Vive, Vive Pro, Va + option_with_deps(XRT_BUILD_DRIVER_WMR "Enable Windows Mixed Reality driver" DEPENDS LINUX) + option_with_deps(XRT_BUILD_DRIVER_XREAL_AIR "Enable Xreal Air HMD driver" DEPENDS XRT_HAVE_HIDAPI) + option_with_deps(XRT_BUILD_DRIVER_SIMULAVR "Enable simula driver" DEPENDS XRT_HAVE_REALSENSE) ++option_with_deps(XRT_BUILD_DRIVER_SOLARXR "Enable SolarXR driver" DEPENDS XRT_HAVE_LINUX) + option(XRT_BUILD_DRIVER_SIMULATED "Enable simulated driver" ON) + + option(XRT_BUILD_SAMPLES "Enable compiling sample code implementations that will not be linked into any final targets" ON) +@@ -440,6 +441,7 @@ list( + "TWRAP" + "XREAL_AIR" + "STEAMVR_LIGHTHOUSE" ++ "SOLARXR" + ) + + # Package name needs to be known by the native code itself. +@@ -666,6 +668,7 @@ message(STATUS "# DRIVER_VIVE: ${XRT_BUILD_DRIVER_VIVE}") + message(STATUS "# DRIVER_WMR: ${XRT_BUILD_DRIVER_WMR}") + message(STATUS "# DRIVER_XREAL_AIR: ${XRT_BUILD_DRIVER_XREAL_AIR}") + message(STATUS "# DRIVER_STEAMVR_LIGHTHOUSE: ${XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE}") ++message(STATUS "# DRIVER_SOLARXR: ${XRT_BUILD_DRIVER_SOLARXR}") + message(STATUS "#####----- Config -----#####") + # cmake-format: on + +diff --git a/src/xrt/drivers/CMakeLists.txt b/src/xrt/drivers/CMakeLists.txt +index 0d422f16e4..b5511f45d8 100644 +--- a/src/xrt/drivers/CMakeLists.txt ++++ b/src/xrt/drivers/CMakeLists.txt +@@ -494,6 +494,22 @@ if(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE) + list(APPEND ENABLED_HEADSET_DRIVERS steamvr_lh) + endif() + ++if(XRT_BUILD_DRIVER_SOLARXR) ++ add_library( ++ drv_solarxr STATIC ++ solarxr/feeder.c ++ solarxr/feeder.h ++ solarxr/ipc_socket.c ++ solarxr/ipc_socket.h ++ solarxr/protocol.c ++ solarxr/protocol.h ++ solarxr/solarxr_device.c ++ solarxr/solarxr_interface.h ++ ) ++ target_link_libraries(drv_solarxr PRIVATE xrt-interfaces aux_util) ++ list(APPEND ENABLED_DRIVERS solarxr) ++endif() ++ + if(XRT_BUILD_SAMPLES) + # We build the sample driver to make sure it stays valid, + # but it never gets linked into a final target. +diff --git a/src/xrt/drivers/solarxr/feeder.c b/src/xrt/drivers/solarxr/feeder.c +new file mode 100644 +index 0000000000..eec813994d +--- /dev/null ++++ b/src/xrt/drivers/solarxr/feeder.c +@@ -0,0 +1,252 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#include "feeder.h" ++#include "ipc_message.h" ++#include "xrt/xrt_device.h" ++#include ++ ++// #define FEEDER_DESTROY_GUARD ++ ++#define PROTOBUF_FLOAT(v_) ((uint8_t *)&(v_))[0], ((uint8_t *)&(v_))[1], ((uint8_t *)&(v_))[2], ((uint8_t *)&(v_))[3] ++#define PROTOBUF_INT32(v_) \ ++ (uint8_t)(0x80 | (uint32_t)(v_)), (uint8_t)(0x80 | (uint32_t)(v_) >> 7), \ ++ (uint8_t)(0x80 | (uint32_t)(v_) >> 14), (uint8_t)(0x80 | (uint32_t)(v_) >> 21), (uint32_t)(v_) >> 28 ++ ++struct feeder_device ++{ ++ struct xrt_device *xdev; ++ enum xrt_input_name input_name; ++ uint32_t id; ++ uint8_t last_status; ++ bool battery_charging; ++ float battery_charge; ++#ifdef FEEDER_DESTROY_GUARD ++ void (*old_destroy)(struct xrt_device *xdev); ++#endif ++}; ++ ++void ++feeder_send_feedback(struct feeder *const feeder, const int64_t time) ++{ ++ os_mutex_lock(&feeder->mutex); ++ uint8_t packet[0x10000], *packet_end = packet; ++ for (uint32_t i = 0, devices_len = feeder->devices_len; i < devices_len; ++i) { ++ struct feeder_device *const device = &feeder->devices[i]; ++ if (device->xdev == NULL) { ++ continue; ++ } ++ ++ bool present = false, charging = false; ++ float charge = 0; ++ if (device->xdev->battery_status_supported && ++ xrt_device_get_battery_status(device->xdev, &present, &charging, &charge) == XRT_SUCCESS && ++ (charging != device->battery_charging || fabsf(charge - device->battery_charge) >= 1e-05)) { ++ device->battery_charging = charging; ++ device->battery_charge = charge; ++ uint8_t message[] = { ++ (5 << 3) | 2, 0, // ProtobufMessage::battery ++ (1 << 3) | 0, PROTOBUF_INT32(device->id), // Battery::tracker_id ++ (2 << 3) | 5, PROTOBUF_FLOAT(charge), // Battery::battery_level ++ (3 << 3) | 0, charging, // Battery::is_charging ++ }; ++ message[1] = sizeof(message) - 2; ++ ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, sizeof(message)); ++ } ++ ++ uint8_t status = 0; // Status::DISCONNECTED ++ struct xrt_space_relation relation = {0}; ++ assert(device->xdev->get_tracked_pose != NULL); ++ if (xrt_device_get_tracked_pose(device->xdev, device->input_name, time, &relation) == XRT_SUCCESS && ++ (relation.relation_flags & XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT) != 0) { ++ uint8_t message[30 + 15] = { ++ (1 << 3) | 2, 0, // ProtobufMessage::position ++ (1 << 3) | 0, PROTOBUF_INT32(device->id), // Position::tracker_id ++ (5 << 3) | 5, PROTOBUF_FLOAT(relation.pose.orientation.x), // Position::qx ++ (6 << 3) | 5, PROTOBUF_FLOAT(relation.pose.orientation.y), // Position::qy ++ (7 << 3) | 5, PROTOBUF_FLOAT(relation.pose.orientation.z), // Position::qz ++ (8 << 3) | 5, PROTOBUF_FLOAT(relation.pose.orientation.w), // Position::qw ++ (9 << 3) | 0, 3, // Position::data_source = DataSource::FULL ++ }; ++ uint32_t message_len = sizeof(message); ++ if ((relation.relation_flags & XRT_SPACE_RELATION_POSITION_TRACKED_BIT) != 0) { ++ const uint8_t position[15] = { ++ (2 << 3) | 5, PROTOBUF_FLOAT(relation.pose.position.x), // Position::x ++ (3 << 3) | 5, PROTOBUF_FLOAT(relation.pose.position.y), // Position::y ++ (4 << 3) | 5, PROTOBUF_FLOAT(relation.pose.position.z), // Position::z ++ }; ++ memcpy(&message[sizeof(message) - sizeof(position)], position, sizeof(position)); ++ } else { ++ message_len -= 15; ++ } ++ message[1] = message_len - 2; ++ ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, message_len); ++ status = 1; // Status::OK ++ } ++ ++ if (status != device->last_status) { ++ device->last_status = status; ++ uint8_t message[] = { ++ (4 << 3) | 2, 0, // ProtobufMessage::tracker_status ++ (1 << 3) | 0, PROTOBUF_INT32(device->id), // TrackerStatus::tracker_id ++ (2 << 3) | 0, status, // TrackerStatus::status ++ }; ++ message[1] = sizeof(message) - 2; ++ ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, sizeof(message)); ++ } ++ } ++ if (packet_end != packet) { ++ ipc_socket_send_raw(&feeder->socket, packet, packet_end - packet); ++ } ++ atomic_store(&feeder->last_send, time); ++ os_mutex_unlock(&feeder->mutex); ++} ++ ++static bool ++filter_feeder_device(struct xrt_device *const device, bool (*const filter)(struct xrt_device *device)) ++{ ++ return device != NULL && device->orientation_tracking_supported && (filter == NULL || filter(device)); ++} ++ ++#ifdef FEEDER_DESTROY_GUARD ++static void ++halt_and_catch_fire(struct xrt_device *xdev) ++{ ++ U_LOG_E("Device destroyed while still in use by feeder!"); ++ abort(); ++} ++#endif ++ ++bool ++feeder_set_devices(struct feeder *const feeder, ++ struct xrt_device *const devices[const], ++ const uint32_t devices_len, ++ bool (*const filter)(struct xrt_device *device)) ++{ ++ uint32_t device_count = 0; ++ for (uint32_t i = 0; i < devices_len; ++i) { ++ device_count += filter_feeder_device(devices[i], filter); ++ } ++ os_mutex_lock(&feeder->mutex); ++ if (!ipc_socket_is_connected(&feeder->socket)) { ++ if (!ipc_socket_connect(&feeder->socket, "SlimeVRInput", "slimevr/SlimeVRInput", NULL, 0)) { ++ os_mutex_unlock(&feeder->mutex); ++ return false; ++ } ++ } ++ for (uint32_t i = 0, devices_len = feeder->devices_len; i < devices_len; ++i) { ++ if (feeder->devices[i].xdev == NULL) { ++ continue; ++ } ++ // The feeder protocol doesn't define a 'removed' message so this is the best we can do ++ uint8_t message[] = { ++ (4 << 3) | 2, 0, // ProtobufMessage::tracker_status ++ (1 << 3) | 0, PROTOBUF_INT32(feeder->devices[i].id), // TrackerStatus::tracker_id ++ (2 << 3) | 0, 0, // TrackerStatus::status = Status::DISCONNECTED ++ }; ++ message[1] = sizeof(message) - 2; ++ ipc_socket_send(&feeder->socket, message, sizeof(message)); ++ ++#ifdef FEEDER_DESTROY_GUARD ++ feeder->devices[i].xdev->destroy = feeder->devices[i].old_destroy; ++#endif ++ feeder->devices[i] = (struct feeder_device){0}; ++ } ++ struct feeder_device *new_devices = NULL; ++ if (device_count != 0) { ++ new_devices = realloc(feeder->devices, device_count * sizeof(*new_devices)); ++ } ++ bool result; ++ if (new_devices == NULL) { ++ free(feeder->devices); ++ feeder->devices = NULL; ++ feeder->devices_len = 0; ++ result = device_count == 0; ++ } else { ++ feeder->devices = new_devices; ++ feeder->devices_len = device_count; ++ for (uint32_t i = 0; i < devices_len; ++i) { ++ if (!filter_feeder_device(devices[i], filter)) { ++ continue; ++ } ++ enum xrt_input_name input_name = XRT_INPUT_GENERIC_TRACKER_POSE; ++ for (size_t input = 0, input_count = devices[i]->input_count; input < input_count; ++input) { ++ if (XRT_GET_INPUT_TYPE(devices[i]->inputs[input].name) == XRT_INPUT_TYPE_POSE) { ++ input_name = devices[i]->inputs[input].name; ++ break; ++ } ++ } ++ uint8_t role = 0; // TrackerRole::NONE ++ switch (devices[i]->device_type) { ++ case XRT_DEVICE_TYPE_HMD: role = 19; break; // TrackerRole::HMD ++ case XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER: role = 14; break; // TrackerRole::RIGHT_CONTROLLER ++ case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER: role = 13; break; // TrackerRole::LEFT_CONTROLLER ++ case XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER: role = 21; break; // TrackerRole::GENERIC_CONTROLLER ++ default:; ++ } ++ assert(new_devices < &feeder->devices[feeder->devices_len]); ++ const uint32_t id = feeder->next_id++; ++ *new_devices++ = (struct feeder_device){ ++ .xdev = devices[i], ++ .input_name = input_name, ++ .id = id, ++ .last_status = UINT8_MAX, ++#ifdef FEEDER_DESTROY_GUARD ++ .old_destroy = devices[i]->destroy, ++#endif ++ }; ++#ifdef FEEDER_DESTROY_GUARD ++ devices[i]->destroy = halt_and_catch_fire; ++#endif ++ ++ const uint32_t serial_len = strlen(devices[i]->serial), name_len = strlen(devices[i]->str); ++ const uint8_t message_1[] = { ++ (3 << 3) | 2, PROTOBUF_INT32(0), // ProtobufMessage::tracker_added ++ (1 << 3) | 0, PROTOBUF_INT32(id), // TrackerAdded::tracker_id ++ (4 << 3) | 0, role, // TrackerAdded::tracker_role ++ (2 << 3) | 2, PROTOBUF_INT32(serial_len), ++ }; ++ const uint8_t message_2[] = { ++ (3 << 3) | 2, ++ PROTOBUF_INT32(name_len), ++ }; ++ uint8_t packet[sizeof(struct ipc_message) + sizeof(message_1) + sizeof(devices[i]->serial) + ++ sizeof(message_2) + sizeof(devices[i]->str)]; ++ struct ipc_message *const message = ipc_message_start(packet, &packet[ARRAY_SIZE(packet)]); ++ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], message_1, sizeof(message_1)); ++ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], (const uint8_t *)devices[i]->serial, ++ serial_len); // TrackerAdded::tracker_serial ++ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], message_2, sizeof(message_2)); ++ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], (const uint8_t *)devices[i]->str, ++ name_len); // TrackerAdded::tracker_name ++ const uint32_t packet_len = ipc_message_end(message, &(uint8_t *){packet}); ++ if (packet_len == 0) { ++ assert(false); ++ continue; ++ } ++ const uint8_t tracker_added[] = { ++ PROTOBUF_INT32(packet_len - sizeof(*message) - sizeof((uint8_t[]){0, PROTOBUF_INT32(0)})), ++ }; ++ memcpy(&message->body[1], tracker_added, sizeof(tracker_added)); ++ ipc_socket_send_raw(&feeder->socket, packet, packet_len); ++ } ++ result = true; ++ } ++ os_mutex_unlock(&feeder->mutex); ++ return result; ++} ++ ++bool ++feeder_init(struct feeder *const feeder, const enum u_logging_level log_level) ++{ ++ ipc_socket_init(&feeder->socket, log_level); ++ return os_mutex_init(&feeder->mutex) == 0; ++} ++ ++void ++feeder_destroy(struct feeder *const feeder) ++{ ++ feeder_set_devices(feeder, NULL, 0, NULL); ++ os_mutex_destroy(&feeder->mutex); ++ ipc_socket_destroy(&feeder->socket); ++} +diff --git a/src/xrt/drivers/solarxr/feeder.h b/src/xrt/drivers/solarxr/feeder.h +new file mode 100644 +index 0000000000..29cbb79b28 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/feeder.h +@@ -0,0 +1,32 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#pragma once ++#include "ipc_socket.h" ++#include "os/os_threading.h" ++ ++struct feeder_device; ++struct feeder ++{ ++ struct os_mutex mutex; ++ struct ipc_socket socket; ++ _Atomic(int64_t) last_send; ++ uint32_t next_id; ++ uint32_t devices_len; ++ struct feeder_device *devices; ++}; ++ ++bool ++feeder_init(struct feeder *feeder, enum u_logging_level log_level); ++ ++void ++feeder_destroy(struct feeder *feeder); ++ ++void ++feeder_send_feedback(struct feeder *feeder, int64_t time); // thread safe ++ ++bool ++feeder_set_devices(struct feeder *feeder, ++ struct xrt_device *const devices[], ++ uint32_t devices_len, ++ bool (*filter)(struct xrt_device *device)); // thread safe +diff --git a/src/xrt/drivers/solarxr/ipc_message.h b/src/xrt/drivers/solarxr/ipc_message.h +new file mode 100644 +index 0000000000..e68edcc102 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/ipc_message.h +@@ -0,0 +1,63 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#pragma once ++#include ++ ++struct ipc_message ++{ ++ uint32_t length; ++ uint8_t body[]; ++}; ++ ++static inline struct ipc_message * ++ipc_message_start(uint8_t head[const], const uint8_t *const end) ++{ ++ if ((size_t)(end - head) < sizeof(struct ipc_message)) { ++ return NULL; ++ } ++ struct ipc_message *const message = (struct ipc_message *)head; ++ message->length = 0; ++ return message; ++} ++ ++static inline bool ++ipc_message_write(struct ipc_message *const message, ++ const uint8_t *const end, ++ const uint8_t data[const], ++ const uint32_t data_len) ++{ ++ if (message == NULL) { ++ return false; ++ } ++ if ((size_t)(end - message->body) < message->length || end - &message->body[message->length] < data_len) { ++ message->length = UINT32_MAX; ++ return false; ++ } ++ memcpy(&message->body[message->length], data, data_len); ++ message->length += data_len; ++ return true; ++} ++ ++static inline uint32_t ++ipc_message_end(struct ipc_message *const message, uint8_t **const end_out) ++{ ++ if (message == NULL || message->length >= UINT32_MAX - sizeof(*message)) { ++ return 0; ++ } ++ *end_out = &message->body[message->length]; ++ const uint32_t length = sizeof(*message) + message->length; ++ message->length = htole32(length); ++ return length; ++} ++ ++static inline uint32_t ++ipc_message_write_single(uint8_t **const head, ++ const uint8_t *const end, ++ const uint8_t data[const], ++ const uint32_t data_len) ++{ ++ struct ipc_message *const message = ipc_message_start(*head, end); ++ ipc_message_write(message, end, data, data_len); ++ return ipc_message_end(message, head); ++} +diff --git a/src/xrt/drivers/solarxr/ipc_socket.c b/src/xrt/drivers/solarxr/ipc_socket.c +new file mode 100644 +index 0000000000..15faea369d +--- /dev/null ++++ b/src/xrt/drivers/solarxr/ipc_socket.c +@@ -0,0 +1,237 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#include "ipc_socket.h" ++#include "os/os_time.h" ++#include "util/u_file.h" ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++void ++ipc_socket_init(struct ipc_socket *const state, const enum u_logging_level log_level) ++{ ++ *state = (struct ipc_socket){ ++ .sockfd = -1, ++ .log_level = log_level, ++ .timestamp = (int64_t)os_monotonic_get_ns(), ++ .buffer = malloc(0x1000), ++ }; ++ if (state->buffer != NULL) { ++ state->buffer_cap = 0x1000; ++ } ++} ++ ++static void ++ipc_socket_close(struct ipc_socket *const state) ++{ ++ const int sockfd = atomic_exchange(&state->sockfd, -1); ++ if (sockfd == -1) { ++ return; ++ } ++ shutdown(sockfd, SHUT_RDWR); // unblock `ipc_socket_wait()` ++ _Static_assert(sizeof(state->reference.count) == sizeof(volatile _Atomic(int)), ""); ++ while (atomic_load((volatile _Atomic(int) *)&state->reference.count) != 0) { ++ sched_yield(); ++ } ++ close(sockfd); ++} ++ ++void ++ipc_socket_destroy(struct ipc_socket *const state) ++{ ++ ipc_socket_close(state); ++ free(state->buffer); ++ state->buffer = NULL; ++ state->buffer_cap = 0; ++} ++ ++static bool ++path_is_socket(const char path[const]) ++{ ++ struct stat result = {0}; ++ return stat(path, &result) == 0 && S_ISSOCK(result.st_mode); ++} ++ ++bool ++ipc_socket_connect(struct ipc_socket *const state, ++ const char runtime_path[const], ++ const char fallback_path[const], ++ char path_out[const], ++ const size_t path_cap) ++{ ++ ipc_socket_close(state); ++ const int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); ++ if (sockfd == -1) { ++ U_LOG_IFL_E(state->log_level, "socket() failed"); ++ return false; ++ } ++ struct sockaddr_un addr = { ++ .sun_family = AF_UNIX, ++ }; ++ ssize_t path_len = u_file_get_path_in_runtime_dir(runtime_path, addr.sun_path, sizeof(addr.sun_path)); ++ if (path_len <= 0 || (size_t)path_len >= sizeof(addr.sun_path)) { ++ U_LOG_IFL_E(state->log_level, "u_file_get_path_in_runtime_dir() failed"); ++ goto fail; ++ } ++ if (!path_is_socket(addr.sun_path)) { ++ U_LOG_IFL_W(state->log_level, "path not found: %s", addr.sun_path); ++ const char *env; ++ if ((env = getenv("XDG_DATA_HOME")) != NULL) { ++ path_len = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", env, fallback_path); ++ } else if ((env = getenv("HOME")) != NULL) { ++ path_len = ++ snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/.local/share/%s", env, fallback_path); ++ } else { ++ path_len = 0; ++ } ++ if (path_len <= 0 || (size_t)path_len >= sizeof(addr.sun_path)) { ++ U_LOG_IFL_E(state->log_level, "failed to resolve SlimeVR socket path"); ++ goto fail; ++ } ++ if (!path_is_socket(addr.sun_path)) { ++ U_LOG_IFL_E(state->log_level, "path not found: %s", addr.sun_path); ++ goto fail; ++ } ++ } ++ if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(addr)) != 0) { ++ U_LOG_IFL_E(state->log_level, "connect() failed: %s", strerror(errno)); ++ goto fail; ++ } ++ if (path_cap >= 1) { ++ if ((size_t)path_len >= path_cap) { ++ path_len = path_cap - 1; ++ } ++ memcpy(path_out, addr.sun_path, path_len + 1); ++ } ++ atomic_store(&state->sockfd, sockfd); ++ return true; ++fail: ++ close(sockfd); ++ return false; ++} ++ ++bool ++ipc_socket_wait(struct ipc_socket *const state) ++{ ++ xrt_reference_inc(&state->reference); ++ struct pollfd sockfd = {atomic_load(&state->sockfd), POLLIN, 0}; ++ bool result = false; ++ if (sockfd.fd != -1) { ++ result = poll(&sockfd, 1, -1) != -1 || errno == EINTR; ++ } ++ xrt_reference_dec(&state->reference); ++ return result; ++} ++ ++static size_t ++ipc_socket_send_common(struct ipc_socket *const state, struct iovec parts[const], const uint32_t parts_len) ++{ ++ xrt_reference_inc(&state->reference); ++ const int sockfd = atomic_load(&state->sockfd); ++ if (sockfd == -1) { ++ xrt_reference_dec(&state->reference); ++ return 0; ++ } ++ const ssize_t result = sendmsg(sockfd, ++ &(const struct msghdr){ ++ .msg_iov = parts, ++ .msg_iovlen = parts_len, ++ }, ++ MSG_NOSIGNAL); ++ xrt_reference_dec(&state->reference); ++ return (size_t)result; ++} ++ ++bool ++ipc_socket_send(struct ipc_socket *const state, const uint8_t message[const], const uint32_t message_len) ++{ ++ struct iovec parts[2] = { ++ {&(uint32_t){htole32(message_len + sizeof(uint32_t))}, sizeof(uint32_t)}, ++ {*(uint8_t **)&message, message_len}, ++ }; ++ return ipc_socket_send_common(state, parts, ARRAY_SIZE(parts)) == sizeof(uint32_t) + message_len; ++} ++ ++bool ++ipc_socket_send_raw(struct ipc_socket *const state, const uint8_t packet[const], const uint32_t packet_len) ++{ ++ struct iovec parts[1] = { ++ {*(uint8_t **)&packet, packet_len}, ++ }; ++ return ipc_socket_send_common(state, parts, ARRAY_SIZE(parts)) == packet_len; ++} ++ ++uint32_t ++ipc_socket_receive(struct ipc_socket *const state) ++{ ++ xrt_reference_inc(&state->reference); ++ const int sockfd = atomic_load(&state->sockfd); ++ if (sockfd == -1) { ++ xrt_reference_dec(&state->reference); ++ return 0; ++ } ++ if (state->head == state->buffer_len) { ++ uint32_t header = 0; ++ ssize_t length = recv(sockfd, &header, sizeof(header), MSG_PEEK | MSG_DONTWAIT); ++ if (length < 0 && errno != EAGAIN) { ++ U_LOG_IFL_E(state->log_level, "recv() failed: %s", strerror(errno)); ++ goto fail; ++ } ++ if (length < (ssize_t)sizeof(header)) { ++ xrt_reference_dec(&state->reference); ++ return 0; ++ } ++ length = recv(sockfd, &header, sizeof(header), MSG_DONTWAIT); ++ if (length != sizeof(header)) { ++ U_LOG_IFL_E(state->log_level, "recv() failed: %s", ++ (length < 0) ? strerror(errno) : "bad length"); ++ goto fail; ++ } ++ const uint32_t packet_length = le32toh(header) - sizeof(header); ++ if (packet_length > state->buffer_cap) { ++ if (packet_length > 0x100000u) { ++ U_LOG_IFL_E(state->log_level, "packet too large"); ++ goto fail; ++ } ++ uint8_t *const new_buffer = realloc(state->buffer, packet_length); ++ if (new_buffer == NULL) { ++ U_LOG_IFL_E(state->log_level, "realloc failed"); ++ goto fail; ++ } ++ state->buffer = new_buffer; ++ state->buffer_cap = packet_length; ++ } ++ state->buffer_len = packet_length; ++ state->head = 0; ++ state->timestamp = (int64_t)os_monotonic_get_ns(); ++ } ++ for (ssize_t length; state->head < state->buffer_len; state->head += (size_t)length) { ++ length = recv(sockfd, &state->buffer[state->head], state->buffer_len - state->head, MSG_DONTWAIT); ++ if (length < 0 && errno != EAGAIN) { ++ U_LOG_IFL_E(state->log_level, "recv() failed: %s", strerror(errno)); ++ goto fail; ++ } ++ if (length <= 0) { ++ xrt_reference_dec(&state->reference); ++ return 0; ++ } ++ if (length > state->buffer_len - state->head) { ++ U_LOG_IFL_E(state->log_level, "recv() returned invalid length"); ++ goto fail; ++ } ++ } ++ xrt_reference_dec(&state->reference); ++ return state->buffer_len; ++fail: ++ xrt_reference_dec(&state->reference); ++ ipc_socket_destroy(state); ++ return 0; ++} +diff --git a/src/xrt/drivers/solarxr/ipc_socket.h b/src/xrt/drivers/solarxr/ipc_socket.h +new file mode 100644 +index 0000000000..c4f1ce4715 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/ipc_socket.h +@@ -0,0 +1,44 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#pragma once ++#include "util/u_logging.h" ++#include ++ ++struct ipc_socket ++{ ++ _Atomic(int) sockfd; ++ struct xrt_reference reference; ++ enum u_logging_level log_level; ++ int64_t timestamp; ++ uint32_t head, buffer_len, buffer_cap; ++ uint8_t *buffer; ++}; ++ ++void ++ipc_socket_init(struct ipc_socket *state, enum u_logging_level log_level); ++ ++void ++ipc_socket_destroy(struct ipc_socket *state); // thread safe ++ ++bool ++ipc_socket_connect( ++ struct ipc_socket *state, const char runtime_path[], const char fallback_path[], char path_out[], size_t path_cap); ++ ++bool ++ipc_socket_wait(struct ipc_socket *state); ++ ++bool ++ipc_socket_send(struct ipc_socket *state, const uint8_t message[], uint32_t message_len); // thread safe ++ ++bool ++ipc_socket_send_raw(struct ipc_socket *state, const uint8_t packet[], uint32_t packet_len); // thread safe ++ ++uint32_t ++ipc_socket_receive(struct ipc_socket *state); ++ ++static inline bool ++ipc_socket_is_connected(struct ipc_socket *const state) ++{ ++ return atomic_load(&state->sockfd) != -1; ++} +diff --git a/src/xrt/drivers/solarxr/protocol.c b/src/xrt/drivers/solarxr/protocol.c +new file mode 100644 +index 0000000000..59607bc344 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/protocol.c +@@ -0,0 +1,374 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#include "protocol.h" ++ ++#include "math/m_api.h" ++ ++#include ++#include ++ ++typedef int32_t flatbuffers_soffset_t; // little-endian byte order ++typedef uint16_t flatbuffers_voffset_t; // little-endian byte order ++typedef flatbuffers_vector(void) flatbuffers_vector_t; ++ ++struct table_data ++{ ++ uint16_t length; ++ const uint8_t *data; ++}; ++ ++static const void * ++read_flatbuffers_uoffset(const uint8_t buffer[const], ++ const size_t buffer_len, ++ const flatbuffers_uoffset_t *const ref, ++ const size_t size) ++{ ++ assert((const uint8_t *)ref >= buffer && (const uint8_t *)ref <= &buffer[buffer_len - sizeof(*ref)]); ++ const uint32_t offset = le32toh(*ref); ++ const size_t cap = &buffer[buffer_len] - (const uint8_t *)ref; ++ const void *const result = (const uint8_t *)ref + offset; ++ if (offset == 0 || cap < size || offset > cap - size || ((uintptr_t)result & 0x3) != 0) { ++ return NULL; ++ } ++ return result; ++} ++ ++static struct table_data ++read_flatbuffers_table(const uint8_t buffer[const], ++ const size_t buffer_len, ++ const flatbuffers_uoffset_t *const ref, ++ uint16_t vtable_out[const], ++ const uint16_t vtable_cap) ++{ ++ memset(vtable_out, 0, vtable_cap * sizeof(*vtable_out)); ++ const flatbuffers_soffset_t *const table = read_flatbuffers_uoffset(buffer, buffer_len, ref, sizeof(*table)); ++ if (table == NULL) { ++ return (struct table_data){0}; ++ } ++ const flatbuffers_voffset_t *const vtable = ++ (const flatbuffers_voffset_t *)((const uint8_t *)table - (int32_t)le32toh(*table)); ++ if ((const uint8_t *)vtable < buffer || (const uint8_t *)vtable > &buffer[buffer_len - 2 * sizeof(*vtable)]) { ++ return (struct table_data){0}; ++ } ++ const uint16_t vtable_size = le16toh(vtable[0]), table_size = le16toh(vtable[1]); ++ if (vtable_size > &buffer[buffer_len] - (const uint8_t *)vtable || ++ table_size > &buffer[buffer_len] - (const uint8_t *)table || (vtable_size & 0x1) != 0 || ++ table_size < sizeof(*table)) { ++ return (struct table_data){0}; ++ } ++ for (uint16_t i = 0, length = MIN(vtable_size / sizeof(*vtable) - 2, vtable_cap); i < length; ++i) { ++ const flatbuffers_voffset_t offset = le16toh(vtable[2 + i]); ++ if (offset < table_size) { ++ vtable_out[i] = offset; ++ } ++ } ++ return (struct table_data){table_size, (const uint8_t *)table}; ++} ++ ++static flatbuffers_vector_t ++read_flatbuffers_vector(const uint8_t buffer[const], ++ const size_t buffer_len, ++ const flatbuffers_uoffset_t *const ref, ++ const size_t element_size) ++{ ++ const uint32_t *const vector = read_flatbuffers_uoffset(buffer, buffer_len, ref, sizeof(*vector)); ++ if (vector == NULL) { ++ return (flatbuffers_vector_t){0}; ++ } ++ const flatbuffers_vector_t out = { ++ .length = le32toh(*vector), ++ .data = &vector[1], ++ }; ++ if (out.length > (&buffer[buffer_len] - (const uint8_t *)out.data) / element_size) { ++ return (flatbuffers_vector_t){0}; ++ } ++ return out; ++} ++ ++static bool ++read_solarxr_quat(struct xrt_quat *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const uint16_t offset) ++{ ++ static_assert(offsetof(struct xrt_quat, x) == 0, ""); ++ static_assert(offsetof(struct xrt_quat, y) == 4, ""); ++ static_assert(offsetof(struct xrt_quat, z) == 8, ""); ++ static_assert(offsetof(struct xrt_quat, w) == 12, ""); ++ static_assert(sizeof(struct xrt_quat) == 16, ""); ++ *out = (struct xrt_quat){.w = 1}; ++ if (offset == 0 || offset + sizeof(*out) > buffer_len) { ++ return false; ++ } ++ memcpy(out, &buffer[offset], sizeof(*out)); ++ return true; ++} ++ ++static bool ++read_solarxr_vec3f(struct xrt_vec3 *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const uint16_t offset) ++{ ++ static_assert(offsetof(struct xrt_vec3, x) == 0, ""); ++ static_assert(offsetof(struct xrt_vec3, y) == 4, ""); ++ static_assert(offsetof(struct xrt_vec3, z) == 8, ""); ++ static_assert(sizeof(struct xrt_vec3) == 12, ""); ++ *out = (struct xrt_vec3){0}; ++ if (offset == 0 || offset + sizeof(*out) > buffer_len) { ++ return false; ++ } ++ memcpy(out, &buffer[offset], sizeof(*out)); ++ return true; ++} ++ ++bool ++read_solarxr_message_bundle(struct solarxr_message_bundle *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_message_bundle_t *const ref) ++{ ++ *out = (struct solarxr_message_bundle){0}; ++ uint16_t bundle_vtable[2]; ++ const struct table_data bundle = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, bundle_vtable, ARRAY_SIZE(bundle_vtable)); ++ if (bundle.length == 0) { ++ return false; ++ } ++ if (bundle_vtable[0] != 0 && bundle_vtable[0] + sizeof(flatbuffers_uoffset_t) <= bundle.length) { ++ *(flatbuffers_vector_t *)&out->data_feed_msgs = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&bundle.data[bundle_vtable[0]], ++ sizeof(*out->data_feed_msgs.data)); ++ } ++ if (bundle_vtable[1] != 0 && bundle_vtable[1] + sizeof(flatbuffers_uoffset_t) <= bundle.length) { ++ *(flatbuffers_vector_t *)&out->rpc_msgs = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&bundle.data[bundle_vtable[1]], ++ sizeof(*out->rpc_msgs.data)); ++ } ++ return true; ++} ++ ++bool ++read_solarxr_data_feed_message_header(struct solarxr_data_feed_message_header *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_data_feed_message_header_t *const ref) ++{ ++ *out = (struct solarxr_data_feed_message_header){0}; ++ uint16_t header_vtable[2]; ++ const struct table_data header = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, header_vtable, ARRAY_SIZE(header_vtable)); ++ if (header.length == 0) { ++ return false; ++ } ++ if (header_vtable[0] == 0 || header_vtable[1] == 0 || ++ header_vtable[1] + sizeof(flatbuffers_uoffset_t) > header.length) { ++ return true; ++ } ++ out->message_type = header.data[header_vtable[0]]; ++ switch (header.data[header_vtable[0]]) { ++ case SOLARXR_DATA_FEED_MESSAGE_DATA_FEED_UPDATE: { ++ uint16_t update_vtable[3]; ++ const struct table_data update = read_flatbuffers_table( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&header.data[header_vtable[1]], update_vtable, ++ ARRAY_SIZE(update_vtable)); ++ if (update.length == 0) { ++ break; ++ } ++ if (update_vtable[0] != 0 && update_vtable[0] + sizeof(flatbuffers_uoffset_t) <= update.length) { ++ *(flatbuffers_vector_t *)&out->message.data_feed_update.devices = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&update.data[update_vtable[0]], ++ sizeof(*out->message.data_feed_update.devices.data)); ++ } ++ if (update_vtable[1] != 0 && update_vtable[1] + sizeof(flatbuffers_uoffset_t) <= update.length) { ++ *(flatbuffers_vector_t *)&out->message.data_feed_update.synthetic_trackers = ++ read_flatbuffers_vector(buffer, buffer_len, ++ (const flatbuffers_uoffset_t *)&update.data[update_vtable[1]], ++ sizeof(*out->message.data_feed_update.synthetic_trackers.data)); ++ } ++ if (update_vtable[2] != 0 && update_vtable[2] + sizeof(flatbuffers_uoffset_t) <= update.length) { ++ *(flatbuffers_vector_t *)&out->message.data_feed_update.bones = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&update.data[update_vtable[2]], ++ sizeof(*out->message.data_feed_update.bones.data)); ++ } ++ break; ++ } ++ default:; ++ } ++ return true; ++} ++ ++bool ++read_solarxr_rpc_message_header(struct solarxr_rpc_message_header *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_rpc_message_header_t *const ref) ++{ ++ *out = (struct solarxr_rpc_message_header){0}; ++ uint16_t header_vtable[3]; ++ const struct table_data header = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, header_vtable, ARRAY_SIZE(header_vtable)); ++ if (header.length == 0) { ++ return false; ++ } ++ if (header_vtable[1] == 0 || header_vtable[2] == 0 || ++ header_vtable[2] + sizeof(flatbuffers_uoffset_t) > header.length) { ++ return true; ++ } ++ out->message_type = header.data[header_vtable[1]]; ++ switch (header.data[header_vtable[1]]) { ++ case SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_RESPONSE: { ++ uint16_t message_vtable[1]; ++ const struct table_data message = read_flatbuffers_table( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&header.data[header_vtable[2]], message_vtable, ++ ARRAY_SIZE(message_vtable)); ++ if (message.length == 0 || message_vtable[0] == 0 || ++ message_vtable[0] + sizeof(flatbuffers_uoffset_t) > message.length) { ++ break; ++ } ++ uint16_t trackers_vtable[15]; ++ const struct table_data trackers = read_flatbuffers_table( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&message.data[message_vtable[0]], ++ trackers_vtable, ARRAY_SIZE(trackers_vtable)); ++ if (trackers.length == 0) { ++ break; ++ } ++ if (trackers_vtable[0] != 0) { ++ out->message.settings_response.steam_vr_trackers.waist = trackers.data[trackers_vtable[0]]; ++ } ++ if (trackers_vtable[1] != 0) { ++ out->message.settings_response.steam_vr_trackers.chest = trackers.data[trackers_vtable[1]]; ++ } ++ if (trackers_vtable[7] != 0) { ++ out->message.settings_response.steam_vr_trackers.left_foot = trackers.data[trackers_vtable[7]]; ++ } ++ if (trackers_vtable[8] != 0) { ++ out->message.settings_response.steam_vr_trackers.right_foot = trackers.data[trackers_vtable[8]]; ++ } ++ if (trackers_vtable[9] != 0) { ++ out->message.settings_response.steam_vr_trackers.left_knee = trackers.data[trackers_vtable[9]]; ++ } ++ if (trackers_vtable[10] != 0) { ++ out->message.settings_response.steam_vr_trackers.right_knee = ++ trackers.data[trackers_vtable[10]]; ++ } ++ if (trackers_vtable[11] != 0) { ++ out->message.settings_response.steam_vr_trackers.left_elbow = ++ trackers.data[trackers_vtable[11]]; ++ } ++ if (trackers_vtable[12] != 0) { ++ out->message.settings_response.steam_vr_trackers.right_elbow = ++ trackers.data[trackers_vtable[12]]; ++ } ++ if (trackers_vtable[13] != 0) { ++ out->message.settings_response.steam_vr_trackers.left_hand = trackers.data[trackers_vtable[13]]; ++ } ++ if (trackers_vtable[14] != 0) { ++ out->message.settings_response.steam_vr_trackers.right_hand = ++ trackers.data[trackers_vtable[14]]; ++ } ++ break; ++ } ++ default:; ++ } ++ return true; ++} ++ ++bool ++read_solarxr_device_data(struct solarxr_device_data *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_device_data_t *const ref) ++{ ++ *out = (struct solarxr_device_data){0}; ++ uint16_t data_vtable[5]; ++ const struct table_data data = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, data_vtable, ARRAY_SIZE(data_vtable)); ++ if (data.length == 0) { ++ return false; ++ } ++ if (data_vtable[0] != 0) { ++ out->id = data.data[data_vtable[0]]; ++ } ++ if (data_vtable[4] != 0 && data_vtable[4] + sizeof(flatbuffers_uoffset_t) <= data.length) { ++ *(flatbuffers_vector_t *)&out->trackers = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&data.data[data_vtable[4]], ++ sizeof(*out->trackers.data)); ++ } ++ return true; ++} ++ ++bool ++read_solarxr_tracker_data(struct solarxr_tracker_data *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_tracker_data_t *const ref) ++{ ++ *out = (struct solarxr_tracker_data){0}; ++ uint16_t data_vtable[9]; ++ const struct table_data data = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, data_vtable, ARRAY_SIZE(data_vtable)); ++ if (data.length == 0) { ++ return false; ++ } ++ if (data_vtable[0] != 0 && data_vtable[0] + sizeof(flatbuffers_uoffset_t) <= data.length) { ++ uint16_t id_vtable[2]; ++ const struct table_data id = read_flatbuffers_table( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&data.data[data_vtable[0]], id_vtable, ++ ARRAY_SIZE(id_vtable)); ++ if (id_vtable[0] != 0) { ++ out->tracker_id.has_device_id = true; ++ out->tracker_id.device_id = id.data[id_vtable[0]]; ++ } ++ if (id_vtable[1] != 0) { ++ out->tracker_id.tracker_num = id.data[id_vtable[1]]; ++ } ++ } ++ if (data_vtable[1] != 0 && data_vtable[1] + sizeof(flatbuffers_uoffset_t) <= data.length) { ++ uint16_t info_vtable[8]; ++ const struct table_data info = read_flatbuffers_table( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&data.data[data_vtable[1]], info_vtable, ++ ARRAY_SIZE(info_vtable)); ++ out->has_info = true; ++ if (info_vtable[1] != 0) { ++ out->info.body_part = info.data[info_vtable[1]]; ++ } ++ if (info_vtable[7] != 0) { ++ *(flatbuffers_vector_t *)&out->info.display_name = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&info.data[info_vtable[7]], ++ sizeof(*out->info.display_name.data)); ++ } ++ } ++ out->has_rotation = read_solarxr_quat(&out->rotation, data.data, data.length, data_vtable[3]); ++ out->has_position = read_solarxr_vec3f(&out->position, data.data, data.length, data_vtable[4]); ++ out->has_raw_angular_velocity = ++ read_solarxr_vec3f(&out->raw_angular_velocity, data.data, data.length, data_vtable[5]); ++ out->has_linear_acceleration = ++ read_solarxr_vec3f(&out->linear_acceleration, data.data, data.length, data_vtable[8]); ++ return true; ++} ++ ++bool ++read_solarxr_bone(struct solarxr_bone *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_bone_t *const ref) ++{ ++ *out = (struct solarxr_bone){0}; ++ uint16_t bone_vtable[4]; ++ const struct table_data bone = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, bone_vtable, ARRAY_SIZE(bone_vtable)); ++ if (bone.length == 0) { ++ return false; ++ } ++ if (bone_vtable[0] != 0) { ++ out->body_part = bone.data[bone_vtable[0]]; ++ } ++ read_solarxr_quat(&out->rotation_g, bone.data, bone.length, bone_vtable[1]); ++ if (bone_vtable[2] != 0 && bone_vtable[2] + sizeof(out->bone_length) <= bone.length) { ++ memcpy(&out->bone_length, &bone.data[bone_vtable[2]], sizeof(out->bone_length)); ++ } ++ read_solarxr_vec3f(&out->head_position_g, bone.data, bone.length, bone_vtable[3]); ++ return true; ++} +diff --git a/src/xrt/drivers/solarxr/protocol.h b/src/xrt/drivers/solarxr/protocol.h +new file mode 100644 +index 0000000000..d85636fc98 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/protocol.h +@@ -0,0 +1,245 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++/*! ++ * @file ++ * @brief Parser for a small subset of the SolarXR Flatbuffers protocol, as defined at ++ * https://github.com/SlimeVR/SolarXR-Protocol ++ * @ingroup drv_solarxr ++ */ ++ ++#pragma once ++#include "xrt/xrt_defines.h" ++#include ++ ++typedef uint32_t flatbuffers_uoffset_t; // little-endian byte order ++ ++enum solarxr_body_part ++{ ++ SOLARXR_BODY_PART_NONE = 0, ++ SOLARXR_BODY_PART_HEAD = 1, ++ SOLARXR_BODY_PART_NECK = 2, ++ SOLARXR_BODY_PART_CHEST = 3, ++ SOLARXR_BODY_PART_WAIST = 4, ++ SOLARXR_BODY_PART_HIP = 5, ++ SOLARXR_BODY_PART_LEFT_UPPER_LEG = 6, ++ SOLARXR_BODY_PART_RIGHT_UPPER_LEG = 7, ++ SOLARXR_BODY_PART_LEFT_LOWER_LEG = 8, ++ SOLARXR_BODY_PART_RIGHT_LOWER_LEG = 9, ++ SOLARXR_BODY_PART_LEFT_FOOT = 10, ++ SOLARXR_BODY_PART_RIGHT_FOOT = 11, ++ SOLARXR_BODY_PART_LEFT_LOWER_ARM = 14, ++ SOLARXR_BODY_PART_RIGHT_LOWER_ARM = 15, ++ SOLARXR_BODY_PART_LEFT_UPPER_ARM = 16, ++ SOLARXR_BODY_PART_RIGHT_UPPER_ARM = 17, ++ SOLARXR_BODY_PART_LEFT_HAND = 18, ++ SOLARXR_BODY_PART_RIGHT_HAND = 19, ++ SOLARXR_BODY_PART_LEFT_SHOULDER = 20, ++ SOLARXR_BODY_PART_RIGHT_SHOULDER = 21, ++ SOLARXR_BODY_PART_UPPER_CHEST = 22, ++ SOLARXR_BODY_PART_LEFT_HIP = 23, ++ SOLARXR_BODY_PART_RIGHT_HIP = 24, ++ SOLARXR_BODY_PART_LEFT_THUMB_PROXIMAL = 25, ++ SOLARXR_BODY_PART_LEFT_THUMB_INTERMEDIATE = 26, ++ SOLARXR_BODY_PART_LEFT_THUMB_DISTAL = 27, ++ SOLARXR_BODY_PART_LEFT_INDEX_PROXIMAL = 28, ++ SOLARXR_BODY_PART_LEFT_INDEX_INTERMEDIATE = 29, ++ SOLARXR_BODY_PART_LEFT_INDEX_DISTAL = 30, ++ SOLARXR_BODY_PART_LEFT_MIDDLE_PROXIMAL = 31, ++ SOLARXR_BODY_PART_LEFT_MIDDLE_INTERMEDIATE = 32, ++ SOLARXR_BODY_PART_LEFT_MIDDLE_DISTAL = 33, ++ SOLARXR_BODY_PART_LEFT_RING_PROXIMAL = 34, ++ SOLARXR_BODY_PART_LEFT_RING_INTERMEDIATE = 35, ++ SOLARXR_BODY_PART_LEFT_RING_DISTAL = 36, ++ SOLARXR_BODY_PART_LEFT_LITTLE_PROXIMAL = 37, ++ SOLARXR_BODY_PART_LEFT_LITTLE_INTERMEDIATE = 38, ++ SOLARXR_BODY_PART_LEFT_LITTLE_DISTAL = 39, ++ SOLARXR_BODY_PART_RIGHT_THUMB_PROXIMAL = 40, ++ SOLARXR_BODY_PART_RIGHT_THUMB_INTERMEDIATE = 41, ++ SOLARXR_BODY_PART_RIGHT_THUMB_DISTAL = 42, ++ SOLARXR_BODY_PART_RIGHT_INDEX_PROXIMAL = 43, ++ SOLARXR_BODY_PART_RIGHT_INDEX_INTERMEDIATE = 44, ++ SOLARXR_BODY_PART_RIGHT_INDEX_DISTAL = 45, ++ SOLARXR_BODY_PART_RIGHT_MIDDLE_PROXIMAL = 46, ++ SOLARXR_BODY_PART_RIGHT_MIDDLE_INTERMEDIATE = 47, ++ SOLARXR_BODY_PART_RIGHT_MIDDLE_DISTAL = 48, ++ SOLARXR_BODY_PART_RIGHT_RING_PROXIMAL = 49, ++ SOLARXR_BODY_PART_RIGHT_RING_INTERMEDIATE = 50, ++ SOLARXR_BODY_PART_RIGHT_RING_DISTAL = 51, ++ SOLARXR_BODY_PART_RIGHT_LITTLE_PROXIMAL = 52, ++ SOLARXR_BODY_PART_RIGHT_LITTLE_INTERMEDIATE = 53, ++ SOLARXR_BODY_PART_RIGHT_LITTLE_DISTAL = 54, ++ SOLARXR_BODY_PART_MAX_ENUM, ++}; ++ ++#define flatbuffers_vector(type_) \ ++ struct \ ++ { \ ++ uint32_t length; \ ++ const type_ *data; \ ++ } ++ ++struct solarxr_tracker_id ++{ // table solarxr_protocol.datatypes.TrackerId ++ bool has_device_id; ++ uint8_t device_id; ++ uint8_t tracker_num; ++}; ++ ++struct solarxr_tracker_info ++{ // table solarxr_protocol.data_feed.tracker.TrackerInfo ++ enum solarxr_body_part body_part; ++ flatbuffers_vector(char) display_name; ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_tracker_data_t; ++ ++struct solarxr_tracker_data ++{ // table solarxr_protocol.data_feed.tracker.TrackerData ++ bool has_info; ++ bool has_rotation; ++ bool has_position; ++ bool has_raw_angular_velocity; ++ bool has_linear_acceleration; ++ struct solarxr_tracker_id tracker_id; ++ struct solarxr_tracker_info info; ++ struct xrt_quat rotation; ++ struct xrt_vec3 position; ++ struct xrt_vec3 raw_angular_velocity; ++ struct xrt_vec3 linear_acceleration; ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_device_data_t; ++ ++struct solarxr_device_data ++{ // table solarxr_protocol.data_feed.device_data.DeviceData ++ uint8_t id; ++ flatbuffers_vector(solarxr_tracker_data_t) trackers; // solarxr_protocol.data_feed.tracker.TrackerData[] ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_bone_t; ++ ++struct solarxr_bone ++{ // table solarxr_protocol.data_feed.Bone ++ enum solarxr_body_part body_part; ++ struct xrt_quat rotation_g; ++ float bone_length; ++ struct xrt_vec3 head_position_g; ++}; ++ ++struct solarxr_data_feed_update ++{ // table solarxr_protocol.data_feed.DataFeedUpdate ++ flatbuffers_vector(solarxr_device_data_t) devices; // solarxr_protocol.data_feed.device_data.DeviceData[] ++ flatbuffers_vector(solarxr_tracker_data_t) ++ synthetic_trackers; // solarxr_protocol.data_feed.tracker.TrackerData[] ++ flatbuffers_vector(solarxr_bone_t) bones; // solarxr_protocol.data_feed.Bone[] ++}; ++ ++enum solarxr_data_feed_message_type ++{ ++ SOLARXR_DATA_FEED_MESSAGE_POLL_DATA_FEED = 1, ++ SOLARXR_DATA_FEED_MESSAGE_DATA_FEED_UPDATE = 3, ++}; ++ ++union solarxr_data_feed_message { // union solarxr_protocol.data_feed.DataFeedMessage ++ struct solarxr_data_feed_update data_feed_update; ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_data_feed_message_header_t; ++ ++struct solarxr_data_feed_message_header ++{ // table solarxr_protocol.data_feed.DataFeedMessageHeader ++ enum solarxr_data_feed_message_type message_type; ++ union solarxr_data_feed_message message; ++}; ++ ++struct solarxr_steamvr_trackers_setting ++{ // table solarxr_protocol.rpc.SteamVRTrackersSetting ++ bool waist; ++ bool chest; ++ bool left_foot; ++ bool right_foot; ++ bool left_knee; ++ bool right_knee; ++ bool left_elbow; ++ bool right_elbow; ++ bool left_hand; ++ bool right_hand; ++}; ++ ++struct solarxr_settings_response ++{ // table solarxr_protocol.rpc.SettingsResponse ++ struct solarxr_steamvr_trackers_setting steam_vr_trackers; ++}; ++ ++enum solarxr_rpc_message_type ++{ ++ SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_REQUEST = 6, ++ SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_RESPONSE = 7, ++}; ++ ++union solarxr_rpc_message { // union solarxr_protocol.rpc.RpcMessage ++ struct solarxr_settings_response settings_response; ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_rpc_message_header_t; ++ ++struct solarxr_rpc_message_header ++{ // table solarxr_protocol.rpc.RpcMessageHeader ++ enum solarxr_rpc_message_type message_type; ++ union solarxr_rpc_message message; ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_message_bundle_t; ++ ++struct solarxr_message_bundle ++{ // table solarxr_protocol.MessageBundle ++ flatbuffers_vector(solarxr_data_feed_message_header_t) ++ data_feed_msgs; // solarxr_protocol.data_feed.DataFeedMessageHeader[] ++ flatbuffers_vector(solarxr_rpc_message_header_t) rpc_msgs; // solarxr_protocol.rpc.RpcMessageHeader[] ++}; ++ ++bool ++read_solarxr_message_bundle(struct solarxr_message_bundle *out, ++ const uint8_t buffer[], ++ size_t buffer_len, ++ const solarxr_message_bundle_t *ref); ++bool ++read_solarxr_data_feed_message_header(struct solarxr_data_feed_message_header *out, ++ const uint8_t buffer[], ++ size_t buffer_len, ++ const solarxr_data_feed_message_header_t *ref); ++bool ++read_solarxr_rpc_message_header(struct solarxr_rpc_message_header *out, ++ const uint8_t buffer[], ++ size_t buffer_len, ++ const solarxr_rpc_message_header_t *ref); ++bool ++read_solarxr_device_data(struct solarxr_device_data *out, ++ const uint8_t buffer[], ++ size_t buffer_len, ++ const solarxr_device_data_t *ref); ++bool ++read_solarxr_tracker_data(struct solarxr_tracker_data *out, ++ const uint8_t buffer[], ++ size_t buffer_len, ++ const solarxr_tracker_data_t *ref); ++bool ++read_solarxr_bone(struct solarxr_bone *out, const uint8_t buffer[], size_t buffer_len, const solarxr_bone_t *ref); +diff --git a/src/xrt/drivers/solarxr/solarxr_device.c b/src/xrt/drivers/solarxr/solarxr_device.c +new file mode 100644 +index 0000000000..e0dfc2f75a +--- /dev/null ++++ b/src/xrt/drivers/solarxr/solarxr_device.c +@@ -0,0 +1,1114 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#include "solarxr_interface.h" ++#include "feeder.h" ++#include "protocol.h" ++ ++#include "math/m_api.h" ++#include "math/m_relation_history.h" ++#include "math/m_vec3.h" ++#include "os/os_time.h" ++#include "util/u_debug.h" ++#include "util/u_device.h" ++ ++#include "xrt/xrt_config_build.h" // TODO: drop `#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META` guards once !2206 is merged ++ ++#include ++#include ++#include ++#include ++ ++#define MAX_GENERIC_TRACKERS 32 ++ ++DEBUG_GET_ONCE_LOG_OPTION(solarxr_log, "SOLARXR_LOG", U_LOGGING_WARN) ++DEBUG_GET_ONCE_BOOL_OPTION(solarxr_raw_trackers, "SOLARXR_RAW_TRACKERS", false) ++DEBUG_GET_ONCE_NUM_OPTION(solarxr_sync_delay_ms, "SOLARXR_SYNC_DELAY_MS", 4) ++DEBUG_GET_ONCE_NUM_OPTION(solarxr_sync_timeout_ms, "SOLARXR_SYNC_TIMEOUT_MS", 50) ++ ++struct solarxr_device; ++struct solarxr_generic_tracker ++{ ++ struct xrt_device base; ++ struct m_relation_history *history; ++ enum solarxr_body_part role; ++ struct solarxr_device *parent; ++ struct solarxr_generic_tracker **weak_ref; ++}; ++ ++struct solarxr_device ++{ ++ struct xrt_device base; ++ struct feeder feeder; ++ struct os_thread thread; ++ struct ipc_socket socket; ++ _Atomic(int64_t) next_sync; ++ struct os_mutex mutex; ++ _Atomic(int64_t) timestamp; ++ _Atomic(uint64_t) enabled_bones; ++ static_assert(SOLARXR_BODY_PART_MAX_ENUM <= 64, "bitfield too small"); ++ struct solarxr_device_bone ++ { ++ struct xrt_pose pose; ++ float length; ++ } bones[SOLARXR_BODY_PART_MAX_ENUM]; ++ wchar_t tracker_ids[MAX_GENERIC_TRACKERS]; ++ struct solarxr_generic_tracker *trackers[MAX_GENERIC_TRACKERS]; ++ bool use_trackers; ++ uint32_t generation; ++ struct xrt_tracking_origin standalone_origin; ++}; ++ ++struct span ++{ ++ size_t length; ++ const uint8_t *data; ++}; ++ ++static void ++solarxr_device_destroy(struct xrt_device *xdev); ++static void ++solarxr_generic_tracker_destroy(struct xrt_device *xdev); ++ ++static inline struct solarxr_device * ++solarxr_device(struct xrt_device *const xdev) ++{ ++ if (xdev == NULL || xdev->destroy != solarxr_device_destroy) { ++ return NULL; ++ } ++ return (struct solarxr_device *)xdev; ++} ++ ++static inline struct solarxr_generic_tracker * ++solarxr_generic_tracker(struct xrt_device *const xdev) ++{ ++ if (xdev == NULL || xdev->destroy != solarxr_generic_tracker_destroy) { ++ return NULL; ++ } ++ return (struct solarxr_generic_tracker *)xdev; ++} ++ ++// returns an arbitrary unique value to identify trackers by ++static inline wchar_t ++solarxr_tracker_id_to_wchar(struct solarxr_tracker_id id) ++{ ++ if (!id.has_device_id) { ++ id.device_id = 0; ++ } ++ wchar_t out = 0; ++ static_assert(sizeof(id) <= sizeof(out), ""); ++ memcpy(&out, &id, sizeof(id)); ++ return le32toh(out); ++} ++ ++static void ++solarxr_device_sync(struct solarxr_device *const device) ++{ ++ const int64_t time = os_monotonic_get_ns(), next_sync = atomic_exchange(&device->next_sync, INT64_MAX); ++ if (time <= next_sync) { ++ atomic_store(&device->next_sync, next_sync); ++ return; ++ } ++ ++ struct poll_packet ++ { ++ uint32_t _root; ++ uint16_t _table_shared[3]; ++ struct ++ { // table MessageBundle ++ int32_t _table; ++ uint32_t data_feed_msgs; // vector* ++ } bundle; ++ struct ++ { // vector ++ uint32_t length; ++ uint32_t values[1]; // table* ++ } data_feed_msgs; ++ uint16_t _table_data_feed_msgs_0[4]; ++ struct ++ { // table DataFeedMessageHeader ++ int32_t _table; ++ uint32_t message; // table* ++ uint8_t message_type; // enum DataFeedMessage ++ uint8_t _pad[3]; ++ } data_feed_msgs_0; ++ struct ++ { // table PollDataFeed ++ int32_t _table; ++ uint32_t config; // table* ++ } message; ++ uint16_t _table_config[6]; ++ struct ++ { // table DataFeedConfig ++ int32_t _table; ++ uint32_t trackers_mask; // table* ++ bool bone_mask; ++ uint8_t _pad[3]; ++ } config; ++ struct ++ { // table DeviceDataMask ++ int32_t _table; ++ uint32_t tracker_data; // table* ++ } data_mask; ++ uint16_t _table_synthetic_trackers_mask[10]; ++ struct ++ { // table TrackerDataMask ++ int32_t _table; ++ bool rotation, position, raw_angular_velocity, linear_acceleration; ++ } synthetic_trackers_mask; ++ } const poll_packet = { ++ ._root = htole32(offsetof(struct poll_packet, bundle)), ++ ._table_shared = ++ { ++ htole16(sizeof(poll_packet._table_shared)), ++ htole16(8), ++ htole16(4), ++ }, ++ .bundle = ++ { ++ ._table = ++ htole32(offsetof(struct poll_packet, bundle) - offsetof(struct poll_packet, _table_shared)), ++ .data_feed_msgs = htole32(offsetof(struct poll_packet, data_feed_msgs) - ++ offsetof(struct poll_packet, bundle.data_feed_msgs)), ++ }, ++ .data_feed_msgs = ++ { ++ .length = htole32(ARRAY_SIZE(poll_packet.data_feed_msgs.values)), ++ .values = {htole32(offsetof(struct poll_packet, data_feed_msgs_0) - ++ offsetof(struct poll_packet, data_feed_msgs.values[0]))}, ++ }, ++ ._table_data_feed_msgs_0 = ++ { ++ htole16(sizeof(poll_packet._table_data_feed_msgs_0)), ++ htole16(sizeof(poll_packet.data_feed_msgs_0) - sizeof(poll_packet.data_feed_msgs_0._pad)), ++ htole16(offsetof(struct poll_packet, data_feed_msgs_0.message_type) - ++ offsetof(struct poll_packet, data_feed_msgs_0)), ++ htole16(offsetof(struct poll_packet, data_feed_msgs_0.message) - ++ offsetof(struct poll_packet, data_feed_msgs_0)), ++ }, ++ .data_feed_msgs_0 = ++ { ++ ._table = htole32(offsetof(struct poll_packet, data_feed_msgs_0) - ++ offsetof(struct poll_packet, _table_data_feed_msgs_0)), ++ .message = htole32(offsetof(struct poll_packet, message) - ++ offsetof(struct poll_packet, data_feed_msgs_0.message)), ++ .message_type = 1, // DataFeedMessage::PollDataFeed ++ }, ++ .message = ++ { ++ ._table = ++ htole32(offsetof(struct poll_packet, message) - offsetof(struct poll_packet, _table_shared)), ++ .config = ++ htole32(offsetof(struct poll_packet, config) - offsetof(struct poll_packet, message.config)), ++ }, ++ ._table_config = ++ { ++ htole16(sizeof(poll_packet._table_config)), ++ htole16(sizeof(poll_packet.config) - sizeof(poll_packet.config._pad)), ++ 0, ++ htole16( ++ (device->use_trackers && debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct poll_packet, config.trackers_mask) - offsetof(struct poll_packet, config))), ++ htole16( ++ (device->use_trackers && !debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct poll_packet, config.trackers_mask) - offsetof(struct poll_packet, config))), ++ htole16(offsetof(struct poll_packet, config.bone_mask) - offsetof(struct poll_packet, config)), ++ }, ++ .config = ++ { ++ ._table = ++ htole32(offsetof(struct poll_packet, config) - offsetof(struct poll_packet, _table_config)), ++ .trackers_mask = htole32((debug_get_bool_option_solarxr_raw_trackers() ++ ? offsetof(struct poll_packet, data_mask) ++ : offsetof(struct poll_packet, synthetic_trackers_mask)) - ++ offsetof(struct poll_packet, config.trackers_mask)), ++ .bone_mask = true, ++ }, ++ .data_mask = ++ { ++ ._table = ++ htole32(offsetof(struct poll_packet, data_mask) - offsetof(struct poll_packet, _table_shared)), ++ .tracker_data = htole32(offsetof(struct poll_packet, synthetic_trackers_mask) - ++ offsetof(struct poll_packet, data_mask.tracker_data)), ++ }, ++ ._table_synthetic_trackers_mask = ++ { ++ htole16(sizeof(poll_packet._table_synthetic_trackers_mask)), ++ htole16(sizeof(poll_packet.synthetic_trackers_mask)), ++ 0, ++ 0, ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.rotation) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.position) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.raw_angular_velocity) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ 0, ++ 0, ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.linear_acceleration) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ }, ++ .synthetic_trackers_mask = ++ { ++ ._table = htole32(offsetof(struct poll_packet, synthetic_trackers_mask) - ++ offsetof(struct poll_packet, _table_synthetic_trackers_mask)), ++ .rotation = true, ++ .position = true, ++ .raw_angular_velocity = true, ++ .linear_acceleration = true, ++ }, ++ }; ++ ++ feeder_send_feedback(&device->feeder, time); ++ ipc_socket_send(&device->socket, (const uint8_t *)&poll_packet, ++ device->use_trackers ? sizeof(poll_packet) : offsetof(struct poll_packet, data_mask)); ++ atomic_store(&device->next_sync, time + debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS); ++} ++ ++static xrt_result_t ++solarxr_device_update_inputs(struct xrt_device *const xdev) ++{ ++ struct solarxr_device *const device = solarxr_device(xdev); ++ assert(device != NULL); ++ const int64_t time = os_monotonic_get_ns(); ++ if (time - atomic_load(&device->feeder.last_send) > ++ debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS) { ++ // ensures SlimeVR continues to receive head positions even if no XR app is running ++ feeder_send_feedback(&device->feeder, time); ++ } ++ ++ for (uint32_t i = 0; i < device->base.input_count; ++i) { ++ device->base.inputs[i].timestamp = atomic_load(&device->timestamp); ++ } ++ return XRT_SUCCESS; ++} ++ ++static xrt_result_t ++solarxr_generic_tracker_update_inputs(struct xrt_device *const xdev) ++{ ++ struct solarxr_generic_tracker *const device = solarxr_generic_tracker(xdev); ++ assert(device != NULL); ++ struct solarxr_device *const parent = device->parent; ++ device->base.inputs[0].active = (atomic_load(&parent->enabled_bones) & (1llu << device->role)) != 0; ++ device->base.inputs[0].timestamp = atomic_load(&parent->timestamp); ++ return XRT_SUCCESS; ++} ++ ++static inline struct xrt_body_skeleton_joint_fb ++offset_joint(const struct xrt_body_skeleton_joint_fb parent, const int32_t name, const struct xrt_vec3 offset) ++{ ++ return (struct xrt_body_skeleton_joint_fb){ ++ .pose = ++ { ++ .orientation = parent.pose.orientation, ++ .position = m_vec3_add(parent.pose.position, offset), ++ }, ++ .joint = name, ++ .parent_joint = parent.joint, ++ }; ++} ++ ++// TODO: filter enabled bones ++static xrt_result_t ++solarxr_device_get_body_skeleton(struct xrt_device *const xdev, ++ const enum xrt_input_name body_tracking_type, ++ struct xrt_body_skeleton *const out_value) ++{ ++ struct xrt_body_skeleton_joint_fb *joints; ++ uint32_t joint_count; ++ int32_t none; ++ switch (body_tracking_type) { ++ case XRT_INPUT_FB_BODY_TRACKING: { ++ joints = out_value->body_skeleton_fb.joints; ++ joint_count = ARRAY_SIZE(out_value->body_skeleton_fb.joints); ++ none = XRT_BODY_JOINT_NONE_FB; ++ break; ++ } ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ case XRT_INPUT_META_FULL_BODY_TRACKING: { ++ joints = out_value->full_body_skeleton_meta.joints; ++ joint_count = ARRAY_SIZE(out_value->full_body_skeleton_meta.joints); ++ none = XRT_FULL_BODY_JOINT_NONE_META; ++ break; ++ } ++#endif ++ default: return XRT_ERROR_NOT_IMPLEMENTED; ++ } ++ ++ struct solarxr_device *const device = solarxr_device(xdev); ++ assert(device != NULL); ++ for (uint32_t i = 0; i < joint_count; ++i) { ++ joints[i] = (struct xrt_body_skeleton_joint_fb){XRT_POSE_IDENTITY, none, none}; ++ } ++ ++ // The standard doesn't describe the layout for these joints more specifically than being "a T-pose" ++ // clang-format off ++ joints[0] = (struct xrt_body_skeleton_joint_fb){XRT_POSE_IDENTITY, XRT_BODY_JOINT_HEAD_FB, XRT_BODY_JOINT_ROOT_FB}; ++ joints[1] = offset_joint(joints[0], XRT_BODY_JOINT_NECK_FB, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_NECK].length, 0.f}); ++ joints[2] = offset_joint(joints[1], XRT_BODY_JOINT_CHEST_FB, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_UPPER_CHEST].length, 0.f}); ++ joints[3] = offset_joint(joints[2], XRT_BODY_JOINT_SPINE_UPPER_FB, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_CHEST].length, 0.f}); ++ joints[4] = offset_joint(joints[3], XRT_BODY_JOINT_SPINE_LOWER_FB, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_WAIST].length, 0.f}); ++ joints[5] = offset_joint(joints[4], XRT_BODY_JOINT_HIPS_FB, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_HIP].length, 0.f}); ++ joints[6] = offset_joint(joints[1], XRT_BODY_JOINT_LEFT_SHOULDER_FB, (struct xrt_vec3){-device->bones[SOLARXR_BODY_PART_LEFT_SHOULDER].length, 0.f, 0.f}); ++ joints[7] = offset_joint(joints[1], XRT_BODY_JOINT_RIGHT_SHOULDER_FB, (struct xrt_vec3){device->bones[SOLARXR_BODY_PART_RIGHT_SHOULDER].length, 0.f, 0.f}); ++ joints[8] = offset_joint(joints[6], XRT_BODY_JOINT_LEFT_ARM_UPPER_FB, (struct xrt_vec3){-device->bones[SOLARXR_BODY_PART_LEFT_UPPER_ARM].length, 0.f, 0.f}); ++ joints[9] = offset_joint(joints[7], XRT_BODY_JOINT_RIGHT_ARM_UPPER_FB, (struct xrt_vec3){device->bones[SOLARXR_BODY_PART_RIGHT_UPPER_ARM].length, 0.f, 0.f}); ++ joints[10] = offset_joint(joints[8], XRT_BODY_JOINT_LEFT_ARM_LOWER_FB, (struct xrt_vec3){-device->bones[SOLARXR_BODY_PART_LEFT_LOWER_ARM].length, 0.f, 0.f}); ++ joints[11] = offset_joint(joints[9], XRT_BODY_JOINT_RIGHT_ARM_LOWER_FB, (struct xrt_vec3){device->bones[SOLARXR_BODY_PART_RIGHT_LOWER_ARM].length, 0.f, 0.f}); ++ joints[12] = offset_joint(joints[10], XRT_BODY_JOINT_LEFT_HAND_WRIST_FB, (struct xrt_vec3){-device->bones[SOLARXR_BODY_PART_LEFT_HAND].length, 0.f, 0.f}); ++ joints[13] = offset_joint(joints[11], XRT_BODY_JOINT_RIGHT_HAND_WRIST_FB, (struct xrt_vec3){device->bones[SOLARXR_BODY_PART_RIGHT_HAND].length, 0.f, 0.f}); ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ if (body_tracking_type != XRT_INPUT_META_FULL_BODY_TRACKING) { ++ return XRT_SUCCESS; ++ } ++ joints[14] = offset_joint(joints[5], XRT_FULL_BODY_JOINT_LEFT_UPPER_LEG_META, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_LEFT_UPPER_LEG].length, 0.f}); ++ joints[15] = offset_joint(joints[5], XRT_FULL_BODY_JOINT_RIGHT_UPPER_LEG_META, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_RIGHT_UPPER_LEG].length, 0.f}); ++ joints[16] = offset_joint(joints[14], XRT_FULL_BODY_JOINT_LEFT_LOWER_LEG_META, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_LEFT_LOWER_LEG].length, 0.f}); ++ joints[17] = offset_joint(joints[15], XRT_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_RIGHT_LOWER_LEG].length, 0.f}); ++ joints[18] = offset_joint(joints[16], XRT_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META, (struct xrt_vec3){0.f, 0.f, -device->bones[SOLARXR_BODY_PART_LEFT_FOOT].length}); ++ joints[19] = offset_joint(joints[17], XRT_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META, (struct xrt_vec3){0.f, 0.f, -device->bones[SOLARXR_BODY_PART_RIGHT_FOOT].length}); ++#endif ++ // clang-format on ++ return XRT_SUCCESS; ++} ++ ++// TODO: filter enabled bones ++static xrt_result_t ++solarxr_device_get_body_joints(struct xrt_device *const xdev, ++ const enum xrt_input_name body_tracking_type, ++ const int64_t desired_timestamp_ns, ++ struct xrt_body_joint_set *const out_value) ++{ ++ static const uint32_t jointMap[SOLARXR_BODY_PART_MAX_ENUM] = { ++ [SOLARXR_BODY_PART_HEAD] = XRT_BODY_JOINT_HEAD_FB, ++ [SOLARXR_BODY_PART_NECK] = XRT_BODY_JOINT_NECK_FB, ++ [SOLARXR_BODY_PART_CHEST] = XRT_BODY_JOINT_SPINE_UPPER_FB, ++ [SOLARXR_BODY_PART_WAIST] = XRT_BODY_JOINT_SPINE_LOWER_FB, ++ [SOLARXR_BODY_PART_HIP] = XRT_BODY_JOINT_HIPS_FB, ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ [SOLARXR_BODY_PART_LEFT_UPPER_LEG] = XRT_FULL_BODY_JOINT_LEFT_UPPER_LEG_META, ++ [SOLARXR_BODY_PART_RIGHT_UPPER_LEG] = XRT_FULL_BODY_JOINT_RIGHT_UPPER_LEG_META, ++ [SOLARXR_BODY_PART_LEFT_LOWER_LEG] = XRT_FULL_BODY_JOINT_LEFT_LOWER_LEG_META, ++ [SOLARXR_BODY_PART_RIGHT_LOWER_LEG] = XRT_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META, ++ [SOLARXR_BODY_PART_LEFT_FOOT] = XRT_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META, ++ [SOLARXR_BODY_PART_RIGHT_FOOT] = XRT_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META, ++#endif ++ [SOLARXR_BODY_PART_LEFT_LOWER_ARM] = XRT_BODY_JOINT_LEFT_ARM_LOWER_FB, ++ [SOLARXR_BODY_PART_RIGHT_LOWER_ARM] = XRT_BODY_JOINT_RIGHT_ARM_LOWER_FB, ++ [SOLARXR_BODY_PART_LEFT_UPPER_ARM] = XRT_BODY_JOINT_LEFT_ARM_UPPER_FB, ++ [SOLARXR_BODY_PART_RIGHT_UPPER_ARM] = XRT_BODY_JOINT_RIGHT_ARM_UPPER_FB, ++ [SOLARXR_BODY_PART_LEFT_HAND] = XRT_BODY_JOINT_LEFT_HAND_WRIST_FB, ++ [SOLARXR_BODY_PART_RIGHT_HAND] = XRT_BODY_JOINT_RIGHT_HAND_WRIST_FB, ++ [SOLARXR_BODY_PART_LEFT_SHOULDER] = XRT_BODY_JOINT_LEFT_SHOULDER_FB, ++ [SOLARXR_BODY_PART_RIGHT_SHOULDER] = XRT_BODY_JOINT_RIGHT_SHOULDER_FB, ++ [SOLARXR_BODY_PART_UPPER_CHEST] = XRT_BODY_JOINT_CHEST_FB, ++ // LEFT_HIP ++ // RIGHT_HIP ++ }; ++ struct xrt_body_joint_location_fb *joints; ++ uint32_t joint_count; ++ switch (body_tracking_type) { ++ case XRT_INPUT_FB_BODY_TRACKING: { ++ joints = out_value->body_joint_set_fb.joint_locations; ++ joint_count = ARRAY_SIZE(out_value->body_joint_set_fb.joint_locations); ++ break; ++ } ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ case XRT_INPUT_META_FULL_BODY_TRACKING: { ++ joints = out_value->full_body_joint_set_meta.joint_locations; ++ joint_count = ARRAY_SIZE(out_value->full_body_joint_set_meta.joint_locations); ++ break; ++ } ++#endif ++ default: return XRT_ERROR_NOT_IMPLEMENTED; ++ } ++ ++ struct solarxr_device *const device = solarxr_device(xdev); ++ assert(device != NULL); ++ solarxr_device_sync(device); ++ ++ os_mutex_lock(&device->mutex); ++ out_value->base_body_joint_set_meta.sample_time_ns = device->timestamp; ++ out_value->base_body_joint_set_meta.confidence = 1.f; // N/A ++ out_value->base_body_joint_set_meta.skeleton_changed_count = device->generation; ++ out_value->base_body_joint_set_meta.is_active = true; ++ for (uint32_t i = 0; i < joint_count; ++i) { ++ joints[i].relation = (struct xrt_space_relation)XRT_SPACE_RELATION_ZERO; ++ } ++ for (enum solarxr_body_part part = 0; part < ARRAY_SIZE(device->bones); ++part) { ++ const struct xrt_pose pose = device->bones[part].pose; ++ static_assert(ARRAY_SIZE(jointMap) == ARRAY_SIZE(device->bones), ""); ++ const uint32_t index = jointMap[part]; ++ if (index == 0 || index >= joint_count || ++ memcmp(&pose.orientation, &(struct xrt_quat){0}, sizeof(struct xrt_quat)) == 0) { ++ continue; ++ } ++ joints[index].relation = (struct xrt_space_relation){ ++ .relation_flags = XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | XRT_SPACE_RELATION_POSITION_VALID_BIT | ++ XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT | ++ XRT_SPACE_RELATION_POSITION_TRACKED_BIT, ++ .pose = pose, ++ }; ++ } ++ out_value->body_pose = (struct xrt_space_relation){ ++ .relation_flags = XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | XRT_SPACE_RELATION_POSITION_VALID_BIT | ++ XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT | XRT_SPACE_RELATION_POSITION_TRACKED_BIT, ++ .pose = XRT_POSE_IDENTITY, ++ }; ++ os_mutex_unlock(&device->mutex); ++ return XRT_SUCCESS; ++} ++ ++static void ++solarxr_device_handle_trackers(struct solarxr_device *const device, ++ const struct span buffer, ++ const solarxr_tracker_data_t trackers[const], ++ const uint32_t trackers_len) ++{ ++ for (uint32_t i = 0; i < trackers_len; ++i) { ++ struct solarxr_tracker_data data; ++ if (!read_solarxr_tracker_data(&data, buffer.data, buffer.length, &trackers[i])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_device_data() failed"); ++ continue; ++ } ++ // `wmemchr()` should be SIMD optimized, making it faster than a hash lookup in this case despite being ++ // O(n^2) ++ const wchar_t *const match = wmemchr(device->tracker_ids, solarxr_tracker_id_to_wchar(data.tracker_id), ++ ARRAY_SIZE(device->tracker_ids)); ++ if (match == NULL) { ++ continue; ++ } ++ struct solarxr_generic_tracker *const tracker = device->trackers[match - device->tracker_ids]; ++ if (tracker == NULL) { ++ continue; ++ } ++ struct xrt_space_relation relation = {.pose.orientation.w = 1}; ++ if (data.has_rotation) { ++ relation.relation_flags |= ++ XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT; ++ relation.pose.orientation = data.rotation; ++ } ++ if (data.has_position) { ++ relation.relation_flags |= ++ XRT_SPACE_RELATION_POSITION_VALID_BIT | XRT_SPACE_RELATION_POSITION_TRACKED_BIT; ++ relation.pose.position = data.position; ++ } ++ if (data.has_raw_angular_velocity) { ++ relation.relation_flags |= XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT; ++ relation.angular_velocity = data.raw_angular_velocity; ++ } ++ if (data.has_linear_acceleration) { ++ relation.relation_flags |= XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT; ++ relation.linear_velocity = data.linear_acceleration; ++ } ++ if (relation.relation_flags != 0) { ++ m_relation_history_push(tracker->history, &relation, device->socket.timestamp); ++ } ++ } ++} ++ ++static struct span ++ipc_socket_receive_blocking(struct ipc_socket *const socket) ++{ ++ do { ++ const uint32_t buffer_len = ipc_socket_receive(socket); ++ if (buffer_len != 0) { ++ return (struct span){buffer_len, socket->buffer}; ++ } ++ } while (ipc_socket_wait(socket)); ++ return (struct span){0}; ++} ++ ++static void * ++solarxr_network_thread(void *const ptr) ++{ ++ struct solarxr_device *const device = (struct solarxr_device *)ptr; ++ for (struct span buffer; (buffer = ipc_socket_receive_blocking(&device->socket)).length != 0;) { ++ struct solarxr_message_bundle bundle; ++ if (!read_solarxr_message_bundle(&bundle, buffer.data, buffer.length, ++ (const solarxr_message_bundle_t *)buffer.data)) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_message_bundle() failed"); ++ continue; ++ } ++ struct solarxr_steamvr_trackers_setting toggles; ++ bool toggles_changed = false; ++ for (uint32_t i = 0; i < bundle.rpc_msgs.length; ++i) { ++ struct solarxr_rpc_message_header header; ++ if (!read_solarxr_rpc_message_header(&header, buffer.data, buffer.length, ++ &bundle.rpc_msgs.data[i])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_rpc_message_header() failed"); ++ continue; ++ } ++ if (header.message_type != SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_RESPONSE) { ++ continue; ++ } ++ toggles = header.message.settings_response.steam_vr_trackers; ++ toggles_changed = true; ++ } ++ if (toggles_changed) { ++ // `SOLARXR_BODY_PART_HEAD` always disabled ++ uint64_t bones = 1llu << SOLARXR_BODY_PART_NECK; ++ bones |= (1llu << SOLARXR_BODY_PART_CHEST) * toggles.chest; ++ bones |= (1llu << SOLARXR_BODY_PART_WAIST) * toggles.waist; ++ bones |= (1llu << SOLARXR_BODY_PART_HIP) * toggles.waist; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_UPPER_LEG) * toggles.left_knee; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_UPPER_LEG) * toggles.right_knee; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_LOWER_LEG) * (toggles.left_knee && toggles.left_foot); ++ bones |= ++ (1llu << SOLARXR_BODY_PART_RIGHT_LOWER_LEG) * (toggles.right_knee && toggles.right_foot); ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_FOOT) * toggles.left_foot; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_FOOT) * toggles.right_foot; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_LOWER_ARM) * (toggles.left_elbow && toggles.left_hand); ++ bones |= ++ (1llu << SOLARXR_BODY_PART_RIGHT_LOWER_ARM) * (toggles.right_elbow && toggles.right_hand); ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_UPPER_ARM) * toggles.left_elbow; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_UPPER_ARM) * toggles.right_elbow; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_HAND) * toggles.left_hand; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_HAND) * toggles.right_hand; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_SHOULDER) * toggles.left_elbow; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_SHOULDER) * toggles.right_elbow; ++ bones |= (1llu << SOLARXR_BODY_PART_UPPER_CHEST) * toggles.chest; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_HIP) * toggles.waist; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_HIP) * toggles.waist; ++ bones |= ((2llu << SOLARXR_BODY_PART_LEFT_LITTLE_DISTAL) - ++ (1llu << SOLARXR_BODY_PART_LEFT_THUMB_PROXIMAL)) * ++ toggles.left_hand; ++ bones |= ((2llu << SOLARXR_BODY_PART_RIGHT_LITTLE_DISTAL) - ++ (1llu << SOLARXR_BODY_PART_RIGHT_THUMB_PROXIMAL)) * ++ toggles.right_hand; ++ atomic_store(&device->enabled_bones, bones); ++ } ++ if (bundle.data_feed_msgs.length == 0) { ++ continue; ++ } ++#if 0 // for latency testing ++ U_LOG_IFL_W(device->socket.log_level, "%.3fus", ((int64_t)os_monotonic_get_ns() - (atomic_load(&device->next_sync) - debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS)) / 1000.); ++#endif ++ atomic_store(&device->next_sync, ++ device->timestamp + debug_get_num_option_solarxr_sync_delay_ms() * U_TIME_1MS_IN_NS); ++ os_mutex_lock(&device->mutex); ++ flatbuffers_vector(solarxr_bone_t) bones = {0}; ++ for (uint32_t i = 0; i < bundle.data_feed_msgs.length; ++i) { ++ struct solarxr_data_feed_message_header header; ++ if (!read_solarxr_data_feed_message_header(&header, buffer.data, buffer.length, ++ &bundle.data_feed_msgs.data[0])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_data_feed_message_header() failed"); ++ continue; ++ } ++ if (header.message_type != SOLARXR_DATA_FEED_MESSAGE_DATA_FEED_UPDATE) { ++ continue; ++ } ++ if (debug_get_bool_option_solarxr_raw_trackers()) { ++ for (uint32_t j = 0; j < header.message.data_feed_update.devices.length; ++j) { ++ struct solarxr_device_data device_data; ++ if (!read_solarxr_device_data( ++ &device_data, buffer.data, buffer.length, ++ &header.message.data_feed_update.devices.data[j])) { ++ U_LOG_IFL_W(device->socket.log_level, ++ "read_solarxr_device_data() failed"); ++ continue; ++ } ++ solarxr_device_handle_trackers(device, buffer, device_data.trackers.data, ++ device_data.trackers.length); ++ } ++ } else { ++ solarxr_device_handle_trackers( ++ device, buffer, header.message.data_feed_update.synthetic_trackers.data, ++ header.message.data_feed_update.synthetic_trackers.length); ++ } ++ if (header.message.data_feed_update.bones.length != 0) { ++ bones.length = header.message.data_feed_update.bones.length; ++ bones.data = header.message.data_feed_update.bones.data; ++ } ++ } ++ if (bones.length != 0) { ++ atomic_store(&device->timestamp, device->socket.timestamp); ++ struct solarxr_device_bone newBones[ARRAY_SIZE(device->bones)] = {0}; ++ for (size_t i = 0; i < bones.length; ++i) { ++ struct solarxr_bone bone; ++ if (!read_solarxr_bone(&bone, buffer.data, buffer.length, &bones.data[i])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_bone() failed"); ++ continue; ++ } ++ if (bone.body_part >= ARRAY_SIZE(device->bones)) { ++ static bool _once = false; ++ if (!_once) { ++ _once = true; ++ U_LOG_IFL_W(device->socket.log_level, "Unexpected SolarXR BodyPart %u", ++ (unsigned)bone.body_part); ++ } ++ continue; ++ } ++ newBones[bone.body_part].pose = (struct xrt_pose){ ++ .orientation = bone.rotation_g, ++ .position = bone.head_position_g, ++ }; ++ newBones[bone.body_part].length = bone.bone_length; ++ } ++ for (uint32_t i = 0; i < ARRAY_SIZE(device->bones); ++i) { ++ if (memcmp(&newBones[i].length, &device->bones[i].length, sizeof(newBones[i].length)) != ++ 0) { ++ ++device->generation; ++ break; ++ } ++ } ++ memcpy(device->bones, newBones, sizeof(device->bones)); ++ } ++ os_mutex_unlock(&device->mutex); ++ } ++ return NULL; ++} ++ ++static void ++solarxr_device_destroy(struct xrt_device *xdev) ++{ ++ struct solarxr_device *const device = solarxr_device(xdev); ++ assert(device != NULL); ++ feeder_destroy(&device->feeder); ++ ipc_socket_destroy(&device->socket); ++ if (!pthread_equal(device->thread.thread, pthread_self())) { ++ os_thread_join(&device->thread); ++ os_thread_destroy(&device->thread); ++ } ++ for (uint32_t i = 0; i < ARRAY_SIZE(device->trackers); ++i) { ++ if (device->trackers[i] == NULL) { ++ continue; ++ } ++ device->trackers[i]->weak_ref = NULL; ++ device->trackers[i]->parent = NULL; ++ } ++ os_mutex_destroy(&device->mutex); ++ u_device_free(&device->base); ++} ++ ++static xrt_result_t ++solarxr_generic_tracker_get_tracked_pose(struct xrt_device *const xdev, ++ const enum xrt_input_name name, ++ const int64_t at_timestamp_ns, ++ struct xrt_space_relation *const out_relation) ++{ ++ struct solarxr_generic_tracker *const device = solarxr_generic_tracker(xdev); ++ assert(device != NULL); ++ struct solarxr_device *const parent = device->parent; ++ solarxr_device_sync(parent); ++ if ((atomic_load(&parent->enabled_bones) & (1llu << device->role)) == 0) { ++ *out_relation = (struct xrt_space_relation){0}; ++ return XRT_ERROR_INPUT_UNSUPPORTED; // TODO: adding/removing devices at runtime ++ } ++ m_relation_history_get(device->history, at_timestamp_ns, out_relation); ++ return XRT_SUCCESS; ++} ++ ++static void ++solarxr_generic_tracker_destroy(struct xrt_device *const xdev) ++{ ++ struct solarxr_generic_tracker *const device = solarxr_generic_tracker(xdev); ++ assert(device != NULL); ++ if (device->weak_ref != NULL) { ++ os_mutex_lock(&device->parent->mutex); ++ *device->weak_ref = NULL; ++ os_mutex_unlock(&device->parent->mutex); ++ } ++ m_relation_history_destroy(&device->history); ++ u_device_free(&device->base); ++} ++ ++uint32_t ++solarxr_device_create_xdevs(struct xrt_tracking_origin *const tracking_origin, ++ struct xrt_device *out_xdevs[const], ++ uint32_t out_xdevs_cap) ++{ ++ if (out_xdevs_cap == 0) { ++ return 0; ++ } ++ if (out_xdevs_cap - 1 > MAX_GENERIC_TRACKERS) { ++ out_xdevs_cap = 1 + MAX_GENERIC_TRACKERS; ++ } ++ ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ struct solarxr_device *const device = U_DEVICE_ALLOCATE(struct solarxr_device, U_DEVICE_ALLOC_NO_FLAGS, 2, 0); ++#else ++ struct solarxr_device *const device = U_DEVICE_ALLOCATE(struct solarxr_device, U_DEVICE_ALLOC_NO_FLAGS, 1, 0); ++#endif ++ device->base.name = XRT_DEVICE_FB_BODY_TRACKING; ++ device->base.device_type = XRT_DEVICE_TYPE_BODY_TRACKER; ++ strncpy(device->base.str, "SolarXR IPC Connection", sizeof(device->base.str) - 1); ++ device->base.tracking_origin = tracking_origin; ++ if (device->base.tracking_origin == NULL) { ++ device->base.tracking_origin = &device->standalone_origin; ++ device->standalone_origin = (struct xrt_tracking_origin){ ++ .name = "SolarXR Bridge", ++ .type = XRT_TRACKING_TYPE_OTHER, ++ .initial_offset = XRT_POSE_IDENTITY, ++ }; ++ } ++ device->base.body_tracking_supported = true; ++ device->base.update_inputs = solarxr_device_update_inputs; ++ device->base.get_body_skeleton = solarxr_device_get_body_skeleton; ++ device->base.get_body_joints = solarxr_device_get_body_joints; ++ device->base.destroy = solarxr_device_destroy; ++ device->base.inputs[0].name = XRT_INPUT_FB_BODY_TRACKING; ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ device->base.inputs[1].name = XRT_INPUT_META_FULL_BODY_TRACKING; ++#endif ++ device->thread.thread = pthread_self(); ++ const bool use_trackers = (out_xdevs_cap >= 2); ++ device->use_trackers = use_trackers; ++ ipc_socket_init(&device->socket, debug_get_log_option_solarxr_log()); ++ memset(device->tracker_ids, 0xff, sizeof(device->tracker_ids)); ++ ++ // `solarxr_device_destroy()` asserts unless both have attempted initialization ++ if (((int)!feeder_init(&device->feeder, debug_get_log_option_solarxr_log()) | os_mutex_init(&device->mutex)) != ++ 0) { ++ goto fail; ++ } ++ ++ if (!ipc_socket_connect(&device->socket, "SlimeVRRpc", "slimevr/SlimeVRRpc", device->base.serial, ++ sizeof(device->base.serial))) { ++ goto fail; ++ } ++ ++ struct request_packet ++ { ++ uint32_t _root; ++ uint16_t _table_bundle[4]; ++ struct ++ { // table MessageBundle ++ int32_t _table; ++ uint32_t data_feed_msgs; // vector* ++ uint32_t rpc_msgs; // vector* ++ } bundle; ++ struct ++ { // vector
++ uint32_t length; ++ uint32_t values[1]; // table* ++ } rpc_msgs; ++ uint16_t _table_rpc_msgs_0[5]; ++ struct ++ { // table RpcMessageHeader ++ int32_t _table; ++ uint32_t message; // table* ++ uint8_t message_type; // enum RpcMessage ++ uint8_t _pad[3]; ++ } rpc_msgs_0; ++ uint16_t _table_request[2]; ++ struct ++ { // table SettingsRequest ++ int32_t _table; ++ } request; ++ struct ++ { // vector
++ uint32_t length; ++ uint32_t values[1]; // table* ++ } data_feed_msgs; ++ uint16_t _table_data_feed_msgs_0[4]; ++ struct ++ { // table DataFeedMessageHeader ++ int32_t _table; ++ uint32_t message; // table* ++ uint8_t message_type; // enum DataFeedMessage ++ uint8_t _pad[3]; ++ } data_feed_msgs_0; ++ uint16_t _table_shared[3]; ++ struct ++ { // table PollDataFeed ++ int32_t _table; ++ uint32_t config; // table* ++ } message; ++ uint16_t _table_config[6]; ++ struct ++ { // table DataFeedConfig ++ int32_t _table; ++ uint32_t trackers_mask; // table* ++ bool bone_mask; ++ uint8_t _pad[3]; ++ } config; ++ struct ++ { // table DeviceDataMask ++ int32_t _table; ++ uint32_t tracker_data; // table* ++ } data_mask; ++ uint16_t _table_synthetic_trackers_mask[3]; ++ struct ++ { // table TrackerDataMask ++ int32_t _table; ++ bool info; ++ } synthetic_trackers_mask; ++ } const request_packet = { ++ ._root = htole32(offsetof(struct request_packet, bundle)), ++ ._table_bundle = ++ { ++ htole16(sizeof(request_packet._table_bundle)), ++ htole16(sizeof(request_packet.bundle)), ++ htole16(use_trackers * (offsetof(struct request_packet, bundle.data_feed_msgs) - ++ offsetof(struct request_packet, bundle))), ++ htole16(offsetof(struct request_packet, bundle.rpc_msgs) - offsetof(struct request_packet, bundle)), ++ }, ++ .bundle = ++ { ++ ._table = htole32(offsetof(struct request_packet, bundle) - ++ offsetof(struct request_packet, _table_bundle)), ++ .data_feed_msgs = htole32(use_trackers * (offsetof(struct request_packet, data_feed_msgs) - ++ offsetof(struct request_packet, bundle.data_feed_msgs))), ++ .rpc_msgs = htole32(offsetof(struct request_packet, rpc_msgs) - ++ offsetof(struct request_packet, bundle.rpc_msgs)), ++ }, ++ .rpc_msgs = ++ { ++ .length = htole32(ARRAY_SIZE(request_packet.rpc_msgs.values)), ++ .values = {htole32(offsetof(struct request_packet, rpc_msgs_0) - ++ offsetof(struct request_packet, rpc_msgs.values[0]))}, ++ }, ++ ._table_rpc_msgs_0 = ++ { ++ htole16(sizeof(request_packet._table_rpc_msgs_0)), ++ htole16(sizeof(request_packet.rpc_msgs_0) - sizeof(request_packet.rpc_msgs_0._pad)), ++ 0, ++ htole16(offsetof(struct request_packet, rpc_msgs_0.message_type) - ++ offsetof(struct request_packet, rpc_msgs_0)), ++ htole16(offsetof(struct request_packet, rpc_msgs_0.message) - ++ offsetof(struct request_packet, rpc_msgs_0)), ++ }, ++ .rpc_msgs_0 = ++ { ++ ._table = htole32(offsetof(struct request_packet, rpc_msgs_0) - ++ offsetof(struct request_packet, _table_rpc_msgs_0)), ++ .message = htole32(offsetof(struct request_packet, request) - ++ offsetof(struct request_packet, rpc_msgs_0.message)), ++ .message_type = SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_REQUEST, ++ }, ++ ._table_request = ++ { ++ htole16(sizeof(request_packet._table_request)), ++ htole16(sizeof(request_packet.request)), ++ }, ++ .request = ++ { ++ ._table = htole32(offsetof(struct request_packet, request) - ++ offsetof(struct request_packet, _table_request)), ++ }, ++ .data_feed_msgs = ++ { ++ .length = htole32(ARRAY_SIZE(request_packet.data_feed_msgs.values)), ++ .values = {htole32(offsetof(struct request_packet, data_feed_msgs_0) - ++ offsetof(struct request_packet, data_feed_msgs.values[0]))}, ++ }, ++ ._table_data_feed_msgs_0 = ++ { ++ htole16(sizeof(request_packet._table_data_feed_msgs_0)), ++ htole16(sizeof(request_packet.data_feed_msgs_0) - sizeof(request_packet.data_feed_msgs_0._pad)), ++ htole16(offsetof(struct request_packet, data_feed_msgs_0.message_type) - ++ offsetof(struct request_packet, data_feed_msgs_0)), ++ htole16(offsetof(struct request_packet, data_feed_msgs_0.message) - ++ offsetof(struct request_packet, data_feed_msgs_0)), ++ }, ++ .data_feed_msgs_0 = ++ { ++ ._table = htole32(offsetof(struct request_packet, data_feed_msgs_0) - ++ offsetof(struct request_packet, _table_data_feed_msgs_0)), ++ .message = htole32(offsetof(struct request_packet, message) - ++ offsetof(struct request_packet, data_feed_msgs_0.message)), ++ .message_type = SOLARXR_DATA_FEED_MESSAGE_POLL_DATA_FEED, ++ }, ++ ._table_shared = ++ { ++ htole16(sizeof(request_packet._table_shared)), ++ htole16(8), ++ htole16(4), ++ }, ++ .message = ++ { ++ ._table = htole32(offsetof(struct request_packet, message) - ++ offsetof(struct request_packet, _table_shared)), ++ .config = htole32(offsetof(struct request_packet, config) - ++ offsetof(struct request_packet, message.config)), ++ }, ++ ._table_config = ++ { ++ htole16(sizeof(request_packet._table_config)), ++ htole16(sizeof(request_packet.config) - sizeof(request_packet.config._pad)), ++ 0, ++ htole16((device->use_trackers && debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct request_packet, config.trackers_mask) - ++ offsetof(struct request_packet, config))), ++ htole16((device->use_trackers && !debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct request_packet, config.trackers_mask) - ++ offsetof(struct request_packet, config))), ++ htole16(offsetof(struct request_packet, config.bone_mask) - ++ offsetof(struct request_packet, config)), ++ }, ++ .config = ++ { ++ ._table = htole32(offsetof(struct request_packet, config) - ++ offsetof(struct request_packet, _table_config)), ++ .trackers_mask = htole32((debug_get_bool_option_solarxr_raw_trackers() ++ ? offsetof(struct request_packet, data_mask) ++ : offsetof(struct request_packet, synthetic_trackers_mask)) - ++ offsetof(struct request_packet, config.trackers_mask)), ++ .bone_mask = true, ++ }, ++ .data_mask = ++ { ++ ._table = htole32(offsetof(struct request_packet, data_mask) - ++ offsetof(struct request_packet, _table_shared)), ++ .tracker_data = htole32(offsetof(struct request_packet, synthetic_trackers_mask) - ++ offsetof(struct request_packet, data_mask.tracker_data)), ++ }, ++ ._table_synthetic_trackers_mask = ++ { ++ htole16(sizeof(request_packet._table_synthetic_trackers_mask)), ++ htole16(sizeof(request_packet.synthetic_trackers_mask)), ++ htole16(offsetof(struct request_packet, synthetic_trackers_mask.info) - ++ offsetof(struct request_packet, synthetic_trackers_mask)), ++ }, ++ .synthetic_trackers_mask = ++ { ++ ._table = htole32(offsetof(struct request_packet, synthetic_trackers_mask) - ++ offsetof(struct request_packet, _table_synthetic_trackers_mask)), ++ .info = true, ++ }, ++ }; ++ ++ if (!ipc_socket_send(&device->socket, (const uint8_t *)&request_packet, ++ use_trackers ? sizeof(request_packet) : offsetof(struct request_packet, data_feed_msgs))) { ++ U_LOG_IFL_E(device->socket.log_level, "ipc_socket_send() failed"); ++ goto fail; ++ } ++ ++ if (use_trackers) { ++ const struct span buffer = ipc_socket_receive_blocking(&device->socket); ++ if (buffer.length == 0) { ++ U_LOG_IFL_E(device->socket.log_level, "ipc_socket_receive() failed"); ++ goto fail; ++ } ++ struct solarxr_message_bundle bundle; ++ if (!read_solarxr_message_bundle(&bundle, buffer.data, buffer.length, ++ (const solarxr_message_bundle_t *)buffer.data)) { ++ U_LOG_IFL_E(device->socket.log_level, "read_solarxr_message_bundle() failed"); ++ goto fail; ++ } ++ if (bundle.data_feed_msgs.length != 1) { ++ U_LOG_IFL_E(device->socket.log_level, "Unexpected data feed count"); ++ goto fail; ++ } ++ struct solarxr_data_feed_message_header header; ++ if (!read_solarxr_data_feed_message_header(&header, buffer.data, buffer.length, ++ &bundle.data_feed_msgs.data[0])) { ++ U_LOG_IFL_E(device->socket.log_level, "read_solarxr_data_feed_message_header() failed"); ++ goto fail; ++ } ++ if (header.message_type != SOLARXR_DATA_FEED_MESSAGE_DATA_FEED_UPDATE) { ++ U_LOG_IFL_E(device->socket.log_level, "Unexpected data feed message type"); ++ goto fail; ++ } ++ uint32_t tracker_descs_len = 0; ++ const solarxr_tracker_data_t *tracker_descs[ARRAY_SIZE(device->trackers)]; ++ if (debug_get_bool_option_solarxr_raw_trackers()) { ++ for (uint32_t i = 0; i < header.message.data_feed_update.devices.length; ++i) { ++ struct solarxr_device_data device_data; ++ if (!read_solarxr_device_data(&device_data, buffer.data, buffer.length, ++ &header.message.data_feed_update.devices.data[i])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_device_data() failed"); ++ continue; ++ } ++ uint32_t length = device_data.trackers.length; ++ if (length >= ARRAY_SIZE(tracker_descs) - tracker_descs_len) { ++ length = ARRAY_SIZE(tracker_descs) - tracker_descs_len; ++ header.message.data_feed_update.devices.length = i; // early exit ++ } ++ for (uint32_t j = 0; j < length; ++j) { ++ tracker_descs[tracker_descs_len++] = &device_data.trackers.data[j]; ++ } ++ } ++ } else { ++ tracker_descs_len = ++ MIN(header.message.data_feed_update.synthetic_trackers.length, ARRAY_SIZE(tracker_descs)); ++ for (uint32_t i = 0; i < tracker_descs_len; ++i) { ++ tracker_descs[i] = &header.message.data_feed_update.synthetic_trackers.data[i]; ++ } ++ } ++ if (tracker_descs_len > out_xdevs_cap - 1) { ++ tracker_descs_len = out_xdevs_cap - 1; ++ } ++ for (uint32_t i = 0; i < tracker_descs_len; ++i) { ++ struct solarxr_tracker_data data; ++ if (!read_solarxr_tracker_data(&data, buffer.data, buffer.length, tracker_descs[i])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_device_data() failed"); ++ continue; ++ } ++ const wchar_t id = solarxr_tracker_id_to_wchar(data.tracker_id); ++ ++ struct solarxr_generic_tracker *const tracker = ++ U_DEVICE_ALLOCATE(struct solarxr_generic_tracker, U_DEVICE_ALLOC_NO_FLAGS, 1, 0); ++ tracker->base.name = XRT_DEVICE_VIVE_TRACKER; // TODO: use different name here? ++ tracker->base.device_type = XRT_DEVICE_TYPE_GENERIC_TRACKER; ++ snprintf(tracker->base.str, sizeof(tracker->base.str), "SolarXR Tracker %06x", id); ++ snprintf(tracker->base.serial, sizeof(tracker->base.serial), "SOLARXR-%06x", id); ++ tracker->base.tracking_origin = device->base.tracking_origin; ++ tracker->base.orientation_tracking_supported = true; ++ tracker->base.position_tracking_supported = true; ++ tracker->base.update_inputs = solarxr_generic_tracker_update_inputs; ++ tracker->base.get_tracked_pose = solarxr_generic_tracker_get_tracked_pose; ++ tracker->base.destroy = solarxr_generic_tracker_destroy; ++ tracker->base.inputs[0].name = XRT_INPUT_GENERIC_TRACKER_POSE; ++ m_relation_history_create(&tracker->history); ++ tracker->role = SOLARXR_BODY_PART_NONE; ++ tracker->parent = device; ++ tracker->weak_ref = &device->trackers[i]; ++ device->trackers[i] = tracker; ++ device->tracker_ids[i] = id; ++ ++ if (!data.has_info) { ++ continue; ++ } ++ if (data.info.body_part < ARRAY_SIZE(device->bones)) { ++ tracker->role = data.info.body_part; ++ } ++ if (data.info.display_name.length != 0) { ++ snprintf(tracker->base.str, sizeof(tracker->base.str), "SolarXR Tracker \"%.*s\"", ++ (unsigned)data.info.display_name.length, data.info.display_name.data); ++ } ++ } ++ } ++ if (os_thread_start(&device->thread, solarxr_network_thread, device) != 0) { ++ U_LOG_IFL_E(device->socket.log_level, "pthread_create() failed"); ++ for (uint32_t i = 0; i < ARRAY_SIZE(device->trackers); ++i) { ++ if (device->trackers[i] != NULL) { ++ solarxr_generic_tracker_destroy(&device->trackers[i]->base); ++ device->trackers[i] = NULL; ++ } ++ } ++ goto fail; ++ } ++ // early sync to initialize bone lengths needed by `solarxr_device_get_body_skeleton()` ++ solarxr_device_sync(device); ++ ++ uint32_t trackerCount = 0; ++ out_xdevs[trackerCount++] = &device->base; ++ for (uint32_t i = 0; i < ARRAY_SIZE(device->trackers); ++i) { ++ if (device->trackers[i] == NULL) { ++ continue; ++ } ++ assert(trackerCount < out_xdevs_cap); ++ out_xdevs[trackerCount++] = &device->trackers[i]->base; ++ } ++ return trackerCount; ++fail: ++ solarxr_device_destroy(&device->base); ++ return 0; ++} ++ ++static bool ++filter_feeder_device(struct xrt_device *const device) ++{ ++ return solarxr_generic_tracker(device) == NULL; ++} ++ ++bool ++solarxr_device_set_feeder_devices(struct xrt_device *const device, ++ struct xrt_device *const xdevs[const], ++ const uint32_t xdevs_len) ++{ ++ struct solarxr_device *const solarxr = solarxr_device(device); ++ return (solarxr != NULL) ? feeder_set_devices(&solarxr->feeder, xdevs, xdevs_len, filter_feeder_device) : false; ++} +diff --git a/src/xrt/drivers/solarxr/solarxr_interface.h b/src/xrt/drivers/solarxr/solarxr_interface.h +new file mode 100644 +index 0000000000..e5f029992f +--- /dev/null ++++ b/src/xrt/drivers/solarxr/solarxr_interface.h +@@ -0,0 +1,40 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++/*! ++ * @file ++ * @brief SolarXR protocol bridge device ++ * @ingroup drv_solarxr ++ */ ++ ++#pragma once ++ ++#include ++#include ++#include ++struct xrt_device; ++struct xrt_tracking_origin; ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++uint32_t ++solarxr_device_create_xdevs(struct xrt_tracking_origin *tracking_origin, ++ struct xrt_device *out_xdevs[], ++ uint32_t out_xdevs_cap); ++ ++static inline struct xrt_device * ++solarxr_device_create(struct xrt_tracking_origin *const tracking_origin) ++{ ++ struct xrt_device *out = NULL; ++ solarxr_device_create_xdevs(tracking_origin, &out, 1); ++ return out; ++} ++ ++bool ++solarxr_device_set_feeder_devices(struct xrt_device *solarxr, struct xrt_device *const xdevs[], uint32_t xdevs_len); ++ ++ ++#ifdef __cplusplus ++} ++#endif +diff --git a/src/xrt/targets/common/CMakeLists.txt b/src/xrt/targets/common/CMakeLists.txt +index e2b9ba79d1..1fbf5f436f 100644 +--- a/src/xrt/targets/common/CMakeLists.txt ++++ b/src/xrt/targets/common/CMakeLists.txt +@@ -201,6 +201,10 @@ if(XRT_BUILD_DRIVER_SIMULAVR) + target_link_libraries(target_lists PRIVATE drv_svr) + endif() + ++if(XRT_BUILD_DRIVER_SOLARXR) ++ target_link_libraries(target_lists PRIVATE drv_solarxr) ++endif() ++ + #### + # Instance + # +-- +GitLab + diff --git a/patches/monado/0099-t-common-Load-SolarXR-driver.patch b/patches/monado/0099-t-common-Load-SolarXR-driver.patch new file mode 100644 index 00000000..c85a04ff --- /dev/null +++ b/patches/monado/0099-t-common-Load-SolarXR-driver.patch @@ -0,0 +1,292 @@ +From 7114d99942608a2f02d45d64d8eac3e1c2ea739c Mon Sep 17 00:00:00 2001 +From: rcelyte +Date: Fri, 23 Aug 2024 20:54:53 +0000 +Subject: [PATCH] t/common: Load SolarXR driver + +--- + src/xrt/drivers/qwerty/qwerty_device.c | 4 +++ + .../common/target_builder_lighthouse.c | 25 +++++++++++++++++ + .../targets/common/target_builder_qwerty.c | 25 +++++++++++++++++ + .../targets/common/target_builder_rift_s.c | 26 ++++++++++++++++++ + .../targets/common/target_builder_steamvr.c | 27 +++++++++++++++++++ + src/xrt/targets/common/target_builder_wmr.c | 25 +++++++++++++++++ + 6 files changed, 132 insertions(+) + +diff --git a/src/xrt/drivers/qwerty/qwerty_device.c b/src/xrt/drivers/qwerty/qwerty_device.c +index 8841413efd..127644bc8b 100644 +--- a/src/xrt/drivers/qwerty/qwerty_device.c ++++ b/src/xrt/drivers/qwerty/qwerty_device.c +@@ -315,6 +315,8 @@ qwerty_hmd_create(void) + + xd->inputs[0].name = XRT_INPUT_GENERIC_HEAD_POSE; + ++ xd->orientation_tracking_supported = true; ++ xd->position_tracking_supported = true; + xd->update_inputs = u_device_noop_update_inputs; + xd->get_tracked_pose = qwerty_get_tracked_pose; + xd->get_view_poses = u_device_get_view_poses; +@@ -367,6 +369,8 @@ qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd) + xd->binding_profiles = binding_profiles; + xd->binding_profile_count = ARRAY_SIZE(binding_profiles); + ++ xd->orientation_tracking_supported = true; ++ xd->position_tracking_supported = true; + xd->update_inputs = qwerty_update_inputs; + xd->get_tracked_pose = qwerty_get_tracked_pose; + xd->set_output = qwerty_set_output; +diff --git a/src/xrt/targets/common/target_builder_lighthouse.c b/src/xrt/targets/common/target_builder_lighthouse.c +index 2386586be3..b8cbafdbed 100644 +--- a/src/xrt/targets/common/target_builder_lighthouse.c ++++ b/src/xrt/targets/common/target_builder_lighthouse.c +@@ -58,6 +58,10 @@ + #include "opengloves/opengloves_interface.h" + #endif + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++#include "solarxr/solarxr_interface.h" ++#endif ++ + #if defined(XRT_BUILD_DRIVER_SURVIVE) + #define DEFAULT_DRIVER "survive" + #else +@@ -509,6 +513,16 @@ try_add_opengloves(struct xrt_device *left, + #endif + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++static void ++destroy_system_devices_solarxr(struct xrt_system_devices *xsysd) ++{ ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, NULL, 0); ++ u_system_devices_close(xsysd); ++ free(xsysd); ++} ++#endif ++ + static xrt_result_t + lighthouse_open_system_impl(struct xrt_builder *xb, + cJSON *config, +@@ -736,6 +750,17 @@ end_valve_index: + try_add_opengloves(left, right, &left_ht, &right_ht); + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++ const uint32_t count = solarxr_device_create_xdevs(head->tracking_origin, &xsysd->xdevs[xsysd->xdev_count], ++ ARRAY_SIZE(xsysd->xdevs) - xsysd->xdev_count); ++ if (count != 0) { ++ xsysd->static_roles.body = xsysd->xdevs[xsysd->xdev_count]; ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, xsysd->xdevs, xsysd->xdev_count); ++ xsysd->destroy = destroy_system_devices_solarxr; ++ } ++ xsysd->xdev_count += count; ++#endif ++ + // Assign to role(s). + ubrh->head = head; + ubrh->left = left; +diff --git a/src/xrt/targets/common/target_builder_qwerty.c b/src/xrt/targets/common/target_builder_qwerty.c +index 2c66ad3038..5a5059ee18 100644 +--- a/src/xrt/targets/common/target_builder_qwerty.c ++++ b/src/xrt/targets/common/target_builder_qwerty.c +@@ -18,6 +18,10 @@ + + #include "qwerty/qwerty_interface.h" + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++#include "solarxr/solarxr_interface.h" ++#endif ++ + #include + + +@@ -67,6 +71,16 @@ qwerty_estimate_system(struct xrt_builder *xb, + return XRT_SUCCESS; + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++static void ++destroy_system_devices_solarxr(struct xrt_system_devices *xsysd) ++{ ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, NULL, 0); ++ u_system_devices_close(xsysd); ++ free(xsysd); ++} ++#endif ++ + static xrt_result_t + qwerty_open_system_impl(struct xrt_builder *xb, + cJSON *config, +@@ -100,6 +114,17 @@ qwerty_open_system_impl(struct xrt_builder *xb, + ubrh->left = left; + ubrh->right = right; + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++ const uint32_t count = solarxr_device_create_xdevs(head->tracking_origin, &xsysd->xdevs[xsysd->xdev_count], ++ ARRAY_SIZE(xsysd->xdevs) - xsysd->xdev_count); ++ if (count != 0) { ++ xsysd->static_roles.body = xsysd->xdevs[xsysd->xdev_count]; ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, xsysd->xdevs, xsysd->xdev_count); ++ xsysd->destroy = destroy_system_devices_solarxr; ++ } ++ xsysd->xdev_count += count; ++#endif ++ + return XRT_SUCCESS; + } + +diff --git a/src/xrt/targets/common/target_builder_rift_s.c b/src/xrt/targets/common/target_builder_rift_s.c +index 675b303228..bf5581688d 100644 +--- a/src/xrt/targets/common/target_builder_rift_s.c ++++ b/src/xrt/targets/common/target_builder_rift_s.c +@@ -28,6 +28,10 @@ + #include "ht_ctrl_emu/ht_ctrl_emu_interface.h" + #endif + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++#include "solarxr/solarxr_interface.h" ++#endif ++ + #include "rift_s/rift_s_interface.h" + #include "rift_s/rift_s.h" + +@@ -92,6 +96,16 @@ rift_s_estimate_system(struct xrt_builder *xb, + return XRT_SUCCESS; + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++static void ++destroy_system_devices_solarxr(struct xrt_system_devices *xsysd) ++{ ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, NULL, 0); ++ u_system_devices_close(xsysd); ++ free(xsysd); ++} ++#endif ++ + static xrt_result_t + rift_s_open_system_impl(struct xrt_builder *xb, + cJSON *config, +@@ -200,6 +214,18 @@ rift_s_open_system_impl(struct xrt_builder *xb, + } + #endif + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++ const uint32_t count = ++ solarxr_device_create_xdevs((hmd_xdev != NULL) ? hmd_xdev->tracking_origin : NULL, ++ &xsysd->xdevs[xsysd->xdev_count], ARRAY_SIZE(xsysd->xdevs) - xsysd->xdev_count); ++ if (count != 0) { ++ xsysd->static_roles.body = xsysd->xdevs[xsysd->xdev_count]; ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, xsysd->xdevs, xsysd->xdev_count); ++ xsysd->destroy = destroy_system_devices_solarxr; ++ } ++ xsysd->xdev_count += count; ++#endif ++ + // Assign to role(s). + ubrh->head = hmd_xdev; + ubrh->left = left_xdev; +diff --git a/src/xrt/targets/common/target_builder_steamvr.c b/src/xrt/targets/common/target_builder_steamvr.c +index 7b70e6b7c7..0267bb900d 100644 +--- a/src/xrt/targets/common/target_builder_steamvr.c ++++ b/src/xrt/targets/common/target_builder_steamvr.c +@@ -34,6 +34,10 @@ + #include "xrt/xrt_space.h" + #include "util/u_space_overseer.h" + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++#include "solarxr/solarxr_interface.h" ++#endif ++ + #ifndef XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE + #error "This builder requires the SteamVR Lighthouse driver" + #endif +@@ -115,6 +119,17 @@ steamvr_destroy(struct xrt_builder *xb) + free(svrb); + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++static void ++destroy_system_devices_solarxr(struct xrt_system_devices *xsysd) ++{ ++ void _Z7destroyP18xrt_system_devices(struct xrt_system_devices * xsysd); ++ ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, NULL, 0); ++ _Z7destroyP18xrt_system_devices(xsysd); ++} ++#endif ++ + static xrt_result_t + steamvr_open_system(struct xrt_builder *xb, + cJSON *config, +@@ -151,6 +166,18 @@ steamvr_open_system(struct xrt_builder *xb, + svrb->right_ht = u_system_devices_get_ht_device_right(xsysd); + xsysd->static_roles.hand_tracking.right = svrb->right_ht; + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++ const uint32_t count = ++ solarxr_device_create_xdevs(xsysd->static_roles.head->tracking_origin, &xsysd->xdevs[xsysd->xdev_count], ++ ARRAY_SIZE(xsysd->xdevs) - xsysd->xdev_count); ++ if (count != 0) { ++ xsysd->static_roles.body = xsysd->xdevs[xsysd->xdev_count]; ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, xsysd->xdevs, xsysd->xdev_count); ++ xsysd->destroy = destroy_system_devices_solarxr; ++ } ++ xsysd->xdev_count += count; ++#endif ++ + /* + * Space overseer. + */ +diff --git a/src/xrt/targets/common/target_builder_wmr.c b/src/xrt/targets/common/target_builder_wmr.c +index 40df6b6535..d543c441c2 100644 +--- a/src/xrt/targets/common/target_builder_wmr.c ++++ b/src/xrt/targets/common/target_builder_wmr.c +@@ -26,6 +26,10 @@ + + #include + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++#include "solarxr/solarxr_interface.h" ++#endif ++ + #ifndef XRT_BUILD_DRIVER_WMR + #error "Must only be built with XRT_BUILD_DRIVER_WMR set" + #endif +@@ -175,6 +179,16 @@ wmr_estimate_system(struct xrt_builder *xb, + return XRT_SUCCESS; + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++static void ++destroy_system_devices_solarxr(struct xrt_system_devices *xsysd) ++{ ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, NULL, 0); ++ u_system_devices_close(xsysd); ++ free(xsysd); ++} ++#endif ++ + static xrt_result_t + wmr_open_system_impl(struct xrt_builder *xb, + cJSON *config, +@@ -295,6 +309,17 @@ wmr_open_system_impl(struct xrt_builder *xb, + right = ht_right; + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++ const uint32_t count = solarxr_device_create_xdevs(head->tracking_origin, &xsysd->xdevs[xsysd->xdev_count], ++ ARRAY_SIZE(xsysd->xdevs) - xsysd->xdev_count); ++ if (count != 0) { ++ xsysd->static_roles.body = xsysd->xdevs[xsysd->xdev_count]; ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, xsysd->xdevs, xsysd->xdev_count); ++ xsysd->destroy = destroy_system_devices_solarxr; ++ } ++ xsysd->xdev_count += count; ++#endif ++ + + // Assign to role(s). + ubrh->head = head; +-- +GitLab + From 4125cad44e87d4f91b2a91b20b751f8cf99ab8ce Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Fri, 16 May 2025 18:39:23 -0400 Subject: [PATCH 04/42] Add a last improvement --- client/scenes/lobby_gui.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 94c14797..2ef25c7c 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -1037,6 +1037,9 @@ void scenes::lobby::gui_about() ImGui::SetCursorPosX(win_width / 4); ImGui::Image(about_picture, {win_width / 2, win_width / 2}); + ImGui::PushFont(imgui_ctx->large_font); + CenterTextH(std::string("Sneed'n'Chuck Edition")); + ImGui::PopFont(); } void scenes::lobby::gui_licenses() From adcf1599162dd43833e7c553930ec5ea0036bae3 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Mon, 26 May 2025 18:36:33 -0400 Subject: [PATCH 05/42] Update ray.png --- assets/ray.png | Bin 581 -> 306 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/assets/ray.png b/assets/ray.png index 7af5eee24d6fdd11ca43c13031c0101613cd2c0b..f72666e3428111a6b1e20473702c910937757d06 100644 GIT binary patch delta 264 zcmX@gvWaPeWHK8A1B0=}j0PaZSRCZ;#CY?hPCbyrlJ4m1$iT3%pZiZDE0C{{>=ES4 zz)+>ez|hdb!0-zw)bN6Vq11qZ;Z*_ygVhWM2JwP9y8>;15^PD{?k+(3Kg0j5n+fuh zH!#Z8zhspXQuTmAh}iVQy`-9OGhz-@F!`@!GP2bn-8FnGH9 KxvXuQ78Gix*006vN57z(y0fT8nLr_UWLm+T+Z)Rz1WdHyuk$sUpNW(xJ z#a~mUrBoa&BE=y?b+U_!IMyl@p+cw?T6HkF^b4A_Bq=VAf@{ISkHxBki?gl{u7V)= z0pjf7r060g{x2!Ci1FaKAMfrx?%n}HtI9O9F9B$}Wn@xGF@Kj|6$7sbA&OxH0hyWg zIY~;xb9~*y$Je_!&+0X49&3-Y1T*vaAxH6Hgd)LE=ZQ zD=xorE;%gl%!rZA%o9h5#ZnI|JEVw$eu-QPxhi1fSU?RLWXBKw2fw>Di&K+s zQaB0pzu5N27!cS6+D+U3KDO=l3E+PQuJo?I)&gcfNpE(w*by+e4P0DzHDwRD+yO?O z>arm_lAoqfECTOm^i6qS=oSdAxxIDvaryvcsjKu2a2jw3jF%{T-Q(TC-roK_)9LRA zLpgGjhwtrvk$fI^=n5JZ77n0X+Xnyu02y>eSad^gZEa<4bO1wgWnpw>WFU8GbZ8() zNlj2!fese{001yaL_t&-(_=WHb&rXGfq`l`Nu7b3<}qm9^P#GFx9(|C)xRu9sp?;* emotT^X&wM`)Ckv23!(Y|0000 Date: Thu, 15 May 2025 10:36:24 -0400 Subject: [PATCH 06/42] Create pull.yml --- .github/pull.yml | 6 ++++++ .github/workflows/APK-Release.yml | 4 ++++ .github/workflows/Sync.yml | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 .github/pull.yml create mode 100644 .github/workflows/Sync.yml diff --git a/.github/pull.yml b/.github/pull.yml new file mode 100644 index 00000000..397643b9 --- /dev/null +++ b/.github/pull.yml @@ -0,0 +1,6 @@ +version: "1" +rules: + - base: master + upstream: WiVRn:master + mergeMethod: hardreset + \ No newline at end of file diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 545d9330..d209e99b 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -26,6 +26,10 @@ jobs: ref: ${{ github.sha }} fetch-depth: 0 + - name: merge alternate fork with master + run: | + git merge --no-commit origin/sneed + - name: set up JDK uses: actions/setup-java@v4 with: diff --git a/.github/workflows/Sync.yml b/.github/workflows/Sync.yml new file mode 100644 index 00000000..5c118f00 --- /dev/null +++ b/.github/workflows/Sync.yml @@ -0,0 +1,22 @@ +name: Sync Upstream + +env: + UPSTREAM_URL: "https://github.com/wivrn/wivrn.git" + WORKFLOW_TOKEN: ${{ secrets.WORKFLOW_TOKEN }} + UPSTREAM_BRANCH: "master" + +on: + schedule: + - cron: '0 5/6 * * *' + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: GitHub Sync to Upstream Repository + uses: dabreadman/sync-upstream-repo@v1.3.0 + with: + upstream_repo: ${{ env.UPSTREAM_URL }} + upstream_branch: ${{ env.UPSTREAM_BRANCH }} + token: ${{ env.WORKFLOW_TOKEN }} \ No newline at end of file From aa1f3b39bdbb02c0e7dc79bd94e2af87b5700119 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 22:33:03 -0400 Subject: [PATCH 07/42] Create pull.yml --- .github/workflows/APK-Release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index d209e99b..f67b1f56 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -28,6 +28,7 @@ jobs: - name: merge alternate fork with master run: | + cd WiVRn/WiVRn git merge --no-commit origin/sneed - name: set up JDK From f94e46ed2451c2f4906951f18ff4ebdc673abb16 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 22:34:17 -0400 Subject: [PATCH 08/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index f67b1f56..1e6b6574 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -28,7 +28,7 @@ jobs: - name: merge alternate fork with master run: | - cd WiVRn/WiVRn + cd ~/work/WiVRn/WiVRn git merge --no-commit origin/sneed - name: set up JDK From 8377d617cf64bc372721f912aa7fcca7cb324e37 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 22:36:55 -0400 Subject: [PATCH 09/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 1e6b6574..9aeb20cf 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -28,8 +28,7 @@ jobs: - name: merge alternate fork with master run: | - cd ~/work/WiVRn/WiVRn - git merge --no-commit origin/sneed + git fetch origin/sneed - name: set up JDK uses: actions/setup-java@v4 From b1db34022728e95da071148be418e7067491b965 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 22:39:15 -0400 Subject: [PATCH 10/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 9aeb20cf..d0284593 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -28,7 +28,7 @@ jobs: - name: merge alternate fork with master run: | - git fetch origin/sneed + git fetch origin sneed - name: set up JDK uses: actions/setup-java@v4 From bc5d80a13aac043278b95c745b171201b8152d53 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 22:40:09 -0400 Subject: [PATCH 11/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index d0284593..44a8a996 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -28,6 +28,7 @@ jobs: - name: merge alternate fork with master run: | + cd ~/work/WiVRn/WiVRn git fetch origin sneed - name: set up JDK From 651c9d5a0f4379e37027abbd510d0887e462209a Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 22:50:38 -0400 Subject: [PATCH 12/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 44a8a996..6f520857 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -26,10 +26,11 @@ jobs: ref: ${{ github.sha }} fetch-depth: 0 - - name: merge alternate fork with master - run: | - cd ~/work/WiVRn/WiVRn - git fetch origin sneed + - uses: actions/checkout@v4 + with: + repository: 'Vindicus999/WiVRn' + ref: 'sneed' + fetch-depth: 1 - name: set up JDK uses: actions/setup-java@v4 From 4740848ca58ba06bcd04b3bc8969b604a5e804a1 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 23:12:00 -0400 Subject: [PATCH 13/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 6f520857..963ee96d 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -29,8 +29,12 @@ jobs: - uses: actions/checkout@v4 with: repository: 'Vindicus999/WiVRn' - ref: 'sneed' - fetch-depth: 1 + ref: sneed + path: sneed + + - name: where is everything stored + run: | + ls - name: set up JDK uses: actions/setup-java@v4 From 59a241de636e5293f1c8f385fd4c9945b11ae216 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 23:14:37 -0400 Subject: [PATCH 14/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 963ee96d..d386aec7 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -30,11 +30,6 @@ jobs: with: repository: 'Vindicus999/WiVRn' ref: sneed - path: sneed - - - name: where is everything stored - run: | - ls - name: set up JDK uses: actions/setup-java@v4 From a7a56d0873d8cc061d4d624f75d8725c30a76e50 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 23:35:47 -0400 Subject: [PATCH 15/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index d386aec7..4753385c 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -106,6 +106,7 @@ jobs: path: apk pattern: 'apk-*' merge-multiple: true + run: ls -R - name: Rename APK artifacts run: | From 6e8e78b912e1d385da2a186397151b70619bd01a Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Fri, 16 May 2025 00:05:26 -0400 Subject: [PATCH 16/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 4753385c..ad3a1891 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -106,7 +106,6 @@ jobs: path: apk pattern: 'apk-*' merge-multiple: true - run: ls -R - name: Rename APK artifacts run: | @@ -139,4 +138,6 @@ jobs: fail_on_unmatched_files: true files: | apk/*.apk + apk/*.zip + apk/* debug-symbols.zip From 52646de23e5eb1a9c2e56e1b98647eb8eb406224 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Fri, 16 May 2025 07:23:38 -0400 Subject: [PATCH 17/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index ad3a1891..73c8c292 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -73,7 +73,9 @@ jobs: - name: Prepare before archiving artifacts run: | mkdir apk + ls build/outputs/apk/ mv $(find build/outputs/apk/ -name "*.apk") apk/ + ls apk/ mkdir debug mv build/intermediates/merged_native_libs/*/*/out/lib/* debug/ find debug -name libopenxr_loader.so -delete @@ -110,6 +112,7 @@ jobs: - name: Rename APK artifacts run: | cd apk + ls for f in *.apk; do BASENAME=`echo ${f}|awk -F '-APK-' '{print $2}'` mv "${f}" "org.meumeu.wivrn-${BASENAME}" From 63aa862a67475436adc8bf6a81a44359d0ec65ee Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Fri, 16 May 2025 18:08:42 -0400 Subject: [PATCH 18/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 73c8c292..6ed50f66 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -117,6 +117,7 @@ jobs: BASENAME=`echo ${f}|awk -F '-APK-' '{print $2}'` mv "${f}" "org.meumeu.wivrn-${BASENAME}" done + ls - name: Download APK debug artifacts uses: actions/download-artifact@v4 @@ -130,6 +131,11 @@ jobs: cd symbols zip -r ../debug-symbols.zip . + - name: How the hell doesnt it work + run: | + ls apk + ls + - name: APK Release uses: softprops/action-gh-release@v2 with: From b997ff3a179ada0ceffdec4d4e36b576fb5f7217 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Fri, 16 May 2025 18:09:10 -0400 Subject: [PATCH 19/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 6ed50f66..219fcca8 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -146,7 +146,5 @@ jobs: prerelease: false fail_on_unmatched_files: true files: | - apk/*.apk - apk/*.zip apk/* debug-symbols.zip From b9ff08d8931b787f75424d88a879514c0cd1ec04 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Fri, 16 May 2025 18:11:13 -0400 Subject: [PATCH 20/42] Update Sync.yml --- .github/workflows/Sync.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Sync.yml b/.github/workflows/Sync.yml index 5c118f00..0952cb02 100644 --- a/.github/workflows/Sync.yml +++ b/.github/workflows/Sync.yml @@ -2,7 +2,7 @@ name: Sync Upstream env: UPSTREAM_URL: "https://github.com/wivrn/wivrn.git" - WORKFLOW_TOKEN: ${{ secrets.WORKFLOW_TOKEN }} + WORKFLOW_TOKEN: ${{ secrets.DOWNSTREAM_GITHUB_TOKEN }} UPSTREAM_BRANCH: "master" on: @@ -19,4 +19,4 @@ jobs: with: upstream_repo: ${{ env.UPSTREAM_URL }} upstream_branch: ${{ env.UPSTREAM_BRANCH }} - token: ${{ env.WORKFLOW_TOKEN }} \ No newline at end of file + token: ${{ env.WORKFLOW_TOKEN }} From 42755dbb7c09e4dcf1645a3b87889a047bf5e1a4 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Fri, 16 May 2025 18:36:57 -0400 Subject: [PATCH 21/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 219fcca8..7eac941f 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -109,15 +109,15 @@ jobs: pattern: 'apk-*' merge-multiple: true - - name: Rename APK artifacts - run: | - cd apk - ls - for f in *.apk; do - BASENAME=`echo ${f}|awk -F '-APK-' '{print $2}'` - mv "${f}" "org.meumeu.wivrn-${BASENAME}" - done - ls + # - name: Rename APK artifacts + # run: | + # cd apk + # ls + # for f in *.apk; do + # BASENAME=`echo ${f}|awk -F '-APK-' '{print $2}'` + # mv "${f}" "org.meumeu.wivrn-${BASENAME}" + # done + # ls - name: Download APK debug artifacts uses: actions/download-artifact@v4 @@ -146,5 +146,5 @@ jobs: prerelease: false fail_on_unmatched_files: true files: | - apk/* + apk/*.apk debug-symbols.zip From b0d9bd2ab7222bf23b73759f4c4efb40edc4c373 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Mon, 26 May 2025 17:30:45 -0400 Subject: [PATCH 22/42] Update Sync.yml --- .github/workflows/Sync.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Sync.yml b/.github/workflows/Sync.yml index 0952cb02..d042278c 100644 --- a/.github/workflows/Sync.yml +++ b/.github/workflows/Sync.yml @@ -16,7 +16,18 @@ jobs: steps: - name: GitHub Sync to Upstream Repository uses: dabreadman/sync-upstream-repo@v1.3.0 - with: + with: upstream_repo: ${{ env.UPSTREAM_URL }} upstream_branch: ${{ env.UPSTREAM_BRANCH }} token: ${{ env.WORKFLOW_TOKEN }} + + - uses: actions/checkout@master + + - name: Merge sneed -> master + uses: devmasx/merge-branch@master + with: + type: now + from_branch: sneed + target_branch: master + github_token: ${{ env.WORKFLOW_TOKEN }} + From 7e0ea37b3c28eb218ff2331c7d9bb38f6d9ec89c Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Mon, 26 May 2025 17:31:36 -0400 Subject: [PATCH 23/42] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 7eac941f..4eec207d 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -22,14 +22,14 @@ jobs: - uses: actions/checkout@v4 with: # Checkout from upstream instead of WiVRn-APK to ensure the GIT_DESC variable is set correctly - repository: 'WiVRn/WiVRn' + repository: 'Vindicus999/WiVRn' ref: ${{ github.sha }} fetch-depth: 0 - - - uses: actions/checkout@v4 - with: - repository: 'Vindicus999/WiVRn' - ref: sneed + # + # - uses: actions/checkout@v4 + # with: + # repository: 'Vindicus999/WiVRn' + # ref: sneed - name: set up JDK uses: actions/setup-java@v4 From fa3313e293351bcc4fe342833f4a0d618211cd38 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Mon, 26 May 2025 17:43:59 -0400 Subject: [PATCH 24/42] Update Sync.yml --- .github/workflows/Sync.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/Sync.yml b/.github/workflows/Sync.yml index d042278c..240c2d11 100644 --- a/.github/workflows/Sync.yml +++ b/.github/workflows/Sync.yml @@ -21,13 +21,14 @@ jobs: upstream_branch: ${{ env.UPSTREAM_BRANCH }} token: ${{ env.WORKFLOW_TOKEN }} - - uses: actions/checkout@master + - name: Checkout stuff + uses: actions/checkout@master - - name: Merge sneed -> master - uses: devmasx/merge-branch@master - with: - type: now - from_branch: sneed - target_branch: master - github_token: ${{ env.WORKFLOW_TOKEN }} + - name: Merge sneed -> master + uses: devmasx/merge-branch@master + with: + type: now + from_branch: sneed + target_branch: master + github_token: ${{ env.WORKFLOW_TOKEN }} From be2027ce9a99af1048e91e4312ef739e99749394 Mon Sep 17 00:00:00 2001 From: Tool Man <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 09:58:06 -0400 Subject: [PATCH 25/42] Adding solarxr patches Remove potential statistics --- CMakeLists.txt | 2 +- client/CMakeLists.txt | 16 +- client/scenes/lobby.cpp | 13 +- images/wivrn-pride.svg | 622 -------------------------------- server/CMakeLists.txt | 1 + server/driver/wivrn_hmd.h | 16 +- server/driver/wivrn_session.cpp | 18 +- 7 files changed, 36 insertions(+), 652 deletions(-) delete mode 100644 images/wivrn-pride.svg diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e136267..cad020f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ set(OVR_COMPAT_SEARCH_PATH "/usr/local/lib/OpenComposite:/usr/lib/OpenComposite: option(WIVRN_FEATURE_DEBUG_GUI "Enable Monado debug GUI" OFF) option(WIVRN_FEATURE_RENDERDOC "Support renderdoc" OFF) -set(WIVRN_FEATURE_SOLARXR OFF) # Will be added back when merged in upstream Monado +option(WIVRN_FEATURE_SOLARXR "Enable SolarXR driver" OFF) option(WIVRN_FEATURE_STEAMVR_LIGHTHOUSE "Enable SteamVR Lighthouse driver" OFF) option(WIVRN_CHECK_CAPSYSNICE "Check if CAP_SYS_NICE is available at startup" ON) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 88acbec3..b317481c 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -229,14 +229,8 @@ add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.png COMMAND ${RSVG_CONVERT} ${IMG_SRC_DIR}/wivrn.svg -w 540 -h 540 -o ${ASSETS_DIR}/wivrn.png ${RSVG_OPTS} DEPENDS ${IMG_SRC_DIR}/wivrn.svg ${WIVRN_CSS_ABS}) -add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn-pride.png - COMMAND ${RSVG_CONVERT} ${IMG_SRC_DIR}/wivrn-pride.svg -w 540 -h 540 -o ${ASSETS_DIR}/wivrn-pride.png ${RSVG_OPTS} - DEPENDS ${IMG_SRC_DIR}/wivrn-pride.svg ${WIVRN_CSS_ABS}) - add_custom_target(assets ALL DEPENDS - ${ASSETS_DIR}/wivrn.png - ${ASSETS_DIR}/wivrn-pride.png -) + ${ASSETS_DIR}/wivrn.png add_dependencies(wivrn assets) @@ -245,9 +239,6 @@ if(ANDROID) add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.ktx2 COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn.ktx2 ${ASSETS_DIR}/wivrn.png DEPENDS ${ASSETS_DIR}/wivrn.png) - add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn-pride.ktx2 - COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn-pride.ktx2 ${ASSETS_DIR}/wivrn-pride.png - DEPENDS ${ASSETS_DIR}/wivrn-pride.png) add_custom_command(OUTPUT ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2 COMMAND ${TOKTX} --encode astc --astc_blk_d 12x12 --astc_quality 100 --genmipmap ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2 ${AST_SRC_DIR}/WoodFloor051_1K-JPG_Color.jpg @@ -259,10 +250,9 @@ if(ANDROID) add_custom_target(assets-android ALL DEPENDS ${ASSETS_DIR}/wivrn.ktx2 - ${ASSETS_DIR}/wivrn-pride.ktx2 ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2 - ${ASSETS_DIR}/vr_splash.png - ) + ${ASSETS_DIR}/vr_splash.png) + add_dependencies(assets-android assets) add_dependencies(wivrn assets-android) endif() diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index c2b6bf53..d4d4727f 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -884,9 +884,20 @@ void scenes::lobby::on_focused() imgui_ctx.emplace(physical_device, device, queue_family_index, queue, imgui_inputs, swapchain_imgui, vps); + std::string image; + /* Could be used for more patriotics logos + auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); auto tm = std::localtime(&t); - std::string image = tm->tm_mon == 5 ? "wivrn-pride" : "wivrn"; + + switch (tm->tm_mon) + { + default: + image = "wivrn"; + break; + } + */ + image = "wivrn"; try { about_picture = imgui_ctx->load_texture(image + ".ktx2"); diff --git a/images/wivrn-pride.svg b/images/wivrn-pride.svg deleted file mode 100644 index 71c38d51..00000000 --- a/images/wivrn-pride.svg +++ /dev/null @@ -1,622 +0,0 @@ - - - -WiVRn Wyvern yippe and GayvrnWiVRn Wyvern yippe and Gayvrn1/25/25 and 5/12/25Yaya, y.a.y.a on Discord. diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index f575469c..7a46459a 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -16,6 +16,7 @@ set(XRT_BUILD_DRIVER_RIFT_S OFF) set(XRT_BUILD_DRIVER_ROKID OFF) set(XRT_BUILD_DRIVER_SIMULATED OFF) set(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE ${WIVRN_FEATURE_STEAMVR_LIGHTHOUSE}) +set(XRT_BUILD_DRIVER_SOLARXR ${WIVRN_FEATURE_SOLARXR}) set(XRT_BUILD_DRIVER_TWRAP OFF) set(XRT_BUILD_DRIVER_VF OFF) set(XRT_BUILD_DRIVER_VIVE OFF) diff --git a/server/driver/wivrn_hmd.h b/server/driver/wivrn_hmd.h index 797cbbd2..4d15a92c 100644 --- a/server/driver/wivrn_hmd.h +++ b/server/driver/wivrn_hmd.h @@ -42,13 +42,6 @@ class wivrn_hmd : public xrt_device .name = XRT_INPUT_GENERIC_HEAD_POSE, }; xrt_hmd_parts hmd_parts{}; - xrt_tracking_origin tracking_origin{ - .name = "WiVRn origin", - .type = XRT_TRACKING_TYPE_OTHER, - .initial_offset = { - .orientation = {0, 0, 0, 1}, - }, - }; view_list views; from_headset::battery battery{}; @@ -66,6 +59,15 @@ class wivrn_hmd : public xrt_device public: using base = xrt_device; + + xrt_tracking_origin tracking_origin{ + .name = "WiVRn origin", + .type = XRT_TRACKING_TYPE_OTHER, + .initial_offset = { + .orientation = {0, 0, 0, 1}, + }, + }; + wivrn_hmd(wivrn::wivrn_session * cnx, const from_headset::headset_info_packet & info); diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 33cede63..c0e4c3c4 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -57,7 +57,7 @@ #endif #if WIVRN_FEATURE_SOLARXR -#include "solarxr_device.h" +#include "solarxr_interface.h" #endif namespace wivrn @@ -253,15 +253,13 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection } #if WIVRN_FEATURE_SOLARXR - xrt_device * solar_devs[XRT_SYSTEM_MAX_DEVICES]; - uint32_t solar_devs_cap = XRT_SYSTEM_MAX_DEVICES - xdev_count; - uint32_t num_devs = solarxr_device_create_xdevs(&hmd, solar_devs, XRT_SYSTEM_MAX_DEVICES - xdev_count); - for (int i = 0; i < num_devs; i++) + uint32_t num_devs = solarxr_device_create_xdevs(&hmd.tracking_origin, &xdevs[xdev_count], ARRAY_SIZE(xdevs) - xdev_count); + if (num_devs != 0) { - xdevs[xdev_count++] = solar_devs[i]; - if (i == 0) - static_roles.body = solar_devs[i]; + static_roles.body = xdevs[xdev_count]; + solarxr_device_set_feeder_devices(static_roles.body, xdevs, xdev_count); } + xdev_count += num_devs; #endif if (roles.left >= 0) @@ -280,6 +278,10 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection wivrn_session::~wivrn_session() { +#if WIVRN_FEATURE_SOLARXR + solarxr_device_set_feeder_devices(static_roles.body, nullptr, 0); +#endif + for (size_t i = 0; i < ARRAY_SIZE(xdevs); i++) { xrt_device_destroy(&xdevs[i]); From 4fd6d6d816c3741a949ca5e8643d6218dcaf5ec2 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 23:00:09 -0400 Subject: [PATCH 26/42] Update CMakeLists.txt --- client/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index b317481c..01059ded 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -230,7 +230,7 @@ add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.png DEPENDS ${IMG_SRC_DIR}/wivrn.svg ${WIVRN_CSS_ABS}) add_custom_target(assets ALL DEPENDS - ${ASSETS_DIR}/wivrn.png + ${ASSETS_DIR}/wivrn.png) add_dependencies(wivrn assets) From 1550a346c3bfe937b3e0751e07e278c4e61970da Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Fri, 16 May 2025 18:29:29 -0400 Subject: [PATCH 27/42] Update patches --- flatpak/io.github.wivrn.wivrn.yml.in | 4 + ...098-d-solarxr-Add-SolarXR-IPC-driver.patch | 2557 +++++++++++++++++ .../0099-t-common-Load-SolarXR-driver.patch | 292 ++ 3 files changed, 2853 insertions(+) create mode 100644 patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch create mode 100644 patches/monado/0099-t-common-Load-SolarXR-driver.patch diff --git a/flatpak/io.github.wivrn.wivrn.yml.in b/flatpak/io.github.wivrn.wivrn.yml.in index a4ee6eef..2d439db1 100644 --- a/flatpak/io.github.wivrn.wivrn.yml.in +++ b/flatpak/io.github.wivrn.wivrn.yml.in @@ -33,6 +33,9 @@ finish-args: # Set the active OpenXR / OpenVR runtime - --filesystem=xdg-config/openxr:create - --filesystem=xdg-config/openvr:create + # SlimeVR + - --filesystem=xdg-run/SlimeVRInput + - --filesystem=xdg-run/SlimeVRRpc # Let outside application access the WiVRn socket - --filesystem=xdg-run/wivrn:create - --own-name=io.github.wivrn.Server @@ -377,6 +380,7 @@ modules: - -DWIVRN_USE_NVENC=ON - -DWIVRN_USE_VULKAN_ENCODE=ON - -DWIVRN_USE_PULSEAUDIO=OFF + - -DWIVRN_FEATURE_SOLARXR=ON - -DWIVRN_WERROR=ON - -DWIVRN_CHECK_CAPSYSNICE=OFF # Capabilities don't work inside flatpak - -DFETCHCONTENT_FULLY_DISCONNECTED=ON diff --git a/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch b/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch new file mode 100644 index 00000000..55bf4399 --- /dev/null +++ b/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch @@ -0,0 +1,2557 @@ +From 421b8e7288cfd03407bcdd0ab9a478e85592393b Mon Sep 17 00:00:00 2001 +From: rcelyte +Date: Mon, 17 Jun 2024 04:32:36 +0000 +Subject: [PATCH] d/solarxr: Add SolarXR IPC driver + +--- + CMakeLists.txt | 3 + + src/xrt/drivers/CMakeLists.txt | 16 + + src/xrt/drivers/solarxr/feeder.c | 252 +++++ + src/xrt/drivers/solarxr/feeder.h | 32 + + src/xrt/drivers/solarxr/ipc_message.h | 63 ++ + src/xrt/drivers/solarxr/ipc_socket.c | 237 ++++ + src/xrt/drivers/solarxr/ipc_socket.h | 44 + + src/xrt/drivers/solarxr/protocol.c | 374 +++++++ + src/xrt/drivers/solarxr/protocol.h | 245 ++++ + src/xrt/drivers/solarxr/solarxr_device.c | 1114 +++++++++++++++++++ + src/xrt/drivers/solarxr/solarxr_interface.h | 40 + + src/xrt/targets/common/CMakeLists.txt | 4 + + 12 files changed, 2424 insertions(+) + create mode 100644 src/xrt/drivers/solarxr/feeder.c + create mode 100644 src/xrt/drivers/solarxr/feeder.h + create mode 100644 src/xrt/drivers/solarxr/ipc_message.h + create mode 100644 src/xrt/drivers/solarxr/ipc_socket.c + create mode 100644 src/xrt/drivers/solarxr/ipc_socket.h + create mode 100644 src/xrt/drivers/solarxr/protocol.c + create mode 100644 src/xrt/drivers/solarxr/protocol.h + create mode 100644 src/xrt/drivers/solarxr/solarxr_device.c + create mode 100644 src/xrt/drivers/solarxr/solarxr_interface.h + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 3d4b6bad32..97ee76f9ca 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -343,6 +343,7 @@ option_with_deps(XRT_BUILD_DRIVER_VIVE "Enable driver for HTC Vive, Vive Pro, Va + option_with_deps(XRT_BUILD_DRIVER_WMR "Enable Windows Mixed Reality driver" DEPENDS LINUX) + option_with_deps(XRT_BUILD_DRIVER_XREAL_AIR "Enable Xreal Air HMD driver" DEPENDS XRT_HAVE_HIDAPI) + option_with_deps(XRT_BUILD_DRIVER_SIMULAVR "Enable simula driver" DEPENDS XRT_HAVE_REALSENSE) ++option_with_deps(XRT_BUILD_DRIVER_SOLARXR "Enable SolarXR driver" DEPENDS XRT_HAVE_LINUX) + option(XRT_BUILD_DRIVER_SIMULATED "Enable simulated driver" ON) + + option(XRT_BUILD_SAMPLES "Enable compiling sample code implementations that will not be linked into any final targets" ON) +@@ -440,6 +441,7 @@ list( + "TWRAP" + "XREAL_AIR" + "STEAMVR_LIGHTHOUSE" ++ "SOLARXR" + ) + + # Package name needs to be known by the native code itself. +@@ -666,6 +668,7 @@ message(STATUS "# DRIVER_VIVE: ${XRT_BUILD_DRIVER_VIVE}") + message(STATUS "# DRIVER_WMR: ${XRT_BUILD_DRIVER_WMR}") + message(STATUS "# DRIVER_XREAL_AIR: ${XRT_BUILD_DRIVER_XREAL_AIR}") + message(STATUS "# DRIVER_STEAMVR_LIGHTHOUSE: ${XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE}") ++message(STATUS "# DRIVER_SOLARXR: ${XRT_BUILD_DRIVER_SOLARXR}") + message(STATUS "#####----- Config -----#####") + # cmake-format: on + +diff --git a/src/xrt/drivers/CMakeLists.txt b/src/xrt/drivers/CMakeLists.txt +index 0d422f16e4..b5511f45d8 100644 +--- a/src/xrt/drivers/CMakeLists.txt ++++ b/src/xrt/drivers/CMakeLists.txt +@@ -494,6 +494,22 @@ if(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE) + list(APPEND ENABLED_HEADSET_DRIVERS steamvr_lh) + endif() + ++if(XRT_BUILD_DRIVER_SOLARXR) ++ add_library( ++ drv_solarxr STATIC ++ solarxr/feeder.c ++ solarxr/feeder.h ++ solarxr/ipc_socket.c ++ solarxr/ipc_socket.h ++ solarxr/protocol.c ++ solarxr/protocol.h ++ solarxr/solarxr_device.c ++ solarxr/solarxr_interface.h ++ ) ++ target_link_libraries(drv_solarxr PRIVATE xrt-interfaces aux_util) ++ list(APPEND ENABLED_DRIVERS solarxr) ++endif() ++ + if(XRT_BUILD_SAMPLES) + # We build the sample driver to make sure it stays valid, + # but it never gets linked into a final target. +diff --git a/src/xrt/drivers/solarxr/feeder.c b/src/xrt/drivers/solarxr/feeder.c +new file mode 100644 +index 0000000000..eec813994d +--- /dev/null ++++ b/src/xrt/drivers/solarxr/feeder.c +@@ -0,0 +1,252 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#include "feeder.h" ++#include "ipc_message.h" ++#include "xrt/xrt_device.h" ++#include ++ ++// #define FEEDER_DESTROY_GUARD ++ ++#define PROTOBUF_FLOAT(v_) ((uint8_t *)&(v_))[0], ((uint8_t *)&(v_))[1], ((uint8_t *)&(v_))[2], ((uint8_t *)&(v_))[3] ++#define PROTOBUF_INT32(v_) \ ++ (uint8_t)(0x80 | (uint32_t)(v_)), (uint8_t)(0x80 | (uint32_t)(v_) >> 7), \ ++ (uint8_t)(0x80 | (uint32_t)(v_) >> 14), (uint8_t)(0x80 | (uint32_t)(v_) >> 21), (uint32_t)(v_) >> 28 ++ ++struct feeder_device ++{ ++ struct xrt_device *xdev; ++ enum xrt_input_name input_name; ++ uint32_t id; ++ uint8_t last_status; ++ bool battery_charging; ++ float battery_charge; ++#ifdef FEEDER_DESTROY_GUARD ++ void (*old_destroy)(struct xrt_device *xdev); ++#endif ++}; ++ ++void ++feeder_send_feedback(struct feeder *const feeder, const int64_t time) ++{ ++ os_mutex_lock(&feeder->mutex); ++ uint8_t packet[0x10000], *packet_end = packet; ++ for (uint32_t i = 0, devices_len = feeder->devices_len; i < devices_len; ++i) { ++ struct feeder_device *const device = &feeder->devices[i]; ++ if (device->xdev == NULL) { ++ continue; ++ } ++ ++ bool present = false, charging = false; ++ float charge = 0; ++ if (device->xdev->battery_status_supported && ++ xrt_device_get_battery_status(device->xdev, &present, &charging, &charge) == XRT_SUCCESS && ++ (charging != device->battery_charging || fabsf(charge - device->battery_charge) >= 1e-05)) { ++ device->battery_charging = charging; ++ device->battery_charge = charge; ++ uint8_t message[] = { ++ (5 << 3) | 2, 0, // ProtobufMessage::battery ++ (1 << 3) | 0, PROTOBUF_INT32(device->id), // Battery::tracker_id ++ (2 << 3) | 5, PROTOBUF_FLOAT(charge), // Battery::battery_level ++ (3 << 3) | 0, charging, // Battery::is_charging ++ }; ++ message[1] = sizeof(message) - 2; ++ ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, sizeof(message)); ++ } ++ ++ uint8_t status = 0; // Status::DISCONNECTED ++ struct xrt_space_relation relation = {0}; ++ assert(device->xdev->get_tracked_pose != NULL); ++ if (xrt_device_get_tracked_pose(device->xdev, device->input_name, time, &relation) == XRT_SUCCESS && ++ (relation.relation_flags & XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT) != 0) { ++ uint8_t message[30 + 15] = { ++ (1 << 3) | 2, 0, // ProtobufMessage::position ++ (1 << 3) | 0, PROTOBUF_INT32(device->id), // Position::tracker_id ++ (5 << 3) | 5, PROTOBUF_FLOAT(relation.pose.orientation.x), // Position::qx ++ (6 << 3) | 5, PROTOBUF_FLOAT(relation.pose.orientation.y), // Position::qy ++ (7 << 3) | 5, PROTOBUF_FLOAT(relation.pose.orientation.z), // Position::qz ++ (8 << 3) | 5, PROTOBUF_FLOAT(relation.pose.orientation.w), // Position::qw ++ (9 << 3) | 0, 3, // Position::data_source = DataSource::FULL ++ }; ++ uint32_t message_len = sizeof(message); ++ if ((relation.relation_flags & XRT_SPACE_RELATION_POSITION_TRACKED_BIT) != 0) { ++ const uint8_t position[15] = { ++ (2 << 3) | 5, PROTOBUF_FLOAT(relation.pose.position.x), // Position::x ++ (3 << 3) | 5, PROTOBUF_FLOAT(relation.pose.position.y), // Position::y ++ (4 << 3) | 5, PROTOBUF_FLOAT(relation.pose.position.z), // Position::z ++ }; ++ memcpy(&message[sizeof(message) - sizeof(position)], position, sizeof(position)); ++ } else { ++ message_len -= 15; ++ } ++ message[1] = message_len - 2; ++ ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, message_len); ++ status = 1; // Status::OK ++ } ++ ++ if (status != device->last_status) { ++ device->last_status = status; ++ uint8_t message[] = { ++ (4 << 3) | 2, 0, // ProtobufMessage::tracker_status ++ (1 << 3) | 0, PROTOBUF_INT32(device->id), // TrackerStatus::tracker_id ++ (2 << 3) | 0, status, // TrackerStatus::status ++ }; ++ message[1] = sizeof(message) - 2; ++ ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, sizeof(message)); ++ } ++ } ++ if (packet_end != packet) { ++ ipc_socket_send_raw(&feeder->socket, packet, packet_end - packet); ++ } ++ atomic_store(&feeder->last_send, time); ++ os_mutex_unlock(&feeder->mutex); ++} ++ ++static bool ++filter_feeder_device(struct xrt_device *const device, bool (*const filter)(struct xrt_device *device)) ++{ ++ return device != NULL && device->orientation_tracking_supported && (filter == NULL || filter(device)); ++} ++ ++#ifdef FEEDER_DESTROY_GUARD ++static void ++halt_and_catch_fire(struct xrt_device *xdev) ++{ ++ U_LOG_E("Device destroyed while still in use by feeder!"); ++ abort(); ++} ++#endif ++ ++bool ++feeder_set_devices(struct feeder *const feeder, ++ struct xrt_device *const devices[const], ++ const uint32_t devices_len, ++ bool (*const filter)(struct xrt_device *device)) ++{ ++ uint32_t device_count = 0; ++ for (uint32_t i = 0; i < devices_len; ++i) { ++ device_count += filter_feeder_device(devices[i], filter); ++ } ++ os_mutex_lock(&feeder->mutex); ++ if (!ipc_socket_is_connected(&feeder->socket)) { ++ if (!ipc_socket_connect(&feeder->socket, "SlimeVRInput", "slimevr/SlimeVRInput", NULL, 0)) { ++ os_mutex_unlock(&feeder->mutex); ++ return false; ++ } ++ } ++ for (uint32_t i = 0, devices_len = feeder->devices_len; i < devices_len; ++i) { ++ if (feeder->devices[i].xdev == NULL) { ++ continue; ++ } ++ // The feeder protocol doesn't define a 'removed' message so this is the best we can do ++ uint8_t message[] = { ++ (4 << 3) | 2, 0, // ProtobufMessage::tracker_status ++ (1 << 3) | 0, PROTOBUF_INT32(feeder->devices[i].id), // TrackerStatus::tracker_id ++ (2 << 3) | 0, 0, // TrackerStatus::status = Status::DISCONNECTED ++ }; ++ message[1] = sizeof(message) - 2; ++ ipc_socket_send(&feeder->socket, message, sizeof(message)); ++ ++#ifdef FEEDER_DESTROY_GUARD ++ feeder->devices[i].xdev->destroy = feeder->devices[i].old_destroy; ++#endif ++ feeder->devices[i] = (struct feeder_device){0}; ++ } ++ struct feeder_device *new_devices = NULL; ++ if (device_count != 0) { ++ new_devices = realloc(feeder->devices, device_count * sizeof(*new_devices)); ++ } ++ bool result; ++ if (new_devices == NULL) { ++ free(feeder->devices); ++ feeder->devices = NULL; ++ feeder->devices_len = 0; ++ result = device_count == 0; ++ } else { ++ feeder->devices = new_devices; ++ feeder->devices_len = device_count; ++ for (uint32_t i = 0; i < devices_len; ++i) { ++ if (!filter_feeder_device(devices[i], filter)) { ++ continue; ++ } ++ enum xrt_input_name input_name = XRT_INPUT_GENERIC_TRACKER_POSE; ++ for (size_t input = 0, input_count = devices[i]->input_count; input < input_count; ++input) { ++ if (XRT_GET_INPUT_TYPE(devices[i]->inputs[input].name) == XRT_INPUT_TYPE_POSE) { ++ input_name = devices[i]->inputs[input].name; ++ break; ++ } ++ } ++ uint8_t role = 0; // TrackerRole::NONE ++ switch (devices[i]->device_type) { ++ case XRT_DEVICE_TYPE_HMD: role = 19; break; // TrackerRole::HMD ++ case XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER: role = 14; break; // TrackerRole::RIGHT_CONTROLLER ++ case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER: role = 13; break; // TrackerRole::LEFT_CONTROLLER ++ case XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER: role = 21; break; // TrackerRole::GENERIC_CONTROLLER ++ default:; ++ } ++ assert(new_devices < &feeder->devices[feeder->devices_len]); ++ const uint32_t id = feeder->next_id++; ++ *new_devices++ = (struct feeder_device){ ++ .xdev = devices[i], ++ .input_name = input_name, ++ .id = id, ++ .last_status = UINT8_MAX, ++#ifdef FEEDER_DESTROY_GUARD ++ .old_destroy = devices[i]->destroy, ++#endif ++ }; ++#ifdef FEEDER_DESTROY_GUARD ++ devices[i]->destroy = halt_and_catch_fire; ++#endif ++ ++ const uint32_t serial_len = strlen(devices[i]->serial), name_len = strlen(devices[i]->str); ++ const uint8_t message_1[] = { ++ (3 << 3) | 2, PROTOBUF_INT32(0), // ProtobufMessage::tracker_added ++ (1 << 3) | 0, PROTOBUF_INT32(id), // TrackerAdded::tracker_id ++ (4 << 3) | 0, role, // TrackerAdded::tracker_role ++ (2 << 3) | 2, PROTOBUF_INT32(serial_len), ++ }; ++ const uint8_t message_2[] = { ++ (3 << 3) | 2, ++ PROTOBUF_INT32(name_len), ++ }; ++ uint8_t packet[sizeof(struct ipc_message) + sizeof(message_1) + sizeof(devices[i]->serial) + ++ sizeof(message_2) + sizeof(devices[i]->str)]; ++ struct ipc_message *const message = ipc_message_start(packet, &packet[ARRAY_SIZE(packet)]); ++ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], message_1, sizeof(message_1)); ++ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], (const uint8_t *)devices[i]->serial, ++ serial_len); // TrackerAdded::tracker_serial ++ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], message_2, sizeof(message_2)); ++ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], (const uint8_t *)devices[i]->str, ++ name_len); // TrackerAdded::tracker_name ++ const uint32_t packet_len = ipc_message_end(message, &(uint8_t *){packet}); ++ if (packet_len == 0) { ++ assert(false); ++ continue; ++ } ++ const uint8_t tracker_added[] = { ++ PROTOBUF_INT32(packet_len - sizeof(*message) - sizeof((uint8_t[]){0, PROTOBUF_INT32(0)})), ++ }; ++ memcpy(&message->body[1], tracker_added, sizeof(tracker_added)); ++ ipc_socket_send_raw(&feeder->socket, packet, packet_len); ++ } ++ result = true; ++ } ++ os_mutex_unlock(&feeder->mutex); ++ return result; ++} ++ ++bool ++feeder_init(struct feeder *const feeder, const enum u_logging_level log_level) ++{ ++ ipc_socket_init(&feeder->socket, log_level); ++ return os_mutex_init(&feeder->mutex) == 0; ++} ++ ++void ++feeder_destroy(struct feeder *const feeder) ++{ ++ feeder_set_devices(feeder, NULL, 0, NULL); ++ os_mutex_destroy(&feeder->mutex); ++ ipc_socket_destroy(&feeder->socket); ++} +diff --git a/src/xrt/drivers/solarxr/feeder.h b/src/xrt/drivers/solarxr/feeder.h +new file mode 100644 +index 0000000000..29cbb79b28 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/feeder.h +@@ -0,0 +1,32 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#pragma once ++#include "ipc_socket.h" ++#include "os/os_threading.h" ++ ++struct feeder_device; ++struct feeder ++{ ++ struct os_mutex mutex; ++ struct ipc_socket socket; ++ _Atomic(int64_t) last_send; ++ uint32_t next_id; ++ uint32_t devices_len; ++ struct feeder_device *devices; ++}; ++ ++bool ++feeder_init(struct feeder *feeder, enum u_logging_level log_level); ++ ++void ++feeder_destroy(struct feeder *feeder); ++ ++void ++feeder_send_feedback(struct feeder *feeder, int64_t time); // thread safe ++ ++bool ++feeder_set_devices(struct feeder *feeder, ++ struct xrt_device *const devices[], ++ uint32_t devices_len, ++ bool (*filter)(struct xrt_device *device)); // thread safe +diff --git a/src/xrt/drivers/solarxr/ipc_message.h b/src/xrt/drivers/solarxr/ipc_message.h +new file mode 100644 +index 0000000000..e68edcc102 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/ipc_message.h +@@ -0,0 +1,63 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#pragma once ++#include ++ ++struct ipc_message ++{ ++ uint32_t length; ++ uint8_t body[]; ++}; ++ ++static inline struct ipc_message * ++ipc_message_start(uint8_t head[const], const uint8_t *const end) ++{ ++ if ((size_t)(end - head) < sizeof(struct ipc_message)) { ++ return NULL; ++ } ++ struct ipc_message *const message = (struct ipc_message *)head; ++ message->length = 0; ++ return message; ++} ++ ++static inline bool ++ipc_message_write(struct ipc_message *const message, ++ const uint8_t *const end, ++ const uint8_t data[const], ++ const uint32_t data_len) ++{ ++ if (message == NULL) { ++ return false; ++ } ++ if ((size_t)(end - message->body) < message->length || end - &message->body[message->length] < data_len) { ++ message->length = UINT32_MAX; ++ return false; ++ } ++ memcpy(&message->body[message->length], data, data_len); ++ message->length += data_len; ++ return true; ++} ++ ++static inline uint32_t ++ipc_message_end(struct ipc_message *const message, uint8_t **const end_out) ++{ ++ if (message == NULL || message->length >= UINT32_MAX - sizeof(*message)) { ++ return 0; ++ } ++ *end_out = &message->body[message->length]; ++ const uint32_t length = sizeof(*message) + message->length; ++ message->length = htole32(length); ++ return length; ++} ++ ++static inline uint32_t ++ipc_message_write_single(uint8_t **const head, ++ const uint8_t *const end, ++ const uint8_t data[const], ++ const uint32_t data_len) ++{ ++ struct ipc_message *const message = ipc_message_start(*head, end); ++ ipc_message_write(message, end, data, data_len); ++ return ipc_message_end(message, head); ++} +diff --git a/src/xrt/drivers/solarxr/ipc_socket.c b/src/xrt/drivers/solarxr/ipc_socket.c +new file mode 100644 +index 0000000000..15faea369d +--- /dev/null ++++ b/src/xrt/drivers/solarxr/ipc_socket.c +@@ -0,0 +1,237 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#include "ipc_socket.h" ++#include "os/os_time.h" ++#include "util/u_file.h" ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++void ++ipc_socket_init(struct ipc_socket *const state, const enum u_logging_level log_level) ++{ ++ *state = (struct ipc_socket){ ++ .sockfd = -1, ++ .log_level = log_level, ++ .timestamp = (int64_t)os_monotonic_get_ns(), ++ .buffer = malloc(0x1000), ++ }; ++ if (state->buffer != NULL) { ++ state->buffer_cap = 0x1000; ++ } ++} ++ ++static void ++ipc_socket_close(struct ipc_socket *const state) ++{ ++ const int sockfd = atomic_exchange(&state->sockfd, -1); ++ if (sockfd == -1) { ++ return; ++ } ++ shutdown(sockfd, SHUT_RDWR); // unblock `ipc_socket_wait()` ++ _Static_assert(sizeof(state->reference.count) == sizeof(volatile _Atomic(int)), ""); ++ while (atomic_load((volatile _Atomic(int) *)&state->reference.count) != 0) { ++ sched_yield(); ++ } ++ close(sockfd); ++} ++ ++void ++ipc_socket_destroy(struct ipc_socket *const state) ++{ ++ ipc_socket_close(state); ++ free(state->buffer); ++ state->buffer = NULL; ++ state->buffer_cap = 0; ++} ++ ++static bool ++path_is_socket(const char path[const]) ++{ ++ struct stat result = {0}; ++ return stat(path, &result) == 0 && S_ISSOCK(result.st_mode); ++} ++ ++bool ++ipc_socket_connect(struct ipc_socket *const state, ++ const char runtime_path[const], ++ const char fallback_path[const], ++ char path_out[const], ++ const size_t path_cap) ++{ ++ ipc_socket_close(state); ++ const int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); ++ if (sockfd == -1) { ++ U_LOG_IFL_E(state->log_level, "socket() failed"); ++ return false; ++ } ++ struct sockaddr_un addr = { ++ .sun_family = AF_UNIX, ++ }; ++ ssize_t path_len = u_file_get_path_in_runtime_dir(runtime_path, addr.sun_path, sizeof(addr.sun_path)); ++ if (path_len <= 0 || (size_t)path_len >= sizeof(addr.sun_path)) { ++ U_LOG_IFL_E(state->log_level, "u_file_get_path_in_runtime_dir() failed"); ++ goto fail; ++ } ++ if (!path_is_socket(addr.sun_path)) { ++ U_LOG_IFL_W(state->log_level, "path not found: %s", addr.sun_path); ++ const char *env; ++ if ((env = getenv("XDG_DATA_HOME")) != NULL) { ++ path_len = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", env, fallback_path); ++ } else if ((env = getenv("HOME")) != NULL) { ++ path_len = ++ snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/.local/share/%s", env, fallback_path); ++ } else { ++ path_len = 0; ++ } ++ if (path_len <= 0 || (size_t)path_len >= sizeof(addr.sun_path)) { ++ U_LOG_IFL_E(state->log_level, "failed to resolve SlimeVR socket path"); ++ goto fail; ++ } ++ if (!path_is_socket(addr.sun_path)) { ++ U_LOG_IFL_E(state->log_level, "path not found: %s", addr.sun_path); ++ goto fail; ++ } ++ } ++ if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(addr)) != 0) { ++ U_LOG_IFL_E(state->log_level, "connect() failed: %s", strerror(errno)); ++ goto fail; ++ } ++ if (path_cap >= 1) { ++ if ((size_t)path_len >= path_cap) { ++ path_len = path_cap - 1; ++ } ++ memcpy(path_out, addr.sun_path, path_len + 1); ++ } ++ atomic_store(&state->sockfd, sockfd); ++ return true; ++fail: ++ close(sockfd); ++ return false; ++} ++ ++bool ++ipc_socket_wait(struct ipc_socket *const state) ++{ ++ xrt_reference_inc(&state->reference); ++ struct pollfd sockfd = {atomic_load(&state->sockfd), POLLIN, 0}; ++ bool result = false; ++ if (sockfd.fd != -1) { ++ result = poll(&sockfd, 1, -1) != -1 || errno == EINTR; ++ } ++ xrt_reference_dec(&state->reference); ++ return result; ++} ++ ++static size_t ++ipc_socket_send_common(struct ipc_socket *const state, struct iovec parts[const], const uint32_t parts_len) ++{ ++ xrt_reference_inc(&state->reference); ++ const int sockfd = atomic_load(&state->sockfd); ++ if (sockfd == -1) { ++ xrt_reference_dec(&state->reference); ++ return 0; ++ } ++ const ssize_t result = sendmsg(sockfd, ++ &(const struct msghdr){ ++ .msg_iov = parts, ++ .msg_iovlen = parts_len, ++ }, ++ MSG_NOSIGNAL); ++ xrt_reference_dec(&state->reference); ++ return (size_t)result; ++} ++ ++bool ++ipc_socket_send(struct ipc_socket *const state, const uint8_t message[const], const uint32_t message_len) ++{ ++ struct iovec parts[2] = { ++ {&(uint32_t){htole32(message_len + sizeof(uint32_t))}, sizeof(uint32_t)}, ++ {*(uint8_t **)&message, message_len}, ++ }; ++ return ipc_socket_send_common(state, parts, ARRAY_SIZE(parts)) == sizeof(uint32_t) + message_len; ++} ++ ++bool ++ipc_socket_send_raw(struct ipc_socket *const state, const uint8_t packet[const], const uint32_t packet_len) ++{ ++ struct iovec parts[1] = { ++ {*(uint8_t **)&packet, packet_len}, ++ }; ++ return ipc_socket_send_common(state, parts, ARRAY_SIZE(parts)) == packet_len; ++} ++ ++uint32_t ++ipc_socket_receive(struct ipc_socket *const state) ++{ ++ xrt_reference_inc(&state->reference); ++ const int sockfd = atomic_load(&state->sockfd); ++ if (sockfd == -1) { ++ xrt_reference_dec(&state->reference); ++ return 0; ++ } ++ if (state->head == state->buffer_len) { ++ uint32_t header = 0; ++ ssize_t length = recv(sockfd, &header, sizeof(header), MSG_PEEK | MSG_DONTWAIT); ++ if (length < 0 && errno != EAGAIN) { ++ U_LOG_IFL_E(state->log_level, "recv() failed: %s", strerror(errno)); ++ goto fail; ++ } ++ if (length < (ssize_t)sizeof(header)) { ++ xrt_reference_dec(&state->reference); ++ return 0; ++ } ++ length = recv(sockfd, &header, sizeof(header), MSG_DONTWAIT); ++ if (length != sizeof(header)) { ++ U_LOG_IFL_E(state->log_level, "recv() failed: %s", ++ (length < 0) ? strerror(errno) : "bad length"); ++ goto fail; ++ } ++ const uint32_t packet_length = le32toh(header) - sizeof(header); ++ if (packet_length > state->buffer_cap) { ++ if (packet_length > 0x100000u) { ++ U_LOG_IFL_E(state->log_level, "packet too large"); ++ goto fail; ++ } ++ uint8_t *const new_buffer = realloc(state->buffer, packet_length); ++ if (new_buffer == NULL) { ++ U_LOG_IFL_E(state->log_level, "realloc failed"); ++ goto fail; ++ } ++ state->buffer = new_buffer; ++ state->buffer_cap = packet_length; ++ } ++ state->buffer_len = packet_length; ++ state->head = 0; ++ state->timestamp = (int64_t)os_monotonic_get_ns(); ++ } ++ for (ssize_t length; state->head < state->buffer_len; state->head += (size_t)length) { ++ length = recv(sockfd, &state->buffer[state->head], state->buffer_len - state->head, MSG_DONTWAIT); ++ if (length < 0 && errno != EAGAIN) { ++ U_LOG_IFL_E(state->log_level, "recv() failed: %s", strerror(errno)); ++ goto fail; ++ } ++ if (length <= 0) { ++ xrt_reference_dec(&state->reference); ++ return 0; ++ } ++ if (length > state->buffer_len - state->head) { ++ U_LOG_IFL_E(state->log_level, "recv() returned invalid length"); ++ goto fail; ++ } ++ } ++ xrt_reference_dec(&state->reference); ++ return state->buffer_len; ++fail: ++ xrt_reference_dec(&state->reference); ++ ipc_socket_destroy(state); ++ return 0; ++} +diff --git a/src/xrt/drivers/solarxr/ipc_socket.h b/src/xrt/drivers/solarxr/ipc_socket.h +new file mode 100644 +index 0000000000..c4f1ce4715 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/ipc_socket.h +@@ -0,0 +1,44 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#pragma once ++#include "util/u_logging.h" ++#include ++ ++struct ipc_socket ++{ ++ _Atomic(int) sockfd; ++ struct xrt_reference reference; ++ enum u_logging_level log_level; ++ int64_t timestamp; ++ uint32_t head, buffer_len, buffer_cap; ++ uint8_t *buffer; ++}; ++ ++void ++ipc_socket_init(struct ipc_socket *state, enum u_logging_level log_level); ++ ++void ++ipc_socket_destroy(struct ipc_socket *state); // thread safe ++ ++bool ++ipc_socket_connect( ++ struct ipc_socket *state, const char runtime_path[], const char fallback_path[], char path_out[], size_t path_cap); ++ ++bool ++ipc_socket_wait(struct ipc_socket *state); ++ ++bool ++ipc_socket_send(struct ipc_socket *state, const uint8_t message[], uint32_t message_len); // thread safe ++ ++bool ++ipc_socket_send_raw(struct ipc_socket *state, const uint8_t packet[], uint32_t packet_len); // thread safe ++ ++uint32_t ++ipc_socket_receive(struct ipc_socket *state); ++ ++static inline bool ++ipc_socket_is_connected(struct ipc_socket *const state) ++{ ++ return atomic_load(&state->sockfd) != -1; ++} +diff --git a/src/xrt/drivers/solarxr/protocol.c b/src/xrt/drivers/solarxr/protocol.c +new file mode 100644 +index 0000000000..59607bc344 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/protocol.c +@@ -0,0 +1,374 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#include "protocol.h" ++ ++#include "math/m_api.h" ++ ++#include ++#include ++ ++typedef int32_t flatbuffers_soffset_t; // little-endian byte order ++typedef uint16_t flatbuffers_voffset_t; // little-endian byte order ++typedef flatbuffers_vector(void) flatbuffers_vector_t; ++ ++struct table_data ++{ ++ uint16_t length; ++ const uint8_t *data; ++}; ++ ++static const void * ++read_flatbuffers_uoffset(const uint8_t buffer[const], ++ const size_t buffer_len, ++ const flatbuffers_uoffset_t *const ref, ++ const size_t size) ++{ ++ assert((const uint8_t *)ref >= buffer && (const uint8_t *)ref <= &buffer[buffer_len - sizeof(*ref)]); ++ const uint32_t offset = le32toh(*ref); ++ const size_t cap = &buffer[buffer_len] - (const uint8_t *)ref; ++ const void *const result = (const uint8_t *)ref + offset; ++ if (offset == 0 || cap < size || offset > cap - size || ((uintptr_t)result & 0x3) != 0) { ++ return NULL; ++ } ++ return result; ++} ++ ++static struct table_data ++read_flatbuffers_table(const uint8_t buffer[const], ++ const size_t buffer_len, ++ const flatbuffers_uoffset_t *const ref, ++ uint16_t vtable_out[const], ++ const uint16_t vtable_cap) ++{ ++ memset(vtable_out, 0, vtable_cap * sizeof(*vtable_out)); ++ const flatbuffers_soffset_t *const table = read_flatbuffers_uoffset(buffer, buffer_len, ref, sizeof(*table)); ++ if (table == NULL) { ++ return (struct table_data){0}; ++ } ++ const flatbuffers_voffset_t *const vtable = ++ (const flatbuffers_voffset_t *)((const uint8_t *)table - (int32_t)le32toh(*table)); ++ if ((const uint8_t *)vtable < buffer || (const uint8_t *)vtable > &buffer[buffer_len - 2 * sizeof(*vtable)]) { ++ return (struct table_data){0}; ++ } ++ const uint16_t vtable_size = le16toh(vtable[0]), table_size = le16toh(vtable[1]); ++ if (vtable_size > &buffer[buffer_len] - (const uint8_t *)vtable || ++ table_size > &buffer[buffer_len] - (const uint8_t *)table || (vtable_size & 0x1) != 0 || ++ table_size < sizeof(*table)) { ++ return (struct table_data){0}; ++ } ++ for (uint16_t i = 0, length = MIN(vtable_size / sizeof(*vtable) - 2, vtable_cap); i < length; ++i) { ++ const flatbuffers_voffset_t offset = le16toh(vtable[2 + i]); ++ if (offset < table_size) { ++ vtable_out[i] = offset; ++ } ++ } ++ return (struct table_data){table_size, (const uint8_t *)table}; ++} ++ ++static flatbuffers_vector_t ++read_flatbuffers_vector(const uint8_t buffer[const], ++ const size_t buffer_len, ++ const flatbuffers_uoffset_t *const ref, ++ const size_t element_size) ++{ ++ const uint32_t *const vector = read_flatbuffers_uoffset(buffer, buffer_len, ref, sizeof(*vector)); ++ if (vector == NULL) { ++ return (flatbuffers_vector_t){0}; ++ } ++ const flatbuffers_vector_t out = { ++ .length = le32toh(*vector), ++ .data = &vector[1], ++ }; ++ if (out.length > (&buffer[buffer_len] - (const uint8_t *)out.data) / element_size) { ++ return (flatbuffers_vector_t){0}; ++ } ++ return out; ++} ++ ++static bool ++read_solarxr_quat(struct xrt_quat *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const uint16_t offset) ++{ ++ static_assert(offsetof(struct xrt_quat, x) == 0, ""); ++ static_assert(offsetof(struct xrt_quat, y) == 4, ""); ++ static_assert(offsetof(struct xrt_quat, z) == 8, ""); ++ static_assert(offsetof(struct xrt_quat, w) == 12, ""); ++ static_assert(sizeof(struct xrt_quat) == 16, ""); ++ *out = (struct xrt_quat){.w = 1}; ++ if (offset == 0 || offset + sizeof(*out) > buffer_len) { ++ return false; ++ } ++ memcpy(out, &buffer[offset], sizeof(*out)); ++ return true; ++} ++ ++static bool ++read_solarxr_vec3f(struct xrt_vec3 *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const uint16_t offset) ++{ ++ static_assert(offsetof(struct xrt_vec3, x) == 0, ""); ++ static_assert(offsetof(struct xrt_vec3, y) == 4, ""); ++ static_assert(offsetof(struct xrt_vec3, z) == 8, ""); ++ static_assert(sizeof(struct xrt_vec3) == 12, ""); ++ *out = (struct xrt_vec3){0}; ++ if (offset == 0 || offset + sizeof(*out) > buffer_len) { ++ return false; ++ } ++ memcpy(out, &buffer[offset], sizeof(*out)); ++ return true; ++} ++ ++bool ++read_solarxr_message_bundle(struct solarxr_message_bundle *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_message_bundle_t *const ref) ++{ ++ *out = (struct solarxr_message_bundle){0}; ++ uint16_t bundle_vtable[2]; ++ const struct table_data bundle = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, bundle_vtable, ARRAY_SIZE(bundle_vtable)); ++ if (bundle.length == 0) { ++ return false; ++ } ++ if (bundle_vtable[0] != 0 && bundle_vtable[0] + sizeof(flatbuffers_uoffset_t) <= bundle.length) { ++ *(flatbuffers_vector_t *)&out->data_feed_msgs = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&bundle.data[bundle_vtable[0]], ++ sizeof(*out->data_feed_msgs.data)); ++ } ++ if (bundle_vtable[1] != 0 && bundle_vtable[1] + sizeof(flatbuffers_uoffset_t) <= bundle.length) { ++ *(flatbuffers_vector_t *)&out->rpc_msgs = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&bundle.data[bundle_vtable[1]], ++ sizeof(*out->rpc_msgs.data)); ++ } ++ return true; ++} ++ ++bool ++read_solarxr_data_feed_message_header(struct solarxr_data_feed_message_header *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_data_feed_message_header_t *const ref) ++{ ++ *out = (struct solarxr_data_feed_message_header){0}; ++ uint16_t header_vtable[2]; ++ const struct table_data header = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, header_vtable, ARRAY_SIZE(header_vtable)); ++ if (header.length == 0) { ++ return false; ++ } ++ if (header_vtable[0] == 0 || header_vtable[1] == 0 || ++ header_vtable[1] + sizeof(flatbuffers_uoffset_t) > header.length) { ++ return true; ++ } ++ out->message_type = header.data[header_vtable[0]]; ++ switch (header.data[header_vtable[0]]) { ++ case SOLARXR_DATA_FEED_MESSAGE_DATA_FEED_UPDATE: { ++ uint16_t update_vtable[3]; ++ const struct table_data update = read_flatbuffers_table( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&header.data[header_vtable[1]], update_vtable, ++ ARRAY_SIZE(update_vtable)); ++ if (update.length == 0) { ++ break; ++ } ++ if (update_vtable[0] != 0 && update_vtable[0] + sizeof(flatbuffers_uoffset_t) <= update.length) { ++ *(flatbuffers_vector_t *)&out->message.data_feed_update.devices = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&update.data[update_vtable[0]], ++ sizeof(*out->message.data_feed_update.devices.data)); ++ } ++ if (update_vtable[1] != 0 && update_vtable[1] + sizeof(flatbuffers_uoffset_t) <= update.length) { ++ *(flatbuffers_vector_t *)&out->message.data_feed_update.synthetic_trackers = ++ read_flatbuffers_vector(buffer, buffer_len, ++ (const flatbuffers_uoffset_t *)&update.data[update_vtable[1]], ++ sizeof(*out->message.data_feed_update.synthetic_trackers.data)); ++ } ++ if (update_vtable[2] != 0 && update_vtable[2] + sizeof(flatbuffers_uoffset_t) <= update.length) { ++ *(flatbuffers_vector_t *)&out->message.data_feed_update.bones = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&update.data[update_vtable[2]], ++ sizeof(*out->message.data_feed_update.bones.data)); ++ } ++ break; ++ } ++ default:; ++ } ++ return true; ++} ++ ++bool ++read_solarxr_rpc_message_header(struct solarxr_rpc_message_header *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_rpc_message_header_t *const ref) ++{ ++ *out = (struct solarxr_rpc_message_header){0}; ++ uint16_t header_vtable[3]; ++ const struct table_data header = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, header_vtable, ARRAY_SIZE(header_vtable)); ++ if (header.length == 0) { ++ return false; ++ } ++ if (header_vtable[1] == 0 || header_vtable[2] == 0 || ++ header_vtable[2] + sizeof(flatbuffers_uoffset_t) > header.length) { ++ return true; ++ } ++ out->message_type = header.data[header_vtable[1]]; ++ switch (header.data[header_vtable[1]]) { ++ case SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_RESPONSE: { ++ uint16_t message_vtable[1]; ++ const struct table_data message = read_flatbuffers_table( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&header.data[header_vtable[2]], message_vtable, ++ ARRAY_SIZE(message_vtable)); ++ if (message.length == 0 || message_vtable[0] == 0 || ++ message_vtable[0] + sizeof(flatbuffers_uoffset_t) > message.length) { ++ break; ++ } ++ uint16_t trackers_vtable[15]; ++ const struct table_data trackers = read_flatbuffers_table( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&message.data[message_vtable[0]], ++ trackers_vtable, ARRAY_SIZE(trackers_vtable)); ++ if (trackers.length == 0) { ++ break; ++ } ++ if (trackers_vtable[0] != 0) { ++ out->message.settings_response.steam_vr_trackers.waist = trackers.data[trackers_vtable[0]]; ++ } ++ if (trackers_vtable[1] != 0) { ++ out->message.settings_response.steam_vr_trackers.chest = trackers.data[trackers_vtable[1]]; ++ } ++ if (trackers_vtable[7] != 0) { ++ out->message.settings_response.steam_vr_trackers.left_foot = trackers.data[trackers_vtable[7]]; ++ } ++ if (trackers_vtable[8] != 0) { ++ out->message.settings_response.steam_vr_trackers.right_foot = trackers.data[trackers_vtable[8]]; ++ } ++ if (trackers_vtable[9] != 0) { ++ out->message.settings_response.steam_vr_trackers.left_knee = trackers.data[trackers_vtable[9]]; ++ } ++ if (trackers_vtable[10] != 0) { ++ out->message.settings_response.steam_vr_trackers.right_knee = ++ trackers.data[trackers_vtable[10]]; ++ } ++ if (trackers_vtable[11] != 0) { ++ out->message.settings_response.steam_vr_trackers.left_elbow = ++ trackers.data[trackers_vtable[11]]; ++ } ++ if (trackers_vtable[12] != 0) { ++ out->message.settings_response.steam_vr_trackers.right_elbow = ++ trackers.data[trackers_vtable[12]]; ++ } ++ if (trackers_vtable[13] != 0) { ++ out->message.settings_response.steam_vr_trackers.left_hand = trackers.data[trackers_vtable[13]]; ++ } ++ if (trackers_vtable[14] != 0) { ++ out->message.settings_response.steam_vr_trackers.right_hand = ++ trackers.data[trackers_vtable[14]]; ++ } ++ break; ++ } ++ default:; ++ } ++ return true; ++} ++ ++bool ++read_solarxr_device_data(struct solarxr_device_data *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_device_data_t *const ref) ++{ ++ *out = (struct solarxr_device_data){0}; ++ uint16_t data_vtable[5]; ++ const struct table_data data = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, data_vtable, ARRAY_SIZE(data_vtable)); ++ if (data.length == 0) { ++ return false; ++ } ++ if (data_vtable[0] != 0) { ++ out->id = data.data[data_vtable[0]]; ++ } ++ if (data_vtable[4] != 0 && data_vtable[4] + sizeof(flatbuffers_uoffset_t) <= data.length) { ++ *(flatbuffers_vector_t *)&out->trackers = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&data.data[data_vtable[4]], ++ sizeof(*out->trackers.data)); ++ } ++ return true; ++} ++ ++bool ++read_solarxr_tracker_data(struct solarxr_tracker_data *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_tracker_data_t *const ref) ++{ ++ *out = (struct solarxr_tracker_data){0}; ++ uint16_t data_vtable[9]; ++ const struct table_data data = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, data_vtable, ARRAY_SIZE(data_vtable)); ++ if (data.length == 0) { ++ return false; ++ } ++ if (data_vtable[0] != 0 && data_vtable[0] + sizeof(flatbuffers_uoffset_t) <= data.length) { ++ uint16_t id_vtable[2]; ++ const struct table_data id = read_flatbuffers_table( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&data.data[data_vtable[0]], id_vtable, ++ ARRAY_SIZE(id_vtable)); ++ if (id_vtable[0] != 0) { ++ out->tracker_id.has_device_id = true; ++ out->tracker_id.device_id = id.data[id_vtable[0]]; ++ } ++ if (id_vtable[1] != 0) { ++ out->tracker_id.tracker_num = id.data[id_vtable[1]]; ++ } ++ } ++ if (data_vtable[1] != 0 && data_vtable[1] + sizeof(flatbuffers_uoffset_t) <= data.length) { ++ uint16_t info_vtable[8]; ++ const struct table_data info = read_flatbuffers_table( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&data.data[data_vtable[1]], info_vtable, ++ ARRAY_SIZE(info_vtable)); ++ out->has_info = true; ++ if (info_vtable[1] != 0) { ++ out->info.body_part = info.data[info_vtable[1]]; ++ } ++ if (info_vtable[7] != 0) { ++ *(flatbuffers_vector_t *)&out->info.display_name = read_flatbuffers_vector( ++ buffer, buffer_len, (const flatbuffers_uoffset_t *)&info.data[info_vtable[7]], ++ sizeof(*out->info.display_name.data)); ++ } ++ } ++ out->has_rotation = read_solarxr_quat(&out->rotation, data.data, data.length, data_vtable[3]); ++ out->has_position = read_solarxr_vec3f(&out->position, data.data, data.length, data_vtable[4]); ++ out->has_raw_angular_velocity = ++ read_solarxr_vec3f(&out->raw_angular_velocity, data.data, data.length, data_vtable[5]); ++ out->has_linear_acceleration = ++ read_solarxr_vec3f(&out->linear_acceleration, data.data, data.length, data_vtable[8]); ++ return true; ++} ++ ++bool ++read_solarxr_bone(struct solarxr_bone *const out, ++ const uint8_t buffer[const], ++ const size_t buffer_len, ++ const solarxr_bone_t *const ref) ++{ ++ *out = (struct solarxr_bone){0}; ++ uint16_t bone_vtable[4]; ++ const struct table_data bone = ++ read_flatbuffers_table(buffer, buffer_len, &ref->offset, bone_vtable, ARRAY_SIZE(bone_vtable)); ++ if (bone.length == 0) { ++ return false; ++ } ++ if (bone_vtable[0] != 0) { ++ out->body_part = bone.data[bone_vtable[0]]; ++ } ++ read_solarxr_quat(&out->rotation_g, bone.data, bone.length, bone_vtable[1]); ++ if (bone_vtable[2] != 0 && bone_vtable[2] + sizeof(out->bone_length) <= bone.length) { ++ memcpy(&out->bone_length, &bone.data[bone_vtable[2]], sizeof(out->bone_length)); ++ } ++ read_solarxr_vec3f(&out->head_position_g, bone.data, bone.length, bone_vtable[3]); ++ return true; ++} +diff --git a/src/xrt/drivers/solarxr/protocol.h b/src/xrt/drivers/solarxr/protocol.h +new file mode 100644 +index 0000000000..d85636fc98 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/protocol.h +@@ -0,0 +1,245 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++/*! ++ * @file ++ * @brief Parser for a small subset of the SolarXR Flatbuffers protocol, as defined at ++ * https://github.com/SlimeVR/SolarXR-Protocol ++ * @ingroup drv_solarxr ++ */ ++ ++#pragma once ++#include "xrt/xrt_defines.h" ++#include ++ ++typedef uint32_t flatbuffers_uoffset_t; // little-endian byte order ++ ++enum solarxr_body_part ++{ ++ SOLARXR_BODY_PART_NONE = 0, ++ SOLARXR_BODY_PART_HEAD = 1, ++ SOLARXR_BODY_PART_NECK = 2, ++ SOLARXR_BODY_PART_CHEST = 3, ++ SOLARXR_BODY_PART_WAIST = 4, ++ SOLARXR_BODY_PART_HIP = 5, ++ SOLARXR_BODY_PART_LEFT_UPPER_LEG = 6, ++ SOLARXR_BODY_PART_RIGHT_UPPER_LEG = 7, ++ SOLARXR_BODY_PART_LEFT_LOWER_LEG = 8, ++ SOLARXR_BODY_PART_RIGHT_LOWER_LEG = 9, ++ SOLARXR_BODY_PART_LEFT_FOOT = 10, ++ SOLARXR_BODY_PART_RIGHT_FOOT = 11, ++ SOLARXR_BODY_PART_LEFT_LOWER_ARM = 14, ++ SOLARXR_BODY_PART_RIGHT_LOWER_ARM = 15, ++ SOLARXR_BODY_PART_LEFT_UPPER_ARM = 16, ++ SOLARXR_BODY_PART_RIGHT_UPPER_ARM = 17, ++ SOLARXR_BODY_PART_LEFT_HAND = 18, ++ SOLARXR_BODY_PART_RIGHT_HAND = 19, ++ SOLARXR_BODY_PART_LEFT_SHOULDER = 20, ++ SOLARXR_BODY_PART_RIGHT_SHOULDER = 21, ++ SOLARXR_BODY_PART_UPPER_CHEST = 22, ++ SOLARXR_BODY_PART_LEFT_HIP = 23, ++ SOLARXR_BODY_PART_RIGHT_HIP = 24, ++ SOLARXR_BODY_PART_LEFT_THUMB_PROXIMAL = 25, ++ SOLARXR_BODY_PART_LEFT_THUMB_INTERMEDIATE = 26, ++ SOLARXR_BODY_PART_LEFT_THUMB_DISTAL = 27, ++ SOLARXR_BODY_PART_LEFT_INDEX_PROXIMAL = 28, ++ SOLARXR_BODY_PART_LEFT_INDEX_INTERMEDIATE = 29, ++ SOLARXR_BODY_PART_LEFT_INDEX_DISTAL = 30, ++ SOLARXR_BODY_PART_LEFT_MIDDLE_PROXIMAL = 31, ++ SOLARXR_BODY_PART_LEFT_MIDDLE_INTERMEDIATE = 32, ++ SOLARXR_BODY_PART_LEFT_MIDDLE_DISTAL = 33, ++ SOLARXR_BODY_PART_LEFT_RING_PROXIMAL = 34, ++ SOLARXR_BODY_PART_LEFT_RING_INTERMEDIATE = 35, ++ SOLARXR_BODY_PART_LEFT_RING_DISTAL = 36, ++ SOLARXR_BODY_PART_LEFT_LITTLE_PROXIMAL = 37, ++ SOLARXR_BODY_PART_LEFT_LITTLE_INTERMEDIATE = 38, ++ SOLARXR_BODY_PART_LEFT_LITTLE_DISTAL = 39, ++ SOLARXR_BODY_PART_RIGHT_THUMB_PROXIMAL = 40, ++ SOLARXR_BODY_PART_RIGHT_THUMB_INTERMEDIATE = 41, ++ SOLARXR_BODY_PART_RIGHT_THUMB_DISTAL = 42, ++ SOLARXR_BODY_PART_RIGHT_INDEX_PROXIMAL = 43, ++ SOLARXR_BODY_PART_RIGHT_INDEX_INTERMEDIATE = 44, ++ SOLARXR_BODY_PART_RIGHT_INDEX_DISTAL = 45, ++ SOLARXR_BODY_PART_RIGHT_MIDDLE_PROXIMAL = 46, ++ SOLARXR_BODY_PART_RIGHT_MIDDLE_INTERMEDIATE = 47, ++ SOLARXR_BODY_PART_RIGHT_MIDDLE_DISTAL = 48, ++ SOLARXR_BODY_PART_RIGHT_RING_PROXIMAL = 49, ++ SOLARXR_BODY_PART_RIGHT_RING_INTERMEDIATE = 50, ++ SOLARXR_BODY_PART_RIGHT_RING_DISTAL = 51, ++ SOLARXR_BODY_PART_RIGHT_LITTLE_PROXIMAL = 52, ++ SOLARXR_BODY_PART_RIGHT_LITTLE_INTERMEDIATE = 53, ++ SOLARXR_BODY_PART_RIGHT_LITTLE_DISTAL = 54, ++ SOLARXR_BODY_PART_MAX_ENUM, ++}; ++ ++#define flatbuffers_vector(type_) \ ++ struct \ ++ { \ ++ uint32_t length; \ ++ const type_ *data; \ ++ } ++ ++struct solarxr_tracker_id ++{ // table solarxr_protocol.datatypes.TrackerId ++ bool has_device_id; ++ uint8_t device_id; ++ uint8_t tracker_num; ++}; ++ ++struct solarxr_tracker_info ++{ // table solarxr_protocol.data_feed.tracker.TrackerInfo ++ enum solarxr_body_part body_part; ++ flatbuffers_vector(char) display_name; ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_tracker_data_t; ++ ++struct solarxr_tracker_data ++{ // table solarxr_protocol.data_feed.tracker.TrackerData ++ bool has_info; ++ bool has_rotation; ++ bool has_position; ++ bool has_raw_angular_velocity; ++ bool has_linear_acceleration; ++ struct solarxr_tracker_id tracker_id; ++ struct solarxr_tracker_info info; ++ struct xrt_quat rotation; ++ struct xrt_vec3 position; ++ struct xrt_vec3 raw_angular_velocity; ++ struct xrt_vec3 linear_acceleration; ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_device_data_t; ++ ++struct solarxr_device_data ++{ // table solarxr_protocol.data_feed.device_data.DeviceData ++ uint8_t id; ++ flatbuffers_vector(solarxr_tracker_data_t) trackers; // solarxr_protocol.data_feed.tracker.TrackerData[] ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_bone_t; ++ ++struct solarxr_bone ++{ // table solarxr_protocol.data_feed.Bone ++ enum solarxr_body_part body_part; ++ struct xrt_quat rotation_g; ++ float bone_length; ++ struct xrt_vec3 head_position_g; ++}; ++ ++struct solarxr_data_feed_update ++{ // table solarxr_protocol.data_feed.DataFeedUpdate ++ flatbuffers_vector(solarxr_device_data_t) devices; // solarxr_protocol.data_feed.device_data.DeviceData[] ++ flatbuffers_vector(solarxr_tracker_data_t) ++ synthetic_trackers; // solarxr_protocol.data_feed.tracker.TrackerData[] ++ flatbuffers_vector(solarxr_bone_t) bones; // solarxr_protocol.data_feed.Bone[] ++}; ++ ++enum solarxr_data_feed_message_type ++{ ++ SOLARXR_DATA_FEED_MESSAGE_POLL_DATA_FEED = 1, ++ SOLARXR_DATA_FEED_MESSAGE_DATA_FEED_UPDATE = 3, ++}; ++ ++union solarxr_data_feed_message { // union solarxr_protocol.data_feed.DataFeedMessage ++ struct solarxr_data_feed_update data_feed_update; ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_data_feed_message_header_t; ++ ++struct solarxr_data_feed_message_header ++{ // table solarxr_protocol.data_feed.DataFeedMessageHeader ++ enum solarxr_data_feed_message_type message_type; ++ union solarxr_data_feed_message message; ++}; ++ ++struct solarxr_steamvr_trackers_setting ++{ // table solarxr_protocol.rpc.SteamVRTrackersSetting ++ bool waist; ++ bool chest; ++ bool left_foot; ++ bool right_foot; ++ bool left_knee; ++ bool right_knee; ++ bool left_elbow; ++ bool right_elbow; ++ bool left_hand; ++ bool right_hand; ++}; ++ ++struct solarxr_settings_response ++{ // table solarxr_protocol.rpc.SettingsResponse ++ struct solarxr_steamvr_trackers_setting steam_vr_trackers; ++}; ++ ++enum solarxr_rpc_message_type ++{ ++ SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_REQUEST = 6, ++ SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_RESPONSE = 7, ++}; ++ ++union solarxr_rpc_message { // union solarxr_protocol.rpc.RpcMessage ++ struct solarxr_settings_response settings_response; ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_rpc_message_header_t; ++ ++struct solarxr_rpc_message_header ++{ // table solarxr_protocol.rpc.RpcMessageHeader ++ enum solarxr_rpc_message_type message_type; ++ union solarxr_rpc_message message; ++}; ++ ++typedef struct ++{ ++ flatbuffers_uoffset_t offset; ++} solarxr_message_bundle_t; ++ ++struct solarxr_message_bundle ++{ // table solarxr_protocol.MessageBundle ++ flatbuffers_vector(solarxr_data_feed_message_header_t) ++ data_feed_msgs; // solarxr_protocol.data_feed.DataFeedMessageHeader[] ++ flatbuffers_vector(solarxr_rpc_message_header_t) rpc_msgs; // solarxr_protocol.rpc.RpcMessageHeader[] ++}; ++ ++bool ++read_solarxr_message_bundle(struct solarxr_message_bundle *out, ++ const uint8_t buffer[], ++ size_t buffer_len, ++ const solarxr_message_bundle_t *ref); ++bool ++read_solarxr_data_feed_message_header(struct solarxr_data_feed_message_header *out, ++ const uint8_t buffer[], ++ size_t buffer_len, ++ const solarxr_data_feed_message_header_t *ref); ++bool ++read_solarxr_rpc_message_header(struct solarxr_rpc_message_header *out, ++ const uint8_t buffer[], ++ size_t buffer_len, ++ const solarxr_rpc_message_header_t *ref); ++bool ++read_solarxr_device_data(struct solarxr_device_data *out, ++ const uint8_t buffer[], ++ size_t buffer_len, ++ const solarxr_device_data_t *ref); ++bool ++read_solarxr_tracker_data(struct solarxr_tracker_data *out, ++ const uint8_t buffer[], ++ size_t buffer_len, ++ const solarxr_tracker_data_t *ref); ++bool ++read_solarxr_bone(struct solarxr_bone *out, const uint8_t buffer[], size_t buffer_len, const solarxr_bone_t *ref); +diff --git a/src/xrt/drivers/solarxr/solarxr_device.c b/src/xrt/drivers/solarxr/solarxr_device.c +new file mode 100644 +index 0000000000..e0dfc2f75a +--- /dev/null ++++ b/src/xrt/drivers/solarxr/solarxr_device.c +@@ -0,0 +1,1114 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#include "solarxr_interface.h" ++#include "feeder.h" ++#include "protocol.h" ++ ++#include "math/m_api.h" ++#include "math/m_relation_history.h" ++#include "math/m_vec3.h" ++#include "os/os_time.h" ++#include "util/u_debug.h" ++#include "util/u_device.h" ++ ++#include "xrt/xrt_config_build.h" // TODO: drop `#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META` guards once !2206 is merged ++ ++#include ++#include ++#include ++#include ++ ++#define MAX_GENERIC_TRACKERS 32 ++ ++DEBUG_GET_ONCE_LOG_OPTION(solarxr_log, "SOLARXR_LOG", U_LOGGING_WARN) ++DEBUG_GET_ONCE_BOOL_OPTION(solarxr_raw_trackers, "SOLARXR_RAW_TRACKERS", false) ++DEBUG_GET_ONCE_NUM_OPTION(solarxr_sync_delay_ms, "SOLARXR_SYNC_DELAY_MS", 4) ++DEBUG_GET_ONCE_NUM_OPTION(solarxr_sync_timeout_ms, "SOLARXR_SYNC_TIMEOUT_MS", 50) ++ ++struct solarxr_device; ++struct solarxr_generic_tracker ++{ ++ struct xrt_device base; ++ struct m_relation_history *history; ++ enum solarxr_body_part role; ++ struct solarxr_device *parent; ++ struct solarxr_generic_tracker **weak_ref; ++}; ++ ++struct solarxr_device ++{ ++ struct xrt_device base; ++ struct feeder feeder; ++ struct os_thread thread; ++ struct ipc_socket socket; ++ _Atomic(int64_t) next_sync; ++ struct os_mutex mutex; ++ _Atomic(int64_t) timestamp; ++ _Atomic(uint64_t) enabled_bones; ++ static_assert(SOLARXR_BODY_PART_MAX_ENUM <= 64, "bitfield too small"); ++ struct solarxr_device_bone ++ { ++ struct xrt_pose pose; ++ float length; ++ } bones[SOLARXR_BODY_PART_MAX_ENUM]; ++ wchar_t tracker_ids[MAX_GENERIC_TRACKERS]; ++ struct solarxr_generic_tracker *trackers[MAX_GENERIC_TRACKERS]; ++ bool use_trackers; ++ uint32_t generation; ++ struct xrt_tracking_origin standalone_origin; ++}; ++ ++struct span ++{ ++ size_t length; ++ const uint8_t *data; ++}; ++ ++static void ++solarxr_device_destroy(struct xrt_device *xdev); ++static void ++solarxr_generic_tracker_destroy(struct xrt_device *xdev); ++ ++static inline struct solarxr_device * ++solarxr_device(struct xrt_device *const xdev) ++{ ++ if (xdev == NULL || xdev->destroy != solarxr_device_destroy) { ++ return NULL; ++ } ++ return (struct solarxr_device *)xdev; ++} ++ ++static inline struct solarxr_generic_tracker * ++solarxr_generic_tracker(struct xrt_device *const xdev) ++{ ++ if (xdev == NULL || xdev->destroy != solarxr_generic_tracker_destroy) { ++ return NULL; ++ } ++ return (struct solarxr_generic_tracker *)xdev; ++} ++ ++// returns an arbitrary unique value to identify trackers by ++static inline wchar_t ++solarxr_tracker_id_to_wchar(struct solarxr_tracker_id id) ++{ ++ if (!id.has_device_id) { ++ id.device_id = 0; ++ } ++ wchar_t out = 0; ++ static_assert(sizeof(id) <= sizeof(out), ""); ++ memcpy(&out, &id, sizeof(id)); ++ return le32toh(out); ++} ++ ++static void ++solarxr_device_sync(struct solarxr_device *const device) ++{ ++ const int64_t time = os_monotonic_get_ns(), next_sync = atomic_exchange(&device->next_sync, INT64_MAX); ++ if (time <= next_sync) { ++ atomic_store(&device->next_sync, next_sync); ++ return; ++ } ++ ++ struct poll_packet ++ { ++ uint32_t _root; ++ uint16_t _table_shared[3]; ++ struct ++ { // table MessageBundle ++ int32_t _table; ++ uint32_t data_feed_msgs; // vector* ++ } bundle; ++ struct ++ { // vector
++ uint32_t length; ++ uint32_t values[1]; // table* ++ } data_feed_msgs; ++ uint16_t _table_data_feed_msgs_0[4]; ++ struct ++ { // table DataFeedMessageHeader ++ int32_t _table; ++ uint32_t message; // table* ++ uint8_t message_type; // enum DataFeedMessage ++ uint8_t _pad[3]; ++ } data_feed_msgs_0; ++ struct ++ { // table PollDataFeed ++ int32_t _table; ++ uint32_t config; // table* ++ } message; ++ uint16_t _table_config[6]; ++ struct ++ { // table DataFeedConfig ++ int32_t _table; ++ uint32_t trackers_mask; // table* ++ bool bone_mask; ++ uint8_t _pad[3]; ++ } config; ++ struct ++ { // table DeviceDataMask ++ int32_t _table; ++ uint32_t tracker_data; // table* ++ } data_mask; ++ uint16_t _table_synthetic_trackers_mask[10]; ++ struct ++ { // table TrackerDataMask ++ int32_t _table; ++ bool rotation, position, raw_angular_velocity, linear_acceleration; ++ } synthetic_trackers_mask; ++ } const poll_packet = { ++ ._root = htole32(offsetof(struct poll_packet, bundle)), ++ ._table_shared = ++ { ++ htole16(sizeof(poll_packet._table_shared)), ++ htole16(8), ++ htole16(4), ++ }, ++ .bundle = ++ { ++ ._table = ++ htole32(offsetof(struct poll_packet, bundle) - offsetof(struct poll_packet, _table_shared)), ++ .data_feed_msgs = htole32(offsetof(struct poll_packet, data_feed_msgs) - ++ offsetof(struct poll_packet, bundle.data_feed_msgs)), ++ }, ++ .data_feed_msgs = ++ { ++ .length = htole32(ARRAY_SIZE(poll_packet.data_feed_msgs.values)), ++ .values = {htole32(offsetof(struct poll_packet, data_feed_msgs_0) - ++ offsetof(struct poll_packet, data_feed_msgs.values[0]))}, ++ }, ++ ._table_data_feed_msgs_0 = ++ { ++ htole16(sizeof(poll_packet._table_data_feed_msgs_0)), ++ htole16(sizeof(poll_packet.data_feed_msgs_0) - sizeof(poll_packet.data_feed_msgs_0._pad)), ++ htole16(offsetof(struct poll_packet, data_feed_msgs_0.message_type) - ++ offsetof(struct poll_packet, data_feed_msgs_0)), ++ htole16(offsetof(struct poll_packet, data_feed_msgs_0.message) - ++ offsetof(struct poll_packet, data_feed_msgs_0)), ++ }, ++ .data_feed_msgs_0 = ++ { ++ ._table = htole32(offsetof(struct poll_packet, data_feed_msgs_0) - ++ offsetof(struct poll_packet, _table_data_feed_msgs_0)), ++ .message = htole32(offsetof(struct poll_packet, message) - ++ offsetof(struct poll_packet, data_feed_msgs_0.message)), ++ .message_type = 1, // DataFeedMessage::PollDataFeed ++ }, ++ .message = ++ { ++ ._table = ++ htole32(offsetof(struct poll_packet, message) - offsetof(struct poll_packet, _table_shared)), ++ .config = ++ htole32(offsetof(struct poll_packet, config) - offsetof(struct poll_packet, message.config)), ++ }, ++ ._table_config = ++ { ++ htole16(sizeof(poll_packet._table_config)), ++ htole16(sizeof(poll_packet.config) - sizeof(poll_packet.config._pad)), ++ 0, ++ htole16( ++ (device->use_trackers && debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct poll_packet, config.trackers_mask) - offsetof(struct poll_packet, config))), ++ htole16( ++ (device->use_trackers && !debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct poll_packet, config.trackers_mask) - offsetof(struct poll_packet, config))), ++ htole16(offsetof(struct poll_packet, config.bone_mask) - offsetof(struct poll_packet, config)), ++ }, ++ .config = ++ { ++ ._table = ++ htole32(offsetof(struct poll_packet, config) - offsetof(struct poll_packet, _table_config)), ++ .trackers_mask = htole32((debug_get_bool_option_solarxr_raw_trackers() ++ ? offsetof(struct poll_packet, data_mask) ++ : offsetof(struct poll_packet, synthetic_trackers_mask)) - ++ offsetof(struct poll_packet, config.trackers_mask)), ++ .bone_mask = true, ++ }, ++ .data_mask = ++ { ++ ._table = ++ htole32(offsetof(struct poll_packet, data_mask) - offsetof(struct poll_packet, _table_shared)), ++ .tracker_data = htole32(offsetof(struct poll_packet, synthetic_trackers_mask) - ++ offsetof(struct poll_packet, data_mask.tracker_data)), ++ }, ++ ._table_synthetic_trackers_mask = ++ { ++ htole16(sizeof(poll_packet._table_synthetic_trackers_mask)), ++ htole16(sizeof(poll_packet.synthetic_trackers_mask)), ++ 0, ++ 0, ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.rotation) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.position) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.raw_angular_velocity) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ 0, ++ 0, ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.linear_acceleration) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ }, ++ .synthetic_trackers_mask = ++ { ++ ._table = htole32(offsetof(struct poll_packet, synthetic_trackers_mask) - ++ offsetof(struct poll_packet, _table_synthetic_trackers_mask)), ++ .rotation = true, ++ .position = true, ++ .raw_angular_velocity = true, ++ .linear_acceleration = true, ++ }, ++ }; ++ ++ feeder_send_feedback(&device->feeder, time); ++ ipc_socket_send(&device->socket, (const uint8_t *)&poll_packet, ++ device->use_trackers ? sizeof(poll_packet) : offsetof(struct poll_packet, data_mask)); ++ atomic_store(&device->next_sync, time + debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS); ++} ++ ++static xrt_result_t ++solarxr_device_update_inputs(struct xrt_device *const xdev) ++{ ++ struct solarxr_device *const device = solarxr_device(xdev); ++ assert(device != NULL); ++ const int64_t time = os_monotonic_get_ns(); ++ if (time - atomic_load(&device->feeder.last_send) > ++ debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS) { ++ // ensures SlimeVR continues to receive head positions even if no XR app is running ++ feeder_send_feedback(&device->feeder, time); ++ } ++ ++ for (uint32_t i = 0; i < device->base.input_count; ++i) { ++ device->base.inputs[i].timestamp = atomic_load(&device->timestamp); ++ } ++ return XRT_SUCCESS; ++} ++ ++static xrt_result_t ++solarxr_generic_tracker_update_inputs(struct xrt_device *const xdev) ++{ ++ struct solarxr_generic_tracker *const device = solarxr_generic_tracker(xdev); ++ assert(device != NULL); ++ struct solarxr_device *const parent = device->parent; ++ device->base.inputs[0].active = (atomic_load(&parent->enabled_bones) & (1llu << device->role)) != 0; ++ device->base.inputs[0].timestamp = atomic_load(&parent->timestamp); ++ return XRT_SUCCESS; ++} ++ ++static inline struct xrt_body_skeleton_joint_fb ++offset_joint(const struct xrt_body_skeleton_joint_fb parent, const int32_t name, const struct xrt_vec3 offset) ++{ ++ return (struct xrt_body_skeleton_joint_fb){ ++ .pose = ++ { ++ .orientation = parent.pose.orientation, ++ .position = m_vec3_add(parent.pose.position, offset), ++ }, ++ .joint = name, ++ .parent_joint = parent.joint, ++ }; ++} ++ ++// TODO: filter enabled bones ++static xrt_result_t ++solarxr_device_get_body_skeleton(struct xrt_device *const xdev, ++ const enum xrt_input_name body_tracking_type, ++ struct xrt_body_skeleton *const out_value) ++{ ++ struct xrt_body_skeleton_joint_fb *joints; ++ uint32_t joint_count; ++ int32_t none; ++ switch (body_tracking_type) { ++ case XRT_INPUT_FB_BODY_TRACKING: { ++ joints = out_value->body_skeleton_fb.joints; ++ joint_count = ARRAY_SIZE(out_value->body_skeleton_fb.joints); ++ none = XRT_BODY_JOINT_NONE_FB; ++ break; ++ } ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ case XRT_INPUT_META_FULL_BODY_TRACKING: { ++ joints = out_value->full_body_skeleton_meta.joints; ++ joint_count = ARRAY_SIZE(out_value->full_body_skeleton_meta.joints); ++ none = XRT_FULL_BODY_JOINT_NONE_META; ++ break; ++ } ++#endif ++ default: return XRT_ERROR_NOT_IMPLEMENTED; ++ } ++ ++ struct solarxr_device *const device = solarxr_device(xdev); ++ assert(device != NULL); ++ for (uint32_t i = 0; i < joint_count; ++i) { ++ joints[i] = (struct xrt_body_skeleton_joint_fb){XRT_POSE_IDENTITY, none, none}; ++ } ++ ++ // The standard doesn't describe the layout for these joints more specifically than being "a T-pose" ++ // clang-format off ++ joints[0] = (struct xrt_body_skeleton_joint_fb){XRT_POSE_IDENTITY, XRT_BODY_JOINT_HEAD_FB, XRT_BODY_JOINT_ROOT_FB}; ++ joints[1] = offset_joint(joints[0], XRT_BODY_JOINT_NECK_FB, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_NECK].length, 0.f}); ++ joints[2] = offset_joint(joints[1], XRT_BODY_JOINT_CHEST_FB, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_UPPER_CHEST].length, 0.f}); ++ joints[3] = offset_joint(joints[2], XRT_BODY_JOINT_SPINE_UPPER_FB, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_CHEST].length, 0.f}); ++ joints[4] = offset_joint(joints[3], XRT_BODY_JOINT_SPINE_LOWER_FB, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_WAIST].length, 0.f}); ++ joints[5] = offset_joint(joints[4], XRT_BODY_JOINT_HIPS_FB, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_HIP].length, 0.f}); ++ joints[6] = offset_joint(joints[1], XRT_BODY_JOINT_LEFT_SHOULDER_FB, (struct xrt_vec3){-device->bones[SOLARXR_BODY_PART_LEFT_SHOULDER].length, 0.f, 0.f}); ++ joints[7] = offset_joint(joints[1], XRT_BODY_JOINT_RIGHT_SHOULDER_FB, (struct xrt_vec3){device->bones[SOLARXR_BODY_PART_RIGHT_SHOULDER].length, 0.f, 0.f}); ++ joints[8] = offset_joint(joints[6], XRT_BODY_JOINT_LEFT_ARM_UPPER_FB, (struct xrt_vec3){-device->bones[SOLARXR_BODY_PART_LEFT_UPPER_ARM].length, 0.f, 0.f}); ++ joints[9] = offset_joint(joints[7], XRT_BODY_JOINT_RIGHT_ARM_UPPER_FB, (struct xrt_vec3){device->bones[SOLARXR_BODY_PART_RIGHT_UPPER_ARM].length, 0.f, 0.f}); ++ joints[10] = offset_joint(joints[8], XRT_BODY_JOINT_LEFT_ARM_LOWER_FB, (struct xrt_vec3){-device->bones[SOLARXR_BODY_PART_LEFT_LOWER_ARM].length, 0.f, 0.f}); ++ joints[11] = offset_joint(joints[9], XRT_BODY_JOINT_RIGHT_ARM_LOWER_FB, (struct xrt_vec3){device->bones[SOLARXR_BODY_PART_RIGHT_LOWER_ARM].length, 0.f, 0.f}); ++ joints[12] = offset_joint(joints[10], XRT_BODY_JOINT_LEFT_HAND_WRIST_FB, (struct xrt_vec3){-device->bones[SOLARXR_BODY_PART_LEFT_HAND].length, 0.f, 0.f}); ++ joints[13] = offset_joint(joints[11], XRT_BODY_JOINT_RIGHT_HAND_WRIST_FB, (struct xrt_vec3){device->bones[SOLARXR_BODY_PART_RIGHT_HAND].length, 0.f, 0.f}); ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ if (body_tracking_type != XRT_INPUT_META_FULL_BODY_TRACKING) { ++ return XRT_SUCCESS; ++ } ++ joints[14] = offset_joint(joints[5], XRT_FULL_BODY_JOINT_LEFT_UPPER_LEG_META, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_LEFT_UPPER_LEG].length, 0.f}); ++ joints[15] = offset_joint(joints[5], XRT_FULL_BODY_JOINT_RIGHT_UPPER_LEG_META, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_RIGHT_UPPER_LEG].length, 0.f}); ++ joints[16] = offset_joint(joints[14], XRT_FULL_BODY_JOINT_LEFT_LOWER_LEG_META, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_LEFT_LOWER_LEG].length, 0.f}); ++ joints[17] = offset_joint(joints[15], XRT_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_RIGHT_LOWER_LEG].length, 0.f}); ++ joints[18] = offset_joint(joints[16], XRT_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META, (struct xrt_vec3){0.f, 0.f, -device->bones[SOLARXR_BODY_PART_LEFT_FOOT].length}); ++ joints[19] = offset_joint(joints[17], XRT_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META, (struct xrt_vec3){0.f, 0.f, -device->bones[SOLARXR_BODY_PART_RIGHT_FOOT].length}); ++#endif ++ // clang-format on ++ return XRT_SUCCESS; ++} ++ ++// TODO: filter enabled bones ++static xrt_result_t ++solarxr_device_get_body_joints(struct xrt_device *const xdev, ++ const enum xrt_input_name body_tracking_type, ++ const int64_t desired_timestamp_ns, ++ struct xrt_body_joint_set *const out_value) ++{ ++ static const uint32_t jointMap[SOLARXR_BODY_PART_MAX_ENUM] = { ++ [SOLARXR_BODY_PART_HEAD] = XRT_BODY_JOINT_HEAD_FB, ++ [SOLARXR_BODY_PART_NECK] = XRT_BODY_JOINT_NECK_FB, ++ [SOLARXR_BODY_PART_CHEST] = XRT_BODY_JOINT_SPINE_UPPER_FB, ++ [SOLARXR_BODY_PART_WAIST] = XRT_BODY_JOINT_SPINE_LOWER_FB, ++ [SOLARXR_BODY_PART_HIP] = XRT_BODY_JOINT_HIPS_FB, ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ [SOLARXR_BODY_PART_LEFT_UPPER_LEG] = XRT_FULL_BODY_JOINT_LEFT_UPPER_LEG_META, ++ [SOLARXR_BODY_PART_RIGHT_UPPER_LEG] = XRT_FULL_BODY_JOINT_RIGHT_UPPER_LEG_META, ++ [SOLARXR_BODY_PART_LEFT_LOWER_LEG] = XRT_FULL_BODY_JOINT_LEFT_LOWER_LEG_META, ++ [SOLARXR_BODY_PART_RIGHT_LOWER_LEG] = XRT_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META, ++ [SOLARXR_BODY_PART_LEFT_FOOT] = XRT_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META, ++ [SOLARXR_BODY_PART_RIGHT_FOOT] = XRT_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META, ++#endif ++ [SOLARXR_BODY_PART_LEFT_LOWER_ARM] = XRT_BODY_JOINT_LEFT_ARM_LOWER_FB, ++ [SOLARXR_BODY_PART_RIGHT_LOWER_ARM] = XRT_BODY_JOINT_RIGHT_ARM_LOWER_FB, ++ [SOLARXR_BODY_PART_LEFT_UPPER_ARM] = XRT_BODY_JOINT_LEFT_ARM_UPPER_FB, ++ [SOLARXR_BODY_PART_RIGHT_UPPER_ARM] = XRT_BODY_JOINT_RIGHT_ARM_UPPER_FB, ++ [SOLARXR_BODY_PART_LEFT_HAND] = XRT_BODY_JOINT_LEFT_HAND_WRIST_FB, ++ [SOLARXR_BODY_PART_RIGHT_HAND] = XRT_BODY_JOINT_RIGHT_HAND_WRIST_FB, ++ [SOLARXR_BODY_PART_LEFT_SHOULDER] = XRT_BODY_JOINT_LEFT_SHOULDER_FB, ++ [SOLARXR_BODY_PART_RIGHT_SHOULDER] = XRT_BODY_JOINT_RIGHT_SHOULDER_FB, ++ [SOLARXR_BODY_PART_UPPER_CHEST] = XRT_BODY_JOINT_CHEST_FB, ++ // LEFT_HIP ++ // RIGHT_HIP ++ }; ++ struct xrt_body_joint_location_fb *joints; ++ uint32_t joint_count; ++ switch (body_tracking_type) { ++ case XRT_INPUT_FB_BODY_TRACKING: { ++ joints = out_value->body_joint_set_fb.joint_locations; ++ joint_count = ARRAY_SIZE(out_value->body_joint_set_fb.joint_locations); ++ break; ++ } ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ case XRT_INPUT_META_FULL_BODY_TRACKING: { ++ joints = out_value->full_body_joint_set_meta.joint_locations; ++ joint_count = ARRAY_SIZE(out_value->full_body_joint_set_meta.joint_locations); ++ break; ++ } ++#endif ++ default: return XRT_ERROR_NOT_IMPLEMENTED; ++ } ++ ++ struct solarxr_device *const device = solarxr_device(xdev); ++ assert(device != NULL); ++ solarxr_device_sync(device); ++ ++ os_mutex_lock(&device->mutex); ++ out_value->base_body_joint_set_meta.sample_time_ns = device->timestamp; ++ out_value->base_body_joint_set_meta.confidence = 1.f; // N/A ++ out_value->base_body_joint_set_meta.skeleton_changed_count = device->generation; ++ out_value->base_body_joint_set_meta.is_active = true; ++ for (uint32_t i = 0; i < joint_count; ++i) { ++ joints[i].relation = (struct xrt_space_relation)XRT_SPACE_RELATION_ZERO; ++ } ++ for (enum solarxr_body_part part = 0; part < ARRAY_SIZE(device->bones); ++part) { ++ const struct xrt_pose pose = device->bones[part].pose; ++ static_assert(ARRAY_SIZE(jointMap) == ARRAY_SIZE(device->bones), ""); ++ const uint32_t index = jointMap[part]; ++ if (index == 0 || index >= joint_count || ++ memcmp(&pose.orientation, &(struct xrt_quat){0}, sizeof(struct xrt_quat)) == 0) { ++ continue; ++ } ++ joints[index].relation = (struct xrt_space_relation){ ++ .relation_flags = XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | XRT_SPACE_RELATION_POSITION_VALID_BIT | ++ XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT | ++ XRT_SPACE_RELATION_POSITION_TRACKED_BIT, ++ .pose = pose, ++ }; ++ } ++ out_value->body_pose = (struct xrt_space_relation){ ++ .relation_flags = XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | XRT_SPACE_RELATION_POSITION_VALID_BIT | ++ XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT | XRT_SPACE_RELATION_POSITION_TRACKED_BIT, ++ .pose = XRT_POSE_IDENTITY, ++ }; ++ os_mutex_unlock(&device->mutex); ++ return XRT_SUCCESS; ++} ++ ++static void ++solarxr_device_handle_trackers(struct solarxr_device *const device, ++ const struct span buffer, ++ const solarxr_tracker_data_t trackers[const], ++ const uint32_t trackers_len) ++{ ++ for (uint32_t i = 0; i < trackers_len; ++i) { ++ struct solarxr_tracker_data data; ++ if (!read_solarxr_tracker_data(&data, buffer.data, buffer.length, &trackers[i])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_device_data() failed"); ++ continue; ++ } ++ // `wmemchr()` should be SIMD optimized, making it faster than a hash lookup in this case despite being ++ // O(n^2) ++ const wchar_t *const match = wmemchr(device->tracker_ids, solarxr_tracker_id_to_wchar(data.tracker_id), ++ ARRAY_SIZE(device->tracker_ids)); ++ if (match == NULL) { ++ continue; ++ } ++ struct solarxr_generic_tracker *const tracker = device->trackers[match - device->tracker_ids]; ++ if (tracker == NULL) { ++ continue; ++ } ++ struct xrt_space_relation relation = {.pose.orientation.w = 1}; ++ if (data.has_rotation) { ++ relation.relation_flags |= ++ XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT; ++ relation.pose.orientation = data.rotation; ++ } ++ if (data.has_position) { ++ relation.relation_flags |= ++ XRT_SPACE_RELATION_POSITION_VALID_BIT | XRT_SPACE_RELATION_POSITION_TRACKED_BIT; ++ relation.pose.position = data.position; ++ } ++ if (data.has_raw_angular_velocity) { ++ relation.relation_flags |= XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT; ++ relation.angular_velocity = data.raw_angular_velocity; ++ } ++ if (data.has_linear_acceleration) { ++ relation.relation_flags |= XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT; ++ relation.linear_velocity = data.linear_acceleration; ++ } ++ if (relation.relation_flags != 0) { ++ m_relation_history_push(tracker->history, &relation, device->socket.timestamp); ++ } ++ } ++} ++ ++static struct span ++ipc_socket_receive_blocking(struct ipc_socket *const socket) ++{ ++ do { ++ const uint32_t buffer_len = ipc_socket_receive(socket); ++ if (buffer_len != 0) { ++ return (struct span){buffer_len, socket->buffer}; ++ } ++ } while (ipc_socket_wait(socket)); ++ return (struct span){0}; ++} ++ ++static void * ++solarxr_network_thread(void *const ptr) ++{ ++ struct solarxr_device *const device = (struct solarxr_device *)ptr; ++ for (struct span buffer; (buffer = ipc_socket_receive_blocking(&device->socket)).length != 0;) { ++ struct solarxr_message_bundle bundle; ++ if (!read_solarxr_message_bundle(&bundle, buffer.data, buffer.length, ++ (const solarxr_message_bundle_t *)buffer.data)) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_message_bundle() failed"); ++ continue; ++ } ++ struct solarxr_steamvr_trackers_setting toggles; ++ bool toggles_changed = false; ++ for (uint32_t i = 0; i < bundle.rpc_msgs.length; ++i) { ++ struct solarxr_rpc_message_header header; ++ if (!read_solarxr_rpc_message_header(&header, buffer.data, buffer.length, ++ &bundle.rpc_msgs.data[i])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_rpc_message_header() failed"); ++ continue; ++ } ++ if (header.message_type != SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_RESPONSE) { ++ continue; ++ } ++ toggles = header.message.settings_response.steam_vr_trackers; ++ toggles_changed = true; ++ } ++ if (toggles_changed) { ++ // `SOLARXR_BODY_PART_HEAD` always disabled ++ uint64_t bones = 1llu << SOLARXR_BODY_PART_NECK; ++ bones |= (1llu << SOLARXR_BODY_PART_CHEST) * toggles.chest; ++ bones |= (1llu << SOLARXR_BODY_PART_WAIST) * toggles.waist; ++ bones |= (1llu << SOLARXR_BODY_PART_HIP) * toggles.waist; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_UPPER_LEG) * toggles.left_knee; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_UPPER_LEG) * toggles.right_knee; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_LOWER_LEG) * (toggles.left_knee && toggles.left_foot); ++ bones |= ++ (1llu << SOLARXR_BODY_PART_RIGHT_LOWER_LEG) * (toggles.right_knee && toggles.right_foot); ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_FOOT) * toggles.left_foot; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_FOOT) * toggles.right_foot; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_LOWER_ARM) * (toggles.left_elbow && toggles.left_hand); ++ bones |= ++ (1llu << SOLARXR_BODY_PART_RIGHT_LOWER_ARM) * (toggles.right_elbow && toggles.right_hand); ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_UPPER_ARM) * toggles.left_elbow; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_UPPER_ARM) * toggles.right_elbow; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_HAND) * toggles.left_hand; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_HAND) * toggles.right_hand; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_SHOULDER) * toggles.left_elbow; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_SHOULDER) * toggles.right_elbow; ++ bones |= (1llu << SOLARXR_BODY_PART_UPPER_CHEST) * toggles.chest; ++ bones |= (1llu << SOLARXR_BODY_PART_LEFT_HIP) * toggles.waist; ++ bones |= (1llu << SOLARXR_BODY_PART_RIGHT_HIP) * toggles.waist; ++ bones |= ((2llu << SOLARXR_BODY_PART_LEFT_LITTLE_DISTAL) - ++ (1llu << SOLARXR_BODY_PART_LEFT_THUMB_PROXIMAL)) * ++ toggles.left_hand; ++ bones |= ((2llu << SOLARXR_BODY_PART_RIGHT_LITTLE_DISTAL) - ++ (1llu << SOLARXR_BODY_PART_RIGHT_THUMB_PROXIMAL)) * ++ toggles.right_hand; ++ atomic_store(&device->enabled_bones, bones); ++ } ++ if (bundle.data_feed_msgs.length == 0) { ++ continue; ++ } ++#if 0 // for latency testing ++ U_LOG_IFL_W(device->socket.log_level, "%.3fus", ((int64_t)os_monotonic_get_ns() - (atomic_load(&device->next_sync) - debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS)) / 1000.); ++#endif ++ atomic_store(&device->next_sync, ++ device->timestamp + debug_get_num_option_solarxr_sync_delay_ms() * U_TIME_1MS_IN_NS); ++ os_mutex_lock(&device->mutex); ++ flatbuffers_vector(solarxr_bone_t) bones = {0}; ++ for (uint32_t i = 0; i < bundle.data_feed_msgs.length; ++i) { ++ struct solarxr_data_feed_message_header header; ++ if (!read_solarxr_data_feed_message_header(&header, buffer.data, buffer.length, ++ &bundle.data_feed_msgs.data[0])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_data_feed_message_header() failed"); ++ continue; ++ } ++ if (header.message_type != SOLARXR_DATA_FEED_MESSAGE_DATA_FEED_UPDATE) { ++ continue; ++ } ++ if (debug_get_bool_option_solarxr_raw_trackers()) { ++ for (uint32_t j = 0; j < header.message.data_feed_update.devices.length; ++j) { ++ struct solarxr_device_data device_data; ++ if (!read_solarxr_device_data( ++ &device_data, buffer.data, buffer.length, ++ &header.message.data_feed_update.devices.data[j])) { ++ U_LOG_IFL_W(device->socket.log_level, ++ "read_solarxr_device_data() failed"); ++ continue; ++ } ++ solarxr_device_handle_trackers(device, buffer, device_data.trackers.data, ++ device_data.trackers.length); ++ } ++ } else { ++ solarxr_device_handle_trackers( ++ device, buffer, header.message.data_feed_update.synthetic_trackers.data, ++ header.message.data_feed_update.synthetic_trackers.length); ++ } ++ if (header.message.data_feed_update.bones.length != 0) { ++ bones.length = header.message.data_feed_update.bones.length; ++ bones.data = header.message.data_feed_update.bones.data; ++ } ++ } ++ if (bones.length != 0) { ++ atomic_store(&device->timestamp, device->socket.timestamp); ++ struct solarxr_device_bone newBones[ARRAY_SIZE(device->bones)] = {0}; ++ for (size_t i = 0; i < bones.length; ++i) { ++ struct solarxr_bone bone; ++ if (!read_solarxr_bone(&bone, buffer.data, buffer.length, &bones.data[i])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_bone() failed"); ++ continue; ++ } ++ if (bone.body_part >= ARRAY_SIZE(device->bones)) { ++ static bool _once = false; ++ if (!_once) { ++ _once = true; ++ U_LOG_IFL_W(device->socket.log_level, "Unexpected SolarXR BodyPart %u", ++ (unsigned)bone.body_part); ++ } ++ continue; ++ } ++ newBones[bone.body_part].pose = (struct xrt_pose){ ++ .orientation = bone.rotation_g, ++ .position = bone.head_position_g, ++ }; ++ newBones[bone.body_part].length = bone.bone_length; ++ } ++ for (uint32_t i = 0; i < ARRAY_SIZE(device->bones); ++i) { ++ if (memcmp(&newBones[i].length, &device->bones[i].length, sizeof(newBones[i].length)) != ++ 0) { ++ ++device->generation; ++ break; ++ } ++ } ++ memcpy(device->bones, newBones, sizeof(device->bones)); ++ } ++ os_mutex_unlock(&device->mutex); ++ } ++ return NULL; ++} ++ ++static void ++solarxr_device_destroy(struct xrt_device *xdev) ++{ ++ struct solarxr_device *const device = solarxr_device(xdev); ++ assert(device != NULL); ++ feeder_destroy(&device->feeder); ++ ipc_socket_destroy(&device->socket); ++ if (!pthread_equal(device->thread.thread, pthread_self())) { ++ os_thread_join(&device->thread); ++ os_thread_destroy(&device->thread); ++ } ++ for (uint32_t i = 0; i < ARRAY_SIZE(device->trackers); ++i) { ++ if (device->trackers[i] == NULL) { ++ continue; ++ } ++ device->trackers[i]->weak_ref = NULL; ++ device->trackers[i]->parent = NULL; ++ } ++ os_mutex_destroy(&device->mutex); ++ u_device_free(&device->base); ++} ++ ++static xrt_result_t ++solarxr_generic_tracker_get_tracked_pose(struct xrt_device *const xdev, ++ const enum xrt_input_name name, ++ const int64_t at_timestamp_ns, ++ struct xrt_space_relation *const out_relation) ++{ ++ struct solarxr_generic_tracker *const device = solarxr_generic_tracker(xdev); ++ assert(device != NULL); ++ struct solarxr_device *const parent = device->parent; ++ solarxr_device_sync(parent); ++ if ((atomic_load(&parent->enabled_bones) & (1llu << device->role)) == 0) { ++ *out_relation = (struct xrt_space_relation){0}; ++ return XRT_ERROR_INPUT_UNSUPPORTED; // TODO: adding/removing devices at runtime ++ } ++ m_relation_history_get(device->history, at_timestamp_ns, out_relation); ++ return XRT_SUCCESS; ++} ++ ++static void ++solarxr_generic_tracker_destroy(struct xrt_device *const xdev) ++{ ++ struct solarxr_generic_tracker *const device = solarxr_generic_tracker(xdev); ++ assert(device != NULL); ++ if (device->weak_ref != NULL) { ++ os_mutex_lock(&device->parent->mutex); ++ *device->weak_ref = NULL; ++ os_mutex_unlock(&device->parent->mutex); ++ } ++ m_relation_history_destroy(&device->history); ++ u_device_free(&device->base); ++} ++ ++uint32_t ++solarxr_device_create_xdevs(struct xrt_tracking_origin *const tracking_origin, ++ struct xrt_device *out_xdevs[const], ++ uint32_t out_xdevs_cap) ++{ ++ if (out_xdevs_cap == 0) { ++ return 0; ++ } ++ if (out_xdevs_cap - 1 > MAX_GENERIC_TRACKERS) { ++ out_xdevs_cap = 1 + MAX_GENERIC_TRACKERS; ++ } ++ ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ struct solarxr_device *const device = U_DEVICE_ALLOCATE(struct solarxr_device, U_DEVICE_ALLOC_NO_FLAGS, 2, 0); ++#else ++ struct solarxr_device *const device = U_DEVICE_ALLOCATE(struct solarxr_device, U_DEVICE_ALLOC_NO_FLAGS, 1, 0); ++#endif ++ device->base.name = XRT_DEVICE_FB_BODY_TRACKING; ++ device->base.device_type = XRT_DEVICE_TYPE_BODY_TRACKER; ++ strncpy(device->base.str, "SolarXR IPC Connection", sizeof(device->base.str) - 1); ++ device->base.tracking_origin = tracking_origin; ++ if (device->base.tracking_origin == NULL) { ++ device->base.tracking_origin = &device->standalone_origin; ++ device->standalone_origin = (struct xrt_tracking_origin){ ++ .name = "SolarXR Bridge", ++ .type = XRT_TRACKING_TYPE_OTHER, ++ .initial_offset = XRT_POSE_IDENTITY, ++ }; ++ } ++ device->base.body_tracking_supported = true; ++ device->base.update_inputs = solarxr_device_update_inputs; ++ device->base.get_body_skeleton = solarxr_device_get_body_skeleton; ++ device->base.get_body_joints = solarxr_device_get_body_joints; ++ device->base.destroy = solarxr_device_destroy; ++ device->base.inputs[0].name = XRT_INPUT_FB_BODY_TRACKING; ++#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META ++ device->base.inputs[1].name = XRT_INPUT_META_FULL_BODY_TRACKING; ++#endif ++ device->thread.thread = pthread_self(); ++ const bool use_trackers = (out_xdevs_cap >= 2); ++ device->use_trackers = use_trackers; ++ ipc_socket_init(&device->socket, debug_get_log_option_solarxr_log()); ++ memset(device->tracker_ids, 0xff, sizeof(device->tracker_ids)); ++ ++ // `solarxr_device_destroy()` asserts unless both have attempted initialization ++ if (((int)!feeder_init(&device->feeder, debug_get_log_option_solarxr_log()) | os_mutex_init(&device->mutex)) != ++ 0) { ++ goto fail; ++ } ++ ++ if (!ipc_socket_connect(&device->socket, "SlimeVRRpc", "slimevr/SlimeVRRpc", device->base.serial, ++ sizeof(device->base.serial))) { ++ goto fail; ++ } ++ ++ struct request_packet ++ { ++ uint32_t _root; ++ uint16_t _table_bundle[4]; ++ struct ++ { // table MessageBundle ++ int32_t _table; ++ uint32_t data_feed_msgs; // vector* ++ uint32_t rpc_msgs; // vector* ++ } bundle; ++ struct ++ { // vector
++ uint32_t length; ++ uint32_t values[1]; // table* ++ } rpc_msgs; ++ uint16_t _table_rpc_msgs_0[5]; ++ struct ++ { // table RpcMessageHeader ++ int32_t _table; ++ uint32_t message; // table* ++ uint8_t message_type; // enum RpcMessage ++ uint8_t _pad[3]; ++ } rpc_msgs_0; ++ uint16_t _table_request[2]; ++ struct ++ { // table SettingsRequest ++ int32_t _table; ++ } request; ++ struct ++ { // vector
++ uint32_t length; ++ uint32_t values[1]; // table* ++ } data_feed_msgs; ++ uint16_t _table_data_feed_msgs_0[4]; ++ struct ++ { // table DataFeedMessageHeader ++ int32_t _table; ++ uint32_t message; // table* ++ uint8_t message_type; // enum DataFeedMessage ++ uint8_t _pad[3]; ++ } data_feed_msgs_0; ++ uint16_t _table_shared[3]; ++ struct ++ { // table PollDataFeed ++ int32_t _table; ++ uint32_t config; // table* ++ } message; ++ uint16_t _table_config[6]; ++ struct ++ { // table DataFeedConfig ++ int32_t _table; ++ uint32_t trackers_mask; // table* ++ bool bone_mask; ++ uint8_t _pad[3]; ++ } config; ++ struct ++ { // table DeviceDataMask ++ int32_t _table; ++ uint32_t tracker_data; // table* ++ } data_mask; ++ uint16_t _table_synthetic_trackers_mask[3]; ++ struct ++ { // table TrackerDataMask ++ int32_t _table; ++ bool info; ++ } synthetic_trackers_mask; ++ } const request_packet = { ++ ._root = htole32(offsetof(struct request_packet, bundle)), ++ ._table_bundle = ++ { ++ htole16(sizeof(request_packet._table_bundle)), ++ htole16(sizeof(request_packet.bundle)), ++ htole16(use_trackers * (offsetof(struct request_packet, bundle.data_feed_msgs) - ++ offsetof(struct request_packet, bundle))), ++ htole16(offsetof(struct request_packet, bundle.rpc_msgs) - offsetof(struct request_packet, bundle)), ++ }, ++ .bundle = ++ { ++ ._table = htole32(offsetof(struct request_packet, bundle) - ++ offsetof(struct request_packet, _table_bundle)), ++ .data_feed_msgs = htole32(use_trackers * (offsetof(struct request_packet, data_feed_msgs) - ++ offsetof(struct request_packet, bundle.data_feed_msgs))), ++ .rpc_msgs = htole32(offsetof(struct request_packet, rpc_msgs) - ++ offsetof(struct request_packet, bundle.rpc_msgs)), ++ }, ++ .rpc_msgs = ++ { ++ .length = htole32(ARRAY_SIZE(request_packet.rpc_msgs.values)), ++ .values = {htole32(offsetof(struct request_packet, rpc_msgs_0) - ++ offsetof(struct request_packet, rpc_msgs.values[0]))}, ++ }, ++ ._table_rpc_msgs_0 = ++ { ++ htole16(sizeof(request_packet._table_rpc_msgs_0)), ++ htole16(sizeof(request_packet.rpc_msgs_0) - sizeof(request_packet.rpc_msgs_0._pad)), ++ 0, ++ htole16(offsetof(struct request_packet, rpc_msgs_0.message_type) - ++ offsetof(struct request_packet, rpc_msgs_0)), ++ htole16(offsetof(struct request_packet, rpc_msgs_0.message) - ++ offsetof(struct request_packet, rpc_msgs_0)), ++ }, ++ .rpc_msgs_0 = ++ { ++ ._table = htole32(offsetof(struct request_packet, rpc_msgs_0) - ++ offsetof(struct request_packet, _table_rpc_msgs_0)), ++ .message = htole32(offsetof(struct request_packet, request) - ++ offsetof(struct request_packet, rpc_msgs_0.message)), ++ .message_type = SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_REQUEST, ++ }, ++ ._table_request = ++ { ++ htole16(sizeof(request_packet._table_request)), ++ htole16(sizeof(request_packet.request)), ++ }, ++ .request = ++ { ++ ._table = htole32(offsetof(struct request_packet, request) - ++ offsetof(struct request_packet, _table_request)), ++ }, ++ .data_feed_msgs = ++ { ++ .length = htole32(ARRAY_SIZE(request_packet.data_feed_msgs.values)), ++ .values = {htole32(offsetof(struct request_packet, data_feed_msgs_0) - ++ offsetof(struct request_packet, data_feed_msgs.values[0]))}, ++ }, ++ ._table_data_feed_msgs_0 = ++ { ++ htole16(sizeof(request_packet._table_data_feed_msgs_0)), ++ htole16(sizeof(request_packet.data_feed_msgs_0) - sizeof(request_packet.data_feed_msgs_0._pad)), ++ htole16(offsetof(struct request_packet, data_feed_msgs_0.message_type) - ++ offsetof(struct request_packet, data_feed_msgs_0)), ++ htole16(offsetof(struct request_packet, data_feed_msgs_0.message) - ++ offsetof(struct request_packet, data_feed_msgs_0)), ++ }, ++ .data_feed_msgs_0 = ++ { ++ ._table = htole32(offsetof(struct request_packet, data_feed_msgs_0) - ++ offsetof(struct request_packet, _table_data_feed_msgs_0)), ++ .message = htole32(offsetof(struct request_packet, message) - ++ offsetof(struct request_packet, data_feed_msgs_0.message)), ++ .message_type = SOLARXR_DATA_FEED_MESSAGE_POLL_DATA_FEED, ++ }, ++ ._table_shared = ++ { ++ htole16(sizeof(request_packet._table_shared)), ++ htole16(8), ++ htole16(4), ++ }, ++ .message = ++ { ++ ._table = htole32(offsetof(struct request_packet, message) - ++ offsetof(struct request_packet, _table_shared)), ++ .config = htole32(offsetof(struct request_packet, config) - ++ offsetof(struct request_packet, message.config)), ++ }, ++ ._table_config = ++ { ++ htole16(sizeof(request_packet._table_config)), ++ htole16(sizeof(request_packet.config) - sizeof(request_packet.config._pad)), ++ 0, ++ htole16((device->use_trackers && debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct request_packet, config.trackers_mask) - ++ offsetof(struct request_packet, config))), ++ htole16((device->use_trackers && !debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct request_packet, config.trackers_mask) - ++ offsetof(struct request_packet, config))), ++ htole16(offsetof(struct request_packet, config.bone_mask) - ++ offsetof(struct request_packet, config)), ++ }, ++ .config = ++ { ++ ._table = htole32(offsetof(struct request_packet, config) - ++ offsetof(struct request_packet, _table_config)), ++ .trackers_mask = htole32((debug_get_bool_option_solarxr_raw_trackers() ++ ? offsetof(struct request_packet, data_mask) ++ : offsetof(struct request_packet, synthetic_trackers_mask)) - ++ offsetof(struct request_packet, config.trackers_mask)), ++ .bone_mask = true, ++ }, ++ .data_mask = ++ { ++ ._table = htole32(offsetof(struct request_packet, data_mask) - ++ offsetof(struct request_packet, _table_shared)), ++ .tracker_data = htole32(offsetof(struct request_packet, synthetic_trackers_mask) - ++ offsetof(struct request_packet, data_mask.tracker_data)), ++ }, ++ ._table_synthetic_trackers_mask = ++ { ++ htole16(sizeof(request_packet._table_synthetic_trackers_mask)), ++ htole16(sizeof(request_packet.synthetic_trackers_mask)), ++ htole16(offsetof(struct request_packet, synthetic_trackers_mask.info) - ++ offsetof(struct request_packet, synthetic_trackers_mask)), ++ }, ++ .synthetic_trackers_mask = ++ { ++ ._table = htole32(offsetof(struct request_packet, synthetic_trackers_mask) - ++ offsetof(struct request_packet, _table_synthetic_trackers_mask)), ++ .info = true, ++ }, ++ }; ++ ++ if (!ipc_socket_send(&device->socket, (const uint8_t *)&request_packet, ++ use_trackers ? sizeof(request_packet) : offsetof(struct request_packet, data_feed_msgs))) { ++ U_LOG_IFL_E(device->socket.log_level, "ipc_socket_send() failed"); ++ goto fail; ++ } ++ ++ if (use_trackers) { ++ const struct span buffer = ipc_socket_receive_blocking(&device->socket); ++ if (buffer.length == 0) { ++ U_LOG_IFL_E(device->socket.log_level, "ipc_socket_receive() failed"); ++ goto fail; ++ } ++ struct solarxr_message_bundle bundle; ++ if (!read_solarxr_message_bundle(&bundle, buffer.data, buffer.length, ++ (const solarxr_message_bundle_t *)buffer.data)) { ++ U_LOG_IFL_E(device->socket.log_level, "read_solarxr_message_bundle() failed"); ++ goto fail; ++ } ++ if (bundle.data_feed_msgs.length != 1) { ++ U_LOG_IFL_E(device->socket.log_level, "Unexpected data feed count"); ++ goto fail; ++ } ++ struct solarxr_data_feed_message_header header; ++ if (!read_solarxr_data_feed_message_header(&header, buffer.data, buffer.length, ++ &bundle.data_feed_msgs.data[0])) { ++ U_LOG_IFL_E(device->socket.log_level, "read_solarxr_data_feed_message_header() failed"); ++ goto fail; ++ } ++ if (header.message_type != SOLARXR_DATA_FEED_MESSAGE_DATA_FEED_UPDATE) { ++ U_LOG_IFL_E(device->socket.log_level, "Unexpected data feed message type"); ++ goto fail; ++ } ++ uint32_t tracker_descs_len = 0; ++ const solarxr_tracker_data_t *tracker_descs[ARRAY_SIZE(device->trackers)]; ++ if (debug_get_bool_option_solarxr_raw_trackers()) { ++ for (uint32_t i = 0; i < header.message.data_feed_update.devices.length; ++i) { ++ struct solarxr_device_data device_data; ++ if (!read_solarxr_device_data(&device_data, buffer.data, buffer.length, ++ &header.message.data_feed_update.devices.data[i])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_device_data() failed"); ++ continue; ++ } ++ uint32_t length = device_data.trackers.length; ++ if (length >= ARRAY_SIZE(tracker_descs) - tracker_descs_len) { ++ length = ARRAY_SIZE(tracker_descs) - tracker_descs_len; ++ header.message.data_feed_update.devices.length = i; // early exit ++ } ++ for (uint32_t j = 0; j < length; ++j) { ++ tracker_descs[tracker_descs_len++] = &device_data.trackers.data[j]; ++ } ++ } ++ } else { ++ tracker_descs_len = ++ MIN(header.message.data_feed_update.synthetic_trackers.length, ARRAY_SIZE(tracker_descs)); ++ for (uint32_t i = 0; i < tracker_descs_len; ++i) { ++ tracker_descs[i] = &header.message.data_feed_update.synthetic_trackers.data[i]; ++ } ++ } ++ if (tracker_descs_len > out_xdevs_cap - 1) { ++ tracker_descs_len = out_xdevs_cap - 1; ++ } ++ for (uint32_t i = 0; i < tracker_descs_len; ++i) { ++ struct solarxr_tracker_data data; ++ if (!read_solarxr_tracker_data(&data, buffer.data, buffer.length, tracker_descs[i])) { ++ U_LOG_IFL_W(device->socket.log_level, "read_solarxr_device_data() failed"); ++ continue; ++ } ++ const wchar_t id = solarxr_tracker_id_to_wchar(data.tracker_id); ++ ++ struct solarxr_generic_tracker *const tracker = ++ U_DEVICE_ALLOCATE(struct solarxr_generic_tracker, U_DEVICE_ALLOC_NO_FLAGS, 1, 0); ++ tracker->base.name = XRT_DEVICE_VIVE_TRACKER; // TODO: use different name here? ++ tracker->base.device_type = XRT_DEVICE_TYPE_GENERIC_TRACKER; ++ snprintf(tracker->base.str, sizeof(tracker->base.str), "SolarXR Tracker %06x", id); ++ snprintf(tracker->base.serial, sizeof(tracker->base.serial), "SOLARXR-%06x", id); ++ tracker->base.tracking_origin = device->base.tracking_origin; ++ tracker->base.orientation_tracking_supported = true; ++ tracker->base.position_tracking_supported = true; ++ tracker->base.update_inputs = solarxr_generic_tracker_update_inputs; ++ tracker->base.get_tracked_pose = solarxr_generic_tracker_get_tracked_pose; ++ tracker->base.destroy = solarxr_generic_tracker_destroy; ++ tracker->base.inputs[0].name = XRT_INPUT_GENERIC_TRACKER_POSE; ++ m_relation_history_create(&tracker->history); ++ tracker->role = SOLARXR_BODY_PART_NONE; ++ tracker->parent = device; ++ tracker->weak_ref = &device->trackers[i]; ++ device->trackers[i] = tracker; ++ device->tracker_ids[i] = id; ++ ++ if (!data.has_info) { ++ continue; ++ } ++ if (data.info.body_part < ARRAY_SIZE(device->bones)) { ++ tracker->role = data.info.body_part; ++ } ++ if (data.info.display_name.length != 0) { ++ snprintf(tracker->base.str, sizeof(tracker->base.str), "SolarXR Tracker \"%.*s\"", ++ (unsigned)data.info.display_name.length, data.info.display_name.data); ++ } ++ } ++ } ++ if (os_thread_start(&device->thread, solarxr_network_thread, device) != 0) { ++ U_LOG_IFL_E(device->socket.log_level, "pthread_create() failed"); ++ for (uint32_t i = 0; i < ARRAY_SIZE(device->trackers); ++i) { ++ if (device->trackers[i] != NULL) { ++ solarxr_generic_tracker_destroy(&device->trackers[i]->base); ++ device->trackers[i] = NULL; ++ } ++ } ++ goto fail; ++ } ++ // early sync to initialize bone lengths needed by `solarxr_device_get_body_skeleton()` ++ solarxr_device_sync(device); ++ ++ uint32_t trackerCount = 0; ++ out_xdevs[trackerCount++] = &device->base; ++ for (uint32_t i = 0; i < ARRAY_SIZE(device->trackers); ++i) { ++ if (device->trackers[i] == NULL) { ++ continue; ++ } ++ assert(trackerCount < out_xdevs_cap); ++ out_xdevs[trackerCount++] = &device->trackers[i]->base; ++ } ++ return trackerCount; ++fail: ++ solarxr_device_destroy(&device->base); ++ return 0; ++} ++ ++static bool ++filter_feeder_device(struct xrt_device *const device) ++{ ++ return solarxr_generic_tracker(device) == NULL; ++} ++ ++bool ++solarxr_device_set_feeder_devices(struct xrt_device *const device, ++ struct xrt_device *const xdevs[const], ++ const uint32_t xdevs_len) ++{ ++ struct solarxr_device *const solarxr = solarxr_device(device); ++ return (solarxr != NULL) ? feeder_set_devices(&solarxr->feeder, xdevs, xdevs_len, filter_feeder_device) : false; ++} +diff --git a/src/xrt/drivers/solarxr/solarxr_interface.h b/src/xrt/drivers/solarxr/solarxr_interface.h +new file mode 100644 +index 0000000000..e5f029992f +--- /dev/null ++++ b/src/xrt/drivers/solarxr/solarxr_interface.h +@@ -0,0 +1,40 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++/*! ++ * @file ++ * @brief SolarXR protocol bridge device ++ * @ingroup drv_solarxr ++ */ ++ ++#pragma once ++ ++#include ++#include ++#include ++struct xrt_device; ++struct xrt_tracking_origin; ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++uint32_t ++solarxr_device_create_xdevs(struct xrt_tracking_origin *tracking_origin, ++ struct xrt_device *out_xdevs[], ++ uint32_t out_xdevs_cap); ++ ++static inline struct xrt_device * ++solarxr_device_create(struct xrt_tracking_origin *const tracking_origin) ++{ ++ struct xrt_device *out = NULL; ++ solarxr_device_create_xdevs(tracking_origin, &out, 1); ++ return out; ++} ++ ++bool ++solarxr_device_set_feeder_devices(struct xrt_device *solarxr, struct xrt_device *const xdevs[], uint32_t xdevs_len); ++ ++ ++#ifdef __cplusplus ++} ++#endif +diff --git a/src/xrt/targets/common/CMakeLists.txt b/src/xrt/targets/common/CMakeLists.txt +index e2b9ba79d1..1fbf5f436f 100644 +--- a/src/xrt/targets/common/CMakeLists.txt ++++ b/src/xrt/targets/common/CMakeLists.txt +@@ -201,6 +201,10 @@ if(XRT_BUILD_DRIVER_SIMULAVR) + target_link_libraries(target_lists PRIVATE drv_svr) + endif() + ++if(XRT_BUILD_DRIVER_SOLARXR) ++ target_link_libraries(target_lists PRIVATE drv_solarxr) ++endif() ++ + #### + # Instance + # +-- +GitLab + diff --git a/patches/monado/0099-t-common-Load-SolarXR-driver.patch b/patches/monado/0099-t-common-Load-SolarXR-driver.patch new file mode 100644 index 00000000..c85a04ff --- /dev/null +++ b/patches/monado/0099-t-common-Load-SolarXR-driver.patch @@ -0,0 +1,292 @@ +From 7114d99942608a2f02d45d64d8eac3e1c2ea739c Mon Sep 17 00:00:00 2001 +From: rcelyte +Date: Fri, 23 Aug 2024 20:54:53 +0000 +Subject: [PATCH] t/common: Load SolarXR driver + +--- + src/xrt/drivers/qwerty/qwerty_device.c | 4 +++ + .../common/target_builder_lighthouse.c | 25 +++++++++++++++++ + .../targets/common/target_builder_qwerty.c | 25 +++++++++++++++++ + .../targets/common/target_builder_rift_s.c | 26 ++++++++++++++++++ + .../targets/common/target_builder_steamvr.c | 27 +++++++++++++++++++ + src/xrt/targets/common/target_builder_wmr.c | 25 +++++++++++++++++ + 6 files changed, 132 insertions(+) + +diff --git a/src/xrt/drivers/qwerty/qwerty_device.c b/src/xrt/drivers/qwerty/qwerty_device.c +index 8841413efd..127644bc8b 100644 +--- a/src/xrt/drivers/qwerty/qwerty_device.c ++++ b/src/xrt/drivers/qwerty/qwerty_device.c +@@ -315,6 +315,8 @@ qwerty_hmd_create(void) + + xd->inputs[0].name = XRT_INPUT_GENERIC_HEAD_POSE; + ++ xd->orientation_tracking_supported = true; ++ xd->position_tracking_supported = true; + xd->update_inputs = u_device_noop_update_inputs; + xd->get_tracked_pose = qwerty_get_tracked_pose; + xd->get_view_poses = u_device_get_view_poses; +@@ -367,6 +369,8 @@ qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd) + xd->binding_profiles = binding_profiles; + xd->binding_profile_count = ARRAY_SIZE(binding_profiles); + ++ xd->orientation_tracking_supported = true; ++ xd->position_tracking_supported = true; + xd->update_inputs = qwerty_update_inputs; + xd->get_tracked_pose = qwerty_get_tracked_pose; + xd->set_output = qwerty_set_output; +diff --git a/src/xrt/targets/common/target_builder_lighthouse.c b/src/xrt/targets/common/target_builder_lighthouse.c +index 2386586be3..b8cbafdbed 100644 +--- a/src/xrt/targets/common/target_builder_lighthouse.c ++++ b/src/xrt/targets/common/target_builder_lighthouse.c +@@ -58,6 +58,10 @@ + #include "opengloves/opengloves_interface.h" + #endif + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++#include "solarxr/solarxr_interface.h" ++#endif ++ + #if defined(XRT_BUILD_DRIVER_SURVIVE) + #define DEFAULT_DRIVER "survive" + #else +@@ -509,6 +513,16 @@ try_add_opengloves(struct xrt_device *left, + #endif + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++static void ++destroy_system_devices_solarxr(struct xrt_system_devices *xsysd) ++{ ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, NULL, 0); ++ u_system_devices_close(xsysd); ++ free(xsysd); ++} ++#endif ++ + static xrt_result_t + lighthouse_open_system_impl(struct xrt_builder *xb, + cJSON *config, +@@ -736,6 +750,17 @@ end_valve_index: + try_add_opengloves(left, right, &left_ht, &right_ht); + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++ const uint32_t count = solarxr_device_create_xdevs(head->tracking_origin, &xsysd->xdevs[xsysd->xdev_count], ++ ARRAY_SIZE(xsysd->xdevs) - xsysd->xdev_count); ++ if (count != 0) { ++ xsysd->static_roles.body = xsysd->xdevs[xsysd->xdev_count]; ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, xsysd->xdevs, xsysd->xdev_count); ++ xsysd->destroy = destroy_system_devices_solarxr; ++ } ++ xsysd->xdev_count += count; ++#endif ++ + // Assign to role(s). + ubrh->head = head; + ubrh->left = left; +diff --git a/src/xrt/targets/common/target_builder_qwerty.c b/src/xrt/targets/common/target_builder_qwerty.c +index 2c66ad3038..5a5059ee18 100644 +--- a/src/xrt/targets/common/target_builder_qwerty.c ++++ b/src/xrt/targets/common/target_builder_qwerty.c +@@ -18,6 +18,10 @@ + + #include "qwerty/qwerty_interface.h" + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++#include "solarxr/solarxr_interface.h" ++#endif ++ + #include + + +@@ -67,6 +71,16 @@ qwerty_estimate_system(struct xrt_builder *xb, + return XRT_SUCCESS; + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++static void ++destroy_system_devices_solarxr(struct xrt_system_devices *xsysd) ++{ ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, NULL, 0); ++ u_system_devices_close(xsysd); ++ free(xsysd); ++} ++#endif ++ + static xrt_result_t + qwerty_open_system_impl(struct xrt_builder *xb, + cJSON *config, +@@ -100,6 +114,17 @@ qwerty_open_system_impl(struct xrt_builder *xb, + ubrh->left = left; + ubrh->right = right; + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++ const uint32_t count = solarxr_device_create_xdevs(head->tracking_origin, &xsysd->xdevs[xsysd->xdev_count], ++ ARRAY_SIZE(xsysd->xdevs) - xsysd->xdev_count); ++ if (count != 0) { ++ xsysd->static_roles.body = xsysd->xdevs[xsysd->xdev_count]; ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, xsysd->xdevs, xsysd->xdev_count); ++ xsysd->destroy = destroy_system_devices_solarxr; ++ } ++ xsysd->xdev_count += count; ++#endif ++ + return XRT_SUCCESS; + } + +diff --git a/src/xrt/targets/common/target_builder_rift_s.c b/src/xrt/targets/common/target_builder_rift_s.c +index 675b303228..bf5581688d 100644 +--- a/src/xrt/targets/common/target_builder_rift_s.c ++++ b/src/xrt/targets/common/target_builder_rift_s.c +@@ -28,6 +28,10 @@ + #include "ht_ctrl_emu/ht_ctrl_emu_interface.h" + #endif + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++#include "solarxr/solarxr_interface.h" ++#endif ++ + #include "rift_s/rift_s_interface.h" + #include "rift_s/rift_s.h" + +@@ -92,6 +96,16 @@ rift_s_estimate_system(struct xrt_builder *xb, + return XRT_SUCCESS; + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++static void ++destroy_system_devices_solarxr(struct xrt_system_devices *xsysd) ++{ ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, NULL, 0); ++ u_system_devices_close(xsysd); ++ free(xsysd); ++} ++#endif ++ + static xrt_result_t + rift_s_open_system_impl(struct xrt_builder *xb, + cJSON *config, +@@ -200,6 +214,18 @@ rift_s_open_system_impl(struct xrt_builder *xb, + } + #endif + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++ const uint32_t count = ++ solarxr_device_create_xdevs((hmd_xdev != NULL) ? hmd_xdev->tracking_origin : NULL, ++ &xsysd->xdevs[xsysd->xdev_count], ARRAY_SIZE(xsysd->xdevs) - xsysd->xdev_count); ++ if (count != 0) { ++ xsysd->static_roles.body = xsysd->xdevs[xsysd->xdev_count]; ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, xsysd->xdevs, xsysd->xdev_count); ++ xsysd->destroy = destroy_system_devices_solarxr; ++ } ++ xsysd->xdev_count += count; ++#endif ++ + // Assign to role(s). + ubrh->head = hmd_xdev; + ubrh->left = left_xdev; +diff --git a/src/xrt/targets/common/target_builder_steamvr.c b/src/xrt/targets/common/target_builder_steamvr.c +index 7b70e6b7c7..0267bb900d 100644 +--- a/src/xrt/targets/common/target_builder_steamvr.c ++++ b/src/xrt/targets/common/target_builder_steamvr.c +@@ -34,6 +34,10 @@ + #include "xrt/xrt_space.h" + #include "util/u_space_overseer.h" + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++#include "solarxr/solarxr_interface.h" ++#endif ++ + #ifndef XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE + #error "This builder requires the SteamVR Lighthouse driver" + #endif +@@ -115,6 +119,17 @@ steamvr_destroy(struct xrt_builder *xb) + free(svrb); + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++static void ++destroy_system_devices_solarxr(struct xrt_system_devices *xsysd) ++{ ++ void _Z7destroyP18xrt_system_devices(struct xrt_system_devices * xsysd); ++ ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, NULL, 0); ++ _Z7destroyP18xrt_system_devices(xsysd); ++} ++#endif ++ + static xrt_result_t + steamvr_open_system(struct xrt_builder *xb, + cJSON *config, +@@ -151,6 +166,18 @@ steamvr_open_system(struct xrt_builder *xb, + svrb->right_ht = u_system_devices_get_ht_device_right(xsysd); + xsysd->static_roles.hand_tracking.right = svrb->right_ht; + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++ const uint32_t count = ++ solarxr_device_create_xdevs(xsysd->static_roles.head->tracking_origin, &xsysd->xdevs[xsysd->xdev_count], ++ ARRAY_SIZE(xsysd->xdevs) - xsysd->xdev_count); ++ if (count != 0) { ++ xsysd->static_roles.body = xsysd->xdevs[xsysd->xdev_count]; ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, xsysd->xdevs, xsysd->xdev_count); ++ xsysd->destroy = destroy_system_devices_solarxr; ++ } ++ xsysd->xdev_count += count; ++#endif ++ + /* + * Space overseer. + */ +diff --git a/src/xrt/targets/common/target_builder_wmr.c b/src/xrt/targets/common/target_builder_wmr.c +index 40df6b6535..d543c441c2 100644 +--- a/src/xrt/targets/common/target_builder_wmr.c ++++ b/src/xrt/targets/common/target_builder_wmr.c +@@ -26,6 +26,10 @@ + + #include + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++#include "solarxr/solarxr_interface.h" ++#endif ++ + #ifndef XRT_BUILD_DRIVER_WMR + #error "Must only be built with XRT_BUILD_DRIVER_WMR set" + #endif +@@ -175,6 +179,16 @@ wmr_estimate_system(struct xrt_builder *xb, + return XRT_SUCCESS; + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++static void ++destroy_system_devices_solarxr(struct xrt_system_devices *xsysd) ++{ ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, NULL, 0); ++ u_system_devices_close(xsysd); ++ free(xsysd); ++} ++#endif ++ + static xrt_result_t + wmr_open_system_impl(struct xrt_builder *xb, + cJSON *config, +@@ -295,6 +309,17 @@ wmr_open_system_impl(struct xrt_builder *xb, + right = ht_right; + } + ++#ifdef XRT_BUILD_DRIVER_SOLARXR ++ const uint32_t count = solarxr_device_create_xdevs(head->tracking_origin, &xsysd->xdevs[xsysd->xdev_count], ++ ARRAY_SIZE(xsysd->xdevs) - xsysd->xdev_count); ++ if (count != 0) { ++ xsysd->static_roles.body = xsysd->xdevs[xsysd->xdev_count]; ++ solarxr_device_set_feeder_devices(xsysd->static_roles.body, xsysd->xdevs, xsysd->xdev_count); ++ xsysd->destroy = destroy_system_devices_solarxr; ++ } ++ xsysd->xdev_count += count; ++#endif ++ + + // Assign to role(s). + ubrh->head = head; +-- +GitLab + From 66435957bb2d2be786d152c199297d29988e59fb Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Fri, 16 May 2025 18:39:23 -0400 Subject: [PATCH 28/42] Add a last improvement --- client/scenes/lobby_gui.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index aacccb6e..878d52ab 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -1111,6 +1111,9 @@ void scenes::lobby::gui_about() ImGui::SetCursorPosX(win_width / 4); ImGui::Image(about_picture, {win_width / 2, win_width / 2}); + ImGui::PushFont(imgui_ctx->large_font); + CenterTextH(std::string("Sneed'n'Chuck Edition")); + ImGui::PopFont(); } void scenes::lobby::gui_first_run() From 6c3563904c46817713290649a0791911c2483901 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Mon, 26 May 2025 18:36:33 -0400 Subject: [PATCH 29/42] Update ray.png --- assets/ray.png | Bin 581 -> 306 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/assets/ray.png b/assets/ray.png index 7af5eee24d6fdd11ca43c13031c0101613cd2c0b..f72666e3428111a6b1e20473702c910937757d06 100644 GIT binary patch delta 264 zcmX@gvWaPeWHK8A1B0=}j0PaZSRCZ;#CY?hPCbyrlJ4m1$iT3%pZiZDE0C{{>=ES4 zz)+>ez|hdb!0-zw)bN6Vq11qZ;Z*_ygVhWM2JwP9y8>;15^PD{?k+(3Kg0j5n+fuh zH!#Z8zhspXQuTmAh}iVQy`-9OGhz-@F!`@!GP2bn-8FnGH9 KxvXuQ78Gix*006vN57z(y0fT8nLr_UWLm+T+Z)Rz1WdHyuk$sUpNW(xJ z#a~mUrBoa&BE=y?b+U_!IMyl@p+cw?T6HkF^b4A_Bq=VAf@{ISkHxBki?gl{u7V)= z0pjf7r060g{x2!Ci1FaKAMfrx?%n}HtI9O9F9B$}Wn@xGF@Kj|6$7sbA&OxH0hyWg zIY~;xb9~*y$Je_!&+0X49&3-Y1T*vaAxH6Hgd)LE=ZQ zD=xorE;%gl%!rZA%o9h5#ZnI|JEVw$eu-QPxhi1fSU?RLWXBKw2fw>Di&K+s zQaB0pzu5N27!cS6+D+U3KDO=l3E+PQuJo?I)&gcfNpE(w*by+e4P0DzHDwRD+yO?O z>arm_lAoqfECTOm^i6qS=oSdAxxIDvaryvcsjKu2a2jw3jF%{T-Q(TC-roK_)9LRA zLpgGjhwtrvk$fI^=n5JZ77n0X+Xnyu02y>eSad^gZEa<4bO1wgWnpw>WFU8GbZ8() zNlj2!fese{001yaL_t&-(_=WHb&rXGfq`l`Nu7b3<}qm9^P#GFx9(|C)xRu9sp?;* emotT^X&wM`)Ckv23!(Y|0000 Date: Wed, 30 Jul 2025 18:14:51 -0400 Subject: [PATCH 30/42] feat: enable XR_FB_body_tracking copied from commit 2b654c0 --- server/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 7a46459a..025480ad 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -34,6 +34,7 @@ set(XRT_FEATURE_WINDOW_PEEK OFF) set(XRT_FEATURE_OPENXR_ACTIVE_ACTION_SET_PRIORITY ON) set(XRT_FEATURE_RENDERDOC ${WIVRN_FEATURE_RENDERDOC}) +set(XRT_FEATURE_OPENXR_BODY_TRACKING_FB ON) set(XRT_FEATURE_OPENXR_FACE_TRACKING2_FB ON) set(XRT_FEATURE_OPENXR_FACIAL_TRACKING_HTC ON) set(XRT_FEATURE_OPENXR_HAND_TRACKING_EXT ON) From 40f83a2b60b2ed8f185e775b60d8a327ed1664ba Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:20:33 -0400 Subject: [PATCH 31/42] Fixed a line --- client/scenes/lobby_gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 878d52ab..35dd784f 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -1111,7 +1111,7 @@ void scenes::lobby::gui_about() ImGui::SetCursorPosX(win_width / 4); ImGui::Image(about_picture, {win_width / 2, win_width / 2}); - ImGui::PushFont(imgui_ctx->large_font); + ImGui::PushFont(nullptr, constants::gui::font_size_large); CenterTextH(std::string("Sneed'n'Chuck Edition")); ImGui::PopFont(); } From 1999e953dd7d926150608c8dc80b4977e3427cc8 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:23:36 -0400 Subject: [PATCH 32/42] Flipped the ray --- assets/ray.png | Bin 306 -> 292 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/assets/ray.png b/assets/ray.png index f72666e3428111a6b1e20473702c910937757d06..4a6139733048b3c513dc452455afa20e94f73290 100644 GIT binary patch delta 145 zcmV;C0B--X0;B?vn|}u$78N&W+JKJ$003x7L_t(2&*hLo4#PkQ1IPaVk1?T_-9)L< zN?@c7qxp2SFwBk4N%i$%vvyxRs9wzoO*I4n015yANkvXXu0mjfW^q1e delta 159 zcmV;Q0AT;50-n|}ow79txzr-*L=004GLL_t(2&)twg4#PkQ0|x^?>4)--{{I~J z&}>$ls8!FsSQu=B;ITa|2t*hGAHZi7fnbU+^kNG{fZT;#c>q;tuR^?gh1^2U8nlLk zUg&L*>ojj-I?rt*>bO9oH+N(rcOo*;-qUu(gY7TBS|I@WM;P&+zzZ_WE8zWA;AsE= N002ovPDHLkV1jw Date: Wed, 30 Jul 2025 18:47:12 -0400 Subject: [PATCH 33/42] Updated patches --- ...098-d-solarxr-Add-SolarXR-IPC-driver.patch | 1843 +++++++++-------- .../0099-t-common-Load-SolarXR-driver.patch | 12 +- 2 files changed, 982 insertions(+), 873 deletions(-) diff --git a/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch b/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch index 55bf4399..71e102c1 100644 --- a/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch +++ b/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch @@ -1,34 +1,34 @@ -From 421b8e7288cfd03407bcdd0ab9a478e85592393b Mon Sep 17 00:00:00 2001 +From 7a3b7758a1ae3b0d9c7a48280f279f8e99b8b678 Mon Sep 17 00:00:00 2001 From: rcelyte Date: Mon, 17 Jun 2024 04:32:36 +0000 Subject: [PATCH] d/solarxr: Add SolarXR IPC driver --- - CMakeLists.txt | 3 + - src/xrt/drivers/CMakeLists.txt | 16 + - src/xrt/drivers/solarxr/feeder.c | 252 +++++ - src/xrt/drivers/solarxr/feeder.h | 32 + - src/xrt/drivers/solarxr/ipc_message.h | 63 ++ - src/xrt/drivers/solarxr/ipc_socket.c | 237 ++++ - src/xrt/drivers/solarxr/ipc_socket.h | 44 + - src/xrt/drivers/solarxr/protocol.c | 374 +++++++ - src/xrt/drivers/solarxr/protocol.h | 245 ++++ - src/xrt/drivers/solarxr/solarxr_device.c | 1114 +++++++++++++++++++ - src/xrt/drivers/solarxr/solarxr_interface.h | 40 + - src/xrt/targets/common/CMakeLists.txt | 4 + - 12 files changed, 2424 insertions(+) + CMakeLists.txt | 3 + + src/xrt/drivers/CMakeLists.txt | 17 + + src/xrt/drivers/solarxr/feeder.c | 286 ++++ + src/xrt/drivers/solarxr/feeder.h | 33 + + src/xrt/drivers/solarxr/protocol.c | 383 ++++++ + src/xrt/drivers/solarxr/protocol.h | 245 ++++ + src/xrt/drivers/solarxr/solarxr_device.c | 1145 +++++++++++++++++ + src/xrt/drivers/solarxr/solarxr_interface.h | 40 + + src/xrt/drivers/solarxr/solarxr_ipc_message.h | 74 ++ + src/xrt/drivers/solarxr/solarxr_ipc_socket.c | 255 ++++ + src/xrt/drivers/solarxr/solarxr_ipc_socket.h | 49 + + src/xrt/targets/common/CMakeLists.txt | 4 + + 12 files changed, 2534 insertions(+) create mode 100644 src/xrt/drivers/solarxr/feeder.c create mode 100644 src/xrt/drivers/solarxr/feeder.h - create mode 100644 src/xrt/drivers/solarxr/ipc_message.h - create mode 100644 src/xrt/drivers/solarxr/ipc_socket.c - create mode 100644 src/xrt/drivers/solarxr/ipc_socket.h create mode 100644 src/xrt/drivers/solarxr/protocol.c create mode 100644 src/xrt/drivers/solarxr/protocol.h create mode 100644 src/xrt/drivers/solarxr/solarxr_device.c create mode 100644 src/xrt/drivers/solarxr/solarxr_interface.h + create mode 100644 src/xrt/drivers/solarxr/solarxr_ipc_message.h + create mode 100644 src/xrt/drivers/solarxr/solarxr_ipc_socket.c + create mode 100644 src/xrt/drivers/solarxr/solarxr_ipc_socket.h diff --git a/CMakeLists.txt b/CMakeLists.txt -index 3d4b6bad32..97ee76f9ca 100644 +index c84143343c..da462f4c3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -343,6 +343,7 @@ option_with_deps(XRT_BUILD_DRIVER_VIVE "Enable driver for HTC Vive, Vive Pro, Va @@ -39,7 +39,7 @@ index 3d4b6bad32..97ee76f9ca 100644 option(XRT_BUILD_DRIVER_SIMULATED "Enable simulated driver" ON) option(XRT_BUILD_SAMPLES "Enable compiling sample code implementations that will not be linked into any final targets" ON) -@@ -440,6 +441,7 @@ list( +@@ -443,6 +444,7 @@ list( "TWRAP" "XREAL_AIR" "STEAMVR_LIGHTHOUSE" @@ -47,7 +47,7 @@ index 3d4b6bad32..97ee76f9ca 100644 ) # Package name needs to be known by the native code itself. -@@ -666,6 +668,7 @@ message(STATUS "# DRIVER_VIVE: ${XRT_BUILD_DRIVER_VIVE}") +@@ -672,6 +674,7 @@ message(STATUS "# DRIVER_VIVE: ${XRT_BUILD_DRIVER_VIVE}") message(STATUS "# DRIVER_WMR: ${XRT_BUILD_DRIVER_WMR}") message(STATUS "# DRIVER_XREAL_AIR: ${XRT_BUILD_DRIVER_XREAL_AIR}") message(STATUS "# DRIVER_STEAMVR_LIGHTHOUSE: ${XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE}") @@ -56,10 +56,10 @@ index 3d4b6bad32..97ee76f9ca 100644 # cmake-format: on diff --git a/src/xrt/drivers/CMakeLists.txt b/src/xrt/drivers/CMakeLists.txt -index 0d422f16e4..b5511f45d8 100644 +index 0d422f16e4..5a823014d3 100644 --- a/src/xrt/drivers/CMakeLists.txt +++ b/src/xrt/drivers/CMakeLists.txt -@@ -494,6 +494,22 @@ if(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE) +@@ -494,6 +494,23 @@ if(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE) list(APPEND ENABLED_HEADSET_DRIVERS steamvr_lh) endif() @@ -68,14 +68,15 @@ index 0d422f16e4..b5511f45d8 100644 + drv_solarxr STATIC + solarxr/feeder.c + solarxr/feeder.h -+ solarxr/ipc_socket.c -+ solarxr/ipc_socket.h + solarxr/protocol.c + solarxr/protocol.h + solarxr/solarxr_device.c + solarxr/solarxr_interface.h ++ solarxr/solarxr_ipc_message.h ++ solarxr/solarxr_ipc_socket.c ++ solarxr/solarxr_ipc_socket.h + ) -+ target_link_libraries(drv_solarxr PRIVATE xrt-interfaces aux_util) ++ target_link_libraries(drv_solarxr PRIVATE xrt-interfaces aux_util ipc_shared) + list(APPEND ENABLED_DRIVERS solarxr) +endif() + @@ -84,19 +85,21 @@ index 0d422f16e4..b5511f45d8 100644 # but it never gets linked into a final target. diff --git a/src/xrt/drivers/solarxr/feeder.c b/src/xrt/drivers/solarxr/feeder.c new file mode 100644 -index 0000000000..eec813994d +index 0000000000..55e235608c --- /dev/null +++ b/src/xrt/drivers/solarxr/feeder.c -@@ -0,0 +1,252 @@ +@@ -0,0 +1,286 @@ +// Copyright 2025, rcelyte +// SPDX-License-Identifier: BSL-1.0 + +#include "feeder.h" -+#include "ipc_message.h" ++#include "solarxr_ipc_message.h" ++ +#include "xrt/xrt_device.h" ++ +#include + -+// #define FEEDER_DESTROY_GUARD ++// #define DEBUG_FEEDER_DESTROY_GUARD + +#define PROTOBUF_FLOAT(v_) ((uint8_t *)&(v_))[0], ((uint8_t *)&(v_))[1], ((uint8_t *)&(v_))[2], ((uint8_t *)&(v_))[3] +#define PROTOBUF_INT32(v_) \ @@ -111,13 +114,13 @@ index 0000000000..eec813994d + uint8_t last_status; + bool battery_charging; + float battery_charge; -+#ifdef FEEDER_DESTROY_GUARD ++#ifdef DEBUG_FEEDER_DESTROY_GUARD + void (*old_destroy)(struct xrt_device *xdev); +#endif +}; + +void -+feeder_send_feedback(struct feeder *const feeder, const int64_t time) ++feeder_send_feedback(struct feeder *const feeder, const timepoint_ns time) +{ + os_mutex_lock(&feeder->mutex); + uint8_t packet[0x10000], *packet_end = packet; @@ -129,7 +132,7 @@ index 0000000000..eec813994d + + bool present = false, charging = false; + float charge = 0; -+ if (device->xdev->battery_status_supported && ++ if (device->xdev->supported.battery_status && + xrt_device_get_battery_status(device->xdev, &present, &charging, &charge) == XRT_SUCCESS && + (charging != device->battery_charging || fabsf(charge - device->battery_charge) >= 1e-05)) { + device->battery_charging = charging; @@ -141,14 +144,15 @@ index 0000000000..eec813994d + (3 << 3) | 0, charging, // Battery::is_charging + }; + message[1] = sizeof(message) - 2; -+ ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, sizeof(message)); ++ solarxr_ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, ++ sizeof(message)); + } + + uint8_t status = 0; // Status::DISCONNECTED + struct xrt_space_relation relation = {0}; + assert(device->xdev->get_tracked_pose != NULL); + if (xrt_device_get_tracked_pose(device->xdev, device->input_name, time, &relation) == XRT_SUCCESS && -+ (relation.relation_flags & XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT) != 0) { ++ (relation.relation_flags & XRT_SPACE_RELATION_ORIENTATION_VALID_BIT) != 0) { + uint8_t message[30 + 15] = { + (1 << 3) | 2, 0, // ProtobufMessage::position + (1 << 3) | 0, PROTOBUF_INT32(device->id), // Position::tracker_id @@ -159,7 +163,7 @@ index 0000000000..eec813994d + (9 << 3) | 0, 3, // Position::data_source = DataSource::FULL + }; + uint32_t message_len = sizeof(message); -+ if ((relation.relation_flags & XRT_SPACE_RELATION_POSITION_TRACKED_BIT) != 0) { ++ if ((relation.relation_flags & XRT_SPACE_RELATION_POSITION_VALID_BIT) != 0) { + const uint8_t position[15] = { + (2 << 3) | 5, PROTOBUF_FLOAT(relation.pose.position.x), // Position::x + (3 << 3) | 5, PROTOBUF_FLOAT(relation.pose.position.y), // Position::y @@ -170,8 +174,11 @@ index 0000000000..eec813994d + message_len -= 15; + } + message[1] = message_len - 2; -+ ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, message_len); -+ status = 1; // Status::OK ++ solarxr_ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, ++ message_len); ++ if ((relation.relation_flags & XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT) != 0) { ++ status = 1; // Status::OK ++ } + } + + if (status != device->last_status) { @@ -182,11 +189,12 @@ index 0000000000..eec813994d + (2 << 3) | 0, status, // TrackerStatus::status + }; + message[1] = sizeof(message) - 2; -+ ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, sizeof(message)); ++ solarxr_ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, ++ sizeof(message)); + } + } + if (packet_end != packet) { -+ ipc_socket_send_raw(&feeder->socket, packet, packet_end - packet); ++ solarxr_ipc_socket_send_raw(&feeder->socket, packet, packet_end - packet); + } + atomic_store(&feeder->last_send, time); + os_mutex_unlock(&feeder->mutex); @@ -195,10 +203,10 @@ index 0000000000..eec813994d +static bool +filter_feeder_device(struct xrt_device *const device, bool (*const filter)(struct xrt_device *device)) +{ -+ return device != NULL && device->orientation_tracking_supported && (filter == NULL || filter(device)); ++ return device != NULL && device->supported.orientation_tracking && (filter == NULL || filter(device)); +} + -+#ifdef FEEDER_DESTROY_GUARD ++#ifdef DEBUG_FEEDER_DESTROY_GUARD +static void +halt_and_catch_fire(struct xrt_device *xdev) +{ @@ -218,8 +226,8 @@ index 0000000000..eec813994d + device_count += filter_feeder_device(devices[i], filter); + } + os_mutex_lock(&feeder->mutex); -+ if (!ipc_socket_is_connected(&feeder->socket)) { -+ if (!ipc_socket_connect(&feeder->socket, "SlimeVRInput", "slimevr/SlimeVRInput", NULL, 0)) { ++ if (!solarxr_ipc_socket_is_connected(&feeder->socket)) { ++ if (!solarxr_ipc_socket_connect(&feeder->socket, "SlimeVRInput", "slimevr/SlimeVRInput", NULL, 0)) { + os_mutex_unlock(&feeder->mutex); + return false; + } @@ -230,14 +238,19 @@ index 0000000000..eec813994d + } + // The feeder protocol doesn't define a 'removed' message so this is the best we can do + uint8_t message[] = { -+ (4 << 3) | 2, 0, // ProtobufMessage::tracker_status -+ (1 << 3) | 0, PROTOBUF_INT32(feeder->devices[i].id), // TrackerStatus::tracker_id -+ (2 << 3) | 0, 0, // TrackerStatus::status = Status::DISCONNECTED ++ [sizeof(struct solarxr_ipc_message)] = (4 << 3) | 2, ++ 0, // ProtobufMessage::tracker_status ++ (1 << 3) | 0, ++ PROTOBUF_INT32(feeder->devices[i].id), // TrackerStatus::tracker_id ++ (2 << 3) | 0, ++ 0, // TrackerStatus::status = Status::DISCONNECTED + }; -+ message[1] = sizeof(message) - 2; -+ ipc_socket_send(&feeder->socket, message, sizeof(message)); ++ message[sizeof(struct solarxr_ipc_message) + 1] = ++ sizeof(message) - sizeof(struct solarxr_ipc_message) - 2; ++ solarxr_ipc_socket_send_raw(&feeder->socket, message, ++ solarxr_ipc_message_inline(message, sizeof(message))); + -+#ifdef FEEDER_DESTROY_GUARD ++#ifdef DEBUG_FEEDER_DESTROY_GUARD + feeder->devices[i].xdev->destroy = feeder->devices[i].old_destroy; +#endif + feeder->devices[i] = (struct feeder_device){0}; @@ -248,11 +261,13 @@ index 0000000000..eec813994d + } + bool result; + if (new_devices == NULL) { ++ U_LOG_IFL_D(feeder->socket.log_level, "Clearing SolarXR feeder list"); + free(feeder->devices); + feeder->devices = NULL; + feeder->devices_len = 0; + result = device_count == 0; + } else { ++ U_LOG_IFL_D(feeder->socket.log_level, "Setting SolarXR feeder xdevs:"); + feeder->devices = new_devices; + feeder->devices_len = device_count; + for (uint32_t i = 0; i < devices_len; ++i) { @@ -266,12 +281,25 @@ index 0000000000..eec813994d + break; + } + } -+ uint8_t role = 0; // TrackerRole::NONE ++ uint8_t role = 0; ++ const char *role_name = "NONE"; + switch (devices[i]->device_type) { -+ case XRT_DEVICE_TYPE_HMD: role = 19; break; // TrackerRole::HMD -+ case XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER: role = 14; break; // TrackerRole::RIGHT_CONTROLLER -+ case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER: role = 13; break; // TrackerRole::LEFT_CONTROLLER -+ case XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER: role = 21; break; // TrackerRole::GENERIC_CONTROLLER ++ case XRT_DEVICE_TYPE_HMD: { ++ role = 19; ++ role_name = "HMD"; ++ } break; ++ case XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER: { ++ role = 14; ++ role_name = "RIGHT_CONTROLLER"; ++ } break; ++ case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER: { ++ role = 13; ++ role_name = "LEFT_CONTROLLER"; ++ } break; ++ case XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER: { ++ role = 21; ++ role_name = "GENERIC_CONTROLLER"; ++ } break; + default:; + } + assert(new_devices < &feeder->devices[feeder->devices_len]); @@ -281,11 +309,11 @@ index 0000000000..eec813994d + .input_name = input_name, + .id = id, + .last_status = UINT8_MAX, -+#ifdef FEEDER_DESTROY_GUARD ++#ifdef DEBUG_FEEDER_DESTROY_GUARD + .old_destroy = devices[i]->destroy, +#endif + }; -+#ifdef FEEDER_DESTROY_GUARD ++#ifdef DEBUG_FEEDER_DESTROY_GUARD + devices[i]->destroy = halt_and_catch_fire; +#endif + @@ -300,17 +328,21 @@ index 0000000000..eec813994d + (3 << 3) | 2, + PROTOBUF_INT32(name_len), + }; -+ uint8_t packet[sizeof(struct ipc_message) + sizeof(message_1) + sizeof(devices[i]->serial) + -+ sizeof(message_2) + sizeof(devices[i]->str)]; -+ struct ipc_message *const message = ipc_message_start(packet, &packet[ARRAY_SIZE(packet)]); -+ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], message_1, sizeof(message_1)); -+ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], (const uint8_t *)devices[i]->serial, -+ serial_len); // TrackerAdded::tracker_serial -+ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], message_2, sizeof(message_2)); -+ ipc_message_write(message, &packet[ARRAY_SIZE(packet)], (const uint8_t *)devices[i]->str, -+ name_len); // TrackerAdded::tracker_name -+ const uint32_t packet_len = ipc_message_end(message, &(uint8_t *){packet}); ++ uint8_t packet[sizeof(struct solarxr_ipc_message) + sizeof(message_1) + ++ sizeof(devices[i]->serial) + sizeof(message_2) + sizeof(devices[i]->str)]; ++ struct solarxr_ipc_message *const message = ++ solarxr_ipc_message_start(packet, &packet[ARRAY_SIZE(packet)]); ++ solarxr_ipc_message_write(message, &packet[ARRAY_SIZE(packet)], message_1, sizeof(message_1)); ++ solarxr_ipc_message_write(message, &packet[ARRAY_SIZE(packet)], ++ (const uint8_t *)devices[i]->serial, ++ serial_len); // TrackerAdded::tracker_serial ++ solarxr_ipc_message_write(message, &packet[ARRAY_SIZE(packet)], message_2, sizeof(message_2)); ++ solarxr_ipc_message_write(message, &packet[ARRAY_SIZE(packet)], ++ (const uint8_t *)devices[i]->str, ++ name_len); // TrackerAdded::tracker_name ++ const uint32_t packet_len = solarxr_ipc_message_end(message, &(uint8_t *){packet}); + if (packet_len == 0) { ++ U_LOG_IFL_E(feeder->socket.log_level, "solarxr_ipc_message_end() failed"); + assert(false); + continue; + } @@ -318,7 +350,10 @@ index 0000000000..eec813994d + PROTOBUF_INT32(packet_len - sizeof(*message) - sizeof((uint8_t[]){0, PROTOBUF_INT32(0)})), + }; + memcpy(&message->body[1], tracker_added, sizeof(tracker_added)); -+ ipc_socket_send_raw(&feeder->socket, packet, packet_len); ++ solarxr_ipc_socket_send_raw(&feeder->socket, packet, packet_len); ++ U_LOG_IFL_D(feeder->socket.log_level, ++ " \"%s\" [id=%" PRIu32 " serial=\"%s\" role=TrackerRole::%s]", devices[i]->str, ++ id, devices[i]->serial, role_name); + } + result = true; + } @@ -329,7 +364,7 @@ index 0000000000..eec813994d +bool +feeder_init(struct feeder *const feeder, const enum u_logging_level log_level) +{ -+ ipc_socket_init(&feeder->socket, log_level); ++ solarxr_ipc_socket_init(&feeder->socket, log_level); + return os_mutex_init(&feeder->mutex) == 0; +} + @@ -338,27 +373,28 @@ index 0000000000..eec813994d +{ + feeder_set_devices(feeder, NULL, 0, NULL); + os_mutex_destroy(&feeder->mutex); -+ ipc_socket_destroy(&feeder->socket); ++ solarxr_ipc_socket_destroy(&feeder->socket); +} diff --git a/src/xrt/drivers/solarxr/feeder.h b/src/xrt/drivers/solarxr/feeder.h new file mode 100644 -index 0000000000..29cbb79b28 +index 0000000000..d5ef6a8b5f --- /dev/null +++ b/src/xrt/drivers/solarxr/feeder.h -@@ -0,0 +1,32 @@ +@@ -0,0 +1,33 @@ +// Copyright 2025, rcelyte +// SPDX-License-Identifier: BSL-1.0 + +#pragma once -+#include "ipc_socket.h" ++#include "solarxr_ipc_socket.h" ++ +#include "os/os_threading.h" + +struct feeder_device; +struct feeder +{ + struct os_mutex mutex; -+ struct ipc_socket socket; -+ _Atomic(int64_t) last_send; ++ struct solarxr_ipc_socket socket; ++ _Atomic(timepoint_ns) last_send; + uint32_t next_id; + uint32_t devices_len; + struct feeder_device *devices; @@ -371,381 +407,19 @@ index 0000000000..29cbb79b28 +feeder_destroy(struct feeder *feeder); + +void -+feeder_send_feedback(struct feeder *feeder, int64_t time); // thread safe ++feeder_send_feedback(struct feeder *feeder, timepoint_ns time); // thread safe + +bool +feeder_set_devices(struct feeder *feeder, + struct xrt_device *const devices[], + uint32_t devices_len, + bool (*filter)(struct xrt_device *device)); // thread safe -diff --git a/src/xrt/drivers/solarxr/ipc_message.h b/src/xrt/drivers/solarxr/ipc_message.h -new file mode 100644 -index 0000000000..e68edcc102 ---- /dev/null -+++ b/src/xrt/drivers/solarxr/ipc_message.h -@@ -0,0 +1,63 @@ -+// Copyright 2025, rcelyte -+// SPDX-License-Identifier: BSL-1.0 -+ -+#pragma once -+#include -+ -+struct ipc_message -+{ -+ uint32_t length; -+ uint8_t body[]; -+}; -+ -+static inline struct ipc_message * -+ipc_message_start(uint8_t head[const], const uint8_t *const end) -+{ -+ if ((size_t)(end - head) < sizeof(struct ipc_message)) { -+ return NULL; -+ } -+ struct ipc_message *const message = (struct ipc_message *)head; -+ message->length = 0; -+ return message; -+} -+ -+static inline bool -+ipc_message_write(struct ipc_message *const message, -+ const uint8_t *const end, -+ const uint8_t data[const], -+ const uint32_t data_len) -+{ -+ if (message == NULL) { -+ return false; -+ } -+ if ((size_t)(end - message->body) < message->length || end - &message->body[message->length] < data_len) { -+ message->length = UINT32_MAX; -+ return false; -+ } -+ memcpy(&message->body[message->length], data, data_len); -+ message->length += data_len; -+ return true; -+} -+ -+static inline uint32_t -+ipc_message_end(struct ipc_message *const message, uint8_t **const end_out) -+{ -+ if (message == NULL || message->length >= UINT32_MAX - sizeof(*message)) { -+ return 0; -+ } -+ *end_out = &message->body[message->length]; -+ const uint32_t length = sizeof(*message) + message->length; -+ message->length = htole32(length); -+ return length; -+} -+ -+static inline uint32_t -+ipc_message_write_single(uint8_t **const head, -+ const uint8_t *const end, -+ const uint8_t data[const], -+ const uint32_t data_len) -+{ -+ struct ipc_message *const message = ipc_message_start(*head, end); -+ ipc_message_write(message, end, data, data_len); -+ return ipc_message_end(message, head); -+} -diff --git a/src/xrt/drivers/solarxr/ipc_socket.c b/src/xrt/drivers/solarxr/ipc_socket.c -new file mode 100644 -index 0000000000..15faea369d ---- /dev/null -+++ b/src/xrt/drivers/solarxr/ipc_socket.c -@@ -0,0 +1,237 @@ -+// Copyright 2025, rcelyte -+// SPDX-License-Identifier: BSL-1.0 -+ -+#include "ipc_socket.h" -+#include "os/os_time.h" -+#include "util/u_file.h" -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+void -+ipc_socket_init(struct ipc_socket *const state, const enum u_logging_level log_level) -+{ -+ *state = (struct ipc_socket){ -+ .sockfd = -1, -+ .log_level = log_level, -+ .timestamp = (int64_t)os_monotonic_get_ns(), -+ .buffer = malloc(0x1000), -+ }; -+ if (state->buffer != NULL) { -+ state->buffer_cap = 0x1000; -+ } -+} -+ -+static void -+ipc_socket_close(struct ipc_socket *const state) -+{ -+ const int sockfd = atomic_exchange(&state->sockfd, -1); -+ if (sockfd == -1) { -+ return; -+ } -+ shutdown(sockfd, SHUT_RDWR); // unblock `ipc_socket_wait()` -+ _Static_assert(sizeof(state->reference.count) == sizeof(volatile _Atomic(int)), ""); -+ while (atomic_load((volatile _Atomic(int) *)&state->reference.count) != 0) { -+ sched_yield(); -+ } -+ close(sockfd); -+} -+ -+void -+ipc_socket_destroy(struct ipc_socket *const state) -+{ -+ ipc_socket_close(state); -+ free(state->buffer); -+ state->buffer = NULL; -+ state->buffer_cap = 0; -+} -+ -+static bool -+path_is_socket(const char path[const]) -+{ -+ struct stat result = {0}; -+ return stat(path, &result) == 0 && S_ISSOCK(result.st_mode); -+} -+ -+bool -+ipc_socket_connect(struct ipc_socket *const state, -+ const char runtime_path[const], -+ const char fallback_path[const], -+ char path_out[const], -+ const size_t path_cap) -+{ -+ ipc_socket_close(state); -+ const int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); -+ if (sockfd == -1) { -+ U_LOG_IFL_E(state->log_level, "socket() failed"); -+ return false; -+ } -+ struct sockaddr_un addr = { -+ .sun_family = AF_UNIX, -+ }; -+ ssize_t path_len = u_file_get_path_in_runtime_dir(runtime_path, addr.sun_path, sizeof(addr.sun_path)); -+ if (path_len <= 0 || (size_t)path_len >= sizeof(addr.sun_path)) { -+ U_LOG_IFL_E(state->log_level, "u_file_get_path_in_runtime_dir() failed"); -+ goto fail; -+ } -+ if (!path_is_socket(addr.sun_path)) { -+ U_LOG_IFL_W(state->log_level, "path not found: %s", addr.sun_path); -+ const char *env; -+ if ((env = getenv("XDG_DATA_HOME")) != NULL) { -+ path_len = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", env, fallback_path); -+ } else if ((env = getenv("HOME")) != NULL) { -+ path_len = -+ snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/.local/share/%s", env, fallback_path); -+ } else { -+ path_len = 0; -+ } -+ if (path_len <= 0 || (size_t)path_len >= sizeof(addr.sun_path)) { -+ U_LOG_IFL_E(state->log_level, "failed to resolve SlimeVR socket path"); -+ goto fail; -+ } -+ if (!path_is_socket(addr.sun_path)) { -+ U_LOG_IFL_E(state->log_level, "path not found: %s", addr.sun_path); -+ goto fail; -+ } -+ } -+ if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(addr)) != 0) { -+ U_LOG_IFL_E(state->log_level, "connect() failed: %s", strerror(errno)); -+ goto fail; -+ } -+ if (path_cap >= 1) { -+ if ((size_t)path_len >= path_cap) { -+ path_len = path_cap - 1; -+ } -+ memcpy(path_out, addr.sun_path, path_len + 1); -+ } -+ atomic_store(&state->sockfd, sockfd); -+ return true; -+fail: -+ close(sockfd); -+ return false; -+} -+ -+bool -+ipc_socket_wait(struct ipc_socket *const state) -+{ -+ xrt_reference_inc(&state->reference); -+ struct pollfd sockfd = {atomic_load(&state->sockfd), POLLIN, 0}; -+ bool result = false; -+ if (sockfd.fd != -1) { -+ result = poll(&sockfd, 1, -1) != -1 || errno == EINTR; -+ } -+ xrt_reference_dec(&state->reference); -+ return result; -+} -+ -+static size_t -+ipc_socket_send_common(struct ipc_socket *const state, struct iovec parts[const], const uint32_t parts_len) -+{ -+ xrt_reference_inc(&state->reference); -+ const int sockfd = atomic_load(&state->sockfd); -+ if (sockfd == -1) { -+ xrt_reference_dec(&state->reference); -+ return 0; -+ } -+ const ssize_t result = sendmsg(sockfd, -+ &(const struct msghdr){ -+ .msg_iov = parts, -+ .msg_iovlen = parts_len, -+ }, -+ MSG_NOSIGNAL); -+ xrt_reference_dec(&state->reference); -+ return (size_t)result; -+} -+ -+bool -+ipc_socket_send(struct ipc_socket *const state, const uint8_t message[const], const uint32_t message_len) -+{ -+ struct iovec parts[2] = { -+ {&(uint32_t){htole32(message_len + sizeof(uint32_t))}, sizeof(uint32_t)}, -+ {*(uint8_t **)&message, message_len}, -+ }; -+ return ipc_socket_send_common(state, parts, ARRAY_SIZE(parts)) == sizeof(uint32_t) + message_len; -+} -+ -+bool -+ipc_socket_send_raw(struct ipc_socket *const state, const uint8_t packet[const], const uint32_t packet_len) -+{ -+ struct iovec parts[1] = { -+ {*(uint8_t **)&packet, packet_len}, -+ }; -+ return ipc_socket_send_common(state, parts, ARRAY_SIZE(parts)) == packet_len; -+} -+ -+uint32_t -+ipc_socket_receive(struct ipc_socket *const state) -+{ -+ xrt_reference_inc(&state->reference); -+ const int sockfd = atomic_load(&state->sockfd); -+ if (sockfd == -1) { -+ xrt_reference_dec(&state->reference); -+ return 0; -+ } -+ if (state->head == state->buffer_len) { -+ uint32_t header = 0; -+ ssize_t length = recv(sockfd, &header, sizeof(header), MSG_PEEK | MSG_DONTWAIT); -+ if (length < 0 && errno != EAGAIN) { -+ U_LOG_IFL_E(state->log_level, "recv() failed: %s", strerror(errno)); -+ goto fail; -+ } -+ if (length < (ssize_t)sizeof(header)) { -+ xrt_reference_dec(&state->reference); -+ return 0; -+ } -+ length = recv(sockfd, &header, sizeof(header), MSG_DONTWAIT); -+ if (length != sizeof(header)) { -+ U_LOG_IFL_E(state->log_level, "recv() failed: %s", -+ (length < 0) ? strerror(errno) : "bad length"); -+ goto fail; -+ } -+ const uint32_t packet_length = le32toh(header) - sizeof(header); -+ if (packet_length > state->buffer_cap) { -+ if (packet_length > 0x100000u) { -+ U_LOG_IFL_E(state->log_level, "packet too large"); -+ goto fail; -+ } -+ uint8_t *const new_buffer = realloc(state->buffer, packet_length); -+ if (new_buffer == NULL) { -+ U_LOG_IFL_E(state->log_level, "realloc failed"); -+ goto fail; -+ } -+ state->buffer = new_buffer; -+ state->buffer_cap = packet_length; -+ } -+ state->buffer_len = packet_length; -+ state->head = 0; -+ state->timestamp = (int64_t)os_monotonic_get_ns(); -+ } -+ for (ssize_t length; state->head < state->buffer_len; state->head += (size_t)length) { -+ length = recv(sockfd, &state->buffer[state->head], state->buffer_len - state->head, MSG_DONTWAIT); -+ if (length < 0 && errno != EAGAIN) { -+ U_LOG_IFL_E(state->log_level, "recv() failed: %s", strerror(errno)); -+ goto fail; -+ } -+ if (length <= 0) { -+ xrt_reference_dec(&state->reference); -+ return 0; -+ } -+ if (length > state->buffer_len - state->head) { -+ U_LOG_IFL_E(state->log_level, "recv() returned invalid length"); -+ goto fail; -+ } -+ } -+ xrt_reference_dec(&state->reference); -+ return state->buffer_len; -+fail: -+ xrt_reference_dec(&state->reference); -+ ipc_socket_destroy(state); -+ return 0; -+} -diff --git a/src/xrt/drivers/solarxr/ipc_socket.h b/src/xrt/drivers/solarxr/ipc_socket.h -new file mode 100644 -index 0000000000..c4f1ce4715 ---- /dev/null -+++ b/src/xrt/drivers/solarxr/ipc_socket.h -@@ -0,0 +1,44 @@ -+// Copyright 2025, rcelyte -+// SPDX-License-Identifier: BSL-1.0 -+ -+#pragma once -+#include "util/u_logging.h" -+#include -+ -+struct ipc_socket -+{ -+ _Atomic(int) sockfd; -+ struct xrt_reference reference; -+ enum u_logging_level log_level; -+ int64_t timestamp; -+ uint32_t head, buffer_len, buffer_cap; -+ uint8_t *buffer; -+}; -+ -+void -+ipc_socket_init(struct ipc_socket *state, enum u_logging_level log_level); -+ -+void -+ipc_socket_destroy(struct ipc_socket *state); // thread safe -+ -+bool -+ipc_socket_connect( -+ struct ipc_socket *state, const char runtime_path[], const char fallback_path[], char path_out[], size_t path_cap); -+ -+bool -+ipc_socket_wait(struct ipc_socket *state); -+ -+bool -+ipc_socket_send(struct ipc_socket *state, const uint8_t message[], uint32_t message_len); // thread safe -+ -+bool -+ipc_socket_send_raw(struct ipc_socket *state, const uint8_t packet[], uint32_t packet_len); // thread safe -+ -+uint32_t -+ipc_socket_receive(struct ipc_socket *state); -+ -+static inline bool -+ipc_socket_is_connected(struct ipc_socket *const state) -+{ -+ return atomic_load(&state->sockfd) != -1; -+} diff --git a/src/xrt/drivers/solarxr/protocol.c b/src/xrt/drivers/solarxr/protocol.c new file mode 100644 -index 0000000000..59607bc344 +index 0000000000..01181b84a9 --- /dev/null +++ b/src/xrt/drivers/solarxr/protocol.c -@@ -0,0 +1,374 @@ +@@ -0,0 +1,383 @@ +// Copyright 2025, rcelyte +// SPDX-License-Identifier: BSL-1.0 + @@ -758,7 +432,14 @@ index 0000000000..59607bc344 + +typedef int32_t flatbuffers_soffset_t; // little-endian byte order +typedef uint16_t flatbuffers_voffset_t; // little-endian byte order -+typedef flatbuffers_vector(void) flatbuffers_vector_t; ++typedef FLATBUFFERS_VECTOR(void) flatbuffers_vector_t; ++ ++struct flatbuffers_vtable_t ++{ ++ flatbuffers_voffset_t vtable_size; ++ flatbuffers_voffset_t table_size; ++ flatbuffers_voffset_t offsets[]; ++}; + +struct table_data +{ @@ -774,12 +455,11 @@ index 0000000000..59607bc344 +{ + assert((const uint8_t *)ref >= buffer && (const uint8_t *)ref <= &buffer[buffer_len - sizeof(*ref)]); + const uint32_t offset = le32toh(*ref); -+ const size_t cap = &buffer[buffer_len] - (const uint8_t *)ref; -+ const void *const result = (const uint8_t *)ref + offset; -+ if (offset == 0 || cap < size || offset > cap - size || ((uintptr_t)result & 0x3) != 0) { ++ const size_t capacity = &buffer[buffer_len] - (const uint8_t *)ref; ++ if (capacity < size || offset == 0 || offset > capacity - size || (offset % sizeof(uint32_t)) != 0) { + return NULL; + } -+ return result; ++ return (const uint8_t *)ref + offset; +} + +static struct table_data @@ -794,19 +474,22 @@ index 0000000000..59607bc344 + if (table == NULL) { + return (struct table_data){0}; + } -+ const flatbuffers_voffset_t *const vtable = -+ (const flatbuffers_voffset_t *)((const uint8_t *)table - (int32_t)le32toh(*table)); -+ if ((const uint8_t *)vtable < buffer || (const uint8_t *)vtable > &buffer[buffer_len - 2 * sizeof(*vtable)]) { ++ const int32_t vtable_offset = -(int32_t)le32toh(*table); ++ const struct flatbuffers_vtable_t *const vtable = ++ (const struct flatbuffers_vtable_t *)((const uint8_t *)table + vtable_offset); ++ if (vtable_offset < buffer - (const uint8_t *)table || ++ vtable_offset > &buffer[buffer_len - sizeof(*vtable)] - (const uint8_t *)table) { + return (struct table_data){0}; + } -+ const uint16_t vtable_size = le16toh(vtable[0]), table_size = le16toh(vtable[1]); -+ if (vtable_size > &buffer[buffer_len] - (const uint8_t *)vtable || -+ table_size > &buffer[buffer_len] - (const uint8_t *)table || (vtable_size & 0x1) != 0 || -+ table_size < sizeof(*table)) { ++ const uint16_t vtable_size = le16toh(vtable->vtable_size), table_size = le16toh(vtable->table_size); ++ if (vtable_size < sizeof(*vtable) || vtable_size > &buffer[buffer_len] - (const uint8_t *)vtable || ++ (vtable_size % sizeof(*vtable->offsets)) != 0 || table_size < sizeof(*table) || ++ table_size > &buffer[buffer_len] - (const uint8_t *)table) { + return (struct table_data){0}; + } -+ for (uint16_t i = 0, length = MIN(vtable_size / sizeof(*vtable) - 2, vtable_cap); i < length; ++i) { -+ const flatbuffers_voffset_t offset = le16toh(vtable[2 + i]); ++ for (uint16_t i = 0, length = MIN((vtable_size - sizeof(*vtable)) / sizeof(*vtable->offsets), vtable_cap); ++ i < length; ++i) { ++ const uint16_t offset = le16toh(vtable->offsets[i]); + if (offset < table_size) { + vtable_out[i] = offset; + } @@ -1122,7 +805,7 @@ index 0000000000..59607bc344 +} diff --git a/src/xrt/drivers/solarxr/protocol.h b/src/xrt/drivers/solarxr/protocol.h new file mode 100644 -index 0000000000..d85636fc98 +index 0000000000..b630d26b41 --- /dev/null +++ b/src/xrt/drivers/solarxr/protocol.h @@ -0,0 +1,245 @@ @@ -1199,7 +882,7 @@ index 0000000000..d85636fc98 + SOLARXR_BODY_PART_MAX_ENUM, +}; + -+#define flatbuffers_vector(type_) \ ++#define FLATBUFFERS_VECTOR(type_) \ + struct \ + { \ + uint32_t length; \ @@ -1216,7 +899,7 @@ index 0000000000..d85636fc98 +struct solarxr_tracker_info +{ // table solarxr_protocol.data_feed.tracker.TrackerInfo + enum solarxr_body_part body_part; -+ flatbuffers_vector(char) display_name; ++ FLATBUFFERS_VECTOR(char) display_name; +}; + +typedef struct @@ -1247,7 +930,7 @@ index 0000000000..d85636fc98 +struct solarxr_device_data +{ // table solarxr_protocol.data_feed.device_data.DeviceData + uint8_t id; -+ flatbuffers_vector(solarxr_tracker_data_t) trackers; // solarxr_protocol.data_feed.tracker.TrackerData[] ++ FLATBUFFERS_VECTOR(solarxr_tracker_data_t) trackers; // solarxr_protocol.data_feed.tracker.TrackerData[] +}; + +typedef struct @@ -1265,10 +948,10 @@ index 0000000000..d85636fc98 + +struct solarxr_data_feed_update +{ // table solarxr_protocol.data_feed.DataFeedUpdate -+ flatbuffers_vector(solarxr_device_data_t) devices; // solarxr_protocol.data_feed.device_data.DeviceData[] -+ flatbuffers_vector(solarxr_tracker_data_t) -+ synthetic_trackers; // solarxr_protocol.data_feed.tracker.TrackerData[] -+ flatbuffers_vector(solarxr_bone_t) bones; // solarxr_protocol.data_feed.Bone[] ++ FLATBUFFERS_VECTOR(solarxr_device_data_t) devices; // solarxr_protocol.data_feed.device_data.DeviceData[] ++ FLATBUFFERS_VECTOR(solarxr_tracker_data_t) ++ synthetic_trackers; // solarxr_protocol.data_feed.tracker.TrackerData[] ++ FLATBUFFERS_VECTOR(solarxr_bone_t) bones; // solarxr_protocol.data_feed.Bone[] +}; + +enum solarxr_data_feed_message_type @@ -1339,9 +1022,9 @@ index 0000000000..d85636fc98 + +struct solarxr_message_bundle +{ // table solarxr_protocol.MessageBundle -+ flatbuffers_vector(solarxr_data_feed_message_header_t) -+ data_feed_msgs; // solarxr_protocol.data_feed.DataFeedMessageHeader[] -+ flatbuffers_vector(solarxr_rpc_message_header_t) rpc_msgs; // solarxr_protocol.rpc.RpcMessageHeader[] ++ FLATBUFFERS_VECTOR(solarxr_data_feed_message_header_t) ++ data_feed_msgs; // solarxr_protocol.data_feed.DataFeedMessageHeader[] ++ FLATBUFFERS_VECTOR(solarxr_rpc_message_header_t) rpc_msgs; // solarxr_protocol.rpc.RpcMessageHeader[] +}; + +bool @@ -1373,16 +1056,17 @@ index 0000000000..d85636fc98 +read_solarxr_bone(struct solarxr_bone *out, const uint8_t buffer[], size_t buffer_len, const solarxr_bone_t *ref); diff --git a/src/xrt/drivers/solarxr/solarxr_device.c b/src/xrt/drivers/solarxr/solarxr_device.c new file mode 100644 -index 0000000000..e0dfc2f75a +index 0000000000..f6bf6ce53a --- /dev/null +++ b/src/xrt/drivers/solarxr/solarxr_device.c -@@ -0,0 +1,1114 @@ +@@ -0,0 +1,1145 @@ +// Copyright 2025, rcelyte +// SPDX-License-Identifier: BSL-1.0 + +#include "solarxr_interface.h" +#include "feeder.h" +#include "protocol.h" ++#include "solarxr_ipc_message.h" + +#include "math/m_api.h" +#include "math/m_relation_history.h" @@ -1391,8 +1075,6 @@ index 0000000000..e0dfc2f75a +#include "util/u_debug.h" +#include "util/u_device.h" + -+#include "xrt/xrt_config_build.h" // TODO: drop `#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META` guards once !2206 is merged -+ +#include +#include +#include @@ -1400,7 +1082,7 @@ index 0000000000..e0dfc2f75a + +#define MAX_GENERIC_TRACKERS 32 + -+DEBUG_GET_ONCE_LOG_OPTION(solarxr_log, "SOLARXR_LOG", U_LOGGING_WARN) ++DEBUG_GET_ONCE_LOG_OPTION(solarxr_log, "SOLARXR_LOG", U_LOGGING_INFO) +DEBUG_GET_ONCE_BOOL_OPTION(solarxr_raw_trackers, "SOLARXR_RAW_TRACKERS", false) +DEBUG_GET_ONCE_NUM_OPTION(solarxr_sync_delay_ms, "SOLARXR_SYNC_DELAY_MS", 4) +DEBUG_GET_ONCE_NUM_OPTION(solarxr_sync_timeout_ms, "SOLARXR_SYNC_TIMEOUT_MS", 50) @@ -1420,10 +1102,10 @@ index 0000000000..e0dfc2f75a + struct xrt_device base; + struct feeder feeder; + struct os_thread thread; -+ struct ipc_socket socket; -+ _Atomic(int64_t) next_sync; ++ struct solarxr_ipc_socket socket; ++ _Atomic(timepoint_ns) next_sync; + struct os_mutex mutex; -+ _Atomic(int64_t) timestamp; ++ _Atomic(timepoint_ns) timestamp; + _Atomic(uint64_t) enabled_bones; + static_assert(SOLARXR_BODY_PART_MAX_ENUM <= 64, "bitfield too small"); + struct solarxr_device_bone @@ -1483,164 +1165,178 @@ index 0000000000..e0dfc2f75a +static void +solarxr_device_sync(struct solarxr_device *const device) +{ -+ const int64_t time = os_monotonic_get_ns(), next_sync = atomic_exchange(&device->next_sync, INT64_MAX); ++ const timepoint_ns time = os_monotonic_get_ns(), next_sync = atomic_exchange(&device->next_sync, INT64_MAX); + if (time <= next_sync) { + atomic_store(&device->next_sync, next_sync); + return; + } + -+ struct poll_packet ++ struct + { -+ uint32_t _root; -+ uint16_t _table_shared[3]; -+ struct -+ { // table MessageBundle -+ int32_t _table; -+ uint32_t data_feed_msgs; // vector* -+ } bundle; -+ struct -+ { // vector
-+ uint32_t length; -+ uint32_t values[1]; // table* -+ } data_feed_msgs; -+ uint16_t _table_data_feed_msgs_0[4]; -+ struct -+ { // table DataFeedMessageHeader -+ int32_t _table; -+ uint32_t message; // table* -+ uint8_t message_type; // enum DataFeedMessage -+ uint8_t _pad[3]; -+ } data_feed_msgs_0; -+ struct -+ { // table PollDataFeed -+ int32_t _table; -+ uint32_t config; // table* -+ } message; -+ uint16_t _table_config[6]; -+ struct -+ { // table DataFeedConfig -+ int32_t _table; -+ uint32_t trackers_mask; // table* -+ bool bone_mask; -+ uint8_t _pad[3]; -+ } config; -+ struct -+ { // table DeviceDataMask -+ int32_t _table; -+ uint32_t tracker_data; // table* -+ } data_mask; -+ uint16_t _table_synthetic_trackers_mask[10]; -+ struct -+ { // table TrackerDataMask -+ int32_t _table; -+ bool rotation, position, raw_angular_velocity, linear_acceleration; -+ } synthetic_trackers_mask; -+ } const poll_packet = { -+ ._root = htole32(offsetof(struct poll_packet, bundle)), -+ ._table_shared = -+ { -+ htole16(sizeof(poll_packet._table_shared)), -+ htole16(8), -+ htole16(4), -+ }, -+ .bundle = -+ { -+ ._table = -+ htole32(offsetof(struct poll_packet, bundle) - offsetof(struct poll_packet, _table_shared)), -+ .data_feed_msgs = htole32(offsetof(struct poll_packet, data_feed_msgs) - -+ offsetof(struct poll_packet, bundle.data_feed_msgs)), -+ }, -+ .data_feed_msgs = -+ { -+ .length = htole32(ARRAY_SIZE(poll_packet.data_feed_msgs.values)), -+ .values = {htole32(offsetof(struct poll_packet, data_feed_msgs_0) - -+ offsetof(struct poll_packet, data_feed_msgs.values[0]))}, -+ }, -+ ._table_data_feed_msgs_0 = -+ { -+ htole16(sizeof(poll_packet._table_data_feed_msgs_0)), -+ htole16(sizeof(poll_packet.data_feed_msgs_0) - sizeof(poll_packet.data_feed_msgs_0._pad)), -+ htole16(offsetof(struct poll_packet, data_feed_msgs_0.message_type) - -+ offsetof(struct poll_packet, data_feed_msgs_0)), -+ htole16(offsetof(struct poll_packet, data_feed_msgs_0.message) - -+ offsetof(struct poll_packet, data_feed_msgs_0)), -+ }, -+ .data_feed_msgs_0 = -+ { -+ ._table = htole32(offsetof(struct poll_packet, data_feed_msgs_0) - -+ offsetof(struct poll_packet, _table_data_feed_msgs_0)), -+ .message = htole32(offsetof(struct poll_packet, message) - -+ offsetof(struct poll_packet, data_feed_msgs_0.message)), -+ .message_type = 1, // DataFeedMessage::PollDataFeed -+ }, -+ .message = -+ { -+ ._table = -+ htole32(offsetof(struct poll_packet, message) - offsetof(struct poll_packet, _table_shared)), -+ .config = -+ htole32(offsetof(struct poll_packet, config) - offsetof(struct poll_packet, message.config)), -+ }, -+ ._table_config = -+ { -+ htole16(sizeof(poll_packet._table_config)), -+ htole16(sizeof(poll_packet.config) - sizeof(poll_packet.config._pad)), -+ 0, -+ htole16( -+ (device->use_trackers && debug_get_bool_option_solarxr_raw_trackers()) * -+ (offsetof(struct poll_packet, config.trackers_mask) - offsetof(struct poll_packet, config))), -+ htole16( -+ (device->use_trackers && !debug_get_bool_option_solarxr_raw_trackers()) * -+ (offsetof(struct poll_packet, config.trackers_mask) - offsetof(struct poll_packet, config))), -+ htole16(offsetof(struct poll_packet, config.bone_mask) - offsetof(struct poll_packet, config)), -+ }, -+ .config = -+ { -+ ._table = -+ htole32(offsetof(struct poll_packet, config) - offsetof(struct poll_packet, _table_config)), -+ .trackers_mask = htole32((debug_get_bool_option_solarxr_raw_trackers() -+ ? offsetof(struct poll_packet, data_mask) -+ : offsetof(struct poll_packet, synthetic_trackers_mask)) - -+ offsetof(struct poll_packet, config.trackers_mask)), -+ .bone_mask = true, -+ }, -+ .data_mask = -+ { -+ ._table = -+ htole32(offsetof(struct poll_packet, data_mask) - offsetof(struct poll_packet, _table_shared)), -+ .tracker_data = htole32(offsetof(struct poll_packet, synthetic_trackers_mask) - -+ offsetof(struct poll_packet, data_mask.tracker_data)), -+ }, -+ ._table_synthetic_trackers_mask = -+ { -+ htole16(sizeof(poll_packet._table_synthetic_trackers_mask)), -+ htole16(sizeof(poll_packet.synthetic_trackers_mask)), -+ 0, -+ 0, -+ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.rotation) - -+ offsetof(struct poll_packet, synthetic_trackers_mask)), -+ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.position) - -+ offsetof(struct poll_packet, synthetic_trackers_mask)), -+ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.raw_angular_velocity) - -+ offsetof(struct poll_packet, synthetic_trackers_mask)), -+ 0, -+ 0, -+ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.linear_acceleration) - -+ offsetof(struct poll_packet, synthetic_trackers_mask)), -+ }, -+ .synthetic_trackers_mask = -+ { -+ ._table = htole32(offsetof(struct poll_packet, synthetic_trackers_mask) - -+ offsetof(struct poll_packet, _table_synthetic_trackers_mask)), -+ .rotation = true, -+ .position = true, -+ .raw_angular_velocity = true, -+ .linear_acceleration = true, -+ }, -+ }; ++ uint8_t head[sizeof(struct solarxr_ipc_message)]; ++ struct poll_packet ++ { ++ uint32_t _root; ++ uint16_t _table_shared[3]; ++ struct ++ { // table MessageBundle ++ int32_t _table; ++ uint32_t data_feed_msgs; // vector* ++ } bundle; ++ struct ++ { // vector
++ uint32_t length; ++ uint32_t values[1]; // table* ++ } data_feed_msgs; ++ uint16_t _table_data_feed_msgs_0[4]; ++ struct ++ { // table DataFeedMessageHeader ++ int32_t _table; ++ uint32_t message; // table* ++ uint8_t message_type; // enum DataFeedMessage ++ uint8_t _pad[3]; ++ } data_feed_msgs_0; ++ struct ++ { // table PollDataFeed ++ int32_t _table; ++ uint32_t config; // table* ++ } message; ++ uint16_t _table_config[6]; ++ struct ++ { // table DataFeedConfig ++ int32_t _table; ++ uint32_t trackers_mask; // table* ++ bool bone_mask; ++ uint8_t _pad[3]; ++ } config; ++ struct ++ { // table DeviceDataMask ++ int32_t _table; ++ uint32_t tracker_data; // table* ++ } data_mask; ++ uint16_t _table_synthetic_trackers_mask[10]; ++ struct ++ { // table TrackerDataMask ++ int32_t _table; ++ bool rotation, position, raw_angular_velocity, linear_acceleration; ++ } synthetic_trackers_mask; ++ } body; ++ } const poll_packet = ++ { ++ .body = ++ { ++ ._root = htole32(offsetof(struct poll_packet, bundle)), ++ ._table_shared = ++ { ++ htole16(sizeof(poll_packet.body._table_shared)), ++ htole16(8), ++ htole16(4), ++ }, ++ .bundle = ++ { ++ ._table = htole32(offsetof(struct poll_packet, bundle) - ++ offsetof(struct poll_packet, _table_shared)), ++ .data_feed_msgs = htole32(offsetof(struct poll_packet, data_feed_msgs) - ++ offsetof(struct poll_packet, bundle.data_feed_msgs)), ++ }, ++ .data_feed_msgs = ++ { ++ .length = htole32(ARRAY_SIZE(poll_packet.body.data_feed_msgs.values)), ++ .values = {htole32(offsetof(struct poll_packet, data_feed_msgs_0) - ++ offsetof(struct poll_packet, data_feed_msgs.values[0]))}, ++ }, ++ ._table_data_feed_msgs_0 = ++ { ++ htole16(sizeof(poll_packet.body._table_data_feed_msgs_0)), ++ htole16(sizeof(poll_packet.body.data_feed_msgs_0) - ++ sizeof(poll_packet.body.data_feed_msgs_0._pad)), ++ htole16(offsetof(struct poll_packet, data_feed_msgs_0.message_type) - ++ offsetof(struct poll_packet, data_feed_msgs_0)), ++ htole16(offsetof(struct poll_packet, data_feed_msgs_0.message) - ++ offsetof(struct poll_packet, data_feed_msgs_0)), ++ }, ++ .data_feed_msgs_0 = ++ { ++ ._table = htole32(offsetof(struct poll_packet, data_feed_msgs_0) - ++ offsetof(struct poll_packet, _table_data_feed_msgs_0)), ++ .message = htole32(offsetof(struct poll_packet, message) - ++ offsetof(struct poll_packet, data_feed_msgs_0.message)), ++ .message_type = 1, // DataFeedMessage::PollDataFeed ++ }, ++ .message = ++ { ++ ._table = htole32(offsetof(struct poll_packet, message) - ++ offsetof(struct poll_packet, _table_shared)), ++ .config = htole32(offsetof(struct poll_packet, config) - ++ offsetof(struct poll_packet, message.config)), ++ }, ++ ._table_config = ++ { ++ htole16(sizeof(poll_packet.body._table_config)), ++ htole16(sizeof(poll_packet.body.config) - sizeof(poll_packet.body.config._pad)), ++ 0, ++ htole16((device->use_trackers && debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct poll_packet, config.trackers_mask) - ++ offsetof(struct poll_packet, config))), ++ htole16((device->use_trackers && !debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct poll_packet, config.trackers_mask) - ++ offsetof(struct poll_packet, config))), ++ htole16(offsetof(struct poll_packet, config.bone_mask) - ++ offsetof(struct poll_packet, config)), ++ }, ++ .config = ++ { ++ ._table = htole32(offsetof(struct poll_packet, config) - ++ offsetof(struct poll_packet, _table_config)), ++ .trackers_mask = htole32((debug_get_bool_option_solarxr_raw_trackers() ++ ? offsetof(struct poll_packet, data_mask) ++ : offsetof(struct poll_packet, synthetic_trackers_mask)) - ++ offsetof(struct poll_packet, config.trackers_mask)), ++ .bone_mask = true, ++ }, ++ .data_mask = ++ { ++ ._table = htole32(offsetof(struct poll_packet, data_mask) - ++ offsetof(struct poll_packet, _table_shared)), ++ .tracker_data = htole32(offsetof(struct poll_packet, synthetic_trackers_mask) - ++ offsetof(struct poll_packet, data_mask.tracker_data)), ++ }, ++ ._table_synthetic_trackers_mask = ++ { ++ htole16(sizeof(poll_packet.body._table_synthetic_trackers_mask)), ++ htole16(sizeof(poll_packet.body.synthetic_trackers_mask)), ++ 0, ++ 0, ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.rotation) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.position) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.raw_angular_velocity) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ 0, ++ 0, ++ htole16(offsetof(struct poll_packet, synthetic_trackers_mask.linear_acceleration) - ++ offsetof(struct poll_packet, synthetic_trackers_mask)), ++ }, ++ .synthetic_trackers_mask = ++ { ++ ._table = htole32(offsetof(struct poll_packet, synthetic_trackers_mask) - ++ offsetof(struct poll_packet, _table_synthetic_trackers_mask)), ++ .rotation = true, ++ .position = true, ++ .raw_angular_velocity = true, ++ .linear_acceleration = true, ++ }, ++ }, ++ }; + + feeder_send_feedback(&device->feeder, time); -+ ipc_socket_send(&device->socket, (const uint8_t *)&poll_packet, -+ device->use_trackers ? sizeof(poll_packet) : offsetof(struct poll_packet, data_mask)); ++ solarxr_ipc_socket_send_raw( ++ &device->socket, (const uint8_t *)&poll_packet, ++ solarxr_ipc_message_inline((uint8_t *)&poll_packet, ++ device->use_trackers ++ ? sizeof(poll_packet) ++ : sizeof(poll_packet.head) + offsetof(struct poll_packet, data_mask))); + atomic_store(&device->next_sync, time + debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS); +} + @@ -1649,12 +1345,6 @@ index 0000000000..e0dfc2f75a +{ + struct solarxr_device *const device = solarxr_device(xdev); + assert(device != NULL); -+ const int64_t time = os_monotonic_get_ns(); -+ if (time - atomic_load(&device->feeder.last_send) > -+ debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS) { -+ // ensures SlimeVR continues to receive head positions even if no XR app is running -+ feeder_send_feedback(&device->feeder, time); -+ } + + for (uint32_t i = 0; i < device->base.input_count; ++i) { + device->base.inputs[i].timestamp = atomic_load(&device->timestamp); @@ -1703,14 +1393,12 @@ index 0000000000..e0dfc2f75a + none = XRT_BODY_JOINT_NONE_FB; + break; + } -+#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META + case XRT_INPUT_META_FULL_BODY_TRACKING: { + joints = out_value->full_body_skeleton_meta.joints; + joint_count = ARRAY_SIZE(out_value->full_body_skeleton_meta.joints); + none = XRT_FULL_BODY_JOINT_NONE_META; + break; + } -+#endif + default: return XRT_ERROR_NOT_IMPLEMENTED; + } + @@ -1736,7 +1424,6 @@ index 0000000000..e0dfc2f75a + joints[11] = offset_joint(joints[9], XRT_BODY_JOINT_RIGHT_ARM_LOWER_FB, (struct xrt_vec3){device->bones[SOLARXR_BODY_PART_RIGHT_LOWER_ARM].length, 0.f, 0.f}); + joints[12] = offset_joint(joints[10], XRT_BODY_JOINT_LEFT_HAND_WRIST_FB, (struct xrt_vec3){-device->bones[SOLARXR_BODY_PART_LEFT_HAND].length, 0.f, 0.f}); + joints[13] = offset_joint(joints[11], XRT_BODY_JOINT_RIGHT_HAND_WRIST_FB, (struct xrt_vec3){device->bones[SOLARXR_BODY_PART_RIGHT_HAND].length, 0.f, 0.f}); -+#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META + if (body_tracking_type != XRT_INPUT_META_FULL_BODY_TRACKING) { + return XRT_SUCCESS; + } @@ -1746,7 +1433,6 @@ index 0000000000..e0dfc2f75a + joints[17] = offset_joint(joints[15], XRT_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META, (struct xrt_vec3){0.f, -device->bones[SOLARXR_BODY_PART_RIGHT_LOWER_LEG].length, 0.f}); + joints[18] = offset_joint(joints[16], XRT_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META, (struct xrt_vec3){0.f, 0.f, -device->bones[SOLARXR_BODY_PART_LEFT_FOOT].length}); + joints[19] = offset_joint(joints[17], XRT_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META, (struct xrt_vec3){0.f, 0.f, -device->bones[SOLARXR_BODY_PART_RIGHT_FOOT].length}); -+#endif + // clang-format on + return XRT_SUCCESS; +} @@ -1764,14 +1450,12 @@ index 0000000000..e0dfc2f75a + [SOLARXR_BODY_PART_CHEST] = XRT_BODY_JOINT_SPINE_UPPER_FB, + [SOLARXR_BODY_PART_WAIST] = XRT_BODY_JOINT_SPINE_LOWER_FB, + [SOLARXR_BODY_PART_HIP] = XRT_BODY_JOINT_HIPS_FB, -+#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META + [SOLARXR_BODY_PART_LEFT_UPPER_LEG] = XRT_FULL_BODY_JOINT_LEFT_UPPER_LEG_META, + [SOLARXR_BODY_PART_RIGHT_UPPER_LEG] = XRT_FULL_BODY_JOINT_RIGHT_UPPER_LEG_META, + [SOLARXR_BODY_PART_LEFT_LOWER_LEG] = XRT_FULL_BODY_JOINT_LEFT_LOWER_LEG_META, + [SOLARXR_BODY_PART_RIGHT_LOWER_LEG] = XRT_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META, + [SOLARXR_BODY_PART_LEFT_FOOT] = XRT_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META, + [SOLARXR_BODY_PART_RIGHT_FOOT] = XRT_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META, -+#endif + [SOLARXR_BODY_PART_LEFT_LOWER_ARM] = XRT_BODY_JOINT_LEFT_ARM_LOWER_FB, + [SOLARXR_BODY_PART_RIGHT_LOWER_ARM] = XRT_BODY_JOINT_RIGHT_ARM_LOWER_FB, + [SOLARXR_BODY_PART_LEFT_UPPER_ARM] = XRT_BODY_JOINT_LEFT_ARM_UPPER_FB, @@ -1792,13 +1476,11 @@ index 0000000000..e0dfc2f75a + joint_count = ARRAY_SIZE(out_value->body_joint_set_fb.joint_locations); + break; + } -+#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META + case XRT_INPUT_META_FULL_BODY_TRACKING: { + joints = out_value->full_body_joint_set_meta.joint_locations; + joint_count = ARRAY_SIZE(out_value->full_body_joint_set_meta.joint_locations); + break; + } -+#endif + default: return XRT_ERROR_NOT_IMPLEMENTED; + } + @@ -1887,14 +1569,25 @@ index 0000000000..e0dfc2f75a +} + +static struct span -+ipc_socket_receive_blocking(struct ipc_socket *const socket) ++solarxr_ipc_socket_receive_blocking(struct solarxr_ipc_socket *const socket, struct feeder *const feeder) +{ ++ const time_duration_ns timeout = debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS; ++ time_duration_ns time_since_feedback = 0; + do { -+ const uint32_t buffer_len = ipc_socket_receive(socket); ++ if (feeder != NULL) { ++ const timepoint_ns time = os_monotonic_get_ns(); ++ time_since_feedback = time - atomic_load(&feeder->last_send); ++ if (time_since_feedback > timeout) { ++ // ensures SlimeVR continues to receive tracker poses even if no XR app is polling them ++ feeder_send_feedback(feeder, time); ++ time_since_feedback = 0; ++ } ++ } ++ const uint32_t buffer_len = solarxr_ipc_socket_receive(socket); + if (buffer_len != 0) { + return (struct span){buffer_len, socket->buffer}; + } -+ } while (ipc_socket_wait(socket)); ++ } while (solarxr_ipc_socket_wait_timeout(socket, (feeder != NULL) ? timeout - time_since_feedback : -1)); + return (struct span){0}; +} + @@ -1902,7 +1595,8 @@ index 0000000000..e0dfc2f75a +solarxr_network_thread(void *const ptr) +{ + struct solarxr_device *const device = (struct solarxr_device *)ptr; -+ for (struct span buffer; (buffer = ipc_socket_receive_blocking(&device->socket)).length != 0;) { ++ for (struct span buffer; ++ (buffer = solarxr_ipc_socket_receive_blocking(&device->socket, &device->feeder)).length != 0;) { + struct solarxr_message_bundle bundle; + if (!read_solarxr_message_bundle(&bundle, buffer.data, buffer.length, + (const solarxr_message_bundle_t *)buffer.data)) { @@ -1955,18 +1649,22 @@ index 0000000000..e0dfc2f75a + bones |= ((2llu << SOLARXR_BODY_PART_RIGHT_LITTLE_DISTAL) - + (1llu << SOLARXR_BODY_PART_RIGHT_THUMB_PROXIMAL)) * + toggles.right_hand; -+ atomic_store(&device->enabled_bones, bones); ++ ++ const uint64_t old_bones = atomic_exchange(&device->enabled_bones, bones); ++ if (old_bones != bones) { ++ U_LOG_IFL_D(device->socket.log_level, "Bone mask set to 0x%016" PRIx64, bones); ++ } + } + if (bundle.data_feed_msgs.length == 0) { + continue; + } +#if 0 // for latency testing -+ U_LOG_IFL_W(device->socket.log_level, "%.3fus", ((int64_t)os_monotonic_get_ns() - (atomic_load(&device->next_sync) - debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS)) / 1000.); ++ U_LOG_IFL_W(device->socket.log_level, "%.3fus", (os_monotonic_get_ns() - (atomic_load(&device->next_sync) - debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS)) / 1000.); +#endif + atomic_store(&device->next_sync, + device->timestamp + debug_get_num_option_solarxr_sync_delay_ms() * U_TIME_1MS_IN_NS); + os_mutex_lock(&device->mutex); -+ flatbuffers_vector(solarxr_bone_t) bones = {0}; ++ FLATBUFFERS_VECTOR(solarxr_bone_t) bones = {0}; + for (uint32_t i = 0; i < bundle.data_feed_msgs.length; ++i) { + struct solarxr_data_feed_message_header header; + if (!read_solarxr_data_feed_message_header(&header, buffer.data, buffer.length, @@ -2044,7 +1742,7 @@ index 0000000000..e0dfc2f75a + struct solarxr_device *const device = solarxr_device(xdev); + assert(device != NULL); + feeder_destroy(&device->feeder); -+ ipc_socket_destroy(&device->socket); ++ solarxr_ipc_socket_destroy(&device->socket); + if (!pthread_equal(device->thread.thread, pthread_self())) { + os_thread_join(&device->thread); + os_thread_destroy(&device->thread); @@ -2104,11 +1802,7 @@ index 0000000000..e0dfc2f75a + out_xdevs_cap = 1 + MAX_GENERIC_TRACKERS; + } + -+#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META + struct solarxr_device *const device = U_DEVICE_ALLOCATE(struct solarxr_device, U_DEVICE_ALLOC_NO_FLAGS, 2, 0); -+#else -+ struct solarxr_device *const device = U_DEVICE_ALLOCATE(struct solarxr_device, U_DEVICE_ALLOC_NO_FLAGS, 1, 0); -+#endif + device->base.name = XRT_DEVICE_FB_BODY_TRACKING; + device->base.device_type = XRT_DEVICE_TYPE_BODY_TRACKER; + strncpy(device->base.str, "SolarXR IPC Connection", sizeof(device->base.str) - 1); @@ -2121,19 +1815,17 @@ index 0000000000..e0dfc2f75a + .initial_offset = XRT_POSE_IDENTITY, + }; + } -+ device->base.body_tracking_supported = true; ++ device->base.supported.body_tracking = true; + device->base.update_inputs = solarxr_device_update_inputs; + device->base.get_body_skeleton = solarxr_device_get_body_skeleton; + device->base.get_body_joints = solarxr_device_get_body_joints; + device->base.destroy = solarxr_device_destroy; + device->base.inputs[0].name = XRT_INPUT_FB_BODY_TRACKING; -+#ifdef XRT_FEATURE_OPENXR_BODY_TRACKING_FULL_BODY_META + device->base.inputs[1].name = XRT_INPUT_META_FULL_BODY_TRACKING; -+#endif + device->thread.thread = pthread_self(); + const bool use_trackers = (out_xdevs_cap >= 2); + device->use_trackers = use_trackers; -+ ipc_socket_init(&device->socket, debug_get_log_option_solarxr_log()); ++ solarxr_ipc_socket_init(&device->socket, debug_get_log_option_solarxr_log()); + memset(device->tracker_ids, 0xff, sizeof(device->tracker_ids)); + + // `solarxr_device_destroy()` asserts unless both have attempted initialization @@ -2142,222 +1834,239 @@ index 0000000000..e0dfc2f75a + goto fail; + } + -+ if (!ipc_socket_connect(&device->socket, "SlimeVRRpc", "slimevr/SlimeVRRpc", device->base.serial, -+ sizeof(device->base.serial))) { ++ if (!solarxr_ipc_socket_connect(&device->socket, "SlimeVRRpc", "slimevr/SlimeVRRpc", device->base.serial, ++ sizeof(device->base.serial))) { + goto fail; + } + -+ struct request_packet ++ struct + { -+ uint32_t _root; -+ uint16_t _table_bundle[4]; -+ struct -+ { // table MessageBundle -+ int32_t _table; -+ uint32_t data_feed_msgs; // vector* -+ uint32_t rpc_msgs; // vector* -+ } bundle; -+ struct -+ { // vector
-+ uint32_t length; -+ uint32_t values[1]; // table* -+ } rpc_msgs; -+ uint16_t _table_rpc_msgs_0[5]; -+ struct -+ { // table RpcMessageHeader -+ int32_t _table; -+ uint32_t message; // table* -+ uint8_t message_type; // enum RpcMessage -+ uint8_t _pad[3]; -+ } rpc_msgs_0; -+ uint16_t _table_request[2]; -+ struct -+ { // table SettingsRequest -+ int32_t _table; -+ } request; -+ struct -+ { // vector
-+ uint32_t length; -+ uint32_t values[1]; // table* -+ } data_feed_msgs; -+ uint16_t _table_data_feed_msgs_0[4]; -+ struct -+ { // table DataFeedMessageHeader -+ int32_t _table; -+ uint32_t message; // table* -+ uint8_t message_type; // enum DataFeedMessage -+ uint8_t _pad[3]; -+ } data_feed_msgs_0; -+ uint16_t _table_shared[3]; -+ struct -+ { // table PollDataFeed -+ int32_t _table; -+ uint32_t config; // table* -+ } message; -+ uint16_t _table_config[6]; -+ struct -+ { // table DataFeedConfig -+ int32_t _table; -+ uint32_t trackers_mask; // table* -+ bool bone_mask; -+ uint8_t _pad[3]; -+ } config; -+ struct -+ { // table DeviceDataMask -+ int32_t _table; -+ uint32_t tracker_data; // table* -+ } data_mask; -+ uint16_t _table_synthetic_trackers_mask[3]; -+ struct -+ { // table TrackerDataMask -+ int32_t _table; -+ bool info; -+ } synthetic_trackers_mask; -+ } const request_packet = { -+ ._root = htole32(offsetof(struct request_packet, bundle)), -+ ._table_bundle = -+ { -+ htole16(sizeof(request_packet._table_bundle)), -+ htole16(sizeof(request_packet.bundle)), -+ htole16(use_trackers * (offsetof(struct request_packet, bundle.data_feed_msgs) - -+ offsetof(struct request_packet, bundle))), -+ htole16(offsetof(struct request_packet, bundle.rpc_msgs) - offsetof(struct request_packet, bundle)), -+ }, -+ .bundle = -+ { -+ ._table = htole32(offsetof(struct request_packet, bundle) - -+ offsetof(struct request_packet, _table_bundle)), -+ .data_feed_msgs = htole32(use_trackers * (offsetof(struct request_packet, data_feed_msgs) - -+ offsetof(struct request_packet, bundle.data_feed_msgs))), -+ .rpc_msgs = htole32(offsetof(struct request_packet, rpc_msgs) - -+ offsetof(struct request_packet, bundle.rpc_msgs)), -+ }, -+ .rpc_msgs = -+ { -+ .length = htole32(ARRAY_SIZE(request_packet.rpc_msgs.values)), -+ .values = {htole32(offsetof(struct request_packet, rpc_msgs_0) - -+ offsetof(struct request_packet, rpc_msgs.values[0]))}, -+ }, -+ ._table_rpc_msgs_0 = -+ { -+ htole16(sizeof(request_packet._table_rpc_msgs_0)), -+ htole16(sizeof(request_packet.rpc_msgs_0) - sizeof(request_packet.rpc_msgs_0._pad)), -+ 0, -+ htole16(offsetof(struct request_packet, rpc_msgs_0.message_type) - -+ offsetof(struct request_packet, rpc_msgs_0)), -+ htole16(offsetof(struct request_packet, rpc_msgs_0.message) - -+ offsetof(struct request_packet, rpc_msgs_0)), -+ }, -+ .rpc_msgs_0 = -+ { -+ ._table = htole32(offsetof(struct request_packet, rpc_msgs_0) - -+ offsetof(struct request_packet, _table_rpc_msgs_0)), -+ .message = htole32(offsetof(struct request_packet, request) - -+ offsetof(struct request_packet, rpc_msgs_0.message)), -+ .message_type = SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_REQUEST, -+ }, -+ ._table_request = -+ { -+ htole16(sizeof(request_packet._table_request)), -+ htole16(sizeof(request_packet.request)), -+ }, -+ .request = -+ { -+ ._table = htole32(offsetof(struct request_packet, request) - -+ offsetof(struct request_packet, _table_request)), -+ }, -+ .data_feed_msgs = -+ { -+ .length = htole32(ARRAY_SIZE(request_packet.data_feed_msgs.values)), -+ .values = {htole32(offsetof(struct request_packet, data_feed_msgs_0) - -+ offsetof(struct request_packet, data_feed_msgs.values[0]))}, -+ }, -+ ._table_data_feed_msgs_0 = -+ { -+ htole16(sizeof(request_packet._table_data_feed_msgs_0)), -+ htole16(sizeof(request_packet.data_feed_msgs_0) - sizeof(request_packet.data_feed_msgs_0._pad)), -+ htole16(offsetof(struct request_packet, data_feed_msgs_0.message_type) - -+ offsetof(struct request_packet, data_feed_msgs_0)), -+ htole16(offsetof(struct request_packet, data_feed_msgs_0.message) - -+ offsetof(struct request_packet, data_feed_msgs_0)), -+ }, -+ .data_feed_msgs_0 = -+ { -+ ._table = htole32(offsetof(struct request_packet, data_feed_msgs_0) - -+ offsetof(struct request_packet, _table_data_feed_msgs_0)), -+ .message = htole32(offsetof(struct request_packet, message) - -+ offsetof(struct request_packet, data_feed_msgs_0.message)), -+ .message_type = SOLARXR_DATA_FEED_MESSAGE_POLL_DATA_FEED, -+ }, -+ ._table_shared = -+ { -+ htole16(sizeof(request_packet._table_shared)), -+ htole16(8), -+ htole16(4), -+ }, -+ .message = -+ { -+ ._table = htole32(offsetof(struct request_packet, message) - -+ offsetof(struct request_packet, _table_shared)), -+ .config = htole32(offsetof(struct request_packet, config) - -+ offsetof(struct request_packet, message.config)), -+ }, -+ ._table_config = -+ { -+ htole16(sizeof(request_packet._table_config)), -+ htole16(sizeof(request_packet.config) - sizeof(request_packet.config._pad)), -+ 0, -+ htole16((device->use_trackers && debug_get_bool_option_solarxr_raw_trackers()) * -+ (offsetof(struct request_packet, config.trackers_mask) - -+ offsetof(struct request_packet, config))), -+ htole16((device->use_trackers && !debug_get_bool_option_solarxr_raw_trackers()) * -+ (offsetof(struct request_packet, config.trackers_mask) - -+ offsetof(struct request_packet, config))), -+ htole16(offsetof(struct request_packet, config.bone_mask) - -+ offsetof(struct request_packet, config)), -+ }, -+ .config = -+ { -+ ._table = htole32(offsetof(struct request_packet, config) - -+ offsetof(struct request_packet, _table_config)), -+ .trackers_mask = htole32((debug_get_bool_option_solarxr_raw_trackers() -+ ? offsetof(struct request_packet, data_mask) -+ : offsetof(struct request_packet, synthetic_trackers_mask)) - -+ offsetof(struct request_packet, config.trackers_mask)), -+ .bone_mask = true, -+ }, -+ .data_mask = -+ { -+ ._table = htole32(offsetof(struct request_packet, data_mask) - -+ offsetof(struct request_packet, _table_shared)), -+ .tracker_data = htole32(offsetof(struct request_packet, synthetic_trackers_mask) - -+ offsetof(struct request_packet, data_mask.tracker_data)), -+ }, -+ ._table_synthetic_trackers_mask = -+ { -+ htole16(sizeof(request_packet._table_synthetic_trackers_mask)), -+ htole16(sizeof(request_packet.synthetic_trackers_mask)), -+ htole16(offsetof(struct request_packet, synthetic_trackers_mask.info) - -+ offsetof(struct request_packet, synthetic_trackers_mask)), -+ }, -+ .synthetic_trackers_mask = -+ { -+ ._table = htole32(offsetof(struct request_packet, synthetic_trackers_mask) - -+ offsetof(struct request_packet, _table_synthetic_trackers_mask)), -+ .info = true, -+ }, -+ }; ++ uint8_t head[sizeof(struct solarxr_ipc_message)]; ++ struct request_packet ++ { ++ uint32_t _root; ++ uint16_t _table_bundle[4]; ++ struct ++ { // table MessageBundle ++ int32_t _table; ++ uint32_t data_feed_msgs; // vector* ++ uint32_t rpc_msgs; // vector* ++ } bundle; ++ struct ++ { // vector
++ uint32_t length; ++ uint32_t values[1]; // table* ++ } rpc_msgs; ++ uint16_t _table_rpc_msgs_0[5]; ++ struct ++ { // table RpcMessageHeader ++ int32_t _table; ++ uint32_t message; // table* ++ uint8_t message_type; // enum RpcMessage ++ uint8_t _pad[3]; ++ } rpc_msgs_0; ++ uint16_t _table_request[2]; ++ struct ++ { // table SettingsRequest ++ int32_t _table; ++ } request; ++ struct ++ { // vector
++ uint32_t length; ++ uint32_t values[1]; // table* ++ } data_feed_msgs; ++ uint16_t _table_data_feed_msgs_0[4]; ++ struct ++ { // table DataFeedMessageHeader ++ int32_t _table; ++ uint32_t message; // table* ++ uint8_t message_type; // enum DataFeedMessage ++ uint8_t _pad[3]; ++ } data_feed_msgs_0; ++ uint16_t _table_shared[3]; ++ struct ++ { // table PollDataFeed ++ int32_t _table; ++ uint32_t config; // table* ++ } message; ++ uint16_t _table_config[6]; ++ struct ++ { // table DataFeedConfig ++ int32_t _table; ++ uint32_t trackers_mask; // table* ++ bool bone_mask; ++ uint8_t _pad[3]; ++ } config; ++ struct ++ { // table DeviceDataMask ++ int32_t _table; ++ uint32_t tracker_data; // table* ++ } data_mask; ++ uint16_t _table_synthetic_trackers_mask[3]; ++ struct ++ { // table TrackerDataMask ++ int32_t _table; ++ bool info; ++ } synthetic_trackers_mask; ++ } body; ++ } const request_packet = ++ { ++ .body = ++ { ++ ._root = htole32(offsetof(struct request_packet, bundle)), ++ ._table_bundle = ++ { ++ htole16(sizeof(request_packet.body._table_bundle)), ++ htole16(sizeof(request_packet.body.bundle)), ++ htole16(use_trackers * (offsetof(struct request_packet, bundle.data_feed_msgs) - ++ offsetof(struct request_packet, bundle))), ++ htole16(offsetof(struct request_packet, bundle.rpc_msgs) - ++ offsetof(struct request_packet, bundle)), ++ }, ++ .bundle = ++ { ++ ._table = htole32(offsetof(struct request_packet, bundle) - ++ offsetof(struct request_packet, _table_bundle)), ++ .data_feed_msgs = ++ htole32(use_trackers * (offsetof(struct request_packet, data_feed_msgs) - ++ offsetof(struct request_packet, bundle.data_feed_msgs))), ++ .rpc_msgs = htole32(offsetof(struct request_packet, rpc_msgs) - ++ offsetof(struct request_packet, bundle.rpc_msgs)), ++ }, ++ .rpc_msgs = ++ { ++ .length = htole32(ARRAY_SIZE(request_packet.body.rpc_msgs.values)), ++ .values = {htole32(offsetof(struct request_packet, rpc_msgs_0) - ++ offsetof(struct request_packet, rpc_msgs.values[0]))}, ++ }, ++ ._table_rpc_msgs_0 = ++ { ++ htole16(sizeof(request_packet.body._table_rpc_msgs_0)), ++ htole16(sizeof(request_packet.body.rpc_msgs_0) - ++ sizeof(request_packet.body.rpc_msgs_0._pad)), ++ 0, ++ htole16(offsetof(struct request_packet, rpc_msgs_0.message_type) - ++ offsetof(struct request_packet, rpc_msgs_0)), ++ htole16(offsetof(struct request_packet, rpc_msgs_0.message) - ++ offsetof(struct request_packet, rpc_msgs_0)), ++ }, ++ .rpc_msgs_0 = ++ { ++ ._table = htole32(offsetof(struct request_packet, rpc_msgs_0) - ++ offsetof(struct request_packet, _table_rpc_msgs_0)), ++ .message = htole32(offsetof(struct request_packet, request) - ++ offsetof(struct request_packet, rpc_msgs_0.message)), ++ .message_type = SOLARXR_RPC_MESSAGE_TYPE_SETTINGS_REQUEST, ++ }, ++ ._table_request = ++ { ++ htole16(sizeof(request_packet.body._table_request)), ++ htole16(sizeof(request_packet.body.request)), ++ }, ++ .request = ++ { ++ ._table = htole32(offsetof(struct request_packet, request) - ++ offsetof(struct request_packet, _table_request)), ++ }, ++ .data_feed_msgs = ++ { ++ .length = htole32(ARRAY_SIZE(request_packet.body.data_feed_msgs.values)), ++ .values = {htole32(offsetof(struct request_packet, data_feed_msgs_0) - ++ offsetof(struct request_packet, data_feed_msgs.values[0]))}, ++ }, ++ ._table_data_feed_msgs_0 = ++ { ++ htole16(sizeof(request_packet.body._table_data_feed_msgs_0)), ++ htole16(sizeof(request_packet.body.data_feed_msgs_0) - ++ sizeof(request_packet.body.data_feed_msgs_0._pad)), ++ htole16(offsetof(struct request_packet, data_feed_msgs_0.message_type) - ++ offsetof(struct request_packet, data_feed_msgs_0)), ++ htole16(offsetof(struct request_packet, data_feed_msgs_0.message) - ++ offsetof(struct request_packet, data_feed_msgs_0)), ++ }, ++ .data_feed_msgs_0 = ++ { ++ ._table = htole32(offsetof(struct request_packet, data_feed_msgs_0) - ++ offsetof(struct request_packet, _table_data_feed_msgs_0)), ++ .message = htole32(offsetof(struct request_packet, message) - ++ offsetof(struct request_packet, data_feed_msgs_0.message)), ++ .message_type = SOLARXR_DATA_FEED_MESSAGE_POLL_DATA_FEED, ++ }, ++ ._table_shared = ++ { ++ htole16(sizeof(request_packet.body._table_shared)), ++ htole16(8), ++ htole16(4), ++ }, ++ .message = ++ { ++ ._table = htole32(offsetof(struct request_packet, message) - ++ offsetof(struct request_packet, _table_shared)), ++ .config = htole32(offsetof(struct request_packet, config) - ++ offsetof(struct request_packet, message.config)), ++ }, ++ ._table_config = ++ { ++ htole16(sizeof(request_packet.body._table_config)), ++ htole16(sizeof(request_packet.body.config) - sizeof(request_packet.body.config._pad)), ++ 0, ++ htole16((device->use_trackers && debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct request_packet, config.trackers_mask) - ++ offsetof(struct request_packet, config))), ++ htole16((device->use_trackers && !debug_get_bool_option_solarxr_raw_trackers()) * ++ (offsetof(struct request_packet, config.trackers_mask) - ++ offsetof(struct request_packet, config))), ++ htole16(offsetof(struct request_packet, config.bone_mask) - ++ offsetof(struct request_packet, config)), ++ }, ++ .config = ++ { ++ ._table = htole32(offsetof(struct request_packet, config) - ++ offsetof(struct request_packet, _table_config)), ++ .trackers_mask = ++ htole32((debug_get_bool_option_solarxr_raw_trackers() ++ ? offsetof(struct request_packet, data_mask) ++ : offsetof(struct request_packet, synthetic_trackers_mask)) - ++ offsetof(struct request_packet, config.trackers_mask)), ++ .bone_mask = true, ++ }, ++ .data_mask = ++ { ++ ._table = htole32(offsetof(struct request_packet, data_mask) - ++ offsetof(struct request_packet, _table_shared)), ++ .tracker_data = htole32(offsetof(struct request_packet, synthetic_trackers_mask) - ++ offsetof(struct request_packet, data_mask.tracker_data)), ++ }, ++ ._table_synthetic_trackers_mask = ++ { ++ htole16(sizeof(request_packet.body._table_synthetic_trackers_mask)), ++ htole16(sizeof(request_packet.body.synthetic_trackers_mask)), ++ htole16(offsetof(struct request_packet, synthetic_trackers_mask.info) - ++ offsetof(struct request_packet, synthetic_trackers_mask)), ++ }, ++ .synthetic_trackers_mask = ++ { ++ ._table = htole32(offsetof(struct request_packet, synthetic_trackers_mask) - ++ offsetof(struct request_packet, _table_synthetic_trackers_mask)), ++ .info = true, ++ }, ++ }, ++ }; + -+ if (!ipc_socket_send(&device->socket, (const uint8_t *)&request_packet, -+ use_trackers ? sizeof(request_packet) : offsetof(struct request_packet, data_feed_msgs))) { -+ U_LOG_IFL_E(device->socket.log_level, "ipc_socket_send() failed"); ++ if (!solarxr_ipc_socket_send_raw( ++ &device->socket, (const uint8_t *)&request_packet, ++ solarxr_ipc_message_inline((uint8_t *)&request_packet, ++ use_trackers ? sizeof(request_packet) ++ : sizeof(request_packet.head) + ++ offsetof(struct request_packet, data_feed_msgs)))) { ++ U_LOG_IFL_E(device->socket.log_level, "solarxr_ipc_socket_send_raw() failed"); + goto fail; + } + + if (use_trackers) { -+ const struct span buffer = ipc_socket_receive_blocking(&device->socket); ++ const struct span buffer = solarxr_ipc_socket_receive_blocking(&device->socket, NULL); + if (buffer.length == 0) { -+ U_LOG_IFL_E(device->socket.log_level, "ipc_socket_receive() failed"); ++ U_LOG_IFL_E(device->socket.log_level, "solarxr_ipc_socket_receive() failed"); + goto fail; + } + struct solarxr_message_bundle bundle; @@ -2406,7 +2115,11 @@ index 0000000000..e0dfc2f75a + tracker_descs[i] = &header.message.data_feed_update.synthetic_trackers.data[i]; + } + } ++ U_LOG_IFL_I(device->socket.log_level, "Enumerated %" PRIu32 " SolarXR %s trackers", tracker_descs_len, ++ debug_get_bool_option_solarxr_raw_trackers() ? "physical" : "synthetic"); + if (tracker_descs_len > out_xdevs_cap - 1) { ++ U_LOG_IFL_W(device->socket.log_level, "Not enough xdev slots! Omitting %" PRIu32 " trackers", ++ tracker_descs_len - (out_xdevs_cap - 1)); + tracker_descs_len = out_xdevs_cap - 1; + } + for (uint32_t i = 0; i < tracker_descs_len; ++i) { @@ -2419,18 +2132,18 @@ index 0000000000..e0dfc2f75a + + struct solarxr_generic_tracker *const tracker = + U_DEVICE_ALLOCATE(struct solarxr_generic_tracker, U_DEVICE_ALLOC_NO_FLAGS, 1, 0); -+ tracker->base.name = XRT_DEVICE_VIVE_TRACKER; // TODO: use different name here? ++ tracker->base.name = XRT_DEVICE_VIVE_TRACKER; + tracker->base.device_type = XRT_DEVICE_TYPE_GENERIC_TRACKER; + snprintf(tracker->base.str, sizeof(tracker->base.str), "SolarXR Tracker %06x", id); + snprintf(tracker->base.serial, sizeof(tracker->base.serial), "SOLARXR-%06x", id); + tracker->base.tracking_origin = device->base.tracking_origin; -+ tracker->base.orientation_tracking_supported = true; -+ tracker->base.position_tracking_supported = true; ++ tracker->base.supported.orientation_tracking = true; ++ tracker->base.supported.position_tracking = true; + tracker->base.update_inputs = solarxr_generic_tracker_update_inputs; + tracker->base.get_tracked_pose = solarxr_generic_tracker_get_tracked_pose; + tracker->base.destroy = solarxr_generic_tracker_destroy; + tracker->base.inputs[0].name = XRT_INPUT_GENERIC_TRACKER_POSE; -+ m_relation_history_create(&tracker->history); ++ m_relation_history_create(&tracker->history, NULL); + tracker->role = SOLARXR_BODY_PART_NONE; + tracker->parent = device; + tracker->weak_ref = &device->trackers[i]; @@ -2486,14 +2199,15 @@ index 0000000000..e0dfc2f75a +bool +solarxr_device_set_feeder_devices(struct xrt_device *const device, + struct xrt_device *const xdevs[const], -+ const uint32_t xdevs_len) ++ const uint32_t xdev_count) +{ + struct solarxr_device *const solarxr = solarxr_device(device); -+ return (solarxr != NULL) ? feeder_set_devices(&solarxr->feeder, xdevs, xdevs_len, filter_feeder_device) : false; ++ return (solarxr != NULL) ? feeder_set_devices(&solarxr->feeder, xdevs, xdev_count, filter_feeder_device) ++ : false; +} diff --git a/src/xrt/drivers/solarxr/solarxr_interface.h b/src/xrt/drivers/solarxr/solarxr_interface.h new file mode 100644 -index 0000000000..e5f029992f +index 0000000000..15916484ff --- /dev/null +++ b/src/xrt/drivers/solarxr/solarxr_interface.h @@ -0,0 +1,40 @@ @@ -2531,12 +2245,408 @@ index 0000000000..e5f029992f +} + +bool -+solarxr_device_set_feeder_devices(struct xrt_device *solarxr, struct xrt_device *const xdevs[], uint32_t xdevs_len); ++solarxr_device_set_feeder_devices(struct xrt_device *solarxr, struct xrt_device *const xdevs[], uint32_t xdev_count); + + +#ifdef __cplusplus +} +#endif +diff --git a/src/xrt/drivers/solarxr/solarxr_ipc_message.h b/src/xrt/drivers/solarxr/solarxr_ipc_message.h +new file mode 100644 +index 0000000000..0d97b51118 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/solarxr_ipc_message.h +@@ -0,0 +1,74 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#pragma once ++#include ++#include ++ ++struct solarxr_ipc_message ++{ ++ uint32_t length; ++ uint8_t body[]; ++}; ++ ++static inline struct solarxr_ipc_message * ++solarxr_ipc_message_start(uint8_t head[const], const uint8_t *const end) ++{ ++ if ((size_t)(end - head) < sizeof(struct solarxr_ipc_message)) { ++ return NULL; ++ } ++ struct solarxr_ipc_message *const message = (struct solarxr_ipc_message *)head; ++ message->length = 0; ++ return message; ++} ++ ++static inline bool ++solarxr_ipc_message_write(struct solarxr_ipc_message *const message, ++ const uint8_t *const end, ++ const uint8_t data[const], ++ const uint32_t data_len) ++{ ++ if (message == NULL) { ++ return false; ++ } ++ if ((size_t)(end - message->body) < message->length || end - &message->body[message->length] < data_len) { ++ message->length = UINT32_MAX; ++ return false; ++ } ++ memcpy(&message->body[message->length], data, data_len); ++ message->length += data_len; ++ return true; ++} ++ ++static inline uint32_t ++solarxr_ipc_message_end(struct solarxr_ipc_message *const message, uint8_t **const end_out) ++{ ++ if (message == NULL || message->length >= UINT32_MAX - sizeof(*message)) { ++ return 0; ++ } ++ *end_out = &message->body[message->length]; ++ const uint32_t length = sizeof(*message) + message->length; ++ message->length = htole32(length); ++ return length; ++} ++ ++static inline uint32_t ++solarxr_ipc_message_write_single(uint8_t **const head, ++ const uint8_t *const end, ++ const uint8_t data[const], ++ const uint32_t data_len) ++{ ++ struct solarxr_ipc_message *const message = solarxr_ipc_message_start(*head, end); ++ solarxr_ipc_message_write(message, end, data, data_len); ++ return solarxr_ipc_message_end(message, head); ++} ++ ++static inline uint32_t ++solarxr_ipc_message_inline(uint8_t data[const], const uint32_t data_len) ++{ ++ struct solarxr_ipc_message *const message = solarxr_ipc_message_start(data, &data[data_len]); ++ if (message != NULL) { ++ message->length = &data[data_len] - message->body; ++ } ++ return solarxr_ipc_message_end(message, &(uint8_t *){NULL}); ++} +diff --git a/src/xrt/drivers/solarxr/solarxr_ipc_socket.c b/src/xrt/drivers/solarxr/solarxr_ipc_socket.c +new file mode 100644 +index 0000000000..b889a76163 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/solarxr_ipc_socket.c +@@ -0,0 +1,255 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#include "solarxr_ipc_socket.h" ++#include "solarxr_ipc_message.h" ++ ++#include "os/os_time.h" ++#include "shared/ipc_message_channel.h" ++#include "util/u_file.h" ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++static bool ++solarxr_ipc_socket_ensure_capacity(struct solarxr_ipc_socket *const state, const uint32_t capacity) ++{ ++ if (state->buffer_cap >= capacity) { ++ return true; ++ } ++ if (capacity > 0x100000u) { ++ U_LOG_IFL_E(state->log_level, "packet too large"); ++ return false; ++ } ++ uint8_t *const new_buffer = realloc(state->buffer, capacity); ++ if (new_buffer == NULL) { ++ U_LOG_IFL_E(state->log_level, "realloc failed"); ++ return false; ++ } ++ state->buffer = new_buffer; ++ state->buffer_cap = capacity; ++ return true; ++} ++ ++void ++solarxr_ipc_socket_init(struct solarxr_ipc_socket *const state, const enum u_logging_level log_level) ++{ ++ *state = (struct solarxr_ipc_socket){ ++ .ipc_handle = XRT_IPC_HANDLE_INVALID, ++ .log_level = log_level, ++ .timestamp = os_monotonic_get_ns(), ++ }; ++ // optimistic allocation to avoid needless reallocs during receive ++ solarxr_ipc_socket_ensure_capacity(state, 0x1000); ++} ++ ++static void ++solarxr_ipc_socket_close(struct solarxr_ipc_socket *const state) ++{ ++ struct ipc_message_channel channel = { ++ .ipc_handle = atomic_exchange(&state->ipc_handle, XRT_IPC_HANDLE_INVALID), ++ .log_level = state->log_level, ++ }; ++ if (channel.ipc_handle == XRT_IPC_HANDLE_INVALID) { ++ return; ++ } ++ shutdown(channel.ipc_handle, SHUT_RDWR); // unblock `solarxr_ipc_socket_wait_timeout()` ++ _Static_assert(sizeof(state->reference.count) == sizeof(volatile _Atomic(int)), ""); ++ while (atomic_load((volatile _Atomic(int) *)&state->reference.count) != 0) { ++ sched_yield(); ++ } ++ ipc_message_channel_close(&channel); ++} ++ ++void ++solarxr_ipc_socket_destroy(struct solarxr_ipc_socket *const state) ++{ ++ solarxr_ipc_socket_close(state); ++ free(state->buffer); ++ state->buffer = NULL; ++ state->buffer_cap = 0; ++} ++ ++static bool ++path_is_socket(const char path[const]) ++{ ++ struct stat result = {0}; ++ return stat(path, &result) == 0 && S_ISSOCK(result.st_mode); ++} ++ ++bool ++solarxr_ipc_socket_connect(struct solarxr_ipc_socket *const state, ++ const char runtime_path[const], ++ const char fallback_path[const], ++ char path_out[const], ++ const size_t path_cap) ++{ ++ solarxr_ipc_socket_close(state); ++ const xrt_ipc_handle_t ipc_handle = socket(AF_UNIX, SOCK_STREAM, 0); ++ if (ipc_handle == XRT_IPC_HANDLE_INVALID) { ++ U_LOG_IFL_E(state->log_level, "socket() failed"); ++ return false; ++ } ++ struct sockaddr_un addr = { ++ .sun_family = AF_UNIX, ++ }; ++ ssize_t path_len = u_file_get_path_in_runtime_dir(runtime_path, addr.sun_path, sizeof(addr.sun_path)); ++ if (path_len <= 0 || (size_t)path_len >= sizeof(addr.sun_path)) { ++ U_LOG_IFL_E(state->log_level, "u_file_get_path_in_runtime_dir() failed"); ++ goto fail; ++ } ++ if (!path_is_socket(addr.sun_path)) { ++ U_LOG_IFL_W(state->log_level, "path not found: %s", addr.sun_path); ++ const char *env; ++ if ((env = getenv("XDG_DATA_HOME")) != NULL) { ++ path_len = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", env, fallback_path); ++ } else if ((env = getenv("HOME")) != NULL) { ++ path_len = ++ snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/.local/share/%s", env, fallback_path); ++ } else { ++ path_len = 0; ++ } ++ if (path_len <= 0 || (size_t)path_len >= sizeof(addr.sun_path)) { ++ U_LOG_IFL_E(state->log_level, "failed to resolve SlimeVR socket path"); ++ goto fail; ++ } ++ if (!path_is_socket(addr.sun_path)) { ++ U_LOG_IFL_E(state->log_level, "path not found: %s", addr.sun_path); ++ goto fail; ++ } ++ } ++ U_LOG_IFL_I(state->log_level, "Connecting to domain socket: %.*s", (int)path_len, addr.sun_path); ++ if (connect(ipc_handle, (const struct sockaddr *)&addr, sizeof(addr)) != 0) { ++ U_LOG_IFL_E(state->log_level, "connect() failed: %s", strerror(errno)); ++ goto fail; ++ } ++ if (path_cap >= 1) { ++ if ((size_t)path_len >= path_cap) { ++ path_len = path_cap - 1; ++ } ++ memcpy(path_out, addr.sun_path, path_len + 1); ++ } ++ atomic_store(&state->ipc_handle, ipc_handle); ++ return true; ++fail: ++ close(ipc_handle); ++ return false; ++} ++ ++// release reference with `xrt_reference_dec(&state->reference);` ++static bool ++solarxr_ipc_socket_reference_channel(struct solarxr_ipc_socket *const state, ++ struct ipc_message_channel *const channel_out) ++{ ++ xrt_reference_inc(&state->reference); ++ const xrt_ipc_handle_t ipc_handle = atomic_load(&state->ipc_handle); ++ if (ipc_handle == XRT_IPC_HANDLE_INVALID) { ++ xrt_reference_dec(&state->reference); ++ return false; ++ } ++ *channel_out = (struct ipc_message_channel){ ++ .ipc_handle = ipc_handle, ++ .log_level = state->log_level, ++ }; ++ return true; ++} ++ ++bool ++solarxr_ipc_socket_wait_timeout(struct solarxr_ipc_socket *const state, const time_duration_ns timeout) ++{ ++ struct ipc_message_channel channel; ++ if (!solarxr_ipc_socket_reference_channel(state, &channel)) { ++ return false; ++ } ++ struct pollfd fd = {channel.ipc_handle, POLLIN, 0}; ++ const struct timespec timeout_ts = {.tv_sec = timeout / U_TIME_1S_IN_NS, .tv_nsec = timeout % U_TIME_1S_IN_NS}; ++ const bool result = ppoll(&fd, 1, (timeout >= 0) ? &timeout_ts : NULL, NULL) != -1 || errno == EINTR; ++ xrt_reference_dec(&state->reference); ++ return result; ++} ++ ++bool ++solarxr_ipc_socket_send_raw(struct solarxr_ipc_socket *const state, ++ const uint8_t packet[const], ++ const uint32_t packet_len) ++{ ++ struct ipc_message_channel channel; ++ if (!solarxr_ipc_socket_reference_channel(state, &channel)) { ++ return false; ++ } ++ const xrt_result_t result = ipc_send(&channel, packet, packet_len); ++ xrt_reference_dec(&state->reference); ++ return result == XRT_SUCCESS; ++} ++ ++static bool ++recv_nonblock(const struct ipc_message_channel channel, ++ uint8_t buffer[const], ++ uint32_t *const head, ++ const uint32_t buffer_cap) ++{ ++ // TODO: use a platform agnostic function like `ipc_receive()`, but with support for partial reads ++ const ssize_t length = recv(channel.ipc_handle, &buffer[*head], buffer_cap - *head, MSG_DONTWAIT); ++ if (length < 0) { ++ if (errno == EAGAIN) { ++ return true; ++ } ++ U_LOG_IFL_E(channel.log_level, "recv() failed: %s", strerror(errno)); ++ return false; ++ } ++ if (length > buffer_cap - *head) { ++ U_LOG_IFL_E(channel.log_level, "recv() returned invalid length"); ++ return false; ++ } ++ *head += (size_t)length; ++ return true; ++} ++ ++uint32_t ++solarxr_ipc_socket_receive(struct solarxr_ipc_socket *const state) ++{ ++ struct ipc_message_channel channel; ++ if (!solarxr_ipc_socket_reference_channel(state, &channel)) { ++ return 0; ++ } ++ if (state->head == state->buffer_len) { ++ state->buffer_len = 0; ++ state->head = 0; ++ } ++ if (state->buffer_len == 0) { ++ struct solarxr_ipc_message header; ++ if (!solarxr_ipc_socket_ensure_capacity(state, sizeof(header)) || ++ !recv_nonblock(channel, state->buffer, &state->head, sizeof(header))) { ++ goto fail; ++ } ++ if (state->head < sizeof(header)) { ++ goto unref; ++ } ++ memcpy(&header, state->buffer, sizeof(header)); ++ const uint32_t packet_length = le32toh(header.length) - sizeof(header); ++ if (!solarxr_ipc_socket_ensure_capacity(state, packet_length)) { ++ goto fail; ++ } ++ state->buffer_len = packet_length; ++ state->head = 0; ++ state->timestamp = os_monotonic_get_ns(); ++ } ++ if (!recv_nonblock(channel, state->buffer, &state->head, state->buffer_len)) { ++ goto fail; ++ } ++unref: ++ xrt_reference_dec(&state->reference); ++ return (state->head < state->buffer_len) ? 0 : state->buffer_len; ++fail: ++ xrt_reference_dec(&state->reference); ++ solarxr_ipc_socket_destroy(state); ++ return 0; ++} +diff --git a/src/xrt/drivers/solarxr/solarxr_ipc_socket.h b/src/xrt/drivers/solarxr/solarxr_ipc_socket.h +new file mode 100644 +index 0000000000..aaebfdd547 +--- /dev/null ++++ b/src/xrt/drivers/solarxr/solarxr_ipc_socket.h +@@ -0,0 +1,49 @@ ++// Copyright 2025, rcelyte ++// SPDX-License-Identifier: BSL-1.0 ++ ++#pragma once ++#include "util/u_logging.h" ++#include "util/u_time.h" ++#include "xrt/xrt_handles.h" ++ ++#include ++ ++struct solarxr_ipc_socket ++{ ++ _Atomic(xrt_ipc_handle_t) ipc_handle; ++ struct xrt_reference reference; ++ enum u_logging_level log_level; ++ timepoint_ns timestamp; ++ uint32_t head, buffer_len, buffer_cap; ++ uint8_t *buffer; ++}; ++ ++void ++solarxr_ipc_socket_init(struct solarxr_ipc_socket *state, enum u_logging_level log_level); ++ ++void ++solarxr_ipc_socket_destroy(struct solarxr_ipc_socket *state); // thread safe ++ ++bool ++solarxr_ipc_socket_connect(struct solarxr_ipc_socket *state, ++ const char runtime_path[], ++ const char fallback_path[], ++ char path_out[], ++ size_t path_cap); ++ ++bool ++solarxr_ipc_socket_wait_timeout(struct solarxr_ipc_socket *state, time_duration_ns timeout); ++ ++bool ++solarxr_ipc_socket_send_raw(struct solarxr_ipc_socket *state, ++ const uint8_t packet[], ++ uint32_t packet_len); // thread safe ++ ++uint32_t ++solarxr_ipc_socket_receive(struct solarxr_ipc_socket *state); ++ ++static inline bool ++solarxr_ipc_socket_is_connected(struct solarxr_ipc_socket *const state) ++{ ++ return atomic_load(&state->ipc_handle) != XRT_IPC_HANDLE_INVALID; ++} diff --git a/src/xrt/targets/common/CMakeLists.txt b/src/xrt/targets/common/CMakeLists.txt index e2b9ba79d1..1fbf5f436f 100644 --- a/src/xrt/targets/common/CMakeLists.txt @@ -2554,4 +2664,3 @@ index e2b9ba79d1..1fbf5f436f 100644 # -- GitLab - diff --git a/patches/monado/0099-t-common-Load-SolarXR-driver.patch b/patches/monado/0099-t-common-Load-SolarXR-driver.patch index c85a04ff..a23c5a32 100644 --- a/patches/monado/0099-t-common-Load-SolarXR-driver.patch +++ b/patches/monado/0099-t-common-Load-SolarXR-driver.patch @@ -1,4 +1,4 @@ -From 7114d99942608a2f02d45d64d8eac3e1c2ea739c Mon Sep 17 00:00:00 2001 +From 999c18895dc60680b0c4e167b4b89de031020445 Mon Sep 17 00:00:00 2001 From: rcelyte Date: Fri, 23 Aug 2024 20:54:53 +0000 Subject: [PATCH] t/common: Load SolarXR driver @@ -13,15 +13,15 @@ Subject: [PATCH] t/common: Load SolarXR driver 6 files changed, 132 insertions(+) diff --git a/src/xrt/drivers/qwerty/qwerty_device.c b/src/xrt/drivers/qwerty/qwerty_device.c -index 8841413efd..127644bc8b 100644 +index 53949d3b90..e1194bc061 100644 --- a/src/xrt/drivers/qwerty/qwerty_device.c +++ b/src/xrt/drivers/qwerty/qwerty_device.c @@ -315,6 +315,8 @@ qwerty_hmd_create(void) xd->inputs[0].name = XRT_INPUT_GENERIC_HEAD_POSE; -+ xd->orientation_tracking_supported = true; -+ xd->position_tracking_supported = true; ++ xd->supported.orientation_tracking = true; ++ xd->supported.position_tracking = true; xd->update_inputs = u_device_noop_update_inputs; xd->get_tracked_pose = qwerty_get_tracked_pose; xd->get_view_poses = u_device_get_view_poses; @@ -29,8 +29,8 @@ index 8841413efd..127644bc8b 100644 xd->binding_profiles = binding_profiles; xd->binding_profile_count = ARRAY_SIZE(binding_profiles); -+ xd->orientation_tracking_supported = true; -+ xd->position_tracking_supported = true; ++ xd->supported.orientation_tracking = true; ++ xd->supported.position_tracking = true; xd->update_inputs = qwerty_update_inputs; xd->get_tracked_pose = qwerty_get_tracked_pose; xd->set_output = qwerty_set_output; From 377e218782fef63eae69b3ed8b1bb5371b624f69 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Tue, 5 Aug 2025 18:45:44 -0400 Subject: [PATCH 34/42] Use spaces instead of tabs --- server/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 025480ad..4d0bacda 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -34,7 +34,7 @@ set(XRT_FEATURE_WINDOW_PEEK OFF) set(XRT_FEATURE_OPENXR_ACTIVE_ACTION_SET_PRIORITY ON) set(XRT_FEATURE_RENDERDOC ${WIVRN_FEATURE_RENDERDOC}) -set(XRT_FEATURE_OPENXR_BODY_TRACKING_FB ON) +set(XRT_FEATURE_OPENXR_BODY_TRACKING_FB ON) set(XRT_FEATURE_OPENXR_FACE_TRACKING2_FB ON) set(XRT_FEATURE_OPENXR_FACIAL_TRACKING_HTC ON) set(XRT_FEATURE_OPENXR_HAND_TRACKING_EXT ON) From 449a5b5201e029c445eea51a3e7015e710b75223 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Sat, 23 Aug 2025 15:40:01 -0400 Subject: [PATCH 35/42] Remove poo water from default icon --- assets/default_icon.png | Bin 0 -> 3135 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 assets/default_icon.png diff --git a/assets/default_icon.png b/assets/default_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..2efba8b5d3475aaffd30c0b63f31106306fa42db GIT binary patch literal 3135 zcmeHJdrVVT82|38?QLODDe@3`6qO=Gq2P<46lj5>k`6Wz=$5RT@{VzVd?o6V+a4%bRxZN=kRIgPQi5sY_sa~<#O;^IDGikG|4*VDyC zG{f81&p$9Q(9LVs?3v==DFK0Eh6JN&+KOl8Xl?B%_HgkKzqXmHfX`v(L|{U|`53{+ z%oo88&6C0g4e1&*3@1p6#pcjl9!e;)1+-EGP7)MFk|_Ig)DI+|8sp&~%Cb`|XA9Q} z#9MY9qC+CUUBAZ&4r7XYU?i7U-|jk^)HXG@-@bGA-tQf{`wzOFcI%(@{L$NIV01A$ zN9=EP@sTc^Bngtu=)&-g$O%44dHA!&geus}*VzfhTR4KST?b35Y0rSzPW#05joh&l z0^28cG13N={X1dVZ=~$Guot?T!HU4p<`H}dfj(2N=m7o}ZgW6XbRN$NHs$KMBBDX3 zkrci2MrEevfKP`34ETBcoC%FKC#ERZ=W$FzQLYI7*$uT7>nd7{pZ1rZH|%k|)fbd& zsI3e+Ve?4yI3uK!*ORf*;PcQ~WNJ2b+%W^pR_}Y7Y9Cfvb*O($zk25Y^kgL0Usv9k z)@5{SS$1n6vyENaJts?}eyHR2na%}->$rMuw?WSZ#4OUBnU(#jrK~K`{E~5aHTIPZEP@6Ml0!&YBHp4QBvO$kvI;AqEQy@^P8zrt= zWGa-Vdxs4~tup>~IF)geF^$?}1c5^KT5eyZ%v|!GbM*GTU(f&exAbmL)yr(4Y@mB6;ZtC{&Y)3yOGC6d9C_u?h-oSDSwXu}g$S|y_-Zv99+*d@!&Id@Jgi4gH z00tDw(gCFU0X#?m2r2+@SX+2j5sW%miE|^R(8gTa%$PJ3q1Q$&P66QAF^<9hLPr#2 zZ;;QIvF~#n?7YUsv=<#mg-o4X8oD5@`O&YTpVs)iTgSKZ049-GRan;M?i z{oC}fFL5ea-t-Z~@RF6PuE(ouVNG$FtE<^xSTU8UE=aHi2~+$mEPJ-pmVcDYzcOze zxHDxIj%uVq@Z@x(o%FDGjV!3VzlF&idTH>r$H@VB(q5f=o>X8U~FmS9ARW$gKiyczf(P)Z>0#lF8n zWm|NMjuzhTOj~nxclGG4O5UI$F3*d@M}IJ_?TToXGoc-|`Y>z-S9oQ2MMAAqj7}4P MToxle5tfksCnKzg Date: Sun, 24 Aug 2025 09:56:21 -0400 Subject: [PATCH 36/42] Revert "Merge branch 'master' of https://github.com/Vindicus999/WiVRn" This reverts commit 6212dccc2be7dddafb9454be17b3a8a7d222e3cd, reversing changes made to 80e31b642ac3fc6c313a4750687fadb6365b9c10. --- .github/ISSUE_TEMPLATE/bug_report.yml | 26 +- .github/workflows/APK-Release.yml | 7 - .github/workflows/Build.yml | 35 +- .github/workflows/Locales.yml | 12 +- CMakeLists.txt | 114 +- build.gradle | 1 - client/CMakeLists.txt | 29 +- client/application.cpp | 232 +- client/application.h | 95 +- client/configuration.cpp | 62 +- client/configuration.h | 2 - client/decoder/shard_accumulator.cpp | 16 +- client/decoder/shard_accumulator.h | 12 +- client/render/gpu_buffer.h | 5 +- client/render/imgui_impl.cpp | 15 +- client/render/scene_loader.cpp | 2 +- client/render/scene_renderer.cpp | 40 +- client/render/text_rasterizer.cpp | 68 +- client/scene.cpp | 4 +- client/scene.h | 1 + client/scenes/lobby.cpp | 234 +- client/scenes/lobby.h | 18 +- client/scenes/lobby_gui.cpp | 102 +- client/scenes/stream.cpp | 178 +- client/scenes/stream.h | 22 +- client/scenes/stream_gui.cpp | 38 +- client/scenes/stream_network.cpp | 20 +- client/scenes/stream_reprojection.cpp | 150 +- client/scenes/stream_reprojection.h | 14 +- client/scenes/stream_tracking.cpp | 144 +- client/shaders/reprojection.glsl | 51 +- client/shaders/reprojection_vsr.glsl | 5 - client/utils/contains.h | 14 +- client/utils/handle.h | 54 +- client/xr/body_tracker.cpp | 80 - client/xr/body_tracker.h | 43 - client/xr/error_category.cpp | 2 +- client/xr/face_tracker.cpp | 94 - client/xr/face_tracker.h | 40 - client/xr/fb_body_tracker.cpp | 59 +- client/xr/fb_body_tracker.h | 16 +- client/xr/fb_face_tracker2.cpp | 11 +- client/xr/fb_face_tracker2.h | 6 +- client/xr/hand_tracker.cpp | 13 +- client/xr/hand_tracker.h | 4 +- client/xr/htc_body_tracker.cpp | 85 +- client/xr/htc_body_tracker.h | 23 +- client/xr/htc_face_tracker.cpp | 52 +- client/xr/htc_face_tracker.h | 12 +- client/xr/instance.cpp | 17 +- client/xr/instance.h | 2 - client/xr/passthrough.cpp | 29 +- client/xr/passthrough.h | 10 +- client/xr/pico_body_tracker.cpp | 18 +- client/xr/pico_body_tracker.h | 6 +- client/xr/pico_face_tracker.cpp | 259 +- client/xr/pico_face_tracker.h | 15 +- client/xr/session.cpp | 17 +- client/xr/session.h | 4 +- client/xr/system.cpp | 35 +- client/xr/system.h | 38 +- .../reprojection.glsl.inc => xr/xr.h} | 45 +- cmake/AutoOption.cmake | 4 + cmake/GitVersion.cmake | 1 - common/CMakeLists.txt | 5 +- common/application.cpp | 74 +- common/application.h | 6 +- common/utils/load_icon.cpp | 398 +- common/utils/load_icon.h | 12 +- common/utils/steam_app_info.cpp | 3 - common/vk/allocation.h | 6 - common/vk/specialization_constants.h | 84 - common/vk/vk_allocator.cpp | 3 +- common/vk/vk_allocator.h | 3 +- common/wivrn_packets.h | 17 +- common/wivrn_sockets.cpp | 9 +- dashboard/apps.cpp | 2 +- dashboard/io.github.wivrn.wivrn.metainfo.xml | 14 - dashboard/qml/Main.qml | 17 +- dashboard/qml/WizardPage.qml | 1 - dashboard/wivrn_server.cpp | 20 +- docs/translating.md | 2 - external/CMakeLists.txt | 4 - external/imspinner/cimspinner.cpp | 1628 ------ external/imspinner/cimspinner.h | 415 -- external/imspinner/cimspinner_config.h | 11 - external/imspinner/imspinner.h | 4950 ----------------- flake.nix | 1 - flatpak/io.github.wivrn.wivrn.yml.in | 14 +- locale/es/wivrn.po | 6 +- locale/fr/wivrn.po | 224 +- locale/it/wivrn.po | 218 +- locale/pt_BR/wivrn-dashboard.po | 119 +- locale/pt_BR/wivrn.po | 436 +- locale/sk/wivrn-dashboard.po | 212 +- locale/sk/wivrn.po | 235 +- locale/tr/wivrn-dashboard.po | 943 ---- locale/tr/wivrn.po | 612 -- patches/apply.sh | 5 - ...001-c-multi-early-wake-of-compositor.patch | 8 +- ...02-ipc-server-Always-listen-to-stdin.patch | 4 +- .../monado/0003-Use-extern-socket-fd.patch | 4 +- ...Add-storage-usage-to-distortion-mesh.patch | 4 +- ...vironment-blend-mode-selection-logic.patch | 4 +- .../0006-Convert-to-YCbCr-in-Monado.patch | 10 +- .../0007-store-alpha-channel-in-layer-1.patch | 4 +- ...main-allow-custom-pacing-app-factory.patch | 4 +- .../0009-st-oxr-forward-0-refresh-rate.patch | 4 +- ...tortion-with-pixel-aligned-foveation.patch | 143 +- ...a-vk-Track-VK_KHR_video_maintenance1.patch | 64 - ...e-video_maintenance_1-device-feature.patch | 134 - ...-Request-video_maintenance_1-feature.patch | 26 - server/driver/wivrn_comp_target.cpp | 110 +- server/driver/wivrn_controller.cpp | 149 +- server/driver/wivrn_controller.h | 7 - server/driver/wivrn_foveation.cpp | 82 +- server/driver/wivrn_foveation.h | 7 +- server/driver/wivrn_generic_tracker.cpp | 8 +- server/driver/wivrn_generic_tracker.h | 8 +- server/driver/wivrn_hand_interaction.cpp | 109 +- server/driver/wivrn_session.cpp | 89 +- server/driver/wivrn_session.h | 12 +- server/encoder/video_encoder.cpp | 26 + server/encoder/video_encoder.h | 5 + server/encoder/video_encoder_vulkan.cpp | 22 +- server/encoder/video_encoder_vulkan.h | 3 +- server/encoder/video_encoder_vulkan_h264.cpp | 68 +- server/encoder/video_encoder_vulkan_h264.h | 3 +- server/encoder/video_encoder_x264.cpp | 8 +- server/main.cpp | 66 +- server/start_systemd_unit.cpp | 21 +- server/utils/wivrn_vk_bundle.cpp | 11 +- tools/check_messages.sh | 56 + tools/check_po.py | 153 +- tools/wireshark/CMakeLists.txt | 2 +- 135 files changed, 2784 insertions(+), 12225 deletions(-) delete mode 100644 client/shaders/reprojection_vsr.glsl delete mode 100644 client/xr/body_tracker.cpp delete mode 100644 client/xr/body_tracker.h delete mode 100644 client/xr/face_tracker.cpp delete mode 100644 client/xr/face_tracker.h rename client/{shaders/reprojection.glsl.inc => xr/xr.h} (57%) create mode 100644 cmake/AutoOption.cmake delete mode 100644 common/vk/specialization_constants.h delete mode 100644 external/imspinner/cimspinner.cpp delete mode 100644 external/imspinner/cimspinner.h delete mode 100644 external/imspinner/cimspinner_config.h delete mode 100644 external/imspinner/imspinner.h delete mode 100644 locale/tr/wivrn-dashboard.po delete mode 100644 locale/tr/wivrn.po delete mode 100644 patches/monado/0011-a-vk-Track-VK_KHR_video_maintenance1.patch delete mode 100644 patches/monado/0012-a-vk-Expose-video_maintenance_1-device-feature.patch delete mode 100644 patches/monado/0013-c-util-Request-video_maintenance_1-feature.patch create mode 100755 tools/check_messages.sh diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 098f36d2..b9417e68 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -36,33 +36,17 @@ body: validations: required: true - - type: input - attributes: - label: Installation method - description: Describe how WiVRn and OpenComposite/xrizer were installed - placeholder: flatpak --user, flatpak, AUR, Gentoo/Guru, built from sources... - - type: textarea attributes: label: Server Config - description: | - Provide the content of `config.json` for the server. - Located in `${XDG_CONFIG_HOME-${HOME}/.config}/wivrn/config.json` - or `~/.var/app/io.github.wivrn.wivrn/config/wivrn/config.json` for the flatpak version - placeholder: | - { - "encoders": [ - {"codec": "h264"} - ] - } + description: Provide the content of `config.json` for the server. + placeholder: Add the content of config.json here... - type: textarea attributes: label: Server Logs description: Provide the `wivrn-server` output. - placeholder: | - Add the output of the wivrn-server here. - If more than a few lines, prefer file attachment. + placeholder: Add the output of the wivrn-server here... - type: dropdown id: gpu @@ -80,7 +64,7 @@ body: attributes: label: Vulkan Info description: Provide the output of `vulkaninfo --summary` command. - placeholder: Attach the output as a file here. + placeholder: Add the output of vulkaninfo command here... - type: dropdown id: hmd @@ -106,4 +90,4 @@ body: attributes: label: ADB Logs description: Provide the output of `adb logcat` command. - placeholder: Attach the output of adb logcat as a file. + placeholder: Add the output of adb logcat command here... diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 8c5b374e..4eec207d 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -31,13 +31,6 @@ jobs: # repository: 'Vindicus999/WiVRn' # ref: sneed - - name: Prepare Vulkan SDK - uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 - with: - vulkan-query-version: 1.3.296.0 - vulkan-components: Glslang, SPIRV-Tools - vulkan-use-cache: true - - name: set up JDK uses: actions/setup-java@v4 with: diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index a24f9a4e..cbc1e2af 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -33,12 +33,12 @@ jobs: - name: Install dependencies run: > - sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev libboost-all-dev librsvg2-bin libssl-dev libnotify-dev librsvg2-dev libarchive-dev + sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev libboost-all-dev librsvg2-bin libssl-dev libnotify-dev librsvg2-dev - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 with: - vulkan-query-version: 1.3.296.0 - vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools + vulkan-query-version: 1.3.283.0 + vulkan-components: Vulkan-Headers vulkan-use-cache: true - name: Configure CMake @@ -87,8 +87,14 @@ jobs: - name: Install dependencies run: > - apt-get update && apt-get install --yes libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin libssl-dev libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git qcoro-qt6-dev librsvg2-dev libarchive-dev libglm-dev glslang-tools + apt-get update && apt-get install --yes libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin libssl-dev libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git qcoro-qt6-dev librsvg2-dev # runtime: qml6-module-qtqml-workerscript qml6-module-qtquick-dialogs + - name: Prepare Vulkan SDK + uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 + with: + vulkan-query-version: 1.3.283.0 + vulkan-components: Vulkan-Headers + vulkan-use-cache: true - name: Configure CMake run: > @@ -176,8 +182,8 @@ jobs: - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 with: - vulkan-query-version: 1.3.296.0 - vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools + vulkan-query-version: 1.3.283.0 + vulkan-components: Vulkan-Headers vulkan-use-cache: true - name: Install dependencies @@ -186,14 +192,13 @@ jobs: - name: install server dependencies run: > - sudo apt-get update && sudo apt-get install libavahi-glib-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libnotify-dev librsvg2-dev libarchive-dev + sudo apt-get update && sudo apt-get install libavahi-glib-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libnotify-dev librsvg2-dev - name: Configure CMake run: > cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=/usr - -DWIVRN_USE_SYSTEM_OPENXR=OFF --preset everything -DWIVRN_BUILD_DASHBOARD=OFF -DWIVRN_BUILD_DISSECTOR=OFF @@ -288,8 +293,8 @@ jobs: - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 with: - vulkan-query-version: 1.3.296.0 - vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools + vulkan-query-version: 1.3.268.0 + vulkan-components: Vulkan-Headers vulkan-use-cache: true - name: Install dependencies @@ -302,7 +307,6 @@ jobs: -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=/usr --preset ${{ matrix.cmake_preset }} - -DWIVRN_USE_SYSTEM_OPENXR=OFF - name: Build run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} @@ -322,13 +326,6 @@ jobs: with: fetch-depth: 0 - - name: Prepare Vulkan SDK - uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 - with: - vulkan-query-version: 1.3.296.0 - vulkan-components: Glslang, SPIRV-Tools - vulkan-use-cache: true - - name: set up JDK uses: actions/setup-java@v4 with: @@ -470,7 +467,7 @@ jobs: - name: Install dependencies run: | apt update - apt install --yes libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin dpkg-dev pkg-config debhelper-compat build-essential lintian cmake libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git wget libssl-dev qcoro-qt6-dev librsvg2-dev libarchive-dev + apt install --yes libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin dpkg-dev pkg-config debhelper-compat build-essential lintian cmake libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git wget libssl-dev qcoro-qt6-dev librsvg2-dev - uses: actions/checkout@v4 with: diff --git a/.github/workflows/Locales.yml b/.github/workflows/Locales.yml index 722586f6..1cefef9b 100644 --- a/.github/workflows/Locales.yml +++ b/.github/workflows/Locales.yml @@ -9,14 +9,10 @@ jobs: - uses: actions/checkout@v4 - name: Install dependencies - run: | - sudo apt-get update && sudo apt-get install gettext - pip install polib PyGithub + run: sudo apt-get update && sudo apt-get install gettext qt6-base-dev qt6-tools-dev qt6-l10n-tools qtchooser python3-polib - name: Check that .po files are up to date run: | - if [[ "${{github.ref}}" == 'refs/heads/master' ]] ; then - tools/check_po.py --manage-issues --github-repository "${{ github.repository }}" --github-token "${{ github.token }}" - else - tools/check_po.py - fi + qtchooser -install qt6 $(which qmake6) + export QT_SELECT=qt6 + tools/check_messages.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index b87c5bf0..e1f9b1aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,12 +17,13 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) include(FetchContent) include(ExternalProject) include(GNUInstallDirs) +include("cmake/AutoOption.cmake") option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON) -option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" ON) -option(WIVRN_USE_SYSTEM_OPENXR "Use system OpenXR headers" ON) -option(WIVRN_USE_SYSTEMD "Use libsystemd" ON) -option(WIVRN_USE_LIBKTX "Use libktx" ${ANDROID}) +auto_option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" AUTO) +auto_option(WIVRN_USE_SYSTEM_OPENXR "Use system OpenXR headers" AUTO) +auto_option(WIVRN_USE_SYSTEMD "Use libsystemd" AUTO) +auto_option(WIVRN_USE_LIBKTX "Use libktx" AUTO) option(WIVRN_USE_ANDROID_VALIDATION_LAYER "Download the android version of the Vulkan validation layer" OFF) option(WIVRN_BUILD_CLIENT "Build WiVRn client" OFF) option(WIVRN_BUILD_SERVER "Build WiVRn server" ON) @@ -34,12 +35,12 @@ option(WIVRN_BUILD_TEST "Build test binaries" OFF) option(WIVRN_WERROR "Treat warnings as errors" OFF) option(WIVRN_USE_NVENC "Enable nvenc (Nvidia) hardware encoder" ON) -option(WIVRN_USE_VAAPI "Enable vaapi (AMD/Intel) hardware encoder" ON) -option(WIVRN_USE_VULKAN_ENCODE "Enable vulkan video encoder" ON) -option(WIVRN_USE_X264 "Enable x264 software encoder" ON) +auto_option(WIVRN_USE_VAAPI "Enable vaapi (AMD/Intel) hardware encoder" AUTO) +auto_option(WIVRN_USE_VULKAN_ENCODE "Enable vulkan video encoder" AUTO) +auto_option(WIVRN_USE_X264 "Enable x264 software encoder" AUTO) -option(WIVRN_USE_PIPEWIRE "Enable pipewire backend" ON) -option(WIVRN_USE_PULSEAUDIO "Enable pulseaudio backend" OFF) +auto_option(WIVRN_USE_PIPEWIRE "Enable pipewire backend" AUTO) +auto_option(WIVRN_USE_PULSEAUDIO "Enable pulseaudio backend" AUTO) set(OVR_COMPAT_SEARCH_PATH "/opt/xrizer:/usr/local/lib/OpenComposite:/usr/lib/OpenComposite:/opt/OpenComposite:/opt/opencomposite" CACHE STRING "List of places to search for the OpenVR compatibility layer, separated by :") @@ -63,12 +64,6 @@ endif() option(ENABLE_COLOURED_OUTPUT "Always produce ANSI-coloured output (GNU/Clang only)." ON) -if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_SERVER OR WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_DISSECTOR) - set(NEED_COMMON TRUE) -else() - set(NEED_COMMON FALSE) -endif() - if(ENABLE_COLOURED_OUTPUT) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") add_compile_options(-fdiagnostics-color=always) @@ -80,13 +75,19 @@ endif() find_package(PkgConfig REQUIRED) find_package(Vulkan REQUIRED) find_package(Git) -if (NEED_COMMON AND NOT ANDROID) +if (NOT ANDROID) find_package(OpenSSL REQUIRED) endif() include(VulkanVersion) -if (WIVRN_USE_SYSTEM_BOOST AND NEED_COMMON) - if (WIVRN_BUILD_DISSECTOR) +if (WIVRN_USE_SYSTEM_BOOST STREQUAL "AUTO") + if(WIVRN_BUILD_DISSECTOR) + find_package(Boost 1.84.0 COMPONENTS locale url) + else() + find_package(Boost 1.75.0 COMPONENTS locale url) + endif() +elseif(WIVRN_USE_SYSTEM_BOOST STREQUAL "ON") + if(WIVRN_BUILD_DISSECTOR) find_package(Boost 1.84.0 REQUIRED COMPONENTS locale url) else() find_package(Boost 1.75.0 REQUIRED COMPONENTS locale url) @@ -103,30 +104,72 @@ if (WIVRN_BUILD_SERVER) message(FATAL_ERROR "No encoder selected, use at least one of WIVRN_USE_NVENC, WIVRN_USE_VAAPI, WIVRN_USE_VULKAN_ENCODE or WIVRN_USE_X264") endif() - if (WIVRN_USE_VAAPI) + if (WIVRN_USE_VAAPI STREQUAL "AUTO") + pkg_check_modules(LIBAV IMPORTED_TARGET libavcodec libavutil libswscale libavfilter) + pkg_check_modules(LIBDRM IMPORTED_TARGET libdrm) + if (LIBAV_FOUND AND LIBDRM_FOUND) + set(WIVRN_USE_VAAPI ON) + else() + set(WIVRN_USE_VAAPI OFF) + endif() + elseif (WIVRN_USE_VAAPI) pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil libswscale libavfilter) pkg_check_modules(LIBDRM REQUIRED IMPORTED_TARGET libdrm) endif() - if (WIVRN_USE_VULKAN_ENCODE) + if (WIVRN_USE_VULKAN_ENCODE STREQUAL "AUTO") + if (Vulkan_VERSION VERSION_GREATER_EQUAL 1.3.283) + set(WIVRN_USE_VULKAN_ENCODE ON) + else() + set(WIVRN_USE_VULKAN_ENCODE OFF) + endif() + elseif(WIVRN_USE_VULKAN_ENCODE) if (Vulkan_VERSION VERSION_LESS 1.3.283) message(FATAL_ERROR "Vulkan video encode requires 1.3.283, found ${Vulkan_VERSION}") endif() endif() - if (WIVRN_USE_X264) + if (WIVRN_USE_X264 STREQUAL "AUTO") + pkg_check_modules(X264 IMPORTED_TARGET x264) + if (X264_FOUND) + set(WIVRN_USE_X264 ON) + else() + set(WIVRN_USE_X264 OFF) + endif() + elseif (WIVRN_USE_X264) pkg_check_modules(X264 REQUIRED IMPORTED_TARGET x264) endif() - if (WIVRN_USE_SYSTEMD) + if (WIVRN_USE_SYSTEMD STREQUAL "AUTO") + pkg_check_modules(SYSTEMD IMPORTED_TARGET libsystemd) + if (SYSTEMD_FOUND) + set(WIVRN_USE_SYSTEMD ON) + else() + set(WIVRN_USE_SYSTEMD OFF) + endif() + elseif (WIVRN_USE_SYSTEMD) pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd) endif() - if (WIVRN_USE_PIPEWIRE) + if (WIVRN_USE_PIPEWIRE STREQUAL "AUTO") + pkg_check_modules(libpipewire IMPORTED_TARGET libpipewire-0.3) + if (libpipewire_FOUND) + set(WIVRN_USE_PIPEWIRE ON) + else() + set(WIVRN_USE_PIPEWIRE OFF) + endif() + elseif (WIVRN_USE_PIPEWIRE) pkg_check_modules(libpipewire REQUIRED IMPORTED_TARGET libpipewire-0.3) endif() - if (WIVRN_USE_PULSEAUDIO) + if (WIVRN_USE_PULSEAUDIO STREQUAL "AUTO") + pkg_check_modules(libpulse IMPORTED_TARGET libpulse) + if (libpulse_FOUND) + set(WIVRN_USE_PULSEAUDIO ON) + else() + set(WIVRN_USE_PULSEAUDIO OFF) + endif() + elseif (WIVRN_USE_PULSEAUDIO) pkg_check_modules(libpulse REQUIRED IMPORTED_TARGET libpulse) endif() @@ -142,8 +185,7 @@ endif() if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER) pkg_check_modules(librsvg-2.0 REQUIRED IMPORTED_TARGET librsvg-2.0) - find_package(LibArchive REQUIRED) - find_package(PNG REQUIRED) + find_package(PNG) endif() if (WIVRN_BUILD_DASHBOARD) @@ -172,11 +214,23 @@ if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_DASHBOARD) find_package(Gettext REQUIRED) endif() +if (WIVRN_BUILD_CLIENT) + if (WIVRN_USE_LIBKTX STREQUAL "AUTO") + if (ANDROID) + set(WIVRN_USE_LIBKTX ON) + else() + set(WIVRN_USE_LIBKTX OFF) + endif() + endif() +endif() + if (WIVRN_BUILD_CLIENT AND NOT ANDROID) pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil libswscale libavfilter) find_package(Fontconfig REQUIRED) - if (WIVRN_USE_SYSTEM_OPENXR) + if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO") + find_package(OpenXR 1.1.48) + elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON") find_package(OpenXR 1.1.48 REQUIRED) endif() @@ -190,7 +244,9 @@ if(ANDROID) endif() if (WIVRN_BUILD_DISSECTOR) - if (WIVRN_USE_SYSTEM_OPENXR) + if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO") + find_package(OpenXR 1.1.48) + elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON") find_package(OpenXR 1.1.48 REQUIRED) endif() find_package(Wireshark REQUIRED) @@ -248,7 +304,7 @@ FetchContent_Declare(monado ) add_subdirectory(external) -if (NEED_COMMON) +if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_SERVER OR WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_DISSECTOR) add_subdirectory(common) endif() diff --git a/build.gradle b/build.gradle index f9474a0d..16d5e697 100644 --- a/build.gradle +++ b/build.gradle @@ -83,7 +83,6 @@ android { '-DCMAKE_ANDROID_NDK_VERSION=' + ndkVersion, '-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', - '-DWIVRN_USE_SYSTEM_BOOST=OFF', '-DWIVRN_USE_SYSTEM_FREETYPE=OFF', '-DWIVRN_BUILD_CLIENT=ON', '-DWIVRN_BUILD_SERVER=OFF', diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 1c11a214..7c903461 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -13,7 +13,7 @@ if (WIVRN_USE_LIBKTX) FetchContent_MakeAvailable(libktx) endif() -if (NOT WIVRN_USE_SYSTEM_BOOST) +if (NOT BOOST_FOUND) FetchContent_MakeAvailable(boost) endif() @@ -51,7 +51,7 @@ if(ANDROID) else() add_executable(wivrn) - if (WIVRN_USE_SYSTEM_OPENXR) + if (OpenXR_FOUND) target_link_libraries(wivrn OpenXR::openxr_loader OpenXR::headers) else() FetchContent_MakeAvailable(openxr_loader) @@ -91,22 +91,7 @@ file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "*.glsl") target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS}) wivrn_compile_glsl(wivrn ${VULKAN_SHADERS}) -target_link_libraries(wivrn - Boost::locale - Boost::url - EnTT::EnTT - fastgltf - FreetypeHarfbuzz - glm::glm - imspinner - simdjson - spdlog::spdlog - stb - uni-algo - Vulkan::Vulkan - wivrn-common - wivrn-external -) +target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb Boost::url Boost::locale) if (WIVRN_USE_LIBKTX) target_link_libraries(wivrn ktx_read) @@ -122,6 +107,10 @@ if(NOT ANDROID) install(TARGETS wivrn) endif() +target_link_libraries(wivrn simdjson uni-algo wivrn-common wivrn-external) + + + ############################################################################## # Dear ImGui # @@ -151,6 +140,10 @@ target_link_libraries(wivrn-imgui FreetypeHarfbuzz) target_link_libraries(wivrn wivrn-imgui) +############################################################################## +# EnTT +# +target_link_libraries(wivrn EnTT::EnTT) ############################################################################## # Vulkan Validation Layer diff --git a/client/application.cpp b/client/application.cpp index 2e612453..b0433274 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -28,20 +28,16 @@ #include "utils/files.h" #include "vk/check.h" #include "wifi_lock.h" -#include "wivrn_packets.h" #include "xr/actionset.h" #include "xr/check.h" -#include "xr/htc_exts.h" -#include "xr/htc_face_tracker.h" #include "xr/meta_body_tracking_fidelity.h" -#include "xr/to_string.h" +#include "xr/xr.h" #include #include #include #include #include #include -#include #include #include #include @@ -138,7 +134,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/facebook/touch_controller_pro", - .required_extensions = {XR_FB_TOUCH_CONTROLLER_PRO_EXTENSION_NAME}, + .required_extensions = {"XR_FB_touch_controller_pro"}, .max_version = XR_MAKE_VERSION(1, 1, 0), .input_sources = { "/user/hand/left/output/haptic", @@ -251,7 +247,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/meta/touch_controller_plus", - .required_extensions = {XR_META_TOUCH_CONTROLLER_PLUS_EXTENSION_NAME}, + .required_extensions = {"XR_META_touch_controller_plus"}, .max_version = XR_MAKE_VERSION(1, 1, 0), .input_sources = { "/user/hand/left/output/haptic", @@ -352,7 +348,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico_neo3_controller", - .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, + .required_extensions = {"XR_BD_controller_interaction"}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -395,7 +391,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico4_controller", - .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, + .required_extensions = {"XR_BD_controller_interaction"}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -438,7 +434,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico4s_controller", - .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, + .required_extensions = {"XR_BD_controller_interaction"}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -481,7 +477,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/htc/vive_focus3_controller", - .required_extensions = {XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME}, + .required_extensions = {"XR_HTC_vive_focus3_controller_interaction"}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -523,7 +519,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/ext/hand_interaction_ext", - .required_extensions = {XR_EXT_HAND_INTERACTION_EXTENSION_NAME}, + .required_extensions = {"XR_EXT_hand_interaction"}, .input_sources = { "/user/hand/left/input/aim/pose", "/user/hand/left/input/grip/pose", @@ -552,14 +548,11 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/htc/vive_xr_tracker", - .required_extensions = { - XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME, - XR_HTC_PATH_ENUMERATION_EXTENSION_NAME, - }, + .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_EXTENSION_NAME}, + .required_extensions = {"XR_EXT_eye_gaze_interaction"}, .input_sources = { "/user/eyes_ext/input/gaze_ext/pose", }, @@ -724,13 +717,15 @@ void application::initialize_vulkan() spdlog::info("Using Vulkan validation layer"); layers.push_back("VK_LAYER_KHRONOS_validation"); } - bool debug_report_found = false; - bool debug_utils_found = false; #endif std::vector instance_extensions{}; std::unordered_set optional_device_extensions{}; +#ifndef NDEBUG + bool debug_report_found = false; + bool debug_utils_found = false; +#endif spdlog::info("Available Vulkan instance extensions:"); std::vector> extensions; for (vk::ExtensionProperties & i: vk_context.enumerateInstanceExtensionProperties(nullptr)) @@ -739,27 +734,28 @@ void application::initialize_vulkan() #ifndef NDEBUG if (!strcmp(i.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME)) - { debug_report_found = true; - instance_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); - } - if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) and - guess_model() != model::oculus_quest) // Quest 1 lies, the extension won't load - { + if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) debug_utils_found = true; - instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - } #endif } std::ranges::sort(extensions); for (const auto & [extension_name, spec_version]: extensions) spdlog::info(" {} (version {})", extension_name, spec_version); +#ifndef NDEBUG + if (debug_utils_found && debug_report_found) + { + // debug_extensions_found = true; + // spdlog::info("Using debug extensions"); + instance_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); + // instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); + } +#endif + vk_device_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); optional_device_extensions.emplace(VK_IMG_FILTER_CUBIC_EXTENSION_NAME); - optional_device_extensions.emplace(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME); - optional_device_extensions.emplace(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME); #ifdef __ANDROID__ vk_device_extensions.push_back(VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME); @@ -878,7 +874,6 @@ void application::initialize_vulkan() .ppEnabledExtensionNames = vk_device_extensions.data(), .pEnabledFeatures = &device_features, }, - vk::PhysicalDeviceFragmentShadingRateFeaturesKHR{}, #ifdef __ANDROID__ vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR{ .samplerYcbcrConversion = VK_TRUE, @@ -886,22 +881,6 @@ void application::initialize_vulkan() #endif }; - if (utils::contains(vk_device_extensions, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) and - utils::contains(vk_device_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME)) - { - auto [feat, fragment_feat] = vk_physical_device.getFeatures2(); - auto & create_feat = device_create_info.get(); - create_feat.primitiveFragmentShadingRate = fragment_feat.primitiveFragmentShadingRate; - create_feat.attachmentFragmentShadingRate = fragment_feat.attachmentFragmentShadingRate; - spdlog::info("Fragment shading rate features: primitive={} attachment={}", - create_feat.primitiveFragmentShadingRate, - create_feat.attachmentFragmentShadingRate); - } - else - { - device_create_info.unlink(); - } - vk_device = xr_system_id.create_device(vk_physical_device, device_create_info.get()); *vk_queue.lock() = vk_device.getQueue(vk_queue_family_index, 0); @@ -923,16 +902,10 @@ void application::initialize_vulkan() pipeline_cache = vk::raii::PipelineCache(vk_device, pipeline_cache_info); allocator.emplace(VmaAllocatorCreateInfo{ - .physicalDevice = *vk_physical_device, - .device = *vk_device, - .instance = *vk_instance, - }, -#ifndef NDEBUG - debug_utils_found -#else - false -#endif - ); + .physicalDevice = *vk_physical_device, + .device = *vk_device, + .instance = *vk_instance, + }); } void application::log_views() @@ -979,6 +952,8 @@ void application::initialize_actions() { spdlog::debug("Initializing actions"); + auto * htc_body = std::get_if(&body_tracker); + // Build an action set with all possible input sources std::vector action_sets; xr_actionset = xr::actionset(xr_instance, "all_actions", "All actions"); @@ -992,9 +967,7 @@ void application::initialize_actions() std::vector sources; for (auto & profile: interaction_profiles) { - profile.available = std::ranges::all_of(profile.required_extensions, [&](auto & ext) { return xr_instance.has_extension(ext); }) and - profile.min_version <= api_version and - profile.max_version > api_version; + profile.available = utils::contains_all(xr_extensions, profile.required_extensions) and profile.min_version <= api_version and profile.max_version > api_version; if (profile.profile_name.ends_with("khr/simple_controller")) { @@ -1035,15 +1008,15 @@ void application::initialize_actions() } if (add_palms) { - if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or xr_instance.has_extension(XR_KHR_MAINTENANCE1_EXTENSION_NAME)) // - and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") // + if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or utils::contains(xr_extensions, XR_KHR_MAINTENANCE1_EXTENSION_NAME)) // + and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") // and not utils::contains(profile.input_sources, "/user/hand/left/input/grip_surface/pose")) { spdlog::info("Adding grip_surface/pose for interaction profile {}", profile.profile_name); profile.input_sources.push_back("/user/hand/left/input/grip_surface/pose"); profile.input_sources.push_back("/user/hand/right/input/grip_surface/pose"); } - else if (xr_instance.has_extension(XR_EXT_PALM_POSE_EXTENSION_NAME) // + else if (utils::contains(xr_extensions, XR_EXT_PALM_POSE_EXTENSION_NAME) // and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") // and not utils::contains(profile.input_sources, "/user/hand/left/input/palm_ext/pose")) { @@ -1054,15 +1027,14 @@ void application::initialize_actions() } // Dynamically add VIVE XR Trackers to the profile if available - if (utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME) and - xr_instance.has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME)) + if (htc_body && utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME)) { - XrPath tracker_profile = xr_instance.string_to_path("/interaction_profiles/htc/vive_xr_tracker"); - for (const auto & user_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile)) + for (const auto & user_path: htc_body->get_paths()) { - generic_trackers.emplace_back(user_path, nullptr); - for (const auto & input_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile, user_path)) - profile.input_sources.push_back(xr_instance.path_to_string(user_path) + xr_instance.path_to_string(input_path)); + for (const auto & input_path: htc_body->get_paths(user_path)) + { + profile.input_sources.push_back(path_to_string(user_path) + path_to_string(input_path)); + } } } @@ -1110,14 +1082,8 @@ void application::initialize_actions() spaces[size_t(xr::spaces::poke_right)] = xr_session.create_action_space(a); else if (name == "/user/eyes_ext/input/gaze_ext/pose") spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a); - else if (name.contains("/input/entity_htc/pose")) - { - for (auto & [path, action]: generic_trackers) - { - if (name.starts_with(xr_instance.path_to_string(path))) - action = xr_session.create_action_space(a); - } - } + else if (name.contains("/input/entity_htc/pose") && htc_body) + htc_body->add(xr_session.create_action_space(a)); } // Build an action set for each scene @@ -1154,7 +1120,7 @@ void application::initialize_actions() xr_bindings.push_back(XrActionSuggestedBinding{ .action = a, - .binding = xr_instance.string_to_path(k.input_source)}); + .binding = string_to_path(k.input_source)}); } } } @@ -1171,7 +1137,7 @@ void application::initialize_actions() for (const auto & name: profile.input_sources) { - xr_bindings.push_back({actions_by_name[name], xr_instance.string_to_path(name)}); + xr_bindings.push_back({actions_by_name[name], string_to_path(name)}); } try @@ -1191,7 +1157,7 @@ void application::initialize() { // LogLayersAndExtensions assert(!xr_instance); - std::vector xr_extensions; + xr_extensions.clear(); // Required extensions xr_extensions.push_back(XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME); @@ -1264,16 +1230,21 @@ void application::initialize() spdlog::info(" Orientation tracking: {}", (bool)properties.trackingProperties.orientationTracking); spdlog::info(" Position tracking: {}", (bool)properties.trackingProperties.positionTracking); - spdlog::info(" Hand tracking support: {}", xr_system_id.hand_tracking_supported()); + if (utils::contains(xr_extensions, XR_EXT_HAND_TRACKING_EXTENSION_NAME)) + { + XrSystemHandTrackingPropertiesEXT hand_tracking_properties = xr_system_id.hand_tracking_properties(); + spdlog::info(" Hand tracking support: {}", (bool)hand_tracking_properties.supportsHandTracking); + hand_tracking_supported = hand_tracking_properties.supportsHandTracking; + } - if (xr_instance.has_extension(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME)) + if (utils::contains(xr_extensions, XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME)) { XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_properties = xr_system_id.eye_gaze_interaction_properties(); spdlog::info(" Eye gaze support: {}", (bool)eye_gaze_properties.supportsEyeGazeInteraction); eye_gaze_supported = eye_gaze_properties.supportsEyeGazeInteraction; } - if (xr_instance.has_extension(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) + if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) { spdlog::info(" OpenXR post-processing extension support: true"); openxr_post_processing_supported = true; @@ -1281,39 +1252,23 @@ void application::initialize() switch (xr_system_id.passthrough_supported()) { - case xr::passthrough_type::none: + case xr::system::passthrough_type::no_passthrough: spdlog::info(" Passthrough: not supported"); break; - case xr::passthrough_type::bw: + case xr::system::passthrough_type::bw: spdlog::info(" Passthrough: black and white"); break; - case xr::passthrough_type::color: + case xr::system::passthrough_type::color: spdlog::info(" Passthrough: color"); break; } - spdlog::info(" Face tracker: {}", magic_enum::enum_name(xr_system_id.face_tracker_supported())); - spdlog::info(" Body tracker: {}", magic_enum::enum_name(xr_system_id.body_tracker_supported())); - // Log view configurations and blend modes log_views(); initialize_vulkan(); - xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue, vk_queue_family_index); - - spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW); - spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE); - - config.emplace(xr_system_id); - - // HTC face tracker fails if created later - // we can destroy it right away, it actually stores static handles - if (xr_system_id.face_tracker_supported() == xr::face_tracker_type::htc) - { - auto props = xr_system_id.htc_face_tracking_properties(); - xr::htc_face_tracker(xr_instance, xr_session, props.supportEyeFacialTracking, props.supportLipFacialTracking); - } + xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue_family_index); { auto spaces = xr_session.get_reference_spaces(); @@ -1322,6 +1277,70 @@ void application::initialize() spdlog::info(" {}", xr::to_string(i)); } + spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW); + spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE); + + config.emplace(xr_system_id); + + if (hand_tracking_supported) + { + left_hand = xr_session.create_hand_tracker(XR_HAND_LEFT_EXT); + right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT); + } + + if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME)) + { + XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties(); + spdlog::info(" FB face tracking support: {}", (bool)fb_face2_properties.supportsVisualFaceTracking); + if (fb_face2_properties.supportsVisualFaceTracking) + face_tracker.emplace(xr_instance, xr_session); + } + + if (std::holds_alternative(face_tracker) && utils::contains(xr_extensions, XR_HTC_FACIAL_TRACKING_EXTENSION_NAME)) + { + XrSystemFacialTrackingPropertiesHTC htc_face_properties = xr_system_id.htc_face_tracking_properties(); + spdlog::info(" HTC eye tracking support: {}", (bool)htc_face_properties.supportEyeFacialTracking); + spdlog::info(" HTC lip tracking support: {}", (bool)htc_face_properties.supportLipFacialTracking); + if (htc_face_properties.supportEyeFacialTracking || htc_face_properties.supportLipFacialTracking) + face_tracker.emplace(xr_instance, xr_session, htc_face_properties.supportEyeFacialTracking, htc_face_properties.supportLipFacialTracking); + } + + if (std::holds_alternative(face_tracker) && eye_gaze_supported) + { + switch (guess_model()) + { + case model::pico_4_pro: + case model::pico_4_enterprise: + spdlog::info(" PICO face tracking support: true"); + face_tracker.emplace(xr_instance, xr_session); + break; + default: + break; + } + } + + if (utils::contains_all(xr_extensions, std::array{XR_FB_BODY_TRACKING_EXTENSION_NAME, XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME, XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME})) + { + XrSystemBodyTrackingPropertiesFB fb_body_properties = xr_system_id.fb_body_tracking_properties(); + spdlog::info(" FB body tracking support: {}", (bool)fb_body_properties.supportsBodyTracking); + if (fb_body_properties.supportsBodyTracking) + body_tracker.emplace(xr_instance, xr_session); + } + + if (std::holds_alternative(body_tracker) && utils::contains_all(xr_extensions, std::array{XR_HTC_PATH_ENUMERATION_EXTENSION_NAME, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME})) + { + spdlog::info(" HTC body tracking support: true"); + body_tracker.emplace(xr_instance, xr_session); + } + + if (std::holds_alternative(body_tracker) && utils::contains(xr_extensions, XR_BD_BODY_TRACKING_EXTENSION_NAME)) + { + XrSystemBodyTrackingPropertiesBD bd_body_properties = xr_system_id.bd_body_tracking_properties(); + spdlog::info(" PICO body tracking support: {}", (bool)bd_body_properties.supportsBodyTracking); + if (bd_body_properties.supportsBodyTracking) + body_tracker.emplace(xr_instance, xr_session); + } + vk::CommandPoolCreateInfo cmdpool_create_info; cmdpool_create_info.queueFamilyIndex = vk_queue_family_index; cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer; @@ -1856,6 +1875,13 @@ void application::poll_events() exit_requested = true; } break; + case XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED: { + if (auto * htc_body = std::get_if(&body_tracker)) + { + htc_body->update_active(); + } + } + break; case XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING: break; case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED: { diff --git a/client/application.h b/client/application.h index 368983fa..cb17f87e 100644 --- a/client/application.h +++ b/client/application.h @@ -28,11 +28,14 @@ #include "utils/thread_safe.h" #include "vk/vk_allocator.h" #include "wifi_lock.h" -#include "xr/actionset.h" -#include "xr/instance.h" -#include "xr/session.h" -#include "xr/swapchain.h" -#include "xr/system.h" +#include "xr/fb_body_tracker.h" +#include "xr/fb_face_tracker2.h" +#include "xr/hand_tracker.h" +#include "xr/htc_body_tracker.h" +#include "xr/htc_face_tracker.h" +#include "xr/pico_body_tracker.h" +#include "xr/pico_face_tracker.h" +#include "xr/xr.h" #include #include #include @@ -123,7 +126,12 @@ class application : public singleton xr::actionset xr_actionset; std::vector> actions; - std::vector> generic_trackers; + bool hand_tracking_supported = false; + xr::hand_tracker left_hand; + xr::hand_tracker right_hand; + + std::variant face_tracker; + std::variant body_tracker; bool eye_gaze_supported = false; @@ -133,6 +141,7 @@ class application : public singleton bool session_focused = false; bool session_visible = false; bool debug_extensions_found = false; + std::vector xr_extensions; std::vector vk_device_extensions; std::atomic exit_requested = false; std::filesystem::path config_path; @@ -262,6 +271,16 @@ public: return std::make_pair(position, orientation); } + static XrPath string_to_path(const std::string & s) + { + return instance().xr_instance.string_to_path(s); + } + + static std::string path_to_string(XrPath p) + { + return instance().xr_instance.path_to_string(p); + } + void run(); static void push_scene(std::shared_ptr); @@ -332,6 +351,16 @@ public: // #endif } + static XrTime now() + { + return instance().xr_instance.now(); + } + + static uint32_t queue_family_index() + { + return instance().vk_queue_family_index; + } + static thread_safe & get_queue() { return instance().vk_queue; @@ -347,21 +376,26 @@ public: return intent; } + static vk::raii::PhysicalDevice & get_physical_device() + { + return instance().vk_physical_device; + } + static const vk::PhysicalDeviceProperties & get_physical_device_properties() { return instance().physical_device_properties; } + static vk::raii::Device & get_device() + { + return instance().vk_device; + } + static vk::raii::Instance & get_vulkan_instance() { return instance().vk_instance; } - static xr::system & get_system() - { - return instance().xr_system_id; - } - static vk::raii::PipelineCache & get_pipeline_cache() { return instance().pipeline_cache; @@ -382,6 +416,21 @@ public: return instance().last_scene_cpu_time; } + static bool get_hand_tracking_supported() + { + return instance().hand_tracking_supported; + } + + static bool get_face_tracking_supported() + { + return !std::holds_alternative(instance().face_tracker); + } + + static bool get_body_tracking_supported() + { + return !std::holds_alternative(instance().body_tracker); + } + static bool get_eye_gaze_supported() { return instance().eye_gaze_supported; @@ -392,9 +441,29 @@ public: return instance().openxr_post_processing_supported; } - static auto & get_generic_trackers() + static xr::hand_tracker & get_left_hand() { - return instance().generic_trackers; + return instance().left_hand; + } + + static xr::hand_tracker & get_right_hand() + { + return instance().right_hand; + } + + static auto & get_face_tracker() + { + return instance().face_tracker; + } + + static auto & get_body_tracker() + { + return instance().body_tracker; + } + + static const std::vector & get_xr_extensions() + { + return instance().xr_extensions; } static const std::vector & get_vk_device_extensions() diff --git a/client/configuration.cpp b/client/configuration.cpp index a8b2bf09..abe7f15e 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -82,8 +82,6 @@ bool configuration::check_feature(feature f) const { std::lock_guard lock(mutex); - auto & system = application::get_system(); - auto it = features.find(f); if (it == features.end()) return false; @@ -96,7 +94,7 @@ bool configuration::check_feature(feature f) const case feature::microphone: break; case feature::hand_tracking: - if (not system.hand_tracking_supported()) + if (not application::get_hand_tracking_supported()) return false; break; case feature::eye_gaze: @@ -104,12 +102,50 @@ bool configuration::check_feature(feature f) const return false; break; case feature::face_tracking: - if (system.face_tracker_supported() == xr::face_tracker_type::none) - return false; + switch (guess_model()) + { + case model::htc_vive_focus_3: + case model::htc_vive_focus_vision: + case model::htc_vive_xr_elite: + if (not std::holds_alternative(application::get_face_tracker())) + return false; + break; + case model::pico_4_pro: + case model::pico_4_enterprise: + if (not std::holds_alternative(application::get_face_tracker())) + return false; + break; + default: + if (not std::holds_alternative(application::get_face_tracker())) + return false; + break; + } break; case feature::body_tracking: - if (system.body_tracker_supported() == xr::body_tracker_type::none) - return false; + switch (guess_model()) + { + case model::meta_quest_3: + case model::meta_quest_3s: + if (not std::holds_alternative(application::get_body_tracker())) + return false; + break; + case model::htc_vive_focus_3: + case model::htc_vive_xr_elite: + case model::htc_vive_focus_vision: + if (not std::holds_alternative(application::get_body_tracker())) + return false; + break; + case model::pico_neo_3: + case model::pico_4: + case model::pico_4s: + case model::pico_4_pro: + case model::pico_4_enterprise: + if (not std::holds_alternative(application::get_body_tracker())) + return false; + break; + default: + break; + } break; } } @@ -145,8 +181,8 @@ void configuration::set_feature(feature f, bool state) configuration::configuration(xr::system & system) { - passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color; - features[feature::hand_tracking] = system.hand_tracking_supported(); + passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; + features[feature::hand_tracking] = application::get_hand_tracking_supported(); try { simdjson::dom::parser parser; @@ -178,9 +214,6 @@ configuration::configuration(xr::system & system) if (auto val = root["resolution_scale"]; val.is_double()) resolution_scale = val.get_double(); - if (auto val = root["enable_stream_gui"]; val.is_bool()) - enable_stream_gui = val.get_bool(); - if (auto val = root["sgsr"]; val.is_object()) parse_sgsr_options(val.get_object()); @@ -207,7 +240,7 @@ configuration::configuration(xr::system & system) features[i] = val.get_bool(); } - if (system.passthrough_supported() == xr::passthrough_type::none) + if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough) passthrough_enabled = false; if (auto val = root["override_foveation_enable"]; val.is_bool()) @@ -233,7 +266,7 @@ configuration::configuration(xr::system & system) resolution_scale = 1.4; sgsr = {}; openxr_post_processing = {}; - passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color; + passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; } } @@ -332,7 +365,6 @@ void configuration::save() json << ",\"mic_unprocessed_audio\":" << std::boolalpha << mic_unprocessed_audio; json << ",\"fb_lower_body\":" << std::boolalpha << fb_lower_body; json << ",\"fb_hip\":" << std::boolalpha << fb_hip; - json << ",\"enable_stream_gui\":" << std::boolalpha << enable_stream_gui; for (auto & [key, value]: features) json << "," << key << ":" << std::boolalpha << value; json << ",\"virtual_keyboard_layout\":" << json_string(virtual_keyboard_layout); diff --git a/client/configuration.h b/client/configuration.h index a0f6ecad..8d34faae 100644 --- a/client/configuration.h +++ b/client/configuration.h @@ -56,8 +56,6 @@ public: bool fb_lower_body = false; bool fb_hip = true; - bool enable_stream_gui = true; - // Snapdragon Game Super Resolution struct sgsr_settings { diff --git a/client/decoder/shard_accumulator.cpp b/client/decoder/shard_accumulator.cpp index 900c05ee..6b6106ce 100644 --- a/client/decoder/shard_accumulator.cpp +++ b/client/decoder/shard_accumulator.cpp @@ -18,9 +18,9 @@ */ #include "shard_accumulator.h" -#include "scenes/stream.h" // IWYU pragma: keep +#include "application.h" +#include "scenes/stream.h" #include "spdlog/spdlog.h" -#include "xr/instance.h" namespace wivrn { @@ -63,10 +63,10 @@ static bool is_complete(const shard_set & shards) return true; } -std::optional shard_set::insert(data_shard && shard, xr::instance & instance) +std::optional shard_set::insert(data_shard && shard) { if (empty()) - feedback.received_first_packet = instance.now(); + feedback.received_first_packet = application::now(); auto idx = shard.shard_idx; if (idx >= data.size()) @@ -121,12 +121,12 @@ void shard_accumulator::push_shard(video_stream_data_shard && shard) } else if (frame_diff == 0) { - auto shard_idx = current.insert(std::move(shard), instance); + auto shard_idx = current.insert(std::move(shard)); try_submit_frame(shard_idx); } else if (frame_diff == 1) { - next.insert(std::move(shard), instance); + next.insert(std::move(shard)); if (is_complete(next)) { debug_why_not_sent(current); @@ -191,7 +191,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx) if (not frame_complete) return; - current.feedback.received_last_packet = instance.now(); + current.feedback.received_last_packet = application::now(); current.feedback.sent_to_decoder = current.feedback.received_last_packet; data_shard::timing_info_t timing_info = data_shards.back()->timing_info.value_or(data_shard::timing_info_t{}); current.feedback.encode_begin = timing_info.encode_begin; @@ -216,7 +216,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx) void shard_accumulator::send_feedback(wivrn::from_headset::feedback & feedback) { if (not feedback.received_last_packet) - feedback.received_first_packet = instance.now(); + feedback.received_first_packet = application::now(); auto scene = weak_scene.lock(); if (scene) scene->send_feedback(feedback); diff --git a/client/decoder/shard_accumulator.h b/client/decoder/shard_accumulator.h index 406c0c49..4777de7f 100644 --- a/client/decoder/shard_accumulator.h +++ b/client/decoder/shard_accumulator.h @@ -34,11 +34,6 @@ using decoder_impl = ::wivrn::ffmpeg::decoder; #include #include -namespace xr -{ -class instance; -} - namespace wivrn { @@ -55,7 +50,7 @@ public: void reset(uint64_t frame_index); bool empty() const; - std::optional insert(data_shard &&, xr::instance & instance); + std::optional insert(data_shard &&); wivrn::from_headset::feedback feedback{}; @@ -75,13 +70,11 @@ private: shard_set current; shard_set next; std::weak_ptr weak_scene; - xr::instance & instance; public: explicit shard_accumulator( vk::raii::Device & device, vk::raii::PhysicalDevice & physical_device, - xr::instance & instance, const wivrn::to_headset::video_stream_description::item & description, float fps, std::weak_ptr scene, @@ -89,8 +82,7 @@ public: decoder(std::make_shared(device, physical_device, description, fps, stream_index, scene, this)), current(stream_index), next(stream_index), - weak_scene(scene), - instance(instance) + weak_scene(scene) { next.reset(1); } diff --git a/client/render/gpu_buffer.h b/client/render/gpu_buffer.h index 892dc3fb..7f03c03e 100644 --- a/client/render/gpu_buffer.h +++ b/client/render/gpu_buffer.h @@ -18,6 +18,7 @@ #pragma once +#include "application.h" #include "utils/alignment.h" #include "vk/allocation.h" #include @@ -114,10 +115,10 @@ public: } } - buffer_allocation copy_to_gpu(vk::raii::Device & device) + buffer_allocation copy_to_gpu() { buffer_allocation gpu_buffer{ - device, + application::get_device(), vk::BufferCreateInfo{ .size = bytes.size(), .usage = usage}, diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index 75556eca..53d59862 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -345,9 +345,9 @@ imgui_context::imgui_context( ImGui_ImplVulkan_InitInfo init_info = { .Instance = *application::get_vulkan_instance(), - .PhysicalDevice = *physical_device, - .Device = *device, - .QueueFamily = queue_family_index, + .PhysicalDevice = *application::get_physical_device(), + .Device = *application::get_device(), + .QueueFamily = application::queue_family_index(), .Queue = *queue.get_unsafe(), .RenderPass = *renderpass, .MinImageCount = 2, @@ -718,7 +718,7 @@ void imgui_context::new_frame(XrTime display_time) ImPlot::SetCurrentContext(plot_context); if (last_display_time) - io.DeltaTime = std::clamp((display_time - last_display_time) * 1e-9f, 0.001f, 0.0166f); + io.DeltaTime = std::min((display_time - last_display_time) * 1e-9f, 0.0166f); last_display_time = display_time; // Uses the window list from last frame @@ -1099,13 +1099,6 @@ ImTextureID imgui_context::load_texture(const std::string & filename) void imgui_context::free_texture(ImTextureID texture) { - // Make sure we are done using the texture - std::vector fences; - for (auto & f: command_buffers) - fences.push_back(*f.fence); - if (auto result = device.waitForFences(fences, true, 1'000'000'000); result != vk::Result::eSuccess) - spdlog::error("vkWaitForfences: {}", vk::to_string(result)); - textures.erase(texture); } diff --git a/client/render/scene_loader.cpp b/client/render/scene_loader.cpp index 07ceddfe..66ba86a4 100644 --- a/client/render/scene_loader.cpp +++ b/client/render/scene_loader.cpp @@ -785,7 +785,7 @@ entt::registry scene_loader::operator()(const std::filesystem::path & gltf_path) // Copy the staging buffer to the GPU spdlog::debug("Uploading scene data ({} bytes) to GPU memory", staging_buffer.size()); - auto buffer = std::make_shared(staging_buffer.copy_to_gpu(device)); + auto buffer = std::make_shared(staging_buffer.copy_to_gpu()); for (auto & i: materials) i->buffer = buffer; diff --git a/client/render/scene_renderer.cpp b/client/render/scene_renderer.cpp index da28ec8f..d944c559 100644 --- a/client/render/scene_renderer.cpp +++ b/client/render/scene_renderer.cpp @@ -28,7 +28,6 @@ #include "vk/allocation.h" #include "vk/pipeline.h" #include "vk/shader.h" -#include "vk/specialization_constants.h" #include #include #include @@ -536,11 +535,34 @@ vk::raii::Pipeline scene_renderer::create_pipeline(const pipeline_info & info) auto vertex_shader = load_shader(device, info.shader_name + ".vert"); auto fragment_shader = load_shader(device, info.shader_name + ".frag"); - auto specialization = make_specialization_constants( - int32_t(info.nb_texcoords), - VkBool32(info.dithering), - VkBool32(info.alpha_cutout), - VkBool32(info.skinning)); + std::array specialization_constants_desc{ + vk::SpecializationMapEntry{ + .constantID = 0, + .offset = offsetof(pipeline_info, nb_texcoords), + .size = sizeof(int32_t), + }, + vk::SpecializationMapEntry{ + .constantID = 1, + .offset = offsetof(pipeline_info, dithering), + .size = sizeof(VkBool32), + }, + vk::SpecializationMapEntry{ + .constantID = 2, + .offset = offsetof(pipeline_info, alpha_cutout), + .size = sizeof(VkBool32), + }, + vk::SpecializationMapEntry{ + .constantID = 3, + .offset = offsetof(pipeline_info, skinning), + .size = sizeof(VkBool32), + }}; + + vk::SpecializationInfo specialization{ + .mapEntryCount = specialization_constants_desc.size(), + .pMapEntries = specialization_constants_desc.data(), + .dataSize = sizeof(pipeline_info), + .pData = &info, + }; return vk::raii::Pipeline{ device, @@ -551,14 +573,14 @@ vk::raii::Pipeline scene_renderer::create_pipeline(const pipeline_info & info) .stage = vk::ShaderStageFlagBits::eVertex, .module = *vertex_shader, .pName = "main", - .pSpecializationInfo = specialization, + .pSpecializationInfo = &specialization, }, vk::PipelineShaderStageCreateInfo{ .stage = vk::ShaderStageFlagBits::eFragment, .module = *fragment_shader, .pName = "main", - .pSpecializationInfo = specialization, + .pSpecializationInfo = &specialization, }, }, @@ -775,7 +797,7 @@ void scene_renderer::update_material_descriptor_set(renderer::material & materia device.updateDescriptorSets(write_ds, {}); } -[[maybe_unused]] static void print_scene_hierarchy(const entt::registry & scene, entt::entity root = entt::null, int level = 0) +static void print_scene_hierarchy(const entt::registry & scene, entt::entity root = entt::null, int level = 0) { if (level == 0) spdlog::info("Node hierarchy:"); diff --git a/client/render/text_rasterizer.cpp b/client/render/text_rasterizer.cpp index ac0f7a83..d206aa15 100644 --- a/client/render/text_rasterizer.cpp +++ b/client/render/text_rasterizer.cpp @@ -139,42 +139,46 @@ text_rasterizer::text_rasterizer(vk::raii::Device & device, vk::raii::PhysicalDe image_allocation text_rasterizer::create_image(vk::Extent2D size) { - return {device, - vk::ImageCreateInfo{ - .imageType = vk::ImageType::e2D, - .format = text::format, - .extent = { - .width = size.width, - .height = size.height, - .depth = 1, - }, - .mipLevels = 1, - .arrayLayers = 1, - .samples = vk::SampleCountFlagBits::e1, - .tiling = vk::ImageTiling::eOptimal, - .usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst, - .sharingMode = vk::SharingMode::eExclusive, - .initialLayout = vk::ImageLayout::eUndefined, - }, - VmaAllocationCreateInfo{ - .flags = 0, - .usage = VMA_MEMORY_USAGE_AUTO, - }, - "text_rasterizer image"}; + image_allocation alloc{device, + vk::ImageCreateInfo{ + .imageType = vk::ImageType::e2D, + .format = text::format, + .extent = { + .width = size.width, + .height = size.height, + .depth = 1, + }, + .mipLevels = 1, + .arrayLayers = 1, + .samples = vk::SampleCountFlagBits::e1, + .tiling = vk::ImageTiling::eOptimal, + .usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst, + .sharingMode = vk::SharingMode::eExclusive, + .initialLayout = vk::ImageLayout::eUndefined, + }, + VmaAllocationCreateInfo{ + .flags = 0, + .usage = VMA_MEMORY_USAGE_AUTO, + }}; + + application::set_debug_reports_name(alloc, "text_rasterizer image"); + return alloc; } buffer_allocation text_rasterizer::create_buffer(size_t size) { - return {device, - vk::BufferCreateInfo{ - .size = size, - .usage = vk::BufferUsageFlagBits::eTransferSrc, - }, - VmaAllocationCreateInfo{ - .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT, - .usage = VMA_MEMORY_USAGE_AUTO, - }, - "text_rasterizer buffer"}; + buffer_allocation alloc{device, + vk::BufferCreateInfo{ + .size = size, + .usage = vk::BufferUsageFlagBits::eTransferSrc, + }, + VmaAllocationCreateInfo{ + .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT, + .usage = VMA_MEMORY_USAGE_AUTO, + }}; + application::set_debug_reports_name(alloc, "text_rasterizer buffer"); + + return alloc; } text_rasterizer::~text_rasterizer() diff --git a/client/scene.cpp b/client/scene.cpp index 684922ee..feeb29fe 100644 --- a/client/scene.cpp +++ b/client/scene.cpp @@ -51,6 +51,8 @@ scene::scene(key, const meta & current_meta, std::span support queue_family_index(application::instance().vk_queue_family_index), current_meta(current_meta) { + passthrough_supported = system.passthrough_supported(); + swapchain_format = vk::Format::eUndefined; spdlog::info("Supported swapchain formats:"); @@ -441,7 +443,7 @@ std::pair scene::load_gltf(const std::filesyst node.layer_mask = layer_mask; assert(renderer); - scene_loader loader(device, physical_device, queue, queue_family_index, renderer->get_default_material()); + scene_loader loader(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material()); loader.add_prefab(world, loader(path), entity); diff --git a/client/scene.h b/client/scene.h index 9593100c..e84bbcea 100644 --- a/client/scene.h +++ b/client/scene.h @@ -103,6 +103,7 @@ public: protected: vk::Format swapchain_format; vk::Format depth_format; + xr::system::passthrough_type passthrough_supported; bool composition_layer_depth_test_supported; bool composition_layer_color_scale_bias_supported; diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 27fa5a17..cd328c19 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -383,18 +383,9 @@ void scenes::lobby::connect(const configuration::server_data & data) data.manual); } -std::optional scenes::lobby::check_recenter_gesture(xr::spaces space, const std::optional> & joints) +std::optional scenes::lobby::check_recenter_gesture(const std::array & joints) { - if (recentering_context and std::get<0>(*recentering_context) != space) - return std::nullopt; - - if (not joints) - { - recentering_context.reset(); - return std::nullopt; - } - - const auto & palm = (*joints)[XR_HAND_JOINT_PALM_EXT].first; + const auto & palm = joints[XR_HAND_JOINT_PALM_EXT].first; const auto & o = palm.pose.orientation; const auto & p = palm.pose.position; glm::quat q{o.w, o.x, o.y, o.z}; @@ -402,130 +393,102 @@ std::optional scenes::lobby::check_recenter_gesture(xr::spaces space, if (glm::dot(q * glm::vec3(0, 1, 0), glm::vec3(0, -1, 0)) > constants::lobby::recenter_cosangle_min) { - recentering_context.emplace(space, glm::vec3{}, 0); return v + glm::vec3(0, constants::lobby::recenter_distance_up, 0) + q * glm::vec3(0, 0, -constants::lobby::recenter_distance_front); } - recentering_context.reset(); return std::nullopt; } std::optional scenes::lobby::check_recenter_action(XrTime predicted_display_time, glm::vec3 head_position) { - xr::spaces controller; - glm::vec3 recenter_position; - float recenter_distance; + std::optional> aim; + glm::vec3 offset_position; + glm::quat offset_orientation; - if (recentering_context) + if (application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second) { - controller = std::get<0>(*recentering_context); - bool state; - switch (controller) - { - case xr::spaces::aim_left: - state = application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second; - break; - - case xr::spaces::aim_right: - state = application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second; - break; - - default: - return std::nullopt; - } - - if (not state) - { - recentering_context.reset(); - return std::nullopt; - } - } - else if (auto state = application::read_action_bool(recenter_left_action); state and state->second) - controller = xr::spaces::aim_left; - else if (auto state = application::read_action_bool(recenter_right_action); state and state->second) - controller = xr::spaces::aim_right; - else - return std::nullopt; - - auto aim = application::locate_controller(application::space(controller), application::space(xr::spaces::world), predicted_display_time); - - if (not aim) - { - // The controller cannot be located - recentering_context.reset(); - return std::nullopt; + aim = application::locate_controller(application::space(xr::spaces::aim_left), application::space(xr::spaces::world), predicted_display_time); + std::tie(offset_position, offset_orientation) = input->offset[xr::spaces::aim_left]; } - // Handle controller offset - auto [offset_position, offset_orientation] = input->offset[controller]; - aim->first = aim->first + glm::mat3_cast(aim->second * offset_orientation) * offset_position; - aim->second = aim->second * offset_orientation; - - if (not recentering_context) + if (application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second) { - // First frame of recentering - imgui_context::controller_state state{ - .active = true, - .aim_position = aim->first, - .aim_orientation = aim->second, - }; + aim = application::locate_controller(application::space(xr::spaces::aim_right), application::space(xr::spaces::world), predicted_display_time); + std::tie(offset_position, offset_orientation) = input->offset[xr::spaces::aim_right]; + } - imgui_ctx->compute_pointer_position(state); + if (aim) + { + // Handle controller offset + aim->first = aim->first + glm::mat3_cast(aim->second * offset_orientation) * offset_position; + aim->second = aim->second * offset_orientation; - if (state.pointer_position) // TODO: check that the pointer is inside an imgui window + if (not gui_recenter_position or not gui_recenter_distance) { - auto M = glm::mat3_cast(imgui_ctx->layers()[0].orientation); + // First frame where the recenter action is active + imgui_context::controller_state state{ + .active = true, + .aim_position = aim->first, + .aim_orientation = aim->second, + }; - // Pointer position in world - glm::vec3 world_pointer_position = imgui_ctx->rw_from_vp(*state.pointer_position); + imgui_ctx->compute_pointer_position(state); - // Pointer position in GUI - recenter_position = glm::transpose(M) * (world_pointer_position - imgui_ctx->layers()[0].position); - recenter_distance = glm::length(state.aim_position - world_pointer_position); + if (state.pointer_position) // TODO: check that the pointer is inside an imgui window + { + auto M = glm::mat3_cast(imgui_ctx->layers()[0].orientation); + + // Pointer position in world + glm::vec3 world_pointer_position = imgui_ctx->rw_from_vp(*state.pointer_position); + + // Pointer position in GUI + gui_recenter_position = glm::transpose(M) * (world_pointer_position - imgui_ctx->layers()[0].position); + gui_recenter_distance = glm::length(state.aim_position - world_pointer_position); + } + else + { + gui_recenter_position = glm::vec3(0, 0, 0); + gui_recenter_distance = constants::lobby::recenter_action_distance; + } } else { - // Use the center of the GUI if the controller points outside of the GUI - recenter_position = glm::vec3(0, 0, 0); - recenter_distance = constants::lobby::recenter_action_distance; - } + // Subsequent frames: find the GUI position that gives the correct world pointer position + glm::vec3 controller_direction = -glm::column(glm::mat3_cast(aim->second), 2); + glm::vec3 wanted_world_pointer_position = aim->first + controller_direction * *gui_recenter_distance; - recentering_context.emplace(controller, recenter_position, recenter_distance); - return std::nullopt; + // I'm sure there's an analytical solution but I can't be bothered to write it so + // let's use a gradient descent instead + auto f = [&](glm::vec3 new_gui_position) { + auto q = compute_gui_orientation(head_position, new_gui_position); + auto M = glm::mat3_cast(q); // plane-to-world transform + + glm::vec3 world_pointer_position = new_gui_position + M * *gui_recenter_position; + + return world_pointer_position - wanted_world_pointer_position; + }; + + // One step is usually enough, the solution will continuously improve in the next frames + glm::vec3 gui_position = imgui_ctx->layers()[0].position; + float eps = 0.01; + glm::vec3 obj = f(gui_position); + glm::vec3 obj_dx = (f(gui_position + glm::vec3(eps, 0, 0)) - obj) / eps; + glm::vec3 obj_dy = (f(gui_position + glm::vec3(0, eps, 0)) - obj) / eps; + glm::vec3 obj_dz = (f(gui_position + glm::vec3(0, 0, eps)) - obj) / eps; + + glm::mat3 jacobian{obj_dx, obj_dy, obj_dz}; + + gui_position -= glm::inverse(jacobian) * obj; + + return gui_position; + } } else { - // Subsequent frames: find the GUI position that gives the correct world pointer position - std::tie(controller, recenter_position, recenter_distance) = *recentering_context; - - glm::vec3 controller_direction = -glm::column(glm::mat3_cast(aim->second), 2); - glm::vec3 wanted_world_pointer_position = aim->first + controller_direction * recenter_distance; - - // I'm sure there's an analytical solution but I can't be bothered to write it so - // let's use a gradient descent instead - auto f = [&](glm::vec3 new_gui_position) { - auto q = compute_gui_orientation(head_position, new_gui_position); - auto M = glm::mat3_cast(q); // plane-to-world transform - - glm::vec3 world_pointer_position = new_gui_position + M * recenter_position; - - return world_pointer_position - wanted_world_pointer_position; - }; - - // One step is usually enough, the solution will continuously improve in the next frames - glm::vec3 gui_position = imgui_ctx->layers()[0].position; - float eps = 0.01; - glm::vec3 obj = f(gui_position); - glm::vec3 obj_dx = (f(gui_position + glm::vec3(eps, 0, 0)) - obj) / eps; - glm::vec3 obj_dy = (f(gui_position + glm::vec3(0, eps, 0)) - obj) / eps; - glm::vec3 obj_dz = (f(gui_position + glm::vec3(0, 0, eps)) - obj) / eps; - - glm::mat3 jacobian{obj_dx, obj_dy, obj_dz}; - - gui_position -= glm::inverse(jacobian) * obj; - - return gui_position; + gui_recenter_position.reset(); } + + return std::nullopt; } std::optional scenes::lobby::check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation) @@ -649,24 +612,26 @@ void scenes::lobby::render(const XrFrameState & frame_state) if (!new_gui_position and head_position) new_gui_position = check_recenter_action(frame_state.predictedDisplayTime, head_position->first); - if (left_hand and right_hand) + if (application::get_hand_tracking_supported()) { - auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime); - auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime); + auto left = application::get_left_hand().locate(world_space, frame_state.predictedDisplayTime); + auto right = application::get_right_hand().locate(world_space, frame_state.predictedDisplayTime); hand_model::apply(world, left, right); if (left and xr::hand_tracker::check_flags(*left, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0)) + { hide_left_controller = true; + if (!new_gui_position) + new_gui_position = check_recenter_gesture(*left); + } if (right and xr::hand_tracker::check_flags(*right, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0)) + { hide_right_controller = true; - - if (not new_gui_position) - new_gui_position = check_recenter_gesture(xr::spaces::palm_left, left); - - if (not new_gui_position) - new_gui_position = check_recenter_gesture(xr::spaces::palm_right, right); + if (!new_gui_position) + new_gui_position = check_recenter_gesture(*right); + } } if (head_position && new_gui_position) @@ -798,7 +763,7 @@ void scenes::lobby::on_focused() // assert(std::ranges::all_of(views, [height](const XrViewConfigurationView & view) { return view.recommendedImageRectHeight == height; })); renderer.emplace(device, physical_device, queue, commandpool); - loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material()); + loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material()); lobby_entity = load_gltf("ground.gltf", layer_lobby).first; @@ -835,6 +800,12 @@ void scenes::lobby::on_focused() xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first; #endif + if (application::get_hand_tracking_supported()) + { + hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers); + hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers); + } + recenter_left_action = get_action("recenter_left").first; recenter_right_action = get_action("recenter_right").first; @@ -856,18 +827,20 @@ void scenes::lobby::on_focused() .haptic_output = get_action("right_haptic").first, }, }; - - if (system.hand_tracking_supported()) + if (auto & hand = application::get_left_hand()) { - left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT); - right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT); - hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers); - hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers); - imgui_inputs.push_back({.hand = &*left_hand}); - imgui_inputs.push_back({.hand = &*right_hand}); + imgui_inputs.push_back( + { + .hand = &hand, + }); + } + if (auto & hand = application::get_right_hand()) + { + imgui_inputs.push_back( + { + .hand = &hand, + }); } - - face_tracker = xr::make_face_tracker(instance, system, session); // 0.4mm / pixel std::vector vps{ @@ -969,9 +942,6 @@ void scenes::lobby::on_unfocused() world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools input.reset(); - left_hand.reset(); - right_hand.reset(); - face_tracker.emplace(); loader.reset(); renderer.reset(); diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index d527ec9c..1ef69eae 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -29,9 +29,7 @@ #include "wivrn_config.h" #include "wivrn_discover.h" #include "wivrn_packets.h" -#include "xr/face_tracker.h" #include -#include #include #include @@ -67,11 +65,6 @@ class lobby : public scene_impl std::optional imgui_ctx; - std::optional left_hand; - std::optional right_hand; - - xr::face_tracker face_tracker; - std::string selected_item; std::unique_ptr license; @@ -101,10 +94,8 @@ class lobby : public scene_impl XrAction recenter_left_action = XR_NULL_HANDLE; XrAction recenter_right_action = XR_NULL_HANDLE; - // std::optional gui_recenter_position; - // std::optional gui_recenter_distance; - // Which controller is used for recentering, position of the pointed point in the GUI, in GUI axes, and distance between the controller and the pointed point during recentering - std::optional> recentering_context; + std::optional gui_recenter_position; + std::optional gui_recenter_distance; bool recenter_gui = true; void move_gui(glm::vec3 head_position, glm::vec3 new_gui_position); @@ -129,7 +120,6 @@ class lobby : public scene_impl ImTextureID about_picture; ImTextureID default_icon; std::unordered_map app_icons; - std::optional timestamp_start_application; virtual_keyboard keyboard; @@ -146,7 +136,7 @@ class lobby : public scene_impl void draw_features_status(XrTime predicted_display_time); void gui_connecting(locked_notifiable & request); void gui_enter_pin(locked_notifiable & request); - void gui_connected(XrTime predicted_display_time); + void gui_connected(); void gui_server_list(); void gui_new_server(); void gui_settings(); @@ -162,7 +152,7 @@ class lobby : public scene_impl void connect(const configuration::server_data & data); std::unique_ptr connect_to_session(wivrn_discover::service service, bool manual_connection); - std::optional check_recenter_gesture(xr::spaces space, const std::optional> & joints); + std::optional check_recenter_gesture(const std::array & joints); std::optional check_recenter_action(XrTime predicted_display_time, glm::vec3 head_position); std::optional check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation); diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index f25126be..b6137db1 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -34,13 +34,11 @@ #include "utils/overloaded.h" #include "utils/ranges.h" #include "version.h" -#include "xr/body_tracker.h" #include #include #include #include #include -#include #include #include #include @@ -247,7 +245,6 @@ void scenes::lobby::gui_connecting(locked_notifiable & pin_req if (next_scene) { current_tab = tab::connected; - timestamp_start_application.reset(); ImGui::CloseCurrentPopup(); return; } @@ -378,7 +375,7 @@ void scenes::lobby::gui_enter_pin(locked_notifiable & pin_requ imgui_ctx->vibrate_on_hover(); } -void scenes::lobby::gui_connected(XrTime predicted_display_time) +void scenes::lobby::gui_connected() { if (not next_scene) { @@ -403,17 +400,14 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time) auto apps = next_scene->get_applications(); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20}); - if (apps->empty()) + if (apps->applications.empty()) { CenterTextHV(_("Start an application on the server to start streaming.")); } else { - bool app_starting = timestamp_start_application and (predicted_display_time - *timestamp_start_application < 10'000'000'000); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 0}); - ImGui::BeginDisabled(app_starting); - ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0, app_starting ? ImGuiWindowFlags_NoScrollWithMouse : 0); + ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0); ImGui::Indent(20); if (server_name.empty()) @@ -432,7 +426,7 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time) ImGui::Indent((usable_window_width - icon_line_width) / 2); auto t0 = std::chrono::steady_clock::now(); - for (const auto [index, app]: utils::enumerate(*apps)) + for (const auto [index, app]: utils::enumerate(apps->applications)) { ImTextureID texture = [&]() -> ImTextureID { if (app.image.empty()) @@ -463,11 +457,8 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time) }(); ImGui::PushStyleColor(ImGuiCol_Button, 0); - if (icon(app.name + "##" + app.id, texture, {256, 256}, ImGuiButtonFlags_PressedOnClickRelease, {icon_width, 0})) - { - timestamp_start_application = predicted_display_time; + if (icon(app.name + "##" + app.id, texture, {256, 256}, 0, {icon_width, 0})) next_scene->start_application(app.id); - } imgui_ctx->vibrate_on_hover(); ImGui::PopStyleColor(); // ImGuiCol_Button @@ -479,7 +470,7 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time) std::vector> to_be_removed; for (const auto & [app_id, app_icon]: app_icons) { - if (not std::ranges::contains(*apps, app_id, &scenes::stream::app::id)) + if (not std::ranges::contains(apps->applications, app_id, &to_headset::application_list::application::id)) to_be_removed.emplace_back(app_id, app_icon); } for (const auto & [app_id, app_icon]: to_be_removed) @@ -490,26 +481,12 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time) ScrollWhenDragging(); ImGui::EndChild(); - ImGui::EndDisabled(); - - if (app_starting) - { - ImGui::SetCursorPos(ImGui::GetWindowSize() / 2 - ImVec2{200, 200} - ImGui::GetStyle().FramePadding); - ImSpinner::SpinnerAng("App starting spinner", - 200, // Radius - 40, // Thickness - ImColor{1.f, 1.f, 1.f, 1.f}, // Colour - ImColor{1.f, 1.f, 1.f, 0.f}, // Background - 6, // Velocity - 0.75f * 2 * M_PI // Angle - ); - } - ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding } ImGui::PopStyleVar(); - ImGui::SetCursorPos(ImGui::GetWindowSize() - disconnect_size - ImVec2{50, 50}); + ImGui::SetCursorPosX(ImGui::GetWindowSize().x - disconnect_size.x - 50); + ImGui::SetCursorPosY(ImGui::GetWindowSize().y - disconnect_size.y - 50); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f)); @@ -890,7 +867,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } { - ImGui::BeginDisabled(not system.hand_tracking_supported()); + ImGui::BeginDisabled(not application::get_hand_tracking_supported()); bool enabled = config.check_feature(feature::hand_tracking); if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled)) { @@ -914,7 +891,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } { - ImGui::BeginDisabled(std::holds_alternative(face_tracker)); + ImGui::BeginDisabled(not application::get_face_tracking_supported()); bool enabled = config.check_feature(feature::face_tracking); if (ImGui::Checkbox(_S("Enable face tracking"), &enabled)) { @@ -926,9 +903,8 @@ void scenes::lobby::gui_settings() imgui_ctx->vibrate_on_hover(); } - auto body_tracker = system.body_tracker_supported(); { - ImGui::BeginDisabled(body_tracker == xr::body_tracker_type::none); + ImGui::BeginDisabled(not application::get_body_tracking_supported()); bool enabled = config.check_feature(feature::body_tracking); if (ImGui::Checkbox(_S("Enable body tracking"), &enabled)) { @@ -943,14 +919,19 @@ void scenes::lobby::gui_settings() } else { - if (body_tracker == xr::body_tracker_type::fb) - imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions")); + std::visit(utils::overloaded{ + [](auto &) {}, + [this](xr::fb_body_tracker &) { + imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions")); + }, + }, + application::get_body_tracker()); } } imgui_ctx->vibrate_on_hover(); } - if (body_tracker == xr::body_tracker_type::fb) + if (std::holds_alternative(application::get_body_tracker())) { ImGui::BeginDisabled(not config.check_feature(feature::body_tracking)); ImGui::Indent(); @@ -976,7 +957,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } - ImGui::BeginDisabled(system.passthrough_supported() == xr::passthrough_type::none); + ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough); if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled)) { setup_passthrough(); @@ -987,13 +968,6 @@ void scenes::lobby::gui_settings() imgui_ctx->tooltip(_("This feature is not supported by your headset")); ImGui::EndDisabled(); - { - ImGui::Checkbox(_S("Enable in-stream window"), &config.enable_stream_gui); - imgui_ctx->vibrate_on_hover(); - if (ImGui::IsItemHovered()) - imgui_ctx->tooltip(_("Enables the configuration window to be shown while the game is streaming.\nIf enabled, the window is activated by pressing both thumbsticks.")); - } - ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing } @@ -1308,12 +1282,12 @@ void scenes::lobby::gui_first_run() item{ .f = feature::face_tracking, .text = _S("Enable face tracking?"), - .supported = not std::holds_alternative(face_tracker), + .supported = application::get_face_tracking_supported(), }, item{ .f = feature::body_tracking, .text = _S("Enable body tracking?"), - .supported = system.body_tracker_supported() != xr::body_tracker_type::none, + .supported = application::get_body_tracking_supported(), }, }; @@ -1643,22 +1617,11 @@ static auto face_weights() return res; } -static const char * get_face_icon(XrTime predicted_display_time, xr::face_tracker & face_tracker) +static const char * get_face_icon(XrTime predicted_display_time) { static const auto w = face_weights(); wivrn::from_headset::tracking::fb_face2 expression; - const char * result = nullptr; - std::visit(utils::overloaded{ - [](std::monostate &) {}, - [&](xr::htc_face_tracker &) { result = ICON_FA_FACE_SMILE_WINK; }, - [&](auto & ft) { - ft.get_weights(predicted_display_time, expression); - }, - }, - face_tracker); - - if (result) - return result; + std::get(application::get_face_tracker()).get_weights(predicted_display_time, expression); if (not expression.is_valid) return ICON_FA_FACE_MEH; @@ -1701,7 +1664,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) .icon_disabled = ICON_FA_MICROPHONE_SLASH, }); - if (system.hand_tracking_supported()) + if (application::get_hand_tracking_supported()) { items.push_back({ .f = feature::hand_tracking, @@ -1722,18 +1685,21 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (not std::holds_alternative(face_tracker)) + if (application::get_face_tracking_supported()) { + const char * icon_enabled = std::holds_alternative(application::get_face_tracker()) + ? get_face_icon(predicted_display_time) + : ICON_FA_FACE_KISS_WINK_HEART; items.push_back({ .f = feature::face_tracking, .tooltip_enabled = _("Face tracking is enabled"), .tooltip_disabled = _("Face tracking is disabled"), - .icon_enabled = get_face_icon(predicted_display_time, face_tracker), + .icon_enabled = icon_enabled, .icon_disabled = ICON_FA_FACE_MEH_BLANK, }); } - if (system.body_tracker_supported() != xr::body_tracker_type::none) + if (application::get_body_tracking_supported()) { items.push_back({ .f = feature::body_tracking, @@ -1807,7 +1773,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) if (*status.charge > 0.995) icon_nr = 5; else - icon_nr = instance.now() / 500'000'000 % 5; + icon_nr = application::now() / 500'000'000 % 5; } else icon_nr = std::round((*status.charge) * 4); @@ -1924,7 +1890,7 @@ std::vector> scenes::lobby::draw_gui(XrTi ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10}); ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove); - gui_connected(predicted_display_time); + gui_connected(); ImGui::End(); ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_FrameRounding, ImGuiStyleVar_FramePadding } @@ -2036,7 +2002,7 @@ std::vector> scenes::lobby::draw_gui(XrTi if (not is_gui_visible(*imgui_ctx, predicted_display_time)) { - if (system.hand_tracking_supported()) + if (application::get_hand_tracking_supported()) display_recentering_tip(*imgui_ctx, _("Press the grip button or put your palm up\nto move the main window")); else display_recentering_tip(*imgui_ctx, _("Press the grip button to move the main window")); diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 63ab4a21..dc20f14e 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -17,9 +17,11 @@ * along with this program. If not, see . */ #include "constants.h" -#include "xr/body_tracker.h" -#include "xr/face_tracker.h" +#include "utils/overloaded.h" +#include "xr/fb_body_tracker.h" #include "xr/fb_face_tracker2.h" +#include "xr/htc_body_tracker.h" +#include "xr/pico_body_tracker.h" #include "xr/space.h" #include #include @@ -40,7 +42,6 @@ #include "utils/ranges.h" #include "vk/pipeline.h" #include "vk/shader.h" -#include "vk/specialization_constants.h" #include "wivrn_packets.h" #include #include @@ -188,11 +189,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrnetwork_session = std::move(network_session); self->network_session->send_control([&]() { - from_headset::headset_info_packet info{ - .language = application::get_messages_info().language, - .country = application::get_messages_info().country, - .variant = application::get_messages_info().variant, - }; + from_headset::headset_info_packet info{}; auto view = self->system.view_configuration_views(self->viewconfig)[0]; view = override_view(view, guess_model()); @@ -254,42 +251,39 @@ std::shared_ptr scenes::stream::create(std::unique_ptrsystem.face_tracker_supported()) - { - case xr::face_tracker_type::none: - info.face_tracking = from_headset::face_type::none; - break; - case xr::face_tracker_type::fb: - case xr::face_tracker_type::pico: - info.face_tracking = from_headset::face_type::fb2; - break; - case xr::face_tracker_type::htc: - info.face_tracking = from_headset::face_type::htc; - break; - } + info.face_tracking = std::visit(utils::overloaded{ + [](std::monostate &) { + return from_headset::face_type::none; + }, + [](xr::fb_face_tracker2 &) { + return from_headset::face_type::fb2; + }, + [](xr::htc_face_tracker &) { + return from_headset::face_type::htc; + }, + [](xr::pico_face_tracker &) { + return from_headset::face_type::fb2; + }, + }, + application::get_face_tracker()); } info.num_generic_trackers = 0; if (config.check_feature(feature::body_tracking)) { - switch (self->system.body_tracker_supported()) - { - case xr::body_tracker_type::none: - break; - case xr::body_tracker_type::fb: - info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size(); - break; - case xr::body_tracker_type::htc: - info.num_generic_trackers = application::get_generic_trackers().size(); - break; - case xr::body_tracker_type::pico: - info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size(); - break; - } + info.num_generic_trackers = std::visit(utils::overloaded{ + [&](std::monostate &) { + return size_t(0); + }, + [&](auto & b) { + return b.count(); + }, + }, + application::get_body_tracker()); } info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right); - info.passthrough = self->system.passthrough_supported() != xr::passthrough_type::none; + info.passthrough = self->system.passthrough_supported() != xr::system::passthrough_type::no_passthrough; info.system_name = std::string(self->system.properties().systemName); audio::get_audio_description(info); @@ -317,6 +311,15 @@ std::shared_ptr scenes::stream::create(std::unique_ptrnetwork_session->send_control(from_headset::get_application_list{ + .language = info.language, + .country = info.country, + .variant = info.variant, + }); + } + { const auto & config = application::get_config(); self->override_foveation_enable = config.override_foveation_enable; @@ -360,7 +363,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrhaptics_actions.emplace(id, haptics_action{ .action = action.first, - .path = self->instance.string_to_path(path), + .path = application::string_to_path(path), }); } } @@ -391,7 +394,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrget_default_material()); + loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material()); std::string profile = controller_name(); input.emplace( @@ -467,11 +470,8 @@ void scenes::stream::on_focused() swapchain_imgui, std::vector{vp}); - if (application::get_config().enable_stream_gui) - { - plots_toggle_1 = get_action("plots_toggle_1").first; - plots_toggle_2 = get_action("plots_toggle_2").first; - } + plots_toggle_1 = get_action("plots_toggle_1").first; + plots_toggle_2 = get_action("plots_toggle_2").first; recenter_left = get_action("recenter_left").first; recenter_right = get_action("recenter_right").first; foveation_pitch = get_action("foveation_pitch").first; @@ -494,8 +494,6 @@ void scenes::stream::on_unfocused() loader.reset(); renderer.reset(); clear_swapchains(); - left_hand.reset(); - right_hand.reset(); imgui_ctx.reset(); swapchain_imgui = xr::swapchain(); @@ -526,16 +524,16 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p { if (decoder != decoders[stream].decoder.get()) return; - handle->feedback.received_from_decoder = instance.now(); + handle->feedback.received_from_decoder = application::now(); std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]); } if (state_ != state::streaming and std::ranges::all_of(decoders, [](accumulator_images & i) { - return i.alpha() or not i.empty(); + return i.alpha() or not i.frames().empty(); })) { state_ = state::streaming; - spdlog::info("Stream scene ready at t={}", instance.now()); + spdlog::info("Stream scene ready at t={}", application::now()); } } @@ -550,14 +548,15 @@ bool scenes::stream::accumulator_images::alpha() const return decoder->desc().channels == wivrn::to_headset::video_stream_description::channels_t::alpha; } -bool scenes::stream::accumulator_images::empty() const +std::vector scenes::stream::accumulator_images::frames() const { + std::vector result; for (const auto & frame: latest_frames) { if (frame) - return false; + result.push_back(frame->feedback.frame_index); } - return true; + return result; } std::vector> scenes::stream::common_frame(XrTime display_time) @@ -767,15 +766,7 @@ void scenes::stream::render(const XrFrameState & frame_state) } if (state_ == state::stalled) - { - network_session->send_control(from_headset::get_application_list{ - .language = application::get_messages_info().language, - .country = application::get_messages_info().country, - .variant = application::get_messages_info().variant, - }); - application::pop_scene(); - } assert(swapchain); for (auto & i: decoders) @@ -808,19 +799,51 @@ void scenes::stream::render(const XrFrameState & frame_state) const auto & description = i.decoder->desc(); vk::Extent2D image_size = i.decoder->image_size(); + std::array useful_size{ + float(description.width) / image_size.width, + float(description.height) / image_size.height, + }; spdlog::info("useful size: {}x{} with buffer {}x{}", description.width, description.height, image_size.width, image_size.height); - auto vert_constants = make_specialization_constants( - float(description.width) / image_size.width, - float(description.height) / image_size.height); + std::array specialization_constants_desc{ + vk::SpecializationMapEntry{ + .constantID = 0, + .offset = 0, + .size = sizeof(float), + }, + vk::SpecializationMapEntry{ + .constantID = 1, + .offset = sizeof(float), + .size = sizeof(float), + }}; - auto frag_constants = make_specialization_constants( - VkBool32(need_srgb_conversion(guess_model())), - VkBool32(i.alpha())); + vk::SpecializationInfo vert_specialization_info; + vert_specialization_info.setMapEntries(specialization_constants_desc); + vert_specialization_info.setData(useful_size); + + std::array constants = { + need_srgb_conversion(guess_model()), + i.alpha(), + }; + std::array frag_specialization_constant_desc = { + vk::SpecializationMapEntry{ + .constantID = 0, + .offset = 0, + .size = sizeof(constants[0]), + }, + vk::SpecializationMapEntry{ + .constantID = 1, + .offset = sizeof(constants[0]), + .size = sizeof(constants[1]), + }, + }; + vk::SpecializationInfo frag_specialization_info; + frag_specialization_info.setMapEntries(frag_specialization_constant_desc); + frag_specialization_info.setData(constants); // Create graphics pipeline vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert"); @@ -838,13 +861,13 @@ void scenes::stream::render(const XrFrameState & frame_state) .stage = vk::ShaderStageFlagBits::eVertex, .module = *vertex_shader, .pName = "main", - .pSpecializationInfo = vert_constants, + .pSpecializationInfo = &vert_specialization_info, }, { .stage = vk::ShaderStageFlagBits::eFragment, .module = *fragment_shader, .pName = "main", - .pSpecializationInfo = frag_constants, + .pSpecializationInfo = &frag_specialization_info, }}, .VertexBindingDescriptions = {}, .VertexAttributeDescriptions = {}, @@ -930,7 +953,7 @@ void scenes::stream::render(const XrFrameState & frame_state) if (not blit_handle or not *i.blit_pipeline) continue; - blit_handle->feedback.blitted = instance.now(); + blit_handle->feedback.blitted = application::now(); if (blit_handle->feedback.blitted - blit_handle->feedback.received_from_decoder > 1'000'000'000) state_ = stream::state::stalled; ++blit_handle->feedback.times_displayed; @@ -979,10 +1002,6 @@ void scenes::stream::render(const XrFrameState & frame_state) uint16_t x_offset = 0; for (auto & out: decoder_output) { - vk::Extent2D decoder_out_size{ - .width = decoder_out_image.info().extent.width, - .height = decoder_out_image.info().extent.height, - }; command_buffer.beginRenderPass( { .renderPass = *blit_render_pass, @@ -1291,7 +1310,10 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript } // Create outputs for the decoders + decoder_out_size = vk::Extent2D{video_width, video_height}; { + decoder_out_format = vk::Format::eA8B8G8R8SrgbPack32; + vk::ImageCreateInfo image_info{ .flags = vk::ImageCreateFlags{}, .imageType = vk::ImageType::e2D, @@ -1315,7 +1337,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript vk::ImageViewCreateInfo image_view_info{ .image = vk::Image{decoder_out_image}, .viewType = vk::ImageViewType::e2D, - .format = image_info.format, + .format = vk::Format::eA8B8G8R8SrgbPack32, .components = {}, .subresourceRange = { .aspectMask = vk::ImageAspectFlagBits::eColor, @@ -1339,8 +1361,8 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript .renderPass = *blit_render_pass, .attachmentCount = 1, .pAttachments = &*output.image_view, - .width = image_info.extent.width, - .height = image_info.extent.height, + .width = decoder_out_size.width, + .height = decoder_out_size.height, .layers = 1, }); } @@ -1365,7 +1387,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y); decoders.push_back(accumulator_images{ - .decoder = std::make_unique(device, physical_device, instance, item, description.fps, shared_from_this(), stream_index), + .decoder = std::make_unique(device, physical_device, item, description.fps, shared_from_this(), stream_index), }); } } @@ -1407,6 +1429,8 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint device, physical_device, decoder_out_image, + vk::Extent2D{.width = video_width, .height = video_height}, + 2, swapchain_images, extent, swapchain.format()); diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 146b6752..6f506ab7 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -48,13 +48,6 @@ public: }; static const size_t image_buffer_size = 3; - struct app - { - std::string id; - std::string name; - std::vector image; - }; - private: static const size_t view_count = 2; @@ -67,12 +60,12 @@ private: vk::DescriptorSet descriptor_set = nullptr; vk::raii::PipelineLayout blit_pipeline_layout = nullptr; vk::raii::Pipeline blit_pipeline = nullptr; - // latest frames, rolling buffer + // latest frames from oldest to most recent std::array, image_buffer_size> latest_frames; std::shared_ptr frame(uint64_t id) const; bool alpha() const; - bool empty() const; + std::vector frames() const; }; wifi_lock::wifi wifi; @@ -84,9 +77,9 @@ private: std::unique_ptr network_session; std::atomic exiting = false; std::thread network_thread; - thread_safe tracking_control{}; + std::mutex tracking_control_mutex; + to_headset::tracking_control tracking_control{}; std::array, 2> interaction_profiles; // left and right hand - std::atomic interaction_profile_changed = false; std::atomic recenter_requested = false; std::atomic display_time_phase = 0; std::atomic display_time_period = 0; @@ -100,6 +93,8 @@ private: vk::raii::DescriptorPool blit_descriptor_pool = nullptr; vk::raii::RenderPass blit_render_pass = nullptr; + vk::Extent2D decoder_out_size; + vk::Format decoder_out_format; image_allocation decoder_out_image; struct renderpass_output @@ -130,8 +125,6 @@ private: std::optional