This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit adfa2e3255477213d292590d1489c53c01c443d3
Author:     Lynne <[email protected]>
AuthorDate: Fri Jun 12 13:25:11 2026 +0900
Commit:     Lynne <[email protected]>
CommitDate: Thu Jul 2 16:45:08 2026 +0900

    vulkan_decode: drop ff_vk_decode_prepare_frame_sdr, use exec owned views
    
    For SDR codecs, we have zero dependency on the images we decode. So using
    the same scheme as the software code led us to needing unnecessarily to 
block
    on a semaphore wait.
    
    Instead of doing this, just make the imageviews a dependency of the exec 
context.
    Saves on CPU, matters particularly for very fast decoding speeds.
    
    FFv1 gets a slight workaround that's still better than what we did before.
---
 libavcodec/vulkan_apv.c        | 19 +++++++----------
 libavcodec/vulkan_decode.c     | 47 ------------------------------------------
 libavcodec/vulkan_decode.h     |  7 -------
 libavcodec/vulkan_dpx.c        | 18 ++++++----------
 libavcodec/vulkan_ffv1.c       | 20 +++++++++++-------
 libavcodec/vulkan_prores.c     | 13 ++++++------
 libavcodec/vulkan_prores_raw.c | 19 +++++++----------
 7 files changed, 39 insertions(+), 104 deletions(-)

diff --git a/libavcodec/vulkan_apv.c b/libavcodec/vulkan_apv.c
index 891b7b74c5..98f4cc2335 100644
--- a/libavcodec/vulkan_apv.c
+++ b/libavcodec/vulkan_apv.c
@@ -118,12 +118,6 @@ static int vk_apv_start_frame(AVCodecContext          
*avctx,
     fd += (APV_MAX_TILE_COLS+1)*2;
     memcpy(fd, apv->tile_info.row_starts, (APV_MAX_TILE_ROWS+1)*2);
 
-    /* Prepare frame to be used */
-    err = ff_vk_decode_prepare_frame_sdr(dec, apv->output_frame, vp, 1,
-                                         FF_VK_REP_NATIVE, 0);
-    if (err < 0)
-        return err;
-
     return 0;
 }
 
@@ -196,10 +190,11 @@ static int vk_apv_end_frame(AVCodecContext *avctx)
                                  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
                                  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
 
-    err = ff_vk_exec_mirror_sem_value(&ctx->s, exec, &vp->sem, &vp->sem_value,
-                                      apv->output_frame);
-    if (err < 0)
-        return err;
+    /* Exec-owned output views: freed on exec recycle, so releasing a picture
+     * needs no blocking wait. No mirror_sem: nothing consumes vp->sem here. */
+    VkImageView views[AV_NUM_DATA_POINTERS];
+    RET(ff_vk_create_imageviews(&ctx->s, exec, views, apv->output_frame,
+                                FF_VK_REP_NATIVE));
 
     RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &vp->slices_buf, 1, 0));
     vp->slices_buf = NULL;
@@ -260,7 +255,7 @@ static int vk_apv_end_frame(AVCodecContext *avctx)
 
     /* Decoding */
     ff_vk_shader_update_img_array(&ctx->s, exec, &apvvk->decode,
-                                  apv->output_frame, vp->view.out,
+                                  apv->output_frame, views,
                                   0, 0,
                                   VK_IMAGE_LAYOUT_GENERAL,
                                   VK_NULL_HANDLE);
@@ -296,7 +291,7 @@ static int vk_apv_end_frame(AVCodecContext *avctx)
 
     /* iDCT */
     ff_vk_shader_update_img_array(&ctx->s, exec, &apvvk->idct,
-                                  apv->output_frame, vp->view.out,
+                                  apv->output_frame, views,
                                   0, 0,
                                   VK_IMAGE_LAYOUT_GENERAL,
                                   VK_NULL_HANDLE);
diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index 8c312221a3..766435ea4d 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -255,53 +255,6 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, 
AVFrame *pic,
     return 0;
 }
 
