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_R16G16B16A16_UNORM,
AV_PIX_FMT_XV36, VK_IMAGE_ASPECT_COLOR_BIT },
37 { VK_FORMAT_B8G8R8A8_UNORM,
AV_PIX_FMT_BGRA, VK_IMAGE_ASPECT_COLOR_BIT },
38 { VK_FORMAT_R8G8B8A8_UNORM,
AV_PIX_FMT_RGBA, VK_IMAGE_ASPECT_COLOR_BIT },
45 { VK_FORMAT_B8G8R8A8_UNORM,
AV_PIX_FMT_BGR0, VK_IMAGE_ASPECT_COLOR_BIT },
46 { VK_FORMAT_R8G8B8A8_UNORM,
AV_PIX_FMT_RGB0, VK_IMAGE_ASPECT_COLOR_BIT },
90 { VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16,
AV_PIX_FMT_Y210, VK_IMAGE_ASPECT_COLOR_BIT },
91 { VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16,
AV_PIX_FMT_Y212, VK_IMAGE_ASPECT_COLOR_BIT },
108 return VK_IMAGE_ASPECT_NONE;
113 if (
desc->nb_components == 1)
114 return VK_VIDEO_CHROMA_SUBSAMPLING_MONOCHROME_BIT_KHR;
115 else if (!
desc->log2_chroma_w && !
desc->log2_chroma_h)
116 return VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR;
117 else if (!
desc->log2_chroma_w &&
desc->log2_chroma_h == 1)
118 return VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR;
119 else if (
desc->log2_chroma_w == 1 &&
desc->log2_chroma_h == 1)
120 return VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR;
121 return VK_VIDEO_CHROMA_SUBSAMPLING_INVALID_KHR;
127 case 8:
return VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR;
128 case 10:
return VK_VIDEO_COMPONENT_BIT_DEPTH_10_BIT_KHR;
129 case 12:
return VK_VIDEO_COMPONENT_BIT_DEPTH_12_BIT_KHR;
132 return VK_VIDEO_COMPONENT_BIT_DEPTH_INVALID_KHR;
138 case STD_VIDEO_H264_LEVEL_IDC_1_0:
return 10;
139 case STD_VIDEO_H264_LEVEL_IDC_1_1:
return 11;
140 case STD_VIDEO_H264_LEVEL_IDC_1_2:
return 12;
141 case STD_VIDEO_H264_LEVEL_IDC_1_3:
return 13;
142 case STD_VIDEO_H264_LEVEL_IDC_2_0:
return 20;
143 case STD_VIDEO_H264_LEVEL_IDC_2_1:
return 21;
144 case STD_VIDEO_H264_LEVEL_IDC_2_2:
return 22;
145 case STD_VIDEO_H264_LEVEL_IDC_3_0:
return 30;
146 case STD_VIDEO_H264_LEVEL_IDC_3_1:
return 31;
147 case STD_VIDEO_H264_LEVEL_IDC_3_2:
return 32;
148 case STD_VIDEO_H264_LEVEL_IDC_4_0:
return 40;
149 case STD_VIDEO_H264_LEVEL_IDC_4_1:
return 41;
150 case STD_VIDEO_H264_LEVEL_IDC_4_2:
return 42;
151 case STD_VIDEO_H264_LEVEL_IDC_5_0:
return 50;
152 case STD_VIDEO_H264_LEVEL_IDC_5_1:
return 51;
153 case STD_VIDEO_H264_LEVEL_IDC_5_2:
return 52;
154 case STD_VIDEO_H264_LEVEL_IDC_6_0:
return 60;
155 case STD_VIDEO_H264_LEVEL_IDC_6_1:
return 61;
157 case STD_VIDEO_H264_LEVEL_IDC_6_2:
return 62;
164 case 10:
return STD_VIDEO_H264_LEVEL_IDC_1_0;
165 case 11:
return STD_VIDEO_H264_LEVEL_IDC_1_1;
166 case 12:
return STD_VIDEO_H264_LEVEL_IDC_1_2;
167 case 13:
return STD_VIDEO_H264_LEVEL_IDC_1_3;
168 case 20:
return STD_VIDEO_H264_LEVEL_IDC_2_0;
169 case 21:
return STD_VIDEO_H264_LEVEL_IDC_2_1;
170 case 22:
return STD_VIDEO_H264_LEVEL_IDC_2_2;
171 case 30:
return STD_VIDEO_H264_LEVEL_IDC_3_0;
172 case 31:
return STD_VIDEO_H264_LEVEL_IDC_3_1;
173 case 32:
return STD_VIDEO_H264_LEVEL_IDC_3_2;
174 case 40:
return STD_VIDEO_H264_LEVEL_IDC_4_0;
175 case 41:
return STD_VIDEO_H264_LEVEL_IDC_4_1;
176 case 42:
return STD_VIDEO_H264_LEVEL_IDC_4_2;
177 case 50:
return STD_VIDEO_H264_LEVEL_IDC_5_0;
178 case 51:
return STD_VIDEO_H264_LEVEL_IDC_5_1;
179 case 52:
return STD_VIDEO_H264_LEVEL_IDC_5_2;
180 case 60:
return STD_VIDEO_H264_LEVEL_IDC_6_0;
181 case 61:
return STD_VIDEO_H264_LEVEL_IDC_6_1;
183 case 62:
return STD_VIDEO_H264_LEVEL_IDC_6_2;
190 case STD_VIDEO_H265_LEVEL_IDC_1_0:
return 10;
191 case STD_VIDEO_H265_LEVEL_IDC_2_0:
return 20;
192 case STD_VIDEO_H265_LEVEL_IDC_2_1:
return 21;
193 case STD_VIDEO_H265_LEVEL_IDC_3_0:
return 30;
194 case STD_VIDEO_H265_LEVEL_IDC_3_1:
return 31;
195 case STD_VIDEO_H265_LEVEL_IDC_4_0:
return 40;
196 case STD_VIDEO_H265_LEVEL_IDC_4_1:
return 41;
197 case STD_VIDEO_H265_LEVEL_IDC_5_0:
return 50;
198 case STD_VIDEO_H265_LEVEL_IDC_5_1:
return 51;
199 case STD_VIDEO_H265_LEVEL_IDC_6_0:
return 60;
200 case STD_VIDEO_H265_LEVEL_IDC_6_1:
return 61;
202 case STD_VIDEO_H265_LEVEL_IDC_6_2:
return 62;
209 case 10:
return STD_VIDEO_H265_LEVEL_IDC_1_0;
210 case 20:
return STD_VIDEO_H265_LEVEL_IDC_2_0;
211 case 21:
return STD_VIDEO_H265_LEVEL_IDC_2_1;
212 case 30:
return STD_VIDEO_H265_LEVEL_IDC_3_0;
213 case 31:
return STD_VIDEO_H265_LEVEL_IDC_3_1;
214 case 40:
return STD_VIDEO_H265_LEVEL_IDC_4_0;
215 case 41:
return STD_VIDEO_H265_LEVEL_IDC_4_1;
216 case 50:
return STD_VIDEO_H265_LEVEL_IDC_5_0;
217 case 51:
return STD_VIDEO_H265_LEVEL_IDC_5_1;
218 case 60:
return STD_VIDEO_H265_LEVEL_IDC_6_0;
219 case 61:
return STD_VIDEO_H265_LEVEL_IDC_6_1;
221 case 62:
return STD_VIDEO_H265_LEVEL_IDC_6_2;
232 default:
return STD_VIDEO_H264_PROFILE_IDC_INVALID;
242 default:
return STD_VIDEO_H265_PROFILE_IDC_INVALID;
268 VkQueueFlagBits family, VkVideoCodecOperationFlagBitsKHR caps)
270 for (
int i = 0;
i <
s->hwctx->nb_qf;
i++) {
271 if ((
s->hwctx->qf[
i].flags & family) &&
272 (
s->hwctx->qf[
i].video_caps & caps)) {
282 VkImageView *view, VkImageAspectFlags *aspect,
289 VkSamplerYcbcrConversionInfo yuv_sampler_info = {
290 .sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
291 .conversion = common->yuv_sampler,
293 VkImageViewCreateInfo img_view_create_info = {
294 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
295 .pNext = &yuv_sampler_info,
296 .viewType = common->layered_dpb && is_dpb ?
297 VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D,
299 .image =
src->img[0],
300 .components = (VkComponentMapping) {
301 .r = VK_COMPONENT_SWIZZLE_IDENTITY,
302 .g = VK_COMPONENT_SWIZZLE_IDENTITY,
303 .b = VK_COMPONENT_SWIZZLE_IDENTITY,
304 .a = VK_COMPONENT_SWIZZLE_IDENTITY,
306 .subresourceRange = (VkImageSubresourceRange) {
307 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
309 .layerCount = common->layered_dpb && is_dpb ?
310 VK_REMAINING_ARRAY_LAYERS : 1,
315 ret = vk->CreateImageView(
s->hwctx->act_dev, &img_view_create_info,
316 s->hwctx->alloc, view);
317 if (
ret != VK_SUCCESS)
320 *aspect = aspect_mask;
326 FFVkVideoCommon *common)
330 if (common->session) {
331 vk->DestroyVideoSessionKHR(
s->hwctx->act_dev, common->session,
333 common->session = VK_NULL_HANDLE;
336 if (common->nb_mem && common->mem)
337 for (
int i = 0;
i < common->nb_mem;
i++)
338 vk->FreeMemory(
s->hwctx->act_dev, common->mem[
i],
s->hwctx->alloc);
342 if (common->layered_view)
343 vk->DestroyImageView(
s->hwctx->act_dev, common->layered_view,
350 if (common->yuv_sampler)
351 vk->DestroySamplerYcbcrConversion(
s->hwctx->act_dev, common->yuv_sampler,
356 FFVkVideoCommon *common,
357 VkVideoSessionCreateInfoKHR *session_create)
362 VkVideoSessionMemoryRequirementsKHR *mem =
NULL;
363 VkBindVideoSessionMemoryInfoKHR *bind_mem =
NULL;
365 int cxpos = 0, cypos = 0;
366 VkSamplerYcbcrConversionCreateInfo yuv_sampler_info = {
367 .sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
369 .ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY,
371 .format = session_create->pictureFormat,
377 yuv_sampler_info.xChromaOffset = cxpos >> 7;
378 yuv_sampler_info.yChromaOffset = cypos >> 7;
379 ret = vk->CreateSamplerYcbcrConversion(
s->hwctx->act_dev, &yuv_sampler_info,
380 s->hwctx->alloc, &common->yuv_sampler);
381 if (
ret != VK_SUCCESS)
385 ret = vk->CreateVideoSessionKHR(
s->hwctx->act_dev, session_create,
386 s->hwctx->alloc, &common->session);
387 if (
ret != VK_SUCCESS)
391 ret = vk->GetVideoSessionMemoryRequirementsKHR(
s->hwctx->act_dev,
395 if (
ret != VK_SUCCESS) {
401 common->mem =
av_mallocz(
sizeof(*common->mem)*common->nb_mem);
406 mem =
av_mallocz(
sizeof(*mem)*common->nb_mem);
411 bind_mem =
av_mallocz(
sizeof(*bind_mem)*common->nb_mem);
418 for (
int i = 0;
i < common->nb_mem;
i++) {
419 mem[
i] = (VkVideoSessionMemoryRequirementsKHR) {
420 .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_MEMORY_REQUIREMENTS_KHR,
425 ret = vk->GetVideoSessionMemoryRequirementsKHR(
s->hwctx->act_dev,
426 common->session, &common->nb_mem,
428 if (
ret != VK_SUCCESS) {
435 for (
int i = 0;
i < common->nb_mem;
i++) {
437 UINT32_MAX,
NULL,
NULL, &common->mem[
i]);
441 bind_mem[
i] = (VkBindVideoSessionMemoryInfoKHR) {
442 .sType = VK_STRUCTURE_TYPE_BIND_VIDEO_SESSION_MEMORY_INFO_KHR,
443 .memory = common->mem[
i],
444 .memoryBindIndex = mem[
i].memoryBindIndex,
446 .memorySize = mem[
i].memoryRequirements.size,
449 av_log(avctx,
AV_LOG_VERBOSE,
"Allocating %"PRIu64
" bytes in bind index %i for video session\n",
450 bind_mem[
i].memorySize, bind_mem[
i].memoryBindIndex);
454 ret = vk->BindVideoSessionMemoryKHR(
s->hwctx->act_dev, common->session,
455 common->nb_mem, bind_mem);
456 if (
ret != VK_SUCCESS) {