Allow manual vaapi device in settings

This commit is contained in:
Patrick Nicolas
2024-02-19 22:13:21 +01:00
parent ef821996a0
commit 386856c54e
6 changed files with 16 additions and 6 deletions
+7 -1
View File
@@ -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.
+1
View File
@@ -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<std::string>());
SET_IF(options);
SET_IF(device);
result.encoders.push_back(e);
}
}
+1
View File
@@ -39,6 +39,7 @@ struct configuration
std::optional<int> group;
std::optional<xrt::drivers::wivrn::video_codec> codec;
std::map<std::string, std::string> options;
std::optional<std::string> device;
};
std::vector<encoder> encoders;
+1
View File
@@ -107,6 +107,7 @@ std::vector<encoder_settings> 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);
+1
View File
@@ -36,6 +36,7 @@ struct encoder_settings : public to_headset::video_stream_description::item
std::map<std::string, std::string> options; // additional encoder-specific configuration
// encoders in the same group are executed in sequence
int group = 0;
std::optional<std::string> device;
};
std::vector<encoder_settings> get_encoder_settings(vk::PhysicalDevice physical_device, uint16_t width, uint16_t height);
+5 -5
View File
@@ -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<std::string>& 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,