diff --git a/server/driver/configuration.cpp b/server/driver/configuration.cpp index de8ea32b..1de229dd 100644 --- a/server/driver/configuration.cpp +++ b/server/driver/configuration.cpp @@ -147,7 +147,6 @@ configuration::encoder parse_encoder(const nlohmann::json & item) SET_IF(codec); if (e.codec == wivrn::video_codec(-1)) throw std::runtime_error("invalid codec value " + item["codec"].get()); - SET_IF(use_10bit); SET_IF(options); SET_IF(device); return e; @@ -201,6 +200,9 @@ configuration::configuration() if (auto it = json.find("use-steamvr-lh"); it != json.end()) use_steamvr_lh = *it; + if (auto it = json.find("encode_10bit"); it != json.end()) + encode_10bit = *it; + if (auto it = json.find("tcp-only"); it != json.end()) tcp_only = *it; else if (auto it = json.find("tcp_only"); it != json.end()) diff --git a/server/driver/configuration.h b/server/driver/configuration.h index 67e2178a..d0629c61 100644 --- a/server/driver/configuration.h +++ b/server/driver/configuration.h @@ -50,7 +50,6 @@ struct configuration std::optional offset_y; std::optional group; std::optional codec; - std::optional use_10bit; std::map options; std::optional device; }; @@ -63,6 +62,7 @@ struct configuration std::vector application; bool debug_gui = false; bool use_steamvr_lh = false; + bool encode_10bit = false; bool tcp_only = false; service_publication publication = service_publication::avahi; diff --git a/server/encoder/encoder_settings.cpp b/server/encoder/encoder_settings.cpp index 5209e11a..36ce53da 100644 --- a/server/encoder/encoder_settings.cpp +++ b/server/encoder/encoder_settings.cpp @@ -144,7 +144,7 @@ static constexpr auto ffmpeg_version() return result; } -static std::optional filter_codecs_vaapi(wivrn_vk_bundle & bundle, const std::vector & codecs) +static std::optional filter_codecs_vaapi(wivrn_vk_bundle & bundle, const std::vector & codecs, bool use_10bit) { video_encoder_ffmpeg::mute_logs mute; encoder_settings s{ @@ -159,6 +159,12 @@ static std::optional filter_codecs_vaapi(wivrn_vk_bundle & b }; for (auto codec: codecs) { + if (codec == wivrn::video_codec::h264) + { + U_LOG_D("Will not use h264: 10-bit not supported"); + continue; + } + if constexpr (ffmpeg_version()[0] < 6) { if (codec == wivrn::video_codec::h264) @@ -212,14 +218,16 @@ static bool probe_nvenc(wivrn_vk_bundle & bundle) } #endif -static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector & headset_codecs, configuration::encoder & config) +static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector & headset_codecs, configuration::encoder & config, bool encode_10bit) { if (config.name.empty()) { if (is_nvidia(*bundle.physical_device)) { #if WIVRN_USE_NVENC - if (probe_nvenc(bundle)) + if (encode_10bit) + U_LOG_W("cannot use nvenc due to missing 10-bit support (disable 10-bit to use nvenc)"); + else if (probe_nvenc(bundle)) config.name = encoder_nvenc; else #else @@ -227,8 +235,13 @@ static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector get_encoder_default_settings(wivrn_vk_bundle & bundle, const std::vector & headset_codecs) +static std::vector get_encoder_default_settings(wivrn_vk_bundle & bundle, const std::vector & headset_codecs, bool encode_10bit) { configuration::encoder base; - fill_defaults(bundle, headset_codecs, base); + fill_defaults(bundle, headset_codecs, base, encode_10bit); #ifdef WIVRN_SPLIT_ENCODERS if (base.name != encoder_x264 and base.name != encoder_nvenc) @@ -337,7 +361,7 @@ std::vector get_encoder_settings(wivrn_vk_bundle & bundle, uin { configuration config; if (config.encoders.empty()) - config.encoders = get_encoder_default_settings(bundle, info.supported_codecs); + config.encoders = get_encoder_default_settings(bundle, info.supported_codecs, config.encode_10bit); if (not config.encoder_passthrough) config.encoder_passthrough.emplace(); @@ -345,7 +369,7 @@ std::vector get_encoder_settings(wivrn_vk_bundle & bundle, uin config.encoder_passthrough->height = 1; config.encoder_passthrough->offset_x = 0; config.encoder_passthrough->offset_y = 0; - fill_defaults(bundle, info.supported_codecs, *config.encoder_passthrough); + fill_defaults(bundle, info.supported_codecs, *config.encoder_passthrough, config.encode_10bit); uint64_t bitrate = config.bitrate.value_or(default_bitrate); std::array default_scale; @@ -363,29 +387,13 @@ std::vector get_encoder_settings(wivrn_vk_bundle & bundle, uin for (auto & encoder: config.encoders) { - fill_defaults(bundle, info.supported_codecs, encoder); + fill_defaults(bundle, info.supported_codecs, encoder, config.encode_10bit); assert(encoder.codec); check_scale(encoder.name, *encoder.codec, std::ceil(encoder.width.value_or(1) * width), std::ceil(encoder.height.value_or(1) * height), scale); - if (maybe_10bit.has_value()) - { - if (maybe_10bit.value() != encoder.use_10bit) - throw std::runtime_error("all encoders must use the same 10-bit setting"); - } - else - maybe_10bit = *encoder.use_10bit; - } - - // TODO: detach alpha into separate vkImage. - // for now, if the main encoder is 10-bit, we also force alpha to be 10-bit - if (maybe_10bit.value_or(false) && !*config.encoder_passthrough->use_10bit) - { - config.encoder_passthrough->name = config.encoders[0].name; - config.encoder_passthrough->codec = config.encoders[0].codec; - config.encoder_passthrough->use_10bit = true; } width = align(width * scale[0], 64); @@ -418,7 +426,7 @@ std::vector get_encoder_settings(wivrn_vk_bundle & bundle, uin settings.video_width = settings.width; settings.video_height = settings.height; settings.codec = *encoder.codec; - settings.use_10bit = *encoder.use_10bit; + settings.use_10bit = config.encode_10bit; if (encoder.group) settings.group = *encoder.group; else @@ -449,7 +457,7 @@ std::vector get_encoder_settings(wivrn_vk_bundle & bundle, uin settings.video_width = settings.width; settings.video_height = settings.height; settings.codec = *encoder.codec; - settings.use_10bit = *encoder.use_10bit; + settings.use_10bit = config.encode_10bit; if (encoder.group) settings.group = *encoder.group; else