Merge branch 'sync' into sneed
This commit is contained in:
+27
-7
@@ -829,9 +829,6 @@ void application::initialize_vulkan()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
std::ranges::sort(extensions);
|
||||
for (const auto & [extension_name, spec_version]: extensions)
|
||||
spdlog::info(" {} (version {})", extension_name, spec_version);
|
||||
|
||||
vk_device_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
|
||||
vk_device_extensions.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
|
||||
@@ -853,6 +850,19 @@ void application::initialize_vulkan()
|
||||
instance_extensions.push_back(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME);
|
||||
#endif
|
||||
|
||||
std::ranges::sort(extensions);
|
||||
for (const auto & [extension_name, spec_version]: extensions)
|
||||
{
|
||||
if (runtime_hmd_traits.blacklisted_extensions.contains(extension_name))
|
||||
{
|
||||
spdlog::info(" {} (version {}) (blacklisted)", extension_name, spec_version);
|
||||
if (std::ranges::find(instance_extensions, extension_name) != instance_extensions.end())
|
||||
throw std::runtime_error("Required Vulkan instance extension is blacklisted");
|
||||
}
|
||||
else
|
||||
spdlog::info(" {} (version {})", extension_name, spec_version);
|
||||
}
|
||||
|
||||
vk::ApplicationInfo application_info{
|
||||
.pApplicationName = app_info.name.c_str(),
|
||||
.applicationVersion = (uint32_t)app_info.version,
|
||||
@@ -912,9 +922,19 @@ void application::initialize_vulkan()
|
||||
spdlog::info("Available Vulkan device extensions:");
|
||||
for (const auto & [extension_name, spec_version]: extensions)
|
||||
{
|
||||
spdlog::info(" {} (version {})", extension_name, spec_version);
|
||||
if (auto it = optional_device_extensions.find(extension_name); it != optional_device_extensions.end())
|
||||
vk_device_extensions.push_back(it->data());
|
||||
if (runtime_hmd_traits.blacklisted_extensions.contains(extension_name))
|
||||
{
|
||||
spdlog::info(" {} (version {}) (blacklisted)", extension_name, spec_version);
|
||||
|
||||
if (std::ranges::find(vk_device_extensions, extension_name) != instance_extensions.end())
|
||||
throw std::runtime_error("Required Vulkan device extension is blacklisted");
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info(" {} (version {})", extension_name, spec_version);
|
||||
if (auto it = optional_device_extensions.find(extension_name); it != optional_device_extensions.end())
|
||||
vk_device_extensions.push_back(it->data());
|
||||
}
|
||||
}
|
||||
|
||||
spdlog::info("Initializing Vulkan with device {}", physical_device_properties.deviceName.data());
|
||||
@@ -1312,7 +1332,7 @@ void application::initialize()
|
||||
auto it = std::find_if(opt_extensions.begin(),
|
||||
opt_extensions.end(),
|
||||
[&ext](const char * i) { return strcmp(i, ext.extensionName) == 0; });
|
||||
if (it != opt_extensions.end())
|
||||
if (it != opt_extensions.end() and not runtime_hmd_traits.blacklisted_extensions.contains(ext.extensionName))
|
||||
xr_extensions.push_back(*it);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,11 +80,7 @@ int32_t wivrn::android::audio::speaker_data_cb(AAudioStream * stream, void * use
|
||||
{
|
||||
// Buffer underrun: add 5ms buffer
|
||||
size_t target_buffer_size = frame_size * AAudioStream_getSampleRate(stream) * 0.005;
|
||||
#if __cpp_lib_shared_ptr_arrays >= 201707L
|
||||
self->speaker_tmp.data.c = std::make_shared<uint8_t[]>(target_buffer_size, 0);
|
||||
#else
|
||||
self->speaker_tmp.data.c.reset(new uint8_t[target_buffer_size]());
|
||||
#endif
|
||||
self->speaker_tmp.payload = std::span(self->speaker_tmp.data.c.get(), target_buffer_size);
|
||||
self->buffer_size_bytes += target_buffer_size;
|
||||
spdlog::debug("Audio sync: underrun, add {} bytes buffer",
|
||||
@@ -159,9 +155,9 @@ void wivrn::android::audio::build_microphone(AAudioStreamBuilder * builder, int3
|
||||
AAudioStreamBuilder_setSharingMode(builder, AAUDIO_SHARING_MODE_EXCLUSIVE);
|
||||
AAudioStreamBuilder_setFormat(builder, AAUDIO_FORMAT_PCM_I16);
|
||||
if (application::get_config().mic_unprocessed_audio)
|
||||
{
|
||||
AAudioStreamBuilder_setInputPreset(builder, AAUDIO_INPUT_PRESET_UNPROCESSED);
|
||||
}
|
||||
else
|
||||
AAudioStreamBuilder_setInputPreset(builder, AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION);
|
||||
|
||||
AAudioStreamBuilder_setDataCallback(builder, µphone_data_cb, this);
|
||||
AAudioStreamBuilder_setErrorCallback(builder, µphone_error_cb, this);
|
||||
|
||||
+137
-71
@@ -19,8 +19,11 @@
|
||||
|
||||
#include "hmd_traits.h"
|
||||
|
||||
#include "utils/overloaded.h"
|
||||
#include "utils/strings.h"
|
||||
#include "xr/to_string.h"
|
||||
|
||||
#include <boost/pfr.hpp>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
@@ -30,6 +33,8 @@
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
@@ -54,7 +59,11 @@ static std::optional<std::string> get_property(const char * property)
|
||||
}
|
||||
#endif
|
||||
|
||||
static std::optional<std::string> env_string(std::string_view name)
|
||||
template <typename T>
|
||||
std::optional<T> env(std::string_view name);
|
||||
|
||||
template <>
|
||||
std::optional<std::string> env(std::string_view name)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
auto android_sysprop_name = std::format("debug.wivrn.{}", name);
|
||||
@@ -71,9 +80,10 @@ static std::optional<std::string> env_string(std::string_view name)
|
||||
#endif
|
||||
}
|
||||
|
||||
static std::optional<uint32_t> env_u32(std::string_view name)
|
||||
template <>
|
||||
std::optional<uint32_t> env(std::string_view name)
|
||||
{
|
||||
const auto value = env_string(name);
|
||||
const auto value = env<std::string>(name);
|
||||
if (not value)
|
||||
return std::nullopt;
|
||||
try
|
||||
@@ -90,9 +100,10 @@ static std::optional<uint32_t> env_u32(std::string_view name)
|
||||
}
|
||||
}
|
||||
|
||||
static std::optional<bool> env_bool(std::string_view name)
|
||||
template <>
|
||||
std::optional<bool> env(std::string_view name)
|
||||
{
|
||||
const auto value = env_string(name);
|
||||
const auto value = env<std::string>(name);
|
||||
if (not value)
|
||||
return std::nullopt;
|
||||
if (strcmp(value->c_str(), "1") == 0 || strcasecmp(value->c_str(), "true") == 0 || strcasecmp(value->c_str(), "yes") == 0 || strcasecmp(value->c_str(), "on") == 0)
|
||||
@@ -102,7 +113,32 @@ static std::optional<bool> env_bool(std::string_view name)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
hmd_traits::hmd_traits() = default;
|
||||
template <>
|
||||
std::optional<std::unordered_map<std::string, std::string>> env(std::string_view name)
|
||||
{
|
||||
const auto values = env<std::string>(name);
|
||||
if (not values)
|
||||
return std::nullopt;
|
||||
|
||||
std::unordered_map<std::string, std::string> map;
|
||||
for (auto value: utils::split(*values, ","))
|
||||
{
|
||||
if (auto pos = value.find('='); pos != std::string::npos)
|
||||
map.insert(std::make_pair(value.substr(0, pos), value.substr(pos + 1)));
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::optional<std::unordered_set<std::string>> env(std::string_view name)
|
||||
{
|
||||
const auto values = env<std::string>(name);
|
||||
if (not values)
|
||||
return std::nullopt;
|
||||
|
||||
return std::unordered_set<std::string>{std::from_range, utils::split(*values, ",")};
|
||||
}
|
||||
|
||||
void hmd_traits::init()
|
||||
{
|
||||
@@ -203,8 +239,32 @@ void hmd_traits::init()
|
||||
{
|
||||
// Accepts OpenXR 1.1 but doesn't actually implement it
|
||||
max_openxr_api_version = XR_API_VERSION_1_0;
|
||||
|
||||
// Doesn't handle additive blend, so needs specific ray model
|
||||
controller_ray_model = "assets://ray-htc.glb";
|
||||
// Fixed in XR elite firmware version 2.0
|
||||
bool need_htc_ray = true;
|
||||
const auto version = get_property("ro.product.version");
|
||||
if (version)
|
||||
{
|
||||
auto digits = utils::split(*version, ".");
|
||||
if (not digits.empty())
|
||||
{
|
||||
try
|
||||
{
|
||||
auto major = std::stoi(digits[0]);
|
||||
if (major >= 2 and model == "VIVE XR Series")
|
||||
need_htc_ray = false;
|
||||
}
|
||||
catch (...)
|
||||
{}
|
||||
}
|
||||
}
|
||||
if (need_htc_ray)
|
||||
override_shader = {
|
||||
{"ray.frag", "ray_htc.frag"},
|
||||
{"ray_skinned.vert", "ray_skinned_htc.vert"},
|
||||
{"ray.vert", "ray_htc.vert"},
|
||||
};
|
||||
|
||||
controller_profile = "htc-vive-focus-3";
|
||||
|
||||
@@ -231,69 +291,75 @@ void hmd_traits::init()
|
||||
#endif
|
||||
|
||||
spdlog::info("HMD traits initialized");
|
||||
auto log_string = [](std::string_view name, std::string & field) {
|
||||
if (auto val = env_string(name))
|
||||
{
|
||||
spdlog::info("\t{} override: {} -> {}", name, field, *val);
|
||||
field = *val;
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info("\t{}: {}", name, field);
|
||||
}
|
||||
};
|
||||
auto log_u32 = [](std::string_view name, uint32_t & field) {
|
||||
if (auto val = env_u32(name))
|
||||
{
|
||||
spdlog::info("\t{} override: {} -> {}", name, field, *val);
|
||||
field = *val;
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info("\t{}: {}", name, field);
|
||||
}
|
||||
};
|
||||
auto log_bool = [](std::string_view name, bool & field) {
|
||||
if (auto val = env_bool(name))
|
||||
{
|
||||
spdlog::info("\t{} override: {} -> {}", name, field, *val);
|
||||
field = *val;
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info("\t{}: {}", name, field);
|
||||
}
|
||||
};
|
||||
|
||||
log_string("controller_profile", controller_profile);
|
||||
log_string("controller_ray_model", controller_ray_model);
|
||||
if (auto val = env_string("max_openxr_api_version"))
|
||||
{
|
||||
XrVersion v;
|
||||
if (val == "1.1")
|
||||
v = XR_API_VERSION_1_1;
|
||||
else if (val == "1.0")
|
||||
v = XR_API_VERSION_1_0;
|
||||
else
|
||||
{
|
||||
spdlog::warn("XrVersion {} not recognized", *val);
|
||||
v = max_openxr_api_version;
|
||||
}
|
||||
spdlog::info("\t{} override: {} -> {}", "max_openxr_api_version", xr::to_string(max_openxr_api_version), xr::to_string(v));
|
||||
max_openxr_api_version = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info("\t{}: {}", "max_openxr_api_version", xr::to_string(max_openxr_api_version));
|
||||
}
|
||||
log_u32("panel_width_override", panel_width_override);
|
||||
log_bool("needs_srgb_conversion", needs_srgb_conversion);
|
||||
log_bool("view_locate", view_locate);
|
||||
log_bool("vk_debug_ext_allowed", vk_debug_ext_allowed);
|
||||
log_bool("bind_simple_controller", bind_simple_controller);
|
||||
log_bool("hand_interaction_grip_surface", hand_interaction_grip_surface);
|
||||
log_bool("pico_face_tracker", pico_face_tracker);
|
||||
log_bool("discard_frame", discard_frame);
|
||||
boost::pfr::for_each_field_with_name(
|
||||
*this,
|
||||
utils::overloaded{
|
||||
[](std::string_view name, auto & field) {
|
||||
if (auto val = env<std::remove_cvref_t<decltype(field)>>(name))
|
||||
{
|
||||
spdlog::info("\t{} override: {} -> {}", name, field, *val);
|
||||
field = *val;
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info("\t{}: {}", name, field);
|
||||
}
|
||||
},
|
||||
[](std::string_view name, XrVersion & field) {
|
||||
if (auto val = env<std::string>(name))
|
||||
{
|
||||
XrVersion v;
|
||||
if (val == "1.1")
|
||||
v = XR_API_VERSION_1_1;
|
||||
else if (val == "1.0")
|
||||
v = XR_API_VERSION_1_0;
|
||||
else
|
||||
{
|
||||
spdlog::warn("XrVersion {} not recognized", *val);
|
||||
v = field;
|
||||
}
|
||||
spdlog::info("\t{} override: {} -> {}", name, xr::to_string(field), xr::to_string(v));
|
||||
field = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info("\t{}: {}", name, xr::to_string(field));
|
||||
}
|
||||
},
|
||||
[](std::string_view name, std::unordered_map<std::string, std::string> & field) {
|
||||
if (auto val = env<std::unordered_map<std::string, std::string>>(name))
|
||||
{
|
||||
for (const auto & [original, overridden]: *val)
|
||||
field.insert_or_assign(original, overridden);
|
||||
}
|
||||
std::erase_if(field, [](const std::pair<std::string, std::string> & kv) { return kv.second == ""; });
|
||||
|
||||
for (const auto & [original, overridden]: field)
|
||||
{
|
||||
spdlog::info("\t{}: {} -> {}", name, original, overridden);
|
||||
}
|
||||
},
|
||||
|
||||
[](std::string_view name, std::unordered_set<std::string> & field) {
|
||||
if (auto val = env<std::unordered_set<std::string>>(name))
|
||||
{
|
||||
for (const auto & i: *val)
|
||||
{
|
||||
if (i.starts_with("-"))
|
||||
field.erase(i.substr(1));
|
||||
else
|
||||
field.insert(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto & i: field)
|
||||
{
|
||||
spdlog::info("\t{}: {}", name, i);
|
||||
}
|
||||
},
|
||||
[](std::string_view, hmd_permissions) {},
|
||||
});
|
||||
}
|
||||
|
||||
static XrViewConfigurationView scale_view(XrViewConfigurationView view, uint32_t width)
|
||||
@@ -488,11 +554,11 @@ std::pair<glm::vec3, glm::quat> hmd_traits::controller_offset(xr::spaces space)
|
||||
{
|
||||
case xr::spaces::grip_left:
|
||||
case xr::spaces::grip_right:
|
||||
return {{0, 0, -0.03}, glm::angleAxis(glm::radians(-35.f), glm::vec3{1, 0, 0})};
|
||||
return {{0, 0, 0}, {1, 0, 0, 0}};
|
||||
|
||||
case xr::spaces::aim_left:
|
||||
case xr::spaces::aim_right:
|
||||
return {{0, 0, 0}, {1, 0, 0, 0}};
|
||||
return {{0, -0.045, 0.035}, {1, 0, 0, 0}};
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
+3
-3
@@ -25,6 +25,7 @@
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <magic_enum_containers.hpp>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
@@ -54,14 +55,13 @@ public:
|
||||
bool hand_interaction_grip_surface = true;
|
||||
bool pico_face_tracker = false;
|
||||
bool discard_frame = true; // can do xrBeginFrame twice to discard the first one
|
||||
std::unordered_map<std::string, std::string> override_shader;
|
||||
std::unordered_set<std::string> blacklisted_extensions;
|
||||
#ifndef NDEBUG
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
#endif
|
||||
|
||||
public:
|
||||
hmd_traits();
|
||||
|
||||
void init();
|
||||
|
||||
const char * permission_name(feature f) const
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "scene_loader.h"
|
||||
|
||||
#include "gpu_buffer.h"
|
||||
#include "hmd_traits.h"
|
||||
#include "image_loader.h"
|
||||
#include "render/scene_components.h"
|
||||
#include "render/vertex_layout.h"
|
||||
@@ -835,6 +836,9 @@ public:
|
||||
if (auto it = extras.find({fastgltf::Category::Materials, material_id, "fragment_shader"}); it != extras.end())
|
||||
material.fragment_shader = it->second;
|
||||
|
||||
if (auto it = application::get_hmd_traits().override_shader.find(material.fragment_shader); it != application::get_hmd_traits().override_shader.end())
|
||||
material.fragment_shader = it->second;
|
||||
|
||||
renderer::material::gpu_data & material_data = material.staging;
|
||||
|
||||
material_data.base_color_factor = convert(gltf_material.pbrData.baseColorFactor);
|
||||
@@ -917,6 +921,9 @@ public:
|
||||
else
|
||||
primitive_ref.vertex_shader = "lit_skinned.vert";
|
||||
|
||||
if (auto it = application::get_hmd_traits().override_shader.find(primitive_ref.vertex_shader); it != application::get_hmd_traits().override_shader.end())
|
||||
primitive_ref.vertex_shader = it->second;
|
||||
|
||||
// For attributes types, see https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview (§ 3.7.2.1)
|
||||
auto shader = shader_loader{device}(primitive_ref.vertex_shader);
|
||||
for (const auto & input: shader->inputs)
|
||||
|
||||
@@ -133,7 +133,9 @@ void main()
|
||||
discard;
|
||||
}
|
||||
|
||||
out_color = vec4(mesh.emissive_factor * texture(emissive_texture, texcoord).rgb, 0);
|
||||
// https://registry.khronos.org/OpenXR/specs/1.1/html/xrspec.html#fundamentals-colors
|
||||
// alpha can't be 0 or it will zero RGB values too
|
||||
out_color = vec4(mesh.emissive_factor * texture(emissive_texture, texcoord).rgb, 1.0 / 255.0);
|
||||
#endif // HTC_WORKAROUND
|
||||
|
||||
}
|
||||
|
||||
@@ -199,7 +199,10 @@ xr::instance::instance(std::string_view application_name, std::vector<const char
|
||||
std::ranges::sort(all_extensions, [](const char * a, const char * b) { return strcmp(a, b) < 0; }, &XrExtensionProperties::extensionName);
|
||||
for (XrExtensionProperties & i: all_extensions)
|
||||
{
|
||||
spdlog::info(" {} (version {})", i.extensionName, i.extensionVersion);
|
||||
if (application::get_hmd_traits().blacklisted_extensions.contains(i.extensionName))
|
||||
spdlog::info(" {} (version {}) (blacklisted)", i.extensionName, i.extensionVersion);
|
||||
else
|
||||
spdlog::info(" {} (version {})", i.extensionName, i.extensionVersion);
|
||||
#ifndef NDEBUG
|
||||
if (!strcmp(i.extensionName, "XR_EXT_debug_utils"))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user