-int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext *dec, AVFrame *pic,
-                                   FFVulkanDecodePicture *vkpic, int 
is_current,
-                                   enum FFVkShaderRepFormat rep_fmt, int 
alloc_dpb)
-{
-    int err;
-    FFVulkanDecodeShared *ctx = dec->shared_ctx;
-    AVHWFramesContext *frames = (AVHWFramesContext *)pic->hw_frames_ctx->data;
-
-    vkpic->slices_size = 0;
-
-    if (vkpic->view.ref[0])
-        return 0;
-
-    init_frame(dec, vkpic);
-
-    for (int i = 0; i < av_pix_fmt_count_planes(frames->sw_format); i++) {
-        if (alloc_dpb) {
-            vkpic->dpb_frame = vk_get_dpb_pool(ctx);
-            if (!vkpic->dpb_frame)
-                return AVERROR(ENOMEM);
-
-            err = ff_vk_create_imageview(&ctx->s,
-                                         &vkpic->view.ref[i], 
&vkpic->view.aspect_ref[i],
-                                         vkpic->dpb_frame, i, rep_fmt);
-            if (err < 0)
-                return err;
-
-            vkpic->view.dst[i] = vkpic->view.ref[i];
-        }
-
-        if (!alloc_dpb || is_current) {
-            err = ff_vk_create_imageview(&ctx->s,
-                                         &vkpic->view.out[i], 
&vkpic->view.aspect[i],
-                                         pic, i, rep_fmt);
-            if (err < 0)
-                return err;
-
-            if (!alloc_dpb) {
-                vkpic->view.ref[i] = vkpic->view.out[i];
-                vkpic->view.aspect_ref[i] = vkpic->view.aspect[i];
-            }
-        }
-    }
-
-    return 0;
-}
-
 int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp,
                            const uint8_t *data, size_t size, int add_startcode,
                            uint32_t *nb_slices, const uint32_t **offsets)
diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h
index c75f0710db..fe5ebcc07f 100644
--- a/libavcodec/vulkan_decode.h
+++ b/libavcodec/vulkan_decode.h
@@ -136,13 +136,6 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, 
AVFrame *pic,
                                FFVulkanDecodePicture *vkpic, int is_current,
                                int alloc_dpb);
 
-/**
- * Software-defined decoder version of ff_vk_decode_prepare_frame.
- */
-int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext *dec, AVFrame *pic,
-                                   FFVulkanDecodePicture *vkpic, int 
is_current,
-                                   enum FFVkShaderRepFormat rep_fmt, int 
alloc_dpb);
-
 /**
  * Add slice data to frame.
  */
diff --git a/libavcodec/vulkan_dpx.c b/libavcodec/vulkan_dpx.c
index 517c4e243d..f0963f0f39 100644
--- a/libavcodec/vulkan_dpx.c
+++ b/libavcodec/vulkan_dpx.c
@@ -60,7 +60,6 @@ static int vk_dpx_start_frame(AVCodecContext          *avctx,
                               av_unused const uint8_t *buffer,
                               av_unused uint32_t       size)
 {
-    int err;
     FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
     FFVulkanDecodeShared *ctx = dec->shared_ctx;
     DPXDecContext *dpx = avctx->priv_data;
@@ -75,12 +74,6 @@ static int vk_dpx_start_frame(AVCodecContext          *avctx,
                               buffer_ref,
                               VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
 
-    /* Prepare frame to be used */
-    err = ff_vk_decode_prepare_frame_sdr(dec, dpx->frame, vp, 1,
-                                         FF_VK_REP_NATIVE, 0);
-    if (err < 0)
-        return err;
-
     return 0;
 }
 
@@ -132,10 +125,11 @@ static int vk_dpx_end_frame(AVCodecContext *avctx)
                                  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
                                  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
 
-    err = ff_vk_exec_mirror_sem_value(&ctx->s, exec, &vp->sem, &vp->sem_value,
-                                      dpx->frame);
-    if (err < 0)
-        return err;
+    /* Exec-owned output views: freed on exec recycle, so releasing a picture
+     * needs no blocking wait. No mirror_sem: nothing consumes vp->sem here. */
+    VkImageView views[AV_NUM_DATA_POINTERS];
+    RET(ff_vk_create_imageviews(&ctx->s, exec, views, dpx->frame,
+                                FF_VK_REP_NATIVE));
 
     RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &vp->slices_buf, 1, 0));
     vp->slices_buf = NULL;
