Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -89,7 +89,7 @@ file(GLOB LOCAL_SOURCE CONFIGURE_DEPENDS
|
||||
|
||||
file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "*.glsl")
|
||||
target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS})
|
||||
wivrn_compile_glsl(wivrn ${VULKAN_SHADERS})
|
||||
wivrn_compile_glsl(wivrn SHADERS ${VULKAN_SHADERS})
|
||||
|
||||
target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb Boost::url Boost::locale)
|
||||
|
||||
@@ -177,6 +177,9 @@ if(USE_ANDROID_VALIDATION_LAYER)
|
||||
file(COPY
|
||||
${CMAKE_BINARY_DIR}/Vulkan-ValidationLayer/android-binaries-${VVL_VERSION}/${CMAKE_ANDROID_ARCH_ABI}
|
||||
DESTINATION ${CMAKE_ANDROID_LIB_DIRECTORIES})
|
||||
else()
|
||||
# silence "Manually-specified variables were not used by the project" warning
|
||||
set(_unused ${CMAKE_ANDROID_LIB_DIRECTORIES})
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
+32
-36
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "application.h"
|
||||
#include "asset.h"
|
||||
|
||||
#include "hardware.h"
|
||||
#include "openxr/openxr.h"
|
||||
#include "scene.h"
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utils/contains.h"
|
||||
#include "utils/files.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "vk/check.h"
|
||||
#include "wifi_lock.h"
|
||||
#include "xr/actionset.h"
|
||||
@@ -67,7 +68,6 @@ struct interaction_profile
|
||||
std::string profile_name;
|
||||
std::vector<std::string> required_extensions;
|
||||
XrVersion min_version = XR_MAKE_VERSION(1, 0, 0);
|
||||
XrVersion max_version = XR_MAKE_VERSION(2, 0, 0); // exclusive
|
||||
std::vector<std::string> input_sources;
|
||||
bool available;
|
||||
};
|
||||
@@ -134,8 +134,7 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
},
|
||||
interaction_profile{
|
||||
.profile_name = "/interaction_profiles/facebook/touch_controller_pro",
|
||||
.required_extensions = {"XR_FB_touch_controller_pro"},
|
||||
.max_version = XR_MAKE_VERSION(1, 1, 0),
|
||||
.required_extensions = {XR_FB_TOUCH_CONTROLLER_PRO_EXTENSION_NAME},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/left/output/haptic_trigger_fb",
|
||||
@@ -247,8 +246,7 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
},
|
||||
interaction_profile{
|
||||
.profile_name = "/interaction_profiles/meta/touch_controller_plus",
|
||||
.required_extensions = {"XR_META_touch_controller_plus"},
|
||||
.max_version = XR_MAKE_VERSION(1, 1, 0),
|
||||
.required_extensions = {XR_META_TOUCH_CONTROLLER_PLUS_EXTENSION_NAME},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
@@ -971,7 +969,8 @@ void application::initialize_actions()
|
||||
std::vector<std::string> sources;
|
||||
for (auto & profile: interaction_profiles)
|
||||
{
|
||||
profile.available = utils::contains_all(xr_extensions, profile.required_extensions) and profile.min_version <= api_version and profile.max_version > api_version;
|
||||
profile.available = std::ranges::all_of(profile.required_extensions, [&](auto & ext) { return xr_instance.has_extension(ext); }) and
|
||||
profile.min_version <= api_version;
|
||||
|
||||
if (profile.profile_name.ends_with("khr/simple_controller"))
|
||||
{
|
||||
@@ -1352,50 +1351,47 @@ void application::initialize()
|
||||
vk_cmdpool = vk::raii::CommandPool{vk_device, cmdpool_create_info};
|
||||
|
||||
initialize_actions();
|
||||
load_locale();
|
||||
}
|
||||
|
||||
void application::load_locale()
|
||||
{
|
||||
gen.add_messages_domain("wivrn");
|
||||
std::locale loc = gen("");
|
||||
|
||||
messages_info.encoding = "UTF-8";
|
||||
if (config->locale.empty())
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
jni::klass java_util_Locale("java/util/Locale");
|
||||
auto default_locale = java_util_Locale.call<jni::object<"java/util/Locale">>("getDefault");
|
||||
jni::klass java_util_Locale("java/util/Locale");
|
||||
auto default_locale = java_util_Locale.call<jni::object<"java/util/Locale">>("getDefault");
|
||||
|
||||
// if (auto language = default_locale.call<jni::string>("toString"))
|
||||
if (auto language = default_locale.call<jni::string>("getLanguage"))
|
||||
messages_info.language = language;
|
||||
|
||||
if (auto country = default_locale.call<jni::string>("getCountry"))
|
||||
messages_info.country = country;
|
||||
|
||||
messages_info.encoding = "UTF-8";
|
||||
// if (auto language = default_locale.call<jni::string>("toString"))
|
||||
if (auto language = default_locale.call<jni::string>("getLanguage"))
|
||||
messages_info.language = language;
|
||||
|
||||
if (auto country = default_locale.call<jni::string>("getCountry"))
|
||||
messages_info.country = country;
|
||||
#else
|
||||
auto & facet = std::use_facet<boost::locale::info>(loc);
|
||||
messages_info.language = facet.language();
|
||||
messages_info.country = facet.country();
|
||||
messages_info.encoding = "UTF-8";
|
||||
auto & facet = std::use_facet<boost::locale::info>(loc);
|
||||
messages_info.language = facet.language();
|
||||
messages_info.country = facet.country();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
auto pos = config->locale.find("_");
|
||||
messages_info.language = config->locale.substr(0, pos);
|
||||
if (pos != std::string::npos)
|
||||
messages_info.country = config->locale.substr(pos + 1);
|
||||
}
|
||||
|
||||
spdlog::info("Current locale: language {}, country {}, encoding {}", messages_info.language, messages_info.country, messages_info.encoding);
|
||||
|
||||
messages_info.paths.push_back("locale");
|
||||
|
||||
messages_info.domains.push_back(boost::locale::gnu_gettext::messages_info::domain("wivrn"));
|
||||
messages_info.callback = [](const std::string & file_name, const std::string & encoding) {
|
||||
std::vector<char> buffer;
|
||||
try
|
||||
{
|
||||
asset file(file_name);
|
||||
buffer.resize(file.size());
|
||||
memcpy(buffer.data(), file.data(), file.size());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
return buffer;
|
||||
};
|
||||
|
||||
messages_info.callback = open_locale_file;
|
||||
loc = std::locale(loc, boost::locale::gnu_gettext::create_messages_facet<char>(messages_info));
|
||||
|
||||
std::locale::global(loc);
|
||||
|
||||
@@ -486,4 +486,6 @@ public:
|
||||
{
|
||||
return instance().messages_info;
|
||||
}
|
||||
|
||||
void load_locale();
|
||||
};
|
||||
|
||||
@@ -214,8 +214,8 @@ configuration::configuration(xr::system & system)
|
||||
if (auto val = root["resolution_scale"]; val.is_double())
|
||||
resolution_scale = val.get_double();
|
||||
|
||||
if (auto val = root["sgsr"]; val.is_object())
|
||||
parse_sgsr_options(val.get_object());
|
||||
if (auto val = root["enable_stream_gui"]; val.is_bool())
|
||||
enable_stream_gui = val.get_bool();
|
||||
|
||||
if (auto val = root["openxr_post_processing"]; val.is_object())
|
||||
parse_openxr_post_processing_options(val.get_object());
|
||||
@@ -254,6 +254,9 @@ configuration::configuration(xr::system & system)
|
||||
|
||||
if (auto val = root["first_run"]; val.is_bool())
|
||||
first_run = val.get_bool();
|
||||
|
||||
if (auto val = root["locale"]; val.is_string())
|
||||
locale = val.get_string().value();
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
@@ -264,31 +267,11 @@ configuration::configuration(xr::system & system)
|
||||
preferred_refresh_rate.reset();
|
||||
minimum_refresh_rate.reset();
|
||||
resolution_scale = 1.4;
|
||||
sgsr = {};
|
||||
openxr_post_processing = {};
|
||||
passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color;
|
||||
}
|
||||
}
|
||||
|
||||
void configuration::parse_sgsr_options(simdjson::simdjson_result<simdjson::dom::object> sgsr_root)
|
||||
{
|
||||
sgsr = {};
|
||||
if (auto val = sgsr_root["enabled"]; val.is_bool())
|
||||
sgsr.enabled = val.get_bool();
|
||||
|
||||
if (auto val = sgsr_root["upscaling_factor"]; val.is_double())
|
||||
sgsr.upscaling_factor = val.get_double();
|
||||
|
||||
if (auto val = sgsr_root["use_edge_direction"]; val.is_bool())
|
||||
sgsr.use_edge_direction = val.get_bool();
|
||||
|
||||
if (auto val = sgsr_root["edge_threshold"]; val.is_double())
|
||||
sgsr.edge_threshold = val.get_double();
|
||||
|
||||
if (auto val = sgsr_root["edge_sharpness"]; val.is_double())
|
||||
sgsr.edge_sharpness = val.get_double();
|
||||
}
|
||||
|
||||
void configuration::parse_openxr_post_processing_options(simdjson::simdjson_result<simdjson::dom::object> openxr_post_processing_root)
|
||||
{
|
||||
openxr_post_processing = {};
|
||||
@@ -304,17 +287,6 @@ static std::ostream & operator<<(std::ostream & stream, feature f)
|
||||
return stream << "\"" << magic_enum::enum_name(f) << "\"";
|
||||
}
|
||||
|
||||
static std::ostream & write_sgsr(std::ofstream & stream, const configuration::sgsr_settings & sgsr)
|
||||
{
|
||||
stream << "{\"enabled\":" << std::boolalpha << sgsr.enabled;
|
||||
stream << ",\"upscaling_factor\":" << sgsr.upscaling_factor;
|
||||
stream << ",\"use_edge_direction\":" << std::boolalpha << sgsr.use_edge_direction;
|
||||
stream << ",\"edge_threshold\":" << sgsr.edge_threshold;
|
||||
stream << ",\"edge_sharpness\":" << sgsr.edge_sharpness;
|
||||
stream << "}";
|
||||
return stream;
|
||||
}
|
||||
|
||||
static std::ostream & write_openxr_post_processing(std::ofstream & stream, const configuration::openxr_post_processing_settings & openxr_post_processing)
|
||||
{
|
||||
stream << "{\"super_sampling\":" << openxr_post_processing.super_sampling;
|
||||
@@ -357,8 +329,6 @@ void configuration::save()
|
||||
if (minimum_refresh_rate)
|
||||
json << ",\"minimum_refresh_rate\":" << *minimum_refresh_rate;
|
||||
json << ",\"resolution_scale\":" << resolution_scale;
|
||||
json << ",\"sgsr\":";
|
||||
write_sgsr(json, sgsr);
|
||||
json << ",\"openxr_post_processing\":";
|
||||
write_openxr_post_processing(json, openxr_post_processing);
|
||||
json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled;
|
||||
@@ -372,5 +342,6 @@ void configuration::save()
|
||||
json << ",\"override_foveation_pitch\":" << override_foveation_pitch;
|
||||
json << ",\"override_foveation_distance\":" << override_foveation_distance;
|
||||
json << ",\"first_run\":" << std::boolalpha << first_run;
|
||||
json << ",\"locale\":" << json_string(locale);
|
||||
json << "}";
|
||||
}
|
||||
|
||||
+3
-11
@@ -56,16 +56,7 @@ public:
|
||||
bool fb_lower_body = false;
|
||||
bool fb_hip = true;
|
||||
|
||||
// Snapdragon Game Super Resolution
|
||||
struct sgsr_settings
|
||||
{
|
||||
bool enabled = false;
|
||||
float upscaling_factor = 1.5;
|
||||
bool use_edge_direction = true;
|
||||
float edge_threshold = 4.0;
|
||||
float edge_sharpness = 2.0;
|
||||
};
|
||||
sgsr_settings sgsr{};
|
||||
bool enable_stream_gui = true;
|
||||
|
||||
// XR_FB_composition_layer_settings extension flags
|
||||
struct openxr_post_processing_settings
|
||||
@@ -83,6 +74,8 @@ public:
|
||||
|
||||
bool first_run = true;
|
||||
|
||||
std::string locale;
|
||||
|
||||
bool check_feature(feature f) const;
|
||||
void set_feature(feature f, bool state);
|
||||
|
||||
@@ -90,7 +83,6 @@ private:
|
||||
mutable std::mutex mutex;
|
||||
std::map<feature, bool> features;
|
||||
|
||||
void parse_sgsr_options(simdjson::simdjson_result<simdjson::dom::object> root);
|
||||
void parse_openxr_post_processing_options(simdjson::simdjson_result<simdjson::dom::object> root);
|
||||
|
||||
public:
|
||||
|
||||
@@ -61,6 +61,7 @@ const char * mime(wivrn::video_codec codec)
|
||||
return "video/av01";
|
||||
}
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void check(media_status_t status, const char * msg)
|
||||
@@ -72,6 +73,26 @@ void check(media_status_t status, const char * msg)
|
||||
}
|
||||
}
|
||||
|
||||
struct android_blit_handle : public decoder::blit_handle
|
||||
{
|
||||
std::shared_ptr<wivrn::android::decoder::mapped_hardware_buffer> vk_data;
|
||||
std::shared_ptr<AImageReader> image_reader;
|
||||
AImage_ptr aimage;
|
||||
android_blit_handle(
|
||||
const wivrn::from_headset::feedback & feedback,
|
||||
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info,
|
||||
vk::ImageView image_view,
|
||||
vk::Image image,
|
||||
vk::ImageLayout & current_layout,
|
||||
decltype(vk_data) vk_data,
|
||||
decltype(image_reader) image_reader,
|
||||
decltype(aimage) aimage) :
|
||||
decoder::blit_handle(feedback, view_info, image_view, image, current_layout),
|
||||
vk_data(vk_data),
|
||||
image_reader(image_reader),
|
||||
aimage(std::move(aimage)) {}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace wivrn::android
|
||||
@@ -85,7 +106,7 @@ decoder::decoder(
|
||||
uint8_t stream_index,
|
||||
std::weak_ptr<scenes::stream> weak_scene,
|
||||
shard_accumulator * accumulator) :
|
||||
description(description), stream_index(stream_index), fps(fps), device(device), weak_scene(weak_scene), accumulator(accumulator)
|
||||
wivrn::decoder(description), stream_index(stream_index), fps(fps), device(device), weak_scene(weak_scene), accumulator(accumulator)
|
||||
{
|
||||
spdlog::info("hbm_mutex.native_handle() = {}", (void *)hbm_mutex.native_handle());
|
||||
|
||||
@@ -222,7 +243,7 @@ void decoder::push_data(std::span<std::span<const uint8_t>> data, uint64_t frame
|
||||
current_input_buffer = input_buffer{};
|
||||
}
|
||||
|
||||
void decoder::frame_completed(wivrn::from_headset::feedback & feedback, const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info)
|
||||
void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info)
|
||||
{
|
||||
if (not media_codec)
|
||||
{
|
||||
@@ -255,7 +276,7 @@ void decoder::on_image_available(AImageReader * reader)
|
||||
assert(reader == image_reader.get());
|
||||
// Executed on image reader thread
|
||||
|
||||
decltype(blit_handle::aimage) image;
|
||||
decltype(android_blit_handle::aimage) image;
|
||||
try
|
||||
{
|
||||
AImage * tmp;
|
||||
@@ -280,13 +301,13 @@ void decoder::on_image_available(AImageReader * reader)
|
||||
|
||||
auto vk_data = map_hardware_buffer(image.get());
|
||||
|
||||
auto handle = std::make_shared<decoder::blit_handle>(
|
||||
auto handle = std::make_shared<android_blit_handle>(
|
||||
info->feedback,
|
||||
info->view_info,
|
||||
vk_data->image_view,
|
||||
*vk_data->image_view,
|
||||
*vk_data->vimage,
|
||||
&vk_data->layout,
|
||||
vk_data,
|
||||
vk_data->layout,
|
||||
std::move(vk_data),
|
||||
image_reader,
|
||||
std::move(image));
|
||||
|
||||
@@ -388,7 +409,8 @@ std::shared_ptr<decoder::mapped_hardware_buffer> decoder::map_hardware_buffer(AI
|
||||
if (!*ycbcr_sampler || memcmp(&ahb_format, &format_properties, sizeof(format_properties)))
|
||||
{
|
||||
memcpy(&ahb_format, &format_properties, sizeof(format_properties));
|
||||
extent = {buffer_desc.width, buffer_desc.height};
|
||||
extent_ = {buffer_desc.width, buffer_desc.height};
|
||||
spdlog::info("decoded image size: {}x{}", buffer_desc.width, buffer_desc.height);
|
||||
create_sampler(buffer_desc, ahb_format);
|
||||
hardware_buffer_map.clear();
|
||||
// TODO tell the reprojector to recreate the pipeline
|
||||
@@ -514,11 +536,6 @@ void decoder::on_media_output_available(AMediaCodec * media_codec, void * userda
|
||||
});
|
||||
}
|
||||
|
||||
void decoder::blit_handle::deleter::operator()(AImage * aimage)
|
||||
{
|
||||
AImage_delete(aimage);
|
||||
}
|
||||
|
||||
static bool hardware_accelerated(AMediaCodec * media_codec)
|
||||
{
|
||||
// MediaCodecInfo has isHardwareAccelerated, but this does not exist in NDK.
|
||||
@@ -542,9 +559,8 @@ static bool hardware_accelerated(AMediaCodec * media_codec)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<wivrn::video_codec> decoder::supported_codecs()
|
||||
void decoder::supported_codecs(std::vector<wivrn::video_codec> & result)
|
||||
{
|
||||
std::vector<wivrn::video_codec> result;
|
||||
// Make sure we update this code when codecs are changed
|
||||
static_assert(magic_enum::enum_count<wivrn::video_codec>() == 3);
|
||||
|
||||
@@ -563,8 +579,6 @@ std::vector<wivrn::video_codec> decoder::supported_codecs()
|
||||
|
||||
spdlog::info("video codec {}: {}supported", magic_enum::enum_name(codec), supported ? "" : "NOT ");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace wivrn::android
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "decoder/decoder.h"
|
||||
#include "utils/sync_queue.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <functional>
|
||||
@@ -59,31 +60,12 @@ class stream;
|
||||
|
||||
namespace wivrn::android
|
||||
{
|
||||
class decoder
|
||||
class decoder : public wivrn::decoder
|
||||
{
|
||||
public:
|
||||
struct mapped_hardware_buffer;
|
||||
|
||||
struct blit_handle
|
||||
{
|
||||
struct deleter
|
||||
{
|
||||
void operator()(AImage *);
|
||||
};
|
||||
wivrn::from_headset::feedback feedback;
|
||||
wivrn::to_headset::video_stream_data_shard::view_info_t view_info;
|
||||
vk::raii::ImageView & image_view;
|
||||
vk::Image image = nullptr;
|
||||
vk::ImageLayout * current_layout = nullptr;
|
||||
|
||||
std::shared_ptr<mapped_hardware_buffer> vk_data;
|
||||
|
||||
std::shared_ptr<AImageReader> image_reader;
|
||||
AImage_ptr aimage;
|
||||
};
|
||||
|
||||
private:
|
||||
wivrn::to_headset::video_stream_description::item description;
|
||||
uint8_t stream_index;
|
||||
float fps;
|
||||
|
||||
@@ -92,7 +74,6 @@ private:
|
||||
vk::AndroidHardwareBufferFormatPropertiesANDROID ahb_format;
|
||||
vk::raii::SamplerYcbcrConversion ycbcr_conversion = nullptr;
|
||||
vk::raii::Sampler ycbcr_sampler = nullptr;
|
||||
vk::Extent2D extent{};
|
||||
|
||||
std::mutex hbm_mutex;
|
||||
std::shared_ptr<AImageReader> image_reader;
|
||||
@@ -146,33 +127,20 @@ public:
|
||||
uint8_t stream_index,
|
||||
std::weak_ptr<scenes::stream> scene,
|
||||
shard_accumulator * accumulator);
|
||||
|
||||
decoder(const decoder &) = delete;
|
||||
decoder(decoder &&) = delete;
|
||||
~decoder();
|
||||
|
||||
void push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial);
|
||||
void push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial) override;
|
||||
|
||||
void frame_completed(
|
||||
wivrn::from_headset::feedback & feedback,
|
||||
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info);
|
||||
const wivrn::from_headset::feedback & feedback,
|
||||
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info) override;
|
||||
|
||||
const auto & desc() const
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
vk::Sampler sampler()
|
||||
vk::Sampler sampler() override
|
||||
{
|
||||
return *ycbcr_sampler;
|
||||
}
|
||||
|
||||
vk::Extent2D image_size()
|
||||
{
|
||||
return extent;
|
||||
}
|
||||
|
||||
static std::vector<wivrn::video_codec> supported_codecs();
|
||||
static void supported_codecs(std::vector<wivrn::video_codec> &);
|
||||
};
|
||||
|
||||
} // namespace wivrn::android
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 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 "decoder.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "decoder/android/android_decoder.h"
|
||||
#else
|
||||
#include "decoder/ffmpeg/ffmpeg_decoder.h"
|
||||
#endif
|
||||
|
||||
wivrn::decoder::~decoder() = default;
|
||||
|
||||
std::shared_ptr<wivrn::decoder> wivrn::decoder::make(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & phys_dev,
|
||||
const wivrn::to_headset::video_stream_description::item & description,
|
||||
float fps,
|
||||
uint8_t stream_index,
|
||||
std::weak_ptr<scenes::stream> scene,
|
||||
shard_accumulator * acc)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
return std::make_shared<wivrn::android::decoder>(
|
||||
device,
|
||||
phys_dev,
|
||||
description,
|
||||
fps,
|
||||
stream_index,
|
||||
scene,
|
||||
acc);
|
||||
#else
|
||||
return std::make_shared<wivrn::ffmpeg::decoder>(
|
||||
device,
|
||||
phys_dev,
|
||||
description,
|
||||
stream_index,
|
||||
scene,
|
||||
acc);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<wivrn::video_codec> wivrn::decoder::supported_codecs()
|
||||
{
|
||||
std::vector<wivrn::video_codec> res;
|
||||
#ifdef __ANDROID__
|
||||
android::decoder::supported_codecs(res);
|
||||
#else
|
||||
ffmpeg::decoder::supported_codecs(res);
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 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 "wivrn_packets.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
namespace scenes
|
||||
{
|
||||
class stream;
|
||||
}
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class shard_accumulator;
|
||||
class decoder
|
||||
{
|
||||
public:
|
||||
struct blit_handle
|
||||
{
|
||||
wivrn::from_headset::feedback feedback;
|
||||
wivrn::to_headset::video_stream_data_shard::view_info_t view_info;
|
||||
vk::ImageView image_view = nullptr;
|
||||
vk::Image image = nullptr;
|
||||
vk::ImageLayout & current_layout;
|
||||
};
|
||||
|
||||
const wivrn::to_headset::video_stream_description::item description;
|
||||
|
||||
protected:
|
||||
decoder(const wivrn::to_headset::video_stream_description::item & description) :
|
||||
description(description) {}
|
||||
vk::Extent2D extent_; // Must be populated when sampler is set
|
||||
|
||||
public:
|
||||
static std::shared_ptr<decoder> make(
|
||||
vk::raii::Device &,
|
||||
vk::raii::PhysicalDevice &,
|
||||
const wivrn::to_headset::video_stream_description::item & description,
|
||||
float fps,
|
||||
uint8_t stream_index,
|
||||
std::weak_ptr<scenes::stream>,
|
||||
shard_accumulator *);
|
||||
virtual ~decoder();
|
||||
virtual void push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial) = 0;
|
||||
|
||||
virtual void frame_completed(
|
||||
const from_headset::feedback & feedback,
|
||||
const to_headset::video_stream_data_shard::view_info_t & view_info) = 0;
|
||||
|
||||
virtual vk::Sampler sampler() = 0;
|
||||
const vk::Extent2D extent()
|
||||
{
|
||||
return extent_;
|
||||
}
|
||||
|
||||
static std::vector<wivrn::video_codec> supported_codecs();
|
||||
};
|
||||
} // namespace wivrn
|
||||
@@ -61,24 +61,53 @@ static AVCodecID codec_id(wivrn::video_codec codec)
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
decoder::blit_handle::~blit_handle()
|
||||
struct decoder::ffmpeg_blit_handle : public wivrn::decoder::blit_handle
|
||||
{
|
||||
std::unique_lock lock(self->mutex);
|
||||
if (image_index < 0)
|
||||
return;
|
||||
int image_index;
|
||||
wivrn::ffmpeg::decoder * self;
|
||||
|
||||
self->free_images.push_back(image_index);
|
||||
}
|
||||
ffmpeg_blit_handle(
|
||||
const wivrn::from_headset::feedback & feedback,
|
||||
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info,
|
||||
vk::ImageView image_view,
|
||||
vk::Image image,
|
||||
vk::ImageLayout & current_layout,
|
||||
int image_index,
|
||||
wivrn::ffmpeg::decoder * self) :
|
||||
wivrn::decoder::blit_handle{
|
||||
feedback,
|
||||
view_info,
|
||||
image_view,
|
||||
image,
|
||||
current_layout,
|
||||
},
|
||||
image_index(image_index),
|
||||
self(self)
|
||||
{}
|
||||
|
||||
~ffmpeg_blit_handle()
|
||||
{
|
||||
std::unique_lock lock(self->mutex);
|
||||
if (image_index < 0)
|
||||
return;
|
||||
|
||||
self->free_images.push_back(image_index);
|
||||
}
|
||||
};
|
||||
|
||||
decoder::decoder(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
const wivrn::to_headset::video_stream_description::item & description,
|
||||
float fps,
|
||||
uint8_t stream_index,
|
||||
std::weak_ptr<scenes::stream> scene,
|
||||
shard_accumulator * accumulator) :
|
||||
device(device), description(description), codec(nullptr, free_codec_context), sws(nullptr, sws_freeContext), weak_scene(scene), accumulator(accumulator)
|
||||
wivrn::decoder(description),
|
||||
device(device),
|
||||
codec(nullptr, free_codec_context),
|
||||
sws(nullptr, sws_freeContext),
|
||||
weak_scene(scene),
|
||||
accumulator(accumulator)
|
||||
{
|
||||
free_images.resize(image_count);
|
||||
|
||||
@@ -108,7 +137,7 @@ decoder::decoder(
|
||||
decoded_images[i].image = image_allocation(device, image_info, alloc_info);
|
||||
|
||||
decoded_images[i].image.map();
|
||||
extent = vk::Extent2D{description.width, description.height};
|
||||
extent_ = vk::Extent2D{description.width, description.height};
|
||||
|
||||
vk::ImageSubresource resource;
|
||||
resource.aspectMask = vk::ImageAspectFlagBits::eColor;
|
||||
@@ -221,12 +250,12 @@ void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, co
|
||||
if (res == 0)
|
||||
throw std::runtime_error{"sws_scale failed"};
|
||||
|
||||
auto handle = std::make_shared<decoder::blit_handle>(
|
||||
auto handle = std::make_shared<ffmpeg_blit_handle>(
|
||||
feedback,
|
||||
view_info,
|
||||
decoded_images[index].image_view,
|
||||
(vk::Image)decoded_images[index].image,
|
||||
&decoded_images[index].current_layout,
|
||||
*decoded_images[index].image_view,
|
||||
decoded_images[index].image,
|
||||
decoded_images[index].current_layout,
|
||||
index,
|
||||
this);
|
||||
|
||||
@@ -234,13 +263,11 @@ void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, co
|
||||
scene->push_blit_handle(accumulator, std::move(handle));
|
||||
}
|
||||
|
||||
std::vector<wivrn::video_codec> decoder::supported_codecs()
|
||||
void decoder::supported_codecs(std::vector<wivrn::video_codec> & res)
|
||||
{
|
||||
return {
|
||||
wivrn::video_codec::h264,
|
||||
wivrn::video_codec::h265,
|
||||
wivrn::video_codec::av1,
|
||||
};
|
||||
res.push_back(wivrn::video_codec::h264);
|
||||
res.push_back(wivrn::video_codec::h265);
|
||||
res.push_back(wivrn::video_codec::av1);
|
||||
}
|
||||
|
||||
} // namespace wivrn::ffmpeg
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "decoder/decoder.h"
|
||||
#include "vk/allocation.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <memory>
|
||||
@@ -46,24 +47,10 @@ class stream;
|
||||
|
||||
namespace wivrn::ffmpeg
|
||||
{
|
||||
class decoder
|
||||
class decoder : public wivrn::decoder
|
||||
{
|
||||
public:
|
||||
struct blit_handle
|
||||
{
|
||||
wivrn::from_headset::feedback feedback;
|
||||
wivrn::to_headset::video_stream_data_shard::view_info_t view_info;
|
||||
vk::raii::ImageView & image_view;
|
||||
vk::Image image = nullptr;
|
||||
vk::ImageLayout * current_layout = nullptr;
|
||||
|
||||
int image_index;
|
||||
decoder * self;
|
||||
|
||||
~blit_handle();
|
||||
};
|
||||
|
||||
private:
|
||||
struct ffmpeg_blit_handle;
|
||||
static const int image_count = 12;
|
||||
struct image
|
||||
{
|
||||
@@ -78,11 +65,8 @@ private:
|
||||
vk::raii::Sampler rgb_sampler = nullptr;
|
||||
|
||||
std::array<image, image_count> decoded_images;
|
||||
vk::Extent2D extent{};
|
||||
std::vector<int> free_images;
|
||||
|
||||
wivrn::to_headset::video_stream_description::item description;
|
||||
|
||||
std::unique_ptr<AVCodecContext, void (*)(AVCodecContext *)> codec;
|
||||
std::unique_ptr<SwsContext, void (*)(SwsContext *)> sws;
|
||||
std::vector<uint8_t> packet;
|
||||
@@ -96,35 +80,21 @@ public:
|
||||
decoder(vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
const wivrn::to_headset::video_stream_description::item & description,
|
||||
float fps,
|
||||
uint8_t stream_index,
|
||||
std::weak_ptr<scenes::stream> scene,
|
||||
shard_accumulator * accumulator);
|
||||
|
||||
decoder(const decoder &) = delete;
|
||||
decoder(decoder &&) = delete;
|
||||
|
||||
void push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial);
|
||||
void push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial) override;
|
||||
|
||||
void frame_completed(
|
||||
const wivrn::from_headset::feedback & feedback,
|
||||
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info);
|
||||
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info) override;
|
||||
|
||||
const auto & desc() const
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
vk::Sampler sampler()
|
||||
vk::Sampler sampler() override
|
||||
{
|
||||
return *rgb_sampler;
|
||||
}
|
||||
|
||||
vk::Extent2D image_size()
|
||||
{
|
||||
return extent;
|
||||
}
|
||||
|
||||
static std::vector<wivrn::video_codec> supported_codecs();
|
||||
static void supported_codecs(std::vector<wivrn::video_codec> &);
|
||||
};
|
||||
} // namespace wivrn::ffmpeg
|
||||
|
||||
@@ -186,7 +186,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx)
|
||||
payload.emplace_back(data_shards[idx]->payload);
|
||||
|
||||
bool frame_complete = last_idx == data_shards.size() and data_shards.back()->flags & video_stream_data_shard::end_of_frame;
|
||||
decoder->push_data(payload, data_shards[shard_idx]->frame_idx, not frame_complete);
|
||||
decoder_->push_data(payload, data_shards[shard_idx]->frame_idx, not frame_complete);
|
||||
|
||||
if (not frame_complete)
|
||||
return;
|
||||
@@ -206,7 +206,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx)
|
||||
}
|
||||
|
||||
// Try to extract a frame
|
||||
decoder->frame_completed(current.feedback, *data_shards.front()->view_info);
|
||||
decoder_->frame_completed(current.feedback, *data_shards.front()->view_info);
|
||||
|
||||
send_feedback(current.feedback);
|
||||
|
||||
|
||||
@@ -19,27 +19,30 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "decoder/android/android_decoder.h"
|
||||
using decoder_impl = ::wivrn::android::decoder;
|
||||
#else
|
||||
#include "decoder/ffmpeg/ffmpeg_decoder.h"
|
||||
using decoder_impl = ::wivrn::ffmpeg::decoder;
|
||||
#endif
|
||||
|
||||
#include "decoder.h"
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class instance;
|
||||
}
|
||||
|
||||
namespace scenes
|
||||
{
|
||||
class stream;
|
||||
}
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
class shard_accumulator
|
||||
{
|
||||
std::shared_ptr<decoder_impl> decoder;
|
||||
std::shared_ptr<decoder> decoder_;
|
||||
|
||||
public:
|
||||
using data_shard = wivrn::to_headset::video_stream_data_shard;
|
||||
@@ -50,7 +53,7 @@ public:
|
||||
void reset(uint64_t frame_index);
|
||||
bool empty() const;
|
||||
|
||||
std::optional<uint16_t> insert(data_shard &&);
|
||||
std::optional<uint16_t> insert(data_shard &&, xr::instance & instance);
|
||||
|
||||
wivrn::from_headset::feedback feedback{};
|
||||
|
||||
@@ -70,19 +73,22 @@ private:
|
||||
shard_set current;
|
||||
shard_set next;
|
||||
std::weak_ptr<scenes::stream> weak_scene;
|
||||
xr::instance & instance;
|
||||
|
||||
public:
|
||||
explicit shard_accumulator(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
xr::instance & instance,
|
||||
const wivrn::to_headset::video_stream_description::item & description,
|
||||
float fps,
|
||||
std::weak_ptr<scenes::stream> scene,
|
||||
uint8_t stream_index) :
|
||||
decoder(std::make_shared<decoder_impl>(device, physical_device, description, fps, stream_index, scene, this)),
|
||||
decoder_(decoder::make(device, physical_device, description, fps, stream_index, scene, this)),
|
||||
current(stream_index),
|
||||
next(stream_index),
|
||||
weak_scene(scene)
|
||||
weak_scene(scene),
|
||||
instance(instance)
|
||||
{
|
||||
next.reset(1);
|
||||
}
|
||||
@@ -91,20 +97,20 @@ public:
|
||||
|
||||
auto & desc() const
|
||||
{
|
||||
return decoder->desc();
|
||||
return decoder_->description;
|
||||
}
|
||||
|
||||
vk::Sampler sampler()
|
||||
{
|
||||
return decoder->sampler();
|
||||
return decoder_->sampler();
|
||||
}
|
||||
|
||||
vk::Extent2D image_size()
|
||||
const vk::Extent2D extent()
|
||||
{
|
||||
return decoder->image_size();
|
||||
return decoder_->extent();
|
||||
}
|
||||
|
||||
using blit_handle = decoder_impl::blit_handle;
|
||||
using blit_handle = decoder::blit_handle;
|
||||
|
||||
private:
|
||||
void try_submit_frame(std::optional<uint16_t> shard_idx);
|
||||
|
||||
@@ -490,22 +490,22 @@ static std::vector<std::string> find_font(std::u16string sample_text, const std:
|
||||
|
||||
void imgui_context::initialize_fonts()
|
||||
{
|
||||
std::u16string sample_text = u"Hello world";
|
||||
|
||||
const auto & locale = application::get_messages_info();
|
||||
auto it = glyph_set_per_language.find(locale.language + "_" + locale.country);
|
||||
if (it == glyph_set_per_language.end())
|
||||
it = glyph_set_per_language.find(locale.language);
|
||||
|
||||
if (it != glyph_set_per_language.end())
|
||||
for (char16_t c: it->second)
|
||||
sample_text += c;
|
||||
|
||||
// Load Fonts
|
||||
auto fonts = find_font(sample_text, application::get_messages_info().language);
|
||||
for (auto & i: fonts)
|
||||
std::vector<std::string> fonts;
|
||||
for (auto & [code, glyphs]: glyph_set_per_language)
|
||||
{
|
||||
spdlog::info("Font {}", i);
|
||||
std::u16string sample_text = u"Hello world";
|
||||
|
||||
for (char16_t c: glyphs)
|
||||
sample_text += c;
|
||||
auto language = code.substr(0, code.find("_"));
|
||||
|
||||
// Load Fonts
|
||||
for (auto && i: find_font(sample_text, language))
|
||||
{
|
||||
spdlog::info("Font for {} {}", code, i);
|
||||
if (not std::ranges::contains(fonts, i))
|
||||
fonts.push_back(std::move(i));
|
||||
}
|
||||
}
|
||||
|
||||
asset font_awesome_regular("Font Awesome 6 Free-Regular-400.otf");
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <ranges>
|
||||
#include <spdlog/spdlog.h>
|
||||
@@ -42,8 +41,6 @@
|
||||
#include <vulkan/vulkan_enums.hpp>
|
||||
#include <vulkan/vulkan_structs.hpp>
|
||||
|
||||
extern const std::map<std::string, std::vector<uint32_t>> shaders;
|
||||
|
||||
// TODO move in lobby?
|
||||
vk::Format scene_renderer::find_usable_image_format(
|
||||
vk::raii::PhysicalDevice physical_device,
|
||||
|
||||
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 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 "blitter.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "vk/pipeline.h"
|
||||
#include "vk/shader.h"
|
||||
#include "vk/specialization_constants.h"
|
||||
#include <format>
|
||||
#include <ranges>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
static const uint32_t num_views = 2;
|
||||
|
||||
blitter::blitter(vk::raii::Device & device, size_t view) :
|
||||
device(device), view(view)
|
||||
{
|
||||
}
|
||||
|
||||
void blitter::reset(const to_headset::video_stream_description & desc)
|
||||
{
|
||||
using channels_t = to_headset::video_stream_description::channels_t;
|
||||
this->desc = desc;
|
||||
|
||||
current = {};
|
||||
target = image_allocation();
|
||||
image_view = nullptr;
|
||||
rp = nullptr;
|
||||
fb = nullptr;
|
||||
sampler = nullptr;
|
||||
pipelines.clear();
|
||||
passthrough_rgb = passthrough_a = -1;
|
||||
|
||||
auto w = desc.width / num_views;
|
||||
for (auto [i, item]: utils::enumerate(desc.items))
|
||||
{
|
||||
if (item.offset_x <= view * w and
|
||||
item.offset_y == 0 and
|
||||
item.offset_x + item.width * item.subsampling >= (view + 1) * w and
|
||||
item.height * item.subsampling >= desc.height)
|
||||
{
|
||||
spdlog::info("Stream {} is eligible for blit-less path on view {}", i, view);
|
||||
switch (item.channels)
|
||||
{
|
||||
case channels_t::colour:
|
||||
passthrough_rgb = i;
|
||||
break;
|
||||
case channels_t::alpha:
|
||||
passthrough_a = i;
|
||||
break;
|
||||
}
|
||||
const bool alpha = item.channels == to_headset::video_stream_description::channels_t::alpha;
|
||||
auto & r = alpha ? current.rect_a : current.rect_rgb;
|
||||
r = vk::Rect2D{
|
||||
.offset = {
|
||||
.x = int32_t(view * w) - item.offset_x,
|
||||
.y = 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (passthrough_rgb != -1 and passthrough_a != -1)
|
||||
return;
|
||||
|
||||
target = image_allocation(
|
||||
device,
|
||||
vk::ImageCreateInfo{
|
||||
.imageType = vk::ImageType::e2D,
|
||||
.format = vk::Format::eB8G8R8A8Srgb,
|
||||
.extent = {
|
||||
.width = w,
|
||||
.height = desc.height,
|
||||
.depth = 1,
|
||||
},
|
||||
.mipLevels = 1,
|
||||
.arrayLayers = 1,
|
||||
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eColorAttachment,
|
||||
},
|
||||
{
|
||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||
},
|
||||
std::format("blit image {}", view));
|
||||
|
||||
image_view = device.createImageView(vk::ImageViewCreateInfo{
|
||||
.image = vk::Image(target),
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = target.info().format,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.levelCount = 1,
|
||||
.layerCount = 1,
|
||||
}});
|
||||
|
||||
// render pass
|
||||
{
|
||||
vk::AttachmentReference color_ref{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::SubpassDescription subpass{
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
.colorAttachmentCount = 1,
|
||||
.pColorAttachments = &color_ref,
|
||||
};
|
||||
|
||||
vk::AttachmentDescription color_desc{
|
||||
.format = target.info().format,
|
||||
.loadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
rp = device.createRenderPass(vk::RenderPassCreateInfo{
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &color_desc,
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subpass,
|
||||
});
|
||||
}
|
||||
|
||||
fb = device.createFramebuffer(
|
||||
vk::FramebufferCreateInfo{
|
||||
.renderPass = *rp,
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &*image_view,
|
||||
.width = w,
|
||||
.height = desc.height,
|
||||
.layers = 1,
|
||||
});
|
||||
|
||||
sampler = device.createSampler(vk::SamplerCreateInfo{
|
||||
.magFilter = vk::Filter::eLinear,
|
||||
.minFilter = vk::Filter::eLinear,
|
||||
.addressModeU = vk::SamplerAddressMode::eClampToBorder,
|
||||
.addressModeV = vk::SamplerAddressMode::eClampToBorder,
|
||||
.addressModeW = vk::SamplerAddressMode::eClampToBorder,
|
||||
.borderColor = vk::BorderColor::eFloatOpaqueBlack,
|
||||
});
|
||||
|
||||
pipelines.resize(desc.items.size());
|
||||
for (auto [i, item]: utils::enumerate(desc.items))
|
||||
{
|
||||
pipelines[i].used = item.offset_x < (view + 1) * w and
|
||||
item.offset_x + item.width * item.subsampling > view * w;
|
||||
}
|
||||
|
||||
current.rgb = *image_view;
|
||||
current.sampler_rgb = *sampler;
|
||||
current.rect_rgb = vk::Rect2D{.extent = {w, desc.height}};
|
||||
current.layout_rgb = vk::ImageLayout::eShaderReadOnlyOptimal;
|
||||
}
|
||||
|
||||
void blitter::begin(vk::raii::CommandBuffer & cmd)
|
||||
{
|
||||
assert(not desc.items.empty());
|
||||
if (*fb == VK_NULL_HANDLE)
|
||||
{
|
||||
current.rgb = nullptr;
|
||||
current.a = nullptr;
|
||||
current.sampler_rgb = nullptr;
|
||||
current.sampler_a = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
current.rgb = *image_view;
|
||||
current.sampler_rgb = *sampler;
|
||||
|
||||
cmd.beginRenderPass(
|
||||
{
|
||||
.renderPass = *rp,
|
||||
.framebuffer = *fb,
|
||||
.renderArea = {
|
||||
.offset = {0, 0},
|
||||
.extent = {target.info().extent.width, target.info().extent.height},
|
||||
},
|
||||
},
|
||||
vk::SubpassContents::eInline);
|
||||
}
|
||||
|
||||
void blitter::push_image(vk::raii::CommandBuffer & cmd, uint8_t stream, vk::Sampler sampler, const vk::Extent2D & extent_, vk::ImageView image, vk::ImageLayout layout)
|
||||
{
|
||||
if (stream == passthrough_rgb)
|
||||
{
|
||||
current.rgb = image;
|
||||
current.sampler_rgb = sampler;
|
||||
current.layout_rgb = layout;
|
||||
current.rect_rgb.extent = vk::Extent2D{
|
||||
extent_.width * desc.items[stream].subsampling,
|
||||
extent_.height * desc.items[stream].subsampling,
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (stream == passthrough_a)
|
||||
{
|
||||
current.a = image;
|
||||
current.sampler_a = sampler;
|
||||
current.layout_a = layout;
|
||||
current.rect_a.extent = vk::Extent2D{
|
||||
extent_.width * desc.items[stream].subsampling,
|
||||
extent_.height * desc.items[stream].subsampling,
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (pipelines.empty())
|
||||
return;
|
||||
|
||||
assert(stream < pipelines.size());
|
||||
auto & p = pipelines[stream];
|
||||
if (not p.used)
|
||||
return;
|
||||
|
||||
const auto & extent = target.info().extent;
|
||||
const auto & description = desc.items[stream];
|
||||
if (not *p.pipeline)
|
||||
{
|
||||
const bool alpha = description.channels == to_headset::video_stream_description::channels_t::alpha;
|
||||
vk::DescriptorSetLayoutBinding sampler_layout_binding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
.pImmutableSamplers = &sampler,
|
||||
};
|
||||
|
||||
p.set_layout = device.createDescriptorSetLayout(vk::DescriptorSetLayoutCreateInfo{
|
||||
.flags = vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR,
|
||||
.bindingCount = 1,
|
||||
.pBindings = &sampler_layout_binding,
|
||||
});
|
||||
|
||||
auto vert_constants = make_specialization_constants(
|
||||
float(description.width) / extent_.width,
|
||||
float(description.height) / extent_.height);
|
||||
|
||||
auto frag_constants = make_specialization_constants(
|
||||
VkBool32(alpha));
|
||||
|
||||
// Create graphics pipeline
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert");
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, "stream.frag");
|
||||
|
||||
p.layout = device.createPipelineLayout(vk::PipelineLayoutCreateInfo{
|
||||
.setLayoutCount = 1,
|
||||
.pSetLayouts = &*p.set_layout,
|
||||
});
|
||||
|
||||
vk::pipeline_builder pipeline_info{
|
||||
.Stages = {{
|
||||
.stage = vk::ShaderStageFlagBits::eVertex,
|
||||
.module = *vertex_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = vert_constants,
|
||||
},
|
||||
{
|
||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.module = *fragment_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = frag_constants,
|
||||
}},
|
||||
.VertexBindingDescriptions = {},
|
||||
.VertexAttributeDescriptions = {},
|
||||
.InputAssemblyState = {{
|
||||
.topology = vk::PrimitiveTopology::eTriangleStrip,
|
||||
}},
|
||||
// With vk::DynamicState::eViewport, vk::DynamicState::eScissor the number of viewports
|
||||
// and scissors is still used, put a vector with one element
|
||||
.Viewports = {{}},
|
||||
.Scissors = {{}},
|
||||
.RasterizationState = {{
|
||||
.polygonMode = vk::PolygonMode::eFill,
|
||||
.lineWidth = 1,
|
||||
}},
|
||||
.MultisampleState = {{
|
||||
.rasterizationSamples = vk::SampleCountFlagBits::e1,
|
||||
}},
|
||||
.ColorBlendAttachments = {
|
||||
{.colorWriteMask = alpha ? vk::ColorComponentFlagBits::eA
|
||||
: vk::ColorComponentFlagBits::eA | vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB}},
|
||||
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
|
||||
.layout = *p.layout,
|
||||
.renderPass = *rp,
|
||||
.subpass = 0,
|
||||
};
|
||||
|
||||
p.pipeline = device.createGraphicsPipeline(application::get_pipeline_cache(), pipeline_info);
|
||||
spdlog::info("Created blit pipeline for stream {}, view {}", stream, view);
|
||||
}
|
||||
|
||||
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, *p.pipeline);
|
||||
|
||||
vk::DescriptorImageInfo image_info{
|
||||
.imageView = image,
|
||||
.imageLayout = layout,
|
||||
};
|
||||
cmd.pushDescriptorSetKHR(
|
||||
vk::PipelineBindPoint::eGraphics,
|
||||
*p.layout,
|
||||
0,
|
||||
vk::WriteDescriptorSet{
|
||||
.dstBinding = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = &image_info,
|
||||
});
|
||||
|
||||
int x0 = description.offset_x - view * extent.width;
|
||||
int y0 = description.offset_y;
|
||||
int x1 = x0 + description.width * description.subsampling;
|
||||
int y1 = y0 + description.height * description.subsampling;
|
||||
|
||||
cmd.setViewport(
|
||||
0,
|
||||
vk::Viewport{
|
||||
.x = (float)x0,
|
||||
.y = (float)y0,
|
||||
.width = float(description.width * description.subsampling),
|
||||
.height = float(description.height * description.subsampling),
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
});
|
||||
|
||||
x0 = std::clamp<int>(x0, 0, extent.width);
|
||||
x1 = std::clamp<int>(x1, 0, extent.width);
|
||||
y0 = std::clamp<int>(y0, 0, extent.height);
|
||||
y1 = std::clamp<int>(y1, 0, extent.height);
|
||||
|
||||
cmd.setScissor(
|
||||
0,
|
||||
vk::Rect2D{
|
||||
.offset = {.x = x0, .y = y0},
|
||||
.extent = {.width = uint32_t(x1 - x0), .height = uint32_t(y1 - y0)},
|
||||
});
|
||||
cmd.draw(3, 1, 0, 0);
|
||||
}
|
||||
|
||||
blitter::output blitter::end(vk::raii::CommandBuffer & cmd)
|
||||
{
|
||||
if (*fb)
|
||||
cmd.endRenderPass();
|
||||
return current;
|
||||
}
|
||||
|
||||
} // namespace wivrn
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 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 "vk/allocation.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class blitter
|
||||
{
|
||||
public:
|
||||
struct output
|
||||
{
|
||||
vk::ImageView rgb;
|
||||
vk::Sampler sampler_rgb;
|
||||
vk::Rect2D rect_rgb;
|
||||
vk::ImageLayout layout_rgb;
|
||||
vk::ImageView a;
|
||||
vk::Sampler sampler_a;
|
||||
vk::Rect2D rect_a;
|
||||
vk::ImageLayout layout_a;
|
||||
};
|
||||
|
||||
private:
|
||||
vk::raii::Device & device;
|
||||
size_t view;
|
||||
to_headset::video_stream_description desc;
|
||||
// indices to simply passthrough, if -1 image needs to be blitted
|
||||
int passthrough_rgb = -1;
|
||||
int passthrough_a = -1;
|
||||
image_allocation target;
|
||||
vk::raii::ImageView image_view = nullptr;
|
||||
vk::raii::RenderPass rp = nullptr;
|
||||
vk::raii::Framebuffer fb = nullptr;
|
||||
vk::raii::Sampler sampler = nullptr;
|
||||
struct pipeline_t
|
||||
{
|
||||
vk::raii::DescriptorSetLayout set_layout = nullptr;
|
||||
vk::raii::PipelineLayout layout = nullptr;
|
||||
vk::raii::Pipeline pipeline = nullptr;
|
||||
bool used = false; // true if we need this image for blitting
|
||||
};
|
||||
std::vector<pipeline_t> pipelines;
|
||||
output current;
|
||||
|
||||
public:
|
||||
blitter(vk::raii::Device & device, size_t view);
|
||||
|
||||
void reset(const to_headset::video_stream_description & desc);
|
||||
void begin(vk::raii::CommandBuffer &);
|
||||
void push_image(vk::raii::CommandBuffer & buf, uint8_t stream, vk::Sampler sampler, const vk::Extent2D &, vk::ImageView image, vk::ImageLayout);
|
||||
output end(vk::raii::CommandBuffer &);
|
||||
};
|
||||
} // namespace wivrn
|
||||
+40
-85
@@ -17,6 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <uni_algo/case.h>
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
#ifdef __ANDROID__
|
||||
@@ -139,7 +140,7 @@ static void InputText(const char * label, std::string & text, const ImVec2 & siz
|
||||
return 0;
|
||||
};
|
||||
|
||||
ImGui::InputTextEx(label, nullptr, text.data(), text.size(), size, flags | ImGuiInputTextFlags_CallbackResize, callback, &text);
|
||||
ImGui::InputTextEx(label, nullptr, text.data(), text.size() + 1, size, flags | ImGuiInputTextFlags_CallbackResize, callback, &text);
|
||||
}
|
||||
|
||||
static void display_recentering_tip(imgui_context & ctx, const std::string & tip)
|
||||
@@ -771,6 +772,43 @@ void scenes::lobby::gui_settings()
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20, 20));
|
||||
|
||||
{
|
||||
auto language_name = [&](const std::locale & loc = std::locale()) {
|
||||
return boost::locale::pgettext("language selection, replace with the name of the language", "English", loc);
|
||||
};
|
||||
std::vector<std::tuple<std::string, std::locale, std::string>> languages;
|
||||
for (const auto & msg_info: get_locales())
|
||||
{
|
||||
std::string code = msg_info.language;
|
||||
if (not msg_info.country.empty())
|
||||
code += "_" + msg_info.country;
|
||||
std::locale loc(std::locale(), boost::locale::gnu_gettext::create_messages_facet<char>(msg_info));
|
||||
languages.emplace_back(language_name(loc), loc, std::move(code));
|
||||
}
|
||||
std::ranges::sort(languages, [](auto & l, auto & r) {
|
||||
return una::casesens::collate_utf8(std::get<0>(l), std::get<0>(r)) < 0;
|
||||
});
|
||||
if (ImGui::BeginCombo(_S("Language"), config.locale.empty() ? _S("System language") : language_name().c_str()))
|
||||
{
|
||||
if (ImGui::Selectable(_S("System language"), config.locale.empty(), ImGuiSelectableFlags_SelectOnRelease))
|
||||
{
|
||||
config.locale.clear();
|
||||
config.save();
|
||||
application::instance().load_locale();
|
||||
}
|
||||
for (const auto & [lang, locale, code]: languages)
|
||||
{
|
||||
if (ImGui::Selectable(lang.c_str(), code == config.locale, ImGuiSelectableFlags_SelectOnRelease))
|
||||
{
|
||||
config.locale = code;
|
||||
config.save();
|
||||
application::instance().load_locale();
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
}
|
||||
|
||||
if (instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME))
|
||||
{
|
||||
const auto & refresh_rates = session.get_refresh_rates();
|
||||
@@ -1034,89 +1072,6 @@ void scenes::lobby::gui_post_processing()
|
||||
ImGui::Unindent();
|
||||
}
|
||||
|
||||
{
|
||||
// SGSR
|
||||
{
|
||||
if (ImGui::Checkbox(_S("Enable Snapdragon Game Super Resolution"), &config.sgsr.enabled))
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
if (application::get_openxr_post_processing_supported())
|
||||
imgui_ctx->tooltip(_("On this headset, this setting has been fully superseded by the native Sharpening setting above.\nOnly enable if you know what you're doing."));
|
||||
else
|
||||
imgui_ctx->tooltip(_("Client-side upscaling and sharpening, adds a performance cost on the headset"));
|
||||
}
|
||||
if (application::get_openxr_post_processing_supported())
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::TextColored(ImColor(0xf9, 0x73, 0x06) /*orange*/, ICON_FA_TRIANGLE_EXCLAMATION);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::BeginDisabled(not config.sgsr.enabled);
|
||||
ImGui::Indent();
|
||||
{
|
||||
const auto current = config.sgsr.upscaling_factor;
|
||||
const auto width = stream_view.recommendedImageRectWidth * config.resolution_scale;
|
||||
const auto height = stream_view.recommendedImageRectHeight * config.resolution_scale;
|
||||
auto intScale = int(current * 100);
|
||||
const auto slider = ImGui::SliderInt(
|
||||
_("Upscaling factor").append("##upscaling_factor").c_str(),
|
||||
&intScale,
|
||||
100,
|
||||
200,
|
||||
fmt::format(_F("%d%% - {}x{} per eye"), int(width * current), int(height * current)).c_str());
|
||||
if (slider)
|
||||
{
|
||||
config.sgsr.upscaling_factor = intScale * 0.01;
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (width * current > stream_view.maxImageRectWidth or height * current > stream_view.maxImageRectHeight)
|
||||
{
|
||||
ImGui::TextColored(ImColor(0xf9, 0x73, 0x06) /*orange*/, ICON_FA_TRIANGLE_EXCLAMATION);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("%s", fmt::format(_F("Resolution larger than {}x{} may not be supported by the headset"), stream_view.maxImageRectWidth, stream_view.maxImageRectHeight).c_str());
|
||||
}
|
||||
}
|
||||
{
|
||||
if (ImGui::Checkbox(_S("Use edge direction"), &config.sgsr.use_edge_direction))
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(_("Adds an additional performance cost"));
|
||||
}
|
||||
{
|
||||
const float current = config.sgsr.edge_threshold;
|
||||
int intScale = int(current);
|
||||
if (ImGui::SliderInt(_S("Edge threshold"), &intScale, 1, 16, "%d.0"))
|
||||
{
|
||||
config.sgsr.edge_threshold = float(intScale);
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(fmt::format(_F("Recommended: {:.1f}"), 4.0));
|
||||
}
|
||||
{
|
||||
if (ImGui::SliderFloat(_S("Edge sharpness"), &config.sgsr.edge_sharpness, 1.0, 2.0, "%.2f"))
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(fmt::format(_F("Recommended: {:.1f}"), 2.0));
|
||||
}
|
||||
ImGui::Unindent();
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
@@ -1347,7 +1302,7 @@ void scenes::lobby::gui_licenses()
|
||||
ImGui::Text("%s", _("Licenses").c_str());
|
||||
ImGui::PopFont();
|
||||
|
||||
const auto components = {"WiVRn", "FontAwesome", "openxr-loader", "simdjson", "SGSR"};
|
||||
const auto components = {"WiVRn", "FontAwesome", "openxr-loader", "simdjson"};
|
||||
if (not license)
|
||||
{
|
||||
selected_item = *components.begin();
|
||||
|
||||
+95
-389
@@ -17,11 +17,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "constants.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "xr/fb_body_tracker.h"
|
||||
#include "xr/body_tracker.h"
|
||||
#include "xr/face_tracker.h"
|
||||
#include "xr/fb_face_tracker2.h"
|
||||
#include "xr/htc_body_tracker.h"
|
||||
#include "xr/pico_body_tracker.h"
|
||||
#include "xr/space.h"
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
@@ -40,8 +38,6 @@
|
||||
#include "utils/contains.h"
|
||||
#include "utils/named_thread.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "vk/pipeline.h"
|
||||
#include "vk/shader.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
@@ -49,6 +45,11 @@
|
||||
#include <thread>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
#include "wivrn_config.h"
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
#include "vk/renderdoc.h"
|
||||
#endif
|
||||
|
||||
using namespace wivrn;
|
||||
|
||||
// clang-format off
|
||||
@@ -151,7 +152,8 @@ static const std::array supported_depth_formats{
|
||||
};
|
||||
|
||||
scenes::stream::stream() :
|
||||
scene_impl<stream>(supported_color_formats, supported_depth_formats)
|
||||
scene_impl<stream>(supported_color_formats, supported_depth_formats),
|
||||
blitters{blitter(device, 0), blitter(device, 1)}
|
||||
{
|
||||
}
|
||||
|
||||
@@ -189,7 +191,11 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
self->network_session = std::move(network_session);
|
||||
|
||||
self->network_session->send_control([&]() {
|
||||
from_headset::headset_info_packet info{};
|
||||
from_headset::headset_info_packet info{
|
||||
.language = application::get_messages_info().language,
|
||||
.country = application::get_messages_info().country,
|
||||
.variant = application::get_messages_info().variant,
|
||||
};
|
||||
|
||||
auto view = self->system.view_configuration_views(self->viewconfig)[0];
|
||||
view = override_view(view, guess_model());
|
||||
@@ -251,46 +257,49 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
|
||||
if (config.check_feature(feature::face_tracking))
|
||||
{
|
||||
info.face_tracking = std::visit(utils::overloaded{
|
||||
[](std::monostate &) {
|
||||
return from_headset::face_type::none;
|
||||
},
|
||||
[](xr::fb_face_tracker2 &) {
|
||||
return from_headset::face_type::fb2;
|
||||
},
|
||||
[](xr::htc_face_tracker &) {
|
||||
return from_headset::face_type::htc;
|
||||
},
|
||||
[](xr::pico_face_tracker &) {
|
||||
return from_headset::face_type::fb2;
|
||||
},
|
||||
},
|
||||
application::get_face_tracker());
|
||||
switch (self->system.face_tracker_supported())
|
||||
{
|
||||
case xr::face_tracker_type::none:
|
||||
info.face_tracking = from_headset::face_type::none;
|
||||
break;
|
||||
case xr::face_tracker_type::fb:
|
||||
case xr::face_tracker_type::pico:
|
||||
info.face_tracking = from_headset::face_type::fb2;
|
||||
break;
|
||||
case xr::face_tracker_type::htc:
|
||||
info.face_tracking = from_headset::face_type::htc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
info.num_generic_trackers = 0;
|
||||
if (config.check_feature(feature::body_tracking))
|
||||
{
|
||||
info.num_generic_trackers = std::visit(utils::overloaded{
|
||||
[&](std::monostate &) {
|
||||
return size_t(0);
|
||||
},
|
||||
[&](auto & b) {
|
||||
return b.count();
|
||||
},
|
||||
},
|
||||
application::get_body_tracker());
|
||||
switch (self->system.body_tracker_supported())
|
||||
{
|
||||
case xr::body_tracker_type::none:
|
||||
break;
|
||||
case xr::body_tracker_type::fb:
|
||||
info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size();
|
||||
break;
|
||||
case xr::body_tracker_type::htc:
|
||||
info.num_generic_trackers = application::get_generic_trackers().size();
|
||||
break;
|
||||
case xr::body_tracker_type::pico:
|
||||
info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right);
|
||||
info.passthrough = self->system.passthrough_supported() != xr::system::passthrough_type::no_passthrough;
|
||||
info.passthrough = self->system.passthrough_supported() != xr::passthrough_type::none;
|
||||
info.system_name = std::string(self->system.properties().systemName);
|
||||
|
||||
audio::get_audio_description(info);
|
||||
if (not(config.check_feature(feature::microphone)))
|
||||
info.microphone = {};
|
||||
|
||||
info.supported_codecs = decoder_impl::supported_codecs();
|
||||
info.supported_codecs = decoder::supported_codecs();
|
||||
return info;
|
||||
}());
|
||||
|
||||
@@ -311,15 +320,6 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const auto & info = application::get_messages_info();
|
||||
self->network_session->send_control(from_headset::get_application_list{
|
||||
.language = info.language,
|
||||
.country = info.country,
|
||||
.variant = info.variant,
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto & config = application::get_config();
|
||||
self->override_foveation_enable = config.override_foveation_enable;
|
||||
@@ -363,7 +363,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
{
|
||||
self->haptics_actions.emplace(id, haptics_action{
|
||||
.action = action.first,
|
||||
.path = application::string_to_path(path),
|
||||
.path = self->instance.string_to_path(path),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -394,7 +394,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
|
||||
void scenes::stream::on_focused()
|
||||
{
|
||||
gui_status_last_change = application::now();
|
||||
gui_status_last_change = instance.now();
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
// stream_view = override_view(views[0], guess_model());
|
||||
@@ -402,7 +402,7 @@ void scenes::stream::on_focused()
|
||||
height = views[0].recommendedImageRectHeight;
|
||||
|
||||
renderer.emplace(device, physical_device, queue, commandpool);
|
||||
loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
|
||||
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
|
||||
|
||||
std::string profile = controller_name();
|
||||
input.emplace(
|
||||
@@ -470,8 +470,11 @@ void scenes::stream::on_focused()
|
||||
swapchain_imgui,
|
||||
std::vector{vp});
|
||||
|
||||
plots_toggle_1 = get_action("plots_toggle_1").first;
|
||||
plots_toggle_2 = get_action("plots_toggle_2").first;
|
||||
if (application::get_config().enable_stream_gui)
|
||||
{
|
||||
plots_toggle_1 = get_action("plots_toggle_1").first;
|
||||
plots_toggle_2 = get_action("plots_toggle_2").first;
|
||||
}
|
||||
recenter_left = get_action("recenter_left").first;
|
||||
recenter_right = get_action("recenter_right").first;
|
||||
foveation_pitch = get_action("foveation_pitch").first;
|
||||
@@ -494,6 +497,8 @@ void scenes::stream::on_unfocused()
|
||||
loader.reset();
|
||||
renderer.reset();
|
||||
clear_swapchains();
|
||||
left_hand.reset();
|
||||
right_hand.reset();
|
||||
|
||||
imgui_ctx.reset();
|
||||
swapchain_imgui = xr::swapchain();
|
||||
@@ -524,16 +529,16 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p
|
||||
{
|
||||
if (decoder != decoders[stream].decoder.get())
|
||||
return;
|
||||
handle->feedback.received_from_decoder = application::now();
|
||||
handle->feedback.received_from_decoder = instance.now();
|
||||
std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]);
|
||||
}
|
||||
|
||||
if (state_ != state::streaming and std::ranges::all_of(decoders, [](accumulator_images & i) {
|
||||
return i.alpha() or not i.frames().empty();
|
||||
return i.alpha() or not i.empty();
|
||||
}))
|
||||
{
|
||||
state_ = state::streaming;
|
||||
spdlog::info("Stream scene ready at t={}", application::now());
|
||||
spdlog::info("Stream scene ready at t={}", instance.now());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,15 +553,14 @@ bool scenes::stream::accumulator_images::alpha() const
|
||||
return decoder->desc().channels == wivrn::to_headset::video_stream_description::channels_t::alpha;
|
||||
}
|
||||
|
||||
std::vector<uint64_t> scenes::stream::accumulator_images::frames() const
|
||||
bool scenes::stream::accumulator_images::empty() const
|
||||
{
|
||||
std::vector<uint64_t> result;
|
||||
for (const auto & frame: latest_frames)
|
||||
{
|
||||
if (frame)
|
||||
result.push_back(frame->feedback.frame_index);
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::common_frame(XrTime display_time)
|
||||
@@ -766,138 +770,17 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
}
|
||||
|
||||
if (state_ == state::stalled)
|
||||
application::pop_scene();
|
||||
|
||||
assert(swapchain);
|
||||
for (auto & i: decoders)
|
||||
{
|
||||
if (auto sampler = i.decoder->sampler(); sampler and not *i.blit_pipeline)
|
||||
{
|
||||
// Create blit pipeline
|
||||
// Create VkDescriptorSetLayout with an immutable sampler
|
||||
vk::DescriptorSetLayoutBinding sampler_layout_binding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
.pImmutableSamplers = &sampler,
|
||||
};
|
||||
network_session->send_control(from_headset::get_application_list{
|
||||
.language = application::get_messages_info().language,
|
||||
.country = application::get_messages_info().country,
|
||||
.variant = application::get_messages_info().variant,
|
||||
});
|
||||
|
||||
vk::DescriptorSetLayoutCreateInfo layout_info{
|
||||
.bindingCount = 1,
|
||||
.pBindings = &sampler_layout_binding,
|
||||
};
|
||||
|
||||
i.descriptor_set_layout = vk::raii::DescriptorSetLayout(device, layout_info);
|
||||
i.descriptor_set = device.allocateDescriptorSets(
|
||||
vk::DescriptorSetAllocateInfo{
|
||||
.descriptorPool = *blit_descriptor_pool,
|
||||
.descriptorSetCount = 1,
|
||||
.pSetLayouts = &*i.descriptor_set_layout,
|
||||
})[0]
|
||||
.release();
|
||||
|
||||
const auto & description = i.decoder->desc();
|
||||
vk::Extent2D image_size = i.decoder->image_size();
|
||||
std::array useful_size{
|
||||
float(description.width) / image_size.width,
|
||||
float(description.height) / image_size.height,
|
||||
};
|
||||
spdlog::info("useful size: {}x{} with buffer {}x{}",
|
||||
description.width,
|
||||
description.height,
|
||||
image_size.width,
|
||||
image_size.height);
|
||||
|
||||
std::array specialization_constants_desc{
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 0,
|
||||
.offset = 0,
|
||||
.size = sizeof(float),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 1,
|
||||
.offset = sizeof(float),
|
||||
.size = sizeof(float),
|
||||
}};
|
||||
|
||||
vk::SpecializationInfo vert_specialization_info;
|
||||
vert_specialization_info.setMapEntries(specialization_constants_desc);
|
||||
vert_specialization_info.setData<float>(useful_size);
|
||||
|
||||
std::array<VkBool32, 2> constants = {
|
||||
need_srgb_conversion(guess_model()),
|
||||
i.alpha(),
|
||||
};
|
||||
std::array frag_specialization_constant_desc = {
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 0,
|
||||
.offset = 0,
|
||||
.size = sizeof(constants[0]),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 1,
|
||||
.offset = sizeof(constants[0]),
|
||||
.size = sizeof(constants[1]),
|
||||
},
|
||||
};
|
||||
vk::SpecializationInfo frag_specialization_info;
|
||||
frag_specialization_info.setMapEntries(frag_specialization_constant_desc);
|
||||
frag_specialization_info.setData<VkBool32>(constants);
|
||||
|
||||
// Create graphics pipeline
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert");
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, "stream.frag");
|
||||
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info{
|
||||
.setLayoutCount = 1,
|
||||
.pSetLayouts = &*i.descriptor_set_layout,
|
||||
};
|
||||
|
||||
i.blit_pipeline_layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||
|
||||
vk::pipeline_builder pipeline_info{
|
||||
.Stages = {{
|
||||
.stage = vk::ShaderStageFlagBits::eVertex,
|
||||
.module = *vertex_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = &vert_specialization_info,
|
||||
},
|
||||
{
|
||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.module = *fragment_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = &frag_specialization_info,
|
||||
}},
|
||||
.VertexBindingDescriptions = {},
|
||||
.VertexAttributeDescriptions = {},
|
||||
.InputAssemblyState = {{
|
||||
.topology = vk::PrimitiveTopology::eTriangleStrip,
|
||||
}},
|
||||
// With vk::DynamicState::eViewport, vk::DynamicState::eScissor the number of viewports
|
||||
// and scissors is still used, put a vector with one element
|
||||
.Viewports = {{}},
|
||||
.Scissors = {{}},
|
||||
.RasterizationState = {{
|
||||
.polygonMode = vk::PolygonMode::eFill,
|
||||
.lineWidth = 1,
|
||||
}},
|
||||
.MultisampleState = {{
|
||||
.rasterizationSamples = vk::SampleCountFlagBits::e1,
|
||||
}},
|
||||
.ColorBlendAttachments = {
|
||||
{.colorWriteMask = i.alpha() ? vk::ColorComponentFlagBits::eA
|
||||
: vk::ColorComponentFlagBits::eA | vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB}},
|
||||
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
|
||||
.layout = *i.blit_pipeline_layout,
|
||||
.renderPass = *blit_render_pass,
|
||||
.subpass = 0,
|
||||
};
|
||||
|
||||
i.blit_pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info);
|
||||
}
|
||||
application::pop_scene();
|
||||
}
|
||||
|
||||
assert(swapchain);
|
||||
if (device.waitForFences(*fence, VK_TRUE, UINT64_MAX) == vk::Result::eTimeout)
|
||||
throw std::runtime_error("Vulkan fence timeout");
|
||||
|
||||
@@ -928,11 +811,13 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
|
||||
std::array<int, view_count> image_indices;
|
||||
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
renderdoc_begin(*vk_instance);
|
||||
#endif
|
||||
command_buffer.reset();
|
||||
|
||||
vk::CommandBufferBeginInfo begin_info;
|
||||
begin_info.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit;
|
||||
command_buffer.begin(begin_info);
|
||||
command_buffer.begin(vk::CommandBufferBeginInfo{
|
||||
.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit,
|
||||
});
|
||||
|
||||
// Keep a reference to the resources needed to blit the images until vkWaitForFences
|
||||
|
||||
@@ -947,13 +832,12 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
std::array<wivrn::to_headset::foveation_parameter, 2> foveation{};
|
||||
bool use_alpha = false;
|
||||
|
||||
// Blit images from the decoders
|
||||
for (auto [i, blit_handle]: std::views::zip(decoders, current_blit_handles))
|
||||
for (auto & blit_handle: current_blit_handles)
|
||||
{
|
||||
if (not blit_handle or not *i.blit_pipeline)
|
||||
if (not blit_handle)
|
||||
continue;
|
||||
|
||||
blit_handle->feedback.blitted = application::now();
|
||||
blit_handle->feedback.blitted = instance.now();
|
||||
if (blit_handle->feedback.blitted - blit_handle->feedback.received_from_decoder > 1'000'000'000)
|
||||
state_ = stream::state::stalled;
|
||||
++blit_handle->feedback.times_displayed;
|
||||
@@ -964,27 +848,12 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
foveation = blit_handle->view_info.foveation;
|
||||
use_alpha = blit_handle->view_info.alpha;
|
||||
|
||||
vk::DescriptorImageInfo image_info{
|
||||
.imageView = *blit_handle->image_view,
|
||||
.imageLayout = vk::ImageLayout::eGeneral,
|
||||
};
|
||||
|
||||
vk::WriteDescriptorSet descriptor_write{
|
||||
.dstSet = i.descriptor_set,
|
||||
.dstBinding = 0,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = &image_info,
|
||||
};
|
||||
|
||||
device.updateDescriptorSets(descriptor_write, {});
|
||||
if (*blit_handle->current_layout != vk::ImageLayout::eGeneral)
|
||||
if (blit_handle->current_layout == vk::ImageLayout::eUndefined)
|
||||
{
|
||||
vk::ImageMemoryBarrier barrier{
|
||||
.srcAccessMask = vk::AccessFlagBits::eNone,
|
||||
.dstAccessMask = vk::AccessFlagBits::eMemoryRead,
|
||||
.oldLayout = *blit_handle->current_layout,
|
||||
.oldLayout = vk::ImageLayout::eUndefined,
|
||||
.newLayout = vk::ImageLayout::eGeneral,
|
||||
.image = blit_handle->image,
|
||||
.subresourceRange = {
|
||||
@@ -995,72 +864,22 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
};
|
||||
|
||||
command_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, {}, {}, barrier);
|
||||
*blit_handle->current_layout = vk::ImageLayout::eGeneral;
|
||||
blit_handle->current_layout = vk::ImageLayout::eGeneral;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t x_offset = 0;
|
||||
for (auto & out: decoder_output)
|
||||
// Blit images from the decoders
|
||||
std::array<blitter::output, view_count> blitted;
|
||||
for (auto [i, b]: utils::enumerate(blitters))
|
||||
{
|
||||
command_buffer.beginRenderPass(
|
||||
{
|
||||
.renderPass = *blit_render_pass,
|
||||
.framebuffer = *out.frame_buffer,
|
||||
.renderArea = {
|
||||
.offset = {0, 0},
|
||||
.extent = decoder_out_size,
|
||||
},
|
||||
.clearValueCount = 0,
|
||||
},
|
||||
vk::SubpassContents::eInline);
|
||||
|
||||
for (const auto & decoder: decoders)
|
||||
b.begin(command_buffer);
|
||||
for (auto [j, blit_handle]: utils::enumerate(current_blit_handles))
|
||||
{
|
||||
if (not *decoder.blit_pipeline)
|
||||
if (not blit_handle)
|
||||
continue;
|
||||
if (decoder.alpha() and not use_alpha)
|
||||
continue;
|
||||
|
||||
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *decoder.blit_pipeline);
|
||||
|
||||
const auto & description = decoder.decoder->desc();
|
||||
int x0 = description.offset_x - x_offset;
|
||||
int y0 = description.offset_y;
|
||||
int x1 = x0 + description.width * description.subsampling;
|
||||
int y1 = y0 + description.height * description.subsampling;
|
||||
|
||||
vk::Viewport viewport{
|
||||
.x = (float)x0,
|
||||
.y = (float)y0,
|
||||
.width = float(description.width * description.subsampling),
|
||||
.height = float(description.height * description.subsampling),
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
};
|
||||
|
||||
x0 = std::clamp<int>(x0, 0, decoder_out_size.width);
|
||||
x1 = std::clamp<int>(x1, 0, decoder_out_size.width);
|
||||
y0 = std::clamp<int>(y0, 0, decoder_out_size.height);
|
||||
y1 = std::clamp<int>(y1, 0, decoder_out_size.height);
|
||||
|
||||
vk::Rect2D scissor{
|
||||
.offset = {.x = x0, .y = y0},
|
||||
.extent = {.width = (uint32_t)(x1 - x0), .height = (uint32_t)(y1 - y0)},
|
||||
};
|
||||
|
||||
command_buffer.setViewport(0, viewport);
|
||||
command_buffer.setScissor(0, scissor);
|
||||
|
||||
command_buffer.bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics,
|
||||
*decoder.blit_pipeline_layout,
|
||||
0,
|
||||
decoder.descriptor_set,
|
||||
nullptr);
|
||||
command_buffer.draw(3, 1, 0, 0);
|
||||
b.push_image(command_buffer, j, decoders[j].decoder->sampler(), decoders[j].decoder->extent(), blit_handle->image_view, blit_handle->current_layout);
|
||||
}
|
||||
command_buffer.endRenderPass();
|
||||
x_offset += decoder_out_size.width;
|
||||
blitted[i] = b.end(command_buffer);
|
||||
}
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
|
||||
@@ -1071,7 +890,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
int32_t max_height = 0;
|
||||
for (size_t i = 0; i < view_count; ++i)
|
||||
{
|
||||
extents[i] = reprojector->defoveated_size(foveation[i]);
|
||||
extents[i] = defoveator->defoveated_size(foveation[i]);
|
||||
max_width = std::max(max_width, extents[i].width);
|
||||
max_height = std::max(max_height, extents[i].height);
|
||||
}
|
||||
@@ -1101,7 +920,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
// defoveate the image
|
||||
int image_index = swapchain.acquire();
|
||||
swapchain.wait();
|
||||
reprojector->reproject(command_buffer, foveation, image_index);
|
||||
defoveator->defoveate(command_buffer, foveation, blitted, image_index);
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
|
||||
|
||||
@@ -1109,6 +928,9 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
vk::SubmitInfo submit_info;
|
||||
submit_info.setCommandBuffers(*command_buffer);
|
||||
queue.lock()->submit(submit_info, *fence);
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
renderdoc_end(*vk_instance);
|
||||
#endif
|
||||
swapchain.release();
|
||||
|
||||
std::vector<XrCompositionLayerProjectionView> layer_view(view_count);
|
||||
@@ -1275,119 +1097,15 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
}
|
||||
|
||||
video_stream_description = description;
|
||||
|
||||
const uint32_t video_width = description.width / view_count;
|
||||
const uint32_t video_height = description.height;
|
||||
|
||||
// Create renderpass
|
||||
{
|
||||
vk::AttachmentDescription color_desc{
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.loadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.storeOp = vk::AttachmentStoreOp::eStore,
|
||||
.initialLayout = vk::ImageLayout::eUndefined,
|
||||
.finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
vk::AttachmentReference color_ref{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::SubpassDescription subpass{
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
};
|
||||
subpass.setColorAttachments(color_ref);
|
||||
|
||||
vk::RenderPassCreateInfo renderpass_info{
|
||||
.flags = {},
|
||||
};
|
||||
renderpass_info.setAttachments(color_desc);
|
||||
renderpass_info.setSubpasses(subpass);
|
||||
|
||||
blit_render_pass = vk::raii::RenderPass(device, renderpass_info);
|
||||
}
|
||||
|
||||
// Create outputs for the decoders
|
||||
decoder_out_size = vk::Extent2D{video_width, video_height};
|
||||
{
|
||||
decoder_out_format = vk::Format::eA8B8G8R8SrgbPack32;
|
||||
|
||||
vk::ImageCreateInfo image_info{
|
||||
.flags = vk::ImageCreateFlags{},
|
||||
.imageType = vk::ImageType::e2D,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.extent = {video_width, video_height, 1},
|
||||
.mipLevels = 1,
|
||||
.arrayLayers = view_count,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.tiling = vk::ImageTiling::eOptimal,
|
||||
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eColorAttachment,
|
||||
.sharingMode = vk::SharingMode::eExclusive,
|
||||
.initialLayout = vk::ImageLayout::eUndefined,
|
||||
};
|
||||
|
||||
VmaAllocationCreateInfo alloc_info{
|
||||
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||
};
|
||||
|
||||
decoder_out_image = image_allocation{device, image_info, alloc_info};
|
||||
|
||||
vk::ImageViewCreateInfo image_view_info{
|
||||
.image = vk::Image{decoder_out_image},
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.components = {},
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
|
||||
for (uint32_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
auto & output = decoder_output[view];
|
||||
|
||||
image_view_info.subresourceRange.baseArrayLayer = view;
|
||||
output.image_view = vk::raii::ImageView(device, image_view_info);
|
||||
|
||||
output.frame_buffer = vk::raii::Framebuffer(
|
||||
device,
|
||||
vk::FramebufferCreateInfo{
|
||||
.renderPass = *blit_render_pass,
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &*output.image_view,
|
||||
.width = decoder_out_size.width,
|
||||
.height = decoder_out_size.height,
|
||||
.layers = 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
vk::DescriptorPoolSize pool_size{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = uint32_t(2 * description.items.size()),
|
||||
};
|
||||
blit_descriptor_pool = vk::raii::DescriptorPool(
|
||||
device,
|
||||
vk::DescriptorPoolCreateInfo{
|
||||
.maxSets = uint32_t(2 * description.items.size()),
|
||||
.poolSizeCount = 1,
|
||||
.pPoolSizes = &pool_size,
|
||||
});
|
||||
}
|
||||
for (auto & b: blitters)
|
||||
b.reset(description);
|
||||
|
||||
for (const auto & [stream_index, item]: utils::enumerate(description.items))
|
||||
{
|
||||
spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y);
|
||||
|
||||
decoders.push_back(accumulator_images{
|
||||
.decoder = std::make_unique<shard_accumulator>(device, physical_device, item, description.fps, shared_from_this(), stream_index),
|
||||
.decoder = std::make_unique<shard_accumulator>(device, physical_device, instance, item, description.fps, shared_from_this(), stream_index),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1400,15 +1118,6 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
|
||||
const uint32_t video_width = video_stream_description->width / view_count;
|
||||
const uint32_t video_height = video_stream_description->height;
|
||||
|
||||
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
|
||||
if (sgsr.enabled)
|
||||
{
|
||||
const float upscaling_factor = sgsr.upscaling_factor;
|
||||
spdlog::info("Using SGSR with an upscale factor of {}", upscaling_factor);
|
||||
swapchain_width *= upscaling_factor;
|
||||
swapchain_height *= upscaling_factor;
|
||||
}
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
|
||||
swapchain = xr::swapchain(session, device, swapchain_format, swapchain_width, swapchain_height, 1, views.size());
|
||||
@@ -1425,12 +1134,9 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
|
||||
for (auto & image: swapchain.images())
|
||||
swapchain_images.push_back(image.image);
|
||||
|
||||
reprojector.emplace(
|
||||
defoveator.emplace(
|
||||
device,
|
||||
physical_device,
|
||||
decoder_out_image,
|
||||
vk::Extent2D{.width = video_width, .height = video_height},
|
||||
2,
|
||||
swapchain_images,
|
||||
extent,
|
||||
swapchain.format());
|
||||
|
||||
+19
-23
@@ -23,8 +23,9 @@
|
||||
#include "decoder/shard_accumulator.h"
|
||||
#include "render/imgui_impl.h"
|
||||
#include "scene.h"
|
||||
#include "scenes/blitter.h"
|
||||
#include "scenes/input_profile.h"
|
||||
#include "stream_reprojection.h"
|
||||
#include "stream_defoveator.h"
|
||||
#include "utils/thread_safe.h"
|
||||
#include "wifi_lock.h"
|
||||
#include "wivrn_client.h"
|
||||
@@ -48,6 +49,13 @@ public:
|
||||
};
|
||||
static const size_t image_buffer_size = 3;
|
||||
|
||||
struct app
|
||||
{
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::vector<std::byte> image;
|
||||
};
|
||||
|
||||
private:
|
||||
static const size_t view_count = 2;
|
||||
|
||||
@@ -56,16 +64,12 @@ private:
|
||||
struct accumulator_images
|
||||
{
|
||||
std::unique_ptr<wivrn::shard_accumulator> decoder;
|
||||
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
|
||||
vk::DescriptorSet descriptor_set = nullptr;
|
||||
vk::raii::PipelineLayout blit_pipeline_layout = nullptr;
|
||||
vk::raii::Pipeline blit_pipeline = nullptr;
|
||||
// latest frames from oldest to most recent
|
||||
// latest frames, rolling buffer
|
||||
std::array<std::shared_ptr<wivrn::shard_accumulator::blit_handle>, image_buffer_size> latest_frames;
|
||||
|
||||
std::shared_ptr<wivrn::shard_accumulator::blit_handle> frame(uint64_t id) const;
|
||||
bool alpha() const;
|
||||
std::vector<uint64_t> frames() const;
|
||||
bool empty() const;
|
||||
};
|
||||
|
||||
wifi_lock::wifi wifi;
|
||||
@@ -77,9 +81,9 @@ private:
|
||||
std::unique_ptr<wivrn_session> network_session;
|
||||
std::atomic<bool> exiting = false;
|
||||
std::thread network_thread;
|
||||
std::mutex tracking_control_mutex;
|
||||
to_headset::tracking_control tracking_control{};
|
||||
thread_safe<to_headset::tracking_control> tracking_control{};
|
||||
std::array<std::atomic<interaction_profile>, 2> interaction_profiles; // left and right hand
|
||||
std::atomic<bool> interaction_profile_changed = false;
|
||||
std::atomic<bool> recenter_requested = false;
|
||||
std::atomic<XrDuration> display_time_phase = 0;
|
||||
std::atomic<XrDuration> display_time_period = 0;
|
||||
@@ -90,21 +94,10 @@ private:
|
||||
std::shared_mutex decoder_mutex;
|
||||
std::optional<to_headset::video_stream_description> video_stream_description;
|
||||
std::vector<accumulator_images> decoders; // Locked by decoder_mutex
|
||||
vk::raii::DescriptorPool blit_descriptor_pool = nullptr;
|
||||
vk::raii::RenderPass blit_render_pass = nullptr;
|
||||
|
||||
vk::Extent2D decoder_out_size;
|
||||
vk::Format decoder_out_format;
|
||||
image_allocation decoder_out_image;
|
||||
std::array<blitter, view_count> blitters;
|
||||
|
||||
struct renderpass_output
|
||||
{
|
||||
vk::raii::ImageView image_view = nullptr;
|
||||
vk::raii::Framebuffer frame_buffer = nullptr;
|
||||
};
|
||||
std::array<renderpass_output, view_count> decoder_output;
|
||||
|
||||
std::optional<stream_reprojection> reprojector;
|
||||
std::optional<stream_defoveator> defoveator;
|
||||
|
||||
vk::raii::Fence fence = nullptr;
|
||||
vk::raii::CommandBuffer command_buffer = nullptr;
|
||||
@@ -125,6 +118,8 @@ private:
|
||||
|
||||
std::optional<audio> audio_handle;
|
||||
|
||||
std::optional<xr::hand_tracker> left_hand;
|
||||
std::optional<xr::hand_tracker> right_hand;
|
||||
std::optional<input_profile> input;
|
||||
static inline const uint32_t layer_controllers = 1 << 0;
|
||||
static inline const uint32_t layer_rays = 1 << 1;
|
||||
@@ -176,7 +171,7 @@ private:
|
||||
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> current_blit_handles;
|
||||
|
||||
// Last application list received from server
|
||||
thread_safe<to_headset::application_list> applications;
|
||||
thread_safe<std::vector<app>> applications;
|
||||
|
||||
stream();
|
||||
|
||||
@@ -202,6 +197,7 @@ public:
|
||||
void operator()(to_headset::video_stream_description &&);
|
||||
void operator()(to_headset::refresh_rate_change &&);
|
||||
void operator()(to_headset::application_list &&);
|
||||
void operator()(to_headset::application_icon &&);
|
||||
void operator()(audio_data &&);
|
||||
|
||||
void push_blit_handle(wivrn::shard_accumulator * decoder, std::shared_ptr<wivrn::shard_accumulator::blit_handle> handle);
|
||||
|
||||
@@ -17,13 +17,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "stream_reprojection.h"
|
||||
#include "stream_defoveator.h"
|
||||
#include "application.h"
|
||||
#include "utils/contains.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "vk/allocation.h"
|
||||
#include "vk/pipeline.h"
|
||||
#include "vk/shader.h"
|
||||
#include "vk/specialization_constants.h"
|
||||
#include <array>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
@@ -31,22 +32,21 @@
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
struct stream_reprojection::vertex
|
||||
struct stream_defoveator::vertex
|
||||
{
|
||||
// output image position
|
||||
alignas(8) glm::vec2 position;
|
||||
// input texture coordinates
|
||||
alignas(8) glm::vec2 uv;
|
||||
// input texture coordinates + shading rate in the first 4 bits of x
|
||||
alignas(8) glm::uvec2 uv;
|
||||
};
|
||||
|
||||
struct SgsrSpecializationConstants
|
||||
struct vert_pc
|
||||
{
|
||||
VkBool32 use_edge_direction;
|
||||
float edge_threshold;
|
||||
float edge_sharpness;
|
||||
glm::ivec4 rgb_rect;
|
||||
glm::ivec4 a_rect;
|
||||
};
|
||||
|
||||
void stream_reprojection::ensure_vertices(size_t num_vertices)
|
||||
void stream_defoveator::ensure_vertices(size_t num_vertices)
|
||||
{
|
||||
vk::BufferCreateInfo create_info{
|
||||
.size = num_vertices * sizeof(vertex) * view_count,
|
||||
@@ -65,212 +65,81 @@ void stream_reprojection::ensure_vertices(size_t num_vertices)
|
||||
vertices_size = num_vertices * sizeof(vertex);
|
||||
}
|
||||
|
||||
stream_reprojection::vertex * stream_reprojection::get_vertices(size_t view)
|
||||
stream_defoveator::vertex * stream_defoveator::get_vertices(size_t view)
|
||||
{
|
||||
assert(buffer);
|
||||
return reinterpret_cast<vertex *>(reinterpret_cast<uintptr_t>(buffer.map()) + view * vertices_size);
|
||||
}
|
||||
|
||||
stream_reprojection::stream_reprojection(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
vk::Image input_image_,
|
||||
vk::Extent2D input_extent,
|
||||
uint32_t view_count,
|
||||
std::vector<vk::Image> output_images_,
|
||||
vk::Extent2D output_extent,
|
||||
vk::Format format) :
|
||||
view_count(view_count),
|
||||
device(device),
|
||||
input_image(input_image_),
|
||||
input_extent(input_extent),
|
||||
output_images(std::move(output_images_)),
|
||||
output_extent(output_extent)
|
||||
stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a)
|
||||
{
|
||||
vk::SamplerCreateInfo sampler_info{
|
||||
.magFilter = vk::Filter::eLinear,
|
||||
.minFilter = vk::Filter::eLinear,
|
||||
.mipmapMode = vk::SamplerMipmapMode::eNearest,
|
||||
.addressModeU = vk::SamplerAddressMode::eClampToBorder,
|
||||
.addressModeV = vk::SamplerAddressMode::eClampToBorder,
|
||||
.addressModeW = vk::SamplerAddressMode::eClampToBorder,
|
||||
.mipLodBias = 0.0f,
|
||||
.anisotropyEnable = VK_FALSE,
|
||||
.maxAnisotropy = 1,
|
||||
.compareEnable = VK_FALSE,
|
||||
.compareOp = vk::CompareOp::eNever,
|
||||
.minLod = 0.0f,
|
||||
.maxLod = 0.0f,
|
||||
.borderColor = vk::BorderColor::eFloatOpaqueBlack,
|
||||
.unnormalizedCoordinates = VK_FALSE,
|
||||
};
|
||||
auto & target = a ? pipeline_a[view] : pipeline_rgb[view];
|
||||
if (*target.pipeline)
|
||||
return target;
|
||||
|
||||
if (utils::contains(application::get_vk_device_extensions(), VK_IMG_FILTER_CUBIC_EXTENSION_NAME))
|
||||
sampler_info.magFilter = vk::Filter::eCubicIMG;
|
||||
|
||||
sampler = vk::raii::Sampler(device, sampler_info);
|
||||
std::array samplers{rgb, a};
|
||||
int32_t alpha = a ? 1 : 0;
|
||||
|
||||
// Create VkDescriptorSetLayout
|
||||
vk::DescriptorSetLayoutBinding layout_binding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
};
|
||||
|
||||
vk::DescriptorSetLayoutCreateInfo layout_info;
|
||||
layout_info.setBindings(layout_binding);
|
||||
|
||||
descriptor_set_layout = vk::raii::DescriptorSetLayout(device, layout_info);
|
||||
|
||||
std::array pool_size{
|
||||
vk::DescriptorPoolSize{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = (uint32_t)view_count,
|
||||
std::array layout_binding{
|
||||
vk::DescriptorSetLayoutBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = uint32_t(alpha + 1),
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
.pImmutableSamplers = samplers.data(),
|
||||
},
|
||||
};
|
||||
|
||||
vk::DescriptorPoolCreateInfo pool_info{
|
||||
.maxSets = view_count,
|
||||
.poolSizeCount = pool_size.size(),
|
||||
.pPoolSizes = pool_size.data(),
|
||||
target.descriptor_set_layout = device.createDescriptorSetLayout(vk::DescriptorSetLayoutCreateInfo{
|
||||
.bindingCount = layout_binding.size(),
|
||||
.pBindings = layout_binding.data(),
|
||||
});
|
||||
|
||||
target.ds = device.allocateDescriptorSets(vk::DescriptorSetAllocateInfo{
|
||||
.descriptorPool = *ds_pool,
|
||||
.descriptorSetCount = 1,
|
||||
.pSetLayouts = &*target.descriptor_set_layout,
|
||||
})[0]
|
||||
.release();
|
||||
|
||||
// pipeline layout
|
||||
vk::PushConstantRange pc_range{
|
||||
.stageFlags = vk::ShaderStageFlagBits::eVertex,
|
||||
.size = sizeof(vert_pc),
|
||||
};
|
||||
|
||||
descriptor_pool = vk::raii::DescriptorPool(device, pool_info);
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info{
|
||||
.setLayoutCount = 1,
|
||||
.pSetLayouts = &*target.descriptor_set_layout,
|
||||
.pushConstantRangeCount = 1,
|
||||
.pPushConstantRanges = &pc_range,
|
||||
};
|
||||
|
||||
// Create image views and descriptor sets
|
||||
for (uint32_t view = 0; view < view_count; ++view)
|
||||
target.layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||
|
||||
const auto & vk_device_extensions = application::get_vk_device_extensions();
|
||||
bool fragment_shading_rate = false;
|
||||
if (utils::contains(vk_device_extensions, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) and
|
||||
utils::contains(vk_device_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME))
|
||||
{
|
||||
vk::ImageViewCreateInfo iv_info{
|
||||
.image = input_image,
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.components = {
|
||||
.r = vk::ComponentSwizzle::eIdentity,
|
||||
.g = vk::ComponentSwizzle::eIdentity,
|
||||
.b = vk::ComponentSwizzle::eIdentity,
|
||||
.a = vk::ComponentSwizzle::eIdentity,
|
||||
},
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = view,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
|
||||
vk::ImageView input_image_view = *input_image_views.emplace_back(device, iv_info);
|
||||
|
||||
vk::DescriptorSetAllocateInfo ds_info{
|
||||
.descriptorPool = *descriptor_pool,
|
||||
.descriptorSetCount = 1,
|
||||
.pSetLayouts = &*descriptor_set_layout,
|
||||
};
|
||||
|
||||
auto descriptor_set = descriptor_sets.emplace_back(device.allocateDescriptorSets(ds_info)[0].release());
|
||||
|
||||
vk::DescriptorImageInfo image_info{
|
||||
.sampler = *sampler,
|
||||
.imageView = input_image_view,
|
||||
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
device.updateDescriptorSets(
|
||||
vk::WriteDescriptorSet{
|
||||
.dstSet = descriptor_set,
|
||||
.dstBinding = 0,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = &image_info,
|
||||
},
|
||||
{});
|
||||
const auto & [prop, rate_prop] = physical_device.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceFragmentShadingRatePropertiesKHR>();
|
||||
const auto & [feat, fragment_feat] = physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
|
||||
fragment_shading_rate = rate_prop.fragmentShadingRateNonTrivialCombinerOps and
|
||||
fragment_feat.primitiveFragmentShadingRate and
|
||||
fragment_feat.attachmentFragmentShadingRate;
|
||||
}
|
||||
|
||||
// Create renderpass
|
||||
vk::AttachmentReference color_ref{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::AttachmentDescription attachment{
|
||||
.format = format,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.loadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.storeOp = vk::AttachmentStoreOp::eStore,
|
||||
.initialLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
.finalLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::SubpassDescription subpass{
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
};
|
||||
subpass.setColorAttachments(color_ref);
|
||||
|
||||
vk::StructureChain renderpass_info{
|
||||
vk::RenderPassCreateInfo{
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &attachment,
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subpass,
|
||||
},
|
||||
};
|
||||
|
||||
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
|
||||
|
||||
// Vertex shader
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert");
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, fragment_shading_rate ? "reprojection_vsr.vert" : "reprojection.vert");
|
||||
|
||||
// Fragment shader
|
||||
std::string fragment_shader_name = "reprojection.frag";
|
||||
auto specialization = make_specialization_constants(
|
||||
int32_t(alpha),
|
||||
VkBool32(need_srgb_conversion(guess_model())));
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, "reprojection.frag");
|
||||
|
||||
vk::SpecializationInfo fragment_specialization_info;
|
||||
SgsrSpecializationConstants fragment_specialization_constants;
|
||||
std::vector<vk::SpecializationMapEntry> fragment_specialization_constants_desc;
|
||||
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
|
||||
if (sgsr.enabled)
|
||||
{
|
||||
fragment_shader_name = "reprojection_sgsr.frag";
|
||||
|
||||
fragment_specialization_constants = {
|
||||
.use_edge_direction = sgsr.use_edge_direction,
|
||||
.edge_threshold = float(sgsr.edge_threshold / 255.0),
|
||||
.edge_sharpness = sgsr.edge_sharpness,
|
||||
};
|
||||
|
||||
fragment_specialization_constants_desc = {
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 0,
|
||||
.offset = offsetof(SgsrSpecializationConstants, use_edge_direction),
|
||||
.size = sizeof(fragment_specialization_constants.use_edge_direction),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 1,
|
||||
.offset = offsetof(SgsrSpecializationConstants, edge_threshold),
|
||||
.size = sizeof(fragment_specialization_constants.edge_threshold),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 2,
|
||||
.offset = offsetof(SgsrSpecializationConstants, edge_sharpness),
|
||||
.size = sizeof(fragment_specialization_constants.edge_sharpness),
|
||||
},
|
||||
};
|
||||
|
||||
fragment_specialization_info.setMapEntries(fragment_specialization_constants_desc);
|
||||
fragment_specialization_info.setDataSize(sizeof(fragment_specialization_constants));
|
||||
fragment_specialization_info.setPData(&fragment_specialization_constants);
|
||||
}
|
||||
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, fragment_shader_name);
|
||||
|
||||
// Create graphics pipeline
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info;
|
||||
pipeline_layout_info.setSetLayouts(*descriptor_set_layout);
|
||||
|
||||
layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||
|
||||
vk::pipeline_builder pipeline_info{
|
||||
vk::pipeline_builder pipeline_info_builder{
|
||||
.flags = {},
|
||||
.Stages = {
|
||||
{
|
||||
@@ -282,7 +151,7 @@ stream_reprojection::stream_reprojection(
|
||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.module = *fragment_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = &fragment_specialization_info,
|
||||
.pSpecializationInfo = specialization,
|
||||
},
|
||||
},
|
||||
.VertexBindingDescriptions = {
|
||||
@@ -302,25 +171,15 @@ stream_reprojection::stream_reprojection(
|
||||
{
|
||||
.location = 1,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32G32Sfloat,
|
||||
.format = vk::Format::eR32G32Uint,
|
||||
.offset = offsetof(vertex, uv),
|
||||
},
|
||||
},
|
||||
.InputAssemblyState = {{
|
||||
.topology = vk::PrimitiveTopology::eTriangleStrip,
|
||||
}},
|
||||
.Viewports = {{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = (float)output_extent.width,
|
||||
.height = (float)output_extent.height,
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
}},
|
||||
.Scissors = {{
|
||||
.offset = {.x = 0, .y = 0},
|
||||
.extent = output_extent,
|
||||
}},
|
||||
.Viewports = {{}},
|
||||
.Scissors = {{}},
|
||||
.RasterizationState = {{
|
||||
.polygonMode = vk::PolygonMode::eFill,
|
||||
.lineWidth = 1,
|
||||
@@ -332,12 +191,109 @@ stream_reprojection::stream_reprojection(
|
||||
.ColorBlendAttachments = {{
|
||||
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
|
||||
}},
|
||||
.layout = *layout,
|
||||
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
|
||||
.layout = *target.layout,
|
||||
.renderPass = *renderpass,
|
||||
.subpass = 0,
|
||||
};
|
||||
|
||||
pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info);
|
||||
vk::GraphicsPipelineCreateInfo pipeline_info(pipeline_info_builder);
|
||||
|
||||
// Variable fragment shading
|
||||
std::array combiner{
|
||||
vk::FragmentShadingRateCombinerOpKHR::eMax,
|
||||
vk::FragmentShadingRateCombinerOpKHR::eMax,
|
||||
};
|
||||
vk::PipelineFragmentShadingRateStateCreateInfoKHR shading{
|
||||
.fragmentSize = vk::Extent2D{1, 1},
|
||||
.combinerOps = combiner,
|
||||
};
|
||||
if (fragment_shading_rate)
|
||||
{
|
||||
pipeline_info.pNext = &shading;
|
||||
|
||||
spdlog::info("Available fragment shading rates:");
|
||||
for (const auto rate: physical_device.getFragmentShadingRatesKHR())
|
||||
{
|
||||
if (rate.sampleCounts & vk::SampleCountFlagBits::e1)
|
||||
{
|
||||
spdlog::info("\tfragment size: {}x{}", rate.fragmentSize.width, rate.fragmentSize.height);
|
||||
int flags = 0;
|
||||
if (rate.fragmentSize.width == 4)
|
||||
flags |= 8;
|
||||
else if (rate.fragmentSize.width == 2)
|
||||
flags |= 4;
|
||||
if (rate.fragmentSize.height == 4)
|
||||
flags |= 2;
|
||||
else if (rate.fragmentSize.height == 2)
|
||||
flags |= 1;
|
||||
for (int y = std::bit_width(rate.fragmentSize.height) - 1; y < 3; ++y)
|
||||
{
|
||||
for (int x = std::bit_width(rate.fragmentSize.width) - 1; x < 3; ++x)
|
||||
{
|
||||
if (fragment_sizes[x][y] == 0)
|
||||
fragment_sizes[x][y] = flags << 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
target.pipeline = device.createGraphicsPipeline(application::get_pipeline_cache(), pipeline_info);
|
||||
return target;
|
||||
}
|
||||
|
||||
stream_defoveator::stream_defoveator(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
std::vector<vk::Image> output_images_,
|
||||
vk::Extent2D output_extent,
|
||||
vk::Format format) :
|
||||
device(device),
|
||||
physical_device(physical_device),
|
||||
output_images(std::move(output_images_)),
|
||||
output_extent(output_extent)
|
||||
{
|
||||
// Create renderpass
|
||||
vk::AttachmentDescription attachment{
|
||||
.format = format,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.loadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.storeOp = vk::AttachmentStoreOp::eStore,
|
||||
.finalLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::AttachmentReference color_ref{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
vk::SubpassDescription subpass{
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
.colorAttachmentCount = 1,
|
||||
.pColorAttachments = &color_ref,
|
||||
};
|
||||
|
||||
vk::StructureChain renderpass_info{
|
||||
vk::RenderPassCreateInfo{
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &attachment,
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subpass,
|
||||
},
|
||||
};
|
||||
|
||||
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
|
||||
|
||||
vk::DescriptorPoolSize pool_size{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = view_count * 4,
|
||||
};
|
||||
|
||||
ds_pool = device.createDescriptorPool(vk::DescriptorPoolCreateInfo{
|
||||
.maxSets = view_count * 2,
|
||||
.poolSizeCount = 1,
|
||||
.pPoolSizes = &pool_size,
|
||||
});
|
||||
|
||||
// Create image views and framebuffers
|
||||
output_image_views.reserve(output_images.size() * view_count);
|
||||
@@ -390,9 +346,25 @@ static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p
|
||||
return (2 * (p.x.size() + 1) + 1) * p.y.size();
|
||||
}
|
||||
|
||||
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
int destination)
|
||||
uint32_t stream_defoveator::shading_rate(int pixels_x, int pixels_y)
|
||||
{
|
||||
int x = 0;
|
||||
if (pixels_x >= 2)
|
||||
x = 1;
|
||||
if (pixels_x >= 4)
|
||||
x = 2;
|
||||
int y = 0;
|
||||
if (pixels_y >= 2)
|
||||
y = 1;
|
||||
if (pixels_y >= 4)
|
||||
y = 2;
|
||||
return fragment_sizes[x][y];
|
||||
}
|
||||
|
||||
void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
std::span<wivrn::blitter::output> inputs,
|
||||
int destination)
|
||||
{
|
||||
if (destination < 0 || destination >= (int)output_images.size())
|
||||
throw std::runtime_error("Invalid destination image index");
|
||||
@@ -401,6 +373,7 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
|
||||
for (size_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
const auto out_size = defoveated_size(foveation[view]);
|
||||
auto vertices = get_vertices(view);
|
||||
const auto & [px, py] = foveation[view];
|
||||
assert(px.size() % 2 == 1);
|
||||
@@ -408,67 +381,64 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
const int n_ratio_y = (py.size() - 1) / 2;
|
||||
const int n_ratio_x = (px.size() - 1) / 2;
|
||||
|
||||
glm::vec2 in(0), out(0); // pixel coordinates
|
||||
glm::vec2 in_pixel_size(1. / input_extent.width,
|
||||
1. / input_extent.height);
|
||||
glm::vec2 out_pixel_size(2. / output_extent.width,
|
||||
2. / output_extent.height);
|
||||
command_buffer.setScissor(
|
||||
0,
|
||||
vk::Rect2D{
|
||||
.extent = {.width = uint32_t(out_size.width), .height = uint32_t(out_size.height)},
|
||||
});
|
||||
command_buffer.setViewport(
|
||||
0,
|
||||
vk::Viewport{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = float(out_size.width),
|
||||
.height = float(out_size.height),
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
});
|
||||
|
||||
glm::uvec2 in(0);
|
||||
glm::vec2 out(-0.5 * out_size.width, -0.5 * out_size.height); // pixel coordinates
|
||||
glm::vec2 out_pixel_size(2. / out_size.width,
|
||||
2. / out_size.height);
|
||||
for (auto [iy, n_out_y]: utils::enumerate_range(py))
|
||||
{
|
||||
// number of output pixels per source pixels
|
||||
const int ratio_y = std::abs(n_ratio_y - int(iy)) + 1;
|
||||
in.x = 0;
|
||||
out.x = 0;
|
||||
out.x = -0.5 * out_size.width;
|
||||
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
||||
{
|
||||
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
|
||||
glm::uvec2 rate = glm::uvec2(shading_rate(ratio_x, ratio_y), 0);
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in | rate,
|
||||
};
|
||||
*vertices++ = {
|
||||
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size - glm::vec2(1),
|
||||
.uv = (in + glm::vec2(0, n_out_y)) * in_pixel_size,
|
||||
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size,
|
||||
.uv = (in + glm::uvec2(0, n_out_y)) | rate,
|
||||
};
|
||||
in.x += n_out_x;
|
||||
out.x += n_out_x * ratio_x;
|
||||
}
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
in.y += n_out_y;
|
||||
out.y += n_out_y * ratio_y;
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
command_buffer.pipelineBarrier(
|
||||
vk::PipelineStageFlagBits::eTopOfPipe,
|
||||
vk::PipelineStageFlagBits::eColorAttachmentOutput,
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
vk::ImageMemoryBarrier{
|
||||
.srcAccessMask = {},
|
||||
.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite,
|
||||
.oldLayout = vk::ImageLayout::eUndefined,
|
||||
.newLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
.image = output_images[destination],
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.levelCount = 1,
|
||||
.layerCount = view_count,
|
||||
},
|
||||
});
|
||||
|
||||
for (size_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
vk::RenderPassBeginInfo begin_info{
|
||||
@@ -480,9 +450,49 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
},
|
||||
};
|
||||
|
||||
const auto & input = inputs[view];
|
||||
auto & pipeline = ensure_pipeline(view, input.sampler_rgb, input.sampler_a);
|
||||
|
||||
std::array image_info{
|
||||
vk::DescriptorImageInfo{
|
||||
.sampler = input.sampler_rgb,
|
||||
.imageView = input.rgb,
|
||||
.imageLayout = input.layout_rgb,
|
||||
},
|
||||
vk::DescriptorImageInfo{
|
||||
.sampler = input.sampler_a,
|
||||
.imageView = input.a,
|
||||
.imageLayout = input.layout_a,
|
||||
},
|
||||
};
|
||||
|
||||
std::array descriptor_writes{
|
||||
vk::WriteDescriptorSet{
|
||||
.dstSet = pipeline.ds,
|
||||
.dstBinding = 0,
|
||||
.descriptorCount = input.sampler_a ? 2u : 1u,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = image_info.data(),
|
||||
},
|
||||
};
|
||||
|
||||
vert_pc pc{
|
||||
.rgb_rect = glm::ivec4(input.rect_rgb.offset.x,
|
||||
input.rect_rgb.offset.y,
|
||||
input.rect_rgb.extent.width,
|
||||
input.rect_rgb.extent.height),
|
||||
.a_rect = glm::ivec4(input.rect_a.offset.x,
|
||||
input.rect_a.offset.y,
|
||||
input.rect_a.extent.width,
|
||||
input.rect_a.extent.height),
|
||||
};
|
||||
|
||||
device.updateDescriptorSets(descriptor_writes, {});
|
||||
|
||||
command_buffer.beginRenderPass(begin_info, vk::SubpassContents::eInline);
|
||||
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *pipeline);
|
||||
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *layout, 0, descriptor_sets[view], {});
|
||||
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *pipeline.pipeline);
|
||||
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *pipeline.layout, 0, pipeline.ds, {});
|
||||
command_buffer.pushConstants<vert_pc>(*pipeline.layout, vk::ShaderStageFlagBits::eVertex, 0, pc);
|
||||
command_buffer.bindVertexBuffers(0, vk::Buffer(buffer), vertices_size * view);
|
||||
command_buffer.draw(required_vertices(foveation[view]), 1, 0, 0);
|
||||
command_buffer.endRenderPass();
|
||||
@@ -502,7 +512,7 @@ static uint16_t count_pixels(const std::vector<uint16_t> & param)
|
||||
return res;
|
||||
}
|
||||
|
||||
XrExtent2Di stream_reprojection::defoveated_size(const wivrn::to_headset::foveation_parameter & view) const
|
||||
XrExtent2Di stream_defoveator::defoveated_size(const wivrn::to_headset::foveation_parameter & view) const
|
||||
{
|
||||
return {
|
||||
count_pixels(view.x),
|
||||
@@ -19,34 +19,42 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "blitter.h"
|
||||
#include "vk/allocation.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
class stream_reprojection
|
||||
class stream_defoveator
|
||||
{
|
||||
struct vertex;
|
||||
const uint32_t view_count;
|
||||
static const uint32_t view_count = 2;
|
||||
// Vertex buffer
|
||||
buffer_allocation buffer;
|
||||
size_t vertices_size = 0;
|
||||
|
||||
vk::raii::Device & device;
|
||||
vk::raii::PhysicalDevice & physical_device;
|
||||
|
||||
// Graphic pipeline
|
||||
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
|
||||
vk::raii::DescriptorPool descriptor_pool = nullptr;
|
||||
vk::raii::PipelineLayout layout = nullptr;
|
||||
vk::raii::RenderPass renderpass = nullptr;
|
||||
vk::raii::Pipeline pipeline = nullptr;
|
||||
vk::raii::DescriptorPool ds_pool = nullptr;
|
||||
struct pipeline_t
|
||||
{
|
||||
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
|
||||
vk::DescriptorSet ds;
|
||||
vk::raii::PipelineLayout layout = nullptr;
|
||||
vk::raii::Pipeline pipeline = nullptr;
|
||||
};
|
||||
pipeline_t pipeline_rgb[view_count];
|
||||
pipeline_t pipeline_a[view_count];
|
||||
|
||||
// Source image
|
||||
vk::raii::Sampler sampler = nullptr;
|
||||
vk::Image input_image;
|
||||
std::vector<vk::raii::ImageView> input_image_views;
|
||||
std::vector<vk::DescriptorSet> descriptor_sets;
|
||||
vk::Extent2D input_extent;
|
||||
// Allowed sizes for variable shading rate
|
||||
// indices are for x, y
|
||||
// 0 is 1 pixel
|
||||
// 1 is 2 or 3 pixels
|
||||
// 2 is 4 pixels or more
|
||||
uint32_t fragment_sizes[3][3] = {};
|
||||
|
||||
// Destination images
|
||||
std::vector<vk::Image> output_images;
|
||||
@@ -57,22 +65,23 @@ class stream_reprojection
|
||||
void ensure_vertices(size_t num_vertices);
|
||||
vertex * get_vertices(size_t view);
|
||||
|
||||
uint32_t shading_rate(int pixels_x, int pixels_y);
|
||||
pipeline_t & ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a);
|
||||
|
||||
public:
|
||||
stream_reprojection(
|
||||
stream_defoveator(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
vk::Image input_image,
|
||||
vk::Extent2D input_extent,
|
||||
uint32_t view_count,
|
||||
std::vector<vk::Image> output_images,
|
||||
vk::Extent2D output_extent,
|
||||
vk::Format format);
|
||||
|
||||
stream_reprojection(const stream_reprojection &) = delete;
|
||||
stream_defoveator(const stream_defoveator &) = delete;
|
||||
|
||||
void reproject(
|
||||
void defoveate(
|
||||
vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
std::span<wivrn::blitter::output> inputs,
|
||||
int destination);
|
||||
|
||||
XrExtent2Di defoveated_size(const wivrn::to_headset::foveation_parameter &) const;
|
||||
@@ -1,179 +0,0 @@
|
||||
/*
|
||||
* Snapdragon™ Game Super Resolution
|
||||
* Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*
|
||||
* https://github.com/SnapdragonStudios/snapdragon-gsr
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#version 450
|
||||
|
||||
precision mediump float;
|
||||
precision highp int;
|
||||
|
||||
#define OperationMode 1
|
||||
|
||||
layout (constant_id = 0) const bool use_edge_direction = true;
|
||||
layout (constant_id = 1) const float edge_threshold = 4.0/255.0;
|
||||
layout (constant_id = 2) const float edge_sharpness = 2.0;
|
||||
|
||||
layout(set = 0, binding = 0) uniform mediump sampler2D texSampler;
|
||||
|
||||
layout(location = 0) in highp vec2 inUV;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
float fastLanczos2(float x)
|
||||
{
|
||||
float wA = x-4.0;
|
||||
float wB = x*wA-wA;
|
||||
wA *= wA;
|
||||
return wB*wA;
|
||||
}
|
||||
|
||||
vec2 weightY(float dx, float dy, float c, vec3 data)
|
||||
{
|
||||
float std = data.x;
|
||||
vec2 dir = data.yz;
|
||||
|
||||
float edgeDis = ((dx*dir.y)+(dy*dir.x));
|
||||
float x = (((dx*dx)+(dy*dy))+((edgeDis*edgeDis)*((clamp(((c*c)*std),0.0,1.0)*0.7)+-1.0)));
|
||||
|
||||
float w = fastLanczos2(x);
|
||||
return vec2(w, w * c);
|
||||
}
|
||||
|
||||
vec2 weightYned(float dx, float dy, float c, float std)
|
||||
{
|
||||
float x = ((dx*dx)+(dy* dy))* 0.55 + clamp(abs(c)*std, 0.0, 1.0);
|
||||
|
||||
float w = fastLanczos2(x);
|
||||
return vec2(w, w * c);
|
||||
}
|
||||
|
||||
vec2 edgeDirection(vec4 left, vec4 right)
|
||||
{
|
||||
vec2 dir;
|
||||
float RxLz = (right.x + (-left.z));
|
||||
float RwLy = (right.w + (-left.y));
|
||||
vec2 delta;
|
||||
delta.x = (RxLz + RwLy);
|
||||
delta.y = (RxLz + (-RwLy));
|
||||
float lengthInv = inversesqrt((delta.x * delta.x+ 3.075740e-05) + (delta.y * delta.y));
|
||||
dir.x = (delta.x * lengthInv);
|
||||
dir.y = (delta.y * lengthInv);
|
||||
return dir;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = textureLod(texSampler,inUV,0.0).xyzw;
|
||||
float alpha = color.a;
|
||||
|
||||
if (OperationMode == 1)
|
||||
color.a = 0.0;
|
||||
|
||||
if (OperationMode != 4)
|
||||
{
|
||||
vec2 dim = textureSize(texSampler, 0);
|
||||
vec4 viewportInfo = vec4(1/dim.x, 1/dim.y, dim.x, dim.y);
|
||||
|
||||
highp vec2 imgCoord = ((inUV.xy*viewportInfo.zw)+vec2(-0.5,0.5));
|
||||
highp vec2 imgCoordPixel = floor(imgCoord);
|
||||
highp vec2 coord = (imgCoordPixel*viewportInfo.xy);
|
||||
vec2 pl = (imgCoord+(-imgCoordPixel));
|
||||
vec4 left = textureGather(texSampler,coord, OperationMode);
|
||||
|
||||
float edgeVote = abs(left.z - left.y) + abs(color[OperationMode] - left.y) + abs(color[OperationMode] - left.z) ;
|
||||
if(edgeVote > edge_threshold)
|
||||
{
|
||||
coord.x += viewportInfo.x;
|
||||
|
||||
vec4 right = textureGather(texSampler,coord + vec2(viewportInfo.x, 0.0), OperationMode);
|
||||
vec4 upDown;
|
||||
upDown.xy = textureGather(texSampler,coord + vec2(0.0, -viewportInfo.y),OperationMode).wz;
|
||||
upDown.zw = textureGather(texSampler,coord + vec2(0.0, viewportInfo.y), OperationMode).yx;
|
||||
|
||||
float mean = (left.y+left.z+right.x+right.w)*0.25;
|
||||
left = left - vec4(mean);
|
||||
right = right - vec4(mean);
|
||||
upDown = upDown - vec4(mean);
|
||||
color.w =color[OperationMode] - mean;
|
||||
|
||||
float sum = (((((abs(left.x)+abs(left.y))+abs(left.z))+abs(left.w))+(((abs(right.x)+abs(right.y))+abs(right.z))+abs(right.w)))+(((abs(upDown.x)+abs(upDown.y))+abs(upDown.z))+abs(upDown.w)));
|
||||
float sumMean = 1.014185e+01/sum;
|
||||
float std = (sumMean*sumMean);
|
||||
|
||||
vec2 aWY;
|
||||
if (use_edge_direction) {
|
||||
vec3 data = vec3(std, edgeDirection(left, right));
|
||||
aWY = weightY(pl.x, pl.y+1.0, upDown.x,data);
|
||||
aWY += weightY(pl.x-1.0, pl.y+1.0, upDown.y,data);
|
||||
aWY += weightY(pl.x-1.0, pl.y-2.0, upDown.z,data);
|
||||
aWY += weightY(pl.x, pl.y-2.0, upDown.w,data);
|
||||
aWY += weightY(pl.x+1.0, pl.y-1.0, left.x,data);
|
||||
aWY += weightY(pl.x, pl.y-1.0, left.y,data);
|
||||
aWY += weightY(pl.x, pl.y, left.z,data);
|
||||
aWY += weightY(pl.x+1.0, pl.y, left.w,data);
|
||||
aWY += weightY(pl.x-1.0, pl.y-1.0, right.x,data);
|
||||
aWY += weightY(pl.x-2.0, pl.y-1.0, right.y,data);
|
||||
aWY += weightY(pl.x-2.0, pl.y, right.z,data);
|
||||
aWY += weightY(pl.x-1.0, pl.y, right.w,data);
|
||||
} else {
|
||||
aWY = weightYned(pl.x, pl.y+1.0, upDown.x,std);
|
||||
aWY += weightYned(pl.x-1.0, pl.y+1.0, upDown.y,std);
|
||||
aWY += weightYned(pl.x-1.0, pl.y-2.0, upDown.z,std);
|
||||
aWY += weightYned(pl.x, pl.y-2.0, upDown.w,std);
|
||||
aWY += weightYned(pl.x+1.0, pl.y-1.0, left.x,std);
|
||||
aWY += weightYned(pl.x, pl.y-1.0, left.y,std);
|
||||
aWY += weightYned(pl.x, pl.y, left.z,std);
|
||||
aWY += weightYned(pl.x+1.0, pl.y, left.w,std);
|
||||
aWY += weightYned(pl.x-1.0, pl.y-1.0, right.x,std);
|
||||
aWY += weightYned(pl.x-2.0, pl.y-1.0, right.y,std);
|
||||
aWY += weightYned(pl.x-2.0, pl.y, right.z,std);
|
||||
aWY += weightYned(pl.x-1.0, pl.y, right.w,std);
|
||||
}
|
||||
|
||||
float finalY = aWY.y/aWY.x;
|
||||
float maxY = max(max(left.y,left.z),max(right.x,right.w));
|
||||
float minY = min(min(left.y,left.z),min(right.x,right.w));
|
||||
float deltaY = clamp(edge_sharpness*finalY, minY, maxY) -color.w;
|
||||
|
||||
//smooth high contrast input
|
||||
deltaY = clamp(deltaY, -23.0 / 255.0, 23.0 / 255.0);
|
||||
|
||||
color.x = clamp((color.x+deltaY),0.0,1.0);
|
||||
color.y = clamp((color.y+deltaY),0.0,1.0);
|
||||
color.z = clamp((color.z+deltaY),0.0,1.0);
|
||||
}
|
||||
}
|
||||
|
||||
outColor = vec4(color.rgb, alpha);
|
||||
}
|
||||
@@ -45,40 +45,16 @@ void main()
|
||||
|
||||
#ifdef FRAG_SHADER
|
||||
layout(binding = 0) uniform sampler2D texSampler;
|
||||
layout(constant_id = 0) const bool do_srgb = true;
|
||||
layout(constant_id = 1) const bool is_alpha = false;
|
||||
layout(constant_id = 0) const bool is_alpha = false;
|
||||
|
||||
layout(location = 0) in vec2 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.r);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
if (do_srgb)
|
||||
{
|
||||
outColor = sRGB_to_linear_rgba(texture(texSampler, inUV));
|
||||
}
|
||||
else
|
||||
{
|
||||
outColor = texture(texSampler, inUV);
|
||||
outColor.a = outColor.r;
|
||||
}
|
||||
outColor = texture(texSampler, inUV);
|
||||
outColor.a = outColor.r;
|
||||
if (!is_alpha)
|
||||
{
|
||||
outColor.a = 1;
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2024 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 "i18n.h"
|
||||
|
||||
#include "asset.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
extern std::map<std::string, std::vector<int>> glyph_set_per_language;
|
||||
|
||||
std::vector<boost::locale::gnu_gettext::messages_info> get_locales()
|
||||
{
|
||||
boost::locale::gnu_gettext::messages_info messages_info;
|
||||
messages_info.paths.push_back("locale");
|
||||
messages_info.encoding = "UTF-8";
|
||||
|
||||
messages_info.domains.push_back(boost::locale::gnu_gettext::messages_info::domain("wivrn"));
|
||||
messages_info.callback = open_locale_file;
|
||||
std::vector<boost::locale::gnu_gettext::messages_info> res;
|
||||
|
||||
messages_info.language = "en";
|
||||
messages_info.country = "US";
|
||||
res.push_back(messages_info);
|
||||
|
||||
for (const auto & [code, glyphs]: glyph_set_per_language)
|
||||
{
|
||||
auto pos = code.find("_");
|
||||
messages_info.language = code.substr(0, pos);
|
||||
if (pos == std::string::npos)
|
||||
messages_info.country = "";
|
||||
else
|
||||
messages_info.country = code.substr(pos + 1);
|
||||
res.push_back(messages_info);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<char> open_locale_file(const std::string & file_name, const std::string & encoding)
|
||||
{
|
||||
std::vector<char> buffer;
|
||||
try
|
||||
{
|
||||
asset file(file_name);
|
||||
buffer.resize(file.size());
|
||||
memcpy(buffer.data(), file.data(), file.size());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
@@ -23,3 +23,6 @@
|
||||
#define _F(x) fmt::runtime(boost::locale::gettext(x))
|
||||
#define _S(x) boost::locale::gettext(x).c_str()
|
||||
#define _cS(c, x) boost::locale::pgettext(c, x).c_str()
|
||||
|
||||
std::vector<boost::locale::gnu_gettext::messages_info> get_locales();
|
||||
std::vector<char> open_locale_file(const std::string & file_name, const std::string & encoding);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "renderdoc.h"
|
||||
#include "renderdoc_app.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <iostream>
|
||||
|
||||
static RENDERDOC_API_1_0_0 * renderdoc_init()
|
||||
{
|
||||
RENDERDOC_API_1_0_0 * renderdoc_api = nullptr;
|
||||
auto renderdoc_module = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD);
|
||||
if (not renderdoc_module)
|
||||
return nullptr;
|
||||
auto * func = reinterpret_cast<pRENDERDOC_GetAPI>(dlsym(renderdoc_module, "RENDERDOC_GetAPI"));
|
||||
if (!func)
|
||||
{
|
||||
std::cerr << "Failed to load RENDERDOC_GetAPI function." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
if (!func(eRENDERDOC_API_Version_1_0_0, reinterpret_cast<void **>(&renderdoc_api)))
|
||||
{
|
||||
std::cerr << "Failed to obtain RenderDoc 1.0.0 API." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int major, minor, patch;
|
||||
renderdoc_api->GetAPIVersion(&major, &minor, &patch);
|
||||
return renderdoc_api;
|
||||
}
|
||||
|
||||
static RENDERDOC_API_1_0_0 * get_renderdoc()
|
||||
{
|
||||
static RENDERDOC_API_1_0_0 * renderdoc_api = renderdoc_init();
|
||||
return renderdoc_api;
|
||||
}
|
||||
|
||||
void wivrn::renderdoc_begin(VkInstance inst)
|
||||
{
|
||||
if (auto renderdoc_api = get_renderdoc())
|
||||
renderdoc_api->StartFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(inst), nullptr);
|
||||
}
|
||||
void wivrn::renderdoc_end(VkInstance inst)
|
||||
{
|
||||
if (auto renderdoc_api = get_renderdoc())
|
||||
renderdoc_api->EndFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(inst), nullptr);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#include <vulkan/vulkan.h>
|
||||
namespace wivrn
|
||||
{
|
||||
void renderdoc_begin(VkInstance);
|
||||
void renderdoc_end(VkInstance);
|
||||
} // namespace wivrn
|
||||
@@ -18,12 +18,13 @@
|
||||
*/
|
||||
|
||||
#include "shader.h"
|
||||
#include "wivrn_shaders.h"
|
||||
|
||||
vk::raii::ShaderModule load_shader(vk::raii::Device & device, const std::vector<uint32_t> & spirv)
|
||||
{
|
||||
vk::ShaderModuleCreateInfo create_info{
|
||||
.codeSize = spirv.size() * sizeof(uint32_t),
|
||||
.pCode = data(spirv),
|
||||
.pCode = spirv.data(),
|
||||
};
|
||||
|
||||
return vk::raii::ShaderModule{device, create_info};
|
||||
|
||||
@@ -19,12 +19,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
extern const std::map<std::string, std::vector<uint32_t>> shaders;
|
||||
|
||||
vk::raii::ShaderModule load_shader(vk::raii::Device & device, const std::vector<uint32_t> & spirv);
|
||||
vk::raii::ShaderModule load_shader(vk::raii::Device & device, const std::string & name);
|
||||
|
||||
+88
-16
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user