[FFmpeg-cvslog] vulkan: flexibly allocate temporary imageviews

Lynne git at videolan.org
Sun Sep 22 03:11:34 EEST 2024


ffmpeg | branch: master | Lynne <dev at lynne.ee> | Sat Sep 21 08:03:40 2024 +0200| [c4048013e5064deeb4d4ff37f2c65a45f7e3f6c3] | committer: Lynne

vulkan: flexibly allocate temporary imageviews

No reason to allocate 16 when 3 will do.

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

 libavutil/vulkan.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index e9f094261d..cca04fb88f 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -1176,8 +1176,8 @@ const char *ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt)
 }
 
 typedef struct ImageViewCtx {
-    VkImageView views[AV_NUM_DATA_POINTERS];
     int nb_views;
+    VkImageView views[];
 } ImageViewCtx;
 
 static void destroy_imageviews(void *opaque, uint8_t *data)
@@ -1206,7 +1206,8 @@ int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e,
     const int nb_images = ff_vk_count_images(vkf);
     const int nb_planes = av_pix_fmt_count_planes(hwfc->sw_format);
 
-    ImageViewCtx *iv = av_mallocz(sizeof(*iv));
+    const size_t buf_size = sizeof(int) + nb_planes*sizeof(VkImageView);
+    ImageViewCtx *iv = av_mallocz(buf_size);
     if (!iv)
         return AVERROR(ENOMEM);
 
@@ -1243,7 +1244,7 @@ int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e,
         iv->nb_views++;
     }
 
-    buf = av_buffer_create((uint8_t *)iv, sizeof(*iv), destroy_imageviews, s, 0);
+    buf = av_buffer_create((uint8_t *)iv, buf_size, destroy_imageviews, s, 0);
     if (!buf) {
         err = AVERROR(ENOMEM);
         goto fail;



More information about the ffmpeg-cvslog mailing list