Skip reprojection if runtime does it correctly

This commit is contained in:
Patrick Nicolas
2024-05-05 18:41:57 +02:00
parent 6b47a326a3
commit d06c96df68
7 changed files with 118 additions and 58 deletions
+24 -11
View File
@@ -501,12 +501,8 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render)
session.begin_frame();
auto [flags, views] = session.locate_views(viewconfig, predicted_display_time, world_space);
assert(views.size() == swapchains.size());
std::array<int, view_count> image_indices;
assert(views.size() == view_count);
for (size_t swapchain_index = 0; swapchain_index < views.size(); swapchain_index++)
for (size_t swapchain_index = 0; swapchain_index < view_count; swapchain_index++)
{
int image_index = swapchains[swapchain_index].acquire();
swapchains[swapchain_index].wait();
@@ -526,8 +522,8 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render)
command_buffer.resetQueryPool(*query_pool, 0, size_gpu_timestamps);
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eTopOfPipe, *query_pool, 0);
std::array<XrPosef, 2> pose = {views[0].pose, views[1].pose};
std::array<XrFovf, 2> fov = {views[0].fov, views[1].fov};
std::array<XrPosef, 2> pose{};
std::array<XrFovf, 2> fov{};
{
std::unique_lock lock(decoder_mutex);
// Search for frame with desired display time on all decoders
@@ -548,8 +544,6 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render)
state_ = stream::state::stalled;
++blit_handle->feedback.times_displayed;
blit_handle->feedback.displayed = predicted_display_time;
blit_handle->feedback.real_pose[0] = views[0].pose;
blit_handle->feedback.real_pose[1] = views[1].pose;
pose = blit_handle->view_info.pose;
fov = blit_handle->view_info.fov;
@@ -654,7 +648,24 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render)
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
// Reproject the image to the real pose
std::vector<XrView> views(view_count);
if (use_runtime_reprojection())
{
// In case of reprojection by runtime, give the original pose/fov
for (size_t i = 0; i < view_count; ++i)
{
views[i].pose = pose[i];
views[i].fov = fov[i];
}
}
else
{
// Fetch the latest view to reproject
views = session.locate_views(viewconfig, predicted_display_time, world_space).second;
assert(views.size() == swapchains.size());
}
// Unfoveate and reproject the image to the real pose
for (size_t view = 0; view < view_count; view++)
{
size_t destination_index = view * swapchains[0].images().size() + image_indices[view];
@@ -887,7 +898,9 @@ void scenes::stream::setup_reprojection_swapchain()
// Create a swapchain larger than video strem so that reprojection and foveation affect image quality less.
const double max_oversample = std::min(double(view.maxImageRectWidth) / swapchain_width,
double(view.maxImageRectHeight) / swapchain_height);
double oversample = std::min(1.4, max_oversample);
double oversample = std::min(
use_runtime_reprojection() ? 1 : 1.4,
max_oversample);
XrExtent2Di extent{
.width = int32_t(swapchain_width * oversample),
.height = int32_t(swapchain_height * oversample),
+51 -40
View File
@@ -19,6 +19,7 @@
#include "stream_reprojection.h"
#include "application.h"
#include "hardware.h"
#include "vk/allocation.h"
#include "vk/pipeline.h"
#include "vk/shader.h"
@@ -241,11 +242,13 @@ stream_reprojection::stream_reprojection(
layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
int use_foveation[] = {
int specialization_constants[] = {
foveation_parameters[0].x.scale < 1,
foveation_parameters[0].y.scale < 1,
nb_reprojection_vertices,
nb_reprojection_vertices};
nb_reprojection_vertices,
not use_runtime_reprojection(),
};
std::array specialization_constants_desc{
vk::SpecializationMapEntry{
@@ -268,12 +271,17 @@ stream_reprojection::stream_reprojection(
.offset = 3 * sizeof(int),
.size = sizeof(int),
},
vk::SpecializationMapEntry{
.constantID = 4,
.offset = 4 * sizeof(int),
.size = sizeof(int),
},
};
vk::SpecializationInfo specialization_info;
specialization_info.setMapEntries(specialization_constants_desc);
specialization_info.setData<int>(use_foveation);
specialization_info.setData<int>(specialization_constants);
vk::pipeline_builder pipeline_info{
.flags = {},
@@ -377,49 +385,52 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, in
if (destination < 0 || destination >= (int)output_images.size())
throw std::runtime_error("Invalid destination image index");
// Compute the reprojection matrix
float zn = 1;
float r = tan(dest_fov.angleRight);
float l = tan(dest_fov.angleLeft);
float t = tan(dest_fov.angleUp);
float b = tan(dest_fov.angleDown);
if (not use_runtime_reprojection())
{
// Compute the reprojection matrix
float zn = 1;
float r = tan(dest_fov.angleRight);
float l = tan(dest_fov.angleLeft);
float t = tan(dest_fov.angleUp);
float b = tan(dest_fov.angleDown);
// clang-format off
glm::mat4 hmd_proj{
{ 2/(r-l), 0, 0, 0 },
{ 0, 2/(b-t), 0, 0 },
{ (l+r)/(r-l), (t+b)/(b-t), -1, -1 },
{ 0, 0, -2*zn, 0 }
};
// clang-format on
// clang-format off
glm::mat4 hmd_proj{
{ 2/(r-l), 0, 0, 0 },
{ 0, 2/(b-t), 0, 0 },
{ (l+r)/(r-l), (t+b)/(b-t), -1, -1 },
{ 0, 0, -2*zn, 0 }
};
// clang-format on
glm::mat4 hmd_view = glm::mat4_cast(glm::quat(
-dest_pose.w,
dest_pose.x,
dest_pose.y,
dest_pose.z));
glm::mat4 hmd_view = glm::mat4_cast(glm::quat(
-dest_pose.w,
dest_pose.x,
dest_pose.y,
dest_pose.z));
r = tan(source_fov.angleRight);
l = tan(source_fov.angleLeft);
t = tan(source_fov.angleUp);
b = tan(source_fov.angleDown);
r = tan(source_fov.angleRight);
l = tan(source_fov.angleLeft);
t = tan(source_fov.angleUp);
b = tan(source_fov.angleDown);
// clang-format off
glm::mat4 video_proj{
{ 2/(r-l), 0, 0, 0 },
{ 0, 2/(b-t), 0, 0 },
{ (l+r)/(r-l), (t+b)/(b-t), -1, -1 },
{ 0, 0, -2*zn, 0 }
};
// clang-format on
// clang-format off
glm::mat4 video_proj{
{ 2/(r-l), 0, 0, 0 },
{ 0, 2/(b-t), 0, 0 },
{ (l+r)/(r-l), (t+b)/(b-t), -1, -1 },
{ 0, 0, -2*zn, 0 }
};
// clang-format on
glm::mat4 video_unview = glm::mat4_cast(glm::quat(
source_pose.w,
source_pose.x,
source_pose.y,
source_pose.z));
glm::mat4 video_unview = glm::mat4_cast(glm::quat(
source_pose.w,
source_pose.x,
source_pose.y,
source_pose.z));
ubo[source]->reprojection = hmd_proj * hmd_view * video_unview * glm::inverse(video_proj);
ubo[source]->reprojection = hmd_proj * hmd_view * video_unview * glm::inverse(video_proj);
}
if (foveation_parameters[source].x.scale < 1)
{