Use comp_target_factory

This commit is contained in:
Patrick Nicolas
2022-12-09 22:19:18 +01:00
parent b77f877f46
commit a5726226a2
11 changed files with 103 additions and 50 deletions
+1 -1
View File
@@ -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
)
+3 -3
View File
@@ -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)
+37
View File
@@ -0,0 +1,37 @@
/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <chrono>
#include <cstdint>
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;
};
}
+1
View File
@@ -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)
{
+8 -6
View File
@@ -19,7 +19,9 @@
#pragma once
#include "wivrn_session.h"
#include "wivrn_packets.h"
#include "clock_offset.h"
#include "xrt/xrt_defines.h"
#include <algorithm>
#include <mutex>
#include <vector>
@@ -38,7 +40,7 @@ class history
std::vector<TimedData> 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<xrt_space_relation>
{
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 &);
};
+2 -2
View File
@@ -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<xrt::drivers::wivrn::wivrn_session> cnx, float fps)
comp_target * comp_target_wivrn_create(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> 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_ptr<xrt::drivers::wivrn::wivr
cn->set_title = comp_wivrn_set_title;
cn->flush = comp_wivrn_flush;
cn->fps = fps;
cn->c = c;
return cn;
}
+1 -1
View File
@@ -22,4 +22,4 @@
#include "main/comp_target.h"
#include "wivrn_session.h"
comp_target * comp_target_wivrn_create(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx, float fps);
comp_target * comp_target_wivrn_create(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx, struct comp_compositor *c, float fps);
-21
View File
@@ -40,7 +40,6 @@
#include <openxr/openxr.h>
#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<xrt::drivers::wivrn::wivrn_session> 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<wivrn_hmd *>(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<wivrn_hmd *>(xdev)->create_compositor_target(comp);
}
+38 -2
View File
@@ -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 <cmath>
struct wivrn_comp_target_factory : public comp_target_factory
{
std::shared_ptr<wivrn_session> session;
float fps;
wivrn_comp_target_factory(std::shared_ptr<wivrn_session> 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<wivrn_controller>(0, self->hmd.get(), self);
self->right_hand = std::make_unique<wivrn_controller>(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
};
+7 -10
View File
@@ -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<wivrn_session>
{
@@ -68,7 +65,7 @@ class wivrn_session : public std::enable_shared_from_this<wivrn_session>
wivrn_session(TCP && tcp, in6_addr & address);
public:
static xrt_system_devices *
static wivrn_system_devices *
create_session(TCP && tcp);
clock_offset
+5 -4
View File
@@ -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;
}