Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Nuo Mi <nuomi2021@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Nuo Mi <nuomi2021@gmail.com>
Subject: [FFmpeg-devel] [PATCH 04/11] avcodec/vvcdec: split ctu table to zero init and no zero init parts
Date: Sun, 28 Jul 2024 11:18:00 +0800
Message-ID: <TYSPR06MB6433C94F5A5CF72083C58182AAB62@TYSPR06MB6433.apcprd06.prod.outlook.com> (raw)
In-Reply-To: <20240728031807.462810-1-nuomi2021@gmail.com>

cus need to init to zero, other parts are not
---
 libavcodec/vvc/ctu.c   | 11 ++++++-----
 libavcodec/vvc/ctu.h   |  3 +--
 libavcodec/vvc/dec.c   | 21 +++++++--------------
 libavcodec/vvc/dec.h   |  5 +++--
 libavcodec/vvc/inter.c |  3 +--
 libavcodec/vvc/intra.c |  5 ++---
 6 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/libavcodec/vvc/ctu.c b/libavcodec/vvc/ctu.c
index 3f9a75190b..d39dd579ae 100644
--- a/libavcodec/vvc/ctu.c
+++ b/libavcodec/vvc/ctu.c
@@ -1174,7 +1174,7 @@ static CodingUnit* alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
     const VVCPPS *pps   = fc->ps.pps;
     const int rx        = x0 >> sps->ctb_log2_size_y;
     const int ry        = y0 >> sps->ctb_log2_size_y;
-    CTU *ctu            = fc->tab.ctus + ry * pps->ctb_width + rx;
+    CodingUnit **cus    = fc->tab.cus + ry * pps->ctb_width + rx;
     CodingUnit *cu      = ff_refstruct_pool_get(fc->cu_pool);
 
     if (!cu)
@@ -1184,7 +1184,7 @@ static CodingUnit* alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
     if (lc->cu)
         lc->cu->next = cu;
     else
-        ctu->cus = cu;
+        *cus = cu;
     lc->cu = cu;
 
     return cu;
@@ -2429,7 +2429,9 @@ static void ctu_get_pred(VVCLocalContext *lc, const int rs)
     const VVCFrameContext *fc       = lc->fc;
     const H266RawSliceHeader *rsh   = lc->sc->sh.r;
     CTU *ctu                        = fc->tab.ctus + rs;
-    const CodingUnit *cu            = ctu->cus;
+    const CodingUnit *cu            = fc->tab.cus[rs];
+
+    ctu->has_dmvr = 0;
 
     if (IS_I(rsh))
         return;
@@ -2526,9 +2528,8 @@ void ff_vvc_set_neighbour_available(VVCLocalContext *lc,
     lc->na.cand_up_right = lc->na.cand_up_right_sap && (x0 + w) < lc->end_of_tiles_x;
 }
 
