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)
{
+72 -9
View File
@@ -17,13 +17,76 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef VERT_SHADER
#include "actionset.h"
#include "error.h"
#include "instance.h"
#include "session.h"
#include "swapchain.h"
#include "system.h"
#include "xr/check.h"
#include "xr/to_string.h"
#if VSR
#extension GL_EXT_fragment_shading_rate: enable
#endif
layout (location = 0) in vec2 vPosition;
layout (location = 1) in uvec2 vUV;
layout(location = 0) out vec4 outUV;
layout(push_constant) uniform pc
{
ivec4 rgb_rect;
ivec4 a_rect;
};
void main()
{
gl_Position = vec4(vPosition, 0.0, 1.0);
#if VSR
gl_PrimitiveShadingRateEXT = int(bitfieldExtract(vUV.x, 28, 4));
vec2 uv = bitfieldInsert(vUV, uvec2(0), 28, 4);
#else
vec2 uv = vUV;
#endif
outUV.xy = (uv + rgb_rect.xy) / rgb_rect.zw;
outUV.zw = (uv + a_rect.xy) / a_rect.zw;
}
#endif
#ifdef FRAG_SHADER
layout(constant_id = 0) const int alpha = 1;
layout(constant_id = 1) const bool do_srgb = false;
layout(set = 0, binding = 0) uniform sampler2D rgb[alpha + 1];
layout(location = 0) in vec4 inUV;
layout(location = 0) out vec4 outColor;
float sRGB_to_linear(float x)
{
if (x <= 0.04045)
return x / 12.92;
return pow((x + 0.055) / 1.055, 2.4);
}
vec4 sRGB_to_linear_rgba(vec4 x)
{
return vec4(
sRGB_to_linear(x.r),
sRGB_to_linear(x.g),
sRGB_to_linear(x.b),
x.a);
}
void main()
{
if (alpha == 1)
outColor = vec4(texture(rgb[0], inUV.xy).rgb, texture(rgb[1], inUV.zw).r);
else
outColor = texture(rgb[0], inUV.xy).rgba;
if (do_srgb)
{
outColor = sRGB_to_linear_rgba(outColor);
}
}
#endif