Revert "Merge branch 'master' of https://github.com/Vindicus999/WiVRn"

This reverts commit 6212dccc2b, reversing
changes made to 80e31b642a.
This commit is contained in:
Vindicus999
2025-08-24 09:56:21 -04:00
parent 6212dccc2b
commit ea45e9f91b
135 changed files with 2784 additions and 12225 deletions
+55 -55
View File
@@ -23,14 +23,12 @@
#include "encoder/video_encoder.h"
#include "util/u_logging.h"
#include "utils/scoped_lock.h"
#include "wivrn_config.h"
#include "wivrn_foveation.h"
#include "main/comp_compositor.h"
#include "math/m_space.h"
#include "xrt_cast.h"
#include <algorithm>
#include <vector>
#include <vulkan/vulkan.hpp>
#include <vulkan/vulkan_core.h>
@@ -60,9 +58,6 @@ std::vector<const char *> wivrn_comp_target::wanted_device_extensions = {
#ifdef VK_KHR_video_encode_queue
VK_KHR_VIDEO_ENCODE_QUEUE_EXTENSION_NAME,
#endif
#ifdef VK_KHR_video_maintenance1
VK_KHR_VIDEO_MAINTENANCE_1_EXTENSION_NAME,
#endif
#ifdef VK_KHR_video_encode_h264
VK_KHR_VIDEO_ENCODE_H264_EXTENSION_NAME,
#endif
@@ -193,51 +188,56 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
cn->images = U_TYPED_ARRAY_CALLOC(struct comp_target_image, cn->image_count);
vk::StructureChain image_info{
vk::ImageCreateInfo{
.flags = vk::ImageCreateFlagBits::eExtendedUsage | vk::ImageCreateFlagBits::eMutableFormat,
.imageType = vk::ImageType::e2D,
.format = format,
.extent = {
.width = cn->width,
.height = cn->height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 2, // colour then alpha
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = flags | vk::ImageUsageFlagBits::eStorage | vk::ImageUsageFlagBits::eTransferSrc,
.sharingMode = vk::SharingMode::eExclusive,
},
vk::ImageFormatListCreateInfo{
.viewFormatCount = formats.size(),
.pViewFormats = formats.data(),
},
};
#if WIVRN_USE_VULKAN_ENCODE
if (
vk->features.video_maintenance_1 and
std::ranges::any_of(
cn->settings,
[](const auto & item) { return item.encoder_name == encoder_vulkan //
and item.offset_x == 0 and item.offset_y == 0; }))
{
image_info.get().flags |= vk::ImageCreateFlagBits::eVideoProfileIndependentKHR;
image_info.get().usage |= vk::ImageUsageFlagBits::eVideoEncodeSrcKHR;
}
auto [video_profiles, encoder_flags] = video_encoder::get_create_image_info(cn->settings);
vk::VideoProfileListInfoKHR video_profile_list{
.profileCount = uint32_t(video_profiles.size()),
.pProfiles = video_profiles.data(),
};
#endif
cn->psc.images.resize(cn->image_count);
for (uint32_t i = 0; i < cn->image_count; i++)
{
vk::ImageFormatListCreateInfo formats_info{
.viewFormatCount = formats.size(),
.pViewFormats = formats.data(),
};
#if WIVRN_USE_VULKAN_ENCODE
if (video_profile_list.profileCount)
formats_info.pNext = &video_profile_list;
#endif
auto & image = cn->psc.images[i].image;
image = image_allocation(
device,
image_info.get(),
{.usage = VMA_MEMORY_USAGE_AUTO},
std::format("comp target image {}", i));
device, {
.pNext = &formats_info,
.flags = vk::ImageCreateFlagBits::eExtendedUsage | vk::ImageCreateFlagBits::eMutableFormat,
.imageType = vk::ImageType::e2D,
.format = format,
.extent = {
.width = cn->width,
.height = cn->height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 2, // colour then alpha
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = flags
#if WIVRN_USE_VULKAN_ENCODE
| encoder_flags
#endif
| vk::ImageUsageFlagBits::eStorage | vk::ImageUsageFlagBits::eTransferSrc,
.sharingMode = vk::SharingMode::eExclusive,
},
{
.usage = VMA_MEMORY_USAGE_AUTO,
});
cn->images[i].handle = image;
cn->wivrn_bundle->name(vk::Image(image), "comp target image");
}
for (uint32_t i = 0; i < cn->image_count; i++)
@@ -483,6 +483,20 @@ static void comp_wivrn_present_thread(std::stop_token stop_token, wivrn_comp_tar
auto res = vk.device.waitForFences(*cn->psc.fence, true, UINT64_MAX);
// Update encoder status, release image
if ((cn->psc.status &= ~status_bit) == 0)
{
cn->psc.status.notify_all();
for (auto & img: cn->psc.images)
{
if (img.status == pseudo_swapchain::status_t::encoding)
{
img.status = pseudo_swapchain::status_t::free;
break;
}
}
}
try
{
for (auto & encoder: encoders)
@@ -499,20 +513,6 @@ static void comp_wivrn_present_thread(std::stop_token stop_token, wivrn_comp_tar
{
// Ignore errors
}
// Update encoder status, release image
if ((cn->psc.status &= ~status_bit) == 0)
{
cn->psc.status.notify_all();
for (auto & img: cn->psc.images)
{
if (img.status == pseudo_swapchain::status_t::encoding)
{
img.status = pseudo_swapchain::status_t::free;
break;
}
}
}
}
}
+74 -75
View File
@@ -37,8 +37,6 @@
namespace wivrn
{
namespace
{
enum wivrn_controller_input_index
{
WIVRN_CONTROLLER_INPUT_INVALID = -1,
@@ -100,7 +98,7 @@ struct input_data
xrt_device_type device;
};
input_data map_input(device_id id)
static input_data map_input(device_id id)
{
switch (id)
{
@@ -249,18 +247,18 @@ input_data map_input(device_id id)
return {WIVRN_CONTROLLER_INPUT_INVALID, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_UNKNOWN};
}
xrt_binding_input_pair simple_input_binding[] = {
static xrt_binding_input_pair simple_input_binding[] = {
{XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_TOUCH_TRIGGER_VALUE},
{XRT_INPUT_SIMPLE_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_TOUCH_GRIP_POSE},
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
};
xrt_binding_output_pair simple_output_binding[] = {
static xrt_binding_output_pair simple_output_binding[] = {
{XRT_OUTPUT_NAME_SIMPLE_VIBRATION, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
};
xrt_binding_input_pair index_input_binding[] = {
static xrt_binding_input_pair index_input_binding[] = {
{XRT_INPUT_INDEX_SYSTEM_CLICK, XRT_INPUT_TOUCH_SYSTEM_CLICK},
{XRT_INPUT_INDEX_SYSTEM_TOUCH, XRT_INPUT_INDEX_SYSTEM_TOUCH},
{XRT_INPUT_INDEX_A_CLICK, XRT_INPUT_TOUCH_A_CLICK},
@@ -282,11 +280,11 @@ xrt_binding_input_pair index_input_binding[] = {
{XRT_INPUT_INDEX_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
};
xrt_binding_output_pair index_output_binding[] = {
static xrt_binding_output_pair index_output_binding[] = {
{XRT_OUTPUT_NAME_INDEX_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
};
xrt_binding_input_pair focus3_input_binding[] = {
static xrt_binding_input_pair focus3_input_binding[] = {
{XRT_INPUT_VIVE_FOCUS3_X_CLICK, XRT_INPUT_TOUCH_X_CLICK},
{XRT_INPUT_VIVE_FOCUS3_Y_CLICK, XRT_INPUT_TOUCH_Y_CLICK},
{XRT_INPUT_VIVE_FOCUS3_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
@@ -307,11 +305,11 @@ xrt_binding_input_pair focus3_input_binding[] = {
{XRT_INPUT_VIVE_FOCUS3_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
};
xrt_binding_output_pair focus3_output_binding[] = {
static xrt_binding_output_pair focus3_output_binding[] = {
{XRT_OUTPUT_NAME_VIVE_FOCUS3_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
};
xrt_binding_input_pair touch_pro_input_binding[] = {
static xrt_binding_input_pair touch_pro_input_binding[] = {
{XRT_INPUT_TOUCH_PRO_X_CLICK, XRT_INPUT_TOUCH_X_CLICK},
{XRT_INPUT_TOUCH_PRO_X_TOUCH, XRT_INPUT_TOUCH_X_TOUCH},
{XRT_INPUT_TOUCH_PRO_Y_CLICK, XRT_INPUT_TOUCH_Y_CLICK},
@@ -339,13 +337,13 @@ xrt_binding_input_pair touch_pro_input_binding[] = {
{XRT_INPUT_TOUCH_PRO_STYLUS_FORCE, XRT_INPUT_TOUCH_PRO_STYLUS_FORCE},
};
xrt_binding_output_pair touch_pro_output_binding[] = {
static xrt_binding_output_pair touch_pro_output_binding[] = {
{XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
{XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_THUMB, XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_THUMB},
{XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_TRIGGER, XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_TRIGGER},
};
xrt_binding_input_pair touch_plus_input_binding[] = {
static xrt_binding_input_pair touch_plus_input_binding[] = {
{XRT_INPUT_TOUCH_PLUS_X_CLICK, XRT_INPUT_TOUCH_X_CLICK},
{XRT_INPUT_TOUCH_PLUS_X_TOUCH, XRT_INPUT_TOUCH_X_TOUCH},
{XRT_INPUT_TOUCH_PLUS_Y_CLICK, XRT_INPUT_TOUCH_Y_CLICK},
@@ -372,11 +370,11 @@ xrt_binding_input_pair touch_plus_input_binding[] = {
{XRT_INPUT_TOUCH_PLUS_TRIGGER_SLIDE, XRT_INPUT_TOUCH_PRO_TRIGGER_SLIDE},
};
xrt_binding_output_pair touch_plus_output_binding[] = {
static xrt_binding_output_pair touch_plus_output_binding[] = {
{XRT_OUTPUT_NAME_TOUCH_PLUS_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
};
xrt_binding_input_pair pico_neo3_input_binding[] = {
static xrt_binding_input_pair pico_neo3_input_binding[] = {
{XRT_INPUT_PICO_NEO3_X_CLICK, XRT_INPUT_TOUCH_X_CLICK},
{XRT_INPUT_PICO_NEO3_X_TOUCH, XRT_INPUT_TOUCH_X_TOUCH},
{XRT_INPUT_PICO_NEO3_Y_CLICK, XRT_INPUT_TOUCH_Y_CLICK},
@@ -399,11 +397,11 @@ xrt_binding_input_pair pico_neo3_input_binding[] = {
{XRT_INPUT_PICO_NEO3_B_TOUCH, XRT_INPUT_TOUCH_B_TOUCH},
};
xrt_binding_output_pair pico_neo3_output_binding[] = {
static xrt_binding_output_pair pico_neo3_output_binding[] = {
{XRT_OUTPUT_NAME_PICO_NEO3_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
};
xrt_binding_input_pair pico4_input_binding[] = {
static xrt_binding_input_pair pico4_input_binding[] = {
{XRT_INPUT_PICO4_X_CLICK, XRT_INPUT_TOUCH_X_CLICK},
{XRT_INPUT_PICO4_X_TOUCH, XRT_INPUT_TOUCH_X_TOUCH},
{XRT_INPUT_PICO4_Y_CLICK, XRT_INPUT_TOUCH_Y_CLICK},
@@ -426,11 +424,11 @@ xrt_binding_input_pair pico4_input_binding[] = {
{XRT_INPUT_PICO4_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
};
xrt_binding_output_pair pico4_output_binding[] = {
static xrt_binding_output_pair pico4_output_binding[] = {
{XRT_OUTPUT_NAME_PICO4_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
};
xrt_binding_profile wivrn_binding_profiles[] = {
static xrt_binding_profile wivrn_binding_profiles[] = {
{
.name = XRT_DEVICE_SIMPLE_CONTROLLER,
.inputs = simple_input_binding,
@@ -482,10 +480,13 @@ xrt_binding_profile wivrn_binding_profiles[] = {
},
};
namespace
{
struct xrt_space_relation_csv_header
{};
} // namespace
std::ostream & operator<<(std::ostream & out, const xrt_space_relation_csv_header &)
static std::ostream & operator<<(std::ostream & out, const xrt_space_relation_csv_header &)
{
for (auto [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
{
@@ -502,7 +503,44 @@ std::ostream & operator<<(std::ostream & out, const xrt_space_relation_csv_heade
out << "avx,avy,avz";
return out;
}
} // namespace
static std::ostream & operator<<(std::ostream & out, const xrt_space_relation & rel)
{
const auto & pos = rel.pose.position;
const auto & o = rel.pose.orientation;
const auto & v = rel.linear_velocity;
const auto & av = rel.angular_velocity;
for (const auto & [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
{
if (value and value != XRT_SPACE_RELATION_BITMASK_ALL)
out << bool(rel.relation_flags & value) << ',';
}
out << pos.x << ',' << pos.y << ',' << pos.z << ',';
out << o.w << ',' << o.x << ',' << o.y << ',' << o.z << ',';
out << v.x << ',' << v.y << ',' << v.z << ',';
out << av.x << ',' << av.y << ',' << av.z;
return out;
}
static std::mutex tracking_dump_mutex;
static std::ofstream & tracking_dump()
{
static auto res = [] {
std::ofstream res;
if (auto wivrn_dump = std::getenv("WIVRN_DUMP_TRACKING"))
{
res.open(wivrn_dump);
res << "device_id,"
"now_ns,"
"timestamp_ns,"
"extrapolation_ns,"
"receive/get,"
<< xrt_space_relation_csv_header{} << std::endl;
}
return res;
}();
return res;
}
wivrn_controller::wivrn_controller(int hand_id,
xrt_device * hmd,
@@ -722,8 +760,9 @@ xrt_result_t wivrn_controller::get_tracked_pose(xrt_input_name name, int64_t at_
return XRT_ERROR_INPUT_UNSUPPORTED;
}
cnx->add_predict_offset(extrapolation_time);
if (auto out = tracking_dump())
if (auto & out = tracking_dump())
{
std::lock_guard lock{tracking_dump_mutex};
auto device = [&] {
switch (name)
{
@@ -734,12 +773,12 @@ xrt_result_t wivrn_controller::get_tracked_pose(xrt_input_name name, int64_t at_
assert(false);
__builtin_unreachable();
} }();
*out->lock() << magic_enum::enum_name(device) << ','
<< os_monotonic_get_ns() << ','
<< at_timestamp_ns << ','
<< extrapolation_time.count() << ','
<< "g,"
<< *res << std::endl;
out << magic_enum::enum_name(device) << ','
<< os_monotonic_get_ns() << ','
<< at_timestamp_ns << ','
<< extrapolation_time.count() << ','
<< "g,"
<< *res << std::endl;
;
}
return XRT_SUCCESS;
@@ -793,19 +832,19 @@ void wivrn_controller::update_tracking(const from_headset::tracking & tracking,
cnx->set_enabled(grip.device, false);
if (not palm.update_tracking(tracking, offset))
cnx->set_enabled(palm.device, false);
if (auto out = tracking_dump(); out and offset)
if (auto & out = tracking_dump(); out and offset)
{
auto locked = out->lock();
std::lock_guard lock{tracking_dump_mutex};
auto now = os_monotonic_get_ns();
for (const auto & pose: tracking.device_poses)
{
if (pose.device == aim.device or pose.device == grip.device or pose.device == palm.device)
*locked << magic_enum::enum_name(pose.device) << ','
<< now << ','
<< offset.from_headset(tracking.timestamp) << ','
<< tracking.timestamp - tracking.production_timestamp << ','
<< "r,"
<< pose_list::convert_pose(pose) << std::endl;
out << magic_enum::enum_name(pose.device) << ','
<< now << ','
<< offset.from_headset(tracking.timestamp) << ','
<< tracking.timestamp - tracking.production_timestamp << ','
<< "r,"
<< pose_list::convert_pose(pose) << std::endl;
}
}
}
@@ -856,44 +895,4 @@ void wivrn_controller::reset_history()
aim.reset();
palm.reset();
}
thread_safe<std::ofstream> * wivrn_controller::tracking_dump()
{
static std::unique_ptr<thread_safe<std::ofstream>> res = [] {
if (auto wivrn_dump = std::getenv("WIVRN_DUMP_TRACKING"))
{
U_LOG_I("Controller tracking dump enabled: %s", wivrn_dump);
std::ofstream res;
res.open(wivrn_dump);
res << "device_id,"
"now_ns,"
"timestamp_ns,"
"extrapolation_ns,"
"receive/get,"
<< xrt_space_relation_csv_header{} << std::endl;
return std::make_unique<thread_safe<std::ofstream>>(std::move(res));
}
return std::unique_ptr<thread_safe<std::ofstream>>();
}();
return res.get();
}
} // namespace wivrn
std::ostream & operator<<(std::ostream & out, const xrt_space_relation & rel)
{
const auto & pos = rel.pose.position;
const auto & o = rel.pose.orientation;
const auto & v = rel.linear_velocity;
const auto & av = rel.angular_velocity;
for (const auto & [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
{
if (value and value != XRT_SPACE_RELATION_BITMASK_ALL)
out << bool(rel.relation_flags & value) << ',';
}
out << pos.x << ',' << pos.y << ',' << pos.z << ',';
out << o.w << ',' << o.x << ',' << o.y << ',' << o.z << ',';
out << v.x << ',' << v.y << ',' << v.z << ',';
out << av.x << ',' << av.y << ',' << av.z;
return out;
}
-7
View File
@@ -23,9 +23,7 @@
#include "hand_joints_list.h"
#include "pose_list.h"
#include "utils/thread_safe.h"
#include <fstream>
#include <mutex>
#include <vector>
@@ -66,10 +64,5 @@ public:
void update_hand_tracking(const from_headset::hand_tracking &, const clock_offset &);
void reset_history();
static thread_safe<std::ofstream> * tracking_dump();
};
} // namespace wivrn
std::ostream & operator<<(std::ostream & out, const xrt_space_relation & rel);
+35 -47
View File
@@ -18,6 +18,7 @@
*/
#include "render/render_interface.h"
#include "vk/vk_mini_helpers.h"
#include "wivrn_foveation.h"
@@ -43,13 +44,22 @@ bool render_distortion_images_ensure(struct render_resources * r,
bool pre_rotate)
{
if (r->distortion.buffer == VK_NULL_HANDLE)
r->distortion.buffer = wivrn::wivrn_foveation::instance().get_gpu_buffer();
{
return vk_buffer_init(vk,
sizeof(render_compute_distortion_foveation_data),
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
&r->distortion.buffer,
&r->distortion.device_memory);
}
return true;
}
void render_distortion_images_fini(struct render_resources * r)
{
r->distortion.buffer = VK_NULL_HANDLE;
auto * vk = r->vk;
D(Buffer, r->distortion.buffer);
DF(Memory, r->distortion.device_memory);
}
// a, b: parameters computed by solve_foveation
@@ -310,34 +320,20 @@ wivrn_foveation::wivrn_foveation(wivrn_vk_bundle & bundle, const xrt_hmd_parts &
.commandPool = *command_pool,
.commandBufferCount = 1,
})[0])),
gpu_buffer(
host_buffer(
bundle.device,
{
.size = sizeof(render_compute_distortion_foveation_data),
.usage = vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eStorageBuffer,
.usage = vk::BufferUsageFlagBits::eTransferSrc,
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT,
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"foveation storage buffer")
})
{
if (not(gpu_buffer.properties() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
{
host_buffer = buffer_allocation(
bundle.device,
{
.size = gpu_buffer.info().size,
.usage = vk::BufferUsageFlagBits::eTransferSrc,
},
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
},
"foveation staging buffer");
}
bundle.name(command_pool, "foveation command pool");
bundle.name(cmd, "foveation command buffer");
bundle.name(vk::Buffer(host_buffer), "foveation staging buffer");
}
void wivrn_foveation::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
@@ -393,7 +389,7 @@ std::array<to_headset::foveation_parameter, 2> wivrn_foveation::get_parameters()
}
static void fill_ubo(
std::span<uint32_t> ubo,
uint32_t * ubo,
const std::vector<uint16_t> & params,
bool flip,
size_t offset,
@@ -402,9 +398,9 @@ static void fill_ubo(
{
assert(params.size() % 2 == 1);
const int n_ratio = (params.size() - 1) / 2;
ubo[0] = offset;
*ubo = offset;
if (flip)
ubo[0] += size;
*ubo += size;
for (auto [i, n]: std::ranges::enumerate_view(params))
{
const int n_source = std::abs(n_ratio - int(i)) + 1;
@@ -415,12 +411,12 @@ static void fill_ubo(
ubo[1] = ubo[0] - n_source;
else
ubo[1] = ubo[0] + n_source;
ubo = ubo.subspan(1);
++ubo;
--count;
}
}
if (not ubo.empty())
std::ranges::fill(ubo, ubo[0]);
if (count > 0)
std::fill(ubo + 1, ubo + count + 1, *ubo);
}
template <typename T>
@@ -438,11 +434,6 @@ static bool operator==(const xrt_fov & a, const xrt_fov & b)
return a.angle_left == b.angle_left and a.angle_right == b.angle_right and a.angle_up == b.angle_up and a.angle_down == b.angle_down;
}
vk::Buffer wivrn_foveation::get_gpu_buffer()
{
return gpu_buffer;
}
vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
vk::Buffer target,
bool flip_y,
@@ -452,6 +443,14 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
if (not target)
return nullptr;
if (target != gpu_buffer)
{
command_pool.reset();
cmd.begin({});
cmd.copyBuffer(host_buffer, target, vk::BufferCopy{.size = sizeof(render_compute_distortion_foveation_data)});
cmd.end();
}
// Check if the last value is still valid
std::lock_guard lock(mutex);
if (last.flip_y == flip_y //
@@ -468,15 +467,6 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
)
return nullptr;
assert(target == gpu_buffer);
if (host_buffer)
{
command_pool.reset();
cmd.begin({});
cmd.copyBuffer(host_buffer, target, vk::BufferCopy{.size = sizeof(render_compute_distortion_foveation_data)});
cmd.end();
}
last = {
.gaze = gaze,
.flip_y = flip_y,
@@ -488,7 +478,7 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
compute_params(source, fovs);
auto ubo = host_buffer ? host_buffer.data<render_compute_distortion_foveation_data>() : gpu_buffer.data<render_compute_distortion_foveation_data>();
auto ubo = (render_compute_distortion_foveation_data *)host_buffer.map();
for (size_t view = 0; view < 2; ++view)
{
bool flip = false;
@@ -505,7 +495,7 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
offset = source[view].offset.w;
extent = source[view].extent.w;
}
fill_ubo(std::span(ubo->x + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, RENDER_FOVEATION_BUFFER_DIMENSIONS), params[view].x, flip, offset, extent, foveated_width);
fill_ubo(ubo->x + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].x, flip, offset, extent, foveated_width);
if (source[view].extent.h < 0)
{
@@ -519,10 +509,8 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
offset = source[view].offset.h;
extent = source[view].extent.h;
}
fill_ubo(std::span(ubo->y + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, RENDER_FOVEATION_BUFFER_DIMENSIONS), params[view].y, flip, offset, extent, foveated_height);
fill_ubo(ubo->y + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].y, flip, offset, extent, foveated_height);
}
if (host_buffer)
return *cmd;
return nullptr;
return *cmd;
}
} // namespace wivrn
+2 -5
View File
@@ -24,7 +24,6 @@
#include "xrt/xrt_defines.h"
#include "xrt/xrt_device.h"
#include "utils/singleton.h"
#include <vulkan/vulkan_raii.hpp>
struct render_resources;
@@ -35,7 +34,7 @@ namespace wivrn
struct clock_offset;
struct wivrn_vk_bundle;
class wivrn_foveation : public singleton<wivrn_foveation>
class wivrn_foveation
{
std::mutex mutex;
@@ -54,8 +53,8 @@ class wivrn_foveation : public singleton<wivrn_foveation>
vk::raii::CommandPool command_pool;
vk::raii::CommandBuffer cmd;
buffer_allocation gpu_buffer;
buffer_allocation host_buffer;
vk::Buffer gpu_buffer = nullptr;
// parameters used for last computation
struct P
@@ -82,8 +81,6 @@ public:
void update_foveation_center_override(const from_headset::override_foveation_center &);
std::array<to_headset::foveation_parameter, 2> get_parameters();
vk::Buffer get_gpu_buffer();
vk::CommandBuffer update_foveation_buffer(
vk::Buffer target,
bool flip_y,
+2 -6
View File
@@ -148,8 +148,7 @@ xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_
{
std::tie(extrapolation_time, *res) = poses.get_pose_at(at_timestamp_ns);
active = true;
cnx.update_tracker_enabled();
cnx.set_tracker_enabled(index, true);
cnx.add_predict_offset(extrapolation_time);
return XRT_SUCCESS;
}
@@ -161,9 +160,6 @@ xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_
void wivrn_generic_tracker::update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset)
{
if (!poses.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset))
{
active = false;
cnx.update_tracker_enabled();
}
cnx.set_tracker_enabled(index, false);
}
} // namespace wivrn
+1 -7
View File
@@ -45,7 +45,6 @@ class wivrn_generic_tracker : public xrt_device
{
tracker_pose_list poses;
xrt_input pose_input;
std::atomic_bool active = false;
wivrn_session & cnx;
int index;
@@ -58,10 +57,5 @@ public:
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
void update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset);
bool is_active()
{
return active;
}
};
} // namespace wivrn
} // namespace wivrn
+76 -33
View File
@@ -31,13 +31,13 @@
#include <numbers>
#include <optional>
#include <fstream>
#include "xrt/xrt_defines.h"
namespace wivrn
{
namespace
{
enum wivrn_hand_interaction_input_index
{
WIVRN_HAND_INTERACTION_INPUT_INVALID = -1,
@@ -73,7 +73,7 @@ struct input_data
xrt_device_type device;
};
input_data map_input(device_id id)
static input_data map_input(device_id id)
{
switch (id)
{
@@ -134,7 +134,7 @@ input_data map_input(device_id id)
return {WIVRN_HAND_INTERACTION_INPUT_INVALID, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_UNKNOWN};
}
xrt_binding_input_pair hand_interaction_input_binding[] = {
static xrt_binding_input_pair hand_interaction_input_binding[] = {
{XRT_INPUT_HAND_GRIP_POSE, XRT_INPUT_HAND_GRIP_POSE},
{XRT_INPUT_HAND_AIM_POSE, XRT_INPUT_HAND_AIM_POSE},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
@@ -147,13 +147,7 @@ xrt_binding_input_pair hand_interaction_input_binding[] = {
{XRT_INPUT_HAND_GRASP_READY, XRT_INPUT_HAND_GRASP_READY},
};
xrt_binding_input_pair simple_input_binding[] = {
{XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_HAND_PINCH_VALUE},
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_HAND_GRIP_POSE},
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_HAND_AIM_POSE},
};
xrt_binding_profile wivrn_binding_profiles[] = {
static xrt_binding_profile wivrn_binding_profiles[] = {
{
.name = XRT_DEVICE_EXT_HAND_INTERACTION,
.inputs = hand_interaction_input_binding,
@@ -161,16 +155,64 @@ xrt_binding_profile wivrn_binding_profiles[] = {
.outputs = nullptr,
.output_count = 0,
},
{
.name = XRT_DEVICE_SIMPLE_CONTROLLER,
.inputs = simple_input_binding,
.input_count = std::size(simple_input_binding),
.outputs = nullptr,
.output_count = 0,
},
};
namespace
{
struct xrt_space_relation_csv_header
{};
} // namespace
static std::ostream & operator<<(std::ostream & out, const xrt_space_relation_csv_header &)
{
for (auto [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
{
if (value and value != XRT_SPACE_RELATION_BITMASK_ALL)
{
name = name.substr(strlen("XRT_SPACE_RELATION_"));
name = name.substr(0, name.size() - strlen("_BIT"));
out << name << ",";
}
}
out << "x,y,z,";
out << "qw,qx,qy,qz";
return out;
}
static std::ostream & operator<<(std::ostream & out, const xrt_space_relation & rel)
{
const auto & pos = rel.pose.position;
const auto & o = rel.pose.orientation;
for (const auto & [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
{
if (value and value != XRT_SPACE_RELATION_BITMASK_ALL)
out << bool(rel.relation_flags & value) << ',';
}
out << pos.x << ',' << pos.y << ',' << pos.z << ',';
out << o.w << ',' << o.x << ',' << o.y << ',' << o.z;
return out;
}
static std::mutex tracking_dump_mutex;
static std::ofstream & tracking_dump()
{
static auto res = [] {
std::ofstream res;
if (auto wivrn_dump = std::getenv("WIVRN_DUMP_TRACKING"))
{
res.open(wivrn_dump);
res << "device_id,"
"now_ns,"
"timestamp_ns,"
"extrapolation_ns,"
"receive/get,"
<< xrt_space_relation_csv_header{} << std::endl;
}
return res;
}();
return res;
}
wivrn_hand_interaction::wivrn_hand_interaction(int hand_id,
xrt_device * hmd,
wivrn::wivrn_session * cnx) :
@@ -355,8 +397,9 @@ xrt_result_t wivrn_hand_interaction::get_tracked_pose(xrt_input_name name, int64
return XRT_ERROR_INPUT_UNSUPPORTED;
}
cnx->add_predict_offset(extrapolation_time);
if (auto out = wivrn_controller::tracking_dump())
if (auto & out = tracking_dump())
{
std::lock_guard lock{tracking_dump_mutex};
auto device = [&] {
switch (name)
{
@@ -369,12 +412,12 @@ xrt_result_t wivrn_hand_interaction::get_tracked_pose(xrt_input_name name, int64
assert(false);
__builtin_unreachable();
} }();
*out->lock() << magic_enum::enum_name(device) << ','
<< os_monotonic_get_ns() << ','
<< at_timestamp_ns << ','
<< extrapolation_time.count() << ','
<< "g,"
<< *res << std::endl;
out << magic_enum::enum_name(device) << ','
<< os_monotonic_get_ns() << ','
<< at_timestamp_ns << ','
<< extrapolation_time.count() << ','
<< "g,"
<< *res << std::endl;
;
}
return XRT_SUCCESS;
@@ -412,19 +455,19 @@ void wivrn_hand_interaction::update_tracking(const from_headset::tracking & trac
cnx->set_enabled(pinch_ext.device, false);
if (not poke_ext.update_tracking(tracking, offset))
cnx->set_enabled(poke_ext.device, false);
if (auto out = wivrn_controller::tracking_dump(); out and offset)
if (auto & out = tracking_dump(); out and offset)
{
std::lock_guard lock{tracking_dump_mutex};
auto now = os_monotonic_get_ns();
auto locked = out->lock();
for (const auto & pose: tracking.device_poses)
{
if (pose.device == aim.device or pose.device == grip.device or pose.device == palm.device)
*locked << magic_enum::enum_name(pose.device) << ','
<< now << ','
<< offset.from_headset(tracking.timestamp) << ','
<< tracking.timestamp - tracking.production_timestamp << ','
<< "r,"
<< pose_list::convert_pose(pose) << std::endl;
out << magic_enum::enum_name(pose.device) << ','
<< now << ','
<< offset.from_headset(tracking.timestamp) << ','
<< tracking.timestamp - tracking.production_timestamp << ','
<< "r,"
<< pose_list::convert_pose(pose) << std::endl;
}
}
}
+23 -66
View File
@@ -28,7 +28,6 @@
#include "util/u_builders.h"
#include "util/u_logging.h"
#include "util/u_system.h"
#include "utils/load_icon.h"
#include "utils/scoped_lock.h"
#include "audio/audio_setup.h"
@@ -172,12 +171,6 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
throw;
}
(*this)(from_headset::get_application_list{
.language = get_info().language,
.country = get_info().country,
.variant = get_info().variant,
});
static_roles.head = xdevs[xdev_count++] = &hmd;
if (hmd.supported.face_tracking)
@@ -240,31 +233,24 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
xdevs[xdev_count++] = htc_face_tracker.get();
}
auto num_generic_trackers = get_info().num_generic_trackers;
generic_trackers.reserve(num_generic_trackers);
num_generic_trackers = get_info().num_generic_trackers;
enabled_trackers.fill(false);
if (num_generic_trackers > 0)
{
if (num_generic_trackers > from_headset::body_tracking::max_tracked_poses)
{
U_LOG_W("reported generic trackers %d larger than maximum %lu",
num_generic_trackers,
from_headset::body_tracking::max_tracked_poses);
num_generic_trackers = from_headset::body_tracking::max_tracked_poses;
}
if (num_generic_trackers + xdev_count > std::size(xdevs))
{
U_LOG_W("Too many generic trackers: %d, only %lu will be active",
num_generic_trackers,
std::size(xdevs) - xdev_count);
num_generic_trackers = std::size(xdevs) - xdev_count;
}
U_LOG_I("Creating %d generic trackers", num_generic_trackers);
if (num_generic_trackers > generic_trackers.size())
throw std::out_of_range(
std::format("{} generic trackers is larger than maximum {}",
num_generic_trackers,
generic_trackers.size()));
for (int i = 0; i < num_generic_trackers; ++i)
{
auto dev = std::make_unique<wivrn_generic_tracker>(i, &hmd, *this);
xdevs[xdev_count++] = dev.get();
generic_trackers.push_back(std::move(dev));
generic_trackers[i] = std::move(dev);
enabled_trackers[i] = true;
}
}
@@ -549,10 +535,12 @@ void wivrn_session::operator()(from_headset::body_tracking && body_tracking)
{
auto offset = offset_est.get_offset();
assert(generic_trackers.size() <= from_headset::body_tracking::max_tracked_poses);
for (int i = 0; i < generic_trackers.size(); i++)
for (int i = 0; i < num_generic_trackers; i++)
{
auto pose = body_tracking.poses ? (*body_tracking.poses)[i] : from_headset::body_tracking::pose{};
auto pose = body_tracking.poses ? body_tracking.poses->at(i) : from_headset::body_tracking::pose{
.pose = {},
.flags = 0,
};
generic_trackers[i]->update_tracking(body_tracking, pose, offset);
}
}
@@ -617,10 +605,12 @@ void wivrn_session::set_enabled(device_id id, bool enabled)
if (tracking_control.set_enabled(to_tracking_control(id), enabled) and enabled)
tracking_control.send(*connection, true);
}
void wivrn_session::update_tracker_enabled()
void wivrn_session::set_tracker_enabled(int index, bool enabled)
{
bool active = std::ranges::any_of(generic_trackers, [](auto & t) { return t->is_active(); });
if (tracking_control.set_enabled(to_headset::tracking_control::id::generic_tracker, active) and active)
assert(index < std::size(enabled_trackers));
enabled_trackers[index] = enabled;
bool keep_active = std::ranges::any_of(enabled_trackers, [](bool b) { return b; });
if (tracking_control.set_enabled(to_headset::tracking_control::id::generic_tracker, keep_active))
tracking_control.send(*connection, true);
}
@@ -746,48 +736,15 @@ void wivrn_session::operator()(from_headset::get_application_list && request)
.country = std::move(request.country),
.variant = std::move(request.variant),
};
auto apps = list_applications();
for (const auto & [id, app]: apps)
for (auto && [id, app]: list_applications())
{
response.applications.emplace_back(
std::move(id),
// FIXME: use locale
app.name.at(""));
app.name.at(""),
app.image);
}
send_control(std::move(response));
for (const auto & [id, app]: apps)
{
if (app.icon_path)
{
try
{
const auto & icons = load_icon(*app.icon_path);
if (icons.empty())
continue;
const auto & largest_icon = std::ranges::max(icons, [](const wivrn::icon & a, const wivrn::icon & b) {
if (a.bpp < b.bpp)
return true;
if (a.bpp > b.bpp)
return false;
return a.width * a.height < b.width * b.height;
});
send_control(to_headset::application_icon{
.id = id,
.image = largest_icon.png_data,
});
}
catch (std::exception & e)
{
U_LOG_W("Error loading icon %s: %s", app.icon_path->c_str(), e.what());
}
}
}
}
void wivrn_session::operator()(const from_headset::start_app & request)
+8 -4
View File
@@ -105,8 +105,6 @@ class wivrn_session : public xrt_system_devices
.gamepad = -1,
};
tracking_control_t tracking_control;
wivrn_hmd hmd;
wivrn_controller left_controller;
int32_t left_controller_index;
@@ -119,13 +117,19 @@ class wivrn_session : public xrt_system_devices
std::unique_ptr<wivrn_eye_tracker> eye_tracker;
std::unique_ptr<wivrn_fb_face2_tracker> fb_face2_tracker;
std::unique_ptr<wivrn_htc_face_tracker> htc_face_tracker;
std::vector<std::unique_ptr<wivrn_generic_tracker>> generic_trackers;
uint32_t num_generic_trackers;
std::array<std::unique_ptr<wivrn_generic_tracker>, from_headset::body_tracking::max_tracked_poses> generic_trackers;
std::array<bool, from_headset::body_tracking::max_tracked_poses> enabled_trackers;
std::shared_mutex comp_target_mutex;
wivrn_comp_target * comp_target;
clock_offset_estimator offset_est;
// prediction offset and enabled tracking to configure client
tracking_control_t tracking_control;
std::mutex tracking_control_mutex;
std::mutex csv_mutex;
std::ofstream feedback_csv;
@@ -165,7 +169,7 @@ public:
void set_enabled(to_headset::tracking_control::id id, bool enabled);
void set_enabled(device_id id, bool enabled);
void update_tracker_enabled();
void set_tracker_enabled(int index, bool enabled);
void operator()(from_headset::crypto_handshake &&) {}
void operator()(from_headset::pin_check_1 &&) {}
+26
View File
@@ -180,6 +180,32 @@ std::unique_ptr<video_encoder> video_encoder::create(
return res;
}
#if WIVRN_USE_VULKAN_ENCODE
std::pair<std::vector<vk::VideoProfileInfoKHR>, vk::ImageUsageFlags> video_encoder::get_create_image_info(const std::vector<encoder_settings> & settings)
{
std::pair<std::vector<vk::VideoProfileInfoKHR>, vk::ImageUsageFlags> result;
for (const auto & item: settings)
{
if (item.encoder_name == encoder_vulkan)
{
result.second |= vk::ImageUsageFlagBits::eVideoEncodeSrcKHR;
switch (item.codec)
{
case h264:
result.first.push_back(video_encoder_vulkan_h264::video_profile_info.get());
break;
case h265:
// result.first.push_back(video_encoder_vulkan_h265::video_profile_info.get());
break;
case av1:
throw std::runtime_error("av1 not supported for vulkan video encode");
}
}
}
return result;
}
#endif
static const uint64_t idr_throttle = 100;
video_encoder::video_encoder(uint8_t stream_idx, to_headset::video_stream_description::channels_t channels, double bitrate_multiplier, bool async_send) :
+5
View File
@@ -20,6 +20,7 @@
#pragma once
#include "driver/clock_offset.h"
#include "wivrn_config.h"
#include "wivrn_packets.h"
#include <atomic>
@@ -113,6 +114,10 @@ public:
int input_height,
float fps);
#if WIVRN_USE_VULKAN_ENCODE
static std::pair<std::vector<vk::VideoProfileInfoKHR>, vk::ImageUsageFlags> get_create_image_info(const std::vector<encoder_settings> &);
#endif
video_encoder(uint8_t stream_idx, to_headset::video_stream_description::channels_t channels, double bitrate_multiplier, bool async_send);
virtual ~video_encoder();
+10 -12
View File
@@ -15,8 +15,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "vk/vk_helpers.h"
#include "video_encoder_vulkan.h"
#include "encoder/encoder_settings.h"
@@ -176,8 +174,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
img_create_info,
{
.usage = VMA_MEMORY_USAGE_AUTO,
},
"vulkan encoder DPB image");
});
vk.name(vk::Image(dpb_image), "vulkan encoder DPB image");
}
// Output buffer
@@ -195,8 +193,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"vulkan encode output buffer");
});
vk.name(vk::Buffer(item.output_buffer), "vulkan encode output buffer");
if (not(item.output_buffer.properties() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
{
@@ -208,8 +206,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"vulkan encode host buffer");
});
vk.name(vk::Buffer(item.host_buffer), "vulkan encode host buffer");
}
}
@@ -268,7 +266,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
.layerCount = 1},
};
if (rect.offset != vk::Offset2D{0, 0} or not vk.vk.features.video_maintenance_1)
if (rect.offset != vk::Offset2D{0, 0})
{
image_view_template.subresourceRange.baseArrayLayer = 0;
for (size_t i = 0; i < num_slots; ++i)
@@ -292,8 +290,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
},
{
.usage = VMA_MEMORY_USAGE_AUTO,
},
"vulkan encoder temporary image");
});
vk.name(vk::Image(slot_data[i].tmp_image), "vulkan encoder temporary image");
image_view_template.image = vk::Image(slot_data[i].tmp_image);
slot_data[i].view = vk.device.createImageView(image_view_template);
vk.name(slot_data[i].view, "vulkan encoder temporary image view");
@@ -480,7 +478,7 @@ std::pair<bool, vk::Semaphore> wivrn::video_encoder_vulkan::present_image(vk::Im
video_cmd_buf.begin({.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit});
// If we encode from top left corner, encode from the source image directly
bool encode_direct = not slot_item.tmp_image;
bool encode_direct = rect.offset == vk::Offset2D{0, 0};
vk::ImageView image_view;
+2 -1
View File
@@ -80,9 +80,10 @@ class video_encoder_vulkan : public video_encoder
bool session_initialized = false;
const vk::Rect2D rect;
vk::VideoEncodeRateControlLayerInfoKHR rate_control_layer;
protected:
const uint8_t num_dpb_slots;
vk::VideoEncodeRateControlLayerInfoKHR rate_control_layer;
std::optional<vk::VideoEncodeRateControlInfoKHR> rate_control;
video_encoder_vulkan(wivrn_vk_bundle & vk,
+23 -45
View File
@@ -169,47 +169,6 @@ std::vector<void *> wivrn::video_encoder_vulkan_h264::setup_slot_info(size_t dpb
return res;
}
auto get_video_caps(vk::raii::PhysicalDevice & phys_dev)
{
vk::StructureChain video_profile_info{
vk::VideoProfileInfoKHR{
.videoCodecOperation =
vk::VideoCodecOperationFlagBitsKHR::eEncodeH264,
.chromaSubsampling = vk::VideoChromaSubsamplingFlagBitsKHR::e420,
.lumaBitDepth = vk::VideoComponentBitDepthFlagBitsKHR::e8,
.chromaBitDepth = vk::VideoComponentBitDepthFlagBitsKHR::e8,
},
vk::VideoEncodeH264ProfileInfoKHR{
.stdProfileIdc = STD_VIDEO_H264_PROFILE_IDC_BASELINE,
},
vk::VideoEncodeUsageInfoKHR{
.videoUsageHints = vk::VideoEncodeUsageFlagBitsKHR::eStreaming,
.videoContentHints = vk::VideoEncodeContentFlagBitsKHR::eRendered,
.tuningMode = vk::VideoEncodeTuningModeKHR::eUltraLowLatency,
}};
try
{
auto [video_caps, encode_caps, encode_h264_caps] =
phys_dev.getVideoCapabilitiesKHR<
vk::VideoCapabilitiesKHR,
vk::VideoEncodeCapabilitiesKHR,
vk::VideoEncodeH264CapabilitiesKHR>(video_profile_info.get());
return std::make_tuple(video_caps, encode_caps, encode_h264_caps, video_profile_info);
}
catch (...)
{}
// NVIDIA fails if the structure is there
video_profile_info.unlink<vk::VideoEncodeUsageInfoKHR>();
auto [video_caps, encode_caps, encode_h264_caps] =
phys_dev.getVideoCapabilitiesKHR<
vk::VideoCapabilitiesKHR,
vk::VideoEncodeCapabilitiesKHR,
vk::VideoEncodeH264CapabilitiesKHR>(video_profile_info.get());
return std::make_tuple(video_caps, encode_caps, encode_h264_caps, video_profile_info);
}
std::unique_ptr<wivrn::video_encoder_vulkan_h264> wivrn::video_encoder_vulkan_h264::create(
wivrn_vk_bundle & vk,
encoder_settings & settings,
@@ -227,11 +186,15 @@ std::unique_ptr<wivrn::video_encoder_vulkan_h264> wivrn::video_encoder_vulkan_h2
},
};
auto [video_caps, encode_caps, encode_h264_caps] =
vk.physical_device.getVideoCapabilitiesKHR<
vk::VideoCapabilitiesKHR,
vk::VideoEncodeCapabilitiesKHR,
vk::VideoEncodeH264CapabilitiesKHR>(video_profile_info.get());
if (settings.bit_depth != 8)
throw std::runtime_error("h264 codec only supports 8-bit encoding");
auto [video_caps, encode_caps, encode_h264_caps, video_profile_info] = get_video_caps(vk.physical_device);
std::unique_ptr<video_encoder_vulkan_h264> self(new video_encoder_vulkan_h264(vk, rect, video_caps, encode_caps, fps, stream_idx, settings));
vk::VideoEncodeH264SessionParametersAddInfoKHR h264_add_info{};
@@ -264,8 +227,6 @@ std::unique_ptr<wivrn::video_encoder_vulkan_h264> wivrn::video_encoder_vulkan_h2
self->rate_control->pNext = &self->rate_control_h264;
}
self->rate_control_layer.pNext = &self->rate_control_layer_h264;
self->init(video_caps, video_profile_info.get(), &session_create_info, &h264_session_params);
return self;
@@ -398,3 +359,20 @@ vk::ExtensionProperties wivrn::video_encoder_vulkan_h264::std_header_version()
VK_STD_VULKAN_VIDEO_CODEC_H264_ENCODE_EXTENSION_NAME);
return std_header_version;
}
decltype(wivrn::video_encoder_vulkan_h264::video_profile_info) wivrn::video_encoder_vulkan_h264::video_profile_info = vk::StructureChain{
vk::VideoProfileInfoKHR{
.videoCodecOperation =
vk::VideoCodecOperationFlagBitsKHR::eEncodeH264,
.chromaSubsampling = vk::VideoChromaSubsamplingFlagBitsKHR::e420,
.lumaBitDepth = vk::VideoComponentBitDepthFlagBitsKHR::e8,
.chromaBitDepth = vk::VideoComponentBitDepthFlagBitsKHR::e8,
},
vk::VideoEncodeH264ProfileInfoKHR{
.stdProfileIdc = STD_VIDEO_H264_PROFILE_IDC_BASELINE,
},
vk::VideoEncodeUsageInfoKHR{
.videoUsageHints = vk::VideoEncodeUsageFlagBitsKHR::eStreaming,
.videoContentHints = vk::VideoEncodeContentFlagBitsKHR::eRendered,
.tuningMode = vk::VideoEncodeTuningModeKHR::eUltraLowLatency,
}};
+2 -1
View File
@@ -46,7 +46,6 @@ class video_encoder_vulkan_h264 : public video_encoder_vulkan
vk::VideoEncodeH264GopRemainingFrameInfoKHR gop_info;
vk::VideoEncodeH264RateControlInfoKHR rate_control_h264;
vk::VideoEncodeH264RateControlLayerInfoKHR rate_control_layer_h264;
video_encoder_vulkan_h264(wivrn_vk_bundle & vk,
vk::Rect2D rect,
@@ -71,5 +70,7 @@ public:
uint8_t stream_idx);
std::vector<uint8_t> get_sps_pps();
static const vk::StructureChain<vk::VideoProfileInfoKHR, vk::VideoEncodeH264ProfileInfoKHR, vk::VideoEncodeUsageInfoKHR> video_profile_info;
};
} // namespace wivrn
+4 -4
View File
@@ -168,8 +168,7 @@ video_encoder_x264::video_encoder_x264(
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"x264 luma buffer");
});
i.chroma = buffer_allocation(
vk.device, {
.size = vk::DeviceSize(settings.video_width * settings.video_height / 2),
@@ -178,8 +177,9 @@ video_encoder_x264::video_encoder_x264(
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"x264 chroma buffer");
});
vk.name(vk::Buffer(i.luma), "x264 luma buffer");
vk.name(vk::Buffer(i.chroma), "x264 chroma buffer");
auto & pic = i.pic;
x264_picture_init(&pic);
+32 -34
View File
@@ -18,6 +18,7 @@
#include "hostname.h"
#include "protocol_version.h"
#include "start_application.h"
#include "utils/flatpak.h"
#include "utils/overloaded.h"
#include "version.h"
#include "wivrn_config.h"
@@ -127,37 +128,46 @@ int create_listen_socket()
return fd;
}
static bool pressure_vessel_openxr_support()
static std::filesystem::path flatpak_app_path()
{
auto pv_var = std::getenv("PRESSURE_VESSEL_IMPORT_OPENXR_1_RUNTIMES");
return pv_var and pv_var == std::string_view("1");
}
if (auto value = flatpak_key(flatpak::section::instance, "app-path"))
{
std::filesystem::path path = *value;
while (path != "" and path != path.parent_path() and path.filename() != "io.github.wivrn.wivrn")
path = path.parent_path();
static void append_delim(std::string & to, std::string_view what, char delim)
{
if (not to.empty())
to += delim;
to += what;
return path;
}
return "/";
}
static std::string steam_command()
{
std::string command;
std::string pressure_vessel_filesystems_rw = "$XDG_RUNTIME_DIR/" XRT_IPC_MSG_SOCK_FILENAME;
std::string vr_override;
if (not pressure_vessel_openxr_support())
command = "PRESSURE_VESSEL_IMPORT_OPENXR_1_RUNTIMES=1";
if (auto p = active_runtime::openvr_compat_path().string(); not p.empty())
// Check if in a flatpak
if (is_flatpak())
{
std::string app_path = flatpak_app_path().string();
// /usr and /var are remapped by steam
if (app_path.starts_with("/var"))
pressure_vessel_filesystems_rw += ":" + app_path;
}
else if (auto p = active_runtime::openvr_compat_path().string(); not p.empty())
{
// /usr cannot be shared in pressure vessel container
if (p.starts_with("/usr"))
append_delim(command, " VR_OVERRIDE=/run/host" + p, ' ');
vr_override = " VR_OVERRIDE=/run/host" + p;
else if (p.starts_with("/var"))
append_delim(command, "PRESSURE_VESSEL_FILESYSTEMS_RW=" + p, ' ');
pressure_vessel_filesystems_rw += ":" + p;
}
if (not command.empty())
command += " %command%";
std::string command = "PRESSURE_VESSEL_FILESYSTEMS_RW=" + pressure_vessel_filesystems_rw + vr_override + " %command%";
if (auto p = active_runtime::manifest_path().string(); p.starts_with("/usr"))
command = "XR_RUNTIME_JSON=/run/host" + p + " " + command;
return command;
}
@@ -425,7 +435,7 @@ gboolean headset_connected_success(void *)
}
catch (std::exception & e)
{
std::cerr << "Failed to start application: " << e.what() << std::endl;
std::cerr << "Failed to start application: " << e.what();
}
delay_next_try = default_delay_next_try;
@@ -678,18 +688,14 @@ void on_json_configuration(WivrnServer * server, const GParamSpec * pspec, gpoin
std::filesystem::path config_new = config;
config_new += ".new";
{
std::ofstream file(config_new);
file.write(json, strlen(json));
}
std::ofstream file(config_new);
file.write(json, strlen(json));
std::error_code ec;
std::filesystem::rename(config_new, config, ec);
if (ec)
std::cerr << "Failed to save configuration: " << ec.message() << std::endl;
wivrn_server_set_steam_command(dbus_server, steam_command().c_str());
}
void expose_known_keys_on_dbus()
@@ -878,8 +884,7 @@ int inner_main(int argc, char * argv[], bool show_instructions)
std::cerr << "WiVRn " << wivrn::git_version << " starting" << std::endl;
if (show_instructions)
{
if (auto command = steam_command(); not command.empty())
std::cerr << "For Steam games, set command to " << command << std::endl;
std::cerr << "For Steam games, set command to " << steam_command() << std::endl;
}
std::filesystem::create_directories(socket_path().parent_path());
@@ -969,7 +974,6 @@ int main(int argc, char * argv[])
std::string config_file;
app.add_option("-f", config_file, "configuration file")->option_text("FILE")->check(CLI::ExistingFile);
auto version_flag = app.add_flag("--version")->description("print version and exit");
auto no_active_runtime = app.add_flag("--no-manage-active-runtime")->description("don't set the active runtime on connection");
auto early_active_runtime = app.add_flag("--early-active-runtime")->description("forcibly manages the active runtime even if no headset present");
auto no_instructions = app.add_flag("--no-instructions")->group("");
@@ -982,12 +986,6 @@ int main(int argc, char * argv[])
CLI11_PARSE(app, argc, argv);
if (*version_flag)
{
std::cout << "WiVRn version " << wivrn::git_version << std::endl;
return 0;
}
if (not config_file.empty())
configuration::set_config_file(config_file);
+5 -16
View File
@@ -19,7 +19,6 @@
#include "start_systemd_unit.h"
#include "systemd_manager.h"
#include "systemd_unit.h"
#include "utils/strings.h"
#include <gio/gio.h>
#include <glib-object.h>
#include <iostream>
@@ -212,10 +211,11 @@ void systemd_units_manager::start_application(const std::vector<std::string> & a
variant_builder argv(G_VARIANT_TYPE("as"));
for (const auto & arg: args)
g_variant_builder_add(&argv, "s", arg.c_str());
auto exec_start = g_variant_new("(s@asb)",
args.front().c_str(),
g_variant_new("as", &argv),
false);
auto exec_start =
g_variant_new("(s@asb)",
args.front().c_str(),
g_variant_new("as", &argv),
false);
g_variant_builder_add(&b,
"(sv)",
"ExecStart",
@@ -224,17 +224,6 @@ void systemd_units_manager::start_application(const std::vector<std::string> & a
&exec_start,
1));
if (auto path = std::getenv("PATH"))
{
variant_builder pathv(G_VARIANT_TYPE("as"));
for (auto item: utils::split(path, ":"))
g_variant_builder_add(&pathv, "s", item.c_str());
g_variant_builder_add(&b,
"(sv)",
"ExecSearchPath",
g_variant_new("as", &pathv));
}
auto properties = b.end();
auto aux = g_variant_new_array(G_VARIANT_TYPE("(sa(sv))"), nullptr, 0);
+5 -6
View File
@@ -83,12 +83,11 @@ wivrn::wivrn_vk_bundle::wivrn_vk_bundle(vk_bundle & vk, std::span<const char *>
physical_device(instance, vk.physical_device),
device(physical_device, vk.device),
allocator({
.physicalDevice = vk.physical_device,
.device = vk.device,
.instance = vk.instance,
.vulkanApiVersion = VK_MAKE_VERSION(1, 3, 0), // FIXME: sync with wivrn_session.cpp
},
vk.has_EXT_debug_utils),
.physicalDevice = vk.physical_device,
.device = vk.device,
.instance = vk.instance,
.vulkanApiVersion = VK_MAKE_VERSION(1, 3, 0), // FIXME: sync with wivrn_session.cpp
}),
queue(device, vk.queue_family_index, vk.queue_index),
queue_family_index(vk.queue_family_index),
#ifdef VK_KHR_video_encode_queue