Automatically enable passthrough if color passthrough is supported

This commit is contained in:
Guillaume Meunier
2024-03-16 20:05:57 +01:00
parent b60c1f7b61
commit 3a02198156
9 changed files with 74 additions and 28 deletions
+13 -4
View File
@@ -18,8 +18,6 @@
*/
#include "application.h"
#include "hardware.h"
#include "magic_enum.hpp"
#include "openxr/openxr.h"
#include "scene.h"
#include "spdlog/common.h"
@@ -395,7 +393,7 @@ void application::initialize_vulkan()
spdlog::info("Available Vulkan instance extensions:");
for(vk::ExtensionProperties& i: vk_context.enumerateInstanceExtensionProperties(nullptr))
{
spdlog::info(" {}", i.extensionName);
spdlog::info(" {} (version {})", i.extensionName, i.specVersion);
#ifndef NDEBUG
if (!strcmp(i.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME))
@@ -804,7 +802,18 @@ void application::initialize()
}
}
spdlog::info("Passthrough: {}", xr_system_id.passthrough_supported() ? "supported" : "not supported");
switch(xr_system_id.passthrough_supported())
{
case xr::system::passthrough_type::no_passthrough:
spdlog::info("Passthrough: not supported");
break;
case xr::system::passthrough_type::bw:
spdlog::info("Passthrough: black and white");
break;
case xr::system::passthrough_type::color:
spdlog::info("Passthrough: color");
break;
}
vk::CommandPoolCreateInfo cmdpool_create_info;
+7 -6
View File
@@ -24,23 +24,24 @@
#include <android_native_app_glue.h>
#endif
#include "utils/singleton.h"
#include "vk/vk_allocator.h"
#include "xr/xr.h"
#include <array>
#include <atomic>
#include <chrono>
#include <filesystem>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <mutex>
#include <unordered_set>
#include <optional>
#include <spdlog/spdlog.h>
#include <unordered_map>
#include <unordered_set>
#include <vulkan/vulkan_raii.hpp>
#include <openxr/openxr.h>
#include <openxr/openxr_platform.h>
#include <openxr/openxr_reflection.h>
#include "vk/vk_allocator.h"
#include "utils/singleton.h"
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <spdlog/spdlog.h>
class scene;
+4 -3
View File
@@ -187,6 +187,9 @@ scenes::lobby::lobby()
if (std::getenv("WIVRN_AUTOCONNECT"))
force_autoconnect = true;
passthrough_supported = system.passthrough_supported();
passthrough_enabled = passthrough_supported == xr::system::passthrough_type::color;
try
{
simdjson::dom::parser parser;
@@ -265,9 +268,7 @@ scenes::lobby::lobby()
spdlog::info("Using format {}", vk::to_string(swapchain_format));
passthrough_supported = system.passthrough_supported();
if (passthrough_supported)
if (passthrough_supported != xr::system::passthrough_type::no_passthrough)
{
if (utils::contains(application::get_xr_extensions(), XR_FB_PASSTHROUGH_EXTENSION_NAME))
{
+1 -1
View File
@@ -89,7 +89,7 @@ class lobby : public scene_impl<lobby>
std::vector<xr::swapchain> swapchains_controllers;
xr::swapchain swapchain_imgui;
vk::Format swapchain_format;
bool passthrough_supported;
xr::system::passthrough_type passthrough_supported;
xr::passthrough passthrough;
void save_config();
+1 -1
View File
@@ -383,7 +383,7 @@ void scenes::lobby::gui_settings()
}
vibrate_on_hover();
ImGui::BeginDisabled(!passthrough_supported);
ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough);
if (ImGui::Checkbox("Enable video passthrough in lobby", &passthrough_enabled))
{
save_config();
+11 -4
View File
@@ -74,10 +74,10 @@ xr::instance::instance(std::string_view application_name, std::vector<const char
spdlog::info("Available OpenXR extensions:");
bool debug_utils_found = false;
for (XrExtensionProperties & i:
xr::details::enumerate<XrExtensionProperties>(xrEnumerateInstanceExtensionProperties, nullptr))
auto all_extensions = xr::instance::extensions();
for (XrExtensionProperties & i: all_extensions)
{
spdlog::info(" {}", i.extensionName);
spdlog::info(" {} (version {})", i.extensionName, i.extensionVersion);
#ifndef NDEBUG
if (!strcmp(i.extensionName, "XR_EXT_debug_utils"))
{
@@ -90,7 +90,14 @@ xr::instance::instance(std::string_view application_name, std::vector<const char
spdlog::info("Using OpenXR extensions:");
for (auto & i: extensions)
{
loaded_extensions.insert(i);
uint32_t version = 0;
for(auto & j: all_extensions)
{
if (!strcmp(j.extensionName, i))
version = j.extensionVersion;
}
loaded_extensions.emplace(i, version);
spdlog::info(" {}", i);
}
+10 -4
View File
@@ -23,13 +23,11 @@
#include <android_native_app_glue.h>
#endif
#include "error.h"
#include "utils/handle.h"
#include "xr/check.h"
#include <optional>
#include <string>
#include <string_view>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <vulkan/vulkan.h>
#include <openxr/openxr.h>
@@ -51,7 +49,7 @@ class instance : public utils::handle<XrInstance>
{
std::string runtime_version;
std::string runtime_name;
std::unordered_set<std::string> loaded_extensions;
std::unordered_map<std::string, uint32_t> loaded_extensions;
public:
#if defined(XR_USE_PLATFORM_ANDROID)
@@ -98,5 +96,13 @@ public:
{
return loaded_extensions.find(extension_name) != loaded_extensions.end();
}
uint32_t extension_version(const std::string & extension_name)
{
auto it = loaded_extensions.find(extension_name);
if (it != loaded_extensions.end())
return it->second;
return 0;
}
};
} // namespace xr
+19 -4
View File
@@ -21,6 +21,7 @@
#include "application.h"
#include "details/enumerate.h"
#include "openxr/openxr.h"
#include "utils/contains.h"
#include "vk/check.h"
#include "xr/check.h"
@@ -84,17 +85,22 @@ XrSystemHandTrackingPropertiesEXT xr::system::hand_tracking_properties() const
return hand_tracking_prop;
}
bool xr::system::passthrough_supported() const
xr::system::passthrough_type 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;
return passthrough_type::color;
if (utils::contains(xr_extensions, XR_FB_PASSTHROUGH_EXTENSION_NAME))
{
XrSystemPassthroughProperties2FB passthrough_prop2{
.type = XR_TYPE_SYSTEM_PASSTHROUGH_PROPERTIES2_FB,
};
XrSystemPassthroughPropertiesFB passthrough_prop
{
.type = XR_TYPE_SYSTEM_PASSTHROUGH_PROPERTIES_FB,
.next = &passthrough_prop2,
};
XrSystemProperties prop{
@@ -103,10 +109,19 @@ bool xr::system::passthrough_supported() const
};
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
return passthrough_prop.supportsPassthrough;
if (passthrough_prop.supportsPassthrough)
{
if (!(passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_BIT_FB))
return passthrough_type::no_passthrough;
if (passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_COLOR_BIT_FB)
return passthrough_type::color;
return passthrough_type::bw;
}
}
return false;
return passthrough_type::no_passthrough;
}
vk::raii::PhysicalDevice xr::system::physical_device(vk::raii::Instance& vulkan) const
+8 -1
View File
@@ -39,6 +39,13 @@ class system
XrSystemId id = XR_NULL_SYSTEM_ID;
public:
enum class passthrough_type
{
no_passthrough,
bw,
color
};
system() = default;
system(const system &) = default;
system & operator=(const system &) = default;
@@ -55,7 +62,7 @@ public:
XrSystemProperties properties() const;
XrSystemHandTrackingPropertiesEXT hand_tracking_properties() const;
bool passthrough_supported() const;
passthrough_type passthrough_supported() const;
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
vk::raii::PhysicalDevice physical_device(vk::raii::Instance& vulkan) const;