@@ -162,7 +156,7 @@ static int vk_dpx_end_frame(AVCodecContext *avctx)
 
     FFVulkanShader *shd = &dxv->shader;
     ff_vk_shader_update_img_array(&ctx->s, exec, shd,
-                                  dpx->frame, vp->view.out,
+                                  dpx->frame, views,
                                   0, 0,
                                   VK_IMAGE_LAYOUT_GENERAL,
                                   VK_NULL_HANDLE);
diff --git a/libavcodec/vulkan_ffv1.c b/libavcodec/vulkan_ffv1.c
index ce2e392233..4be037d2dc 100644
--- a/libavcodec/vulkan_ffv1.c
+++ b/libavcodec/vulkan_ffv1.c
@@ -182,11 +182,11 @@ static int vk_ffv1_start_frame(AVCodecContext          
*avctx,
             return err;
     }
 
-    /* Prepare frame to be used */
-    err = ff_vk_decode_prepare_frame_sdr(dec, f->picture.f, vp, 1,
-                                         FF_VK_REP_NATIVE, 0);
-    if (err < 0)
-        return err;
+    /* The context-less free callback needs these device functions, which
+     * prepare_frame_sdr() used to set. vp->sem is kept for the next
+     * non-keyframe's wait and the free callback's CRC readback. */
+    vp->wait_semaphores          = ctx->s.vkfn.WaitSemaphores;
+    vp->invalidate_memory_ranges = ctx->s.vkfn.InvalidateMappedMemoryRanges;
 
     /* Create a temporaty frame for RGB */
     if (is_rgb) {
@@ -265,6 +265,7 @@ static int vk_ffv1_end_frame(AVCodecContext *avctx)
     if (fp->slice_fltmap_buf)
         fltmap_buf = (FFVkBuffer *)fp->slice_fltmap_buf->data;
 
+    VkImageView output_views[AV_NUM_DATA_POINTERS];
     VkImageView rct_image_views[AV_NUM_DATA_POINTERS];
 
     VkImageMemoryBarrier2 img_bar[37];
@@ -285,6 +286,11 @@ static int vk_ffv1_end_frame(AVCodecContext *avctx)
     if (err < 0)
         return err;
 
+    /* Exec-owned output views (vp->sem is still mirrored above, for the next
+     * frame's dependency and the free callback's CRC readback). */
+    RET(ff_vk_create_imageviews(&ctx->s, exec, output_views, f->picture.f,
+                                FF_VK_REP_NATIVE));
+
     if (is_rgb) {
         RET(ff_vk_create_imageviews(&ctx->s, exec, rct_image_views,
                                     vp->dpb_frame, FF_VK_REP_NATIVE));
@@ -517,7 +523,7 @@ static int vk_ffv1_end_frame(AVCodecContext *avctx)
                                     VK_FORMAT_UNDEFINED);
 
     AVFrame *decode_dst = is_rgb ? vp->dpb_frame : f->picture.f;
-    VkImageView *decode_dst_view = is_rgb ? rct_image_views : vp->view.out;
+    VkImageView *decode_dst_view = is_rgb ? rct_image_views : output_views;
     ff_vk_shader_update_img_array(&ctx->s, exec, &fv->decode,
                                   decode_dst, decode_dst_view,
                                   1, 4,
@@ -525,7 +531,7 @@ static int vk_ffv1_end_frame(AVCodecContext *avctx)
                                   VK_NULL_HANDLE);
     if (is_rgb)
         ff_vk_shader_update_img_array(&ctx->s, exec, &fv->decode,
-                                      f->picture.f, vp->view.out,
+                                      f->picture.f, output_views,
                                       1, 5,
                                       VK_IMAGE_LAYOUT_GENERAL,
                                       VK_NULL_HANDLE);
diff --git a/libavcodec/vulkan_prores.c b/libavcodec/vulkan_prores.c
index 69a9a080b9..c5611894b1 100644
--- a/libavcodec/vulkan_prores.c
+++ b/libavcodec/vulkan_prores.c
@@ -109,10 +109,6 @@ static int vk_prores_start_frame(AVCodecContext          
*avctx,
                                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
                                 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
 
-    /* Prepare frame to be used */
-    RET(ff_vk_decode_prepare_frame_sdr(dec, pr->frame, vp, 1,
-                                       FF_VK_REP_NATIVE, 0));
-
     pp->slice_num = 0;
     pp->bitstream_start = pp->bitstream_size = 0;
 
@@ -211,7 +207,10 @@ static int vk_prores_end_frame(AVCodecContext *avctx)
                                  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
                                  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
 
-    RET(ff_vk_exec_mirror_sem_value(&ctx->s, exec, &vp->sem, &vp->sem_value, 
f));
+    /* Exec-owned output views: freed on exec recycle, so releasing a picture
+     * needs no blocking wait. No mirror_sem: nothing consumes vp->sem here. */
+    VkImageView views[AV_NUM_DATA_POINTERS];
+    RET(ff_vk_create_imageviews(&ctx->s, exec, views, f, FF_VK_REP_NATIVE));
 
     /* Transfer ownership to the exec context */
     RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &vp->slices_buf, 1, 0));
