diff mbox series

[FFmpeg-devel] vulkan_encode: set the quality level in session parameters

Message ID 20240920113317.760007-1-vjaquez@igalia.com
State New
Headers show
Series [FFmpeg-devel] vulkan_encode: set the quality level in session parameters | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Víctor Manuel Jáquez Leal Sept. 20, 2024, 11:33 a.m. UTC
While running this command

./ffmpeg_g -loglevel debug -hwaccel vulkan -init_hw_device vulkan=vk:0,debug=1 -hwaccel_output_format vulkan -i input.y4m -vf 'format=nv12,hwupload' -c:v h264_vulkan -quality 2 output.mp4 -y

It hit this validation error:

Validation Error: [ VUID-vkCmdEncodeVideoKHR-None-08318 ] Object 0: handle =
0x8f000000008f, type = VK_OBJECT_TYPE_VIDEO_SESSION_KHR; Object 1: handle =
0xfd00000000fd, type = VK_OBJECT_TYPE_VIDEO_SESSION_PARAMETERS_KHR;
| MessageID = 0x5dc3dd39
| vkCmdEncodeVideoKHR(): The currently configured encode quality level (2) for
VkVideoSessionKHR 0x8f000000008f[] does not match the encode quality level (0)
VkVideoSessionParametersKHR 0xfd00000000fd[] was created with. The Vulkan spec
states: The bound video session parameters object must have been created with
the currently set video encode quality level for the bound video session at the
time the command is executed on the
device (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdEncodeVideoKHR-None-08318)

This patch sets the quality level at session parameter creation for both H.264
and H.265 Vulkan encoders.
---
 libavcodec/vulkan_encode_h264.c | 8 +++++++-
 libavcodec/vulkan_encode_h265.c | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

Comments

Lynne Sept. 20, 2024, 5:25 p.m. UTC | #1
On 20/09/2024 13:33, Víctor Manuel Jáquez Leal wrote:
> While running this command
> 
> ./ffmpeg_g -loglevel debug -hwaccel vulkan -init_hw_device vulkan=vk:0,debug=1 -hwaccel_output_format vulkan -i input.y4m -vf 'format=nv12,hwupload' -c:v h264_vulkan -quality 2 output.mp4 -y
> 
> It hit this validation error:
> 
> Validation Error: [ VUID-vkCmdEncodeVideoKHR-None-08318 ] Object 0: handle =
> 0x8f000000008f, type = VK_OBJECT_TYPE_VIDEO_SESSION_KHR; Object 1: handle =
> 0xfd00000000fd, type = VK_OBJECT_TYPE_VIDEO_SESSION_PARAMETERS_KHR;
> | MessageID = 0x5dc3dd39
> | vkCmdEncodeVideoKHR(): The currently configured encode quality level (2) for
> VkVideoSessionKHR 0x8f000000008f[] does not match the encode quality level (0)
> VkVideoSessionParametersKHR 0xfd00000000fd[] was created with. The Vulkan spec
> states: The bound video session parameters object must have been created with
> the currently set video encode quality level for the bound video session at the
> time the command is executed on the
> device (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdEncodeVideoKHR-None-08318)
> 
> This patch sets the quality level at session parameter creation for both H.264
> and H.265 Vulkan encoders.
> ---
>   libavcodec/vulkan_encode_h264.c | 8 +++++++-
>   libavcodec/vulkan_encode_h265.c | 8 +++++++-
>   2 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/vulkan_encode_h264.c b/libavcodec/vulkan_encode_h264.c
> index af229afe52..4b78e6f43d 100644
> --- a/libavcodec/vulkan_encode_h264.c
> +++ b/libavcodec/vulkan_encode_h264.c
> @@ -1016,6 +1016,7 @@ static int create_session_params(AVCodecContext *avctx)
>       VkVideoEncodeH264SessionParametersAddInfoKHR h264_params_info;
>       VkVideoEncodeH264SessionParametersCreateInfoKHR h264_params;
>       VkVideoSessionParametersCreateInfoKHR session_params_create;
> +    VkVideoEncodeQualityLevelInfoKHR q_info;
>   
>       /* Convert it to Vulkan */
>       err = base_unit_to_vk(avctx, &vk_units);
> @@ -1044,9 +1045,14 @@ static int create_session_params(AVCodecContext *avctx)
>           .maxStdPPSCount = 1,
>           .pParametersAddInfo = &h264_params_info,
>       };
> +    q_info = (VkVideoEncodeQualityLevelInfoKHR) {
> +        .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_QUALITY_LEVEL_INFO_KHR,
> +        .pNext = &h264_params,
> +        .qualityLevel = ctx->opts.quality,
> +    };
>       session_params_create = (VkVideoSessionParametersCreateInfoKHR) {
>           .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
> -        .pNext = &h264_params,
> +        .pNext = &q_info,
>           .videoSession = ctx->common.session,
>           .videoSessionParametersTemplate = NULL,
>       };
> diff --git a/libavcodec/vulkan_encode_h265.c b/libavcodec/vulkan_encode_h265.c
> index 3cb7a3b7df..f1e61ab894 100644
> --- a/libavcodec/vulkan_encode_h265.c
> +++ b/libavcodec/vulkan_encode_h265.c
> @@ -1166,6 +1166,7 @@ static int create_session_params(AVCodecContext *avctx)
>       VkVideoEncodeH265SessionParametersAddInfoKHR h265_params_info;
>       VkVideoEncodeH265SessionParametersCreateInfoKHR h265_params;
>       VkVideoSessionParametersCreateInfoKHR session_params_create;
> +    VkVideoEncodeQualityLevelInfoKHR q_info;
>   
>       /* Convert it to Vulkan */
>       err = base_unit_to_vk(avctx, &vk_units);
> @@ -1197,9 +1198,14 @@ static int create_session_params(AVCodecContext *avctx)
>           .maxStdVPSCount = 1,
>           .pParametersAddInfo = &h265_params_info,
>       };
> +    q_info = (VkVideoEncodeQualityLevelInfoKHR) {
> +        .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_QUALITY_LEVEL_INFO_KHR,
> +        .pNext = &h265_params,
> +        .qualityLevel = ctx->opts.quality,
> +    };
>       session_params_create = (VkVideoSessionParametersCreateInfoKHR) {
>           .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
> -        .pNext = &h265_params,
> +        .pNext = &q_info,
>           .videoSession = ctx->common.session,
>           .videoSessionParametersTemplate = NULL,
>       };

