diff --git a/docs/configuration.md b/docs/configuration.md index cf59f1b2..137f2e01 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -123,7 +123,13 @@ Creates a hardware encoder for left eye, and a software encoder for right eye. Creates two hardware encoders, one for left eye and one for right eye, executed sequentially as they have the same `group`. This allows the left eye image to be encoded faster than the full image would be, so network transfer starts earlier, and decoding starts earlier. While the total encoding, transfer and decoding time remain the same or are longer, this can reduce the latency. -### `options` (very advanced) +### `device`, only for vaapi +Default value: unset + +Manually specify the device for encoding, can be used to offload encode to an iGPU. Device shall be in the form "/dev/dri/renderD128". + + +### `options` (very advanced), only for vaapi Default value: unset Json object of additional options to pass directly to ffmpeg `avcodec_open2`'s `option` parameter. diff --git a/server/driver/configuration.cpp b/server/driver/configuration.cpp index 39430ed6..59dff3b7 100644 --- a/server/driver/configuration.cpp +++ b/server/driver/configuration.cpp @@ -105,6 +105,7 @@ configuration configuration::read_user_configuration() if (e.codec == xrt::drivers::wivrn::video_codec(-1)) throw std::runtime_error("invalid codec value " + encoder["codec"].get()); SET_IF(options); + SET_IF(device); result.encoders.push_back(e); } } diff --git a/server/driver/configuration.h b/server/driver/configuration.h index 798f06f2..e0811b83 100644 --- a/server/driver/configuration.h +++ b/server/driver/configuration.h @@ -39,6 +39,7 @@ struct configuration std::optional group; std::optional codec; std::map options; + std::optional device; }; std::vector encoders; diff --git a/server/encoder/encoder_settings.cpp b/server/encoder/encoder_settings.cpp index 9e6884ad..c7a5b646 100644 --- a/server/encoder/encoder_settings.cpp +++ b/server/encoder/encoder_settings.cpp @@ -107,6 +107,7 @@ std::vector xrt::drivers::wivrn::get_encoder_settings(vk::Phys settings.codec = encoder.codec.value_or(xrt::drivers::wivrn::h264); settings.group = encoder.group.value_or(next_group); settings.options = encoder.options; + settings.device = encoder.device; next_group = std::max(next_group, settings.group + 1); res.push_back(settings); diff --git a/server/encoder/encoder_settings.h b/server/encoder/encoder_settings.h index 5969c93f..0f0cabb1 100644 --- a/server/encoder/encoder_settings.h +++ b/server/encoder/encoder_settings.h @@ -36,6 +36,7 @@ struct encoder_settings : public to_headset::video_stream_description::item std::map options; // additional encoder-specific configuration // encoders in the same group are executed in sequence int group = 0; + std::optional device; }; std::vector get_encoder_settings(vk::PhysicalDevice physical_device, uint16_t width, uint16_t height); diff --git a/server/encoder/ffmpeg/video_encoder_va.cpp b/server/encoder/ffmpeg/video_encoder_va.cpp index 94c3d759..5a3cb7ab 100644 --- a/server/encoder/ffmpeg/video_encoder_va.cpp +++ b/server/encoder/ffmpeg/video_encoder_va.cpp @@ -94,11 +94,11 @@ get_render_device(vk::raii::PhysicalDevice & physical_device) return path; } -av_buffer_ptr make_drm_hw_ctx(vk::raii::PhysicalDevice & physical_device) +av_buffer_ptr make_drm_hw_ctx(vk::raii::PhysicalDevice & physical_device, const std::optional& device) { - const auto device = get_render_device(physical_device); + const auto render_device = device ? *device : get_render_device(physical_device); AVBufferRef * hw_ctx; - int err = av_hwdevice_ctx_create(&hw_ctx, AV_HWDEVICE_TYPE_DRM, device ? device->c_str() : NULL, NULL, 0); + int err = av_hwdevice_ctx_create(&hw_ctx, AV_HWDEVICE_TYPE_DRM, render_device ? render_device->c_str() : NULL, NULL, 0); if (err) throw std::system_error(err, av_error_category(), "FFMPEG drm hardware context creation failed"); return av_buffer_ptr(hw_ctx); @@ -127,7 +127,7 @@ vk::Format drm_to_vulkan_fmt(uint32_t drm_fourcc) video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk, xrt::drivers::wivrn::encoder_settings & settings, float fps) : luma(nullptr), chroma(nullptr) { - auto drm_hw_ctx = make_drm_hw_ctx(vk.physical_device); + auto drm_hw_ctx = make_drm_hw_ctx(vk.physical_device, settings.device); AVBufferRef * tmp; int err = av_hwdevice_ctx_create_derived(&tmp, AV_HWDEVICE_TYPE_VAAPI, @@ -296,7 +296,7 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk, xrt::drivers::wivrn::en vk::StructureChain alloc_info{ vk::MemoryAllocateInfo{ .allocationSize = desc->objects[i].size, - .memoryTypeIndex = vk.get_memory_type(memory_props.memoryTypeBits, vk::MemoryPropertyFlagBits::eDeviceLocal), + .memoryTypeIndex = vk.get_memory_type(memory_props.memoryTypeBits, {}), }, vk::MemoryDedicatedAllocateInfo{ .image = *image,