Move everything in the client/ subdirectory
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 "actionset.h"
|
||||
#include "xr.h"
|
||||
#include <cstring>
|
||||
|
||||
xr::actionset::actionset(xr::instance & inst, const std::string & name, const std::string & localized_name, uint32_t priority)
|
||||
{
|
||||
this->inst = &inst;
|
||||
|
||||
XrActionSetCreateInfo create_info{};
|
||||
create_info.type = XR_TYPE_ACTION_SET_CREATE_INFO;
|
||||
strncpy(create_info.actionSetName, name.c_str(), sizeof(create_info.actionSetName) - 1);
|
||||
strncpy(create_info.localizedActionSetName, localized_name.c_str(), sizeof(create_info.localizedActionSetName) - 1);
|
||||
create_info.priority = priority;
|
||||
|
||||
CHECK_XR(xrCreateActionSet(inst, &create_info, &id));
|
||||
}
|
||||
|
||||
XrAction xr::actionset::create_action(XrActionType type, const std::string & name, const std::string & localized_name, const std::vector<std::string> & subactionpaths)
|
||||
{
|
||||
std::vector<XrPath> paths(subactionpaths.size());
|
||||
for (size_t i = 0; i < subactionpaths.size(); i++)
|
||||
{
|
||||
paths[i] = inst->string_to_path(subactionpaths[i]);
|
||||
}
|
||||
|
||||
XrActionCreateInfo create_info{};
|
||||
create_info.type = XR_TYPE_ACTION_CREATE_INFO;
|
||||
create_info.actionType = type,
|
||||
strncpy(create_info.actionName, name.c_str(), sizeof(create_info.actionName) - 1);
|
||||
strncpy(create_info.localizedActionName, localized_name.c_str(), sizeof(create_info.localizedActionName) - 1);
|
||||
create_info.countSubactionPaths = paths.size();
|
||||
create_info.subactionPaths = paths.data();
|
||||
|
||||
XrAction action;
|
||||
CHECK_XR(xrCreateAction(id, &create_info, &action));
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
xr::actionset::~actionset()
|
||||
{
|
||||
if (id != XR_NULL_HANDLE)
|
||||
xrDestroyActionSet(id);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 "utils/handle.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class instance;
|
||||
|
||||
class actionset : public utils::handle<XrActionSet>
|
||||
{
|
||||
instance * inst;
|
||||
|
||||
public:
|
||||
actionset() = default;
|
||||
actionset(instance & inst, const std::string & name, const std::string & localized_name, uint32_t priority = 0);
|
||||
actionset(actionset &&) = default;
|
||||
actionset & operator=(actionset &&) = default;
|
||||
|
||||
XrAction create_action(XrActionType type, const std::string & name, const std::string & localized_name, const std::vector<std::string> & subactionpaths = {});
|
||||
|
||||
XrAction create_action(XrActionType type, const std::string & name, const std::vector<std::string> & subactionpaths = {})
|
||||
{
|
||||
return create_action(type, name, name, subactionpaths);
|
||||
}
|
||||
|
||||
~actionset();
|
||||
};
|
||||
} // namespace xr
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#ifdef XR_USE_PLATFORM_ANDROID
|
||||
#include <jni.h>
|
||||
#endif
|
||||
|
||||
#include "utils/check.h"
|
||||
#include "utils/typename.h"
|
||||
#include <type_traits>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <openxr/openxr.h>
|
||||
#include <openxr/openxr_platform.h>
|
||||
|
||||
namespace xr::details
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct structure_traits_base
|
||||
{
|
||||
static constexpr inline XrStructureType type = XR_TYPE_UNKNOWN;
|
||||
using base = T;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct structure_traits : structure_traits_base<T>
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct structure_traits<XrViewConfigurationView> : structure_traits_base<XrViewConfigurationView>
|
||||
{
|
||||
static constexpr inline XrStructureType type = XR_TYPE_VIEW_CONFIGURATION_VIEW;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct structure_traits<XrView> : structure_traits_base<XrView>
|
||||
{
|
||||
static constexpr inline XrStructureType type = XR_TYPE_VIEW;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct structure_traits<XrApiLayerProperties> : structure_traits_base<XrApiLayerProperties>
|
||||
{
|
||||
static constexpr inline XrStructureType type = XR_TYPE_API_LAYER_PROPERTIES;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct structure_traits<XrExtensionProperties> : structure_traits_base<XrExtensionProperties>
|
||||
{
|
||||
static constexpr inline XrStructureType type = XR_TYPE_EXTENSION_PROPERTIES;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct structure_traits<XrSwapchainImageVulkanKHR> : structure_traits_base<XrSwapchainImageVulkanKHR>
|
||||
{
|
||||
static constexpr inline XrStructureType type = XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR;
|
||||
using base = XrSwapchainImageBaseHeader;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
constexpr inline XrStructureType structure_type = structure_traits<T>::type;
|
||||
|
||||
template <typename T, typename F, typename... Args>
|
||||
auto enumerate(F f, Args &&... args) -> auto
|
||||
{
|
||||
using array_type = std::conditional_t<std::is_same_v<T, char>, std::string, std::vector<T>>;
|
||||
array_type array;
|
||||
uint32_t count;
|
||||
XrResult result;
|
||||
|
||||
result = f(std::forward<Args>(args)..., 0, &count, nullptr);
|
||||
|
||||
if (XR_SUCCEEDED(result))
|
||||
{
|
||||
if constexpr (structure_type<T> == XR_TYPE_UNKNOWN)
|
||||
{
|
||||
array.resize(count);
|
||||
}
|
||||
else
|
||||
{
|
||||
T default_value{};
|
||||
default_value.type = structure_type<T>;
|
||||
array.resize(count, default_value);
|
||||
}
|
||||
result = f(std::forward<Args>(args)..., count, &count, reinterpret_cast<typename structure_traits<T>::base *>(array.data()));
|
||||
}
|
||||
|
||||
if (!XR_SUCCEEDED(result))
|
||||
{
|
||||
throw std::system_error(result, xr::error_category(), "enumerating " + type_name<T>());
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
} // namespace xr::details
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 "utils/check.h"
|
||||
#include "xr.h"
|
||||
#include <system_error>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct : std::error_category
|
||||
{
|
||||
const char * name() const noexcept override
|
||||
{
|
||||
return "openxr";
|
||||
}
|
||||
|
||||
std::string message(int condition) const override
|
||||
{
|
||||
return xr::to_string(static_cast<XrResult>(condition));
|
||||
}
|
||||
} openxr_error_category;
|
||||
} // namespace
|
||||
|
||||
const std::error_category & xr::error_category()
|
||||
{
|
||||
return openxr_error_category;
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* 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 "instance.h"
|
||||
|
||||
#include "spdlog/fmt/fmt.h"
|
||||
#include "xr.h"
|
||||
#include "xr/details/enumerate.h"
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <utility>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <openxr/openxr.h>
|
||||
#include <openxr/openxr_platform.h>
|
||||
#include <openxr/openxr_reflection.h>
|
||||
|
||||
static XrBool32 debug_callback(
|
||||
XrDebugUtilsMessageSeverityFlagsEXT messageSeverity,
|
||||
XrDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
const XrDebugUtilsMessengerCallbackDataEXT * callbackData,
|
||||
void * userData)
|
||||
{
|
||||
spdlog::info("OpenXR debug message: severity={}, type={}, function={}, {}", messageSeverity, messageTypes, callbackData->functionName, callbackData->message);
|
||||
|
||||
return XR_FALSE;
|
||||
}
|
||||
|
||||
#if defined(XR_USE_PLATFORM_ANDROID)
|
||||
xr::instance::instance(std::string_view application_name, void * applicationVM, void * applicationActivity, std::vector<const char *> extensions)
|
||||
#else
|
||||
xr::instance::instance(std::string_view application_name, std::vector<const char *> extensions)
|
||||
#endif
|
||||
{
|
||||
#if defined(XR_USE_GRAPHICS_API_VULKAN)
|
||||
extensions.push_back(XR_KHR_VULKAN_ENABLE2_EXTENSION_NAME);
|
||||
#else
|
||||
#error Not implemented
|
||||
#endif
|
||||
|
||||
#if defined(XR_USE_PLATFORM_ANDROID)
|
||||
extensions.push_back(XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME);
|
||||
#endif
|
||||
|
||||
std::vector<const char *> layers;
|
||||
// TODO: runtime switch
|
||||
|
||||
spdlog::info("Available OpenXR layers:");
|
||||
for (XrApiLayerProperties & i: xr::details::enumerate<XrApiLayerProperties>(xrEnumerateApiLayerProperties))
|
||||
{
|
||||
spdlog::info(" {}", i.layerName);
|
||||
#ifndef NDEBUG
|
||||
if (!strcmp(i.layerName, "XR_APILAYER_LUNARG_core_validation"))
|
||||
{
|
||||
layers.push_back("XR_APILAYER_LUNARG_core_validation");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
spdlog::info("Available OpenXR extensions:");
|
||||
bool debug_utils_found = false;
|
||||
for (XrExtensionProperties & i:
|
||||
xr::details::enumerate<XrExtensionProperties>(xrEnumerateInstanceExtensionProperties, nullptr))
|
||||
{
|
||||
spdlog::info(" {}", i.extensionName);
|
||||
#ifndef NDEBUG
|
||||
if (!strcmp(i.extensionName, "XR_EXT_debug_utils"))
|
||||
{
|
||||
debug_utils_found = true;
|
||||
extensions.push_back("XR_EXT_debug_utils");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
spdlog::info("Using OpenXR extensions:");
|
||||
for (auto & i: extensions)
|
||||
{
|
||||
loaded_extensions.insert(i);
|
||||
spdlog::info(" {}", i);
|
||||
}
|
||||
|
||||
XrInstanceCreateInfo create_info{
|
||||
.type = XR_TYPE_INSTANCE_CREATE_INFO,
|
||||
.applicationInfo = {.apiVersion = XR_CURRENT_API_VERSION},
|
||||
.enabledApiLayerCount = (uint32_t)layers.size(),
|
||||
.enabledApiLayerNames = layers.data(),
|
||||
.enabledExtensionCount = (uint32_t)extensions.size(),
|
||||
.enabledExtensionNames = extensions.data(),
|
||||
};
|
||||
strncpy(create_info.applicationInfo.applicationName, application_name.data(), sizeof(create_info.applicationInfo.applicationName) - 1);
|
||||
|
||||
#if defined(XR_USE_PLATFORM_ANDROID)
|
||||
XrInstanceCreateInfoAndroidKHR instanceCreateInfoAndroid{
|
||||
.type = XR_TYPE_INSTANCE_CREATE_INFO_ANDROID_KHR,
|
||||
.applicationVM = applicationVM,
|
||||
.applicationActivity = applicationActivity,
|
||||
};
|
||||
create_info.next = &instanceCreateInfoAndroid;
|
||||
#endif
|
||||
|
||||
CHECK_XR(xrCreateInstance(&create_info, &id));
|
||||
assert(id != XR_NULL_HANDLE);
|
||||
|
||||
if (debug_utils_found)
|
||||
{
|
||||
XrDebugUtilsMessengerCreateInfoEXT debug_messenger_info{
|
||||
.type = XR_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
|
||||
.messageSeverities = XR_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | XR_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT | XR_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | XR_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT,
|
||||
.messageTypes = XR_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | XR_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT | XR_DEBUG_UTILS_MESSAGE_TYPE_CONFORMANCE_BIT_EXT,
|
||||
.userCallback = debug_callback};
|
||||
auto xrCreateDebugUtilsMessengerEXT = get_proc<PFN_xrCreateDebugUtilsMessengerEXT>("xrCreateDebugUtilsMessengerEXT");
|
||||
XrDebugUtilsMessengerEXT messenger;
|
||||
CHECK_XR(xrCreateDebugUtilsMessengerEXT(id, &debug_messenger_info, &messenger));
|
||||
}
|
||||
|
||||
XrInstanceProperties prop{XR_TYPE_INSTANCE_PROPERTIES};
|
||||
CHECK_XR(xrGetInstanceProperties(id, &prop));
|
||||
// TODO: exception safety
|
||||
// if (!XR_SUCCEEDED(result))
|
||||
// {
|
||||
// xrDestroyInstance(id);
|
||||
// throw error("Cannot get instance properties", result);
|
||||
// }
|
||||
|
||||
runtime_version = to_string(prop.runtimeVersion);
|
||||
runtime_name = prop.runtimeName;
|
||||
}
|
||||
|
||||
std::string xr::instance::path_to_string(XrPath path)
|
||||
{
|
||||
if (path == XR_NULL_PATH)
|
||||
return "XR_NULL_PATH";
|
||||
|
||||
uint32_t length;
|
||||
std::string s;
|
||||
|
||||
CHECK_XR(xrPathToString(id, path, 0, &length, nullptr));
|
||||
s.resize(length);
|
||||
CHECK_XR(xrPathToString(id, path, length, &length, s.data()));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
XrPath xr::instance::string_to_path(const std::string & path)
|
||||
{
|
||||
XrPath p;
|
||||
CHECK_XR(xrStringToPath(id, path.c_str(), &p));
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
bool xr::instance::poll_event(xr::event & buffer)
|
||||
{
|
||||
buffer.header.type = XR_TYPE_EVENT_DATA_BUFFER;
|
||||
buffer.header.next = nullptr;
|
||||
XrResult result = CHECK_XR(xrPollEvent(id, &buffer.header));
|
||||
|
||||
return result == XR_SUCCESS;
|
||||
}
|
||||
|
||||
void xr::instance::suggest_bindings(const std::string & interaction_profile,
|
||||
std::vector<XrActionSuggestedBinding> & bindings)
|
||||
{
|
||||
XrInteractionProfileSuggestedBinding suggested_binding{};
|
||||
suggested_binding.type = XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING;
|
||||
suggested_binding.interactionProfile = string_to_path(interaction_profile);
|
||||
suggested_binding.countSuggestedBindings = bindings.size();
|
||||
suggested_binding.suggestedBindings = bindings.data();
|
||||
CHECK_XR(xrSuggestInteractionProfileBindings(id, &suggested_binding));
|
||||
}
|
||||
|
||||
xr::instance::~instance()
|
||||
{
|
||||
if (id != XR_NULL_HANDLE)
|
||||
xrDestroyInstance(id);
|
||||
}
|
||||
|
||||
XrTime xr::instance::now()
|
||||
{
|
||||
static PFN_xrConvertTimespecTimeToTimeKHR xrConvertTimespecTimeToTimeKHR =
|
||||
get_proc<PFN_xrConvertTimespecTimeToTimeKHR>("xrConvertTimespecTimeToTimeKHR");
|
||||
timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
XrTime res;
|
||||
CHECK_XR(xrConvertTimespecTimeToTimeKHR(id, &ts, &res));
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<XrExtensionProperties> xr::instance::extensions(const char * layer_name)
|
||||
{
|
||||
return xr::details::enumerate<XrExtensionProperties>(xrEnumerateInstanceExtensionProperties, layer_name);
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#ifdef XR_USE_PLATFORM_ANDROID
|
||||
#include <android_native_app_glue.h>
|
||||
#endif
|
||||
|
||||
#include "error.h"
|
||||
#include "utils/check.h"
|
||||
#include "utils/handle.h"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <openxr/openxr.h>
|
||||
#include <openxr/openxr_platform.h>
|
||||
|
||||
namespace xr
|
||||
{
|
||||
union event
|
||||
{
|
||||
XrEventDataBuffer header;
|
||||
XrEventDataInstanceLossPending loss_pending;
|
||||
XrEventDataInteractionProfileChanged interaction_profile_changed;
|
||||
XrEventDataReferenceSpaceChangePending space_changed_pending;
|
||||
XrEventDataSessionStateChanged state_changed;
|
||||
};
|
||||
class instance : public utils::handle<XrInstance>
|
||||
{
|
||||
std::string runtime_version;
|
||||
std::string runtime_name;
|
||||
std::unordered_set<std::string> loaded_extensions;
|
||||
|
||||
public:
|
||||
#if defined(XR_USE_PLATFORM_ANDROID)
|
||||
explicit instance(std::string_view application_name, void * applicationVM, void * applicationActivity, std::vector<const char *> extensions = {});
|
||||
#else
|
||||
explicit instance(std::string_view application_name, std::vector<const char *> extensions = {});
|
||||
#endif
|
||||
|
||||
instance() = default;
|
||||
instance(instance &&) = default;
|
||||
instance & operator=(instance &&) = default;
|
||||
~instance();
|
||||
|
||||
const std::string & get_runtime_version() const
|
||||
{
|
||||
return runtime_version;
|
||||
}
|
||||
const std::string & get_runtime_name() const
|
||||
{
|
||||
return runtime_name;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
F get_proc(const char * name)
|
||||
{
|
||||
F f;
|
||||
XrResult result = xrGetInstanceProcAddr(id, name, (PFN_xrVoidFunction *)&f);
|
||||
if (!XR_SUCCEEDED(result))
|
||||
{
|
||||
throw std::system_error(result, vk::error_category(), std::string("xrGetInstanceProcAddr(") + name + ")");
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
bool poll_event(event &);
|
||||
|
||||
XrPath string_to_path(const std::string & path);
|
||||
std::string path_to_string(XrPath path);
|
||||
|
||||
void suggest_bindings(const std::string & interaction_profile,
|
||||
std::vector<XrActionSuggestedBinding> & bindings);
|
||||
|
||||
XrTime now();
|
||||
|
||||
static std::vector<XrExtensionProperties> extensions(const char * layer_name = nullptr);
|
||||
|
||||
bool has_extension(const std::string & extension_name)
|
||||
{
|
||||
return loaded_extensions.find(extension_name) != loaded_extensions.end();
|
||||
}
|
||||
};
|
||||
} // namespace xr
|
||||
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* 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 "session.h"
|
||||
|
||||
#include "details/enumerate.h"
|
||||
#include "xr.h"
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <openxr/openxr_platform.h>
|
||||
|
||||
xr::session::session(xr::instance & inst, xr::system & sys, VkInstance vk_inst, VkPhysicalDevice pdev, VkDevice dev, int queue_family_index) :
|
||||
inst(&inst)
|
||||
{
|
||||
XrGraphicsBindingVulkan2KHR vulkan_binding{};
|
||||
vulkan_binding.type = XR_TYPE_GRAPHICS_BINDING_VULKAN2_KHR;
|
||||
|
||||
vulkan_binding.instance = vk_inst;
|
||||
vulkan_binding.physicalDevice = pdev;
|
||||
vulkan_binding.device = dev;
|
||||
vulkan_binding.queueFamilyIndex = queue_family_index;
|
||||
vulkan_binding.queueIndex = 0;
|
||||
|
||||
XrSessionCreateInfo session_info{};
|
||||
session_info.type = XR_TYPE_SESSION_CREATE_INFO;
|
||||
session_info.next = &vulkan_binding;
|
||||
session_info.systemId = sys;
|
||||
CHECK_XR(xrCreateSession(inst, &session_info, &id));
|
||||
}
|
||||
|
||||
std::vector<XrReferenceSpaceType> xr::session::get_reference_spaces() const
|
||||
{
|
||||
return details::enumerate<XrReferenceSpaceType>(xrEnumerateReferenceSpaces, id);
|
||||
}
|
||||
|
||||
xr::space xr::session::create_reference_space(XrReferenceSpaceType ref, const XrPosef & pose)
|
||||
{
|
||||
XrReferenceSpaceCreateInfo create_info{};
|
||||
create_info.type = XR_TYPE_REFERENCE_SPACE_CREATE_INFO;
|
||||
create_info.referenceSpaceType = ref;
|
||||
create_info.poseInReferenceSpace = pose;
|
||||
|
||||
XrSpace s;
|
||||
CHECK_XR(xrCreateReferenceSpace(id, &create_info, &s));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
xr::space xr::session::create_action_space(XrAction action, const XrPosef & pose)
|
||||
{
|
||||
XrActionSpaceCreateInfo create_info{};
|
||||
create_info.type = XR_TYPE_ACTION_SPACE_CREATE_INFO;
|
||||
create_info.action = action;
|
||||
create_info.poseInActionSpace = pose;
|
||||
create_info.subactionPath = XR_NULL_PATH;
|
||||
|
||||
XrSpace s;
|
||||
CHECK_XR(xrCreateActionSpace(id, &create_info, &s));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
std::vector<VkFormat> xr::session::get_swapchain_formats() const
|
||||
{
|
||||
std::vector<VkFormat> formats;
|
||||
for (auto i: details::enumerate<int64_t>(xrEnumerateSwapchainFormats, id))
|
||||
formats.push_back(static_cast<VkFormat>(i));
|
||||
return formats;
|
||||
}
|
||||
|
||||
XrFrameState xr::session::wait_frame()
|
||||
{
|
||||
XrFrameWaitInfo wait_info{};
|
||||
wait_info.type = XR_TYPE_FRAME_WAIT_INFO;
|
||||
|
||||
XrFrameState state{};
|
||||
state.type = XR_TYPE_FRAME_STATE;
|
||||
|
||||
CHECK_XR(xrWaitFrame(id, &wait_info, &state));
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void xr::session::begin_frame()
|
||||
{
|
||||
XrFrameBeginInfo begin_info{};
|
||||
begin_info.type = XR_TYPE_FRAME_BEGIN_INFO;
|
||||
|
||||
CHECK_XR(xrBeginFrame(id, &begin_info));
|
||||
}
|
||||
|
||||
void xr::session::end_frame(XrTime display_time, const std::vector<XrCompositionLayerBaseHeader *> & layers, XrEnvironmentBlendMode blend_mode)
|
||||
{
|
||||
XrFrameEndInfo end_info{};
|
||||
end_info.type = XR_TYPE_FRAME_END_INFO;
|
||||
end_info.displayTime = display_time;
|
||||
end_info.environmentBlendMode = blend_mode;
|
||||
end_info.layerCount = layers.size();
|
||||
end_info.layers = layers.data();
|
||||
|
||||
CHECK_XR(xrEndFrame(id, &end_info));
|
||||
}
|
||||
|
||||
void xr::session::begin_session(XrViewConfigurationType view_config)
|
||||
{
|
||||
XrSessionBeginInfo begin_info{};
|
||||
begin_info.type = XR_TYPE_SESSION_BEGIN_INFO;
|
||||
begin_info.primaryViewConfigurationType = view_config;
|
||||
|
||||
CHECK_XR(xrBeginSession(id, &begin_info));
|
||||
}
|
||||
|
||||
void xr::session::end_session()
|
||||
{
|
||||
CHECK_XR(xrEndSession(id));
|
||||
}
|
||||
|
||||
std::pair<XrViewStateFlags, std::vector<XrView>> xr::session::locate_views(XrViewConfigurationType view_config_type,
|
||||
XrTime display_time,
|
||||
XrSpace space)
|
||||
{
|
||||
XrViewLocateInfo view_locate_info{};
|
||||
view_locate_info.type = XR_TYPE_VIEW_LOCATE_INFO;
|
||||
view_locate_info.viewConfigurationType = view_config_type;
|
||||
view_locate_info.displayTime = display_time;
|
||||
view_locate_info.space = space;
|
||||
|
||||
XrViewState view_state{};
|
||||
view_state.type = XR_TYPE_VIEW_STATE;
|
||||
|
||||
auto views = details::enumerate<XrView>(xrLocateViews, id, &view_locate_info, &view_state);
|
||||
|
||||
return {view_state.viewStateFlags, views};
|
||||
}
|
||||
|
||||
std::string xr::session::get_current_interaction_profile(const std::string & path)
|
||||
{
|
||||
XrInteractionProfileState state{};
|
||||
state.type = XR_TYPE_INTERACTION_PROFILE_STATE;
|
||||
CHECK_XR(xrGetCurrentInteractionProfile(id, inst->string_to_path(path), &state));
|
||||
|
||||
return inst->path_to_string(state.interactionProfile);
|
||||
}
|
||||
|
||||
void xr::session::attach_actionsets(const std::vector<XrActionSet> & actionsets)
|
||||
{
|
||||
XrSessionActionSetsAttachInfo attach_info{};
|
||||
attach_info.type = XR_TYPE_SESSION_ACTION_SETS_ATTACH_INFO;
|
||||
attach_info.countActionSets = actionsets.size();
|
||||
attach_info.actionSets = actionsets.data();
|
||||
|
||||
CHECK_XR(xrAttachSessionActionSets(id, &attach_info));
|
||||
}
|
||||
|
||||
std::vector<std::string> xr::session::sources_for_action(XrAction action)
|
||||
{
|
||||
XrBoundSourcesForActionEnumerateInfo action_info{
|
||||
.type = XR_TYPE_BOUND_SOURCES_FOR_ACTION_ENUMERATE_INFO,
|
||||
.action = action,
|
||||
};
|
||||
|
||||
auto sources = xr::details::enumerate<XrPath>(xrEnumerateBoundSourcesForAction, id, &action_info);
|
||||
|
||||
std::vector<std::string> sources_name;
|
||||
sources_name.reserve(sources.size());
|
||||
for (XrPath path: sources)
|
||||
{
|
||||
sources_name.push_back(inst->path_to_string(path));
|
||||
}
|
||||
|
||||
return sources_name;
|
||||
}
|
||||
|
||||
std::vector<std::string> xr::session::localized_sources_for_action(XrAction action, XrInputSourceLocalizedNameFlags components)
|
||||
{
|
||||
XrBoundSourcesForActionEnumerateInfo action_info{
|
||||
.type = XR_TYPE_BOUND_SOURCES_FOR_ACTION_ENUMERATE_INFO,
|
||||
.action = action,
|
||||
};
|
||||
|
||||
auto sources = xr::details::enumerate<XrPath>(xrEnumerateBoundSourcesForAction, id, &action_info);
|
||||
|
||||
std::vector<std::string> sources_name;
|
||||
sources_name.reserve(sources.size());
|
||||
for (XrPath path: details::enumerate<XrPath>(xrEnumerateBoundSourcesForAction, id, &action_info))
|
||||
{
|
||||
XrInputSourceLocalizedNameGetInfo name_info{
|
||||
.type = XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO,
|
||||
.sourcePath = path,
|
||||
.whichComponents = components,
|
||||
};
|
||||
|
||||
sources_name.push_back(details::enumerate<char>(xrGetInputSourceLocalizedName, id, &name_info));
|
||||
}
|
||||
|
||||
return sources_name;
|
||||
}
|
||||
|
||||
float xr::session::get_current_refresh_rate()
|
||||
{
|
||||
auto xrGetDisplayRefreshRateFB = inst->get_proc<PFN_xrGetDisplayRefreshRateFB>("xrGetDisplayRefreshRateFB");
|
||||
|
||||
float refresh_rate = 0;
|
||||
if (xrGetDisplayRefreshRateFB)
|
||||
CHECK_XR(xrGetDisplayRefreshRateFB(id, &refresh_rate));
|
||||
|
||||
return refresh_rate;
|
||||
}
|
||||
|
||||
std::vector<float> xr::session::get_refresh_rates()
|
||||
{
|
||||
auto xrEnumerateDisplayRefreshRatesFB = inst->get_proc<PFN_xrEnumerateDisplayRefreshRatesFB>("xrEnumerateDisplayRefreshRatesFB");
|
||||
|
||||
if (xrEnumerateDisplayRefreshRatesFB)
|
||||
return xr::details::enumerate<float>(xrEnumerateDisplayRefreshRatesFB, id);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void xr::session::sync_actions(XrActionSet action_set, XrPath subaction_path)
|
||||
{
|
||||
XrActiveActionSet active_action_set{
|
||||
.actionSet = action_set,
|
||||
.subactionPath = subaction_path};
|
||||
|
||||
XrActionsSyncInfo sync_info{
|
||||
.type = XR_TYPE_ACTIONS_SYNC_INFO,
|
||||
.countActiveActionSets = 1,
|
||||
.activeActionSets = &active_action_set,
|
||||
};
|
||||
|
||||
CHECK_XR(xrSyncActions(id, &sync_info));
|
||||
}
|
||||
|
||||
void xr::session::sync_actions(XrActionSet action_set, const std::string & subaction_path)
|
||||
{
|
||||
sync_actions(action_set, inst->string_to_path(subaction_path));
|
||||
}
|
||||
|
||||
xr::session::~session()
|
||||
{
|
||||
if (id != XR_NULL_HANDLE)
|
||||
xrDestroySession(id);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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 "utils/handle.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
#include "space.h"
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class instance;
|
||||
class system;
|
||||
|
||||
class session : public utils::handle<XrSession>
|
||||
{
|
||||
instance * inst = nullptr;
|
||||
|
||||
public:
|
||||
session() = default;
|
||||
session(instance &, system &, VkInstance, VkPhysicalDevice, VkDevice, int queue_family_index);
|
||||
session(session &&) = default;
|
||||
session & operator=(session &&) = default;
|
||||
|
||||
~session();
|
||||
|
||||
std::vector<XrReferenceSpaceType> get_reference_spaces() const;
|
||||
space create_reference_space(XrReferenceSpaceType ref, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
|
||||
space create_action_space(XrAction action, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
|
||||
|
||||
std::vector<VkFormat> get_swapchain_formats() const;
|
||||
|
||||
XrFrameState wait_frame();
|
||||
void begin_frame();
|
||||
void end_frame(XrTime display_time, const std::vector<XrCompositionLayerBaseHeader *> & layers, XrEnvironmentBlendMode blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE);
|
||||
|
||||
void begin_session(XrViewConfigurationType view_config);
|
||||
void end_session();
|
||||
|
||||
std::pair<XrViewStateFlags, std::vector<XrView>> locate_views(XrViewConfigurationType view_config_type,
|
||||
XrTime display_time,
|
||||
XrSpace space);
|
||||
|
||||
std::string get_current_interaction_profile(const std::string & path);
|
||||
void attach_actionsets(const std::vector<XrActionSet> & actionsets);
|
||||
std::vector<std::string> sources_for_action(XrAction a);
|
||||
std::vector<std::string> localized_sources_for_action(XrAction action, XrInputSourceLocalizedNameFlags components = XR_INPUT_SOURCE_LOCALIZED_NAME_USER_PATH_BIT | XR_INPUT_SOURCE_LOCALIZED_NAME_INTERACTION_PROFILE_BIT | XR_INPUT_SOURCE_LOCALIZED_NAME_COMPONENT_BIT);
|
||||
|
||||
float get_current_refresh_rate();
|
||||
std::vector<float> get_refresh_rates();
|
||||
|
||||
void sync_actions(XrActionSet action_set, XrPath subaction_path = XR_NULL_PATH);
|
||||
void sync_actions(XrActionSet action_set, const std::string & subaction_path);
|
||||
};
|
||||
} // namespace xr
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 "utils/handle.h"
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class space : public utils::handle<XrSpace>
|
||||
{
|
||||
public:
|
||||
space() = default;
|
||||
space(XrSpace s)
|
||||
{
|
||||
id = s;
|
||||
}
|
||||
space(space &&) = default;
|
||||
space & operator=(space &&) = default;
|
||||
|
||||
~space()
|
||||
{
|
||||
if (id != XR_NULL_HANDLE)
|
||||
xrDestroySpace(id);
|
||||
}
|
||||
};
|
||||
} // namespace xr
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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 "swapchain.h"
|
||||
#include "details/enumerate.h"
|
||||
#include "error.h"
|
||||
#include "session.h"
|
||||
#include "vk/vk.h"
|
||||
#include "xr.h"
|
||||
|
||||
xr::swapchain::swapchain(xr::session & s, VkDevice device, VkFormat format, uint32_t width, uint32_t height, int sample_count) :
|
||||
device(device)
|
||||
{
|
||||
assert(sample_count == 1);
|
||||
|
||||
XrSwapchainCreateInfo create_info{};
|
||||
create_info.type = XR_TYPE_SWAPCHAIN_CREATE_INFO;
|
||||
create_info.createFlags = 0;
|
||||
create_info.usageFlags = XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT | XR_SWAPCHAIN_USAGE_TRANSFER_DST_BIT;
|
||||
create_info.format = format;
|
||||
create_info.sampleCount = sample_count;
|
||||
create_info.width = width;
|
||||
create_info.height = height;
|
||||
create_info.faceCount = 1;
|
||||
create_info.arraySize = 1;
|
||||
create_info.mipCount = 1;
|
||||
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
sample_count_ = sample_count;
|
||||
format_ = format;
|
||||
|
||||
CHECK_XR(xrCreateSwapchain(s, &create_info, &id));
|
||||
|
||||
std::vector<XrSwapchainImageVulkanKHR> array =
|
||||
details::enumerate<XrSwapchainImageVulkanKHR>(xrEnumerateSwapchainImages, id);
|
||||
|
||||
images_.resize(array.size());
|
||||
for (uint32_t i = 0; i < array.size(); i++)
|
||||
{
|
||||
images_[i].image = array[i].image;
|
||||
|
||||
VkImageViewCreateInfo iv_create_info{};
|
||||
iv_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
iv_create_info.image = array[i].image;
|
||||
iv_create_info.viewType = VkImageViewType::VK_IMAGE_VIEW_TYPE_2D;
|
||||
iv_create_info.format = format;
|
||||
iv_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
iv_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
iv_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
iv_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
iv_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
iv_create_info.subresourceRange.baseMipLevel = 0;
|
||||
iv_create_info.subresourceRange.levelCount = 1;
|
||||
iv_create_info.subresourceRange.baseArrayLayer = 0;
|
||||
iv_create_info.subresourceRange.layerCount = 1;
|
||||
CHECK_VK(vkCreateImageView(device, &iv_create_info, nullptr, &images_[i].view));
|
||||
}
|
||||
}
|
||||
|
||||
xr::swapchain::~swapchain()
|
||||
{
|
||||
for (auto & i: images_)
|
||||
{
|
||||
if (i.view)
|
||||
vkDestroyImageView(device, i.view, nullptr);
|
||||
}
|
||||
|
||||
if (id != XR_NULL_HANDLE)
|
||||
xrDestroySwapchain(id);
|
||||
}
|
||||
|
||||
int xr::swapchain::acquire()
|
||||
{
|
||||
uint32_t index;
|
||||
|
||||
XrSwapchainImageAcquireInfo acquire_info{};
|
||||
acquire_info.type = XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO;
|
||||
|
||||
CHECK_XR(xrAcquireSwapchainImage(id, &acquire_info, &index));
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
bool xr::swapchain::wait(XrDuration timeout)
|
||||
{
|
||||
XrSwapchainImageWaitInfo wait_info{};
|
||||
wait_info.type = XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO;
|
||||
wait_info.timeout = timeout;
|
||||
|
||||
XrResult result = xrWaitSwapchainImage(id, &wait_info);
|
||||
CHECK_XR(result, "xrWaitSwapchainImage");
|
||||
return result == XR_SUCCESS;
|
||||
}
|
||||
|
||||
void xr::swapchain::release()
|
||||
{
|
||||
XrSwapchainImageReleaseInfo release_info{};
|
||||
release_info.type = XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO;
|
||||
|
||||
CHECK_XR(xrReleaseSwapchainImage(id, &release_info));
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#ifdef XR_USE_PLATFORM_ANDROID
|
||||
#include <android_native_app_glue.h>
|
||||
#endif
|
||||
|
||||
#include "utils/handle.h"
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <openxr/openxr.h>
|
||||
#include <openxr/openxr_platform.h>
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class session;
|
||||
|
||||
class swapchain : public utils::handle<XrSwapchain>
|
||||
{
|
||||
public:
|
||||
struct image
|
||||
{
|
||||
VkImage image{};
|
||||
VkImageView view{};
|
||||
};
|
||||
|
||||
private:
|
||||
VkDevice device;
|
||||
uint32_t width_;
|
||||
uint32_t height_;
|
||||
int sample_count_;
|
||||
VkFormat format_;
|
||||
|
||||
std::vector<image> images_;
|
||||
|
||||
public:
|
||||
swapchain() = default;
|
||||
swapchain(session &, VkDevice device, VkFormat format, uint32_t width, uint32_t height, int sample_count = 1);
|
||||
swapchain(swapchain &&) = default;
|
||||
swapchain(const swapchain &) = delete;
|
||||
swapchain & operator=(swapchain &&) = default;
|
||||
swapchain & operator=(const swapchain &) = delete;
|
||||
~swapchain();
|
||||
|
||||
uint32_t width() const
|
||||
{
|
||||
return width_;
|
||||
}
|
||||
uint32_t height() const
|
||||
{
|
||||
return height_;
|
||||
}
|
||||
int sample_count() const
|
||||
{
|
||||
return sample_count_;
|
||||
}
|
||||
const std::vector<image> & images() const
|
||||
{
|
||||
return images_;
|
||||
};
|
||||
std::vector<image> & images()
|
||||
{
|
||||
return images_;
|
||||
}
|
||||
VkFormat format() const
|
||||
{
|
||||
return format_;
|
||||
}
|
||||
|
||||
int acquire();
|
||||
bool wait(XrDuration timeout = XR_INFINITE_DURATION);
|
||||
void release();
|
||||
};
|
||||
} // namespace xr
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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 "system.h"
|
||||
|
||||
#include "details/enumerate.h"
|
||||
#include "xr.h"
|
||||
#include <cassert>
|
||||
#include <openxr/openxr_platform.h>
|
||||
|
||||
xr::system::system(xr::instance & inst, XrFormFactor formfactor)
|
||||
{
|
||||
if (!inst)
|
||||
throw std::invalid_argument("instance");
|
||||
|
||||
this->inst = &inst;
|
||||
|
||||
XrSystemGetInfo system_info{};
|
||||
system_info.type = XR_TYPE_SYSTEM_GET_INFO;
|
||||
system_info.formFactor = formfactor;
|
||||
CHECK_XR(xrGetSystem(inst, &system_info, &id));
|
||||
|
||||
assert(id != XR_NULL_SYSTEM_ID);
|
||||
}
|
||||
|
||||
XrGraphicsRequirementsVulkan2KHR xr::system::graphics_requirements() const
|
||||
{
|
||||
auto xrGetVulkanGraphicsRequirements2KHR =
|
||||
inst->get_proc<PFN_xrGetVulkanGraphicsRequirements2KHR>("xrGetVulkanGraphicsRequirements2KHR");
|
||||
|
||||
XrGraphicsRequirementsVulkan2KHR requirements{};
|
||||
requirements.type = XR_TYPE_GRAPHICS_REQUIREMENTS_VULKAN2_KHR;
|
||||
|
||||
CHECK_XR(xrGetVulkanGraphicsRequirements2KHR(*inst, id, &requirements));
|
||||
return requirements;
|
||||
}
|
||||
|
||||
XrSystemProperties xr::system::properties() const
|
||||
{
|
||||
if (!id)
|
||||
throw std::invalid_argument("this");
|
||||
|
||||
XrSystemProperties prop;
|
||||
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
|
||||
|
||||
return prop;
|
||||
}
|
||||
|
||||
VkPhysicalDevice xr::system::physical_device(VkInstance vulkan) const
|
||||
{
|
||||
auto xrGetVulkanGraphicsDevice2KHR =
|
||||
inst->get_proc<PFN_xrGetVulkanGraphicsDevice2KHR>("xrGetVulkanGraphicsDevice2KHR");
|
||||
|
||||
XrVulkanGraphicsDeviceGetInfoKHR get_info{};
|
||||
get_info.type = XR_TYPE_VULKAN_GRAPHICS_DEVICE_GET_INFO_KHR;
|
||||
get_info.systemId = id;
|
||||
get_info.vulkanInstance = vulkan;
|
||||
|
||||
VkPhysicalDevice dev;
|
||||
CHECK_XR(xrGetVulkanGraphicsDevice2KHR(*inst, &get_info, &dev));
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
VkDevice xr::system::create_device(VkPhysicalDevice pdev, VkDeviceCreateInfo & create_info) const
|
||||
{
|
||||
XrVulkanDeviceCreateInfoKHR xr_create_info{};
|
||||
|
||||
xr_create_info.type = XR_TYPE_VULKAN_DEVICE_CREATE_INFO_KHR;
|
||||
xr_create_info.pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
|
||||
xr_create_info.systemId = id;
|
||||
xr_create_info.vulkanPhysicalDevice = pdev;
|
||||
xr_create_info.vulkanCreateInfo = &create_info;
|
||||
|
||||
VkDevice dev;
|
||||
VkResult vresult;
|
||||
|
||||
auto xrCreateVulkanDeviceKHR = inst->get_proc<PFN_xrCreateVulkanDeviceKHR>("xrCreateVulkanDeviceKHR");
|
||||
CHECK_XR(xrCreateVulkanDeviceKHR(*inst, &xr_create_info, &dev, &vresult));
|
||||
CHECK_VK(vresult, "xrCreateVulkanDeviceKHR");
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
std::vector<XrViewConfigurationType> xr::system::view_configurations() const
|
||||
{
|
||||
return details::enumerate<XrViewConfigurationType>(xrEnumerateViewConfigurations, *inst, id);
|
||||
}
|
||||
|
||||
XrViewConfigurationProperties xr::system::view_configuration_properties(XrViewConfigurationType type) const
|
||||
{
|
||||
XrViewConfigurationProperties prop{};
|
||||
prop.type = XR_TYPE_VIEW_CONFIGURATION_PROPERTIES;
|
||||
CHECK_XR(xrGetViewConfigurationProperties(*inst, id, type, &prop));
|
||||
|
||||
return prop;
|
||||
}
|
||||
|
||||
std::vector<XrViewConfigurationView> xr::system::view_configuration_views(XrViewConfigurationType type) const
|
||||
{
|
||||
return details::enumerate<XrViewConfigurationView>(xrEnumerateViewConfigurationViews, *inst, id, type);
|
||||
}
|
||||
|
||||
std::vector<XrEnvironmentBlendMode> xr::system::environment_blend_modes(XrViewConfigurationType type) const
|
||||
{
|
||||
return details::enumerate<XrEnvironmentBlendMode>(xrEnumerateEnvironmentBlendModes, *inst, id, type);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#ifdef XR_USE_PLATFORM_ANDROID
|
||||
#include <android_native_app_glue.h>
|
||||
#endif
|
||||
|
||||
#include "xr.h"
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <openxr/openxr.h>
|
||||
#include <openxr/openxr_platform.h>
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class instance;
|
||||
|
||||
class system
|
||||
{
|
||||
instance * inst = nullptr;
|
||||
XrSystemId id = XR_NULL_SYSTEM_ID;
|
||||
|
||||
public:
|
||||
system() = default;
|
||||
system(const system &) = default;
|
||||
system & operator=(const system &) = default;
|
||||
system(xr::instance &, XrFormFactor formfactor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY);
|
||||
|
||||
operator XrSystemId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
operator bool() const
|
||||
{
|
||||
return id != XR_NULL_SYSTEM_ID;
|
||||
}
|
||||
|
||||
XrSystemProperties properties() const;
|
||||
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
|
||||
VkPhysicalDevice physical_device(VkInstance vulkan) const;
|
||||
VkDevice create_device(VkPhysicalDevice pdev, VkDeviceCreateInfo & create_info) const;
|
||||
|
||||
std::vector<XrViewConfigurationType> view_configurations() const;
|
||||
XrViewConfigurationProperties view_configuration_properties(XrViewConfigurationType) const;
|
||||
std::vector<XrViewConfigurationView> view_configuration_views(XrViewConfigurationType) const;
|
||||
std::vector<XrEnvironmentBlendMode> environment_blend_modes(XrViewConfigurationType) const;
|
||||
};
|
||||
} // namespace xr
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 "xr.h"
|
||||
|
||||
#include "spdlog/fmt/fmt.h"
|
||||
|
||||
std::string xr::to_string(XrVersion version)
|
||||
{
|
||||
return fmt::format("{}.{}.{}", XR_VERSION_MAJOR(version), XR_VERSION_MINOR(version), XR_VERSION_PATCH(version));
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 "actionset.h"
|
||||
#include "error.h"
|
||||
#include "instance.h"
|
||||
#include "session.h"
|
||||
#include "swapchain.h"
|
||||
#include "system.h"
|
||||
#include "utils/check.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <openxr/openxr_reflection.h>
|
||||
|
||||
namespace xr
|
||||
{
|
||||
#define XR_ENUM_CASE_STR(name, val) \
|
||||
case name: \
|
||||
return #name;
|
||||
#define XR_ENUM_STR(enumType) \
|
||||
constexpr const char * to_string(enumType e) \
|
||||
{ \
|
||||
switch (e) \
|
||||
{ \
|
||||
XR_LIST_ENUM_##enumType(XR_ENUM_CASE_STR) default : return "Unknown"; \
|
||||
} \
|
||||
}
|
||||
|
||||
XR_ENUM_STR(XrResult);
|
||||
XR_ENUM_STR(XrFormFactor);
|
||||
XR_ENUM_STR(XrViewConfigurationType);
|
||||
XR_ENUM_STR(XrEnvironmentBlendMode);
|
||||
XR_ENUM_STR(XrReferenceSpaceType);
|
||||
XR_ENUM_STR(XrActionType);
|
||||
XR_ENUM_STR(XrEyeVisibility);
|
||||
XR_ENUM_STR(XrSessionState);
|
||||
XR_ENUM_STR(XrObjectType);
|
||||
XR_ENUM_STR(XrStructureType);
|
||||
|
||||
std::string to_string(XrVersion version);
|
||||
|
||||
} // namespace xr
|
||||
Reference in New Issue
Block a user