Could you move this to vulkan_encode.c?
Thanks
diff mbox series

Patch

diff --git a/libavcodec/vulkan_encode_h264.c b/libavcodec/vulkan_encode_h264.c
index af229afe52..4b78e6f43d 100644
--- a/libavcodec/vulkan_encode_h264.c
+++ b/libavcodec/vulkan_encode_h264.c
@@ -1016,6 +1016,7 @@  static int create_session_params(AVCodecContext *avctx)
     VkVideoEncodeH264SessionParametersAddInfoKHR h264_params_info;
     VkVideoEncodeH264SessionParametersCreateInfoKHR h264_params;
     VkVideoSessionParametersCreateInfoKHR session_params_create;
+    VkVideoEncodeQualityLevelInfoKHR q_info;
 
     /* Convert it to Vulkan */
     err = base_unit_to_vk(avctx, &vk_units);
@@ -1044,9 +1045,14 @@  static int create_session_params(AVCodecContext *avctx)
         .maxStdPPSCount = 1,
         .pParametersAddInfo = &h264_params_info,
     };
+    q_info = (VkVideoEncodeQualityLevelInfoKHR) {
+        .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_QUALITY_LEVEL_INFO_KHR,
+        .pNext = &h264_params,
+        .qualityLevel = ctx->opts.quality,
+    };
     session_params_create = (VkVideoSessionParametersCreateInfoKHR) {
         .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
-        .pNext = &h264_params,
+        .pNext = &q_info,
         .videoSession = ctx->common.session,
         .videoSessionParametersTemplate = NULL,
     };
diff --git a/libavcodec/vulkan_encode_h265.c b/libavcodec/vulkan_encode_h265.c
index 3cb7a3b7df..f1e61ab894 100644
--- a/libavcodec/vulkan_encode_h265.c
+++ b/libavcodec/vulkan_encode_h265.c
@@ -1166,6 +1166,7 @@  static int create_session_params(AVCodecContext *avctx)
     VkVideoEncodeH265SessionParametersAddInfoKHR h265_params_info;
     VkVideoEncodeH265SessionParametersCreateInfoKHR h265_params;
     VkVideoSessionParametersCreateInfoKHR session_params_create;
+    VkVideoEncodeQualityLevelInfoKHR q_info;
 
     /* Convert it to Vulkan */
     err = base_unit_to_vk(avctx, &vk_units);
@@ -1197,9 +1198,14 @@  static int create_session_params(AVCodecContext *avctx)
         .maxStdVPSCount = 1,
         .pParametersAddInfo = &h265_params_info,
     };
+    q_info = (VkVideoEncodeQualityLevelInfoKHR) {
+        .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_QUALITY_LEVEL_INFO_KHR,
+        .pNext = &h265_params,
+        .qualityLevel = ctx->opts.quality,
+    };
     session_params_create = (VkVideoSessionParametersCreateInfoKHR) {
         .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
-        .pNext = &h265_params,
+        .pNext = &q_info,
         .videoSession = ctx->common.session,
         .videoSessionParametersTemplate = NULL,
     };