Skip reprojection if runtime does it correctly
This commit is contained in:
@@ -192,7 +192,6 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx)
|
||||
spdlog::warn("first shard has no view_info");
|
||||
return;
|
||||
}
|
||||
feedback.received_pose = data_shards.front()->view_info->pose;
|
||||
|
||||
// Try to extract a frame
|
||||
decoder->frame_completed(feedback, timing_info, *data_shards.front()->view_info);
|
||||
|
||||
+31
-1
@@ -42,7 +42,7 @@ static std::string get_property(const char * property)
|
||||
}
|
||||
#endif
|
||||
|
||||
model guess_model()
|
||||
static model guess_model_()
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
const auto device = get_property("ro.product.device");
|
||||
@@ -85,6 +85,12 @@ model guess_model()
|
||||
return model::unknown;
|
||||
}
|
||||
|
||||
model guess_model()
|
||||
{
|
||||
static model m = guess_model_();
|
||||
return m;
|
||||
}
|
||||
|
||||
static XrViewConfigurationView scale_view(XrViewConfigurationView view, uint32_t width)
|
||||
{
|
||||
double ratio = double(width) / view.recommendedImageRectWidth;
|
||||
@@ -123,3 +129,27 @@ XrViewConfigurationView override_view(XrViewConfigurationView view, model m)
|
||||
}
|
||||
throw std::range_error("invalid model " + std::to_string((int)m));
|
||||
}
|
||||
|
||||
static bool use_runtime_reprojection_()
|
||||
{
|
||||
switch (guess_model())
|
||||
{
|
||||
case model::oculus_quest:
|
||||
return false;
|
||||
case model::oculus_quest_2:
|
||||
case model::meta_quest_pro:
|
||||
case model::meta_quest_3:
|
||||
case model::pico_neo_3:
|
||||
case model::pico_4:
|
||||
case model::htc_vive_focus_3:
|
||||
case model::htc_vive_xr_elite:
|
||||
case model::unknown:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool use_runtime_reprojection()
|
||||
{
|
||||
static bool r = use_runtime_reprojection_();
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -36,3 +36,5 @@ enum class model
|
||||
model guess_model();
|
||||
|
||||
XrViewConfigurationView override_view(XrViewConfigurationView, model);
|
||||
|
||||
bool use_runtime_reprojection();
|
||||
|
||||
+24
-11
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -23,6 +23,7 @@ layout (constant_id = 0) const bool use_foveation_x = false;
|
||||
layout (constant_id = 1) const bool use_foveation_y = false;
|
||||
layout (constant_id = 2) const int nb_x = 64;
|
||||
layout (constant_id = 3) const int nb_y = 64;
|
||||
layout (constant_id = 4) const bool reproject = false;
|
||||
|
||||
layout(set = 0, binding = 1) uniform UniformBufferObject
|
||||
{
|
||||
@@ -53,8 +54,15 @@ vec2 reproject_and_unfoveate(vec2 uv)
|
||||
uv.y = (ubo.lambda * tan(ubo.a * uv + ubo.b) + ubo.xc).y;
|
||||
}
|
||||
}
|
||||
vec4 tmp = ubo.reprojection * vec4(uv, 1.0, 1.0);
|
||||
return vec2(tmp) / tmp.z; // between -1 and 1
|
||||
if (reproject)
|
||||
{
|
||||
vec4 tmp = ubo.reprojection * vec4(uv, 1.0, 1.0);
|
||||
return vec2(tmp) / tmp.z; // between -1 and 1
|
||||
}
|
||||
else
|
||||
{
|
||||
return uv;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERT_SHADER
|
||||
|
||||
@@ -213,9 +213,6 @@ struct feedback
|
||||
XrTime displayed;
|
||||
|
||||
uint8_t times_displayed;
|
||||
|
||||
std::array<XrPosef, 2> received_pose;
|
||||
std::array<XrPosef, 2> real_pose;
|
||||
};
|
||||
|
||||
using packets = std::variant<headset_info_packet, feedback, audio_data, handshake, tracking, hand_tracking, inputs, timesync_response>;
|
||||
|
||||
Reference in New Issue
Block a user