From 29ea3f918b45809193bf8200c3f5225906dfdc89 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/62] 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 6842a8fb..247e9165 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ set(OVR_COMPAT_SEARCH_PATH "/opt/xrizer:/usr/local/lib/OpenComposite:/usr/lib/Op 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 35a33459..fcb5464b 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -236,14 +236,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) @@ -252,9 +246,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}/default_icon.ktx2 COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn-pride.ktx2 ${ASSETS_DIR}/default_icon.png @@ -270,10 +261,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 2b9154ab..27fa5a17 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -911,9 +911,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 3794c3c6..d7899e9d 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 0144461b..7dac8ed2 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -58,7 +58,7 @@ #endif #if WIVRN_FEATURE_SOLARXR -#include "solarxr_device.h" +#include "solarxr_interface.h" #endif namespace wivrn @@ -269,15 +269,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) @@ -296,6 +294,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 7e1a04afba379f6a241ea448af162463befe1905 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/62] 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 fcb5464b..bf6da72d 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -237,7 +237,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 34c49cdae60cf53ee37c75e57acd120608da49c4 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/62] Update patches --- flatpak/io.github.wivrn.wivrn.yml.in | 27 +- ...098-d-solarxr-Add-SolarXR-IPC-driver.patch | 2557 +++++++++++++++++ .../0099-t-common-Load-SolarXR-driver.patch | 292 ++ 3 files changed, 2862 insertions(+), 14 deletions(-) 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 abb34416..737d1b04 100644 --- a/flatpak/io.github.wivrn.wivrn.yml.in +++ b/flatpak/io.github.wivrn.wivrn.yml.in @@ -23,18 +23,14 @@ finish-args: - --system-talk-name=org.freedesktop.Avahi # Allow getting the pretty hostname - --system-talk-name=org.freedesktop.hostname1 - # List applications from $XDG_DATA_DIRS - - --filesystem=host-os:ro - - --filesystem=xdg-data/applications:ro - # List Steam games - - --filesystem=xdg-data/Steam:ro - - --filesystem=~/.steam:ro - - --filesystem=~/.var/app/com.valvesoftware.Steam:ro # Pipewire - --filesystem=xdg-run/pipewire-0 # 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 @@ -97,11 +93,10 @@ modules: url: https://www.mpfr.org/mpfr-4.2.1/mpfr-4.2.1.tar.xz sha256: 277807353a6726978996945af13e52829e3abd7a9a5b7fb2793894e18f1fcbb2 - type: file - dest-filename: isl-0.26.tar.xz - url: https://sourceforge.net/projects/libisl/files/isl-0.26.tar.xz/download + url: https://libisl.sourceforge.io/isl-0.26.tar.xz sha256: a0b5cb06d24f9fa9e77b55fabbe9a3c94a336190345c2555f9915bb38e976504 - type: file - url: https://ftpmirror.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz + url: https://www.multiprecision.org/downloads/mpc-1.3.1.tar.gz sha256: ab642492f5cf882b74aa0cb730cd410a81edcdbec895183ce930e706c1c759b8 - type: file url: https://invisible-mirror.net/archives/ncurses/ncurses-6.4.tar.gz @@ -281,7 +276,7 @@ modules: sources: - type: git url: https://gitlab.com/znixian/OpenOVR.git - tag: cff07db75c4823afe93ed7027b03d5f7bc86f164 + tag: 538639b86c5c71223f11040b09479e5c0a83078c - name: xrizer buildsystem: simple @@ -312,7 +307,7 @@ modules: sources: - type: git url: https://github.com/Supreeeme/xrizer.git - tag: 76e01ac8ad79fed226a883985daa3cbe61271ca7 + tag: fcc6793ffeadf0d7676c4cfd5a6c57da481a520c - xrizer-gen-src.json - name: wivrn-library @@ -353,6 +348,10 @@ modules: - WIVRN_SRC1 WIVRN_SRC2 WIVRN_SRC3 + - type: archive + url: BOOSTPFR_URL + dest: deps/boostpfr-src + sha256: BOOSTPFR_SHA256 - type: git url: https://gitlab.freedesktop.org/monado/monado tag: MONADO_COMMIT @@ -360,6 +359,7 @@ modules: - type: shell commands: - cd deps/monado-src && ../../patches/apply.sh ../../patches/monado/* + - cd deps/boostpfr-src && ../../patches/apply.sh ../../flatpak/boostpfr-gcc-12-internal-compiler-error.patch - name: wivrn buildsystem: cmake-ninja @@ -374,8 +374,7 @@ modules: - -DWIVRN_USE_NVENC=ON - -DWIVRN_USE_VULKAN_ENCODE=ON - -DWIVRN_USE_PULSEAUDIO=OFF - - -DWIVRN_USE_PIPEWIRE=ON - - -DWIVRN_USE_SYSTEM_BOOST=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 5255887a852f3b5d055ecc328cd336fb32e885dd 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/62] 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 fce6fce7..cf13fba6 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -1231,6 +1231,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 bec073ef91fdbe9e49e036eb83fe7b9de64f3e37 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/62] 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/62] 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 c2afadc2..5c8bc5a5 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 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 bb511c855e20bbb1fa6c9e8b8660b2a9d424ece1 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/62] 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 5c8bc5a5..ea3c435a 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: Prepare Vulkan SDK From eb2e0c12cac02581b194970d56fb8a1b602fb0a5 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/62] 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 ea3c435a..9a5b0c3b 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: Prepare Vulkan SDK From f92a55d5fdfb5aa83cf359d5dedf1f145420b338 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/62] 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 9a5b0c3b..2196218a 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From 011b347b87e16b5309411bdef598fda558f60eed 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/62] 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 2196218a..baf1b83b 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From e271c6c2d6b5cfad8d84145d38c225395cc27d13 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/62] 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 baf1b83b..c12bf501 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: Prepare Vulkan SDK From 928ce0444309e2834b0eca935434d65bc1394450 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/62] 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 c12bf501..ae681d6b 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From 5895c53e2ff92acd03ab96064232079c24388b2a 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/62] 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 ae681d6b..011de216 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From b3604697abd903d5c0359af32641c6296cb0fe6a 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/62] 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 011de216..d6a1d042 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From 06df375a2a122a698dd48f0414223582c567200a 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/62] 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 d6a1d042..3897518a 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -113,6 +113,7 @@ jobs: path: apk pattern: 'apk-*' merge-multiple: true + run: ls -R - name: Rename APK artifacts run: | From 642ed2ce23af8b1d894e06baded8323b966e719a 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/62] 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 3897518a..0aacd2e4 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -113,7 +113,6 @@ jobs: path: apk pattern: 'apk-*' merge-multiple: true - run: ls -R - name: Rename APK artifacts run: | @@ -146,4 +145,6 @@ jobs: fail_on_unmatched_files: true files: | apk/*.apk + apk/*.zip + apk/* debug-symbols.zip From 143a05ba2f204fb56a24bc5a15a2aacc1188dfca 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/62] 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 0aacd2e4..7a10a5dc 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -80,7 +80,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 @@ -117,6 +119,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 5925b2197e9604be3ee5e95736e82016d4f1dada 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/62] 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 7a10a5dc..0a04e7ea 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -124,6 +124,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 @@ -137,6 +138,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 6d9d6f5a80599c6534194e73b2a7ce27198274ef 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/62] 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 0a04e7ea..5b78a260 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -153,7 +153,5 @@ jobs: prerelease: false fail_on_unmatched_files: true files: | - apk/*.apk - apk/*.zip apk/* debug-symbols.zip From 155abc0bc2597000e484151eac60c95d11f67c9a 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/62] 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 517c80981743c02b30070f25fffb92b754ada648 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/62] 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 5b78a260..b43ecf94 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -116,15 +116,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 @@ -153,5 +153,5 @@ jobs: prerelease: false fail_on_unmatched_files: true files: | - apk/* + apk/*.apk debug-symbols.zip From 675464a868165369a58e6925e906e5f7be9a83a9 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/62] 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 07c0ecd31bd409f0d8f2f11ea05203fe83406b4f 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/62] 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 b43ecf94..8c5b374e 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From 3c1909a2d9e159f2f6ad2fce5d5602fd53cf30b6 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/62] 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 f4e55b41d75bd309a1bcf4ef8827436c8a65d919 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/62] Adding solarxr patches Remove potential statistics --- client/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index bf6da72d..8090ae81 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -247,10 +247,6 @@ if(ANDROID) 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}/default_icon.ktx2 - COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn-pride.ktx2 ${ASSETS_DIR}/default_icon.png - DEPENDS ${ASSETS_DIR}/default_icon.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 DEPENDS ${AST_SRC_DIR}/WoodFloor051_1K-JPG_Color.jpg) From eb86dbf209057585fc05834ed6b331a463a04573 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:14:51 -0400 Subject: [PATCH 26/62] 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 d7899e9d..98110b58 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 9f826752372fe94cc30c44a4e28905f698cb5723 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 27/62] 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 cf13fba6..fa7222cc 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -1231,7 +1231,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 3a0e1fa2a6b65c225df63a1aa03e884be18ed1ed 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 28/62] 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 29/62] 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 ef5020892352ecde5adbc05610090140b11d6196 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 30/62] 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 98110b58..589fe56b 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 f0c31a7994ba5340e0d01200edf5895935e9b42d Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Sun, 24 Aug 2025 09:56:21 -0400 Subject: [PATCH 31/62] 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 | 28 +- .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 | 298 +- client/application.h | 95 +- client/configuration.cpp | 100 +- client/configuration.h | 14 +- client/decoder/shard_accumulator.cpp | 16 +- client/decoder/shard_accumulator.h | 46 +- 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 | 486 +- client/scenes/stream.h | 42 +- client/scenes/stream_defoveator.cpp | 510 +- client/scenes/stream_defoveator.h | 45 +- client/scenes/stream_gui.cpp | 38 +- client/scenes/stream_network.cpp | 20 +- client/scenes/stream_tracking.cpp | 144 +- client/shaders/reprojection.glsl | 51 +- client/shaders/reprojection.glsl.inc | 92 - 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/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 +- client/xr/{face_tracker.h => xr.h} | 31 +- cmake/AutoOption.cmake | 4 + common/CMakeLists.txt | 4 +- common/application.cpp | 74 +- common/application.h | 6 +- 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 | 24 - 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 | 12 +- locale/es/wivrn.po | 327 +- locale/fr/wivrn.po | 335 +- locale/it/wivrn.po | 323 +- locale/pt_BR/wivrn-dashboard.po | 173 +- locale/pt_BR/wivrn.po | 499 +- locale/sk/wivrn-dashboard.po | 212 +- locale/sk/wivrn.po | 358 +- locale/tr/wivrn-dashboard.po | 943 ---- locale/tr/wivrn.po | 629 --- patches/apply.sh | 5 - ...001-c-multi-early-wake-of-compositor.patch | 10 +- ...02-ipc-server-Always-listen-to-stdin.patch | 6 +- .../monado/0003-Use-extern-socket-fd.patch | 6 +- ...Add-storage-usage-to-distortion-mesh.patch | 25 + ...vironment-blend-mode-selection-logic.patch | 6 +- .../0005-st-oxr-forward-0-refresh-rate.patch | 6 +- ...06-Replace-distortion-with-foveation.patch | 825 +-- .../0007-store-alpha-channel-in-layer-1.patch | 94 + ...main-allow-custom-pacing-app-factory.patch | 82 + ...tortion-with-pixel-aligned-foveation.patch | 700 +++ 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 | 8 +- 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 | 82 +- server/start_systemd_unit.cpp | 21 +- server/utils/wivrn_vk_bundle.cpp | 19 +- tools/check_messages.sh | 56 + tools/check_po.py | 153 +- tools/wireshark/CMakeLists.txt | 2 +- 130 files changed, 4568 insertions(+), 13124 deletions(-) delete mode 100644 client/shaders/reprojection.glsl.inc 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 rename client/xr/{face_tracker.h => xr.h} (56%) 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 create mode 100644 patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch create mode 100644 patches/monado/0007-store-alpha-channel-in-layer-1.patch create mode 100644 patches/monado/0008-c-main-allow-custom-pacing-app-factory.patch create mode 100644 patches/monado/0010-Replace-distortion-with-pixel-aligned-foveation.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 5c847e25..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,8 +64,7 @@ body: attributes: label: Vulkan Info description: Provide the output of `vulkaninfo --summary` command. - render: text - placeholder: Attach the output as a file here. + placeholder: Add the output of vulkaninfo command here... - type: dropdown id: hmd @@ -107,5 +90,4 @@ body: attributes: label: ADB Logs description: Provide the output of `adb logcat` command. - render: plain - 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 04c1921c..c57d944f 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 247e9165..16aded6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,12 +18,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) @@ -36,12 +37,12 @@ option(WIVRN_WERROR "Treat warnings as errors" OFF) option(WIVRN_OPTIMIZE_SHADERS "Run siprv-opt on compiled shaders" ON) 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 :") @@ -65,12 +66,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) @@ -82,13 +77,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) @@ -105,30 +106,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() @@ -144,8 +187,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) @@ -174,11 +216,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() @@ -192,7 +246,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) @@ -249,7 +305,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 f4512f7a..b0dd3325 100644 --- a/build.gradle +++ b/build.gradle @@ -124,7 +124,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 8090ae81..d2c1770e 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 SHADERS ${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 24082765..b0433274 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -18,7 +18,7 @@ */ #include "application.h" - +#include "asset.h" #include "hardware.h" #include "openxr/openxr.h" #include "scene.h" @@ -26,23 +26,18 @@ #include "spdlog/spdlog.h" #include "utils/contains.h" #include "utils/files.h" -#include "utils/i18n.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 @@ -72,6 +67,7 @@ struct interaction_profile std::string profile_name; std::vector required_extensions; XrVersion min_version = XR_MAKE_VERSION(1, 0, 0); + XrVersion max_version = XR_MAKE_VERSION(2, 0, 0); // exclusive std::vector input_sources; bool available; }; @@ -138,7 +134,8 @@ 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", "/user/hand/left/output/haptic_trigger_fb", @@ -250,7 +247,8 @@ 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", "/user/hand/right/output/haptic", @@ -350,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", @@ -393,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", @@ -436,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", @@ -479,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", @@ -521,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", @@ -550,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", }, @@ -654,7 +649,6 @@ VkBool32 application::vulkan_debug_report_callback( } #ifndef NDEBUG - bool my_error = true; if (level >= spdlog::level::warn) { bool validation_layer_found = false; @@ -665,13 +659,10 @@ VkBool32 application::vulkan_debug_report_callback( if (validation_layer_found && i.library != "libVkLayer_khronos_validation.so") spdlog::log(level, "{:#016x}: {} + {:#x}", i.pc, i.library, i.pc - i.library_base); - - if (i.library == "libopenxr_loader.so") - my_error = false; } } - if (level >= spdlog::level::err and my_error) + if (level >= spdlog::level::err) abort(); #endif @@ -726,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)) @@ -741,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); @@ -880,7 +874,6 @@ void application::initialize_vulkan() .ppEnabledExtensionNames = vk_device_extensions.data(), .pEnabledFeatures = &device_features, }, - vk::PhysicalDeviceFragmentShadingRateFeaturesKHR{}, #ifdef __ANDROID__ vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR{ .samplerYcbcrConversion = VK_TRUE, @@ -888,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); @@ -925,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() @@ -981,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"); @@ -994,8 +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; + 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")) { @@ -1036,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")) { @@ -1055,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)); + } } } @@ -1111,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 @@ -1155,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)}); } } } @@ -1172,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 @@ -1192,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); @@ -1265,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; @@ -1282,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(); @@ -1323,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; @@ -1330,47 +1348,50 @@ void application::initialize() vk_cmdpool = vk::raii::CommandPool{vk_device, cmdpool_create_info}; initialize_actions(); - load_locale(); -} -void application::load_locale() -{ gen.add_messages_domain("wivrn"); std::locale loc = gen(""); - messages_info.encoding = "UTF-8"; - if (config->locale.empty()) - { #ifdef __ANDROID__ - jni::klass java_util_Locale("java/util/Locale"); - auto default_locale = java_util_Locale.call>("getDefault"); + jni::klass java_util_Locale("java/util/Locale"); + auto default_locale = java_util_Locale.call>("getDefault"); - // if (auto language = default_locale.call("toString")) - if (auto language = default_locale.call("getLanguage")) - messages_info.language = language; + // if (auto language = default_locale.call("toString")) + if (auto language = default_locale.call("getLanguage")) + messages_info.language = language; + + if (auto country = default_locale.call("getCountry")) + messages_info.country = country; + + messages_info.encoding = "UTF-8"; - if (auto country = default_locale.call("getCountry")) - messages_info.country = country; #else - auto & facet = std::use_facet(loc); - messages_info.language = facet.language(); - messages_info.country = facet.country(); + auto & facet = std::use_facet(loc); + messages_info.language = facet.language(); + messages_info.country = facet.country(); + messages_info.encoding = "UTF-8"; #endif - } - else - { - auto pos = config->locale.find("_"); - messages_info.language = config->locale.substr(0, pos); - if (pos != std::string::npos) - messages_info.country = config->locale.substr(pos + 1); - } spdlog::info("Current locale: language {}, country {}, encoding {}", messages_info.language, messages_info.country, messages_info.encoding); messages_info.paths.push_back("locale"); messages_info.domains.push_back(boost::locale::gnu_gettext::messages_info::domain("wivrn")); - messages_info.callback = open_locale_file; + messages_info.callback = [](const std::string & file_name, const std::string & encoding) { + std::vector buffer; + try + { + asset file(file_name); + buffer.resize(file.size()); + memcpy(buffer.data(), file.data(), file.size()); + } + catch (...) + { + } + + return buffer; + }; + loc = std::locale(loc, boost::locale::gnu_gettext::create_messages_facet(messages_info)); std::locale::global(loc); @@ -1854,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 365ebcf6..69327ae2 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 dbea9cf2..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,8 +214,8 @@ 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()); if (auto val = root["openxr_post_processing"]; val.is_object()) parse_openxr_post_processing_options(val.get_object()); @@ -204,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()) @@ -218,9 +254,6 @@ configuration::configuration(xr::system & system) if (auto val = root["first_run"]; val.is_bool()) first_run = val.get_bool(); - - if (auto val = root["locale"]; val.is_string()) - locale = val.get_string().value(); } catch (std::exception & e) { @@ -231,11 +264,31 @@ configuration::configuration(xr::system & system) preferred_refresh_rate.reset(); minimum_refresh_rate.reset(); 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; } } +void configuration::parse_sgsr_options(simdjson::simdjson_result sgsr_root) +{ + sgsr = {}; + if (auto val = sgsr_root["enabled"]; val.is_bool()) + sgsr.enabled = val.get_bool(); + + if (auto val = sgsr_root["upscaling_factor"]; val.is_double()) + sgsr.upscaling_factor = val.get_double(); + + if (auto val = sgsr_root["use_edge_direction"]; val.is_bool()) + sgsr.use_edge_direction = val.get_bool(); + + if (auto val = sgsr_root["edge_threshold"]; val.is_double()) + sgsr.edge_threshold = val.get_double(); + + if (auto val = sgsr_root["edge_sharpness"]; val.is_double()) + sgsr.edge_sharpness = val.get_double(); +} + void configuration::parse_openxr_post_processing_options(simdjson::simdjson_result openxr_post_processing_root) { openxr_post_processing = {}; @@ -251,6 +304,17 @@ static std::ostream & operator<<(std::ostream & stream, feature f) return stream << "\"" << magic_enum::enum_name(f) << "\""; } +static std::ostream & write_sgsr(std::ofstream & stream, const configuration::sgsr_settings & sgsr) +{ + stream << "{\"enabled\":" << std::boolalpha << sgsr.enabled; + stream << ",\"upscaling_factor\":" << sgsr.upscaling_factor; + stream << ",\"use_edge_direction\":" << std::boolalpha << sgsr.use_edge_direction; + stream << ",\"edge_threshold\":" << sgsr.edge_threshold; + stream << ",\"edge_sharpness\":" << sgsr.edge_sharpness; + stream << "}"; + return stream; +} + static std::ostream & write_openxr_post_processing(std::ofstream & stream, const configuration::openxr_post_processing_settings & openxr_post_processing) { stream << "{\"super_sampling\":" << openxr_post_processing.super_sampling; @@ -293,13 +357,14 @@ void configuration::save() if (minimum_refresh_rate) json << ",\"minimum_refresh_rate\":" << *minimum_refresh_rate; json << ",\"resolution_scale\":" << resolution_scale; + json << ",\"sgsr\":"; + write_sgsr(json, sgsr); json << ",\"openxr_post_processing\":"; write_openxr_post_processing(json, openxr_post_processing); json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled; 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); @@ -307,6 +372,5 @@ void configuration::save() json << ",\"override_foveation_pitch\":" << override_foveation_pitch; json << ",\"override_foveation_distance\":" << override_foveation_distance; json << ",\"first_run\":" << std::boolalpha << first_run; - json << ",\"locale\":" << json_string(locale); json << "}"; } diff --git a/client/configuration.h b/client/configuration.h index d8dfbf6f..8d34faae 100644 --- a/client/configuration.h +++ b/client/configuration.h @@ -56,7 +56,16 @@ public: bool fb_lower_body = false; bool fb_hip = true; - bool enable_stream_gui = true; + // Snapdragon Game Super Resolution + struct sgsr_settings + { + bool enabled = false; + float upscaling_factor = 1.5; + bool use_edge_direction = true; + float edge_threshold = 4.0; + float edge_sharpness = 2.0; + }; + sgsr_settings sgsr{}; // XR_FB_composition_layer_settings extension flags struct openxr_post_processing_settings @@ -74,8 +83,6 @@ public: bool first_run = true; - std::string locale; - bool check_feature(feature f) const; void set_feature(feature f, bool state); @@ -83,6 +90,7 @@ private: mutable std::mutex mutex; std::map features; + void parse_sgsr_options(simdjson::simdjson_result root); void parse_openxr_post_processing_options(simdjson::simdjson_result root); public: diff --git a/client/decoder/shard_accumulator.cpp b/client/decoder/shard_accumulator.cpp index a7ec0636..c570fa93 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 a0145e22..4777de7f 100644 --- a/client/decoder/shard_accumulator.h +++ b/client/decoder/shard_accumulator.h @@ -19,30 +19,27 @@ #pragma once -#include "decoder.h" -#include "wivrn_packets.h" - #include +#include + +#ifdef __ANDROID__ +#include "decoder/android/android_decoder.h" +using decoder_impl = ::wivrn::android::decoder; +#else +#include "decoder/ffmpeg/ffmpeg_decoder.h" +using decoder_impl = ::wivrn::ffmpeg::decoder; +#endif + +#include "wivrn_packets.h" #include #include -#include - -namespace xr -{ -class instance; -} - -namespace scenes -{ -class stream; -} namespace wivrn { class shard_accumulator { - std::shared_ptr decoder_; + std::shared_ptr decoder; public: using data_shard = wivrn::to_headset::video_stream_data_shard; @@ -53,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{}; @@ -73,22 +70,19 @@ 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, uint8_t stream_index) : - decoder_(decoder::make(device, physical_device, description, fps, stream_index, scene, this)), + 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); } @@ -97,20 +91,20 @@ public: auto & desc() const { - return decoder_->description; + return decoder->desc(); } vk::Sampler sampler() { - return decoder_->sampler(); + return decoder->sampler(); } - const vk::Extent2D extent() + vk::Extent2D image_size() { - return decoder_->extent(); + return decoder->image_size(); } - using blit_handle = decoder::blit_handle; + using blit_handle = decoder_impl::blit_handle; private: void try_submit_frame(std::optional shard_idx); 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 888e4865..7a2daabb 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 2074e5aa..e67831ce 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 @@ -533,11 +532,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, @@ -548,14 +570,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, }, }, @@ -772,7 +794,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 fa7222cc..5ff2efa0 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -35,13 +35,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 @@ -248,7 +246,6 @@ void scenes::lobby::gui_connecting(locked_notifiable & pin_req if (next_scene) { current_tab = tab::connected; - timestamp_start_application.reset(); ImGui::CloseCurrentPopup(); return; } @@ -379,7 +376,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) { @@ -404,17 +401,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()) @@ -433,7 +427,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()) @@ -464,11 +458,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 @@ -480,7 +471,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) @@ -491,26 +482,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)); @@ -928,7 +905,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)) { @@ -952,7 +929,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)) { @@ -964,9 +941,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)) { @@ -981,14 +957,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(); @@ -1014,7 +995,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(); @@ -1025,13 +1006,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 } @@ -1263,12 +1237,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(), }, }; @@ -1598,22 +1572,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; @@ -1656,7 +1619,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, @@ -1677,18 +1640,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, @@ -1762,7 +1728,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); @@ -1879,7 +1845,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 } @@ -1991,7 +1957,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 e79c1305..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 @@ -38,6 +40,8 @@ #include "utils/contains.h" #include "utils/named_thread.h" #include "utils/ranges.h" +#include "vk/pipeline.h" +#include "vk/shader.h" #include "wivrn_packets.h" #include #include @@ -45,11 +49,6 @@ #include #include -#include "wivrn_config.h" -#if WIVRN_FEATURE_RENDERDOC -#include "vk/renderdoc.h" -#endif - using namespace wivrn; // clang-format off @@ -152,8 +151,7 @@ static const std::array supported_depth_formats{ }; scenes::stream::stream() : - scene_impl(supported_color_formats, supported_depth_formats), - blitters{blitter(device, 0), blitter(device, 1)} + scene_impl(supported_color_formats, supported_depth_formats) { } @@ -191,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()); @@ -257,49 +251,46 @@ 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); if (not(config.check_feature(feature::microphone))) info.microphone = {}; - info.supported_codecs = decoder::supported_codecs(); + info.supported_codecs = decoder_impl::supported_codecs(); return info; }()); @@ -320,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; @@ -363,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), }); } } @@ -394,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( @@ -470,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; @@ -497,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(); @@ -529,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()); } } @@ -553,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) @@ -770,17 +766,138 @@ 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) + { + if (auto sampler = i.decoder->sampler(); sampler and not *i.blit_pipeline) + { + // Create blit pipeline + // Create VkDescriptorSetLayout with an immutable sampler + vk::DescriptorSetLayoutBinding sampler_layout_binding{ + .binding = 0, + .descriptorType = vk::DescriptorType::eCombinedImageSampler, + .descriptorCount = 1, + .stageFlags = vk::ShaderStageFlagBits::eFragment, + .pImmutableSamplers = &sampler, + }; + + vk::DescriptorSetLayoutCreateInfo layout_info{ + .bindingCount = 1, + .pBindings = &sampler_layout_binding, + }; + + i.descriptor_set_layout = vk::raii::DescriptorSetLayout(device, layout_info); + i.descriptor_set = device.allocateDescriptorSets( + vk::DescriptorSetAllocateInfo{ + .descriptorPool = *blit_descriptor_pool, + .descriptorSetCount = 1, + .pSetLayouts = &*i.descriptor_set_layout, + })[0] + .release(); + + 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); + + std::array specialization_constants_desc{ + vk::SpecializationMapEntry{ + .constantID = 0, + .offset = 0, + .size = sizeof(float), + }, + vk::SpecializationMapEntry{ + .constantID = 1, + .offset = sizeof(float), + .size = sizeof(float), + }}; + + 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"); + vk::raii::ShaderModule fragment_shader = load_shader(device, "stream.frag"); + + vk::PipelineLayoutCreateInfo pipeline_layout_info{ + .setLayoutCount = 1, + .pSetLayouts = &*i.descriptor_set_layout, + }; + + i.blit_pipeline_layout = vk::raii::PipelineLayout(device, pipeline_layout_info); + + vk::pipeline_builder pipeline_info{ + .Stages = {{ + .stage = vk::ShaderStageFlagBits::eVertex, + .module = *vertex_shader, + .pName = "main", + .pSpecializationInfo = &vert_specialization_info, + }, + { + .stage = vk::ShaderStageFlagBits::eFragment, + .module = *fragment_shader, + .pName = "main", + .pSpecializationInfo = &frag_specialization_info, + }}, + .VertexBindingDescriptions = {}, + .VertexAttributeDescriptions = {}, + .InputAssemblyState = {{ + .topology = vk::PrimitiveTopology::eTriangleStrip, + }}, + // With vk::DynamicState::eViewport, vk::DynamicState::eScissor the number of viewports + // and scissors is still used, put a vector with one element + .Viewports = {{}}, + .Scissors = {{}}, + .RasterizationState = {{ + .polygonMode = vk::PolygonMode::eFill, + .lineWidth = 1, + }}, + .MultisampleState = {{ + .rasterizationSamples = vk::SampleCountFlagBits::e1, + }}, + .ColorBlendAttachments = { + {.colorWriteMask = i.alpha() ? vk::ColorComponentFlagBits::eA + : vk::ColorComponentFlagBits::eA | vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB}}, + .DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor}, + .layout = *i.blit_pipeline_layout, + .renderPass = *blit_render_pass, + .subpass = 0, + }; + + i.blit_pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info); + } + } + if (device.waitForFences(*fence, VK_TRUE, UINT64_MAX) == vk::Result::eTimeout) throw std::runtime_error("Vulkan fence timeout"); @@ -811,13 +928,11 @@ void scenes::stream::render(const XrFrameState & frame_state) std::array image_indices; -#if WIVRN_FEATURE_RENDERDOC - renderdoc_begin(*vk_instance); -#endif command_buffer.reset(); - command_buffer.begin(vk::CommandBufferBeginInfo{ - .flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit, - }); + + vk::CommandBufferBeginInfo begin_info; + begin_info.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit; + command_buffer.begin(begin_info); // Keep a reference to the resources needed to blit the images until vkWaitForFences @@ -832,12 +947,13 @@ void scenes::stream::render(const XrFrameState & frame_state) std::array foveation{}; bool use_alpha = false; - for (auto & blit_handle: current_blit_handles) + // Blit images from the decoders + for (auto [i, blit_handle]: std::views::zip(decoders, current_blit_handles)) { - if (not blit_handle) + 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; @@ -848,12 +964,27 @@ void scenes::stream::render(const XrFrameState & frame_state) foveation = blit_handle->view_info.foveation; use_alpha = blit_handle->view_info.alpha; - if (blit_handle->current_layout == vk::ImageLayout::eUndefined) + vk::DescriptorImageInfo image_info{ + .imageView = *blit_handle->image_view, + .imageLayout = vk::ImageLayout::eGeneral, + }; + + vk::WriteDescriptorSet descriptor_write{ + .dstSet = i.descriptor_set, + .dstBinding = 0, + .dstArrayElement = 0, + .descriptorCount = 1, + .descriptorType = vk::DescriptorType::eCombinedImageSampler, + .pImageInfo = &image_info, + }; + + device.updateDescriptorSets(descriptor_write, {}); + if (*blit_handle->current_layout != vk::ImageLayout::eGeneral) { vk::ImageMemoryBarrier barrier{ .srcAccessMask = vk::AccessFlagBits::eNone, .dstAccessMask = vk::AccessFlagBits::eMemoryRead, - .oldLayout = vk::ImageLayout::eUndefined, + .oldLayout = *blit_handle->current_layout, .newLayout = vk::ImageLayout::eGeneral, .image = blit_handle->image, .subresourceRange = { @@ -864,22 +995,72 @@ void scenes::stream::render(const XrFrameState & frame_state) }; command_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, {}, {}, barrier); - blit_handle->current_layout = vk::ImageLayout::eGeneral; + *blit_handle->current_layout = vk::ImageLayout::eGeneral; } } - // Blit images from the decoders - std::array blitted; - for (auto [i, b]: utils::enumerate(blitters)) + uint16_t x_offset = 0; + for (auto & out: decoder_output) { - b.begin(command_buffer); - for (auto [j, blit_handle]: utils::enumerate(current_blit_handles)) + command_buffer.beginRenderPass( + { + .renderPass = *blit_render_pass, + .framebuffer = *out.frame_buffer, + .renderArea = { + .offset = {0, 0}, + .extent = decoder_out_size, + }, + .clearValueCount = 0, + }, + vk::SubpassContents::eInline); + + for (const auto & decoder: decoders) { - if (not blit_handle) + if (not *decoder.blit_pipeline) continue; - b.push_image(command_buffer, j, decoders[j].decoder->sampler(), decoders[j].decoder->extent(), blit_handle->image_view, blit_handle->current_layout); + if (decoder.alpha() and not use_alpha) + continue; + + command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *decoder.blit_pipeline); + + const auto & description = decoder.decoder->desc(); + int x0 = description.offset_x - x_offset; + int y0 = description.offset_y; + int x1 = x0 + description.width * description.subsampling; + int y1 = y0 + description.height * description.subsampling; + + vk::Viewport viewport{ + .x = (float)x0, + .y = (float)y0, + .width = float(description.width * description.subsampling), + .height = float(description.height * description.subsampling), + .minDepth = 0, + .maxDepth = 1, + }; + + x0 = std::clamp(x0, 0, decoder_out_size.width); + x1 = std::clamp(x1, 0, decoder_out_size.width); + y0 = std::clamp(y0, 0, decoder_out_size.height); + y1 = std::clamp(y1, 0, decoder_out_size.height); + + vk::Rect2D scissor{ + .offset = {.x = x0, .y = y0}, + .extent = {.width = (uint32_t)(x1 - x0), .height = (uint32_t)(y1 - y0)}, + }; + + command_buffer.setViewport(0, viewport); + command_buffer.setScissor(0, scissor); + + command_buffer.bindDescriptorSets( + vk::PipelineBindPoint::eGraphics, + *decoder.blit_pipeline_layout, + 0, + decoder.descriptor_set, + nullptr); + command_buffer.draw(3, 1, 0, 0); } - blitted[i] = b.end(command_buffer); + command_buffer.endRenderPass(); + x_offset += decoder_out_size.width; } command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1); @@ -890,7 +1071,7 @@ void scenes::stream::render(const XrFrameState & frame_state) int32_t max_height = 0; for (size_t i = 0; i < view_count; ++i) { - extents[i] = defoveator->defoveated_size(foveation[i]); + extents[i] = reprojector->defoveated_size(foveation[i]); max_width = std::max(max_width, extents[i].width); max_height = std::max(max_height, extents[i].height); } @@ -920,7 +1101,7 @@ void scenes::stream::render(const XrFrameState & frame_state) // defoveate the image int image_index = swapchain.acquire(); swapchain.wait(); - defoveator->defoveate(command_buffer, foveation, blitted, image_index); + reprojector->reproject(command_buffer, foveation, image_index); command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2); @@ -928,9 +1109,6 @@ void scenes::stream::render(const XrFrameState & frame_state) vk::SubmitInfo submit_info; submit_info.setCommandBuffers(*command_buffer); queue.lock()->submit(submit_info, *fence); -#if WIVRN_FEATURE_RENDERDOC - renderdoc_end(*vk_instance); -#endif swapchain.release(); std::vector layer_view(view_count); @@ -1097,15 +1275,119 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript } video_stream_description = description; - for (auto & b: blitters) - b.reset(description); + + const uint32_t video_width = description.width / view_count; + const uint32_t video_height = description.height; + + // Create renderpass + { + vk::AttachmentDescription color_desc{ + .format = vk::Format::eA8B8G8R8SrgbPack32, + .samples = vk::SampleCountFlagBits::e1, + .loadOp = vk::AttachmentLoadOp::eDontCare, + .storeOp = vk::AttachmentStoreOp::eStore, + .initialLayout = vk::ImageLayout::eUndefined, + .finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal, + }; + + vk::AttachmentReference color_ref{ + .attachment = 0, + .layout = vk::ImageLayout::eColorAttachmentOptimal, + }; + + vk::SubpassDescription subpass{ + .pipelineBindPoint = vk::PipelineBindPoint::eGraphics, + }; + subpass.setColorAttachments(color_ref); + + vk::RenderPassCreateInfo renderpass_info{ + .flags = {}, + }; + renderpass_info.setAttachments(color_desc); + renderpass_info.setSubpasses(subpass); + + blit_render_pass = vk::raii::RenderPass(device, renderpass_info); + } + + // 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, + .format = vk::Format::eA8B8G8R8SrgbPack32, + .extent = {video_width, video_height, 1}, + .mipLevels = 1, + .arrayLayers = view_count, + .samples = vk::SampleCountFlagBits::e1, + .tiling = vk::ImageTiling::eOptimal, + .usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eColorAttachment, + .sharingMode = vk::SharingMode::eExclusive, + .initialLayout = vk::ImageLayout::eUndefined, + }; + + VmaAllocationCreateInfo alloc_info{ + .requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + }; + + decoder_out_image = image_allocation{device, image_info, alloc_info}; + + vk::ImageViewCreateInfo image_view_info{ + .image = vk::Image{decoder_out_image}, + .viewType = vk::ImageViewType::e2D, + .format = vk::Format::eA8B8G8R8SrgbPack32, + .components = {}, + .subresourceRange = { + .aspectMask = vk::ImageAspectFlagBits::eColor, + .baseMipLevel = 0, + .levelCount = 1, + .baseArrayLayer = 0, + .layerCount = 1, + }, + }; + + for (uint32_t view = 0; view < view_count; ++view) + { + auto & output = decoder_output[view]; + + image_view_info.subresourceRange.baseArrayLayer = view; + output.image_view = vk::raii::ImageView(device, image_view_info); + + output.frame_buffer = vk::raii::Framebuffer( + device, + vk::FramebufferCreateInfo{ + .renderPass = *blit_render_pass, + .attachmentCount = 1, + .pAttachments = &*output.image_view, + .width = decoder_out_size.width, + .height = decoder_out_size.height, + .layers = 1, + }); + } + } + + { + vk::DescriptorPoolSize pool_size{ + .type = vk::DescriptorType::eCombinedImageSampler, + .descriptorCount = uint32_t(2 * description.items.size()), + }; + blit_descriptor_pool = vk::raii::DescriptorPool( + device, + vk::DescriptorPoolCreateInfo{ + .maxSets = uint32_t(2 * description.items.size()), + .poolSizeCount = 1, + .pPoolSizes = &pool_size, + }); + } for (const auto & [stream_index, item]: utils::enumerate(description.items)) { 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), }); } } @@ -1118,6 +1400,15 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint const uint32_t video_width = video_stream_description->width / view_count; const uint32_t video_height = video_stream_description->height; + const configuration::sgsr_settings sgsr = application::get_config().sgsr; + if (sgsr.enabled) + { + const float upscaling_factor = sgsr.upscaling_factor; + spdlog::info("Using SGSR with an upscale factor of {}", upscaling_factor); + swapchain_width *= upscaling_factor; + swapchain_height *= upscaling_factor; + } + auto views = system.view_configuration_views(viewconfig); swapchain = xr::swapchain(session, device, swapchain_format, swapchain_width, swapchain_height, 1, views.size()); @@ -1134,9 +1425,12 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint for (auto & image: swapchain.images()) swapchain_images.push_back(image.image); - defoveator.emplace( + reprojector.emplace( 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 64cafea0..6f506ab7 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -23,9 +23,8 @@ #include "decoder/shard_accumulator.h" #include "render/imgui_impl.h" #include "scene.h" -#include "scenes/blitter.h" #include "scenes/input_profile.h" -#include "stream_defoveator.h" +#include "stream_reprojection.h" #include "utils/thread_safe.h" #include "wifi_lock.h" #include "wivrn_client.h" @@ -49,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; @@ -64,12 +56,16 @@ private: struct accumulator_images { std::unique_ptr decoder; - // latest frames, rolling buffer + vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr; + vk::DescriptorSet descriptor_set = nullptr; + vk::raii::PipelineLayout blit_pipeline_layout = nullptr; + vk::raii::Pipeline blit_pipeline = nullptr; + // 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; @@ -81,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; @@ -94,10 +90,21 @@ private: std::shared_mutex decoder_mutex; std::optional video_stream_description; std::vector decoders; // Locked by decoder_mutex + vk::raii::DescriptorPool blit_descriptor_pool = nullptr; + vk::raii::RenderPass blit_render_pass = nullptr; - std::array blitters; + vk::Extent2D decoder_out_size; + vk::Format decoder_out_format; + image_allocation decoder_out_image; - std::optional defoveator; + struct renderpass_output + { + vk::raii::ImageView image_view = nullptr; + vk::raii::Framebuffer frame_buffer = nullptr; + }; + std::array decoder_output; + + std::optional reprojector; vk::raii::Fence fence = nullptr; vk::raii::CommandBuffer command_buffer = nullptr; @@ -118,8 +125,6 @@ private: std::optional
++ 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 + From 184254cb6297739e0d02e53366b74fe6f2dd4051 Mon Sep 17 00:00:00 2001 From: Tool Man <211831565+Vindicus999@users.noreply.github.com> Date: Thu, 15 May 2025 10:36:24 -0400 Subject: [PATCH 39/62] Create pull.yml --- .github/workflows/APK-Release.yml | 16 +++++++++++----- .github/workflows/Sync.yml | 1 - 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 4eec207d..921d96b1 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -25,11 +25,17 @@ jobs: repository: 'Vindicus999/WiVRn' ref: ${{ github.sha }} fetch-depth: 0 - # - # - uses: actions/checkout@v4 - # with: - # repository: 'Vindicus999/WiVRn' - # ref: sneed + + - name: merge alternate fork with master + run: | + git merge --no-commit origin/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 diff --git a/.github/workflows/Sync.yml b/.github/workflows/Sync.yml index 240c2d11..5f630079 100644 --- a/.github/workflows/Sync.yml +++ b/.github/workflows/Sync.yml @@ -31,4 +31,3 @@ jobs: from_branch: sneed target_branch: master github_token: ${{ env.WORKFLOW_TOKEN }} - From 8441add99b5400a993da6bd10fc4a67579227e85 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 40/62] 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 921d96b1..9cc30445 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: Prepare Vulkan SDK From 66c7b3e04dbcb5778c66259abaef8085fb68e3ee 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 41/62] 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 9cc30445..335e9778 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: Prepare Vulkan SDK From 33cf4be5fd93e7eec4a5534621be6e386d5c5bd9 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 42/62] 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 335e9778..9cbf5347 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From 5e590273f72a27a72d5786c6a600240898e3ab05 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 43/62] 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 9cbf5347..5c9d7590 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From 0c8f319a861c55ebbd1841d9cbbd060eb4e2ad22 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 44/62] 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 5c9d7590..dfce94d5 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: Prepare Vulkan SDK From 85493b659977364d0e7390c77369f6ecf5bb3e36 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 45/62] 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 dfce94d5..4f4db035 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From 4cc00b6a676436b01739728d31b236b9b86a1733 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 46/62] 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 4f4db035..35b8e133 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From 9dee429515a88d34a3f684aeb778b0cd99e51c00 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 47/62] 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 35b8e133..e625095c 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From ec83166955dc8280c88b0115563bbbef59325b78 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 48/62] 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 e625095c..5b0b2537 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -115,6 +115,7 @@ jobs: path: apk pattern: 'apk-*' merge-multiple: true + run: ls -R # - name: Rename APK artifacts # run: | From c3065d49505684f18dfa8dd01851c79d9c00d3ce 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 49/62] 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 5b0b2537..5767b193 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -115,7 +115,6 @@ jobs: path: apk pattern: 'apk-*' merge-multiple: true - run: ls -R # - name: Rename APK artifacts # run: | @@ -155,4 +154,6 @@ jobs: fail_on_unmatched_files: true files: | apk/*.apk + apk/*.zip + apk/* debug-symbols.zip From d45fae44e7632d598ab2b4b15f90c5eed8c290b6 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 50/62] 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 5767b193..a7688d0d 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -153,7 +153,5 @@ jobs: prerelease: false fail_on_unmatched_files: true files: | - apk/*.apk - apk/*.zip apk/* debug-symbols.zip From 9439c75f75b5bfc9e1036463085c722163cb0722 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 51/62] Update Sync.yml --- .github/workflows/Sync.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/Sync.yml b/.github/workflows/Sync.yml index 5f630079..240c2d11 100644 --- a/.github/workflows/Sync.yml +++ b/.github/workflows/Sync.yml @@ -31,3 +31,4 @@ jobs: from_branch: sneed target_branch: master github_token: ${{ env.WORKFLOW_TOKEN }} + From bee076416cca502c11589e8fb086a8139de30520 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 52/62] 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 a7688d0d..e625095c 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -153,5 +153,5 @@ jobs: prerelease: false fail_on_unmatched_files: true files: | - apk/* + apk/*.apk debug-symbols.zip From faa1a0c02fadbcf04481e746483c20454b53154f 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 53/62] Update Sync.yml --- .github/workflows/Sync.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/Sync.yml b/.github/workflows/Sync.yml index 240c2d11..5f630079 100644 --- a/.github/workflows/Sync.yml +++ b/.github/workflows/Sync.yml @@ -31,4 +31,3 @@ jobs: from_branch: sneed target_branch: master github_token: ${{ env.WORKFLOW_TOKEN }} - From 393cefda8fe33cfefa7f57832db282c61bc9d7d4 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 54/62] Update APK-Release.yml --- .github/workflows/APK-Release.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index e625095c..8c5b374e 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -25,11 +25,11 @@ jobs: 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: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 From 963caf17949b429fa3b4395d3e62cef861ec63f7 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:47:12 -0400 Subject: [PATCH 55/62] Updated patches --- ...098-d-solarxr-Add-SolarXR-IPC-driver.patch | 1843 +++++++++-------- 1 file changed, 976 insertions(+), 867 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 - From 28b6771511e7a9e5b4c6551fa6ce0c4c05e6f2eb 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 56/62] Remove poo water from default icon --- assets/default_icon.png | Bin 930 -> 3135 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/assets/default_icon.png b/assets/default_icon.png index 414191f3d574fdd46871ed0bc5c1a377c816daac..2efba8b5d3475aaffd30c0b63f31106306fa42db 100644 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 MToxle5tfksCnKzgQL70(Y)*J~224-$g7srr_TW{|g`W-e9X?Q5Isesjt?cISFs|_}XCG~`} zbKln76x)^iV@~?Eft-sBI?^T=-;-wkqWRqB_pesL zga1_-6c`#97?>D1fDDKA$CjEenc~CQq_y-0BUBJ7`{C}5s>a(5&so;ZXZHJLcW;uO zecqw9FF!xDeIow!<5SHiyVh-zMK%nmkKIjKVbi9yzVqXE%|F`z-+%w!=e?mvv4FO#qst!rlM? From 870c3c07968945d18565a0e67f37b7082896ed6f Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Sun, 24 Aug 2025 09:56:21 -0400 Subject: [PATCH 57/62] Revert "Merge branch 'master' of https://github.com/Vindicus999/WiVRn" This reverts commit 6212dccc2be7dddafb9454be17b3a8a7d222e3cd, reversing changes made to 80e31b642ac3fc6c313a4750687fadb6365b9c10. --- .github/workflows/APK-Release.yml | 7 --- client/xr/xr.h | 92 ++++++++++++++++++++++++++++ flatpak/io.github.wivrn.wivrn.yml.in | 12 +++- 3 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 client/xr/xr.h 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/client/xr/xr.h b/client/xr/xr.h new file mode 100644 index 00000000..fae06d9a --- /dev/null +++ b/client/xr/xr.h @@ -0,0 +1,92 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2022 Guillaume Meunier + * Copyright (C) 2022 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifdef VERT_SHADER + +#if VSR + #extension GL_EXT_fragment_shading_rate: enable +#endif + + +layout (location = 0) in vec2 vPosition; +layout (location = 1) in uvec2 vUV; + +layout(location = 0) out vec4 outUV; + +layout(push_constant) uniform pc +{ + ivec4 rgb_rect; + ivec4 a_rect; +}; + +void main() +{ + gl_Position = vec4(vPosition, 0.0, 1.0); +#if VSR + gl_PrimitiveShadingRateEXT = int(bitfieldExtract(vUV.x, 28, 4)); + vec2 uv = bitfieldInsert(vUV, uvec2(0), 28, 4); +#else + vec2 uv = vUV; +#endif + outUV.xy = (uv + rgb_rect.xy) / rgb_rect.zw; + outUV.zw = (uv + a_rect.xy) / a_rect.zw; +} +#endif + +#ifdef FRAG_SHADER + +layout(constant_id = 0) const int alpha = 1; +layout(constant_id = 1) const bool do_srgb = false; + +layout(set = 0, binding = 0) uniform sampler2D rgb[alpha + 1]; + +layout(location = 0) in vec4 inUV; + +layout(location = 0) out vec4 outColor; + +float sRGB_to_linear(float x) +{ + if (x <= 0.04045) + return x / 12.92; + return pow((x + 0.055) / 1.055, 2.4); +} + +vec4 sRGB_to_linear_rgba(vec4 x) +{ + return vec4( + sRGB_to_linear(x.r), + sRGB_to_linear(x.g), + sRGB_to_linear(x.b), + x.a); +} + +void main() +{ + if (alpha == 1) + outColor = vec4(texture(rgb[0], inUV.xy).rgb, texture(rgb[1], inUV.zw).r); + else + outColor = texture(rgb[0], inUV.xy).rgba; + + if (do_srgb) + { + outColor = sRGB_to_linear_rgba(outColor); + } +} + +#endif diff --git a/flatpak/io.github.wivrn.wivrn.yml.in b/flatpak/io.github.wivrn.wivrn.yml.in index 737d1b04..803e9c99 100644 --- a/flatpak/io.github.wivrn.wivrn.yml.in +++ b/flatpak/io.github.wivrn.wivrn.yml.in @@ -23,6 +23,11 @@ finish-args: - --system-talk-name=org.freedesktop.Avahi # Allow getting the pretty hostname - --system-talk-name=org.freedesktop.hostname1 + # List applications from $XDG_DATA_DIRS + - --filesystem=host-os:ro + - --filesystem=xdg-data:ro + # List flatpak Steam games + - --filesystem=~/.var/app/com.valvesoftware.Steam:ro # Pipewire - --filesystem=xdg-run/pipewire-0 # Set the active OpenXR / OpenVR runtime @@ -93,10 +98,11 @@ modules: url: https://www.mpfr.org/mpfr-4.2.1/mpfr-4.2.1.tar.xz sha256: 277807353a6726978996945af13e52829e3abd7a9a5b7fb2793894e18f1fcbb2 - type: file - url: https://libisl.sourceforge.io/isl-0.26.tar.xz + dest-filename: isl-0.26.tar.xz + url: https://sourceforge.net/projects/libisl/files/isl-0.26.tar.xz/download sha256: a0b5cb06d24f9fa9e77b55fabbe9a3c94a336190345c2555f9915bb38e976504 - type: file - url: https://www.multiprecision.org/downloads/mpc-1.3.1.tar.gz + url: https://ftpmirror.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz sha256: ab642492f5cf882b74aa0cb730cd410a81edcdbec895183ce930e706c1c759b8 - type: file url: https://invisible-mirror.net/archives/ncurses/ncurses-6.4.tar.gz @@ -307,7 +313,7 @@ modules: sources: - type: git url: https://github.com/Supreeeme/xrizer.git - tag: fcc6793ffeadf0d7676c4cfd5a6c57da481a520c + tag: 76e01ac8ad79fed226a883985daa3cbe61271ca7 - xrizer-gen-src.json - name: wivrn-library From a110a54256c9e97c18dd82b9e031e20234c30410 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Sun, 24 Aug 2025 19:20:52 -0400 Subject: [PATCH 58/62] feat: add solarxr patches --- ...098-d-solarxr-Add-SolarXR-IPC-driver.patch | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 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 71e102c1..684840be 100644 --- a/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch +++ b/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch @@ -1,4 +1,4 @@ -From 7a3b7758a1ae3b0d9c7a48280f279f8e99b8b678 Mon Sep 17 00:00:00 2001 +From fee8044b7304f789f5bb6f1b3b442d57847dba7b 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 @@ -28,7 +28,7 @@ Subject: [PATCH] d/solarxr: Add SolarXR IPC driver create mode 100644 src/xrt/drivers/solarxr/solarxr_ipc_socket.h diff --git a/CMakeLists.txt b/CMakeLists.txt -index c84143343c..da462f4c3f 100644 +index f4f13fbb2..755bebb33 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 c84143343c..da462f4c3f 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) -@@ -443,6 +444,7 @@ list( +@@ -446,6 +447,7 @@ list( "TWRAP" "XREAL_AIR" "STEAMVR_LIGHTHOUSE" @@ -47,7 +47,7 @@ index c84143343c..da462f4c3f 100644 ) # Package name needs to be known by the native code itself. -@@ -672,6 +674,7 @@ message(STATUS "# DRIVER_VIVE: ${XRT_BUILD_DRIVER_VIVE}") +@@ -678,6 +680,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 c84143343c..da462f4c3f 100644 # cmake-format: on diff --git a/src/xrt/drivers/CMakeLists.txt b/src/xrt/drivers/CMakeLists.txt -index 0d422f16e4..5a823014d3 100644 +index 90dc4970f..a41d25117 100644 --- a/src/xrt/drivers/CMakeLists.txt +++ b/src/xrt/drivers/CMakeLists.txt -@@ -494,6 +494,23 @@ if(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE) +@@ -510,6 +510,23 @@ if(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE) list(APPEND ENABLED_HEADSET_DRIVERS steamvr_lh) endif() @@ -85,7 +85,7 @@ index 0d422f16e4..5a823014d3 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..55e235608c +index 000000000..55e235608 --- /dev/null +++ b/src/xrt/drivers/solarxr/feeder.c @@ -0,0 +1,286 @@ @@ -377,7 +377,7 @@ index 0000000000..55e235608c +} diff --git a/src/xrt/drivers/solarxr/feeder.h b/src/xrt/drivers/solarxr/feeder.h new file mode 100644 -index 0000000000..d5ef6a8b5f +index 000000000..d5ef6a8b5 --- /dev/null +++ b/src/xrt/drivers/solarxr/feeder.h @@ -0,0 +1,33 @@ @@ -416,7 +416,7 @@ index 0000000000..d5ef6a8b5f + bool (*filter)(struct xrt_device *device)); // thread safe diff --git a/src/xrt/drivers/solarxr/protocol.c b/src/xrt/drivers/solarxr/protocol.c new file mode 100644 -index 0000000000..01181b84a9 +index 000000000..01181b84a --- /dev/null +++ b/src/xrt/drivers/solarxr/protocol.c @@ -0,0 +1,383 @@ @@ -805,7 +805,7 @@ index 0000000000..01181b84a9 +} diff --git a/src/xrt/drivers/solarxr/protocol.h b/src/xrt/drivers/solarxr/protocol.h new file mode 100644 -index 0000000000..b630d26b41 +index 000000000..b630d26b4 --- /dev/null +++ b/src/xrt/drivers/solarxr/protocol.h @@ -0,0 +1,245 @@ @@ -1056,7 +1056,7 @@ index 0000000000..b630d26b41 +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..f6bf6ce53a +index 000000000..3fc8f74a0 --- /dev/null +++ b/src/xrt/drivers/solarxr/solarxr_device.c @@ -0,0 +1,1145 @@ @@ -2143,7 +2143,7 @@ index 0000000000..f6bf6ce53a + 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, NULL); ++ m_relation_history_create(&tracker->history); + tracker->role = SOLARXR_BODY_PART_NONE; + tracker->parent = device; + tracker->weak_ref = &device->trackers[i]; @@ -2207,7 +2207,7 @@ index 0000000000..f6bf6ce53a +} diff --git a/src/xrt/drivers/solarxr/solarxr_interface.h b/src/xrt/drivers/solarxr/solarxr_interface.h new file mode 100644 -index 0000000000..15916484ff +index 000000000..15916484f --- /dev/null +++ b/src/xrt/drivers/solarxr/solarxr_interface.h @@ -0,0 +1,40 @@ @@ -2253,7 +2253,7 @@ index 0000000000..15916484ff +#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 +index 000000000..0d97b5111 --- /dev/null +++ b/src/xrt/drivers/solarxr/solarxr_ipc_message.h @@ -0,0 +1,74 @@ @@ -2333,7 +2333,7 @@ index 0000000000..0d97b51118 +} 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 +index 000000000..b889a7616 --- /dev/null +++ b/src/xrt/drivers/solarxr/solarxr_ipc_socket.c @@ -0,0 +1,255 @@ @@ -2594,7 +2594,7 @@ index 0000000000..b889a76163 +} 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 +index 000000000..aaebfdd54 --- /dev/null +++ b/src/xrt/drivers/solarxr/solarxr_ipc_socket.h @@ -0,0 +1,49 @@ @@ -2648,10 +2648,10 @@ index 0000000000..aaebfdd547 + 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 +index e7655456a..c42697d0e 100644 --- a/src/xrt/targets/common/CMakeLists.txt +++ b/src/xrt/targets/common/CMakeLists.txt -@@ -201,6 +201,10 @@ if(XRT_BUILD_DRIVER_SIMULAVR) +@@ -205,6 +205,10 @@ if(XRT_BUILD_DRIVER_SIMULAVR) target_link_libraries(target_lists PRIVATE drv_svr) endif() @@ -2663,4 +2663,5 @@ index e2b9ba79d1..1fbf5f436f 100644 # Instance # -- -GitLab +2.50.1 + From ca05a3cf293a6b5c7545d16924561972652d5e20 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Wed, 24 Sep 2025 22:09:29 -0400 Subject: [PATCH 59/62] Update CMakeList.txt so that it's the same as Master --- CMakeLists.txt | 114 +++++++++++++------------------------------------ build.gradle | 1 + flake.nix | 1 + 3 files changed, 31 insertions(+), 85 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01c4980b..585c3434 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,13 +18,12 @@ 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) -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_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}) 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) @@ -37,12 +36,12 @@ option(WIVRN_WERROR "Treat warnings as errors" OFF) option(WIVRN_OPTIMIZE_SHADERS "Run siprv-opt on compiled shaders" ON) option(WIVRN_USE_NVENC "Enable nvenc (Nvidia) hardware 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_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_PIPEWIRE "Enable pipewire backend" AUTO) -auto_option(WIVRN_USE_PULSEAUDIO "Enable pulseaudio backend" AUTO) +option(WIVRN_USE_PIPEWIRE "Enable pipewire backend" ON) +option(WIVRN_USE_PULSEAUDIO "Enable pulseaudio backend" OFF) set(OVR_COMPAT_SEARCH_PATH "/usr/local/lib/OpenComposite:/usr/lib/OpenComposite:/opt/OpenComposite:/opt/opencomposite:/opt/xrizer" CACHE STRING "List of places to search for the OpenVR compatibility layer, separated by :") @@ -66,6 +65,12 @@ 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) @@ -77,19 +82,13 @@ endif() find_package(PkgConfig REQUIRED) find_package(Vulkan REQUIRED) find_package(Git) -if (NOT ANDROID) +if (NEED_COMMON AND NOT ANDROID) find_package(OpenSSL REQUIRED) endif() include(VulkanVersion) -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) +if (WIVRN_USE_SYSTEM_BOOST AND NEED_COMMON) + 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) @@ -106,72 +105,30 @@ 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 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) + if (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 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 (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 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) + if (WIVRN_USE_X264) pkg_check_modules(X264 REQUIRED IMPORTED_TARGET x264) endif() - 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) + if (WIVRN_USE_SYSTEMD) pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd) endif() - 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) + if (WIVRN_USE_PIPEWIRE) pkg_check_modules(libpipewire REQUIRED IMPORTED_TARGET libpipewire-0.3) endif() - 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) + if (WIVRN_USE_PULSEAUDIO) pkg_check_modules(libpulse REQUIRED IMPORTED_TARGET libpulse) endif() @@ -187,7 +144,8 @@ endif() if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER) pkg_check_modules(librsvg-2.0 REQUIRED IMPORTED_TARGET librsvg-2.0) - find_package(PNG) + find_package(LibArchive REQUIRED) + find_package(PNG REQUIRED) endif() if (WIVRN_BUILD_DASHBOARD) @@ -216,23 +174,11 @@ 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 STREQUAL "AUTO") - find_package(OpenXR 1.1.48) - elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON") + if (WIVRN_USE_SYSTEM_OPENXR) find_package(OpenXR 1.1.48 REQUIRED) endif() @@ -246,9 +192,7 @@ if(ANDROID) endif() if (WIVRN_BUILD_DISSECTOR) - if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO") - find_package(OpenXR 1.1.48) - elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON") + if (WIVRN_USE_SYSTEM_OPENXR) find_package(OpenXR 1.1.48 REQUIRED) endif() find_package(Wireshark REQUIRED) @@ -305,7 +249,7 @@ FetchContent_Declare(monado ) add_subdirectory(external) -if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_SERVER OR WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_DISSECTOR) +if (NEED_COMMON) add_subdirectory(common) endif() diff --git a/build.gradle b/build.gradle index b0dd3325..f4512f7a 100644 --- a/build.gradle +++ b/build.gradle @@ -124,6 +124,7 @@ 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/flake.nix b/flake.nix index eb6ebb76..93304fe4 100644 --- a/flake.nix +++ b/flake.nix @@ -19,6 +19,7 @@ pkgs.librsvg pkgs.libpng + pkgs.libarchive ]; extraNativeBuildInputs = [ pkgs.util-linux From 7867063c3705be6699c6d5523a6a3272ef371f1f Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Wed, 24 Sep 2025 22:10:21 -0400 Subject: [PATCH 60/62] Update flake.nix --- flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/flake.nix b/flake.nix index 93304fe4..ff091957 100644 --- a/flake.nix +++ b/flake.nix @@ -16,7 +16,6 @@ extraBuildInputs = [ # XRT_FEATURE_DEBUG_GUI requires SDL2 pkgs.sdl2-compat - pkgs.librsvg pkgs.libpng pkgs.libarchive From d89714070e4478c377541cd74e779d1b05b62597 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Wed, 24 Sep 2025 22:19:38 -0400 Subject: [PATCH 61/62] feat: add solarxr patches --- ...098-d-solarxr-Add-SolarXR-IPC-driver.patch | 2667 ----------------- 1 file changed, 2667 deletions(-) delete mode 100644 patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch diff --git a/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch b/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch deleted file mode 100644 index 684840be..00000000 --- a/patches/monado/0098-d-solarxr-Add-SolarXR-IPC-driver.patch +++ /dev/null @@ -1,2667 +0,0 @@ -From fee8044b7304f789f5bb6f1b3b442d57847dba7b 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 | 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/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 f4f13fbb2..755bebb33 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) -@@ -446,6 +447,7 @@ list( - "TWRAP" - "XREAL_AIR" - "STEAMVR_LIGHTHOUSE" -+ "SOLARXR" - ) - - # Package name needs to be known by the native code itself. -@@ -678,6 +680,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 90dc4970f..a41d25117 100644 ---- a/src/xrt/drivers/CMakeLists.txt -+++ b/src/xrt/drivers/CMakeLists.txt -@@ -510,6 +510,23 @@ 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/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 ipc_shared) -+ 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 000000000..55e235608 ---- /dev/null -+++ b/src/xrt/drivers/solarxr/feeder.c -@@ -0,0 +1,286 @@ -+// Copyright 2025, rcelyte -+// SPDX-License-Identifier: BSL-1.0 -+ -+#include "feeder.h" -+#include "solarxr_ipc_message.h" -+ -+#include "xrt/xrt_device.h" -+ -+#include -+ -+// #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_) \ -+ (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 DEBUG_FEEDER_DESTROY_GUARD -+ void (*old_destroy)(struct xrt_device *xdev); -+#endif -+}; -+ -+void -+feeder_send_feedback(struct feeder *const feeder, const timepoint_ns 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->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; -+ 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; -+ 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_VALID_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_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 -+ (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; -+ 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) { -+ 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; -+ solarxr_ipc_message_write_single(&packet_end, &packet[ARRAY_SIZE(packet)], message, -+ sizeof(message)); -+ } -+ } -+ if (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); -+} -+ -+static bool -+filter_feeder_device(struct xrt_device *const device, bool (*const filter)(struct xrt_device *device)) -+{ -+ return device != NULL && device->supported.orientation_tracking && (filter == NULL || filter(device)); -+} -+ -+#ifdef DEBUG_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 (!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; -+ } -+ } -+ 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[] = { -+ [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[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 DEBUG_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) { -+ 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) { -+ 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; -+ const char *role_name = "NONE"; -+ switch (devices[i]->device_type) { -+ 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]); -+ 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 DEBUG_FEEDER_DESTROY_GUARD -+ .old_destroy = devices[i]->destroy, -+#endif -+ }; -+#ifdef DEBUG_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 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; -+ } -+ 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)); -+ 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; -+ } -+ os_mutex_unlock(&feeder->mutex); -+ return result; -+} -+ -+bool -+feeder_init(struct feeder *const feeder, const enum u_logging_level log_level) -+{ -+ solarxr_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); -+ 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 000000000..d5ef6a8b5 ---- /dev/null -+++ b/src/xrt/drivers/solarxr/feeder.h -@@ -0,0 +1,33 @@ -+// Copyright 2025, rcelyte -+// SPDX-License-Identifier: BSL-1.0 -+ -+#pragma once -+#include "solarxr_ipc_socket.h" -+ -+#include "os/os_threading.h" -+ -+struct feeder_device; -+struct feeder -+{ -+ struct os_mutex mutex; -+ struct solarxr_ipc_socket socket; -+ _Atomic(timepoint_ns) 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, 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/protocol.c b/src/xrt/drivers/solarxr/protocol.c -new file mode 100644 -index 000000000..01181b84a ---- /dev/null -+++ b/src/xrt/drivers/solarxr/protocol.c -@@ -0,0 +1,383 @@ -+// 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 flatbuffers_vtable_t -+{ -+ flatbuffers_voffset_t vtable_size; -+ flatbuffers_voffset_t table_size; -+ flatbuffers_voffset_t offsets[]; -+}; -+ -+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 capacity = &buffer[buffer_len] - (const uint8_t *)ref; -+ if (capacity < size || offset == 0 || offset > capacity - size || (offset % sizeof(uint32_t)) != 0) { -+ return NULL; -+ } -+ return (const uint8_t *)ref + offset; -+} -+ -+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 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->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)) / sizeof(*vtable->offsets), vtable_cap); -+ i < length; ++i) { -+ const uint16_t offset = le16toh(vtable->offsets[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 000000000..b630d26b4 ---- /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 000000000..3fc8f74a0 ---- /dev/null -+++ b/src/xrt/drivers/solarxr/solarxr_device.c -@@ -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" -+#include "math/m_vec3.h" -+#include "os/os_time.h" -+#include "util/u_debug.h" -+#include "util/u_device.h" -+ -+#include -+#include -+#include -+#include -+ -+#define MAX_GENERIC_TRACKERS 32 -+ -+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) -+ -+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 solarxr_ipc_socket socket; -+ _Atomic(timepoint_ns) next_sync; -+ struct os_mutex mutex; -+ _Atomic(timepoint_ns) 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 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 -+ { -+ 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); -+ 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); -+} -+ -+static xrt_result_t -+solarxr_device_update_inputs(struct xrt_device *const xdev) -+{ -+ struct solarxr_device *const device = solarxr_device(xdev); -+ assert(device != NULL); -+ -+ 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; -+ } -+ 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; -+ } -+ 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}); -+ 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}); -+ // 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, -+ [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, -+ [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; -+ } -+ 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; -+ } -+ 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 -+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 { -+ 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 (solarxr_ipc_socket_wait_timeout(socket, (feeder != NULL) ? timeout - time_since_feedback : -1)); -+ 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 = 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)) { -+ 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; -+ -+ 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", (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); -+ solarxr_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; -+ } -+ -+ struct solarxr_device *const device = U_DEVICE_ALLOCATE(struct solarxr_device, U_DEVICE_ALLOC_NO_FLAGS, 2, 0); -+ 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.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; -+ device->base.inputs[1].name = XRT_INPUT_META_FULL_BODY_TRACKING; -+ device->thread.thread = pthread_self(); -+ const bool use_trackers = (out_xdevs_cap >= 2); -+ device->use_trackers = use_trackers; -+ 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 -+ if (((int)!feeder_init(&device->feeder, debug_get_log_option_solarxr_log()) | os_mutex_init(&device->mutex)) != -+ 0) { -+ goto fail; -+ } -+ -+ if (!solarxr_ipc_socket_connect(&device->socket, "SlimeVRRpc", "slimevr/SlimeVRRpc", device->base.serial, -+ sizeof(device->base.serial))) { -+ goto fail; -+ } -+ -+ struct -+ { -+ 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 (!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 = solarxr_ipc_socket_receive_blocking(&device->socket, NULL); -+ if (buffer.length == 0) { -+ U_LOG_IFL_E(device->socket.log_level, "solarxr_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]; -+ } -+ } -+ 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) { -+ 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; -+ 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.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); -+ 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 xdev_count) -+{ -+ struct solarxr_device *const solarxr = solarxr_device(device); -+ 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 000000000..15916484f ---- /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 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 000000000..0d97b5111 ---- /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 000000000..b889a7616 ---- /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 000000000..aaebfdd54 ---- /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 e7655456a..c42697d0e 100644 ---- a/src/xrt/targets/common/CMakeLists.txt -+++ b/src/xrt/targets/common/CMakeLists.txt -@@ -205,6 +205,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 - # --- -2.50.1 - From 7e0dba71a5691453961eb7561545347d2deb6bab Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Wed, 24 Sep 2025 22:20:41 -0400 Subject: [PATCH 62/62] feat(flatpak): enable WIVRN_FEATURE_SOLARXR --- flatpak/io.github.wivrn.wivrn.yml.in | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flatpak/io.github.wivrn.wivrn.yml.in b/flatpak/io.github.wivrn.wivrn.yml.in index 803e9c99..eda2e2f1 100644 --- a/flatpak/io.github.wivrn.wivrn.yml.in +++ b/flatpak/io.github.wivrn.wivrn.yml.in @@ -25,8 +25,10 @@ finish-args: - --system-talk-name=org.freedesktop.hostname1 # List applications from $XDG_DATA_DIRS - --filesystem=host-os:ro - - --filesystem=xdg-data:ro - # List flatpak Steam games + - --filesystem=xdg-data/applications:ro + # List Steam games + - --filesystem=xdg-data/Steam:ro + - --filesystem=~/.steam:ro - --filesystem=~/.var/app/com.valvesoftware.Steam:ro # Pipewire - --filesystem=xdg-run/pipewire-0 @@ -36,6 +38,7 @@ finish-args: # SlimeVR - --filesystem=xdg-run/SlimeVRInput - --filesystem=xdg-run/SlimeVRRpc + - --filesystem=xdg-run/app/dev.slimevr.SlimeVR # Let outside application access the WiVRn socket - --filesystem=xdg-run/wivrn:create - --own-name=io.github.wivrn.Server @@ -282,7 +285,7 @@ modules: sources: - type: git url: https://gitlab.com/znixian/OpenOVR.git - tag: 538639b86c5c71223f11040b09479e5c0a83078c + tag: cff07db75c4823afe93ed7027b03d5f7bc86f164 - name: xrizer buildsystem: simple @@ -344,6 +347,7 @@ modules: - -DWIVRN_BUILD_SERVER_LIBRARY=ON - -DWIVRN_BUILD_DASHBOARD=OFF - -DWIVRN_BUILD_WIVRNCTL=OFF + - -DWIVRN_FEATURE_SOLARXR=ON - -DWIVRN_WERROR=ON - -DFETCHCONTENT_FULLY_DISCONNECTED=ON - -DFETCHCONTENT_BASE_DIR=deps @@ -354,10 +358,6 @@ modules: - WIVRN_SRC1 WIVRN_SRC2 WIVRN_SRC3 - - type: archive - url: BOOSTPFR_URL - dest: deps/boostpfr-src - sha256: BOOSTPFR_SHA256 - type: git url: https://gitlab.freedesktop.org/monado/monado tag: MONADO_COMMIT @@ -365,7 +365,6 @@ modules: - type: shell commands: - cd deps/monado-src && ../../patches/apply.sh ../../patches/monado/* - - cd deps/boostpfr-src && ../../patches/apply.sh ../../flatpak/boostpfr-gcc-12-internal-compiler-error.patch - name: wivrn buildsystem: cmake-ninja @@ -380,7 +379,8 @@ modules: - -DWIVRN_USE_NVENC=ON - -DWIVRN_USE_VULKAN_ENCODE=ON - -DWIVRN_USE_PULSEAUDIO=OFF - - -DWIVRN_FEATURE_SOLARXR=ON + - -DWIVRN_USE_PIPEWIRE=ON + - -DWIVRN_USE_SYSTEM_BOOST=OFF - -DWIVRN_WERROR=ON - -DWIVRN_CHECK_CAPSYSNICE=OFF # Capabilities don't work inside flatpak - -DFETCHCONTENT_FULLY_DISCONNECTED=ON