| @@ -111,7 +111,6 @@ int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) · 110 unmodified lines |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | dst_ctx->dedicated_dpb = src_ctx->dedicated_dpb; |
| 114 | | − dst_ctx->layered_dpb = src_ctx->layered_dpb; |
| 115 | 114 | dst_ctx->external_fg = src_ctx->external_fg; |
| 116 | 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 | 124 | return 0; |
| 126 | 125 | } |
| 127 | 126 | |
| 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 | | − |
| 173 | 127 | static AVFrame *vk_get_dpb_pool(FFVulkanDecodeShared *ctx) |
| 174 | 128 | { |
| 175 | 129 | int err; |
| @@ -177,7 +131,7 @@ static AVFrame *vk_get_dpb_pool(FFVulkanDecodeShared *ctx) · 1 unmodified line |
| 177 | 131 | if (!avf) |
| 178 | 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 | 135 | if (err < 0) |
| 182 | 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 | 161 | vkpic->destroy_image_view = vk->DestroyImageView; |
| 208 | 162 | vkpic->wait_semaphores = vk->WaitSemaphores; |
| 209 | 163 | |
| 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; |
| 213 | 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 | 169 | AVVulkanFramesContext *dpb_hwfc = dpb_frames->hwctx; |
| 216 | 170 | |
| 217 | 171 | vkpic->dpb_frame = vk_get_dpb_pool(ctx); |
| 218 | 172 | if (!vkpic->dpb_frame) |
| 219 | 173 | return AVERROR(ENOMEM); |
| 220 | 174 | |
| 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); |
| 225 | 179 | if (err < 0) |
| 226 | 180 | return err; |
| 227 | 181 | |
| @@ -232,10 +186,10 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic, · 4 unmodified lines |
| 232 | 186 | AVHWFramesContext *frames = (AVHWFramesContext *)pic->hw_frames_ctx->data; |
| 233 | 187 | AVVulkanFramesContext *hwfc = frames->hwctx; |
| 234 | 188 | |
| 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); |
| 239 | 193 | if (err < 0) |
| 240 | 194 | return err; |
| 241 | 195 | |
| @@ -366,7 +320,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx, · 124 unmodified lines |
| 366 | 320 | AVVkFrame *vkf = (AVVkFrame *)pic->buf[0]->data; |
| 367 | 321 | |
| 368 | 322 | /* Quirks */ |
| 369 | | − const int layered_dpb = dec->layered_dpb; |
| 323 | + const int layered_dpb = ctx->common.layered_dpb; |
| 370 | 324 | |
| 371 | 325 | VkVideoSessionParametersKHR *par = (VkVideoSessionParametersKHR *)dec->session_params->data; |
| 372 | 326 | VkVideoBeginCodingInfoKHR decode_start = { |
| @@ -470,7 +424,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx, · 97 unmodified lines |
| 470 | 424 | .srcAccessMask = VK_ACCESS_2_NONE, |
| 471 | 425 | .dstAccessMask = VK_ACCESS_2_VIDEO_DECODE_WRITE_BIT_KHR, |
| 472 | 426 | .oldLayout = vkf->layout[0], |
| 473 | | − .newLayout = (dec->layered_dpb || vp->dpb_frame) ? |
| 427 | + .newLayout = (layered_dpb || vp->dpb_frame) ? |
| 474 | 428 | VK_IMAGE_LAYOUT_VIDEO_DECODE_DST_KHR : |
| 475 | 429 | VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR, /* Spec, 07252 utter madness */ |
| 476 | 430 | .srcQueueFamilyIndex = vkf->queue_family[0], |
| @@ -545,7 +499,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx, · 68 unmodified lines |
| 545 | 499 | } else if (vp->decode_info.referenceSlotCount || |
| 546 | 500 | vp->img_view_out != vp->img_view_ref) { |
| 547 | 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 | 503 | VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR, |
| 550 | 504 | VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR); |
| 551 | 505 | if (err < 0) |
| @@ -616,13 +570,8 @@ static void free_common(FFRefStructOpaque unused, void *obj) · 64 unmodified lines |
| 616 | 570 | FFVulkanContext *s = &ctx->s; |
| 617 | 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 | 573 | /* 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); |
| 626 | 575 | |
| 627 | 576 | /* Destroy parameters */ |
| 628 | 577 | if (ctx->empty_session_params) |
| @@ -634,10 +583,6 @@ static void free_common(FFRefStructOpaque unused, void *obj) · 5 unmodified lines |
| 634 | 583 | |
| 635 | 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 | 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 | 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 : |
| 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); |
| 929 | 874 | |
| 930 | 875 | if (dec->dedicated_dpb) { |
| 931 | 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 | |
| 1129 | 1074 | int 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 | 1077 | VkResult ret; |
| 1133 | 1078 | FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; |
| 1134 | 1079 | FFVulkanDecodeShared *ctx; |
| @@ -1159,12 +1104,6 @@ int ff_vk_decode_init(AVCodecContext *avctx) · 24 unmodified lines |
| 1159 | 1104 | VkVideoSessionCreateInfoKHR session_create = { |
| 1160 | 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 | 1108 | err = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VULKAN); |
| 1170 | 1109 | if (err < 0) |
| @@ -1230,30 +1169,18 @@ int ff_vk_decode_init(AVCodecContext *avctx) · 59 unmodified lines |
| 1230 | 1169 | if (err < 0) |
| 1231 | 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 | 1172 | /* If doing an out-of-place decoding, create a DPB pool */ |
| 1246 | 1173 | if (dec->dedicated_dpb || avctx->codec_id == AV_CODEC_ID_AV1) { |
| 1247 | 1174 | AVHWFramesContext *dpb_frames; |
| 1248 | 1175 | AVVulkanFramesContext *dpb_hwfc; |
| 1249 | 1176 | |
| 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) { |
| 1252 | 1179 | err = AVERROR(ENOMEM); |
| 1253 | 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 | 1184 | dpb_frames->format = s->frames->format; |
| 1258 | 1185 | dpb_frames->sw_format = s->frames->sw_format; |
| 1259 | 1186 | dpb_frames->width = avctx->coded_width; |
| @@ -1267,23 +1194,25 @@ int ff_vk_decode_init(AVCodecContext *avctx) · 7 unmodified lines |
| 1267 | 1194 | dpb_hwfc->usage = VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR | |
| 1268 | 1195 | VK_IMAGE_USAGE_SAMPLED_BIT; /* Shuts validator up. */ |
| 1269 | 1196 | |
| 1270 | | − if (dec->layered_dpb) |
| 1197 | + if (ctx->common.layered_dpb) |
| 1271 | 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 | 1201 | if (err < 0) |
| 1275 | 1202 | goto fail; |
| 1276 | 1203 | |
| 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) { |
| 1280 | 1207 | err = AVERROR(ENOMEM); |
| 1281 | 1208 | goto fail; |
| 1282 | 1209 | } |
| 1283 | 1210 | |
| 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); |
| 1287 | 1216 | if (err < 0) |
| 1288 | 1217 | goto fail; |
| 1289 | 1218 | } |