Remove WiVRn-reprojection code
This commit is contained in:
@@ -129,27 +129,3 @@ 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,5 +36,3 @@ enum class model
|
||||
model guess_model();
|
||||
|
||||
XrViewConfigurationView override_view(XrViewConfigurationView, model);
|
||||
|
||||
bool use_runtime_reprojection();
|
||||
|
||||
@@ -648,28 +648,11 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render)
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
|
||||
|
||||
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
|
||||
// Unfoveate 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];
|
||||
reprojector->reproject(command_buffer, view, destination_index, pose[view].orientation, fov[view], views[view].pose.orientation, views[view].fov);
|
||||
reprojector->reproject(command_buffer, view, destination_index);
|
||||
}
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
|
||||
@@ -680,18 +663,17 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render)
|
||||
queue.submit(submit_info, *fence);
|
||||
|
||||
std::vector<XrCompositionLayerBaseHeader *> layers_base;
|
||||
std::vector<XrCompositionLayerProjectionView> layer_view;
|
||||
layer_view.resize(views.size());
|
||||
std::vector<XrCompositionLayerProjectionView> layer_view(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++)
|
||||
{
|
||||
swapchains[swapchain_index].release();
|
||||
|
||||
layer_view[swapchain_index] =
|
||||
{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW,
|
||||
.pose = views[swapchain_index].pose,
|
||||
.fov = views[swapchain_index].fov,
|
||||
.pose = pose[swapchain_index],
|
||||
.fov = fov[swapchain_index],
|
||||
|
||||
.subImage = {
|
||||
.swapchain = swapchains[swapchain_index],
|
||||
@@ -895,15 +877,9 @@ void scenes::stream::setup_reprojection_swapchain()
|
||||
swapchains.reserve(views.size());
|
||||
for (auto view: views)
|
||||
{
|
||||
// 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(
|
||||
use_runtime_reprojection() ? 1 : 1.4,
|
||||
max_oversample);
|
||||
XrExtent2Di extent{
|
||||
.width = int32_t(swapchain_width * oversample),
|
||||
.height = int32_t(swapchain_height * oversample),
|
||||
.width = std::min<int32_t>(view.maxImageRectWidth, swapchain_width),
|
||||
.height = std::min<int32_t>(view.maxImageRectHeight, swapchain_height),
|
||||
};
|
||||
swapchains.emplace_back(session, device, swapchain_format, extent.width, extent.height);
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "stream_reprojection.h"
|
||||
#include "application.h"
|
||||
#include "hardware.h"
|
||||
#include "vk/allocation.h"
|
||||
#include "vk/pipeline.h"
|
||||
#include "vk/shader.h"
|
||||
@@ -33,8 +32,6 @@
|
||||
|
||||
struct stream_reprojection::uniform
|
||||
{
|
||||
alignas(16) glm::mat4 reprojection;
|
||||
|
||||
// Foveation parameters
|
||||
alignas(8) glm::vec2 a;
|
||||
alignas(8) glm::vec2 b;
|
||||
@@ -247,7 +244,6 @@ stream_reprojection::stream_reprojection(
|
||||
foveation_parameters[0].y.scale < 1,
|
||||
nb_reprojection_vertices,
|
||||
nb_reprojection_vertices,
|
||||
not use_runtime_reprojection(),
|
||||
};
|
||||
|
||||
std::array specialization_constants_desc{
|
||||
@@ -271,11 +267,6 @@ 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;
|
||||
@@ -378,60 +369,13 @@ stream_reprojection::stream_reprojection(
|
||||
}
|
||||
}
|
||||
|
||||
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, int source, int destination, XrQuaternionf source_pose, XrFovf source_fov, XrQuaternionf dest_pose, XrFovf dest_fov)
|
||||
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, int source, int destination)
|
||||
{
|
||||
if (source < 0 || source >= (int)input_images.size())
|
||||
throw std::runtime_error("Invalid source image index");
|
||||
if (destination < 0 || destination >= (int)output_images.size())
|
||||
throw std::runtime_error("Invalid destination image index");
|
||||
|
||||
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
|
||||
|
||||
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);
|
||||
|
||||
// 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));
|
||||
|
||||
ubo[source]->reprojection = hmd_proj * hmd_view * video_unview * glm::inverse(video_proj);
|
||||
}
|
||||
|
||||
if (foveation_parameters[source].x.scale < 1)
|
||||
{
|
||||
ubo[source]->a.x = foveation_parameters[source].x.a;
|
||||
|
||||
@@ -69,9 +69,5 @@ public:
|
||||
void reproject(
|
||||
vk::raii::CommandBuffer & command_buffer,
|
||||
int source,
|
||||
int destination,
|
||||
XrQuaternionf source_pose,
|
||||
XrFovf source_fov,
|
||||
XrQuaternionf destination_pose,
|
||||
XrFovf destination_fov);
|
||||
int destination);
|
||||
};
|
||||
|
||||
@@ -23,12 +23,9 @@ 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
|
||||
{
|
||||
mat4 reprojection;
|
||||
|
||||
vec2 a;
|
||||
vec2 b;
|
||||
vec2 lambda;
|
||||
@@ -36,7 +33,7 @@ layout(set = 0, binding = 1) uniform UniformBufferObject
|
||||
}
|
||||
ubo;
|
||||
|
||||
vec2 reproject_and_unfoveate(vec2 uv)
|
||||
vec2 unfoveate(vec2 uv)
|
||||
{
|
||||
uv = 2 * uv - 1;
|
||||
if (use_foveation_x && use_foveation_y)
|
||||
@@ -54,15 +51,7 @@ vec2 reproject_and_unfoveate(vec2 uv)
|
||||
uv.y = (ubo.lambda * tan(ubo.a * uv + ubo.b) + ubo.xc).y;
|
||||
}
|
||||
}
|
||||
if (reproject)
|
||||
{
|
||||
vec4 tmp = ubo.reprojection * vec4(uv, 1.0, 1.0);
|
||||
return vec2(tmp) / tmp.z; // between -1 and 1
|
||||
}
|
||||
else
|
||||
{
|
||||
return uv;
|
||||
}
|
||||
return uv;
|
||||
}
|
||||
|
||||
#ifdef VERT_SHADER
|
||||
@@ -81,7 +70,7 @@ void main()
|
||||
vec2 top_left = quad_size * vec2(cell_id % nb_x, cell_id / nb_x);
|
||||
outUV = top_left + positions[gl_VertexIndex % 6] * quad_size;
|
||||
|
||||
gl_Position = vec4(reproject_and_unfoveate(outUV), 0.0, 1.0);
|
||||
gl_Position = vec4(unfoveate(outUV), 0.0, 1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user