diff --git a/CMakeLists.txt b/CMakeLists.txt index 25856ff8..2ead49a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,7 @@ FetchContent_Declare(tinygltf URL https://github.com/syoyo/tinygltf/archive/refs FetchContent_Declare(boostpfr URL https://github.com/boostorg/pfr/archive/refs/tags/2.0.3.tar.gz) FetchContent_Declare(monado GIT_REPOSITORY https://gitlab.freedesktop.org/xytovl/monado - GIT_TAG 3046a5eee4105c4d1c07bc466d6e3a0bb749df42 + GIT_TAG 7fff0982b2ffbf5426e5de8085e1ce369cda8b6d ) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 2eb39864..8f270c5f 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -34,9 +34,9 @@ set(XRT_HAVE_SDL2 OFF) set(BUILD_DOC OFF) set(BUILD_TESTING OFF) -set(XRT_IPC_MSG_SOCK_FILENAME "wivrn_comp_ipc" CACHE STRING "Service socket filename") -set(XRT_PID_FILE_NAME "wivrn.pid" CACHE STRING "Service pidfile filename") -set(XRT_RUNTIME_SUFFIX "wivrn" CACHE STRING "OpenXR client library suffix") +set(XRT_IPC_MSG_SOCK_FILENAME "wivrn_comp_ipc" CACHE STRING "Service socket filename") +set(XRT_IPC_SERVICE_PID_FILE_NAME "wivrn.pid" CACHE STRING "Service pidfile filename") +set(OXR_RUNTIME_SUFFIX "wivrn" CACHE STRING "OpenXR client library suffix") FetchContent_GetProperties(monado) if(NOT monado_POPULATED) diff --git a/server/driver/clock_offset.h b/server/driver/clock_offset.h new file mode 100644 index 00000000..3dc5a006 --- /dev/null +++ b/server/driver/clock_offset.h @@ -0,0 +1,37 @@ +/* + * 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 . + */ + +#pragma once + +#include +#include + +namespace xrt::drivers::wivrn +{ +struct clock_offset +{ + std::chrono::nanoseconds epoch_offset{}; + + uint64_t from_headset(uint64_t) const; + + std::chrono::nanoseconds + to_headset(uint64_t timestamp_ns) const; +}; + +} diff --git a/server/driver/pose_list.cpp b/server/driver/pose_list.cpp index 5ce1c67b..47ea5fdc 100644 --- a/server/driver/pose_list.cpp +++ b/server/driver/pose_list.cpp @@ -25,6 +25,7 @@ #include "xrt_cast.h" using namespace xrt::auxiliary::math; +using namespace xrt::drivers::wivrn; xrt_space_relation interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t) { diff --git a/server/driver/pose_list.h b/server/driver/pose_list.h index 4053f3c8..300cc11e 100644 --- a/server/driver/pose_list.h +++ b/server/driver/pose_list.h @@ -19,7 +19,9 @@ #pragma once -#include "wivrn_session.h" +#include "wivrn_packets.h" +#include "clock_offset.h" +#include "xrt/xrt_defines.h" #include #include #include @@ -38,7 +40,7 @@ class history std::vector data; protected: - void add_sample(uint64_t timestamp, const Data & sample, const clock_offset & offset) + void add_sample(uint64_t timestamp, const Data & sample, const xrt::drivers::wivrn::clock_offset & offset) { std::lock_guard lock(mutex); @@ -99,13 +101,13 @@ xrt_space_relation extrapolate(const xrt_space_relation & a, const xrt_space_rel class pose_list : public history { - device_id device; + xrt::drivers::wivrn::device_id device; public: - pose_list(device_id id) : + pose_list(xrt::drivers::wivrn::device_id id) : device(id) {} - void update_tracking(const from_headset::tracking &, const clock_offset & offset); + void update_tracking(const xrt::drivers::wivrn::from_headset::tracking &, const xrt::drivers::wivrn::clock_offset & offset); - static xrt_space_relation convert_pose(const from_headset::tracking::pose &); + static xrt_space_relation convert_pose(const xrt::drivers::wivrn::from_headset::tracking::pose &); }; diff --git a/server/driver/wivrn_comp_target.cpp b/server/driver/wivrn_comp_target.cpp index 18647732..a5c0fe77 100644 --- a/server/driver/wivrn_comp_target.cpp +++ b/server/driver/wivrn_comp_target.cpp @@ -613,7 +613,6 @@ static VkResult comp_wivrn_present(struct comp_target * ct, xrt_relation_chain xrc{}; xrt_space_relation result{}; m_relation_chain_push_pose_if_not_identity(&xrc, &cn->c->base.slot.poses[eye]); - m_relation_chain_push_relation(&xrc, &cn->c->base.slot.head_relation); m_relation_chain_resolve(&xrc, &result); view_info.fov[eye] = xrt_cast(cn->c->base.slot.fovs[eye]); view_info.pose[eye] = xrt_cast(result.pose); @@ -731,7 +730,7 @@ static void comp_wivrn_info_gpu(struct comp_target * ct, int64_t frame_id, uint6 * */ -comp_target * comp_target_wivrn_create(std::shared_ptr cnx, float fps) +comp_target * comp_target_wivrn_create(std::shared_ptr cnx, struct comp_compositor* c, float fps) { wivrn_comp_target * cn = new wivrn_comp_target{}; @@ -751,6 +750,7 @@ comp_target * comp_target_wivrn_create(std::shared_ptrset_title = comp_wivrn_set_title; cn->flush = comp_wivrn_flush; cn->fps = fps; + cn->c = c; return cn; } diff --git a/server/driver/wivrn_comp_target.h b/server/driver/wivrn_comp_target.h index 81655189..620f4ce5 100644 --- a/server/driver/wivrn_comp_target.h +++ b/server/driver/wivrn_comp_target.h @@ -22,4 +22,4 @@ #include "main/comp_target.h" #include "wivrn_session.h" -comp_target * comp_target_wivrn_create(std::shared_ptr cnx, float fps); +comp_target * comp_target_wivrn_create(std::shared_ptr cnx, struct comp_compositor *c, float fps); diff --git a/server/driver/wivrn_hmd.cpp b/server/driver/wivrn_hmd.cpp index d4424cca..69075d50 100644 --- a/server/driver/wivrn_hmd.cpp +++ b/server/driver/wivrn_hmd.cpp @@ -40,7 +40,6 @@ #include #include "configuration.h" -#include "wivrn_comp_target.h" /* * @@ -77,10 +76,6 @@ static void wivrn_hmd_get_view_poses(xrt_device * xdev, xrt_fov * out_fovs, xrt_pose * out_poses); -static void wivrn_hmd_create_compositor_target(struct xrt_device * xdev, - struct comp_compositor * comp, - struct comp_target ** out_target); - static double foveate(double a, double b, double scale, double c, double x) { // In order to save encoding, transmit and decoding time, only a portion of the image is encoded in full resolution. @@ -237,7 +232,6 @@ wivrn_hmd::wivrn_hmd(std::shared_ptr cnx, base->update_inputs = wivrn_hmd_update_inputs; base->get_tracked_pose = wivrn_hmd_get_tracked_pose; base->get_view_poses = wivrn_hmd_get_view_poses; - base->create_compositor_target = wivrn_hmd_create_compositor_target; base->destroy = wivrn_hmd_destroy; name = XRT_DEVICE_GENERIC_HMD; device_type = XRT_DEVICE_TYPE_HMD; @@ -389,14 +383,6 @@ void wivrn_hmd::get_view_poses(const xrt_vec3 * default_eye_relation, } } -comp_target * wivrn_hmd::create_compositor_target(struct comp_compositor * comp) -{ - comp_target * target = comp_target_wivrn_create(cnx, fps); - - target->c = comp; - return target; -} - /* * * Functions @@ -431,10 +417,3 @@ static void wivrn_hmd_get_view_poses(xrt_device * xdev, { static_cast(xdev)->get_view_poses(default_eye_relation, at_timestamp_ns, view_count, out_head_relation, out_fovs, out_poses); } - -static void wivrn_hmd_create_compositor_target(struct xrt_device * xdev, - struct comp_compositor * comp, - struct comp_target ** out_target) -{ - *out_target = static_cast(xdev)->create_compositor_target(comp); -} diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index d84406cd..c268967a 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -22,17 +22,51 @@ #include "os/os_time.h" #include "util/u_logging.h" +#include "wivrn_comp_target.h" #include "wivrn_controller.h" #include "wivrn_hmd.h" #include +struct wivrn_comp_target_factory : public comp_target_factory +{ + std::shared_ptr session; + float fps; + + wivrn_comp_target_factory(std::shared_ptr session, float fps) : + comp_target_factory{ + .name = "WiVRn", + .identifier = "wivrn", + .requires_vulkan_for_create = false, + .is_deferred = false, + .required_instance_extensions = {}, + .required_instance_extension_count = 0, + .detect = wivrn_comp_target_factory::detect, + .create_target = wivrn_comp_target_factory::create_target}, + session(session), + fps(fps) + {} + + static bool detect(struct comp_target_factory * ctf, struct comp_compositor * c) + { + return true; + } + + static bool create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) + { + auto self = (wivrn_comp_target_factory*)ctf; + *out_ct = comp_target_wivrn_create(self->session, c, self->fps); + return true; + } +}; + + xrt::drivers::wivrn::wivrn_session::wivrn_session(xrt::drivers::wivrn::TCP && tcp, in6_addr & address) : connection(std::move(tcp), address) { } -xrt_system_devices * xrt::drivers::wivrn::wivrn_session::create_session(xrt::drivers::wivrn::TCP && tcp) +wivrn_system_devices * xrt::drivers::wivrn::wivrn_session::create_session(xrt::drivers::wivrn::TCP && tcp) { sockaddr_in6 address; socklen_t address_len = sizeof(address); @@ -77,7 +111,7 @@ xrt_system_devices * xrt::drivers::wivrn::wivrn_session::create_session(xrt::dri self->left_hand = std::make_unique(0, self->hmd.get(), self); self->right_hand = std::make_unique(1, self->hmd.get(), self); - xrt_system_devices * devices = new xrt_system_devices{}; + wivrn_system_devices * devices = new wivrn_system_devices{}; int n = 0; if (self->hmd) @@ -88,6 +122,8 @@ xrt_system_devices * xrt::drivers::wivrn::wivrn_session::create_session(xrt::dri devices->roles.right = devices->xdevs[n++] = self->right_hand.get(); devices->xdev_count = n; + + devices->ctf = new wivrn_comp_target_factory(self, info.preferred_refresh_rate); devices->destroy = [](xrt_system_devices * xsd) { // TODO }; diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 8312a538..e01b5e0d 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -19,6 +19,8 @@ #pragma once +#include "clock_offset.h" +#include "main/comp_target.h" #include "wivrn_connection.h" #include "wivrn_packets.h" #include "xrt/xrt_system.h" @@ -35,15 +37,10 @@ struct audio_publish_handle; namespace xrt::drivers::wivrn { -struct clock_offset -{ - std::chrono::nanoseconds epoch_offset{}; - - uint64_t from_headset(uint64_t) const; - - std::chrono::nanoseconds - to_headset(uint64_t timestamp_ns) const; -}; + struct wivrn_system_devices : public xrt_system_devices + { + comp_target_factory *ctf; + }; class wivrn_session : public std::enable_shared_from_this { @@ -68,7 +65,7 @@ class wivrn_session : public std::enable_shared_from_this wivrn_session(TCP && tcp, in6_addr & address); public: - static xrt_system_devices * + static wivrn_system_devices * create_session(TCP && tcp); clock_offset diff --git a/server/target_instance_wivrn.cpp b/server/target_instance_wivrn.cpp index 3fd8a7b8..3eda35ef 100644 --- a/server/target_instance_wivrn.cpp +++ b/server/target_instance_wivrn.cpp @@ -7,8 +7,8 @@ */ #include "xrt/xrt_config_build.h" -#include "xrt/xrt_gfx_native.h" #include "xrt/xrt_system.h" +#include "main/comp_main_interface.h" #include "os/os_time.h" @@ -38,7 +38,7 @@ wivrn_instance_create_system(struct xrt_instance * xinst, assert(out_xsysc == NULL || *out_xsysc == NULL); struct xrt_system_compositor * xsysc = NULL; - struct xrt_system_devices * xsysd = xrt::drivers::wivrn::wivrn_session::create_session(std::move(*tcp)); + auto * xsysd = xrt::drivers::wivrn::wivrn_session::create_session(std::move(*tcp)); tcp.reset(); if (!xsysd) @@ -50,12 +50,13 @@ wivrn_instance_create_system(struct xrt_instance * xinst, if (xret == XRT_SUCCESS && xsysc == NULL) { - xret = xrt_gfx_provider_create_system(head, &xsysc); + xret = comp_main_create_system_compositor(head, xsysd->ctf, &xsysc); } if (xret != XRT_SUCCESS) { - xrt_system_devices_destroy(&xsysd); + if (xsysd) + xsysd->destroy(xsysd); return xret; }