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();
|
||||
|
||||
XrFrameState framestate = session.wait_frame();
|
||||
// auto t0 = application::now();
|
||||
|
||||
if (decoders.empty())
|
||||
framestate.shouldRender = false;
|
||||
@@ -233,7 +232,6 @@ void scenes::stream::render()
|
||||
}
|
||||
|
||||
session.begin_frame();
|
||||
// auto dt2 = application::now() - t0;
|
||||
|
||||
auto [flags, views] = session.locate_views(viewconfig, framestate.predictedDisplayTime, world_space);
|
||||
assert(views.size() == swapchains.size());
|
||||
@@ -354,7 +352,6 @@ void scenes::stream::render()
|
||||
.pCommandBuffers = &command_buffer,
|
||||
};
|
||||
CHECK_VK(vkQueueSubmit(queue, 1, &submit_info, fence));
|
||||
// auto dt4 = application::now() - t0;
|
||||
|
||||
std::vector<XrCompositionLayerBaseHeader *> layers_base;
|
||||
std::vector<XrCompositionLayerProjectionView> layer_view;
|
||||
@@ -396,17 +393,13 @@ void scenes::stream::render()
|
||||
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer));
|
||||
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(vkResetFences(device, 1, &fence));
|
||||
|
||||
// We don't need those after vkWaitForFences
|
||||
current_blit_handles.clear();
|
||||
|
||||
// auto dt6 = application::now() - t0;
|
||||
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()
|
||||
@@ -528,7 +521,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
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()
|
||||
|
||||
@@ -28,6 +28,12 @@
|
||||
struct stream_reprojection::uniform
|
||||
{
|
||||
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()
|
||||
@@ -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();
|
||||
this->device = device;
|
||||
@@ -76,6 +82,7 @@ void stream_reprojection::init(VkDevice device, VkPhysicalDevice physical_device
|
||||
this->output_images = std::move(output_images_);
|
||||
this->extent = extent;
|
||||
this->format = format;
|
||||
foveation_parameters = description.foveation;
|
||||
|
||||
VkPhysicalDeviceProperties 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}});
|
||||
|
||||
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{
|
||||
.shader_stages =
|
||||
{{.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_attributes = {},
|
||||
.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]->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{};
|
||||
|
||||
VkRenderPassBeginInfo begin_info{
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "vk/pipeline_layout.h"
|
||||
#include "vk/renderpass.h"
|
||||
#include "vk/shader.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
@@ -60,12 +61,15 @@ class stream_reprojection
|
||||
vk::pipeline pipeline;
|
||||
vk::renderpass renderpass;
|
||||
|
||||
// Foveation
|
||||
std::array<xrt::drivers::wivrn::to_headset::video_stream_description::foveation_parameter, 2> foveation_parameters;
|
||||
|
||||
void cleanup();
|
||||
|
||||
public:
|
||||
stream_reprojection() = default;
|
||||
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();
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ ubo;
|
||||
|
||||
void main()
|
||||
{
|
||||
// outUV = vec2(ubo.reprojection * vec4(positions[gl_VertexIndex], 1.0, 1.0));
|
||||
outUV = positions[gl_VertexIndex];
|
||||
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
|
||||
{
|
||||
mat4 reprojection;
|
||||
|
||||
vec2 a;
|
||||
vec2 b;
|
||||
vec2 lambda;
|
||||
vec2 xc;
|
||||
}
|
||||
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) out vec4 outColor;
|
||||
@@ -58,7 +65,24 @@ layout(location = 0) out vec4 outColor;
|
||||
void main()
|
||||
{
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user