Add device-specific logic

Controller bindings have been moved to the new logic.
Recommended view sizes are now overriden as recommendation is based on
the integrated GPU while for streaming headsets can usually do much
better.
This commit is contained in:
Patrick Nicolas
2023-11-20 21:14:28 +01:00
parent 3f783ceb0c
commit 347052109d
5 changed files with 240 additions and 75 deletions
+28 -39
View File
@@ -18,15 +18,13 @@
*/
#include "application.h"
#include "hardware.h"
#include "magic_enum.hpp"
#include "scene.h"
#include "spdlog/common.h"
#include "spdlog/spdlog.h"
#include "utils/ranges.h"
#include "utils/strings.h"
#include "vk/details/enumerate.h"
#include "vk/pipeline.h"
#include "vk/shader.h"
#include "vk/vk.h"
#include "xr/xr.h"
#include <algorithm>
@@ -42,8 +40,8 @@
#endif
#ifdef XR_USE_PLATFORM_ANDROID
#include <sys/system_properties.h>
#include <android/native_activity.h>
#include <sys/system_properties.h>
#endif
using namespace std::chrono_literals;
@@ -398,8 +396,9 @@ void application::initialize()
auto views = xr_system_id.view_configuration_views(app_info.viewconfig);
xr_swapchains.reserve(views.size());
for (auto & view: views)
for (auto view: views)
{
view = override_view(view, guess_model());
xr_swapchains.emplace_back(xr_session, vk_device, swapchain_format, view.recommendedImageRectWidth, view.recommendedImageRectHeight);
spdlog::info("Created swapchain {}: {}x{}", xr_swapchains.size(), xr_swapchains.back().width(), xr_swapchains.back().height());
@@ -410,34 +409,22 @@ void application::initialize()
// TODO get it from application info
xr_actionset = xr::actionset(xr_instance, "actions", "Actions");
// TODO better way to handle bindings for different vendors/flavors of vendor
#ifdef XR_USE_PLATFORM_ANDROID
char property_chararr[PROP_VALUE_MAX + 1];
__system_property_get("ro.product.manufacturer", property_chararr);
#else
char property_chararr[93];
#endif
std::string manufacturer_string(property_chararr);
if (manufacturer_string == "Oculus" || manufacturer_string == "Meta")
switch (guess_model())
{
spdlog::info("Suggesting Oculus Quest 2 bindings");
std::vector<XrActionSuggestedBinding> touch_controller_bindings;
for (const auto & [name, type]: oculus_touch)
{
process_binding_action(touch_controller_bindings, name, type);
case model::oculus_quest:
case model::oculus_quest_2:
case model::meta_quest_3: {
spdlog::info("Suggesting oculus/touch_controller bindings");
std::vector<XrActionSuggestedBinding> touch_controller_bindings;
for (const auto & [name, type]: oculus_touch)
{
process_binding_action(touch_controller_bindings, name, type);
}
xr_instance.suggest_bindings("/interaction_profiles/oculus/touch_controller", touch_controller_bindings);
}
xr_instance.suggest_bindings("/interaction_profiles/oculus/touch_controller", touch_controller_bindings);
}
else if (manufacturer_string == "Pico")
{
#ifdef XR_USE_PLATFORM_ANDROID
__system_property_get("ro.product.model", property_chararr);
#endif
std::string model_string(property_chararr);
break;
if (model_string == "Pico Neo 3")
{
case model::pico_neo_3: {
spdlog::info("Suggesting Pico Neo 3 bindings");
std::vector<XrActionSuggestedBinding> pico_neo_3_bindings;
for (const auto & [name, type]: pico_neo_3)
@@ -446,8 +433,9 @@ void application::initialize()
}
xr_instance.suggest_bindings("/interaction_profiles/bytedance/pico_neo3_controller", pico_neo_3_bindings);
}
else
{
break;
case model::pico_4: {
spdlog::info("Suggesting Pico 4 bindings");
std::vector<XrActionSuggestedBinding> pico_4_bindings;
for (const auto & [name, type]: pico_4)
@@ -456,9 +444,8 @@ void application::initialize()
}
xr_instance.suggest_bindings("/interaction_profiles/bytedance/pico4_controller", pico_4_bindings);
}
}
else
{
case model::unknown: {
spdlog::info("Suggesting Khronos simple controller bindings");
std::vector<XrActionSuggestedBinding> simple_controller_bindings;
for (const auto & [name, type]: simple_controller)
@@ -466,6 +453,8 @@ void application::initialize()
process_binding_action(simple_controller_bindings, name, type);
}
xr_instance.suggest_bindings("/interaction_profiles/khr/simple_controller", simple_controller_bindings);
}
break;
}
xr_session.attach_actionsets({xr_actionset});
@@ -581,7 +570,7 @@ application::application(application_info info) :
jobject intent = Env->CallObjectMethod(activity->clazz, jtmID);
jtmID = Env->GetMethodID(Env->GetObjectClass(intent), "getDataString", "()Ljava/lang/String;");
jstring dataString_jni = (jstring)Env->CallObjectMethod(intent, jtmID);
jstring dataString_jni = (jstring)Env->CallObjectMethod(intent, jtmID);
std::string dataString;
if (dataString_jni)
{
@@ -787,7 +776,7 @@ void application::poll_actions()
instance_->xr_session.sync_actions(instance_->xr_actionset);
}
bool application::read_action(XrAction action, bool & value, XrTime& last_change_time)
bool application::read_action(XrAction action, bool & value, XrTime & last_change_time)
{
if (!is_focused())
return false;
@@ -808,7 +797,7 @@ bool application::read_action(XrAction action, bool & value, XrTime& last_change
return true;
}
bool application::read_action(XrAction action, float & value, XrTime& last_change_time)
bool application::read_action(XrAction action, float & value, XrTime & last_change_time)
{
if (!is_focused())
return false;
@@ -829,7 +818,7 @@ bool application::read_action(XrAction action, float & value, XrTime& last_chang
return true;
}
bool application::read_action(XrAction action, XrVector2f & value, XrTime& last_change_time)
bool application::read_action(XrAction action, XrVector2f & value, XrTime & last_change_time)
{
if (!is_focused())
return false;
+103
View File
@@ -0,0 +1,103 @@
/*
* WiVRn VR streaming
* Copyright (C) 2023 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2023 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 "hardware.h"
#include <stdexcept>
#include <string>
#include <spdlog/spdlog.h>
#ifdef XR_USE_PLATFORM_ANDROID
#include "utils/wrap_lambda.h"
#include <sys/system_properties.h>
static std::string get_property(const char * property)
{
auto info = __system_property_find(property);
std::string result;
wrap_lambda cb = [&result](const char * name, const char * value, uint32_t serial) {
result = value;
};
__system_property_read_callback(info, cb.userdata_first(), cb);
return result;
}
#endif
model guess_model()
{
#ifdef XR_USE_PLATFORM_ANDROID
const auto device = get_property("ro.product.device");
if (device == "monterey")
return model::oculus_quest;
if (device == "hollywood")
return model::oculus_quest_2;
const auto manufacturer = get_property("ro.product.manufacturer");
const auto model = get_property("ro.product.model");
if (manufacturer == "Pico")
{
if (model == "Pico Neo 3")
return model::pico_neo_3;
spdlog::info("manufacturer={}, model={}, device={} assuming Pico 4", manufacturer, model, device);
return model::pico_4;
}
spdlog::info("Unknown model, manufacturer={}, model={}, device={}", manufacturer, model, device);
#endif
return model::unknown;
}
XrViewConfigurationView override_view(XrViewConfigurationView view, model m)
{
// Standalone headsets tend to report a lower resolution
// as the GPU can't handle full res.
// Return the panel resolution instead.
switch (m)
{
case model::oculus_quest:
spdlog::info("Using panel resolution 1440x1600 for Quest");
view.recommendedImageRectWidth = 1440;
view.recommendedImageRectHeight = 1600;
return view;
case model::oculus_quest_2:
spdlog::info("Using panel resolution 1832x1920 for Quest 2");
view.recommendedImageRectWidth = 1832;
view.recommendedImageRectHeight = 1920;
return view;
case model::meta_quest_3:
spdlog::info("Using panel resolution 2064x2208 for Quest 3");
view.recommendedImageRectWidth = 2064;
view.recommendedImageRectHeight = 2208;
return view;
case model::pico_neo_3:
return view;
case model::pico_4:
spdlog::info("Using panel resolution 2160x2160 for Pico 4");
view.recommendedImageRectWidth = 2160;
view.recommendedImageRectHeight = 2160;
return view;
case model::unknown:
return view;
}
throw std::range_error("invalid model " + std::to_string((int)m));
}
+35
View File
@@ -0,0 +1,35 @@
/*
* WiVRn VR streaming
* Copyright (C) 2023 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2023 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 <openxr/openxr.h>
enum class model
{
oculus_quest,
oculus_quest_2,
meta_quest_3,
pico_neo_3,
pico_4,
unknown
};
model guess_model();
XrViewConfigurationView override_view(XrViewConfigurationView, model);
+73
View File
@@ -0,0 +1,73 @@
/*
* WiVRn VR streaming
* Copyright (C) 2023 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2023 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 <functional>
namespace details
{
template <typename... Args>
struct add_void;
template <typename T, typename... Args>
struct add_void<std::function<T(Args...)>>
{
template <typename L>
static T fn_0(void * userdata, Args... a)
{
L * f = (L *)userdata;
return (*f)(a...);
}
template <typename L>
static T fn(Args... a, void * userdata)
{
L * f = (L *)userdata;
return (*f)(a...);
}
};
} // namespace details
template <typename T>
class wrap_lambda
{
T impl;
public:
wrap_lambda(T && l) :
impl(l) {}
auto userdata_first()
{
using F = decltype(std::function(impl));
return details::add_void<F>::template fn_0<T>;
}
operator auto()
{
using F = decltype(std::function(impl));
return details::add_void<F>::template fn<T>;
}
operator void *()
{
return this;
}
};
+1 -36
View File
@@ -4,6 +4,7 @@
#include "os/os_time.h"
#include "util/u_logging.h"
#include "utils/sync_queue.h"
#include "utils/wrap_lambda.h"
#include "wivrn_session.h"
#include <pulse/context.h>
@@ -15,7 +16,6 @@
#include <atomic>
#include <fcntl.h>
#include <filesystem>
#include <functional>
#include <future>
#include <iostream>
#include <sys/poll.h>
@@ -49,41 +49,6 @@ void wait_connected(std::atomic<pa_context_state> & state)
}
}
template <typename... Args>
struct add_void;
template <typename T, typename... Args>
struct add_void<std::function<T(Args...)>>
{
template <typename L>
static T fn(Args... a, void * userdata)
{
L * f = (L *)userdata;
return (*f)(a...);
}
};
template <typename T>
class wrap_lambda
{
T impl;
public:
wrap_lambda(T && l) :
impl(l) {}
operator auto()
{
using F = decltype(std::function(impl));
return add_void<F>::template fn<T>;
}
operator void *()
{
return this;
}
};
void unload_module(uintptr_t id);
void unload_module(pa_context * ctx, uint32_t id)