change encode_10bit → bit-depth

This commit is contained in:
galister
2025-07-11 23:09:37 +02:00
committed by xytovl
parent ed32676299
commit ec42db83bc
10 changed files with 66 additions and 50 deletions
+15 -7
View File
@@ -29,6 +29,7 @@
#include <drm_fourcc.h>
#include <filesystem>
#include <libavutil/pixfmt.h>
#include <optional>
#include <unordered_map>
#include <vulkan/vulkan_raii.hpp>
@@ -134,9 +135,10 @@ std::unordered_map<uint32_t, vk::Format> vulkan_drm_format_map_10bit = {
{DRM_FORMAT_RG1616, vk::Format::eR10X6G10X6Unorm2Pack16},
};
vk::Format drm_to_vulkan_fmt(uint32_t drm_fourcc, bool use_10bit)
/// bit_depth not checked, valid values are 8 and 10
vk::Format drm_to_vulkan_fmt(uint32_t drm_fourcc, int bit_depth)
{
if (use_10bit)
if (bit_depth == 10)
return vulkan_drm_format_map_10bit.at(drm_fourcc);
else
return vulkan_drm_format_map.at(drm_fourcc);
@@ -170,11 +172,16 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
{
case video_codec::av1:
case video_codec::h265:
sw_format = settings.use_10bit ? AV_PIX_FMT_P010 : AV_PIX_FMT_NV12;
if (settings.bit_depth == 10)
sw_format = AV_PIX_FMT_P010;
else if (settings.bit_depth == 8)
sw_format = AV_PIX_FMT_NV12;
else
throw std::runtime_error("selected codec only supports 10-bit or 8-bit encoding");
break;
default:
if (settings.use_10bit)
throw std::runtime_error("selected codec does not support 10-bit encoding");
if (settings.bit_depth != 8)
throw std::runtime_error("selected codec only supports 8-bit encoding");
sw_format = AV_PIX_FMT_NV12;
break;
}
@@ -226,7 +233,8 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
av_dict_set(&opts, "rc_mode", "CBR", 0);
break;
case video_codec::h265:
encoder_ctx->profile = settings.use_10bit ? FF_PROFILE_HEVC_MAIN_10 : FF_PROFILE_HEVC_MAIN;
// bit_depth is either 8 or 10 here
encoder_ctx->profile = settings.bit_depth == 10 ? FF_PROFILE_HEVC_MAIN_10 : FF_PROFILE_HEVC_MAIN;
break;
case video_codec::av1:
encoder_ctx->profile = FF_PROFILE_AV1_MAIN;
@@ -309,7 +317,7 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
vk::StructureChain image_create_info{
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = drm_to_vulkan_fmt(desc->layers[i].format, settings.use_10bit),
.format = drm_to_vulkan_fmt(desc->layers[i].format, settings.bit_depth),
.extent = {
.width = uint32_t(drm_frame->width / (i == 0 ? 1 : 2)),
.height = uint32_t(drm_frame->height / (i == 0 ? 1 : 2)),