History

vulkan_video: move imageview creation and DPB fields to common context

Shared between decoders and encoders.

Lynne committed 2 years ago

Commit 66e950f1 parent 06483d07 files · +133 −120Browse files

Unified · Split

7 files
  1. libavcodec/vulkan_av1.c +2 −1
  2. libavcodec/vulkan_decode.c +33 −104
  3. libavcodec/vulkan_decode.h +0 −9
  4. libavcodec/vulkan_h264.c +2 −1
  5. libavcodec/vulkan_hevc.c +2 −1
  6. libavcodec/vulkan_video.c +77 −3
  7. libavcodec/vulkan_video.h +17 −1
libavcodec/vulkan_av1.c+2−1
@@ -79,6 +79,7 @@ static int vk_av1_fill_pict(AVCodecContext *avctx, const AV1Frame **ref_src, · 78 unmodified lines
7979 const uint8_t *saved_order_hints)
8080 {
8181 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
82+ FFVulkanDecodeShared *ctx = dec->shared_ctx;
8283 AV1VulkanDecodePicture *hp = pic->hwaccel_picture_private;
8384 FFVulkanDecodePicture *vkpic = &hp->vp;
8485
@@ -119,7 +120,7 @@ static int vk_av1_fill_pict(AVCodecContext *avctx, const AV1Frame **ref_src, · 34 unmodified lines
119120 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
120121 .codedOffset = (VkOffset2D){ 0, 0 },
121122 .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },
122− .baseArrayLayer = ((has_grain || dec->dedicated_dpb) && dec->layered_dpb) ?
123+ .baseArrayLayer = ((has_grain || dec->dedicated_dpb) && ctx->common.layered_dpb) ?
123124 hp->frame_id : 0,
124125 .imageViewBinding = vkpic->img_view_ref,
125126 };
libavcodec/vulkan_decode.c+33−104
@@ -111,7 +111,6 @@ int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) · 110 unmodified lines
111111 }
112112
113113 dst_ctx->dedicated_dpb = src_ctx->dedicated_dpb;
114− dst_ctx->layered_dpb = src_ctx->layered_dpb;
115114 dst_ctx->external_fg = src_ctx->external_fg;
116115 dst_ctx->frame_id_alloc_mask = src_ctx->frame_id_alloc_mask;
117116
@@ -125,51 +124,6 @@ int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint · 7 unmodified lines
125124 return 0;
126125 }
127126
128−static int vk_decode_create_view(FFVulkanDecodeContext *dec, VkImageView *dst_view,
129− VkImageAspectFlags *aspect, AVVkFrame *src,
130− VkFormat vkf, int is_current)
131−{
132− VkResult ret;
133− FFVulkanDecodeShared *ctx = dec->shared_ctx;
134− FFVulkanFunctions *vk = &ctx->s.vkfn;
135− VkImageAspectFlags aspect_mask = ff_vk_aspect_bits_from_vkfmt(vkf);
136−
137− VkSamplerYcbcrConversionInfo yuv_sampler_info = {
138− .sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
139− .conversion = ctx->yuv_sampler,
140− };
141− VkImageViewCreateInfo img_view_create_info = {
142− .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
143− .pNext = &yuv_sampler_info,
144− .viewType = dec->layered_dpb && !is_current ?
145− VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D,
146− .format = vkf,
147− .image = src->img[0],
148− .components = (VkComponentMapping) {
149− .r = VK_COMPONENT_SWIZZLE_IDENTITY,
150− .g = VK_COMPONENT_SWIZZLE_IDENTITY,
151− .b = VK_COMPONENT_SWIZZLE_IDENTITY,
152− .a = VK_COMPONENT_SWIZZLE_IDENTITY,
153− },
154− .subresourceRange = (VkImageSubresourceRange) {
155− .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
156− .baseArrayLayer = 0,
157− .layerCount = dec->layered_dpb && !is_current ?
158− VK_REMAINING_ARRAY_LAYERS : 1,
159− .levelCount = 1,
160− },
161− };
162−
163− ret = vk->CreateImageView(ctx->s.hwctx->act_dev, &img_view_create_info,
164− ctx->s.hwctx->alloc, dst_view);
165− if (ret != VK_SUCCESS)
166− return AVERROR_EXTERNAL;
167−
168− *aspect = aspect_mask;
169−
170− return 0;
171−}
172−
173127 static AVFrame *vk_get_dpb_pool(FFVulkanDecodeShared *ctx)
174128 {
175129 int err;
@@ -177,7 +131,7 @@ static AVFrame *vk_get_dpb_pool(FFVulkanDecodeShared *ctx) · 1 unmodified line
177131 if (!avf)
178132 return NULL;
179133
180− err = av_hwframe_get_buffer(ctx->dpb_hwfc_ref, avf, 0x0);
134+ err = av_hwframe_get_buffer(ctx->common.dpb_hwfc_ref, avf, 0x0);
181135 if (err < 0)
182136 av_frame_free(&avf);
183137
@@ -207,21 +161,21 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic, · 23 unmodified lines
207161 vkpic->destroy_image_view = vk->DestroyImageView;
208162 vkpic->wait_semaphores = vk->WaitSemaphores;
209163
210− if (dec->layered_dpb && alloc_dpb) {
211− vkpic->img_view_ref = ctx->layered_view;
212− vkpic->img_aspect_ref = ctx->layered_aspect;
164+ if (ctx->common.layered_dpb && alloc_dpb) {
165+ vkpic->img_view_ref = ctx->common.layered_view;
166+ vkpic->img_aspect_ref = ctx->common.layered_aspect;
213167 } else if (alloc_dpb) {
214− AVHWFramesContext *dpb_frames = (AVHWFramesContext *)ctx->dpb_hwfc_ref->data;
168+ AVHWFramesContext *dpb_frames = (AVHWFramesContext *)ctx->common.dpb_hwfc_ref->data;
215169 AVVulkanFramesContext *dpb_hwfc = dpb_frames->hwctx;
216170
217171 vkpic->dpb_frame = vk_get_dpb_pool(ctx);
218172 if (!vkpic->dpb_frame)
219173 return AVERROR(ENOMEM);
220174
221− err = vk_decode_create_view(dec, &vkpic->img_view_ref,
222− &vkpic->img_aspect_ref,
223− (AVVkFrame *)vkpic->dpb_frame->data[0],
224− dpb_hwfc->format[0], is_current);
175+ err = ff_vk_create_view(&ctx->s, &ctx->common,
176+ &vkpic->img_view_ref, &vkpic->img_aspect_ref,
177+ (AVVkFrame *)vkpic->dpb_frame->data[0],
178+ dpb_hwfc->format[0], !is_current);
225179 if (err < 0)
226180 return err;
227181
@@ -232,10 +186,10 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic, · 4 unmodified lines
232186 AVHWFramesContext *frames = (AVHWFramesContext *)pic->hw_frames_ctx->data;
233187 AVVulkanFramesContext *hwfc = frames->hwctx;
234188
235− err = vk_decode_create_view(dec, &vkpic->img_view_out,
236− &vkpic->img_aspect,
237− (AVVkFrame *)pic->data[0],
238− hwfc->format[0], is_current);
189+ err = ff_vk_create_view(&ctx->s, &ctx->common,
190+ &vkpic->img_view_out, &vkpic->img_aspect,
191+ (AVVkFrame *)pic->data[0],
192+ hwfc->format[0], !is_current);
239193 if (err < 0)
240194 return err;
241195
@@ -366,7 +320,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx, · 124 unmodified lines
366320 AVVkFrame *vkf = (AVVkFrame *)pic->buf[0]->data;
367321
368322 /* Quirks */
369− const int layered_dpb = dec->layered_dpb;
323+ const int layered_dpb = ctx->common.layered_dpb;
370324
371325 VkVideoSessionParametersKHR *par = (VkVideoSessionParametersKHR *)dec->session_params->data;
372326 VkVideoBeginCodingInfoKHR decode_start = {
@@ -470,7 +424,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx, · 97 unmodified lines
470424 .srcAccessMask = VK_ACCESS_2_NONE,
471425 .dstAccessMask = VK_ACCESS_2_VIDEO_DECODE_WRITE_BIT_KHR,
472426 .oldLayout = vkf->layout[0],
473− .newLayout = (dec->layered_dpb || vp->dpb_frame) ?
427+ .newLayout = (layered_dpb || vp->dpb_frame) ?
474428 VK_IMAGE_LAYOUT_VIDEO_DECODE_DST_KHR :
475429 VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR, /* Spec, 07252 utter madness */
476430 .srcQueueFamilyIndex = vkf->queue_family[0],
@@ -545,7 +499,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx, · 68 unmodified lines
545499 } else if (vp->decode_info.referenceSlotCount ||
546500 vp->img_view_out != vp->img_view_ref) {
547501 /* Single barrier for a single layered ref */
548− err = ff_vk_exec_add_dep_frame(&ctx->s, exec, ctx->layered_frame,
502+ err = ff_vk_exec_add_dep_frame(&ctx->s, exec, ctx->common.layered_frame,
549503 VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR,
550504 VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR);
551505 if (err < 0)
@@ -616,13 +570,8 @@ static void free_common(FFRefStructOpaque unused, void *obj) · 64 unmodified lines
616570 FFVulkanContext *s = &ctx->s;
617571 FFVulkanFunctions *vk = &ctx->s.vkfn;
618572
619− /* Destroy layered view */
620− if (ctx->layered_view)
621− vk->DestroyImageView(s->hwctx->act_dev, ctx->layered_view, s->hwctx->alloc);
622−
623573 /* This also frees all references from this pool */
624− av_frame_free(&ctx->layered_frame);
625− av_buffer_unref(&ctx->dpb_hwfc_ref);
574+ av_frame_free(&ctx->common.layered_frame);
626575
627576 /* Destroy parameters */
628577 if (ctx->empty_session_params)
@@ -634,10 +583,6 @@ static void free_common(FFRefStructOpaque unused, void *obj) · 5 unmodified lines
634583
635584 ff_vk_video_common_uninit(s, &ctx->common);
636585
637− if (ctx->yuv_sampler)
638− vk->DestroySamplerYcbcrConversion(s->hwctx->act_dev, ctx->yuv_sampler,
639− s->hwctx->alloc);
640−
641586 ff_vk_uninit(s);
642587 }
643588
@@ -924,8 +869,8 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_ · 280 unmodified lines
924869 }
925870
926871 dec->dedicated_dpb = !(dec_caps->flags & VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR);
927− dec->layered_dpb = !dec->dedicated_dpb ? 0 :
928− !(caps->flags & VK_VIDEO_CAPABILITY_SEPARATE_REFERENCE_IMAGES_BIT_KHR);
872+ ctx->common.layered_dpb = !dec->dedicated_dpb ? 0 :
873+ !(caps->flags & VK_VIDEO_CAPABILITY_SEPARATE_REFERENCE_IMAGES_BIT_KHR);
929874
930875 if (dec->dedicated_dpb) {
931876 fmt_info.imageUsage = VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR;
@@ -1128,7 +1073,7 @@ int ff_vk_decode_uninit(AVCodecContext *avctx) · 196 unmodified lines
11281073
11291074 int ff_vk_decode_init(AVCodecContext *avctx)
11301075 {
1131− int err, cxpos = 0, cypos = 0, nb_q = 0;
1076+ int err, nb_q = 0;
11321077 VkResult ret;
11331078 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
11341079 FFVulkanDecodeShared *ctx;
@@ -1159,12 +1104,6 @@ int ff_vk_decode_init(AVCodecContext *avctx) · 24 unmodified lines
11591104 VkVideoSessionCreateInfoKHR session_create = {
11601105 .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_CREATE_INFO_KHR,
11611106 };
1162− VkSamplerYcbcrConversionCreateInfo yuv_sampler_info = {
1163− .sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
1164− .components = ff_comp_identity_map,
1165− .ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY,
1166− .ycbcrRange = avctx->color_range == AVCOL_RANGE_MPEG, /* Ignored */
1167− };
11681107
11691108 err = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VULKAN);
11701109 if (err < 0)
@@ -1230,30 +1169,18 @@ int ff_vk_decode_init(AVCodecContext *avctx) · 59 unmodified lines
12301169 if (err < 0)
12311170 goto fail;
12321171
1233− /* Get sampler */
1234− av_chroma_location_enum_to_pos(&cxpos, &cypos, avctx->chroma_sample_location);
1235− yuv_sampler_info.xChromaOffset = cxpos >> 7;
1236− yuv_sampler_info.yChromaOffset = cypos >> 7;
1237− yuv_sampler_info.format = s->hwfc->format[0];
1238− ret = vk->CreateSamplerYcbcrConversion(s->hwctx->act_dev, &yuv_sampler_info,
1239− s->hwctx->alloc, &ctx->yuv_sampler);
1240− if (ret != VK_SUCCESS) {
1241− err = AVERROR_EXTERNAL;
1242− goto fail;
1243− }
1244−
12451172 /* If doing an out-of-place decoding, create a DPB pool */
12461173 if (dec->dedicated_dpb || avctx->codec_id == AV_CODEC_ID_AV1) {
12471174 AVHWFramesContext *dpb_frames;
12481175 AVVulkanFramesContext *dpb_hwfc;
12491176
1250− ctx->dpb_hwfc_ref = av_hwframe_ctx_alloc(s->frames->device_ref);
1251− if (!ctx->dpb_hwfc_ref) {
1177+ ctx->common.dpb_hwfc_ref = av_hwframe_ctx_alloc(s->frames->device_ref);
1178+ if (!ctx->common.dpb_hwfc_ref) {
12521179 err = AVERROR(ENOMEM);
12531180 goto fail;
12541181 }
12551182
1256− dpb_frames = (AVHWFramesContext *)ctx->dpb_hwfc_ref->data;
1183+ dpb_frames = (AVHWFramesContext *)ctx->common.dpb_hwfc_ref->data;
12571184 dpb_frames->format = s->frames->format;
12581185 dpb_frames->sw_format = s->frames->sw_format;
12591186 dpb_frames->width = avctx->coded_width;
@@ -1267,23 +1194,25 @@ int ff_vk_decode_init(AVCodecContext *avctx) · 7 unmodified lines
12671194 dpb_hwfc->usage = VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR |
12681195 VK_IMAGE_USAGE_SAMPLED_BIT; /* Shuts validator up. */
12691196
1270− if (dec->layered_dpb)
1197+ if (ctx->common.layered_dpb)
12711198 dpb_hwfc->nb_layers = ctx->caps.maxDpbSlots;
12721199
1273− err = av_hwframe_ctx_init(ctx->dpb_hwfc_ref);
1200+ err = av_hwframe_ctx_init(ctx->common.dpb_hwfc_ref);
12741201 if (err < 0)
12751202 goto fail;
12761203
1277− if (dec->layered_dpb) {
1278− ctx->layered_frame = vk_get_dpb_pool(ctx);
1279− if (!ctx->layered_frame) {
1204+ if (ctx->common.layered_dpb) {
1205+ ctx->common.layered_frame = vk_get_dpb_pool(ctx);
1206+ if (!ctx->common.layered_frame) {
12801207 err = AVERROR(ENOMEM);
12811208 goto fail;
12821209 }
12831210
1284− err = vk_decode_create_view(dec, &ctx->layered_view, &ctx->layered_aspect,
1285− (AVVkFrame *)ctx->layered_frame->data[0],
1286− s->hwfc->format[0], 0);
1211+ err = ff_vk_create_view(&ctx->s, &ctx->common,
1212+ &ctx->common.layered_view,
1213+ &ctx->common.layered_aspect,
1214+ (AVVkFrame *)ctx->common.layered_frame->data[0],
1215+ s->hwfc->format[0], 1);
12871216 if (err < 0)
12881217 goto fail;
12891218 }
libavcodec/vulkan_decode.h+0−9
@@ -53,15 +53,7 @@ typedef struct FFVulkanDecodeShared { · 52 unmodified lines
5353 VkVideoCapabilitiesKHR caps;
5454 VkVideoDecodeCapabilitiesKHR dec_caps;
5555
56− AVBufferRef *dpb_hwfc_ref; /* Only used for dedicated_dpb */
57−
58− AVFrame *layered_frame; /* Only used for layered_dpb */
59− VkImageView layered_view;
60− VkImageAspectFlags layered_aspect;
61−
6256 VkVideoSessionParametersKHR empty_session_params;
63−
64− VkSamplerYcbcrConversion yuv_sampler;
6557 } FFVulkanDecodeShared;
6658
6759 typedef struct FFVulkanDecodeContext {
@@ -70,7 +62,6 @@ typedef struct FFVulkanDecodeContext { · 2 unmodified lines
7062 FFVkExecPool exec_pool;
7163
7264 int dedicated_dpb; /* Oddity #1 - separate DPB images */
73− int layered_dpb; /* Madness #1 - layered DPB images */
7465 int external_fg; /* Oddity #2 - hardware can't apply film grain */
7566 uint32_t frame_id_alloc_mask; /* For AV1 only */
7667
libavcodec/vulkan_h264.c+2−1
@@ -60,6 +60,7 @@ static int vk_h264_fill_pict(AVCodecContext *avctx, H264Picture **ref_src, · 59 unmodified lines
6060 int dpb_slot_index)
6161 {
6262 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
63+ FFVulkanDecodeShared *ctx = dec->shared_ctx;
6364 H264VulkanDecodePicture *hp = pic->hwaccel_picture_private;
6465 FFVulkanDecodePicture *vkpic = &hp->vp;
6566
@@ -95,7 +96,7 @@ static int vk_h264_fill_pict(AVCodecContext *avctx, H264Picture **ref_src, · 29 unmodified lines
9596 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
9697 .codedOffset = (VkOffset2D){ 0, 0 },
9798 .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },
98− .baseArrayLayer = dec->layered_dpb ? dpb_slot_index : 0,
99+ .baseArrayLayer = ctx->common.layered_dpb ? dpb_slot_index : 0,
99100 .imageViewBinding = vkpic->img_view_ref,
100101 };
101102
libavcodec/vulkan_hevc.c+2−1
@@ -136,6 +136,7 @@ static int vk_hevc_fill_pict(AVCodecContext *avctx, HEVCFrame **ref_src, · 135 unmodified lines
136136 HEVCFrame *pic, int is_current, int pic_id)
137137 {
138138 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
139+ FFVulkanDecodeShared *ctx = dec->shared_ctx;
139140 HEVCVulkanDecodePicture *hp = pic->hwaccel_picture_private;
140141 FFVulkanDecodePicture *vkpic = &hp->vp;
141142
@@ -161,7 +162,7 @@ static int vk_hevc_fill_pict(AVCodecContext *avctx, HEVCFrame **ref_src, · 19 unmodified lines
161162 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
162163 .codedOffset = (VkOffset2D){ 0, 0 },
163164 .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },
164− .baseArrayLayer = dec->layered_dpb ? pic_id : 0,
165+ .baseArrayLayer = ctx->common.layered_dpb ? pic_id : 0,
165166 .imageViewBinding = vkpic->img_view_ref,
166167 };
167168
libavcodec/vulkan_video.c+77−3
@@ -16,7 +16,6 @@ · 15 unmodified lines
1616 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717 */
1818
19−#include "defs.h"
2019 #include "libavutil/mem.h"
2120 #include "vulkan_video.h"
2221
@@ -240,6 +239,50 @@ int ff_vk_video_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, · 217 unmodified lines
240239 return AVERROR(ENOTSUP);
241240 }
242241
242+int ff_vk_create_view(FFVulkanContext *s, FFVkVideoCommon *common,
243+ VkImageView *view, VkImageAspectFlags *aspect,
244+ AVVkFrame *src, VkFormat vkf, int is_dpb)
245+{
246+ VkResult ret;
247+ FFVulkanFunctions *vk = &s->vkfn;
248+ VkImageAspectFlags aspect_mask = ff_vk_aspect_bits_from_vkfmt(vkf);
249+
250+ VkSamplerYcbcrConversionInfo yuv_sampler_info = {
251+ .sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
252+ .conversion = common->yuv_sampler,
253+ };
254+ VkImageViewCreateInfo img_view_create_info = {
255+ .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
256+ .pNext = &yuv_sampler_info,
257+ .viewType = common->layered_dpb && is_dpb ?
258+ VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D,
259+ .format = vkf,
260+ .image = src->img[0],
261+ .components = (VkComponentMapping) {
262+ .r = VK_COMPONENT_SWIZZLE_IDENTITY,
263+ .g = VK_COMPONENT_SWIZZLE_IDENTITY,
264+ .b = VK_COMPONENT_SWIZZLE_IDENTITY,
265+ .a = VK_COMPONENT_SWIZZLE_IDENTITY,
266+ },
267+ .subresourceRange = (VkImageSubresourceRange) {
268+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
269+ .baseArrayLayer = 0,
270+ .layerCount = common->layered_dpb && is_dpb ?
271+ VK_REMAINING_ARRAY_LAYERS : 1,
272+ .levelCount = 1,
273+ },
274+ };
275+
276+ ret = vk->CreateImageView(s->hwctx->act_dev, &img_view_create_info,
277+ s->hwctx->alloc, view);
278+ if (ret != VK_SUCCESS)
279+ return AVERROR_EXTERNAL;
280+
281+ *aspect = aspect_mask;
282+
283+ return 0;
284+}
285+
243286 av_cold void ff_vk_video_common_uninit(FFVulkanContext *s,
244287 FFVkVideoCommon *common)
245288 {
@@ -256,9 +299,21 @@ av_cold void ff_vk_video_common_uninit(FFVulkanContext *s, · 10 unmodified lines
256299 vk->FreeMemory(s->hwctx->act_dev, common->mem[i], s->hwctx->alloc);
257300
258301 av_freep(&common->mem);
302+
303+ if (common->layered_view)
304+ vk->DestroyImageView(s->hwctx->act_dev, common->layered_view,
305+ s->hwctx->alloc);
306+
307+ av_frame_free(&common->layered_frame);
308+
309+ av_buffer_unref(&common->dpb_hwfc_ref);
310+
311+ if (common->yuv_sampler)
312+ vk->DestroySamplerYcbcrConversion(s->hwctx->act_dev, common->yuv_sampler,
313+ s->hwctx->alloc);
259314 }
260315
261−av_cold int ff_vk_video_common_init(void *log, FFVulkanContext *s,
316+av_cold int ff_vk_video_common_init(AVCodecContext *avctx, FFVulkanContext *s,
262317 FFVkVideoCommon *common,
263318 VkVideoSessionCreateInfoKHR *session_create)
264319 {
@@ -268,6 +323,25 @@ av_cold int ff_vk_video_common_init(void *log, FFVulkanContext *s, · 3 unmodified lines
268323 VkVideoSessionMemoryRequirementsKHR *mem = NULL;
269324 VkBindVideoSessionMemoryInfoKHR *bind_mem = NULL;
270325
326+ int cxpos = 0, cypos = 0;
327+ VkSamplerYcbcrConversionCreateInfo yuv_sampler_info = {
328+ .sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
329+ .components = ff_comp_identity_map,
330+ .ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY,
331+ .ycbcrRange = avctx->color_range == AVCOL_RANGE_MPEG, /* Ignored */
332+ .format = session_create->pictureFormat,
333+ };
334+
335+ /* Create identity YUV sampler
336+ * (VkImageViews of YUV image formats require it, even if it does nothing) */
337+ av_chroma_location_enum_to_pos(&cxpos, &cypos, avctx->chroma_sample_location);
338+ yuv_sampler_info.xChromaOffset = cxpos >> 7;
339+ yuv_sampler_info.yChromaOffset = cypos >> 7;
340+ ret = vk->CreateSamplerYcbcrConversion(s->hwctx->act_dev, &yuv_sampler_info,
341+ s->hwctx->alloc, &common->yuv_sampler);
342+ if (ret != VK_SUCCESS)
343+ return AVERROR_EXTERNAL;
344+
271345 /* Create session */
272346 ret = vk->CreateVideoSessionKHR(s->hwctx->act_dev, session_create,
273347 s->hwctx->alloc, &common->session);
@@ -333,7 +407,7 @@ av_cold int ff_vk_video_common_init(void *log, FFVulkanContext *s, · 59 unmodified lines
333407 .memorySize = mem[i].memoryRequirements.size,
334408 };
335409
336− av_log(log, AV_LOG_VERBOSE, "Allocating %"PRIu64" bytes in bind index %i for video session\n",
410+ av_log(avctx, AV_LOG_VERBOSE, "Allocating %"PRIu64" bytes in bind index %i for video session\n",
337411 bind_mem[i].memorySize, bind_mem[i].memoryBindIndex);
338412 }
339413
libavcodec/vulkan_video.h+17−1
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #ifndef AVCODEC_VULKAN_VIDEO_H
2020 #define AVCODEC_VULKAN_VIDEO_H
2121
22+#include "avcodec.h"
2223 #include "vulkan.h"
2324
2425 #include <vk_video/vulkan_video_codecs_common.h>
@@ -32,6 +33,14 @@ typedef struct FFVkVideoSession { · 7 unmodified lines
3233 VkVideoSessionKHR session;
3334 VkDeviceMemory *mem;
3435 uint32_t nb_mem;
36+
37+ VkSamplerYcbcrConversion yuv_sampler;
38+
39+ AVBufferRef *dpb_hwfc_ref;
40+ int layered_dpb;
41+ AVFrame *layered_frame;
42+ VkImageView layered_view;
43+ VkImageAspectFlags layered_aspect;
3544 } FFVkVideoCommon;
3645
3746 /**
@@ -74,10 +83,17 @@ StdVideoH264LevelIdc ff_vk_h264_level_to_vk(int level_idc); · 36 unmodified lines
7483 StdVideoH264ProfileIdc ff_vk_h264_profile_to_vk(int profile);
7584 int ff_vk_h264_profile_to_av(StdVideoH264ProfileIdc profile);
7685
86+/**
87+ * Creates image views for video frames.
88+ */
89+int ff_vk_create_view(FFVulkanContext *s, FFVkVideoCommon *common,
90+ VkImageView *view, VkImageAspectFlags *aspect,
91+ AVVkFrame *src, VkFormat vkf, int is_dpb);
92+
7793 /**
7894 * Initialize video session, allocating and binding necessary memory.
7995 */
80−int ff_vk_video_common_init(void *log, FFVulkanContext *s,
96+int ff_vk_video_common_init(AVCodecContext *avctx, FFVulkanContext *s,
8197 FFVkVideoCommon *common,
8298 VkVideoSessionCreateInfoKHR *session_create);
8399

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t