Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Vindicus999
2025-09-24 21:25:03 -04:00
88 changed files with 6692 additions and 3956 deletions
+88 -16
View File
@@ -24,6 +24,8 @@
#include <algorithm>
#include <cassert>
#include <cstring>
#include <map>
#include <set>
#include <spdlog/spdlog.h>
#include <vulkan/vulkan.h>
#include <openxr/openxr.h>
@@ -41,7 +43,54 @@ static XrBool32 debug_callback(
return XR_FALSE;
}
static std::pair<XrVersion, XrInstance> create_instance(XrInstanceCreateInfo & info)
namespace
{
struct version_info
{
std::set<const char *, std::less<>> promoted_extensions;
std::set<const char *, std::less<>> removed_extensions;
bool shall_request(std::string_view extension) const
{
return not(promoted_extensions.contains(extension) or removed_extensions.contains(extension));
}
static const std::map<XrVersion, version_info> versions;
static const version_info * get(XrVersion version)
{
auto it = versions.find(XR_MAKE_VERSION(XR_VERSION_MAJOR(version), XR_VERSION_MINOR(version), 0));
if (it == versions.end())
return nullptr;
return &it->second;
}
};
const std::map<XrVersion, version_info> version_info::versions = {{
XR_MAKE_VERSION(1, 1, 0),
{
.promoted_extensions = {
XR_KHR_LOCATE_SPACES_EXTENSION_NAME,
XR_KHR_MAINTENANCE1_EXTENSION_NAME,
XR_EXT_HP_MIXED_REALITY_CONTROLLER_EXTENSION_NAME,
XR_EXT_LOCAL_FLOOR_EXTENSION_NAME,
XR_EXT_PALM_POSE_EXTENSION_NAME,
XR_EXT_SAMSUNG_ODYSSEY_CONTROLLER_EXTENSION_NAME,
XR_EXT_UUID_EXTENSION_NAME,
XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME,
XR_HTC_VIVE_COSMOS_CONTROLLER_INTERACTION_EXTENSION_NAME,
XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME,
XR_ML_ML2_CONTROLLER_INTERACTION_EXTENSION_NAME,
XR_VARJO_QUAD_VIEWS_EXTENSION_NAME,
},
.removed_extensions = {
// Extensions that are included, but actually different
XR_FB_TOUCH_CONTROLLER_PRO_EXTENSION_NAME,
XR_META_TOUCH_CONTROLLER_PLUS_EXTENSION_NAME,
},
},
}};
} // namespace
static std::pair<XrVersion, XrInstance> create_instance(XrInstanceCreateInfo & info, std::vector<const char *> & in_extensions)
{
XrResult res;
for (XrVersion version: {
@@ -49,11 +98,34 @@ static std::pair<XrVersion, XrInstance> create_instance(XrInstanceCreateInfo & i
XR_API_VERSION_1_0,
})
{
std::vector<const char *> extensions;
info.applicationInfo.apiVersion = version;
auto v_info = version_info::get(version);
if (v_info)
{
std::ranges::copy_if(
in_extensions,
std::back_inserter(extensions),
[v_info](const char * ext) { return v_info->shall_request(ext); });
info.enabledExtensionNames = extensions.data();
info.enabledExtensionCount = extensions.size();
}
else
{
info.enabledExtensionNames = in_extensions.data();
info.enabledExtensionCount = in_extensions.size();
}
XrInstance inst;
res = xrCreateInstance(&info, &inst);
if (XR_SUCCEEDED(res))
{
if (v_info)
{
extensions.insert(extensions.end(), v_info->promoted_extensions.begin(), v_info->promoted_extensions.end());
std::swap(in_extensions, extensions);
}
return {version, inst};
}
spdlog::info("Failed to create OpenXR instance version {}: {}",
xr::to_string(version),
xr::to_string(res));
@@ -128,20 +200,6 @@ xr::instance::instance(std::string_view application_name, std::vector<const char
#endif
}
spdlog::info("Using OpenXR extensions:");
for (auto & i: extensions)
{
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);
}
XrInstanceCreateInfo create_info{
.type = XR_TYPE_INSTANCE_CREATE_INFO,
.enabledApiLayerCount = (uint32_t)layers.size(),
@@ -160,7 +218,21 @@ xr::instance::instance(std::string_view application_name, std::vector<const char
create_info.next = &instanceCreateInfoAndroid;
#endif
std::tie(api_version, id) = create_instance(create_info);
std::tie(api_version, id) = create_instance(create_info, extensions);
spdlog::info("Using OpenXR extensions:");
for (auto i: extensions)
{
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);
}
if (debug_utils_found)
{