22 #define ASPECT_2PLANE (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT)
23 #define ASPECT_3PLANE (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT | VK_IMAGE_ASPECT_PLANE_2_BIT)
36 { VK_FORMAT_B8G8R8A8_UNORM,
AV_PIX_FMT_BGRA, VK_IMAGE_ASPECT_COLOR_BIT },
37 { VK_FORMAT_R8G8B8A8_UNORM,
AV_PIX_FMT_RGBA, VK_IMAGE_ASPECT_COLOR_BIT },
44 { VK_FORMAT_B8G8R8A8_UNORM,
AV_PIX_FMT_BGR0, VK_IMAGE_ASPECT_COLOR_BIT },
45 { VK_FORMAT_R8G8B8A8_UNORM,
AV_PIX_FMT_RGB0, VK_IMAGE_ASPECT_COLOR_BIT },
89 { VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16,
AV_PIX_FMT_Y210, VK_IMAGE_ASPECT_COLOR_BIT },
90 { VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16,
AV_PIX_FMT_Y212, VK_IMAGE_ASPECT_COLOR_BIT },
91 { VK_FORMAT_G16B16G16R16_422_UNORM,
AV_PIX_FMT_Y216, VK_IMAGE_ASPECT_COLOR_BIT },
94 { VK_FORMAT_A2R10G10B10_UNORM_PACK32,
AV_PIX_FMT_XV30, VK_IMAGE_ASPECT_COLOR_BIT },
95 { VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16,
AV_PIX_FMT_XV36, VK_IMAGE_ASPECT_COLOR_BIT },
112 return VK_IMAGE_ASPECT_NONE;
117 if (
desc->nb_components == 1)
118 return VK_VIDEO_CHROMA_SUBSAMPLING_MONOCHROME_BIT_KHR;
119 else if (!
desc->log2_chroma_w && !
desc->log2_chroma_h)
120 return VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR;
121 else if (!
desc->log2_chroma_w &&
desc->log2_chroma_h == 1)
122 return VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR;
123 else if (
desc->log2_chroma_w == 1 &&
desc->log2_chroma_h == 1)
124 return VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR;
125 return VK_VIDEO_CHROMA_SUBSAMPLING_INVALID_KHR;
131 case 8:
return VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR;
132 case 10:
return VK_VIDEO_COMPONENT_BIT_DEPTH_10_BIT_KHR;
133 case 12:
return VK_VIDEO_COMPONENT_BIT_DEPTH_12_BIT_KHR;
136 return VK_VIDEO_COMPONENT_BIT_DEPTH_INVALID_KHR;
142 case STD_VIDEO_H264_LEVEL_IDC_1_0:
return 10;
143 case STD_VIDEO_H264_LEVEL_IDC_1_1:
return 11;
144 case STD_VIDEO_H264_LEVEL_IDC_1_2:
return 12;
145 case STD_VIDEO_H264_LEVEL_IDC_1_3:
return 13;
146 case STD_VIDEO_H264_LEVEL_IDC_2_0:
return 20;
147 case STD_VIDEO_H264_LEVEL_IDC_2_1:
return 21;
148 case STD_VIDEO_H264_LEVEL_IDC_2_2:
return 22;
149 case STD_VIDEO_H264_LEVEL_IDC_3_0:
return 30;
150 case STD_VIDEO_H264_LEVEL_IDC_3_1:
return 31;
151 case STD_VIDEO_H264_LEVEL_IDC_3_2:
return 32;
152 case STD_VIDEO_H264_LEVEL_IDC_4_0:
return 40;
153 case STD_VIDEO_H264_LEVEL_IDC_4_1:
return 41;
154 case STD_VIDEO_H264_LEVEL_IDC_4_2:
return 42;
155 case STD_VIDEO_H264_LEVEL_IDC_5_0:
return 50;
156 case STD_VIDEO_H264_LEVEL_IDC_5_1:
return 51;
157 case STD_VIDEO_H264_LEVEL_IDC_5_2:
return 52;
158 case STD_VIDEO_H264_LEVEL_IDC_6_0:
return 60;
159 case STD_VIDEO_H264_LEVEL_IDC_6_1:
return 61;
161 case STD_VIDEO_H264_LEVEL_IDC_6_2:
return 62;
168 case 10:
return STD_VIDEO_H264_LEVEL_IDC_1_0;
169 case 11:
return STD_VIDEO_H264_LEVEL_IDC_1_1;
170 case 12:
return STD_VIDEO_H264_LEVEL_IDC_1_2;
171 case 13:
return STD_VIDEO_H264_LEVEL_IDC_1_3;
172 case 20:
return STD_VIDEO_H264_LEVEL_IDC_2_0;
173 case 21:
return STD_VIDEO_H264_LEVEL_IDC_2_1;
174 case 22:
return STD_VIDEO_H264_LEVEL_IDC_2_2;
175 case 30:
return STD_VIDEO_H264_LEVEL_IDC_3_0;
176 case 31:
return STD_VIDEO_H264_LEVEL_IDC_3_1;
177 case 32:
return STD_VIDEO_H264_LEVEL_IDC_3_2;
178 case 40:
return STD_VIDEO_H264_LEVEL_IDC_4_0;
179 case 41:
return STD_VIDEO_H264_LEVEL_IDC_4_1;
180 case 42:
return STD_VIDEO_H264_LEVEL_IDC_4_2;
181 case 50:
return STD_VIDEO_H264_LEVEL_IDC_5_0;
182 case 51:
return STD_VIDEO_H264_LEVEL_IDC_5_1;
183 case 52:
return STD_VIDEO_H264_LEVEL_IDC_5_2;
184 case 60:
return STD_VIDEO_H264_LEVEL_IDC_6_0;
185 case 61:
return STD_VIDEO_H264_LEVEL_IDC_6_1;
187 case 62:
return STD_VIDEO_H264_LEVEL_IDC_6_2;
194 case STD_VIDEO_H265_LEVEL_IDC_1_0:
return 10;
195 case STD_VIDEO_H265_LEVEL_IDC_2_0:
return 20;
196 case STD_VIDEO_H265_LEVEL_IDC_2_1:
return 21;
197 case STD_VIDEO_H265_LEVEL_IDC_3_0:
return 30;
198 case STD_VIDEO_H265_LEVEL_IDC_3_1:
return 31;
199 case STD_VIDEO_H265_LEVEL_IDC_4_0:
return 40;
200 case STD_VIDEO_H265_LEVEL_IDC_4_1:
return 41;
201 case STD_VIDEO_H265_LEVEL_IDC_5_0:
return 50;
202 case STD_VIDEO_H265_LEVEL_IDC_5_1:
return 51;
203 case STD_VIDEO_H265_LEVEL_IDC_6_0:
return 60;
204 case STD_VIDEO_H265_LEVEL_IDC_6_1:
return 61;
206 case STD_VIDEO_H265_LEVEL_IDC_6_2:
return 62;
213 case 10:
return STD_VIDEO_H265_LEVEL_IDC_1_0;
214 case 20:
return STD_VIDEO_H265_LEVEL_IDC_2_0;
215 case 21:
return STD_VIDEO_H265_LEVEL_IDC_2_1;
216 case 30:
return STD_VIDEO_H265_LEVEL_IDC_3_0;
217 case 31:
return STD_VIDEO_H265_LEVEL_IDC_3_1;
218 case 40:
return STD_VIDEO_H265_LEVEL_IDC_4_0;
219 case 41:
return STD_VIDEO_H265_LEVEL_IDC_4_1;
220 case 50:
return STD_VIDEO_H265_LEVEL_IDC_5_0;
221 case 51:
return STD_VIDEO_H265_LEVEL_IDC_5_1;
222 case 60:
return STD_VIDEO_H265_LEVEL_IDC_6_0;
223 case 61:
return STD_VIDEO_H265_LEVEL_IDC_6_1;
225 case 62:
return STD_VIDEO_H265_LEVEL_IDC_6_2;
236 default:
return STD_VIDEO_H264_PROFILE_IDC_INVALID;
246 default:
return STD_VIDEO_H265_PROFILE_IDC_INVALID;
272 VkQueueFlagBits family, VkVideoCodecOperationFlagBitsKHR caps)
274 for (
int i = 0;
i <
s->hwctx->nb_qf;
i++) {
275 if ((
s->hwctx->qf[
i].flags & family) &&
276 (
s->hwctx->qf[
i].video_caps & caps)) {
286 VkImageView *view, VkImageAspectFlags *aspect,
293 VkSamplerYcbcrConversionInfo yuv_sampler_info = {
294 .sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
295 .conversion = common->yuv_sampler,
297 VkImageViewCreateInfo img_view_create_info = {
298 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
299 .pNext = &yuv_sampler_info,
300 .viewType = common->layered_dpb && is_dpb ?
301 VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D,
303 .image =
src->img[0],
304 .components = (VkComponentMapping) {
305 .r = VK_COMPONENT_SWIZZLE_IDENTITY,
306 .g = VK_COMPONENT_SWIZZLE_IDENTITY,
307 .b = VK_COMPONENT_SWIZZLE_IDENTITY,
308 .a = VK_COMPONENT_SWIZZLE_IDENTITY,
310 .subresourceRange = (VkImageSubresourceRange) {
311 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
313 .layerCount = common->layered_dpb && is_dpb ?
314 VK_REMAINING_ARRAY_LAYERS : 1,
319 ret = vk->CreateImageView(
s->hwctx->act_dev, &img_view_create_info,
320 s->hwctx->alloc, view);
321 if (
ret != VK_SUCCESS)
324 *aspect = aspect_mask;
330 FFVkVideoCommon *common)
334 if (common->session) {
335 vk->DestroyVideoSessionKHR(
s->hwctx->act_dev, common->session,
337 common->session = VK_NULL_HANDLE;
340 if (common->nb_mem && common->mem)
341 for (
int i = 0;
i < common->nb_mem;
i++)
342 vk->FreeMemory(
s->hwctx->act_dev, common->mem[
i],
s->hwctx->alloc);
346 if (common->layered_view)
347 vk->DestroyImageView(
s->hwctx->act_dev, common->layered_view,
354 if (common->yuv_sampler)
355 vk->DestroySamplerYcbcrConversion(
s->hwctx->act_dev, common->yuv_sampler,
360 FFVkVideoCommon *common,
361 VkVideoSessionCreateInfoKHR *session_create)
366 VkVideoSessionMemoryRequirementsKHR *mem =
NULL;
367 VkBindVideoSessionMemoryInfoKHR *bind_mem =
NULL;
369 int cxpos = 0, cypos = 0;
370 VkSamplerYcbcrConversionCreateInfo yuv_sampler_info = {
371 .sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
373 .ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY,
375 .format = session_create->pictureFormat,
381 yuv_sampler_info.xChromaOffset = cxpos >> 7;
382 yuv_sampler_info.yChromaOffset = cypos >> 7;
383 ret = vk->CreateSamplerYcbcrConversion(
s->hwctx->act_dev, &yuv_sampler_info,
384 s->hwctx->alloc, &common->yuv_sampler);
385 if (
ret != VK_SUCCESS)
389 ret = vk->CreateVideoSessionKHR(
s->hwctx->act_dev, session_create,
390 s->hwctx->alloc, &common->session);
391 if (
ret != VK_SUCCESS)
395 ret = vk->GetVideoSessionMemoryRequirementsKHR(
s->hwctx->act_dev,
399 if (
ret != VK_SUCCESS) {
405 common->mem =
av_mallocz(
sizeof(*common->mem)*common->nb_mem);
410 mem =
av_mallocz(
sizeof(*mem)*common->nb_mem);
415 bind_mem =
av_mallocz(
sizeof(*bind_mem)*common->nb_mem);
422 for (
int i = 0;
i < common->nb_mem;
i++) {
423 mem[
i] = (VkVideoSessionMemoryRequirementsKHR) {
424 .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_MEMORY_REQUIREMENTS_KHR,
429 ret = vk->GetVideoSessionMemoryRequirementsKHR(
s->hwctx->act_dev,
430 common->session, &common->nb_mem,
432 if (
ret != VK_SUCCESS) {
439 for (
int i = 0;
i < common->nb_mem;
i++) {
441 UINT32_MAX,
NULL,
NULL, &common->mem[
i]);
445 bind_mem[
i] = (VkBindVideoSessionMemoryInfoKHR) {
446 .sType = VK_STRUCTURE_TYPE_BIND_VIDEO_SESSION_MEMORY_INFO_KHR,
447 .memory = common->mem[
i],
448 .memoryBindIndex = mem[
i].memoryBindIndex,
450 .memorySize = mem[
i].memoryRequirements.size,
453 av_log(avctx,
AV_LOG_VERBOSE,
"Allocating %"PRIu64
" bytes in bind index %i for video session\n",
454 bind_mem[
i].memorySize, bind_mem[
i].memoryBindIndex);
458 ret = vk->BindVideoSessionMemoryKHR(
s->hwctx->act_dev, common->session,
459 common->nb_mem, bind_mem);
460 if (
ret != VK_SUCCESS) {