[FFmpeg-cvslog] vulkan_decode: fix pedantic validation issue

Lynne git at videolan.org
Wed Oct 25 22:47:31 EEST 2023


ffmpeg | branch: master | Lynne <dev at lynne.ee> | Tue Oct 24 22:43:06 2023 +0200| [467e4118393170ff11b7725ec4565350fd1da195] | committer: Lynne

vulkan_decode: fix pedantic validation issue

"Validation Error: [ VUID-VkImageViewCreateInfo-imageViewType-04974 ] Object 0: handle = 0x9f9b41000000003c, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0xc120e150 | vkCreateImageView():
Using pCreateInfo->viewType VK_IMAGE_VIEW_TYPE_2D and the subresourceRange.layerCount VK_REMAINING_ARRAY_LAYERS=(17) and must 1 (try looking into VK_IMAGE_VIEW_TYPE_*_ARRAY).
The Vulkan spec states: If viewType is VK_IMAGE_VIEW_TYPE_1D, VK_IMAGE_VIEW_TYPE_2D, or VK_IMAGE_VIEW_TYPE_3D; and subresourceRange.layerCount is VK_REMAINING_ARRAY_LAYERS,
then the remaining number of layers must be 1"

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=467e4118393170ff11b7725ec4565350fd1da195
---

 libavcodec/vulkan_decode.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index 3b9576c0a9..c01eeb9cdc 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -113,11 +113,12 @@ int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint
     return 0;
 }
 
-static int vk_decode_create_view(FFVulkanDecodeShared *ctx, VkImageView *dst_view,
+static int vk_decode_create_view(FFVulkanDecodeContext *dec, VkImageView *dst_view,
                                  VkImageAspectFlags *aspect, AVVkFrame *src,
-                                 VkFormat vkf)
+                                 VkFormat vkf, int is_current)
 {
     VkResult ret;
+    FFVulkanDecodeShared *ctx = dec->shared_ctx;
     FFVulkanFunctions *vk = &ctx->s.vkfn;
     VkImageAspectFlags aspect_mask = ff_vk_aspect_bits_from_vkfmt(vkf);
 
@@ -128,7 +129,8 @@ static int vk_decode_create_view(FFVulkanDecodeShared *ctx, VkImageView *dst_vie
     VkImageViewCreateInfo img_view_create_info = {
         .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
         .pNext = &yuv_sampler_info,
-        .viewType = VK_IMAGE_VIEW_TYPE_2D,
+        .viewType = dec->layered_dpb && !is_current ?
+                    VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D,
         .format = vkf,
         .image = src->img[0],
         .components = (VkComponentMapping) {
@@ -140,7 +142,8 @@ static int vk_decode_create_view(FFVulkanDecodeShared *ctx, VkImageView *dst_vie
         .subresourceRange = (VkImageSubresourceRange) {
             .aspectMask     = VK_IMAGE_ASPECT_COLOR_BIT,
             .baseArrayLayer = 0,
-            .layerCount     = VK_REMAINING_ARRAY_LAYERS,
+            .layerCount     = dec->layered_dpb && !is_current ?
+                              VK_REMAINING_ARRAY_LAYERS : 1,
             .levelCount     = 1,
         },
     };
@@ -203,10 +206,10 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic,
         if (!vkpic->dpb_frame)
             return AVERROR(ENOMEM);
 
-        err = vk_decode_create_view(ctx, &vkpic->img_view_ref,
+        err = vk_decode_create_view(dec, &vkpic->img_view_ref,
                                     &vkpic->img_aspect_ref,
                                     (AVVkFrame *)vkpic->dpb_frame->data[0],
-                                    dpb_hwfc->format[0]);
+                                    dpb_hwfc->format[0], is_current);
         if (err < 0)
             return err;
 
@@ -217,10 +220,10 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic,
         AVHWFramesContext *frames = (AVHWFramesContext *)pic->hw_frames_ctx->data;
         AVVulkanFramesContext *hwfc = frames->hwctx;
 
-        err = vk_decode_create_view(ctx, &vkpic->img_view_out,
+        err = vk_decode_create_view(dec, &vkpic->img_view_out,
                                     &vkpic->img_aspect,
                                     (AVVkFrame *)pic->data[0],
-                                    hwfc->format[0]);
+                                    hwfc->format[0], is_current);
         if (err < 0)
             return err;
 
@@ -1249,9 +1252,9 @@ int ff_vk_decode_init(AVCodecContext *avctx)
                 goto fail;
             }
 
-            err = vk_decode_create_view(ctx, &ctx->layered_view, &ctx->layered_aspect,
+            err = vk_decode_create_view(dec, &ctx->layered_view, &ctx->layered_aspect,
                                         (AVVkFrame *)ctx->layered_frame->data[0],
-                                        s->hwfc->format[0]);
+                                        s->hwfc->format[0], 0);
             if (err < 0)
                 goto fail;
         }



More information about the ffmpeg-cvslog mailing list