PR #24085 opened by t-boiko URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24085 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24085.patch
Without ALLOW_ENCODE_PARAMETER_OPTIMIZATIONS and with min CU forced to 8x8, hevc_vulkan keeps a much heavier encode config at common quality levels than h264_vulkan (16x16 macroblocks, no min-CU SPS field). Set the session flag and use min CU 16x16 when CTB >= 32; also fix max_transform_hierarchy_depth_inter assignment. Reporter cmd (1080p testsrc2, quality 1, 1000 frames): before: hevc ~200–317 fps vs higher h264 after: hevc 289/325/358 fps, h264 288/317/359 fps (parity) From 5de6c689204b272d85d0007c1f3ecde2703a3c03 Mon Sep 17 00:00:00 2001 From: Tymur Boiko <[email protected]> Date: Tue, 11 Aug 2026 18:24:18 +0200 Subject: [PATCH] avcodec/vulkan_encode: speed up hevc_vulkan with encode optimizations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without ALLOW_ENCODE_PARAMETER_OPTIMIZATIONS and with min CU forced to 8x8, hevc_vulkan keeps a much heavier encode config at common quality levels than h264_vulkan (16x16 macroblocks, no min-CU SPS field). Set the session flag and use min CU 16x16 when CTB >= 32; also fix max_transform_hierarchy_depth_inter assignment. Reporter cmd (1080p testsrc2, quality 1, 1000 frames): before: hevc ~200–317 fps vs higher h264 after: hevc 289/325/358 fps, h264 288/317/359 fps (parity) --- libavcodec/vulkan_encode.c | 4 +++- libavcodec/vulkan_encode_h265.c | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libavcodec/vulkan_encode.c b/libavcodec/vulkan_encode.c index 3a2cf101f4..bc18be0d7f 100644 --- a/libavcodec/vulkan_encode.c +++ b/libavcodec/vulkan_encode.c @@ -1058,7 +1058,9 @@ av_cold int ff_vulkan_encode_init(AVCodecContext *avctx, FFVulkanEncodeContext * /* Create session */ session_create.pVideoProfile = &ctx->profile; - session_create.flags = 0x0; + /* Allow the implementation to optimize codec parameters for the selected + * quality level (e.g. CU size). Matches typical encode-sample usage. */ + session_create.flags = VK_VIDEO_SESSION_CREATE_ALLOW_ENCODE_PARAMETER_OPTIMIZATIONS_BIT_KHR; session_create.queueFamilyIndex = ctx->qf_enc->idx; session_create.maxCodedExtent = ctx->caps.maxCodedExtent; session_create.maxDpbSlots = ctx->caps.maxDpbSlots; diff --git a/libavcodec/vulkan_encode_h265.c b/libavcodec/vulkan_encode_h265.c index 7ed0fdbe77..942866a465 100644 --- a/libavcodec/vulkan_encode_h265.c +++ b/libavcodec/vulkan_encode_h265.c @@ -793,14 +793,21 @@ static av_cold int init_sequence_headers(AVCodecContext *avctx) else if (enc->caps.transformBlockSizes & VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_4_BIT_KHR) max_tb_size = 4; - units->raw_sps.log2_min_luma_coding_block_size_minus3 = 0; - units->raw_sps.log2_diff_max_min_luma_coding_block_size = av_log2(max_ctb_size) - 3; + /* Prefer 16x16 min CU when the CTB is at least 32; 8x8 min CU is much + * more expensive on some implementations for the common quality levels. */ + if (max_ctb_size >= 32) { + units->raw_sps.log2_min_luma_coding_block_size_minus3 = 1; + units->raw_sps.log2_diff_max_min_luma_coding_block_size = av_log2(max_ctb_size) - 4; + } else { + units->raw_sps.log2_min_luma_coding_block_size_minus3 = 0; + units->raw_sps.log2_diff_max_min_luma_coding_block_size = av_log2(max_ctb_size) - 3; + } units->raw_sps.log2_min_luma_transform_block_size_minus2 = av_log2(min_tb_size) - 2; units->raw_sps.log2_diff_max_min_luma_transform_block_size = av_log2(max_tb_size) - av_log2(min_tb_size); max_transform_hierarchy = av_log2(max_ctb_size) - av_log2(min_tb_size); units->raw_sps.max_transform_hierarchy_depth_intra = max_transform_hierarchy; - units->raw_sps.max_transform_hierarchy_depth_intra = max_transform_hierarchy; + units->raw_sps.max_transform_hierarchy_depth_inter = max_transform_hierarchy; units->raw_sps.vui.bitstream_restriction_flag = 0; units->raw_sps.vui.max_bytes_per_pic_denom = 2; -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
