Merge branch 'WiVRn:master' into sneed
This commit is contained in:
@@ -727,7 +727,7 @@ void scenes::lobby::gui_settings()
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
{
|
||||
ImGui::BeginDisabled(not(application::get_fb_face_tracking2_supported() or application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported()));
|
||||
ImGui::BeginDisabled(not(application::get_fb_face_tracking2_supported() or application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported() or application::get_pico_face_tracking_supported()));
|
||||
bool enabled = config.check_feature(feature::face_tracking);
|
||||
if (ImGui::Checkbox(_S("Enable face tracking"), &enabled))
|
||||
{
|
||||
@@ -740,6 +740,58 @@ void scenes::lobby::gui_settings()
|
||||
vibrate_on_hover();
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::BeginDisabled(not(application::get_fb_body_tracking_supported() or application::get_pico_body_tracking_supported()));
|
||||
bool enabled = config.check_feature(feature::body_tracking);
|
||||
if (ImGui::Checkbox(_S("Enable body tracking"), &enabled))
|
||||
{
|
||||
config.set_feature(feature::body_tracking, enabled);
|
||||
config.save();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
|
||||
{
|
||||
if (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled)
|
||||
{
|
||||
tooltip(_("This feature is not supported by your headset"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (application::get_fb_body_tracking_supported())
|
||||
tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions"));
|
||||
else if (application::get_pico_body_tracking_supported())
|
||||
tooltip(_("Uses the Pico Motion Trackers to track body joint positions"));
|
||||
}
|
||||
}
|
||||
|
||||
vibrate_on_hover();
|
||||
}
|
||||
if (application::get_fb_body_tracking_supported())
|
||||
{
|
||||
ImGui::BeginDisabled(not config.check_feature(feature::body_tracking));
|
||||
ImGui::Indent();
|
||||
if (ImGui::Checkbox(_S("Enable lower body tracking"), &config.fb_lower_body))
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
tooltip(_("Estimate lower body joint positions using Generative Legs\nRequires 'Hand and body tracking' to be enabled in the Quest movement tracking settings"));
|
||||
|
||||
ImGui::BeginDisabled(not config.fb_lower_body);
|
||||
if (ImGui::Checkbox(_S("Enable hip tracking"), &config.fb_hip))
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
tooltip(_("Only takes affect with lower body tracking enabled\nMay be desired when using another source of hip tracking"));
|
||||
ImGui::EndDisabled();
|
||||
|
||||
ImGui::Unindent();
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
|
||||
ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough);
|
||||
if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled))
|
||||
{
|
||||
@@ -1422,7 +1474,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
});
|
||||
}
|
||||
|
||||
if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported())
|
||||
if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported() or application::get_pico_face_tracking_supported())
|
||||
{
|
||||
items.push_back({
|
||||
.f = feature::face_tracking,
|
||||
@@ -1433,6 +1485,16 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
});
|
||||
}
|
||||
|
||||
if (application::get_fb_body_tracking_supported() or application::get_pico_body_tracking_supported())
|
||||
{
|
||||
items.push_back({
|
||||
.f = feature::body_tracking,
|
||||
.tooltip_enabled = _("Body tracking is enabled"),
|
||||
.tooltip_disabled = _("Body tracking is disabled"),
|
||||
.icon_enabled = ICON_FA_PERSON,
|
||||
});
|
||||
}
|
||||
|
||||
// Get statuses
|
||||
for (auto & i: items)
|
||||
{
|
||||
@@ -1459,7 +1521,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
if (&i != &items.front())
|
||||
ImGui::SameLine();
|
||||
auto pos = ImGui::GetCursorPos();
|
||||
if (ImGui::Button(i.enabled ? i.icon_enabled : i.icon_disabled))
|
||||
if (ImGui::Button(fmt::format("{}##{}", i.enabled ? i.icon_enabled : i.icon_disabled, i.icon_enabled).c_str()))
|
||||
{
|
||||
// button doesn't alter the bool
|
||||
config.set_feature(i.f, not i.enabled);
|
||||
|
||||
+33
-10
@@ -17,6 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "utils/overloaded.h"
|
||||
#include "xr/fb_body_tracker.h"
|
||||
#define GLM_FORCE_RADIANS
|
||||
|
||||
#include "stream.h"
|
||||
@@ -220,6 +221,17 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
info.face_tracking = from_headset::face_type::fb2;
|
||||
else if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported())
|
||||
info.face_tracking = from_headset::face_type::htc;
|
||||
else if (application::get_pico_face_tracking_supported())
|
||||
info.face_tracking = from_headset::face_type::pico;
|
||||
}
|
||||
|
||||
info.num_generic_trackers = 0;
|
||||
if (config.check_feature(feature::body_tracking))
|
||||
{
|
||||
if (application::get_fb_body_tracking_supported())
|
||||
info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size();
|
||||
else if (application::get_pico_body_tracking_supported())
|
||||
info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size();
|
||||
}
|
||||
|
||||
info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right);
|
||||
@@ -858,10 +870,16 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
}
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
|
||||
reprojector->set_foveation(foveation);
|
||||
|
||||
// Unfoveate the image to the real pose
|
||||
reprojector->reproject(command_buffer, image_index);
|
||||
// defoveate the image
|
||||
auto extents = reprojector->reproject(command_buffer, foveation, image_index);
|
||||
for (size_t i = 0; i < view_count; ++i)
|
||||
{
|
||||
extents[i] = {
|
||||
.width = std::min(extents[i].width, swapchain.width()),
|
||||
.height = std::min(extents[i].height, swapchain.height()),
|
||||
};
|
||||
}
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
|
||||
|
||||
@@ -906,10 +924,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
.swapchain = swapchain,
|
||||
.imageRect = {
|
||||
.offset = {0, 0},
|
||||
.extent = {
|
||||
swapchain.width(),
|
||||
swapchain.height(),
|
||||
},
|
||||
.extent = extents[view],
|
||||
},
|
||||
.imageArrayIndex = view,
|
||||
},
|
||||
@@ -1159,8 +1174,8 @@ void scenes::stream::setup_reprojection_swapchain()
|
||||
|
||||
const uint32_t video_width = video_stream_description->width / view_count;
|
||||
const uint32_t video_height = video_stream_description->height;
|
||||
uint32_t swapchain_width = video_width / video_stream_description->foveation[0].x.scale;
|
||||
uint32_t swapchain_height = video_height / video_stream_description->foveation[0].y.scale;
|
||||
uint32_t swapchain_width = video_stream_description->defoveated_width / view_count;
|
||||
uint32_t swapchain_height = video_stream_description->defoveated_height;
|
||||
|
||||
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
|
||||
if (sgsr.enabled)
|
||||
@@ -1187,7 +1202,15 @@ void scenes::stream::setup_reprojection_swapchain()
|
||||
for (auto & image: swapchain.images())
|
||||
swapchain_images.push_back(image.image);
|
||||
|
||||
reprojector.emplace(device, physical_device, decoder_out_image, 2, swapchain_images, extent, swapchain.format(), *video_stream_description);
|
||||
reprojector.emplace(
|
||||
device,
|
||||
physical_device,
|
||||
decoder_out_image,
|
||||
vk::Extent2D{.width = video_width, .height = video_height},
|
||||
2,
|
||||
swapchain_images,
|
||||
extent,
|
||||
swapchain.format());
|
||||
}
|
||||
|
||||
scene::meta & scenes::stream::get_meta_scene()
|
||||
|
||||
@@ -20,30 +20,24 @@
|
||||
#include "stream_reprojection.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 <array>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <vk_mem_alloc.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
namespace
|
||||
struct stream_reprojection::vertex
|
||||
{
|
||||
struct uniform
|
||||
{
|
||||
// Foveation parameters
|
||||
alignas(8) glm::vec2 a;
|
||||
alignas(8) glm::vec2 b;
|
||||
alignas(8) glm::vec2 lambda;
|
||||
alignas(8) glm::vec2 xc;
|
||||
// output image position
|
||||
alignas(8) glm::vec2 position;
|
||||
// input texture coordinates
|
||||
alignas(8) glm::vec2 uv;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
const int nb_reprojection_vertices = 128;
|
||||
|
||||
struct SgsrSpecializationConstants
|
||||
{
|
||||
@@ -52,24 +46,47 @@ struct SgsrSpecializationConstants
|
||||
float edge_sharpness;
|
||||
};
|
||||
|
||||
void stream_reprojection::ensure_vertices(size_t num_vertices)
|
||||
{
|
||||
vk::BufferCreateInfo create_info{
|
||||
.size = num_vertices * sizeof(vertex) * view_count,
|
||||
.usage = vk::BufferUsageFlagBits::eVertexBuffer,
|
||||
.sharingMode = vk::SharingMode::eExclusive,
|
||||
};
|
||||
|
||||
if (create_info.size <= buffer.info().size)
|
||||
return;
|
||||
|
||||
VmaAllocationCreateInfo alloc_info{
|
||||
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||
};
|
||||
|
||||
buffer = buffer_allocation(device, create_info, alloc_info);
|
||||
vertices_size = num_vertices * sizeof(vertex);
|
||||
}
|
||||
|
||||
stream_reprojection::vertex * stream_reprojection::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 extent,
|
||||
vk::Format format,
|
||||
const wivrn::to_headset::video_stream_description & description) :
|
||||
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_)),
|
||||
extent(extent)
|
||||
output_extent(output_extent)
|
||||
{
|
||||
foveation_parameters = description.foveation;
|
||||
|
||||
vk::PhysicalDeviceProperties properties = physical_device.getProperties();
|
||||
|
||||
vk::SamplerCreateInfo sampler_info{
|
||||
.magFilter = vk::Filter::eLinear,
|
||||
.minFilter = vk::Filter::eLinear,
|
||||
@@ -93,35 +110,12 @@ stream_reprojection::stream_reprojection(
|
||||
|
||||
sampler = vk::raii::Sampler(device, sampler_info);
|
||||
|
||||
uniform_size = sizeof(uniform) + properties.limits.minUniformBufferOffsetAlignment - 1;
|
||||
uniform_size = uniform_size - uniform_size % properties.limits.minUniformBufferOffsetAlignment;
|
||||
|
||||
vk::BufferCreateInfo create_info{
|
||||
.size = uniform_size * view_count,
|
||||
.usage = vk::BufferUsageFlagBits::eUniformBuffer,
|
||||
.sharingMode = vk::SharingMode::eExclusive,
|
||||
};
|
||||
|
||||
VmaAllocationCreateInfo alloc_info{
|
||||
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||
};
|
||||
|
||||
buffer = buffer_allocation(device, create_info, alloc_info);
|
||||
|
||||
// Create VkDescriptorSetLayout
|
||||
std::array layout_binding{
|
||||
vk::DescriptorSetLayoutBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
},
|
||||
vk::DescriptorSetLayoutBinding{
|
||||
.binding = 1,
|
||||
.descriptorType = vk::DescriptorType::eUniformBuffer,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
|
||||
},
|
||||
vk::DescriptorSetLayoutBinding layout_binding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
};
|
||||
|
||||
vk::DescriptorSetLayoutCreateInfo layout_info;
|
||||
@@ -134,10 +128,6 @@ stream_reprojection::stream_reprojection(
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = (uint32_t)view_count,
|
||||
},
|
||||
vk::DescriptorPoolSize{
|
||||
.type = vk::DescriptorType::eUniformBuffer,
|
||||
.descriptorCount = (uint32_t)view_count,
|
||||
},
|
||||
};
|
||||
|
||||
vk::DescriptorPoolCreateInfo pool_info{
|
||||
@@ -153,7 +143,7 @@ stream_reprojection::stream_reprojection(
|
||||
{
|
||||
vk::ImageViewCreateInfo iv_info{
|
||||
.image = input_image,
|
||||
.viewType = vk::ImageViewType::e2DArray,
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.components = {
|
||||
.r = vk::ComponentSwizzle::eIdentity,
|
||||
@@ -186,13 +176,7 @@ stream_reprojection::stream_reprojection(
|
||||
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
vk::DescriptorBufferInfo buffer_info{
|
||||
.buffer = buffer,
|
||||
.offset = uniform_size * view,
|
||||
.range = sizeof(uniform),
|
||||
};
|
||||
|
||||
std::array write{
|
||||
device.updateDescriptorSets(
|
||||
vk::WriteDescriptorSet{
|
||||
.dstSet = descriptor_set,
|
||||
.dstBinding = 0,
|
||||
@@ -201,17 +185,7 @@ stream_reprojection::stream_reprojection(
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = &image_info,
|
||||
},
|
||||
vk::WriteDescriptorSet{
|
||||
.dstSet = descriptor_set,
|
||||
.dstBinding = 1,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vk::DescriptorType::eUniformBuffer,
|
||||
.pBufferInfo = &buffer_info,
|
||||
},
|
||||
};
|
||||
|
||||
device.updateDescriptorSets(write, {});
|
||||
{});
|
||||
}
|
||||
|
||||
// Create renderpass
|
||||
@@ -248,40 +222,6 @@ stream_reprojection::stream_reprojection(
|
||||
// Vertex shader
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert");
|
||||
|
||||
int vertex_specialization_constants[] = {
|
||||
foveation_parameters[0].x.scale < 1,
|
||||
foveation_parameters[0].y.scale < 1,
|
||||
nb_reprojection_vertices,
|
||||
nb_reprojection_vertices,
|
||||
};
|
||||
|
||||
std::array vertex_specialization_constants_desc{
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 0,
|
||||
.offset = 0,
|
||||
.size = sizeof(int),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 1,
|
||||
.offset = sizeof(int),
|
||||
.size = sizeof(int),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 2,
|
||||
.offset = 2 * sizeof(int),
|
||||
.size = sizeof(int),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 3,
|
||||
.offset = 3 * sizeof(int),
|
||||
.size = sizeof(int),
|
||||
},
|
||||
};
|
||||
|
||||
vk::SpecializationInfo vertex_specialization_info;
|
||||
vertex_specialization_info.setMapEntries(vertex_specialization_constants_desc);
|
||||
vertex_specialization_info.setData<int>(vertex_specialization_constants);
|
||||
|
||||
// Fragment shader
|
||||
std::string fragment_shader_name = "reprojection.frag";
|
||||
|
||||
@@ -337,7 +277,6 @@ stream_reprojection::stream_reprojection(
|
||||
.stage = vk::ShaderStageFlagBits::eVertex,
|
||||
.module = *vertex_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = &vertex_specialization_info,
|
||||
},
|
||||
{
|
||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||
@@ -346,22 +285,41 @@ stream_reprojection::stream_reprojection(
|
||||
.pSpecializationInfo = &fragment_specialization_info,
|
||||
},
|
||||
},
|
||||
.VertexBindingDescriptions = {},
|
||||
.VertexAttributeDescriptions = {},
|
||||
.VertexBindingDescriptions = {
|
||||
{
|
||||
.binding = 0,
|
||||
.stride = sizeof(vertex),
|
||||
.inputRate = vk::VertexInputRate::eVertex,
|
||||
},
|
||||
},
|
||||
.VertexAttributeDescriptions = {
|
||||
{
|
||||
.location = 0,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32G32Sfloat,
|
||||
.offset = offsetof(vertex, position),
|
||||
},
|
||||
{
|
||||
.location = 1,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32G32Sfloat,
|
||||
.offset = offsetof(vertex, uv),
|
||||
},
|
||||
},
|
||||
.InputAssemblyState = {{
|
||||
.topology = vk::PrimitiveTopology::eTriangleList,
|
||||
.topology = vk::PrimitiveTopology::eTriangleStrip,
|
||||
}},
|
||||
.Viewports = {{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = (float)extent.width,
|
||||
.height = (float)extent.height,
|
||||
.width = (float)output_extent.width,
|
||||
.height = (float)output_extent.height,
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
}},
|
||||
.Scissors = {{
|
||||
.offset = {.x = 0, .y = 0},
|
||||
.extent = extent,
|
||||
.extent = output_extent,
|
||||
}},
|
||||
.RasterizationState = {{
|
||||
.polygonMode = vk::PolygonMode::eFill,
|
||||
@@ -411,8 +369,8 @@ stream_reprojection::stream_reprojection(
|
||||
|
||||
vk::FramebufferCreateInfo fb_create_info{
|
||||
.renderPass = *renderpass,
|
||||
.width = extent.width,
|
||||
.height = extent.height,
|
||||
.width = output_extent.width,
|
||||
.height = output_extent.height,
|
||||
.layers = 1,
|
||||
};
|
||||
fb_create_info.setAttachments(*output_image_views.back());
|
||||
@@ -422,28 +380,82 @@ stream_reprojection::stream_reprojection(
|
||||
}
|
||||
}
|
||||
|
||||
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, int destination)
|
||||
static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p)
|
||||
{
|
||||
// strips are constructed like this:
|
||||
// 0 2 4
|
||||
// 1 3 5 5*
|
||||
// there is one such line per value in y
|
||||
// the last element is repeated to break the line
|
||||
return (2 * (p.x.size() + 1) + 1) * p.y.size();
|
||||
}
|
||||
|
||||
std::vector<XrExtent2Di> stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
int destination)
|
||||
{
|
||||
if (destination < 0 || destination >= (int)output_images.size())
|
||||
throw std::runtime_error("Invalid destination image index");
|
||||
|
||||
ensure_vertices(std::max(required_vertices(foveation[0]), required_vertices(foveation[1])));
|
||||
std::vector<XrExtent2Di> out_extents(view_count, XrExtent2Di{});
|
||||
|
||||
for (size_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
auto & ubo = *reinterpret_cast<uniform *>(reinterpret_cast<uintptr_t>(buffer.map()) + view * uniform_size);
|
||||
if (foveation_parameters[view].x.scale < 1)
|
||||
auto vertices = get_vertices(view);
|
||||
const auto & [px, py] = foveation[view];
|
||||
assert(px.size() % 2 == 1);
|
||||
assert(py.size() % 2 == 1);
|
||||
const int n_ratio_y = (py.size() - 1) / 2;
|
||||
const int n_ratio_x = (px.size() - 1) / 2;
|
||||
|
||||
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
||||
{
|
||||
ubo.a.x = foveation_parameters[view].x.a;
|
||||
ubo.b.x = foveation_parameters[view].x.b;
|
||||
ubo.lambda.x = foveation_parameters[view].x.scale / foveation_parameters[view].x.a;
|
||||
ubo.xc.x = foveation_parameters[view].x.center;
|
||||
// number of output pixels per source pixels
|
||||
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
|
||||
out_extents[view].width += ratio_x * n_out_x;
|
||||
}
|
||||
|
||||
if (foveation_parameters[view].y.scale < 1)
|
||||
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);
|
||||
for (auto [iy, n_out_y]: utils::enumerate_range(py))
|
||||
{
|
||||
ubo.a.y = foveation_parameters[view].y.a;
|
||||
ubo.b.y = foveation_parameters[view].y.b;
|
||||
ubo.lambda.y = foveation_parameters[view].y.scale / foveation_parameters[view].y.a;
|
||||
ubo.xc.y = foveation_parameters[view].y.center;
|
||||
// number of output pixels per source pixels
|
||||
const int ratio_y = std::abs(n_ratio_y - int(iy)) + 1;
|
||||
out_extents[view].height += ratio_y * n_out_y;
|
||||
in.x = 0;
|
||||
out.x = 0;
|
||||
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
||||
{
|
||||
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
};
|
||||
*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,
|
||||
};
|
||||
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,
|
||||
};
|
||||
*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,
|
||||
};
|
||||
*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,
|
||||
};
|
||||
in.y += n_out_y;
|
||||
out.y += n_out_y * ratio_y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,19 +485,16 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, in
|
||||
.framebuffer = *framebuffers[destination * view_count + view],
|
||||
.renderArea = {
|
||||
.offset = {0, 0},
|
||||
.extent = extent,
|
||||
.extent = output_extent,
|
||||
},
|
||||
};
|
||||
|
||||
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.draw(6 * nb_reprojection_vertices * nb_reprojection_vertices, 1, 0, 0);
|
||||
command_buffer.bindVertexBuffers(0, vk::Buffer(buffer), vertices_size * view);
|
||||
command_buffer.draw(required_vertices(foveation[view]), 1, 0, 0);
|
||||
command_buffer.endRenderPass();
|
||||
}
|
||||
}
|
||||
|
||||
void stream_reprojection::set_foveation(std::array<wivrn::to_headset::foveation_parameter, 2> foveation)
|
||||
{
|
||||
foveation_parameters = foveation;
|
||||
return out_extents;
|
||||
}
|
||||
|
||||
@@ -26,10 +26,13 @@
|
||||
|
||||
class stream_reprojection
|
||||
{
|
||||
struct vertex;
|
||||
const uint32_t view_count;
|
||||
// Uniform buffer
|
||||
// Vertex buffer
|
||||
buffer_allocation buffer;
|
||||
size_t uniform_size;
|
||||
size_t vertices_size = 0;
|
||||
|
||||
vk::raii::Device & device;
|
||||
|
||||
// Graphic pipeline
|
||||
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
|
||||
@@ -43,32 +46,32 @@ class stream_reprojection
|
||||
vk::Image input_image;
|
||||
std::vector<vk::raii::ImageView> input_image_views;
|
||||
std::vector<vk::DescriptorSet> descriptor_sets;
|
||||
vk::Extent2D input_extent;
|
||||
|
||||
// Destination images
|
||||
std::vector<vk::Image> output_images;
|
||||
std::vector<vk::raii::ImageView> output_image_views;
|
||||
std::vector<vk::raii::Framebuffer> framebuffers;
|
||||
vk::Extent2D extent;
|
||||
vk::Extent2D output_extent;
|
||||
|
||||
// Foveation
|
||||
std::array<wivrn::to_headset::foveation_parameter, 2> foveation_parameters;
|
||||
void ensure_vertices(size_t num_vertices);
|
||||
vertex * get_vertices(size_t view);
|
||||
|
||||
public:
|
||||
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 extent,
|
||||
vk::Format format,
|
||||
const wivrn::to_headset::video_stream_description & description);
|
||||
vk::Extent2D output_extent,
|
||||
vk::Format format);
|
||||
|
||||
stream_reprojection(const stream_reprojection &) = delete;
|
||||
|
||||
void reproject(
|
||||
std::vector<XrExtent2Di> reproject(
|
||||
vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
int destination);
|
||||
|
||||
void set_foveation(std::array<wivrn::to_headset::foveation_parameter, 2> foveation);
|
||||
};
|
||||
|
||||
@@ -232,9 +232,11 @@ void scenes::stream::tracking()
|
||||
|
||||
XrTime t0 = instance.now();
|
||||
XrTime last_hand_sample = t0;
|
||||
XrTime last_body_sample = t0;
|
||||
std::vector<from_headset::tracking> tracking;
|
||||
std::vector<from_headset::tracking> tracking_pool; // pre-allocated objects
|
||||
std::vector<from_headset::hand_tracking> hands;
|
||||
std::vector<from_headset::body_tracking> body;
|
||||
std::vector<XrView> views;
|
||||
|
||||
std::vector<from_headset::trackings> merged_tracking;
|
||||
@@ -248,6 +250,36 @@ void scenes::stream::tracking()
|
||||
face_tracking = from_headset::face_type::fb2;
|
||||
else if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported())
|
||||
face_tracking = from_headset::face_type::htc;
|
||||
else if (application::get_pico_face_tracking_supported())
|
||||
{
|
||||
face_tracking = from_headset::face_type::pico;
|
||||
// We can't start the face tracking on application initialisation like we do for
|
||||
// other face trackers due to a Pico runtime bug where face tracking freezes when
|
||||
// the headset is taken off or the application is quit.
|
||||
application::get_pico_face_tracker().start();
|
||||
}
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
body_none,
|
||||
body_fb,
|
||||
body_pico,
|
||||
} body_tracking = body_none;
|
||||
|
||||
if (config.check_feature(feature::body_tracking))
|
||||
{
|
||||
if (application::get_fb_body_tracking_supported())
|
||||
{
|
||||
body_tracking = body_fb;
|
||||
// TODO maybe handle reconnection better, if the settings are changed since
|
||||
// last connection to running server, the tracker count will mismatch and
|
||||
// stuff might break
|
||||
application::get_fb_body_tracker().stop();
|
||||
application::get_fb_body_tracker().start(config.fb_lower_body, config.fb_hip);
|
||||
}
|
||||
else if (application::get_pico_body_tracking_supported())
|
||||
body_tracking = body_pico;
|
||||
}
|
||||
|
||||
on_interaction_profile_changed({});
|
||||
@@ -258,6 +290,7 @@ void scenes::stream::tracking()
|
||||
{
|
||||
tracking.clear();
|
||||
hands.clear();
|
||||
body.clear();
|
||||
|
||||
XrTime now = instance.now();
|
||||
if (now < t0)
|
||||
@@ -327,6 +360,30 @@ void scenes::stream::tracking()
|
||||
locate_hands(application::get_right_hand(), world_space, t0 + Δt));
|
||||
}
|
||||
|
||||
if (body_tracking != body_none and t0 >= last_body_sample + period and
|
||||
(Δt == 0 or Δt >= prediction - 2 * period))
|
||||
{
|
||||
last_body_sample = t0;
|
||||
if (control.enabled[size_t(tid::generic_tracker)])
|
||||
{
|
||||
auto & body_packet = body.emplace_back(from_headset::body_tracking{
|
||||
.production_timestamp = t0,
|
||||
.timestamp = t0 + Δt,
|
||||
});
|
||||
switch (body_tracking)
|
||||
{
|
||||
case body_none:
|
||||
__builtin_unreachable();
|
||||
case body_fb:
|
||||
body_packet.poses = application::get_fb_body_tracker().locate_spaces(t0 + Δt, world_space);
|
||||
break;
|
||||
case body_pico:
|
||||
body_packet.poses = application::get_pico_body_tracker().locate_spaces(t0 + Δt, world_space);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (control.enabled[size_t(tid::face)])
|
||||
{
|
||||
switch (face_tracking)
|
||||
@@ -334,10 +391,10 @@ void scenes::stream::tracking()
|
||||
case wivrn::from_headset::face_type::none:
|
||||
break;
|
||||
case wivrn::from_headset::face_type::fb2:
|
||||
application::get_fb_face_tracker2().get_weights(t0 + Δt, packet.face.emplace());
|
||||
application::get_fb_face_tracker2().get_weights(t0 + Δt, packet.face.emplace<wivrn::from_headset::tracking::fb_face2>());
|
||||
break;
|
||||
case wivrn::from_headset::face_type::htc:
|
||||
auto & face_htc = packet.face_htc.emplace();
|
||||
case wivrn::from_headset::face_type::htc: {
|
||||
auto & face_htc = packet.face.emplace<wivrn::from_headset::tracking::htc_face>();
|
||||
face_htc.eye_active = false;
|
||||
face_htc.lip_active = false;
|
||||
if (application::get_htc_face_tracking_eye_supported())
|
||||
@@ -345,6 +402,10 @@ void scenes::stream::tracking()
|
||||
if (application::get_htc_face_tracking_lip_supported())
|
||||
application::get_htc_face_tracker_lip().get_weights(t0 + Δt, face_htc);
|
||||
break;
|
||||
}
|
||||
case wivrn::from_headset::face_type::pico:
|
||||
application::get_pico_face_tracker().get_weights(t0 + Δt, packet.face.emplace<wivrn::from_headset::tracking::fb_face2>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -396,7 +457,7 @@ void scenes::stream::tracking()
|
||||
merged_tracking.back().items.emplace_back(std::move(item));
|
||||
}
|
||||
|
||||
packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size()));
|
||||
packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size() + body.size()));
|
||||
size_t packet_count = 0;
|
||||
for (const auto & i: merged_tracking)
|
||||
{
|
||||
@@ -413,6 +474,15 @@ void scenes::stream::tracking()
|
||||
wivrn_session::stream_socket_t::serialize(packet, i);
|
||||
}
|
||||
}
|
||||
for (const auto & i: body)
|
||||
{
|
||||
if (i.poses)
|
||||
{
|
||||
auto & packet = packets[packet_count++];
|
||||
packet.clear();
|
||||
wivrn_session::stream_socket_t::serialize(packet, i);
|
||||
}
|
||||
}
|
||||
|
||||
network_session->send_stream(std::span(packets.data(), packet_count));
|
||||
|
||||
@@ -438,6 +508,9 @@ void scenes::stream::tracking()
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
if (face_tracking == from_headset::face_type::pico)
|
||||
application::get_pico_face_tracker().stop();
|
||||
}
|
||||
|
||||
void scenes::stream::operator()(to_headset::tracking_control && packet)
|
||||
|
||||
Reference in New Issue
Block a user