@@ -289,7 +288,7 @@ static int vk_prores_end_frame(AVCodecContext *avctx)
                                     pp->mb_params_sz,
                                     VK_FORMAT_UNDEFINED);
     ff_vk_shader_update_img_array(&ctx->s, exec, &pv->vld,
-                                  f, vp->view.out,
+                                  f, views,
                                   0, 2,
                                   VK_IMAGE_LAYOUT_GENERAL,
                                   VK_NULL_HANDLE);
@@ -337,7 +336,7 @@ static int vk_prores_end_frame(AVCodecContext *avctx)
                                     pp->qmat_sz,
                                     VK_FORMAT_UNDEFINED);
     ff_vk_shader_update_img_array(&ctx->s, exec, &pv->idct,
-                                  f, vp->view.out,
+                                  f, views,
                                   0, 2,
                                   VK_IMAGE_LAYOUT_GENERAL,
                                   VK_NULL_HANDLE);
diff --git a/libavcodec/vulkan_prores_raw.c b/libavcodec/vulkan_prores_raw.c
index b6314ab693..4a8d92c627 100644
--- a/libavcodec/vulkan_prores_raw.c
+++ b/libavcodec/vulkan_prores_raw.c
@@ -93,12 +93,6 @@ static int vk_prores_raw_start_frame(AVCodecContext          
*avctx,
     if (err < 0)
         return err;
 
-    /* Prepare frame to be used */
-    err = ff_vk_decode_prepare_frame_sdr(dec, prr->frame, vp, 1,
-                                         FF_VK_REP_NATIVE, 0);
-    if (err < 0)
-        return err;
-
     return 0;
 }
 
@@ -163,10 +157,11 @@ static int vk_prores_raw_end_frame(AVCodecContext *avctx)
                                  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
                                  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
 
-    err = ff_vk_exec_mirror_sem_value(&ctx->s, exec, &vp->sem, &vp->sem_value,
-                                      prr->frame);
-    if (err < 0)
-        return err;
+    /* Exec-owned output views: freed on exec recycle, so releasing a picture
+     * needs no blocking wait. No mirror_sem: nothing consumes vp->sem here. */
+    VkImageView views[AV_NUM_DATA_POINTERS];
+    RET(ff_vk_create_imageviews(&ctx->s, exec, views, prr->frame,
+                                FF_VK_REP_NATIVE));
 
     RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &pp->frame_data_buf, 1, 0));
     pp->frame_data_buf = NULL;
@@ -216,7 +211,7 @@ static int vk_prores_raw_end_frame(AVCodecContext *avctx)
 
     FFVulkanShader *decode_shader = &prv->decode;
     ff_vk_shader_update_img_array(&ctx->s, exec, decode_shader,
-                                  prr->frame, vp->view.out,
+                                  prr->frame, views,
                                   0, 0,
                                   VK_IMAGE_LAYOUT_GENERAL,
                                   VK_NULL_HANDLE);
@@ -250,7 +245,7 @@ static int vk_prores_raw_end_frame(AVCodecContext *avctx)
 
     FFVulkanShader *idct_shader = &prv->idct;
     ff_vk_shader_update_img_array(&ctx->s, exec, idct_shader,
-                                  prr->frame, vp->view.out,
+                                  prr->frame, views,
                                   0, 0,
                                   VK_IMAGE_LAYOUT_GENERAL,
                                   VK_NULL_HANDLE);

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to