Add continuous foveated encoding
Co-authored-by: Patrick Nicolas <patricknicolas@laposte.net>
This commit is contained in:
co-authored by
Patrick Nicolas
parent
c97512d912
commit
f16cfa8ae8
@@ -211,7 +211,6 @@ void scenes::stream::render()
|
|||||||
application::pop_scene();
|
application::pop_scene();
|
||||||
|
|
||||||
XrFrameState framestate = session.wait_frame();
|
XrFrameState framestate = session.wait_frame();
|
||||||
// auto t0 = application::now();
|
|
||||||
|
|
||||||
if (decoders.empty())
|
if (decoders.empty())
|
||||||
framestate.shouldRender = false;
|
framestate.shouldRender = false;
|
||||||
@@ -233,7 +232,6 @@ void scenes::stream::render()
|
|||||||
}
|
}
|
||||||
|
|
||||||
session.begin_frame();
|
session.begin_frame();
|
||||||
// auto dt2 = application::now() - t0;
|
|
||||||
|
|
||||||
auto [flags, views] = session.locate_views(viewconfig, framestate.predictedDisplayTime, world_space);
|
auto [flags, views] = session.locate_views(viewconfig, framestate.predictedDisplayTime, world_space);
|
||||||
assert(views.size() == swapchains.size());
|
assert(views.size() == swapchains.size());
|
||||||
@@ -354,7 +352,6 @@ void scenes::stream::render()
|
|||||||
.pCommandBuffers = &command_buffer,
|
.pCommandBuffers = &command_buffer,
|
||||||
};
|
};
|
||||||
CHECK_VK(vkQueueSubmit(queue, 1, &submit_info, fence));
|
CHECK_VK(vkQueueSubmit(queue, 1, &submit_info, fence));
|
||||||
// auto dt4 = application::now() - t0;
|
|
||||||
|
|
||||||
std::vector<XrCompositionLayerBaseHeader *> layers_base;
|
std::vector<XrCompositionLayerBaseHeader *> layers_base;
|
||||||
std::vector<XrCompositionLayerProjectionView> layer_view;
|
std::vector<XrCompositionLayerProjectionView> layer_view;
|
||||||
@@ -396,17 +393,13 @@ void scenes::stream::render()
|
|||||||
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer));
|
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer));
|
||||||
session.end_frame(/*timestamp*/ framestate.predictedDisplayTime, layers_base);
|
session.end_frame(/*timestamp*/ framestate.predictedDisplayTime, layers_base);
|
||||||
|
|
||||||
// auto dt5 = application::now() - t0;
|
|
||||||
CHECK_VK(vkWaitForFences(device, 1, &fence, VK_TRUE, UINT64_MAX));
|
CHECK_VK(vkWaitForFences(device, 1, &fence, VK_TRUE, UINT64_MAX));
|
||||||
CHECK_VK(vkResetFences(device, 1, &fence));
|
CHECK_VK(vkResetFences(device, 1, &fence));
|
||||||
|
|
||||||
// We don't need those after vkWaitForFences
|
// We don't need those after vkWaitForFences
|
||||||
current_blit_handles.clear();
|
current_blit_handles.clear();
|
||||||
|
|
||||||
// auto dt6 = application::now() - t0;
|
|
||||||
read_actions();
|
read_actions();
|
||||||
|
|
||||||
// spdlog::info("Render timing: begin frame {:.3f}ms, submit commands {:.3f}ms, end frame {:.3f}ms, wait fence {:.3f}ms, predicted display time {:.3f}ms", dt2/1.e6, dt4/1.e6, dt5/1.e6, dt6/1.e6, (framestate.predictedDisplayTime - t0) / 1.e6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void scenes::stream::cleanup()
|
void scenes::stream::cleanup()
|
||||||
@@ -528,7 +521,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
|||||||
images.push_back(i.image);
|
images.push_back(i.image);
|
||||||
}
|
}
|
||||||
|
|
||||||
reprojector.init(device, physical_device, images, swapchain_images, extent, swapchains[0].format());
|
reprojector.init(device, physical_device, images, swapchain_images, extent, swapchains[0].format(), description);
|
||||||
}
|
}
|
||||||
|
|
||||||
void scenes::stream::video()
|
void scenes::stream::video()
|
||||||
|
|||||||
@@ -28,6 +28,12 @@
|
|||||||
struct stream_reprojection::uniform
|
struct stream_reprojection::uniform
|
||||||
{
|
{
|
||||||
alignas(16) glm::mat4 reprojection;
|
alignas(16) glm::mat4 reprojection;
|
||||||
|
|
||||||
|
// Foveation parameters
|
||||||
|
alignas(8) glm::vec2 a;
|
||||||
|
alignas(8) glm::vec2 b;
|
||||||
|
alignas(8) glm::vec2 lambda;
|
||||||
|
alignas(8) glm::vec2 xc;
|
||||||
};
|
};
|
||||||
|
|
||||||
stream_reprojection::~stream_reprojection()
|
stream_reprojection::~stream_reprojection()
|
||||||
@@ -67,7 +73,7 @@ void stream_reprojection::cleanup()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stream_reprojection::init(VkDevice device, VkPhysicalDevice physical_device, std::vector<VkImage> input_images_, std::vector<VkImage> output_images_, VkExtent2D extent, VkFormat format)
|
void stream_reprojection::init(VkDevice device, VkPhysicalDevice physical_device, std::vector<VkImage> input_images_, std::vector<VkImage> output_images_, VkExtent2D extent, VkFormat format, const xrt::drivers::wivrn::to_headset::video_stream_description & description)
|
||||||
{
|
{
|
||||||
cleanup();
|
cleanup();
|
||||||
this->device = device;
|
this->device = device;
|
||||||
@@ -76,6 +82,7 @@ void stream_reprojection::init(VkDevice device, VkPhysicalDevice physical_device
|
|||||||
this->output_images = std::move(output_images_);
|
this->output_images = std::move(output_images_);
|
||||||
this->extent = extent;
|
this->extent = extent;
|
||||||
this->format = format;
|
this->format = format;
|
||||||
|
foveation_parameters = description.foveation;
|
||||||
|
|
||||||
VkPhysicalDeviceProperties properties;
|
VkPhysicalDeviceProperties properties;
|
||||||
vkGetPhysicalDeviceProperties(physical_device, &properties);
|
vkGetPhysicalDeviceProperties(physical_device, &properties);
|
||||||
@@ -253,10 +260,26 @@ void stream_reprojection::init(VkDevice device, VkPhysicalDevice physical_device
|
|||||||
|
|
||||||
layout = vk::pipeline_layout(device, {.descriptor_set_layouts = {descriptor_set_layout}});
|
layout = vk::pipeline_layout(device, {.descriptor_set_layouts = {descriptor_set_layout}});
|
||||||
|
|
||||||
|
VkBool32 use_foveation[] = {
|
||||||
|
foveation_parameters[0].x.scale < 1,
|
||||||
|
foveation_parameters[0].y.scale < 1
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<VkSpecializationMapEntry> specialization_constants_desc = {
|
||||||
|
{.constantID = 0, .offset = 0, .size = sizeof(VkBool32)},
|
||||||
|
{.constantID = 1, .offset = sizeof(VkBool32), .size = sizeof(VkBool32)}
|
||||||
|
};
|
||||||
|
|
||||||
|
VkSpecializationInfo specialization_info{
|
||||||
|
.mapEntryCount = (uint32_t)specialization_constants_desc.size(),
|
||||||
|
.pMapEntries = specialization_constants_desc.data(),
|
||||||
|
.dataSize = sizeof(use_foveation),
|
||||||
|
.pData = use_foveation};
|
||||||
|
|
||||||
vk::pipeline::graphics_info pipeline_info{
|
vk::pipeline::graphics_info pipeline_info{
|
||||||
.shader_stages =
|
.shader_stages =
|
||||||
{{.stage = VK_SHADER_STAGE_VERTEX_BIT, .module = vertex_shader, .pName = "main"},
|
{{.stage = VK_SHADER_STAGE_VERTEX_BIT, .module = vertex_shader, .pName = "main"},
|
||||||
{.stage = VK_SHADER_STAGE_FRAGMENT_BIT, .module = fragment_shader, .pName = "main"}},
|
{.stage = VK_SHADER_STAGE_FRAGMENT_BIT, .module = fragment_shader, .pName = "main", .pSpecializationInfo = &specialization_info}},
|
||||||
.vertex_input_bindings = {},
|
.vertex_input_bindings = {},
|
||||||
.vertex_input_attributes = {},
|
.vertex_input_attributes = {},
|
||||||
.InputAssemblyState = {.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP},
|
.InputAssemblyState = {.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP},
|
||||||
@@ -366,6 +389,16 @@ void stream_reprojection::reproject(VkCommandBuffer command_buffer, int source,
|
|||||||
|
|
||||||
ubo[source]->reprojection = video_proj * video_view * hmd_unview * glm::inverse(hmd_proj);
|
ubo[source]->reprojection = video_proj * video_view * hmd_unview * glm::inverse(hmd_proj);
|
||||||
|
|
||||||
|
ubo[source]->a.x = foveation_parameters[source].x.a;
|
||||||
|
ubo[source]->b.x = foveation_parameters[source].x.b;
|
||||||
|
ubo[source]->lambda.x = foveation_parameters[source].x.a / foveation_parameters[source].x.scale;
|
||||||
|
ubo[source]->xc.x = foveation_parameters[source].x.center;
|
||||||
|
|
||||||
|
ubo[source]->a.y = foveation_parameters[source].y.a;
|
||||||
|
ubo[source]->b.y = foveation_parameters[source].y.b;
|
||||||
|
ubo[source]->lambda.y = foveation_parameters[source].y.a / foveation_parameters[source].y.scale;
|
||||||
|
ubo[source]->xc.y = foveation_parameters[source].y.center;
|
||||||
|
|
||||||
VkClearValue clear_color{};
|
VkClearValue clear_color{};
|
||||||
|
|
||||||
VkRenderPassBeginInfo begin_info{
|
VkRenderPassBeginInfo begin_info{
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "vk/pipeline_layout.h"
|
#include "vk/pipeline_layout.h"
|
||||||
#include "vk/renderpass.h"
|
#include "vk/renderpass.h"
|
||||||
#include "vk/shader.h"
|
#include "vk/shader.h"
|
||||||
|
#include "wivrn_packets.h"
|
||||||
#include <vulkan/vulkan_core.h>
|
#include <vulkan/vulkan_core.h>
|
||||||
#include <openxr/openxr.h>
|
#include <openxr/openxr.h>
|
||||||
|
|
||||||
@@ -60,12 +61,15 @@ class stream_reprojection
|
|||||||
vk::pipeline pipeline;
|
vk::pipeline pipeline;
|
||||||
vk::renderpass renderpass;
|
vk::renderpass renderpass;
|
||||||
|
|
||||||
|
// Foveation
|
||||||
|
std::array<xrt::drivers::wivrn::to_headset::video_stream_description::foveation_parameter, 2> foveation_parameters;
|
||||||
|
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
stream_reprojection() = default;
|
stream_reprojection() = default;
|
||||||
stream_reprojection(const stream_reprojection &) = delete;
|
stream_reprojection(const stream_reprojection &) = delete;
|
||||||
void init(VkDevice device, VkPhysicalDevice physical_device, std::vector<VkImage> input_images, std::vector<VkImage> output_images, VkExtent2D extent, VkFormat format);
|
void init(VkDevice device, VkPhysicalDevice physical_device, std::vector<VkImage> input_images, std::vector<VkImage> output_images, VkExtent2D extent, VkFormat format, const xrt::drivers::wivrn::to_headset::video_stream_description & description);
|
||||||
|
|
||||||
~stream_reprojection();
|
~stream_reprojection();
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ ubo;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// outUV = vec2(ubo.reprojection * vec4(positions[gl_VertexIndex], 1.0, 1.0));
|
|
||||||
outUV = positions[gl_VertexIndex];
|
outUV = positions[gl_VertexIndex];
|
||||||
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
|
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
|
||||||
}
|
}
|
||||||
@@ -48,9 +47,17 @@ layout(set = 0, binding = 0) uniform sampler2D texSampler;
|
|||||||
layout(set = 0, binding = 1) uniform UniformBufferObject
|
layout(set = 0, binding = 1) uniform UniformBufferObject
|
||||||
{
|
{
|
||||||
mat4 reprojection;
|
mat4 reprojection;
|
||||||
|
|
||||||
|
vec2 a;
|
||||||
|
vec2 b;
|
||||||
|
vec2 lambda;
|
||||||
|
vec2 xc;
|
||||||
}
|
}
|
||||||
ubo;
|
ubo;
|
||||||
|
|
||||||
|
layout (constant_id = 0) const bool use_foveation_x = false;
|
||||||
|
layout (constant_id = 1) const bool use_foveation_y = false;
|
||||||
|
|
||||||
layout(location = 0) in vec2 inUV;
|
layout(location = 0) in vec2 inUV;
|
||||||
|
|
||||||
layout(location = 0) out vec4 outColor;
|
layout(location = 0) out vec4 outColor;
|
||||||
@@ -58,7 +65,24 @@ layout(location = 0) out vec4 outColor;
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 tmp = ubo.reprojection * vec4(inUV, 1.0, 1.0);
|
vec4 tmp = ubo.reprojection * vec4(inUV, 1.0, 1.0);
|
||||||
|
vec2 uv = vec2(tmp) / tmp.z; // between -1 and 1
|
||||||
|
|
||||||
outColor = texture(texSampler, vec2(tmp) / tmp.z * 0.5 + vec2(0.5, 0.5));
|
if (use_foveation_x && use_foveation_y)
|
||||||
|
{
|
||||||
|
uv = ubo.xc + ubo.lambda * atan((uv - ubo.b) / ubo.a);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (use_foveation_x)
|
||||||
|
{
|
||||||
|
uv.x = (ubo.xc + ubo.lambda * atan((uv - ubo.b) / ubo.a)).x;
|
||||||
|
}
|
||||||
|
if (use_foveation_y)
|
||||||
|
{
|
||||||
|
uv.y = (ubo.xc + ubo.lambda * atan((uv - ubo.b) / ubo.a)).y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outColor = texture(texSampler, uv * 0.5 + vec2(0.5, 0.5));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -190,9 +190,22 @@ struct video_stream_description
|
|||||||
std::optional<uint32_t> range; // VkSamplerYcbcrRange
|
std::optional<uint32_t> range; // VkSamplerYcbcrRange
|
||||||
std::optional<uint32_t> color_model; // VkSamplerYcbcrModelConversion
|
std::optional<uint32_t> color_model; // VkSamplerYcbcrModelConversion
|
||||||
};
|
};
|
||||||
|
struct foveation_parameter_item
|
||||||
|
{
|
||||||
|
double center;
|
||||||
|
double scale;
|
||||||
|
double a;
|
||||||
|
double b;
|
||||||
|
};
|
||||||
|
struct foveation_parameter
|
||||||
|
{
|
||||||
|
foveation_parameter_item x;
|
||||||
|
foveation_parameter_item y;
|
||||||
|
};
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
uint16_t height;
|
uint16_t height;
|
||||||
float fps;
|
float fps;
|
||||||
|
std::array<foveation_parameter, 2> foveation;
|
||||||
std::vector<item> items;
|
std::vector<item> items;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,12 @@ configuration configuration::read_user_configuration()
|
|||||||
auto json = nlohmann::json::parse(file);
|
auto json = nlohmann::json::parse(file);
|
||||||
|
|
||||||
if (json.contains("scale"))
|
if (json.contains("scale"))
|
||||||
result.scale = json["scale"];
|
{
|
||||||
|
if (json["scale"].is_number())
|
||||||
|
result.scale = std::array<double, 2>{json["scale"], json["scale"]};
|
||||||
|
else
|
||||||
|
result.scale = json["scale"];
|
||||||
|
}
|
||||||
|
|
||||||
if (json.contains("encoders"))
|
if (json.contains("encoders"))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -41,8 +42,7 @@ struct configuration
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::vector<encoder> encoders;
|
std::vector<encoder> encoders;
|
||||||
std::optional<double> scale;
|
std::optional<std::array<double, 2>> scale;
|
||||||
|
|
||||||
static configuration read_user_configuration();
|
static configuration read_user_configuration();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ static void create_encoders(wivrn_comp_target * cn, std::vector<encoder_settings
|
|||||||
desc.width = cn->width;
|
desc.width = cn->width;
|
||||||
desc.height = cn->height;
|
desc.height = cn->height;
|
||||||
desc.fps = cn->fps;
|
desc.fps = cn->fps;
|
||||||
|
desc.foveation = cn->cnx->get_foveation_parameters();
|
||||||
|
|
||||||
std::map<int, encoder_thread_param> thread_params;
|
std::map<int, encoder_thread_param> thread_params;
|
||||||
|
|
||||||
|
|||||||
+186
-13
@@ -35,6 +35,7 @@
|
|||||||
#include "util/u_time.h"
|
#include "util/u_time.h"
|
||||||
#include "util/u_var.h"
|
#include "util/u_var.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <openxr/openxr.h>
|
#include <openxr/openxr.h>
|
||||||
|
|
||||||
@@ -80,6 +81,147 @@ static void wivrn_hmd_create_compositor_target(struct xrt_device * xdev,
|
|||||||
struct comp_compositor * comp,
|
struct comp_compositor * comp,
|
||||||
struct comp_target ** out_target);
|
struct comp_target ** out_target);
|
||||||
|
|
||||||
|
static double foveate(double a, double b, double scale, double c, double x)
|
||||||
|
{
|
||||||
|
// In order to save encoding, transmit and decoding time, only a portion of the image is encoded in full resolution.
|
||||||
|
// on each axis, foveated coordinates are defined by the following formula.
|
||||||
|
return a * tan(scale / a * (x - c)) + b;
|
||||||
|
// a and b are defined such as:
|
||||||
|
// edges of the image are not moved
|
||||||
|
// f(-1) = -1
|
||||||
|
// f( 1) = 1
|
||||||
|
// the function also enforces pixel ratio 1:1 at fovea
|
||||||
|
// df(x)/dx = scale for x = c
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::tuple<float, float> solve_foveation(float scale, float c)
|
||||||
|
{
|
||||||
|
// Compute a and b for the foveation function such that:
|
||||||
|
// foveate(a, b, scale, c, -1) = -1 (eq. 1)
|
||||||
|
// foveate(a, b, scale, c, 1) = 1 (eq. 2)
|
||||||
|
//
|
||||||
|
// The first step is to solve for a by subtracting equation 1 and 2:
|
||||||
|
// foveate(a, b, scale, c, 1) - foveate(a, b, scale, c, -1) = 2 (eq. 3)
|
||||||
|
//
|
||||||
|
// Where b is cancelled by the subtraction, so the equation to solve becomes:
|
||||||
|
// f(a) = 0 where:
|
||||||
|
auto f = [scale, c](double a) { return foveate(a, 0, scale, c, 1) - foveate(a, 0, scale, c, -1) - 2; };
|
||||||
|
|
||||||
|
// b is computed rewriting equation 2 as:
|
||||||
|
// foveate(a, 0, scale, c, 1) + b = 1
|
||||||
|
// Therefore:
|
||||||
|
// b = 1 - foveate(a, 0, scale, c, 1)
|
||||||
|
//
|
||||||
|
// Note that there are infinitely many solutions to equation 3, but we want
|
||||||
|
// to have a value of a such that:
|
||||||
|
// ∀ x ∈ [-1, 1], abs(scale / a * (x - c)) < π / 2 (eq. 4)
|
||||||
|
// So that foveate(x) is defined over [-1, 1]
|
||||||
|
//
|
||||||
|
// Equation 4 can be rewritten as:
|
||||||
|
// a > 2 * scale / π * abs(x - c)
|
||||||
|
//
|
||||||
|
// The minimum value of abs(x - c) for x ∈ [-1, 1] is 1 + abs(c)
|
||||||
|
// so a must be larger than a0 with:
|
||||||
|
double a0 = 2 * scale / M_PI * (1 + std::abs(c));
|
||||||
|
|
||||||
|
// f is monotonically decreasing over (a0, +∞) with:
|
||||||
|
// lim f(a) = +∞
|
||||||
|
// a→a0+
|
||||||
|
//
|
||||||
|
// lim f(a) = 2 * scale - 2
|
||||||
|
// a→∞
|
||||||
|
//
|
||||||
|
// Therefore there is one solution iff scale < 1
|
||||||
|
//
|
||||||
|
// a0 is the lowermost value for a, f(a0) is undefined and f(a0 + ε) > 0
|
||||||
|
// We want an upper bound a1 for a, f(a1) < 0:
|
||||||
|
//
|
||||||
|
// Find the value by computing f(a0*2^n) until negative
|
||||||
|
double a1 = a0 * 2;
|
||||||
|
while (f(a1) > 0)
|
||||||
|
a1 *= 2;
|
||||||
|
|
||||||
|
// Solve f(a) = 0
|
||||||
|
|
||||||
|
// last computed values for f(a0) and f(a1)
|
||||||
|
std::optional<double> f_a0;
|
||||||
|
double f_a1 = f(a1);
|
||||||
|
|
||||||
|
int n = 0;
|
||||||
|
double a;
|
||||||
|
while (std::abs(a1 - a0) > 0.0000001 && n++ < 100)
|
||||||
|
{
|
||||||
|
if (not f_a0)
|
||||||
|
{
|
||||||
|
// use binary search
|
||||||
|
a = 0.5 * (a0 + a1);
|
||||||
|
double val = f(a);
|
||||||
|
if (val > 0)
|
||||||
|
{
|
||||||
|
a0 = a;
|
||||||
|
f_a0 = val;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
a1 = a;
|
||||||
|
f_a1 = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// f(a1) is always defined
|
||||||
|
// when f(a0) is defined, use secant method
|
||||||
|
a = a1 - f_a1 * (a1 - a0) / (f_a1 - *f_a0);
|
||||||
|
a0 = a1;
|
||||||
|
a1 = a;
|
||||||
|
f_a0 = f_a1;
|
||||||
|
f_a1 = f(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double b = 1 - foveate(a, 0, scale, c, 1);
|
||||||
|
|
||||||
|
return {a, b};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wivrn_hmd::wivrn_hmd_compute_distortion(xrt_device * xdev, int view_index, float u, float v, xrt_uv_triplet * result)
|
||||||
|
{
|
||||||
|
// u,v are in the output coordinates (sent to the encoder)
|
||||||
|
// result is in the input coordinates (from the application)
|
||||||
|
const auto & param = ((wivrn_hmd *)xdev)->foveation_parameters[view_index];
|
||||||
|
xrt_vec2 out;
|
||||||
|
|
||||||
|
if (param.x.scale < 1)
|
||||||
|
{
|
||||||
|
u = 2 * u - 1;
|
||||||
|
|
||||||
|
out.x = param.x.a * tan(param.x.scale / param.x.a * (u - param.x.center)) + param.x.b;
|
||||||
|
out.x = std::clamp<float>((1 + out.x) / 2, 0, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out.x = u;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.y.scale < 1)
|
||||||
|
{
|
||||||
|
v = 2 * v - 1;
|
||||||
|
|
||||||
|
out.y = param.y.a * tan(param.y.scale / param.y.a * (v - param.y.center)) + param.y.b;
|
||||||
|
out.y = std::clamp<float>((1 + out.y) / 2, 0, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out.y = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
result->r = out;
|
||||||
|
result->g = out;
|
||||||
|
result->b = out;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
wivrn_hmd::wivrn_hmd(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx,
|
wivrn_hmd::wivrn_hmd(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx,
|
||||||
const from_headset::headset_info_packet & info) :
|
const from_headset::headset_info_packet & info) :
|
||||||
xrt_device{}, cnx(cnx)
|
xrt_device{}, cnx(cnx)
|
||||||
@@ -115,17 +257,20 @@ wivrn_hmd::wivrn_hmd(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx,
|
|||||||
|
|
||||||
const auto config = configuration::read_user_configuration();
|
const auto config = configuration::read_user_configuration();
|
||||||
|
|
||||||
auto eye_width = info.recommended_eye_width * config.scale.value_or(1);
|
auto eye_width = info.recommended_eye_width; // * config.scale.value_or(1);
|
||||||
auto eye_height = info.recommended_eye_height * config.scale.value_or(1);
|
auto eye_height = info.recommended_eye_height; // * config.scale.value_or(1);
|
||||||
|
auto scale = config.scale.value_or(std::array<double, 2>{1., 1.});
|
||||||
|
auto foveated_eye_width = info.recommended_eye_width * scale[0];
|
||||||
|
auto foveated_eye_height = info.recommended_eye_height * scale[1];
|
||||||
fps = info.preferred_refresh_rate;
|
fps = info.preferred_refresh_rate;
|
||||||
|
|
||||||
// Setup info.
|
// Setup info.
|
||||||
hmd->blend_modes[0] = XRT_BLEND_MODE_OPAQUE;
|
hmd->blend_modes[0] = XRT_BLEND_MODE_OPAQUE;
|
||||||
hmd->blend_mode_count = 1;
|
hmd->blend_mode_count = 1;
|
||||||
hmd->distortion.models = XRT_DISTORTION_MODEL_NONE;
|
hmd->distortion.models = XRT_DISTORTION_MODEL_COMPUTE;
|
||||||
hmd->distortion.preferred = XRT_DISTORTION_MODEL_NONE;
|
hmd->distortion.preferred = XRT_DISTORTION_MODEL_COMPUTE;
|
||||||
hmd->screens[0].w_pixels = eye_width * 2;
|
hmd->screens[0].w_pixels = foveated_eye_width * 2;
|
||||||
hmd->screens[0].h_pixels = eye_height;
|
hmd->screens[0].h_pixels = foveated_eye_height;
|
||||||
hmd->screens[0].nominal_frame_interval_ns = 1000000000 / fps;
|
hmd->screens[0].nominal_frame_interval_ns = 1000000000 / fps;
|
||||||
|
|
||||||
// Left
|
// Left
|
||||||
@@ -133,17 +278,17 @@ wivrn_hmd::wivrn_hmd(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx,
|
|||||||
hmd->views[0].display.h_pixels = eye_height;
|
hmd->views[0].display.h_pixels = eye_height;
|
||||||
hmd->views[0].viewport.x_pixels = 0;
|
hmd->views[0].viewport.x_pixels = 0;
|
||||||
hmd->views[0].viewport.y_pixels = 0;
|
hmd->views[0].viewport.y_pixels = 0;
|
||||||
hmd->views[0].viewport.w_pixels = eye_width;
|
hmd->views[0].viewport.w_pixels = foveated_eye_width;
|
||||||
hmd->views[0].viewport.h_pixels = eye_height;
|
hmd->views[0].viewport.h_pixels = foveated_eye_height;
|
||||||
hmd->views[0].rot = u_device_rotation_ident;
|
hmd->views[0].rot = u_device_rotation_ident;
|
||||||
|
|
||||||
// Right
|
// Right
|
||||||
hmd->views[1].display.w_pixels = eye_width;
|
hmd->views[1].display.w_pixels = eye_width;
|
||||||
hmd->views[1].display.h_pixels = eye_height;
|
hmd->views[1].display.h_pixels = eye_height;
|
||||||
hmd->views[1].viewport.x_pixels = eye_width;
|
hmd->views[1].viewport.x_pixels = foveated_eye_width;
|
||||||
hmd->views[1].viewport.y_pixels = 0;
|
hmd->views[1].viewport.y_pixels = 0;
|
||||||
hmd->views[1].viewport.w_pixels = eye_width;
|
hmd->views[1].viewport.w_pixels = foveated_eye_width;
|
||||||
hmd->views[1].viewport.h_pixels = eye_height;
|
hmd->views[1].viewport.h_pixels = foveated_eye_height;
|
||||||
hmd->views[1].rot = u_device_rotation_ident;
|
hmd->views[1].rot = u_device_rotation_ident;
|
||||||
|
|
||||||
// Default FOV from Oculus Quest
|
// Default FOV from Oculus Quest
|
||||||
@@ -157,8 +302,36 @@ wivrn_hmd::wivrn_hmd(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx,
|
|||||||
hmd->distortion.fov[1].angle_up = 47 * M_PI / 180;
|
hmd->distortion.fov[1].angle_up = 47 * M_PI / 180;
|
||||||
hmd->distortion.fov[1].angle_down = -53 * M_PI / 180;
|
hmd->distortion.fov[1].angle_down = -53 * M_PI / 180;
|
||||||
|
|
||||||
// Distortion information, fills in xdev->compute_distortion().
|
for (int i = 0; i < 2; ++i)
|
||||||
u_distortion_mesh_set_none(this);
|
{
|
||||||
|
foveation_parameters[i].x.scale = scale[0];
|
||||||
|
foveation_parameters[i].y.scale = scale[1];
|
||||||
|
const auto & view = hmd->views[i];
|
||||||
|
const auto & fov = hmd->distortion.fov[i];
|
||||||
|
float l = tan(fov.angle_left);
|
||||||
|
float r = tan(fov.angle_right);
|
||||||
|
float t = tan(fov.angle_up);
|
||||||
|
float b = tan(fov.angle_down);
|
||||||
|
if (scale[0] < 1)
|
||||||
|
{
|
||||||
|
float cu = (r + l) / (l - r);
|
||||||
|
foveation_parameters[i].x.center = cu;
|
||||||
|
|
||||||
|
std::tie(foveation_parameters[i].x.a, foveation_parameters[i].x.b) = solve_foveation(scale[0], cu);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scale[1] < 1)
|
||||||
|
{
|
||||||
|
float cv = (t + b) / (t - b);
|
||||||
|
foveation_parameters[i].y.center = cv;
|
||||||
|
|
||||||
|
std::tie(foveation_parameters[i].y.a, foveation_parameters[i].y.b) = solve_foveation(scale[1], cv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Distortion information
|
||||||
|
compute_distortion = wivrn_hmd_compute_distortion;
|
||||||
|
u_distortion_mesh_fill_in_compute(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wivrn_hmd::update_inputs()
|
void wivrn_hmd::update_inputs()
|
||||||
|
|||||||
@@ -39,9 +39,12 @@ class wivrn_hmd : public xrt_device
|
|||||||
xrt_tracking_origin tracking_origin;
|
xrt_tracking_origin tracking_origin;
|
||||||
|
|
||||||
view_list views;
|
view_list views;
|
||||||
|
std::array<to_headset::video_stream_description::foveation_parameter, 2> foveation_parameters{};
|
||||||
|
|
||||||
std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx;
|
std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx;
|
||||||
|
|
||||||
|
static bool wivrn_hmd_compute_distortion(xrt_device * xdev, int view_index, float u, float v, xrt_uv_triplet * result);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wivrn_hmd(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx,
|
wivrn_hmd(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx,
|
||||||
const from_headset::headset_info_packet & info);
|
const from_headset::headset_info_packet & info);
|
||||||
@@ -61,4 +64,9 @@ public:
|
|||||||
xrt_pose * out_poses);
|
xrt_pose * out_poses);
|
||||||
|
|
||||||
void update_tracking(const from_headset::tracking &, const clock_offset &);
|
void update_tracking(const from_headset::tracking &, const clock_offset &);
|
||||||
|
|
||||||
|
const auto & get_foveation_parameters()
|
||||||
|
{
|
||||||
|
return foveation_parameters;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -202,6 +202,11 @@ void wivrn_session::run(std::weak_ptr<wivrn_session> weak_self)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::array<to_headset::video_stream_description::foveation_parameter, 2> wivrn_session::get_foveation_parameters()
|
||||||
|
{
|
||||||
|
return hmd->get_foveation_parameters();
|
||||||
|
}
|
||||||
|
|
||||||
void wivrn_session::dump_time(const std::string &event, uint64_t frame, uint64_t time, uint8_t stream)
|
void wivrn_session::dump_time(const std::string &event, uint64_t frame, uint64_t time, uint8_t stream)
|
||||||
{
|
{
|
||||||
if (feedback_csv)
|
if (feedback_csv)
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ public:
|
|||||||
connection.send_control(packet);
|
connection.send_control(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::array<to_headset::video_stream_description::foveation_parameter, 2> get_foveation_parameters();
|
||||||
|
|
||||||
void dump_time(const std::string& event, uint64_t frame, uint64_t time, uint8_t stream = -1);
|
void dump_time(const std::string& event, uint64_t frame, uint64_t time, uint8_t stream = -1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user