Skip to content

Commit 2bcc124

Browse files
ceyusacyanreg
authored andcommitted
vulkan_encode: set the quality level in session parameters
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 adds a new function helper for creating session parameters, which also sets the quality level and it's called by the H.264 and H.265 Vulkan encoders.
1 parent 39c640e commit 2bcc124

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

libavcodec/vulkan_encode.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,3 +1023,37 @@ av_cold int ff_vulkan_encode_init(AVCodecContext *avctx, FFVulkanEncodeContext *
10231023

10241024
return 0;
10251025
}
1026+
1027+
int ff_vulkan_encode_create_session_params(AVCodecContext *avctx, FFVulkanEncodeContext *ctx,
1028+
void *codec_params_pnext)
1029+
{
1030+
VkResult ret;
1031+
FFVulkanFunctions *vk = &ctx->s.vkfn;
1032+
FFVulkanContext *s = &ctx->s;
1033+
1034+
VkVideoEncodeQualityLevelInfoKHR q_info;
1035+
VkVideoSessionParametersCreateInfoKHR session_params_create;
1036+
1037+
q_info = (VkVideoEncodeQualityLevelInfoKHR) {
1038+
.sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_QUALITY_LEVEL_INFO_KHR,
1039+
.pNext = codec_params_pnext,
1040+
.qualityLevel = ctx->opts.quality,
1041+
};
1042+
session_params_create = (VkVideoSessionParametersCreateInfoKHR) {
1043+
.sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
1044+
.pNext = &q_info,
1045+
.videoSession = ctx->common.session,
1046+
.videoSessionParametersTemplate = VK_NULL_HANDLE,
1047+
};
1048+
1049+
/* Create session parameters */
1050+
ret = vk->CreateVideoSessionParametersKHR(s->hwctx->act_dev, &session_params_create,
1051+
s->hwctx->alloc, &ctx->session_params);
1052+
if (ret != VK_SUCCESS) {
1053+
av_log(avctx, AV_LOG_ERROR, "Unable to create Vulkan video session parameters: %s!\n",
1054+
ff_vk_ret2str(ret));
1055+
return AVERROR_EXTERNAL;
1056+
}
1057+
1058+
return 0;
1059+
}

libavcodec/vulkan_encode.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ int ff_vulkan_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
245245
*/
246246
void ff_vulkan_encode_uninit(FFVulkanEncodeContext *ctx);
247247

248+
/**
249+
* Create session parameters.
250+
*/
251+
int ff_vulkan_encode_create_session_params(AVCodecContext *avctx, FFVulkanEncodeContext *ctx,
252+
void *codec_params_pnext);
253+
248254
/**
249255
* Paperwork.
250256
*/

libavcodec/vulkan_encode_h264.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,6 @@ static av_cold int base_unit_to_vk(AVCodecContext *avctx,
10051005
static int create_session_params(AVCodecContext *avctx)
10061006
{
10071007
int err;
1008-
VkResult ret;
10091008
VulkanEncodeH264Context *enc = avctx->priv_data;
10101009
FFVulkanEncodeContext *ctx = &enc->common;
10111010
FFVulkanContext *s = &ctx->s;
@@ -1015,7 +1014,6 @@ static int create_session_params(AVCodecContext *avctx)
10151014

10161015
VkVideoEncodeH264SessionParametersAddInfoKHR h264_params_info;
10171016
VkVideoEncodeH264SessionParametersCreateInfoKHR h264_params;
1018-
VkVideoSessionParametersCreateInfoKHR session_params_create;
10191017

10201018
/* Convert it to Vulkan */
10211019
err = base_unit_to_vk(avctx, &vk_units);
@@ -1044,23 +1042,8 @@ static int create_session_params(AVCodecContext *avctx)
10441042
.maxStdPPSCount = 1,
10451043
.pParametersAddInfo = &h264_params_info,
10461044
};
1047-
session_params_create = (VkVideoSessionParametersCreateInfoKHR) {
1048-
.sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
1049-
.pNext = &h264_params,
1050-
.videoSession = ctx->common.session,
1051-
.videoSessionParametersTemplate = NULL,
1052-
};
1053-
1054-
/* Create session parameters */
1055-
ret = vk->CreateVideoSessionParametersKHR(s->hwctx->act_dev, &session_params_create,
1056-
s->hwctx->alloc, &ctx->session_params);
1057-
if (ret != VK_SUCCESS) {
1058-
av_log(avctx, AV_LOG_ERROR, "Unable to create Vulkan video session parameters: %s!\n",
1059-
ff_vk_ret2str(ret));
1060-
return AVERROR_EXTERNAL;
1061-
}
10621045

1063-
return 0;
1046+
return ff_vulkan_encode_create_session_params(avctx, ctx, &h264_params);
10641047
}
10651048

10661049
static int parse_feedback_units(AVCodecContext *avctx,

libavcodec/vulkan_encode_h265.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,6 @@ static av_cold int base_unit_to_vk(AVCodecContext *avctx,
11551155
static int create_session_params(AVCodecContext *avctx)
11561156
{
11571157
int err;
1158-
VkResult ret;
11591158
VulkanEncodeH265Context *enc = avctx->priv_data;
11601159
FFVulkanEncodeContext *ctx = &enc->common;
11611160
FFVulkanContext *s = &ctx->s;
@@ -1165,7 +1164,6 @@ static int create_session_params(AVCodecContext *avctx)
11651164

11661165
VkVideoEncodeH265SessionParametersAddInfoKHR h265_params_info;
11671166
VkVideoEncodeH265SessionParametersCreateInfoKHR h265_params;
1168-
VkVideoSessionParametersCreateInfoKHR session_params_create;
11691167

11701168
/* Convert it to Vulkan */
11711169
err = base_unit_to_vk(avctx, &vk_units);
@@ -1197,23 +1195,8 @@ static int create_session_params(AVCodecContext *avctx)
11971195
.maxStdVPSCount = 1,
11981196
.pParametersAddInfo = &h265_params_info,
11991197
};
1200-
session_params_create = (VkVideoSessionParametersCreateInfoKHR) {
1201-
.sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
1202-
.pNext = &h265_params,
1203-
.videoSession = ctx->common.session,
1204-
.videoSessionParametersTemplate = NULL,
1205-
};
1206-
1207-
/* Create session parameters */
1208-
ret = vk->CreateVideoSessionParametersKHR(s->hwctx->act_dev, &session_params_create,
1209-
s->hwctx->alloc, &ctx->session_params);
1210-
if (ret != VK_SUCCESS) {
1211-
av_log(avctx, AV_LOG_ERROR, "Unable to create Vulkan video session parameters: %s!\n",
1212-
ff_vk_ret2str(ret));
1213-
return AVERROR_EXTERNAL;
1214-
}
12151198

1216-
return 0;
1199+
return ff_vulkan_encode_create_session_params(avctx, ctx, &h265_params);
12171200
}
12181201

12191202
static int parse_feedback_units(AVCodecContext *avctx,

0 commit comments

Comments
 (0)