Add support for passthrough in lobby

This commit is contained in:
Guillaume Meunier
2024-03-16 20:05:57 +01:00
parent a581e7f856
commit 6f5a00cdd3
13 changed files with 301 additions and 11 deletions
+3 -3
View File
@@ -35,11 +35,11 @@ class hand_tracker : public utils::handle<XrHandTrackerEXT>
public:
hand_tracker() = default;
hand_tracker(instance * inst, XrHandTrackerEXT h)
hand_tracker(instance & inst, XrHandTrackerEXT h)
{
id = h;
xrLocateHandJointsEXT = inst->get_proc<PFN_xrLocateHandJointsEXT>("xrLocateHandJointsEXT");
xrDestroyHandTrackerEXT = inst->get_proc<PFN_xrDestroyHandTrackerEXT>("xrDestroyHandTrackerEXT");
xrLocateHandJointsEXT = inst.get_proc<PFN_xrLocateHandJointsEXT>("xrLocateHandJointsEXT");
xrDestroyHandTrackerEXT = inst.get_proc<PFN_xrDestroyHandTrackerEXT>("xrDestroyHandTrackerEXT");
}
hand_tracker(hand_tracker &&) = default;
hand_tracker & operator=(hand_tracker &&) = default;
+1
View File
@@ -45,6 +45,7 @@ union event
XrEventDataReferenceSpaceChangePending space_changed_pending;
XrEventDataSessionStateChanged state_changed;
XrEventDataDisplayRefreshRateChangedFB refresh_rate_changed;
XrEventDataPassthroughStateChangedFB passthrough_state_changed;
};
class instance : public utils::handle<XrInstance>
{
+109
View File
@@ -0,0 +1,109 @@
/*
* 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/>.
*/
#include "passthrough.h"
#include "session.h"
#include "openxr/openxr.h"
xr::passthrough_fb::passthrough_fb(instance & inst, session & s)
{
PFN_xrCreatePassthroughFB xrCreatePassthroughFB = inst.get_proc<PFN_xrCreatePassthroughFB>("xrCreatePassthroughFB");
PFN_xrCreatePassthroughLayerFB xrCreatePassthroughLayerFB = inst.get_proc<PFN_xrCreatePassthroughLayerFB>("xrCreatePassthroughLayerFB");
xrDestroyPassthroughFB = inst.get_proc<PFN_xrDestroyPassthroughFB>("xrDestroyPassthroughFB");
xrPassthroughStartFB = inst.get_proc<PFN_xrPassthroughStartFB>("xrPassthroughStartFB");
xrPassthroughPauseFB = inst.get_proc<PFN_xrPassthroughPauseFB>("xrPassthroughPauseFB");
xrPassthroughLayerPauseFB = inst.get_proc<PFN_xrPassthroughLayerPauseFB>("xrPassthroughLayerPauseFB");
xrPassthroughLayerResumeFB = inst.get_proc<PFN_xrPassthroughLayerResumeFB>("xrPassthroughLayerResumeFB");
XrPassthroughCreateInfoFB info{
.type = XR_TYPE_PASSTHROUGH_CREATE_INFO_FB,
.flags = 0
};
CHECK_XR(xrCreatePassthroughFB(s, &info, &id));
XrPassthroughLayerCreateInfoFB layer_info{
.type = XR_TYPE_PASSTHROUGH_LAYER_CREATE_INFO_FB,
.passthrough = id,
.flags = 0,
.purpose = XR_PASSTHROUGH_LAYER_PURPOSE_RECONSTRUCTION_FB
};
CHECK_XR(xrCreatePassthroughLayerFB(s, &layer_info, &passthrough_layer));
composition_layer = XrCompositionLayerPassthroughFB{
.type = XR_TYPE_COMPOSITION_LAYER_PASSTHROUGH_FB,
.flags = 0,
.space = XR_NULL_HANDLE,
.layerHandle = passthrough_layer
};
}
xr::passthrough_fb::~passthrough_fb()
{
if (passthrough_layer && xrDestroyPassthroughLayerFB)
xrDestroyPassthroughLayerFB(passthrough_layer);
if (id != XR_NULL_HANDLE && xrDestroyPassthroughFB)
xrDestroyPassthroughFB(id);
}
void xr::passthrough_fb::start()
{
CHECK_XR(xrPassthroughStartFB(id));
CHECK_XR(xrPassthroughLayerResumeFB(passthrough_layer));
}
void xr::passthrough_fb::pause()
{
CHECK_XR(xrPassthroughLayerPauseFB(passthrough_layer));
CHECK_XR(xrPassthroughPauseFB(id));
}
xr::passthrough_htc::passthrough_htc(instance & inst, session & s)
{
PFN_xrCreatePassthroughHTC xrCreatePassthroughHTC = inst.get_proc<PFN_xrCreatePassthroughHTC>("xrCreatePassthroughHTC");
xrDestroyPassthroughHTC = inst.get_proc<PFN_xrDestroyPassthroughHTC>("xrDestroyPassthroughHTC");
XrPassthroughCreateInfoHTC info{
.type = XR_TYPE_PASSTHROUGH_CREATE_INFO_HTC,
.form = XR_PASSTHROUGH_FORM_PLANAR_HTC
};
CHECK_XR(xrCreatePassthroughHTC(s, &info, &id));
composition_layer = XrCompositionLayerPassthroughHTC{
.type = XR_TYPE_COMPOSITION_LAYER_PASSTHROUGH_HTC,
.layerFlags = 0,
.space = XR_NULL_HANDLE,
.passthrough = id,
.color = {
.type = XR_TYPE_PASSTHROUGH_COLOR_HTC,
.alpha = 1
}
};
}
xr::passthrough_htc::~passthrough_htc()
{
if (id != XR_NULL_HANDLE && xrDestroyPassthroughHTC)
xrDestroyPassthroughHTC(id);
}
+78
View File
@@ -0,0 +1,78 @@
/*
* 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 "openxr/openxr.h"
#include "xr.h"
#include <variant>
namespace xr
{
class session;
class passthrough_fb : public utils::handle<XrPassthroughFB>
{
PFN_xrDestroyPassthroughFB xrDestroyPassthroughFB{};
PFN_xrDestroyPassthroughLayerFB xrDestroyPassthroughLayerFB{};
PFN_xrPassthroughStartFB xrPassthroughStartFB{};
PFN_xrPassthroughPauseFB xrPassthroughPauseFB{};
PFN_xrPassthroughLayerPauseFB xrPassthroughLayerPauseFB{};
PFN_xrPassthroughLayerResumeFB xrPassthroughLayerResumeFB{};
XrPassthroughLayerFB passthrough_layer{};
XrCompositionLayerPassthroughFB composition_layer;
public:
passthrough_fb() = default;
passthrough_fb(instance &, session &);
passthrough_fb(passthrough_fb &&) = default;
passthrough_fb(const passthrough_fb &) = delete;
passthrough_fb & operator=(passthrough_fb &&) = default;
passthrough_fb & operator=(const passthrough_fb &) = delete;
~passthrough_fb();
void start();
void pause();
XrCompositionLayerBaseHeader * layer() { return (XrCompositionLayerBaseHeader*)&composition_layer; }
};
class passthrough_htc : public utils::handle<XrPassthroughHTC>
{
PFN_xrDestroyPassthroughHTC xrDestroyPassthroughHTC{};
XrCompositionLayerPassthroughHTC composition_layer;
public:
passthrough_htc() = default;
passthrough_htc(instance &, session &);
passthrough_htc(passthrough_htc &&) = default;
passthrough_htc(const passthrough_htc &) = delete;
passthrough_htc & operator=(passthrough_htc &&) = default;
passthrough_htc & operator=(const passthrough_htc &) = delete;
~passthrough_htc();
void start() {}
void pause() {}
XrCompositionLayerBaseHeader * layer() { return (XrCompositionLayerBaseHeader*)&composition_layer; }
};
using passthrough = std::variant<passthrough_fb, passthrough_htc>;
} // namespace xr
+1 -1
View File
@@ -93,7 +93,7 @@ xr::hand_tracker xr::session::create_hand_tracker(XrHandEXT hand, XrHandJointSet
assert(xrCreateHandTrackerEXT);
CHECK_XR(xrCreateHandTrackerEXT(id, &create_info, &ht));
return {inst, ht};
return {*inst, ht};
}
std::vector<vk::Format> xr::session::get_swapchain_formats() const
+27
View File
@@ -19,7 +19,9 @@
#include "system.h"
#include "application.h"
#include "details/enumerate.h"
#include "utils/contains.h"
#include "vk/check.h"
#include "xr/check.h"
#include <cassert>
@@ -82,6 +84,31 @@ XrSystemHandTrackingPropertiesEXT xr::system::hand_tracking_properties() const
return hand_tracking_prop;
}
bool xr::system::passthrough_supported() const
{
const std::vector<std::string>& xr_extensions = application::get_xr_extensions();
if (utils::contains(xr_extensions, XR_HTC_PASSTHROUGH_EXTENSION_NAME))
return true;
if (utils::contains(xr_extensions, XR_FB_PASSTHROUGH_EXTENSION_NAME))
{
XrSystemPassthroughPropertiesFB passthrough_prop
{
.type = XR_TYPE_SYSTEM_PASSTHROUGH_PROPERTIES_FB,
};
XrSystemProperties prop{
.type = XR_TYPE_SYSTEM_PROPERTIES,
.next = &passthrough_prop,
};
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
return passthrough_prop.supportsPassthrough;
}
return false;
}
vk::raii::PhysicalDevice xr::system::physical_device(vk::raii::Instance& vulkan) const
{
auto xrGetVulkanGraphicsDevice2KHR =
+1
View File
@@ -55,6 +55,7 @@ public:
XrSystemProperties properties() const;
XrSystemHandTrackingPropertiesEXT hand_tracking_properties() const;
bool passthrough_supported() const;
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
vk::raii::PhysicalDevice physical_device(vk::raii::Instance& vulkan) const;