Get maximum size from nvenc capabilities
This commit is contained in:
@@ -23,8 +23,6 @@
|
||||
#include "math/m_space.h"
|
||||
#include "utils/scoped_lock.h"
|
||||
#include "xrt_cast.h"
|
||||
#include <condition_variable>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
@@ -99,7 +97,7 @@ struct encoder_thread_param
|
||||
|
||||
static void * comp_wivrn_present_thread(void * void_param);
|
||||
|
||||
static void create_encoders(wivrn_comp_target * cn, std::vector<encoder_settings> & _settings)
|
||||
static void create_encoders(wivrn_comp_target * cn)
|
||||
{
|
||||
auto vk = get_vk(cn);
|
||||
assert(cn->encoders.empty());
|
||||
@@ -109,12 +107,11 @@ static void create_encoders(wivrn_comp_target * cn, std::vector<encoder_settings
|
||||
auto & desc = cn->desc;
|
||||
desc.width = cn->width;
|
||||
desc.height = cn->height;
|
||||
desc.fps = cn->fps;
|
||||
desc.foveation = cn->cnx->get_foveation_parameters();
|
||||
desc.foveation = cn->cnx->set_foveated_size(desc.width, desc.height);
|
||||
|
||||
std::map<int, encoder_thread_param> thread_params;
|
||||
|
||||
for (auto & settings: _settings)
|
||||
for (auto & settings: cn->settings)
|
||||
{
|
||||
uint8_t stream_index = cn->encoders.size();
|
||||
auto & encoder = cn->encoders.emplace_back(
|
||||
@@ -139,7 +136,7 @@ static void create_encoders(wivrn_comp_target * cn, std::vector<encoder_settings
|
||||
cn->cnx->send_control(desc);
|
||||
}
|
||||
|
||||
static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags flags, const std::vector<xrt::drivers::wivrn::encoder_settings> & settings)
|
||||
static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags flags)
|
||||
{
|
||||
auto vk = get_vk(cn);
|
||||
assert(cn->image_count > 0);
|
||||
@@ -230,13 +227,24 @@ static bool comp_wivrn_init_post_vulkan(struct comp_target * ct, uint32_t prefer
|
||||
.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
|
||||
.queueFamilyIndex = vk->queue_family_index,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
U_LOG_E("Compositor target init failed: %s", e.what());
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
cn->settings = get_encoder_settings(*cn->wivrn_bundle->physical_device, cn->c->settings.preferred.width, cn->c->settings.preferred.height);
|
||||
print_encoders(cn->settings);
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
U_LOG_E("Failed to create video encoder: %s", e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool comp_wivrn_check_ready(struct comp_target * ct)
|
||||
@@ -323,31 +331,16 @@ static void comp_wivrn_create_images(struct comp_target * ct, const struct comp_
|
||||
ct->surface_transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
|
||||
cn->image_count = 3;
|
||||
cn->format = ct->format;
|
||||
cn->width = create_info->extent.width;
|
||||
cn->height = create_info->extent.height;
|
||||
cn->color_space = create_info->color_space;
|
||||
|
||||
auto settings = get_encoder_settings(*cn->wivrn_bundle->physical_device, cn->width, cn->height);
|
||||
|
||||
VkResult res = create_images(cn, vk::ImageUsageFlags(create_info->image_usage), settings);
|
||||
VkResult res = create_images(cn, vk::ImageUsageFlags(create_info->image_usage));
|
||||
if (res != VK_SUCCESS)
|
||||
{
|
||||
vk_print_result(get_vk(cn), __FILE__, __LINE__, __func__, res, "create_images");
|
||||
// TODO
|
||||
abort();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
print_encoders(settings);
|
||||
create_encoders(cn, settings);
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
U_LOG_E("Failed to create video encoder: %s", e.what());
|
||||
abort();
|
||||
}
|
||||
create_encoders(cn);
|
||||
}
|
||||
|
||||
static bool comp_wivrn_has_images(struct comp_target * ct)
|
||||
@@ -670,5 +663,6 @@ wivrn_comp_target::wivrn_comp_target(std::shared_ptr<xrt::drivers::wivrn::wivrn_
|
||||
set_title = comp_wivrn_set_title;
|
||||
flush = comp_wivrn_flush;
|
||||
this->fps = fps;
|
||||
desc.fps = fps;
|
||||
this->c = c;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "vk/allocation.h"
|
||||
|
||||
#include "driver/wivrn_pacer.h"
|
||||
#include "encoder/encoder_settings.h"
|
||||
#include <condition_variable>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
@@ -92,6 +93,7 @@ struct wivrn_comp_target : public comp_target
|
||||
os_thread_helper_destroy(&thread);
|
||||
}
|
||||
};
|
||||
std::vector<encoder_settings> settings;
|
||||
to_headset::video_stream_description desc{};
|
||||
std::list<encoder_thread> encoder_threads;
|
||||
std::vector<std::shared_ptr<VideoEncoder>> encoders;
|
||||
|
||||
+54
-51
@@ -214,16 +214,6 @@ wivrn_hmd::wivrn_hmd(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx,
|
||||
|
||||
auto eye_width = info.recommended_eye_width;
|
||||
auto eye_height = info.recommended_eye_height;
|
||||
auto scale = config.scale.value_or(std::array<double, 2>{0.8, 0.8});
|
||||
int foveated_eye_width = info.recommended_eye_width * scale[0];
|
||||
if (foveated_eye_width > 2048 and not config.scale)
|
||||
{
|
||||
scale[1] = scale[0] = 2048. / info.recommended_eye_width;
|
||||
U_LOG_I("Encoded video would be %d wide, setting scale to %f", 2 * foveated_eye_width, scale[0]);
|
||||
foveated_eye_width = info.recommended_eye_width * scale[0];
|
||||
}
|
||||
int foveated_eye_height = info.recommended_eye_height * scale[1];
|
||||
foveated_eye_height += foveated_eye_height % 2;
|
||||
|
||||
// Setup info.
|
||||
hmd->view_count = 2;
|
||||
@@ -231,62 +221,23 @@ wivrn_hmd::wivrn_hmd(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx,
|
||||
hmd->blend_mode_count = 1;
|
||||
hmd->distortion.models = XRT_DISTORTION_MODEL_COMPUTE;
|
||||
hmd->distortion.preferred = XRT_DISTORTION_MODEL_COMPUTE;
|
||||
hmd->screens[0].w_pixels = foveated_eye_width * 2;
|
||||
hmd->screens[0].h_pixels = foveated_eye_height;
|
||||
hmd->screens[0].w_pixels = eye_width * 2;
|
||||
hmd->screens[0].h_pixels = eye_height;
|
||||
hmd->screens[0].nominal_frame_interval_ns = 1000000000 / info.preferred_refresh_rate;
|
||||
|
||||
// Left
|
||||
hmd->views[0].display.w_pixels = eye_width;
|
||||
hmd->views[0].display.h_pixels = eye_height;
|
||||
hmd->views[0].viewport.x_pixels = 0;
|
||||
hmd->views[0].viewport.y_pixels = 0;
|
||||
hmd->views[0].viewport.w_pixels = foveated_eye_width;
|
||||
hmd->views[0].viewport.h_pixels = foveated_eye_height;
|
||||
hmd->views[0].rot = u_device_rotation_ident;
|
||||
|
||||
// Right
|
||||
hmd->views[1].display.w_pixels = eye_width;
|
||||
hmd->views[1].display.h_pixels = eye_height;
|
||||
hmd->views[1].viewport.x_pixels = foveated_eye_width;
|
||||
hmd->views[1].viewport.y_pixels = 0;
|
||||
hmd->views[1].viewport.w_pixels = foveated_eye_width;
|
||||
hmd->views[1].viewport.h_pixels = foveated_eye_height;
|
||||
hmd->views[1].rot = u_device_rotation_ident;
|
||||
|
||||
// FOV from headset info packet
|
||||
hmd->distortion.fov[0] = xrt_cast(info.fov[0]);
|
||||
hmd->distortion.fov[1] = xrt_cast(info.fov[1]);
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
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()
|
||||
@@ -347,6 +298,58 @@ void wivrn_hmd::get_view_poses(const xrt_vec3 * default_eye_relation,
|
||||
}
|
||||
}
|
||||
|
||||
decltype(wivrn_hmd::foveation_parameters) wivrn_hmd::set_foveated_size(uint32_t width, uint32_t height)
|
||||
{
|
||||
assert(width % 2 == 0);
|
||||
uint32_t eye_width = width / 2;
|
||||
std::array<double, 2> scale{
|
||||
double(eye_width) / hmd->views[0].display.w_pixels,
|
||||
double(height) / hmd->views[0].display.h_pixels,
|
||||
};
|
||||
|
||||
hmd->screens[0].w_pixels = width;
|
||||
hmd->screens[0].h_pixels = height;
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
auto & view = hmd->views[i];
|
||||
view.viewport.x_pixels = i * eye_width;
|
||||
view.viewport.y_pixels = 0;
|
||||
|
||||
view.viewport.w_pixels = eye_width;
|
||||
view.viewport.h_pixels = height;
|
||||
|
||||
foveation_parameters[i].x.scale = scale[0];
|
||||
foveation_parameters[i].y.scale = scale[1];
|
||||
|
||||
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);
|
||||
return foveation_parameters;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Functions
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "view_list.h"
|
||||
#include "wivrn_session.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -66,8 +67,5 @@ public:
|
||||
|
||||
void update_tracking(const from_headset::tracking &, const clock_offset &);
|
||||
|
||||
const auto & get_foveation_parameters()
|
||||
{
|
||||
return foveation_parameters;
|
||||
}
|
||||
decltype(foveation_parameters) set_foveated_size(uint32_t width, uint32_t height);
|
||||
};
|
||||
|
||||
@@ -292,9 +292,9 @@ 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()
|
||||
std::array<to_headset::video_stream_description::foveation_parameter, 2> wivrn_session::set_foveated_size(uint32_t width, uint32_t height)
|
||||
{
|
||||
return hmd->get_foveation_parameters();
|
||||
return hmd->set_foveated_size(width, height);
|
||||
}
|
||||
|
||||
void wivrn_session::dump_time(const std::string & event, uint64_t frame, uint64_t time, uint8_t stream, const char * extra)
|
||||
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
connection.send_control(std::forward<T>(packet));
|
||||
}
|
||||
|
||||
std::array<to_headset::video_stream_description::foveation_parameter, 2> get_foveation_parameters();
|
||||
std::array<to_headset::video_stream_description::foveation_parameter, 2> set_foveated_size(uint32_t width, uint32_t height);
|
||||
|
||||
void dump_time(const std::string & event, uint64_t frame, uint64_t time, uint8_t stream = -1, const char * extra = "");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user