[FFmpeg-devel] [PATCH] lavc: Diracdec / Vulkan Dirac. Fix epirat's suggestion without formatting

Petro Mozil mozil.petryk at gmail.com
Sat Sep 21 16:54:29 EEST 2024


From: Petro Mozil <mozil.petryk at gmail.com>
Date: Sat, 21 Sep 2024 16:52:03 +0300
Subject: [PATCH] lavc: Diracdec / Vulkan Dirac. Fix epirat's suggestion
without formatting

Sorry for the delay, this is the patch without formatting.

Signed-off-by: Petro Mozil <mozil.petryk at gmail.com>
---
 libavcodec/diracdec.c     | 29 ++++++-------------
 libavcodec/vulkan_dirac.c | 60 ++++++++++++++++-----------------------
 2 files changed, 34 insertions(+), 55 deletions(-)

diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c
index 9fbc8f18d3..8f5b1eee29 100644
--- a/libavcodec/diracdec.c
+++ b/libavcodec/diracdec.c
@@ -1675,13 +1675,13 @@ static int dirac_decode_frame_internal(DiracContext
*s)
     }

     if (s->avctx->hwaccel) {
-        ret = ffhwaccel(s->avctx->hwaccel)->end_frame(s->avctx);
+        ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame);
         if (ret == 0) {
-            /* Hwaccel failed - fall back on software decoder */
-        }
             return ret;
+        }
     }

