diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b205141..8f7af377 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -project(WiVRn VERSION 1.0 LANGUAGES C CXX) +project(WiVRn VERSION 1.0.0 LANGUAGES C CXX) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) @@ -78,7 +78,7 @@ FetchContent_Declare(tinygltf URL https://github.com/syoyo/tinygltf/archive/refs FetchContent_Declare(boostpfr URL https://github.com/boostorg/pfr/archive/refs/tags/2.0.3.tar.gz) FetchContent_Declare(monado GIT_REPOSITORY https://gitlab.freedesktop.org/monado/monado - GIT_TAG e9475b13137db2cca8571576b5381a70fb8180a5 + GIT_TAG e39e0ee5ffc6b961dd51a556c83fe5e7f76822d8 ) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 40eb95f2..0572cb5d 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -1,23 +1,25 @@ -set(XRT_BUILD_DRIVER_ARDUINO OFF) -set(XRT_BUILD_DRIVER_DAYDREAM OFF) -set(XRT_BUILD_DRIVER_EUROC OFF) -set(XRT_BUILD_DRIVER_HDK OFF) -set(XRT_BUILD_DRIVER_HYDRA OFF) -set(XRT_BUILD_DRIVER_NS OFF) -set(XRT_BUILD_DRIVER_OHMD OFF) -set(XRT_BUILD_DRIVER_OPENGLOVES OFF) -set(XRT_BUILD_DRIVER_PSMV OFF) -set(XRT_BUILD_DRIVER_PSVR OFF) -set(XRT_BUILD_DRIVER_QWERTY OFF) -set(XRT_BUILD_DRIVER_REMOTE OFF) -set(XRT_BUILD_DRIVER_RIFT_S OFF) -set(XRT_BUILD_DRIVER_SIMULATED ON) -set(XRT_BUILD_DRIVER_TWRAP OFF) -set(XRT_BUILD_DRIVER_VF OFF) -set(XRT_BUILD_DRIVER_VIVE OFF) -set(XRT_BUILD_DRIVER_WMR OFF) -set(XRT_BUILD_SAMPLES OFF) +set(XRT_BUILD_DRIVER_ARDUINO OFF) +set(XRT_BUILD_DRIVER_DAYDREAM OFF) +set(XRT_BUILD_DRIVER_EUROC OFF) +set(XRT_BUILD_DRIVER_HDK OFF) +set(XRT_BUILD_DRIVER_HYDRA OFF) +set(XRT_BUILD_DRIVER_NS OFF) +set(XRT_BUILD_DRIVER_OHMD OFF) +set(XRT_BUILD_DRIVER_OPENGLOVES OFF) +set(XRT_BUILD_DRIVER_PSMV OFF) +set(XRT_BUILD_DRIVER_PSSENSE OFF) +set(XRT_BUILD_DRIVER_PSVR OFF) +set(XRT_BUILD_DRIVER_QWERTY OFF) +set(XRT_BUILD_DRIVER_REMOTE OFF) +set(XRT_BUILD_DRIVER_RIFT_S OFF) +set(XRT_BUILD_DRIVER_SIMULATED ON) +set(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE OFF) +set(XRT_BUILD_DRIVER_TWRAP OFF) +set(XRT_BUILD_DRIVER_VF OFF) +set(XRT_BUILD_DRIVER_VIVE OFF) +set(XRT_BUILD_DRIVER_WMR OFF) +set(XRT_BUILD_SAMPLES OFF) set(XRT_FEATURE_COMPOSITOR_NULL OFF) set(XRT_FEATURE_SERVICE ON) diff --git a/server/driver/video_encoder.cpp b/server/driver/video_encoder.cpp index 3824d449..4797f686 100644 --- a/server/driver/video_encoder.cpp +++ b/server/driver/video_encoder.cpp @@ -40,6 +40,7 @@ namespace xrt::drivers::wivrn std::unique_ptr VideoEncoder::Create( vk_bundle * vk, + vk_cmd_pool & pool, encoder_settings & settings, uint8_t stream_idx, int input_width, @@ -51,7 +52,7 @@ std::unique_ptr VideoEncoder::Create( #ifdef WIVRN_HAVE_X264 if (settings.encoder_name == encoder_x264) { - res = std::make_unique(vk, settings, input_width, input_height, fps); + res = std::make_unique(vk, pool, settings, input_width, input_height, fps); } #endif #ifdef WIVRN_HAVE_CUDA diff --git a/server/driver/video_encoder.h b/server/driver/video_encoder.h index e651ac09..4cf4468a 100644 --- a/server/driver/video_encoder.h +++ b/server/driver/video_encoder.h @@ -19,6 +19,7 @@ #pragma once +#include "vk/vk_cmd_pool.h" #include "vk/vk_helpers.h" #include #include @@ -40,8 +41,10 @@ inline const char * encoder_x264 = "x264"; class VideoEncoder { std::mutex mutex; + protected: uint8_t stream_idx; + private: uint64_t frame_idx; @@ -52,6 +55,7 @@ private: public: static std::unique_ptr Create(vk_bundle * vk, + vk_cmd_pool & pool, encoder_settings & settings, uint8_t stream_idx, int input_width, diff --git a/server/driver/video_encoder_x264.cpp b/server/driver/video_encoder_x264.cpp index 3d709edd..32b8707c 100644 --- a/server/driver/video_encoder_x264.cpp +++ b/server/driver/video_encoder_x264.cpp @@ -82,6 +82,7 @@ void VideoEncoderX264::InsertInPendingNal(pending_nal && nal) VideoEncoderX264::VideoEncoderX264( vk_bundle * vk, + vk_cmd_pool & pool, encoder_settings & settings, int input_width, int input_height, @@ -100,6 +101,7 @@ VideoEncoderX264::VideoEncoderX264( converter = std::make_unique( vk, + pool, VkExtent3D{uint32_t(settings.video_width), uint32_t(settings.video_height), 1}, settings.offset_x, settings.offset_y, diff --git a/server/driver/video_encoder_x264.h b/server/driver/video_encoder_x264.h index 94490498..6ab787af 100644 --- a/server/driver/video_encoder_x264.h +++ b/server/driver/video_encoder_x264.h @@ -51,7 +51,7 @@ class VideoEncoderX264 : public VideoEncoder std::list pending_nals; public: - VideoEncoderX264(vk_bundle * vk, encoder_settings & settings, int input_width, int input_height, float fps); + VideoEncoderX264(vk_bundle * vk, vk_cmd_pool & pool, encoder_settings & settings, int input_width, int input_height, float fps); void SetImages(int width, int height, diff --git a/server/driver/wivrn_comp_target.cpp b/server/driver/wivrn_comp_target.cpp index 55e06302..c0a2046b 100644 --- a/server/driver/wivrn_comp_target.cpp +++ b/server/driver/wivrn_comp_target.cpp @@ -22,6 +22,8 @@ #include "math/m_space.h" #include "util/u_pacing.h" #include "video_encoder.h" +#include "vk/vk_cmd.h" +#include "vk/vk_cmd_pool.h" #include "xrt/xrt_config_have.h" #include "xrt_cast.h" #include @@ -53,6 +55,8 @@ struct wivrn_comp_target : public comp_target //! Compositor frame pacing helper struct u_pacing_compositor * upc{}; + vk_cmd_pool pool; + float fps; int64_t current_frame_id; @@ -116,7 +120,7 @@ static void destroy_images(struct wivrn_comp_target * cn) vk->vkDestroyImageView(vk->device, cn->images[i].view, NULL); vk->vkDestroyImage(vk->device, cn->images[i].handle, NULL); vk->vkFreeMemory(vk->device, cn->psc.images[i].memory, NULL); - vk->vkFreeCommandBuffers(vk->device, vk->cmd_pool, 1, &cn->psc.images[i].present_cmd); + vk->vkFreeCommandBuffers(vk->device, cn->pool.pool, 1, &cn->psc.images[i].present_cmd); } free(cn->images); @@ -154,7 +158,7 @@ static void create_encoders(wivrn_comp_target * cn, std::vectorencoders.size(); auto & encoder = cn->encoders.emplace_back( - VideoEncoder::Create(vk, settings, stream_index, desc.width, desc.height, desc.fps)); + VideoEncoder::Create(vk, cn->pool, settings, stream_index, desc.width, desc.height, desc.fps)); desc.items.push_back(settings); std::vector images(cn->image_count); @@ -304,11 +308,10 @@ static VkResult create_images(struct wivrn_comp_target * cn, VkImageUsageFlags f createinfo.flags = 0; res = vk->vkCreateFence(vk->device, &createinfo, NULL, &cn->psc.images[i].fence); - vk_check_error("vkCreateFence", res, res); - res = vk_cmd_buffer_create_and_begin(vk, &cn->psc.images[i].present_cmd); - vk_check_error("vk_cmd_buffer_create_and_begin", res, res); + res = vk_cmd_pool_create_and_begin_cmd_buffer(vk, &cn->pool, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, &cn->psc.images[i].present_cmd); + vk_check_error("vk_cmd_pool_create_and_begin_cmd_buffer", res, res); VkImageSubresourceRange first_color_level_subresource_range{ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, @@ -333,7 +336,10 @@ static bool comp_wivrn_init_pre_vulkan(struct comp_target * ct) static bool comp_wivrn_init_post_vulkan(struct comp_target * ct, uint32_t preferred_width, uint32_t preferred_height) { - return true; + struct wivrn_comp_target * cn = (struct wivrn_comp_target *)ct; + + auto res = vk_cmd_pool_init(get_vk(cn), &cn->pool, 0); + return not vk_has_error(res, "vk_cmd_pool_init", __FILE__, __LINE__); } static bool comp_wivrn_check_ready(struct comp_target * ct) @@ -456,7 +462,7 @@ static VkResult comp_wivrn_acquire(struct comp_target * ct, uint32_t * out_index submit.signalSemaphoreCount = 1; submit.pSignalSemaphores = &cn->semaphores.present_complete; - VkResult res = vk_locked_submit(vk, vk->queue, 1, &submit, VK_NULL_HANDLE); + VkResult res = vk_cmd_pool_submit(vk, &cn->pool, 1, &submit, VK_NULL_HANDLE); vk_check_error("vk_locked_submit", res, res); res = VK_ERROR_OUT_OF_HOST_MEMORY; @@ -523,7 +529,8 @@ static void * comp_wivrn_present_thread(void * void_param) } VkResult res = vk->vkWaitForFences(vk->device, nb_fences, fences.data(), VK_TRUE, UINT64_MAX); - if (nb_fences > 1) { + if (nb_fences > 1) + { U_LOG_I("Encoder group %d dropped %d frames", param->thread->index, nb_fences - 1); } vk_check_error("vkWaitForFences", res, NULL); @@ -601,7 +608,7 @@ static VkResult comp_wivrn_present(struct comp_target * ct, std::lock_guard lock(cn->psc.mutex); VkResult res = vk->vkResetFences(vk->device, 1, &cn->psc.images[index].fence); vk_check_error("vkResetFences", res, res); - res = vk_locked_submit(vk, vk->queue, 1, &submit, cn->psc.images[index].fence); + res = vk_cmd_pool_submit(vk, &cn->pool, 1, &submit, cn->psc.images[index].fence); vk_check_error("vk_locked_submit", res, res); assert(cn->psc.images[index].status == image_acquired); @@ -734,7 +741,7 @@ static void comp_wivrn_info_gpu(struct comp_target * ct, int64_t frame_id, uint6 * */ -comp_target * comp_target_wivrn_create(std::shared_ptr cnx, struct comp_compositor* c, float fps) +comp_target * comp_target_wivrn_create(std::shared_ptr cnx, struct comp_compositor * c, float fps) { wivrn_comp_target * cn = new wivrn_comp_target{}; diff --git a/server/driver/yuv_converter.cpp b/server/driver/yuv_converter.cpp index 40418f00..0c497998 100644 --- a/server/driver/yuv_converter.cpp +++ b/server/driver/yuv_converter.cpp @@ -128,8 +128,8 @@ static void destroy_all(YuvConverter * ptr) throw std::runtime_error(fun "failed"); \ } while (0) -YuvConverter::YuvConverter(vk_bundle * vk, VkExtent3D extent, int offset_x, int offset_y, int input_width, int input_height) : - vk(*vk) +YuvConverter::YuvConverter(vk_bundle * vk, vk_cmd_pool & pool, VkExtent3D extent, int offset_x, int offset_y, int input_width, int input_height) : + vk(*vk), pool(pool) { std::unique_ptr deleter(this, destroy_all); @@ -365,8 +365,8 @@ void YuvConverter::SetImages(int num_images, VkImage * images, VkImageView * vie vk.vkUpdateDescriptorSets(vk.device, 1, &descriptorWrite, 0, nullptr); VkCommandBuffer cmdBuffer; - res = vk_cmd_buffer_create_and_begin(&vk, &cmdBuffer); - vk_check_throw("vk_cmd_buffer_create_and_begin", res); + res = vk_cmd_pool_create_and_begin_cmd_buffer(&vk, &pool, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, &cmdBuffer); + vk_check_throw("vk_cmd_pool_create_and_begin_cmd_buffer", res); for (auto & comp: {y, uv}) { diff --git a/server/driver/yuv_converter.h b/server/driver/yuv_converter.h index 7a6ee460..0aec44ad 100644 --- a/server/driver/yuv_converter.h +++ b/server/driver/yuv_converter.h @@ -19,6 +19,7 @@ #pragma once +#include "vk/vk_cmd_pool.h" #include "vk/vk_helpers.h" #include #include @@ -42,6 +43,7 @@ public: int stride; }; vk_bundle & vk; + vk_cmd_pool & pool; image_bundle y; image_bundle uv; VkSampler sampler = VK_NULL_HANDLE; @@ -55,7 +57,7 @@ public: std::vector command_buffers; std::vector descriptor_sets; - YuvConverter(vk_bundle * vk, VkExtent3D extent, int offset_x, int offset_y, int input_width, int input_height); + YuvConverter(vk_bundle * vk, vk_cmd_pool & pool, VkExtent3D extent, int offset_x, int offset_y, int input_width, int input_height); ~YuvConverter(); void SetImages(int num_images, VkImage * images, VkImageView * views);