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
79 const uint8_t *saved_order_hints)79 const uint8_t *saved_order_hints)
80{80{
81 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;81 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
82 FFVulkanDecodeShared *ctx = dec->shared_ctx;
82 AV1VulkanDecodePicture *hp = pic->hwaccel_picture_private;83 AV1VulkanDecodePicture *hp = pic->hwaccel_picture_private;
83 FFVulkanDecodePicture *vkpic = &hp->vp;84 FFVulkanDecodePicture *vkpic = &hp->vp;
84 85
@@ -119,7 +120,7 @@ static int vk_av1_fill_pict(AVCodecContext *avctx, const AV1Frame **ref_src, · 34 unmodified lines
119 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,120 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
120 .codedOffset = (VkOffset2D){ 0, 0 },121 .codedOffset = (VkOffset2D){ 0, 0 },
121 .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },122 .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) ?
123 hp->frame_id : 0,124 hp->frame_id : 0,
124 .imageViewBinding = vkpic->img_view_ref,125 .imageViewBinding = vkpic->img_view_ref,
125 };126 };
libavcodec/vulkan_decode.c+33−104
@@ -111,7 +111,6 @@ int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) · 110 unmodified lines
111 }111 }
112 112
113 dst_ctx->dedicated_dpb = src_ctx->dedicated_dpb;113 dst_ctx->dedicated_dpb = src_ctx->dedicated_dpb;
114 dst_ctx->layered_dpb = src_ctx->layered_dpb;
115 dst_ctx->external_fg = src_ctx->external_fg;114 dst_ctx->external_fg = src_ctx->external_fg;
116 dst_ctx->frame_id_alloc_mask = src_ctx->frame_id_alloc_mask;115 dst_ctx->frame_id_alloc_mask = src_ctx->frame_id_alloc_mask;
117 116
@@ -125,51 +124,6 @@ int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint · 7 unmodified lines
125 return 0;124 return 0;
126}125}
127 126
128static 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
173static AVFrame *vk_get_dpb_pool(FFVulkanDecodeShared *ctx)127static AVFrame *vk_get_dpb_pool(FFVulkanDecodeShared *ctx)
174{128{
175 int err;129 int err;
@@ -177,7 +131,7 @@ static AVFrame *vk_get_dpb_pool(FFVulkanDecodeShared *ctx) · 1 unmodified line
177 if (!avf)131 if (!avf)
178 return NULL;132 return NULL;
179 133
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);
181 if (err < 0)135 if (err < 0)
182 av_frame_free(&avf);136 av_frame_free(&avf);
183 137
@@ -207,21 +161,21 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic, · 23 unmodified lines
207 vkpic->destroy_image_view = vk->DestroyImageView;161 vkpic->destroy_image_view = vk->DestroyImageView;
208 vkpic->wait_semaphores = vk->WaitSemaphores;162 vkpic->wait_semaphores = vk->WaitSemaphores;
209 163
210 if (dec->layered_dpb && alloc_dpb) {164 if (ctx->common.layered_dpb && alloc_dpb) {
211 vkpic->img_view_ref = ctx->layered_view;165 vkpic->img_view_ref = ctx->common.layered_view;
212 vkpic->img_aspect_ref = ctx->layered_aspect;166 vkpic->img_aspect_ref = ctx->common.layered_aspect;
213 } else if (alloc_dpb) {167 } 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;
215 AVVulkanFramesContext *dpb_hwfc = dpb_frames->hwctx;169 AVVulkanFramesContext *dpb_hwfc = dpb_frames->hwctx;
216 170
217 vkpic->dpb_frame = vk_get_dpb_pool(ctx);171 vkpic->dpb_frame = vk_get_dpb_pool(ctx);
218 if (!vkpic->dpb_frame)172 if (!vkpic->dpb_frame)
219 return AVERROR(ENOMEM);173 return AVERROR(ENOMEM);
220 174
221 err = vk_decode_create_view(dec, &vkpic->img_view_ref,175 err = ff_vk_create_view(&ctx->s, &ctx->common,
222 &vkpic->img_aspect_ref,176 &vkpic->img_view_ref, &vkpic->img_aspect_ref,
223 (AVVkFrame *)vkpic->dpb_frame->data[0],177 (AVVkFrame *)vkpic->dpb_frame->data[0],
224 dpb_hwfc->format[0], is_current);178 dpb_hwfc->format[0], !is_current);
225 if (err < 0)179 if (err < 0)
226 return err;180 return err;
227 181
@@ -232,10 +186,10 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic, · 4 unmodified lines
232 AVHWFramesContext *frames = (AVHWFramesContext *)pic->hw_frames_ctx->data;186 AVHWFramesContext *frames = (AVHWFramesContext *)pic->hw_frames_ctx->data;
233 AVVulkanFramesContext *hwfc = frames->hwctx;187 AVVulkanFramesContext *hwfc = frames->hwctx;
234 188
235 err = vk_decode_create_view(dec, &vkpic->img_view_out,189 err = ff_vk_create_view(&ctx->s, &ctx->common,
236 &vkpic->img_aspect,190 &vkpic->img_view_out, &vkpic->img_aspect,
237 (AVVkFrame *)pic->data[0],191 (AVVkFrame *)pic->data[0],
238 hwfc->format[0], is_current);192 hwfc->format[0], !is_current);
239 if (err < 0)193 if (err < 0)
240 return err;194 return err;
241 195
@@ -366,7 +320,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx, · 124 unmodified lines
366 AVVkFrame *vkf = (AVVkFrame *)pic->buf[0]->data;320 AVVkFrame *vkf = (AVVkFrame *)pic->buf[0]->data;
367 321
368 /* Quirks */322 /* Quirks */
369 const int layered_dpb = dec->layered_dpb;323 const int layered_dpb = ctx->common.layered_dpb;
370 324
371 VkVideoSessionParametersKHR *par = (VkVideoSessionParametersKHR *)dec->session_params->data;325 VkVideoSessionParametersKHR *par = (VkVideoSessionParametersKHR *)dec->session_params->data;
372 VkVideoBeginCodingInfoKHR decode_start = {326 VkVideoBeginCodingInfoKHR decode_start = {
@@ -470,7 +424,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx, · 97 unmodified lines
470 .srcAccessMask = VK_ACCESS_2_NONE,424 .srcAccessMask = VK_ACCESS_2_NONE,
471 .dstAccessMask = VK_ACCESS_2_VIDEO_DECODE_WRITE_BIT_KHR,425 .dstAccessMask = VK_ACCESS_2_VIDEO_DECODE_WRITE_BIT_KHR,
472 .oldLayout = vkf->layout[0],426 .oldLayout = vkf->layout[0],
473 .newLayout = (dec->layered_dpb || vp->dpb_frame) ?427 .newLayout = (layered_dpb || vp->dpb_frame) ?
474 VK_IMAGE_LAYOUT_VIDEO_DECODE_DST_KHR :428 VK_IMAGE_LAYOUT_VIDEO_DECODE_DST_KHR :
475 VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR, /* Spec, 07252 utter madness */429 VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR, /* Spec, 07252 utter madness */
476 .srcQueueFamilyIndex = vkf->queue_family[0],430 .srcQueueFamilyIndex = vkf->queue_family[0],
@@ -545,7 +499,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx, · 68 unmodified lines
545 } else if (vp->decode_info.referenceSlotCount ||499 } else if (vp->decode_info.referenceSlotCount ||
546 vp->img_view_out != vp->img_view_ref) {500 vp->img_view_out != vp->img_view_ref) {
547 /* Single barrier for a single layered ref */501 /* 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,
549 VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR,503 VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR,
550 VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR);504 VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR);
551 if (err < 0)505 if (err < 0)
@@ -616,13 +570,8 @@ static void free_common(FFRefStructOpaque unused, void *obj) · 64 unmodified lines
616 FFVulkanContext *s = &ctx->s;570 FFVulkanContext *s = &ctx->s;
617 FFVulkanFunctions *vk = &ctx->s.vkfn;571 FFVulkanFunctions *vk = &ctx->s.vkfn;
618 572
619 /* Destroy layered view */
620 if (ctx->layered_view)
621 vk->DestroyImageView(s->hwctx->act_dev, ctx->layered_view, s->hwctx->alloc);
622
623 /* This also frees all references from this pool */573 /* This also frees all references from this pool */
624 av_frame_free(&ctx->layered_frame);574 av_frame_free(&ctx->common.layered_frame);
625 av_buffer_unref(&ctx->dpb_hwfc_ref);
626 575
627 /* Destroy parameters */576 /* Destroy parameters */
628 if (ctx->empty_session_params)577 if (ctx->empty_session_params)
@@ -634,10 +583,6 @@ static void free_common(FFRefStructOpaque unused, void *obj) · 5 unmodified lines
634 583
635 ff_vk_video_common_uninit(s, &ctx->common);584 ff_vk_video_common_uninit(s, &ctx->common);
636 585
637 if (ctx->yuv_sampler)
638 vk->DestroySamplerYcbcrConversion(s->hwctx->act_dev, ctx->yuv_sampler,
639 s->hwctx->alloc);
640
641 ff_vk_uninit(s);586 ff_vk_uninit(s);
642}587}
643 588
@@ -924,8 +869,8 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_ · 280 unmodified lines
924 }869 }
925 870
926 dec->dedicated_dpb = !(dec_caps->flags & VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR);871 dec->dedicated_dpb = !(dec_caps->flags & VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR);
927 dec->layered_dpb = !dec->dedicated_dpb ? 0 :872 ctx->common.layered_dpb = !dec->dedicated_dpb ? 0 :
928 !(caps->flags & VK_VIDEO_CAPABILITY_SEPARATE_REFERENCE_IMAGES_BIT_KHR);873 !(caps->flags & VK_VIDEO_CAPABILITY_SEPARATE_REFERENCE_IMAGES_BIT_KHR);
929 874
930 if (dec->dedicated_dpb) {875 if (dec->dedicated_dpb) {
931 fmt_info.imageUsage = VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR;876 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
1128 1073
1129int ff_vk_decode_init(AVCodecContext *avctx)1074int ff_vk_decode_init(AVCodecContext *avctx)
1130{1075{
1131 int err, cxpos = 0, cypos = 0, nb_q = 0;1076 int err, nb_q = 0;
1132 VkResult ret;1077 VkResult ret;
1133 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;1078 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
1134 FFVulkanDecodeShared *ctx;1079 FFVulkanDecodeShared *ctx;
@@ -1159,12 +1104,6 @@ int ff_vk_decode_init(AVCodecContext *avctx) · 24 unmodified lines
1159 VkVideoSessionCreateInfoKHR session_create = {1104 VkVideoSessionCreateInfoKHR session_create = {
1160 .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_CREATE_INFO_KHR,1105 .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_CREATE_INFO_KHR,
1161 };1106 };
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 };
1168 1107
1169 err = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VULKAN);1108 err = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VULKAN);
1170 if (err < 0)1109 if (err < 0)
@@ -1230,30 +1169,18 @@ int ff_vk_decode_init(AVCodecContext *avctx) · 59 unmodified lines
1230 if (err < 0)1169 if (err < 0)
1231 goto fail;1170 goto fail;
1232 1171
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
1245 /* If doing an out-of-place decoding, create a DPB pool */1172 /* If doing an out-of-place decoding, create a DPB pool */
1246 if (dec->dedicated_dpb || avctx->codec_id == AV_CODEC_ID_AV1) {1173 if (dec->dedicated_dpb || avctx->codec_id == AV_CODEC_ID_AV1) {
1247 AVHWFramesContext *dpb_frames;1174 AVHWFramesContext *dpb_frames;
1248 AVVulkanFramesContext *dpb_hwfc;1175 AVVulkanFramesContext *dpb_hwfc;
1249 1176
1250 ctx->dpb_hwfc_ref = av_hwframe_ctx_alloc(s->frames->device_ref);1177 ctx->common.dpb_hwfc_ref = av_hwframe_ctx_alloc(s->frames->device_ref);
1251 if (!ctx->dpb_hwfc_ref) {1178 if (!ctx->common.dpb_hwfc_ref) {
1252 err = AVERROR(ENOMEM);1179 err = AVERROR(ENOMEM);
1253 goto fail;1180 goto fail;
1254 }1181 }
1255 1182
1256 dpb_frames = (AVHWFramesContext *)ctx->dpb_hwfc_ref->data;1183 dpb_frames = (AVHWFramesContext *)ctx->common.dpb_hwfc_ref->data;
1257 dpb_frames->format = s->frames->format;1184 dpb_frames->format = s->frames->format;
1258 dpb_frames->sw_format = s->frames->sw_format;1185 dpb_frames->sw_format = s->frames->sw_format;
1259 dpb_frames->width = avctx->coded_width;1186 dpb_frames->width = avctx->coded_width;
@@ -1267,23 +1194,25 @@ int ff_vk_decode_init(AVCodecContext *avctx) · 7 unmodified lines
1267 dpb_hwfc->usage = VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR |1194 dpb_hwfc->usage = VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR |
1268 VK_IMAGE_USAGE_SAMPLED_BIT; /* Shuts validator up. */1195 VK_IMAGE_USAGE_SAMPLED_BIT; /* Shuts validator up. */
1269 1196
1270 if (dec->layered_dpb)1197 if (ctx->common.layered_dpb)
1271 dpb_hwfc->nb_layers = ctx->caps.maxDpbSlots;1198 dpb_hwfc->nb_layers = ctx->caps.maxDpbSlots;
1272 1199
1273 err = av_hwframe_ctx_init(ctx->dpb_hwfc_ref);1200 err = av_hwframe_ctx_init(ctx->common.dpb_hwfc_ref);
1274 if (err < 0)1201 if (err < 0)
1275 goto fail;1202 goto fail;
1276 1203
1277 if (dec->layered_dpb) {1204 if (ctx->common.layered_dpb) {
1278 ctx->layered_frame = vk_get_dpb_pool(ctx);1205 ctx->common.layered_frame = vk_get_dpb_pool(ctx);
1279 if (!ctx->layered_frame) {1206 if (!ctx->common.layered_frame) {
1280 err = AVERROR(ENOMEM);1207 err = AVERROR(ENOMEM);
1281 goto fail;1208 goto fail;
1282 }1209 }
1283 1210
1284 err = vk_decode_create_view(dec, &ctx->layered_view, &ctx->layered_aspect,1211 err = ff_vk_create_view(&ctx->s, &ctx->common,
1285 (AVVkFrame *)ctx->layered_frame->data[0],1212 &ctx->common.layered_view,
1286 s->hwfc->format[0], 0);1213 &ctx->common.layered_aspect,
1214 (AVVkFrame *)ctx->common.layered_frame->data[0],
1215 s->hwfc->format[0], 1);
1287 if (err < 0)1216 if (err < 0)
1288 goto fail;1217 goto fail;
1289 }1218 }
libavcodec/vulkan_decode.h+0−9
@@ -53,15 +53,7 @@ typedef struct FFVulkanDecodeShared { · 52 unmodified lines
53 VkVideoCapabilitiesKHR caps;53 VkVideoCapabilitiesKHR caps;
54 VkVideoDecodeCapabilitiesKHR dec_caps;54 VkVideoDecodeCapabilitiesKHR dec_caps;
55 55
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
62 VkVideoSessionParametersKHR empty_session_params;56 VkVideoSessionParametersKHR empty_session_params;
63
64 VkSamplerYcbcrConversion yuv_sampler;
65} FFVulkanDecodeShared;57} FFVulkanDecodeShared;
66 58
67typedef struct FFVulkanDecodeContext {59typedef struct FFVulkanDecodeContext {
@@ -70,7 +62,6 @@ typedef struct FFVulkanDecodeContext { · 2 unmodified lines
70 FFVkExecPool exec_pool;62 FFVkExecPool exec_pool;
71 63
72 int dedicated_dpb; /* Oddity #1 - separate DPB images */64 int dedicated_dpb; /* Oddity #1 - separate DPB images */
73 int layered_dpb; /* Madness #1 - layered DPB images */
74 int external_fg; /* Oddity #2 - hardware can't apply film grain */65 int external_fg; /* Oddity #2 - hardware can't apply film grain */
75 uint32_t frame_id_alloc_mask; /* For AV1 only */66 uint32_t frame_id_alloc_mask; /* For AV1 only */
76 67
libavcodec/vulkan_h264.c+2−1
@@ -60,6 +60,7 @@ static int vk_h264_fill_pict(AVCodecContext *avctx, H264Picture **ref_src, · 59 unmodified lines
60 int dpb_slot_index)60 int dpb_slot_index)
61{61{
62 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;62 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
63 FFVulkanDecodeShared *ctx = dec->shared_ctx;
63 H264VulkanDecodePicture *hp = pic->hwaccel_picture_private;64 H264VulkanDecodePicture *hp = pic->hwaccel_picture_private;
64 FFVulkanDecodePicture *vkpic = &hp->vp;65 FFVulkanDecodePicture *vkpic = &hp->vp;
65 66
@@ -95,7 +96,7 @@ static int vk_h264_fill_pict(AVCodecContext *avctx, H264Picture **ref_src, · 29 unmodified lines
95 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,96 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
96 .codedOffset = (VkOffset2D){ 0, 0 },97 .codedOffset = (VkOffset2D){ 0, 0 },
97 .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },98 .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,
99 .imageViewBinding = vkpic->img_view_ref,100 .imageViewBinding = vkpic->img_view_ref,
100 };101 };
101 102
libavcodec/vulkan_hevc.c+2−1
@@ -136,6 +136,7 @@ static int vk_hevc_fill_pict(AVCodecContext *avctx, HEVCFrame **ref_src, · 135 unmodified lines
136 HEVCFrame *pic, int is_current, int pic_id)136 HEVCFrame *pic, int is_current, int pic_id)
137{137{
138 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;138 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
139 FFVulkanDecodeShared *ctx = dec->shared_ctx;
139 HEVCVulkanDecodePicture *hp = pic->hwaccel_picture_private;140 HEVCVulkanDecodePicture *hp = pic->hwaccel_picture_private;
140 FFVulkanDecodePicture *vkpic = &hp->vp;141 FFVulkanDecodePicture *vkpic = &hp->vp;
141 142
@@ -161,7 +162,7 @@ static int vk_hevc_fill_pict(AVCodecContext *avctx, HEVCFrame **ref_src, · 19 unmodified lines
161 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,162 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
162 .codedOffset = (VkOffset2D){ 0, 0 },163 .codedOffset = (VkOffset2D){ 0, 0 },
163 .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },164 .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,
165 .imageViewBinding = vkpic->img_view_ref,166 .imageViewBinding = vkpic->img_view_ref,
166 };167 };
167 168
libavcodec/vulkan_video.c+77−3
@@ -16,7 +16,6 @@ · 15 unmodified lines
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */17 */
18 18
19#include "defs.h"
20#include "libavutil/mem.h"19#include "libavutil/mem.h"
21#include "vulkan_video.h"20#include "vulkan_video.h"
22 21
@@ -240,6 +239,50 @@ int ff_vk_video_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, · 217 unmodified lines
240 return AVERROR(ENOTSUP);239 return AVERROR(ENOTSUP);
241}240}
242 241
242int 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
243av_cold void ff_vk_video_common_uninit(FFVulkanContext *s,286av_cold void ff_vk_video_common_uninit(FFVulkanContext *s,
244 FFVkVideoCommon *common)287 FFVkVideoCommon *common)
245{288{
@@ -256,9 +299,21 @@ av_cold void ff_vk_video_common_uninit(FFVulkanContext *s, · 10 unmodified lines
256 vk->FreeMemory(s->hwctx->act_dev, common->mem[i], s->hwctx->alloc);299 vk->FreeMemory(s->hwctx->act_dev, common->mem[i], s->hwctx->alloc);
257 300
258 av_freep(&common->mem);301 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);
259}314}
260 315
261av_cold int ff_vk_video_common_init(void *log, FFVulkanContext *s,316av_cold int ff_vk_video_common_init(AVCodecContext *avctx, FFVulkanContext *s,
262 FFVkVideoCommon *common,317 FFVkVideoCommon *common,
263 VkVideoSessionCreateInfoKHR *session_create)318 VkVideoSessionCreateInfoKHR *session_create)
264{319{
@@ -268,6 +323,25 @@ av_cold int ff_vk_video_common_init(void *log, FFVulkanContext *s, · 3 unmodified lines
268 VkVideoSessionMemoryRequirementsKHR *mem = NULL;323 VkVideoSessionMemoryRequirementsKHR *mem = NULL;
269 VkBindVideoSessionMemoryInfoKHR *bind_mem = NULL;324 VkBindVideoSessionMemoryInfoKHR *bind_mem = NULL;
270 325
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
271 /* Create session */345 /* Create session */
272 ret = vk->CreateVideoSessionKHR(s->hwctx->act_dev, session_create,346 ret = vk->CreateVideoSessionKHR(s->hwctx->act_dev, session_create,
273 s->hwctx->alloc, &common->session);347 s->hwctx->alloc, &common->session);
@@ -333,7 +407,7 @@ av_cold int ff_vk_video_common_init(void *log, FFVulkanContext *s, · 59 unmodified lines
333 .memorySize = mem[i].memoryRequirements.size,407 .memorySize = mem[i].memoryRequirements.size,
334 };408 };
335 409
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",
337 bind_mem[i].memorySize, bind_mem[i].memoryBindIndex);411 bind_mem[i].memorySize, bind_mem[i].memoryBindIndex);
338 }412 }
339 413
libavcodec/vulkan_video.h+17−1
@@ -19,6 +19,7 @@ · 18 unmodified lines
19#ifndef AVCODEC_VULKAN_VIDEO_H19#ifndef AVCODEC_VULKAN_VIDEO_H
20#define AVCODEC_VULKAN_VIDEO_H20#define AVCODEC_VULKAN_VIDEO_H
21 21
22#include "avcodec.h"
22#include "vulkan.h"23#include "vulkan.h"
23 24
24#include <vk_video/vulkan_video_codecs_common.h>25#include <vk_video/vulkan_video_codecs_common.h>
@@ -32,6 +33,14 @@ typedef struct FFVkVideoSession { · 7 unmodified lines
32 VkVideoSessionKHR session;33 VkVideoSessionKHR session;
33 VkDeviceMemory *mem;34 VkDeviceMemory *mem;
34 uint32_t nb_mem;35 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;
35} FFVkVideoCommon;44} FFVkVideoCommon;
36 45
37/**46/**
@@ -74,10 +83,17 @@ StdVideoH264LevelIdc ff_vk_h264_level_to_vk(int level_idc); · 36 unmodified lines
74StdVideoH264ProfileIdc ff_vk_h264_profile_to_vk(int profile);83StdVideoH264ProfileIdc ff_vk_h264_profile_to_vk(int profile);
75int ff_vk_h264_profile_to_av(StdVideoH264ProfileIdc profile);84int ff_vk_h264_profile_to_av(StdVideoH264ProfileIdc profile);
76 85
86/**
87 * Creates image views for video frames.
88 */
89int ff_vk_create_view(FFVulkanContext *s, FFVkVideoCommon *common,
90 VkImageView *view, VkImageAspectFlags *aspect,
91 AVVkFrame *src, VkFormat vkf, int is_dpb);
92
77/**93/**
78 * Initialize video session, allocating and binding necessary memory.94 * Initialize video session, allocating and binding necessary memory.
79 */95 */
80int ff_vk_video_common_init(void *log, FFVulkanContext *s,96int ff_vk_video_common_init(AVCodecContext *avctx, FFVulkanContext *s,
81 FFVkVideoCommon *common,97 FFVkVideoCommon *common,
82 VkVideoSessionCreateInfoKHR *session_create);98 VkVideoSessionCreateInfoKHR *session_create);
83 99

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