-void ff_vvc_ctu_free_cus(CTU *ctu)
+void ff_vvc_ctu_free_cus(CodingUnit **cus)
 {
-    CodingUnit **cus  = &ctu->cus;
     while (*cus) {
         CodingUnit *cu          = *cus;
         TransformUnit **head    = &cu->tus.head;
diff --git a/libavcodec/vvc/ctu.h b/libavcodec/vvc/ctu.h
index d5c3e8d96f..eab4612561 100644
--- a/libavcodec/vvc/ctu.h
+++ b/libavcodec/vvc/ctu.h
@@ -329,7 +329,6 @@ typedef struct CodingUnit {
 } CodingUnit;
 
 typedef struct CTU {
-    CodingUnit *cus;
     int max_y[2][VVC_MAX_REF_ENTRIES];
     int max_y_idx[2];
     int has_dmvr;
@@ -484,7 +483,7 @@ int ff_vvc_coding_tree_unit(VVCLocalContext *lc, int ctu_idx, int rs, int rx, in
 //utils
 void ff_vvc_set_neighbour_available(VVCLocalContext *lc, int x0, int y0, int w, int h);
 void ff_vvc_decode_neighbour(VVCLocalContext *lc, int x_ctb, int y_ctb, int rx, int ry, int rs);
-void ff_vvc_ctu_free_cus(CTU *ctu);
+void ff_vvc_ctu_free_cus(CodingUnit **cus);
 int ff_vvc_get_qPy(const VVCFrameContext *fc, int xc, int yc);
 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep, int bit_depth, int persistent_rice_adaptation_enabled_flag);
 
diff --git a/libavcodec/vvc/dec.c b/libavcodec/vvc/dec.c
index d609fc5184..568229d2c3 100644
--- a/libavcodec/vvc/dec.c
+++ b/libavcodec/vvc/dec.c
@@ -91,17 +91,6 @@ static int tl_create(TabList *l)
     return 0;
 }
 
-static void ctu_tl_init(TabList *l, VVCFrameContext *fc)
-{
-    const VVCPPS *pps   = fc->ps.pps;
-    const int ctu_count = pps ? pps->ctb_count : 0;
-    const int changed   = fc->tab.sz.ctu_count != ctu_count;
-
-    tl_init(l, 1, changed);
-
-    TL_ADD(ctus,    ctu_count);
-}
-
 static void ctu_nz_tl_init(TabList *l, VVCFrameContext *fc)
 {
     const VVCSPS *sps   = fc->ps.sps;
@@ -112,6 +101,8 @@ static void ctu_nz_tl_init(TabList *l, VVCFrameContext *fc)
 
     tl_init(l, 0, changed);
 
+    TL_ADD(cus,     ctu_count);
+    TL_ADD(ctus,    ctu_count);
     TL_ADD(deblock, ctu_count);
     TL_ADD(sao,     ctu_count);
     TL_ADD(alf,     ctu_count);
@@ -307,7 +298,6 @@ typedef void (*tl_init_fn)(TabList *l, VVCFrameContext *fc);
 static int frame_context_for_each_tl(VVCFrameContext *fc, int (*unary_fn)(TabList *l))
 {
     const tl_init_fn init[] = {
-        ctu_tl_init,
         ctu_nz_tl_init,
         min_cb_tl_init,
         min_cb_nz_tl_init,
@@ -334,9 +324,9 @@ static int frame_context_for_each_tl(VVCFrameContext *fc, int (*unary_fn)(TabLis
 
 static void free_cus(VVCFrameContext *fc)
 {
-    if (fc->tab.ctus) {
+    if (fc->tab.cus) {
         for (int i = 0; i < fc->tab.sz.ctu_count; i++)
-            ff_vvc_ctu_free_cus(fc->tab.ctus + i);
+            ff_vvc_ctu_free_cus(fc->tab.cus + i);
     }
 }
 
@@ -364,6 +354,9 @@ static int pic_arrays_init(VVCContext *s, VVCFrameContext *fc)
     if (ret < 0)
         return ret;
 
+    // for error handling case, we may call free_cus before VVC_TASK_STAGE_INIT, so we need to set cus to 0 here
+    memset(fc->tab.cus, 0, sizeof(*fc->tab.cus) * ctu_count);
+
     memset(fc->tab.slice_idx, -1, sizeof(*fc->tab.slice_idx) * ctu_count);
 
     if (fc->tab.sz.ctu_count != ctu_count) {
diff --git a/libavcodec/vvc/dec.h b/libavcodec/vvc/dec.h
index eb8d0bad6b..d27cf52ca2 100644
--- a/libavcodec/vvc/dec.h
+++ b/libavcodec/vvc/dec.h
@@ -187,8 +187,9 @@ typedef struct VVCFrameContext {
         uint8_t *alf_pixel_buffer_h[VVC_MAX_SAMPLE_ARRAYS][2];
         uint8_t *alf_pixel_buffer_v[VVC_MAX_SAMPLE_ARRAYS][2];
 
-        int         *coeffs;
-        struct CTU  *ctus;
+        int                 *coeffs;
+        struct CTU          *ctus;
+        struct CodingUnit  **cus;
 
         uint8_t *ibc_vir_buf[VVC_MAX_SAMPLE_ARRAYS];    ///< IbcVirBuf[]
 
diff --git a/libavcodec/vvc/inter.c b/libavcodec/vvc/inter.c
index 9578fd8de4..64a9dd1e46 100644
--- a/libavcodec/vvc/inter.c
+++ b/libavcodec/vvc/inter.c
@@ -1003,8 +1003,7 @@ static int has_inter_luma(const CodingUnit *cu)
 int ff_vvc_predict_inter(VVCLocalContext *lc, const int rs)
 {
     const VVCFrameContext *fc = lc->fc;
-    const CTU *ctu            = fc->tab.ctus + rs;
-    CodingUnit *cu            = ctu->cus;
+    CodingUnit *cu            = fc->tab.cus[rs];
 
     while (cu) {
         lc->cu = cu;
diff --git a/libavcodec/vvc/intra.c b/libavcodec/vvc/intra.c
index f77a012f09..e79a83bc30 100644
--- a/libavcodec/vvc/intra.c
+++ b/libavcodec/vvc/intra.c
@@ -664,8 +664,7 @@ int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, const int rx, const in
     const VVCSPS *sps           = fc->ps.sps;
     const int x_ctb             = rx << sps->ctb_log2_size_y;
     const int y_ctb             = ry << sps->ctb_log2_size_y;
-    CTU *ctu                    = fc->tab.ctus + rs;
-    CodingUnit *cu              = ctu->cus;
+    CodingUnit *cu              = fc->tab.cus[rs];
     int ret                     = 0;
 
     lc->num_ras[0] = lc->num_ras[1] = 0;
@@ -691,7 +690,7 @@ int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, const int rx, const in
             ibc_fill_vir_buf(lc, cu);
         cu = cu->next;
     }
-    ff_vvc_ctu_free_cus(ctu);
+    ff_vvc_ctu_free_cus(fc->tab.cus + rs);
     return ret;
 }
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2024-07-28  3:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240728031807.462810-1-nuomi2021@gmail.com>
2024-07-28  3:17 ` [FFmpeg-devel] [PATCH 02/11] avcodec/vvcdec: refact, combine bs tab with tu tab Nuo Mi
2024-07-28  3:17 ` [FFmpeg-devel] [PATCH 03/11] avcodec/vvcdec: remove unnecessary perframe initializations Nuo Mi
2024-07-28  3:18 ` Nuo Mi [this message]
2024-07-28  3:18 ` [FFmpeg-devel] [PATCH 05/11] avcodec/vvcdec: refact out is_available from is_a0_available Nuo Mi
2024-07-28  3:18 ` [FFmpeg-devel] [PATCH 06/11] avcodec/vvcdec: do not zero frame mvf table Nuo Mi
2024-07-28  3:18 ` [FFmpeg-devel] [PATCH 07/11] avcodec/vvcdec: check_available, use && instead of &= for shortcut evaluation Nuo Mi
2024-07-28  3:18 ` [FFmpeg-devel] [PATCH 08/11] avcodec/vvcdec: do not zero frame cpm table Nuo Mi
2024-07-28  3:18 ` [FFmpeg-devel] [PATCH 09/11] avcodec/vvcdec: do not zero frame msf mmi table Nuo Mi
2024-07-28  3:18 ` [FFmpeg-devel] [PATCH 10/11] avcodec/vvcdec: do not zero frame qp table Nuo Mi
2024-07-28  3:18 ` [FFmpeg-devel] [PATCH 11/11] avcodec/vvcdec: move frame tab memset from the main thread to worker threads Nuo Mi
2024-08-11 14:01   ` Nuo Mi
2024-08-15 12:45     ` Nuo Mi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=TYSPR06MB6433C94F5A5CF72083C58182AAB62@TYSPR06MB6433.apcprd06.prod.outlook.com \
    --to=nuomi2021@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git