+    /* Hwaccel failed - fall back on software decoder */
     for (comp = 0; comp < 3; comp++) {
         Plane *p       = &s->plane[comp];
         uint8_t *frame = s->current_picture->avframe->data[comp];
@@ -1770,13 +1770,6 @@ static int get_buffer_with_edge(AVCodecContext
*avctx, AVFrame *f, int flags)
     if (ret < 0)
         return ret;

-    /*if (avctx->hwaccel) {*/
-    /*    f->width   = s->plane[0].width;*/
-    /*    f->height  = s->plane[0].height;*/
-    /*    ret = ff_get_buffer(avctx, f, flags);*/
-    /*    return ret;*/
-    /*}*/
-
     f->width  = avctx->width  + 2 * EDGE_WIDTH;
     f->height = avctx->height + 2 * EDGE_WIDTH + 2;
     ret = ff_get_buffer(avctx, f, flags);
@@ -1976,18 +1969,14 @@ static int dirac_decode_data_unit(AVCodecContext
*avctx, const uint8_t *buf, int

         s->pshift = s->bit_depth > 8;

-        /*if (s->pshift) {*/
-        /*    avctx->pix_fmt = s->sof_pix_fmt;*/
-        /*} else {*/
-            pix_fmts = (enum AVPixelFormat[]){
+        pix_fmts = (enum AVPixelFormat[]){
 #if CONFIG_DIRAC_VULKAN_HWACCEL
-                AV_PIX_FMT_VULKAN,
+            AV_PIX_FMT_VULKAN,
 #endif
-                s->sof_pix_fmt,
-                AV_PIX_FMT_NONE,
-            };
-            avctx->pix_fmt = ff_get_format(s->avctx, pix_fmts);
-        /*}*/
+            s->sof_pix_fmt,
+            AV_PIX_FMT_NONE,
+        };
+        avctx->pix_fmt = ff_get_format(s->avctx, pix_fmts);

         ret = av_pix_fmt_get_chroma_sub_sample(s->sof_pix_fmt,
                                                &s->chroma_x_shift,
diff --git a/libavcodec/vulkan_dirac.c b/libavcodec/vulkan_dirac.c
index 7f30e4f0fe..2520c9f27e 100644
--- a/libavcodec/vulkan_dirac.c
+++ b/libavcodec/vulkan_dirac.c
@@ -135,13 +135,6 @@ static void free_common(AVCodecContext *avctx) {
         ff_vk_pipeline_free(s, &dec->horiz_wavelet_pl[i]);
         ff_vk_shader_free(s, &dec->horiz_wavelet_shd[i]);
     }
-    // TODO: Add freeing all pipelines and shaders for wavelets
-    //
-
-    // if (dec->yuv_sampler)
-    //     vk->DestroySamplerYcbcrConversion(s->hwctx->act_dev,
-    //     dec->yuv_sampler,
-    //                                       s->hwctx->alloc);
     if (dec->sampler)
         vk->DestroySampler(s->hwctx->act_dev, dec->sampler,
s->hwctx->alloc);

@@ -225,8 +218,6 @@ static inline int alloc_tmp_bufs(DiracContext *ctx,
 static inline int alloc_host_mapped_buf(DiracVulkanDecodeContext *dec,
                                         size_t req_size, void **mem,
                                         AVBufferRef **avbuf, FFVkBuffer
**buf) {
-    // FFVulkanFunctions *vk = &dec->vkctx.vkfn;
-    // VkResult ret;
     int err;

     err = ff_vk_create_avbuf(&dec->vkctx, avbuf, req_size, NULL, NULL,
@@ -307,7 +298,6 @@ static int alloc_quant_buf(DiracContext *ctx,
DiracVulkanDecodeContext *dec) {
         subband_coeffs(ctx, ctx->num_x - 1, ctx->num_y - 1, 0, 0, tmp) + 8;
     coef_buf_size = coef_buf_size + 512;
     dec->slice_vals_size = coef_buf_size / sizeof(int32_t);
-    // coef_buf_size *= sizeof(int32_t);

     if (dec->quant_val_buf_vk_ptr) {
         av_buffer_unref(&dec->av_quant_val_buf);
@@ -364,7 +354,6 @@ static int init_cpy_shd(DiracVulkanDecodeContext *s,
FFVkSPIRVCompiler *spv,
             .stages = VK_SHADER_STAGE_COMPUTE_BIT,
             .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
             .mem_quali = "writeonly",
-            // .mem_layout = ff_vk_shader_rep_fmt(vkctx->output_format),
             .mem_layout = "rgba16f",
             .dimensions = 2,
             .elems = planes,
@@ -2988,7 +2977,6 @@ static int init_quant_shd(DiracVulkanDecodeContext
*s, FFVkSPIRVCompiler *spv) {
     uint8_t *spv_data;
     size_t spv_len;
     void *spv_opaque = NULL;
-    // const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
     FFVulkanContext *vkctx = &s->vkctx;
     FFVulkanDescriptorSetBinding *desc;
     FFVkSPIRVShader *shd = &s->quant_shd;
@@ -3219,11 +3207,6 @@ static av_always_inline int inline quant_pl_pass(
 }

 static int vulkan_dirac_uninit(AVCodecContext *avctx) {
-    // DiracContext *d = avctx->priv_data;
-    // if (d->hwaccel_picture_private) {
-    //     av_freep(d->hwaccel_picture_private);
-    // }
-
     free_common(avctx);

     return 0;
@@ -3326,8 +3309,9 @@ static int vulkan_dirac_init(AVCodecContext *avctx) {
     s = &dec->vkctx;

     err = ff_vk_init(s, avctx, NULL, avctx->hw_frames_ctx);
-    if (err < 0)
-        return err;
+    if (err < 0) {
+      goto fafil;
+    }

     /* Create queue context */
     ff_vk_qf_init(s, &dec->qf, VK_QUEUE_COMPUTE_BIT);
@@ -3384,13 +3368,15 @@ static int vulkan_dirac_init(AVCodecContext *avctx)
{
                                VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                            VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
                                VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
-    if (err < 0)
-        return err;
+    if (err < 0) {
+      goto fail;
+    }

     err = ff_vk_map_buffer(&dec->vkctx, &dec->subband_info,
                            (uint8_t **)&dec->subband_info_ptr, 0);
-    if (err < 0)
-        return err;
+    if (err < 0) {
+      goto fail;
+    }

     return 0;

@@ -3444,7 +3430,6 @@ static int vulkan_dirac_frame_params(AVCodecContext
*avctx,
 }

 static void vulkan_dirac_free_frame_priv(FFRefStructOpaque _hwctx, void
*data) {
-    // AVHWDeviceContext *hwctx = _hwctx.nc;
     DiracVulkanDecodePicture *dp = data;

     /* Free frame resources */
@@ -3607,15 +3592,20 @@ static int vulkan_dirac_end_frame(AVCodecContext
*avctx) {
         err = AVERROR_PATCHWELCOME;
         break;
     }
+    if (err < 0) {
+      goto fail;
+    }

     err = cpy_to_image_pass(dec, ctx, exec, views, buf_bar, &nb_buf_bar,
                             img_bar, &nb_img_bar, (ctx->bit_depth - 8) >>
1);
-    if (err < 0)
-        goto fail;
+    if (err < 0) {
+      goto fail;
+    }

     err = ff_vk_exec_submit(&dec->vkctx, exec);
-    if (err < 0)
-        goto fail;
+    if (err < 0) {
+      goto fail;
+    }

     ff_vk_exec_wait(&dec->vkctx, exec);

@@ -3690,13 +3680,15 @@ static int
vulkan_dirac_update_thread_context(AVCodecContext *dst,
                                VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                            VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
                                VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
-    if (err < 0)
-        return err;
+    if (err < 0) {
+      goto fail;
+    }

     err = ff_vk_map_buffer(&dst_ctx->vkctx, &dst_ctx->subband_info,
                            (uint8_t **)&dst_ctx->subband_info_ptr, 0);
-    if (err < 0)
-        return err;
+    if (err < 0) {
+      goto fail;
+    }

     return 0;

@@ -3787,7 +3779,6 @@ static int vulkan_dirac_decode_slice(AVCodecContext
*avctx, const uint8_t *data,
                                      uint32_t size) {
     DiracContext *s = avctx->priv_data;

-    /*avctx->execute2(avctx, decode_hq_slice_row, NULL, NULL, s->num_y);*/
     for (int i = 0; i < s->num_y; i++) {
         decode_hq_slice_row(avctx, NULL, i, 0);
     }
@@ -3812,6 +3803,5 @@ const FFHWAccel ff_dirac_vulkan_hwaccel = {
     .flush = &ff_vk_decode_flush,
     .update_thread_context = &vulkan_dirac_update_thread_context,
     .priv_data_size = sizeof(DiracVulkanDecodeContext),
-    // .caps_internal = HWACCEL_CAP_ASYNC_SAFE | HWACCEL_CAP_THREAD_SAFE,
-    .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE,
+    .caps_internal = HWACCEL_CAP_ASYNC_SAFE | HWACCEL_CAP_THREAD_SAFE,
 };
-- 
2.46.1


More information about the ffmpeg-devel mailing list