From: Nuo Mi <nuomi2021@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Nuo Mi <nuomi2021@gmail.com>
Subject: [FFmpeg-devel] [PATCH 01/11] avcodec/vvcdec: refact out deblock_bs to reduce duplicate code
Date: Thu, 22 Feb 2024 15:13:56 +0800
Message-ID: <TYSPR06MB6433650860DF55B7E0DA576EAA562@TYSPR06MB6433.apcprd06.prod.outlook.com> (raw)
In-Reply-To: <20240222071406.5714-1-nuomi2021@gmail.com>
---
libavcodec/vvc/vvc_filter.c | 176 +++++++++++-------------------------
1 file changed, 55 insertions(+), 121 deletions(-)
diff --git a/libavcodec/vvc/vvc_filter.c b/libavcodec/vvc/vvc_filter.c
index 5fa711c9e0..ca541fd997 100644
--- a/libavcodec/vvc/vvc_filter.c
+++ b/libavcodec/vvc/vvc_filter.c
@@ -474,8 +474,9 @@ static void vvc_deblock_subblock_bs_horizontal(const VVCLocalContext *lc,
}
}
-static void vvc_deblock_bs_luma_vertical(const VVCLocalContext *lc,
- const int x0, const int y0, const int width, const int height)
+static av_always_inline int deblock_bs(const VVCLocalContext *lc,
+ const int x_p, const int y_p, const int x_q, const int y_q,
+ const RefPicList *rpl_p, const int c_idx, const int off_to_cb, const uint8_t has_sub_block)
{
const VVCFrameContext *fc = lc->fc;
const MvField *tab_mvf = fc->tab.mvf;
@@ -483,6 +484,44 @@ static void vvc_deblock_bs_luma_vertical(const VVCLocalContext *lc,
const int log2_min_tu_size = MIN_TU_LOG2;
const int min_pu_width = fc->ps.pps->min_pu_width;
const int min_tu_width = fc->ps.pps->min_tu_width;
+ const int pu_p = (y_p >> log2_min_pu_size) * min_pu_width + (x_p >> log2_min_pu_size);
+ const int pu_q = (y_q >> log2_min_pu_size) * min_pu_width + (x_q >> log2_min_pu_size);
+ const MvField *mvf_p = &tab_mvf[pu_p];
+ const MvField *mvf_q = &tab_mvf[pu_q];
+ const uint8_t chroma = !!c_idx;
+ const int tu_p = (y_p >> log2_min_tu_size) * min_tu_width + (x_p >> log2_min_tu_size);
+ const int tu_q = (y_q >> log2_min_tu_size) * min_tu_width + (x_q >> log2_min_tu_size);
+ const uint8_t pcmf = fc->tab.pcmf[chroma][tu_p] && fc->tab.pcmf[chroma][tu_q];
+
+ if (pcmf)
+ return 0;
+
+ if (mvf_p->pred_flag == PF_INTRA || mvf_q->pred_flag == PF_INTRA || mvf_p->ciip_flag || mvf_q->ciip_flag)
+ return 2;
+
+ if (chroma) {
+ return fc->tab.tu_coded_flag[c_idx][tu_p] ||
+ fc->tab.tu_coded_flag[c_idx][tu_q] ||
+ fc->tab.tu_joint_cbcr_residual_flag[tu_p] ||
+ fc->tab.tu_joint_cbcr_residual_flag[tu_q];
+ }
+
+ if (fc->tab.tu_coded_flag[LUMA][tu_p] || fc->tab.tu_coded_flag[LUMA][tu_q])
+ return 1;
+
+ if ((off_to_cb && ((off_to_cb % 8) || !has_sub_block)))
+ return 0; // inside a cu, not aligned to 8 or with no subblocks
+
+ return boundary_strength(lc, mvf_q, mvf_p, rpl_p);
+}
+
+static void vvc_deblock_bs_luma_vertical(const VVCLocalContext *lc,
+ const int x0, const int y0, const int width, const int height)
+{
+ const VVCFrameContext *fc = lc->fc;
+ const MvField *tab_mvf = fc->tab.mvf;
+ const int log2_min_pu_size = MIN_PU_LOG2;
+ const int min_pu_width = fc->ps.pps->min_pu_width;
const int min_cb_log2 = fc->ps.sps->min_cb_log2_size_y;
const int min_cb_width = fc->ps.pps->min_cb_width;
const int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width +
@@ -494,6 +533,7 @@ static void vvc_deblock_bs_luma_vertical(const VVCLocalContext *lc,
const int cb_x = fc->tab.cb_pos_x[LUMA][off_q];
const int cb_y = fc->tab.cb_pos_y[LUMA][off_q];
const int cb_width = fc->tab.cb_width[LUMA][off_q];
+ const int off_x = cb_x - x0;
if (!is_intra) {
if (fc->tab.msf[off_q] || fc->tab.iaf[off_q])
@@ -514,34 +554,9 @@ static void vvc_deblock_bs_luma_vertical(const VVCLocalContext *lc,
if (boundary_left) {
const RefPicList *rpl_left =
(lc->boundary_flags & BOUNDARY_LEFT_SLICE) ? ff_vvc_get_ref_list(fc, fc->ref, x0 - 1, y0) : lc->sc->rpl;
- const int xp_pu = (x0 - 1) >> log2_min_pu_size;
- const int xq_pu = x0 >> log2_min_pu_size;
- const int xp_tu = (x0 - 1) >> log2_min_tu_size;
- const int xq_tu = x0 >> log2_min_tu_size;
-
for (int i = 0; i < height; i += 4) {
- const int off_x = cb_x - x0;
- const int y_pu = (y0 + i) >> log2_min_pu_size;
- const int y_tu = (y0 + i) >> log2_min_tu_size;
- const MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
- const MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
- const uint8_t left_cbf_luma = fc->tab.tu_coded_flag[LUMA][y_tu * min_tu_width + xp_tu];
- const uint8_t curr_cbf_luma = fc->tab.tu_coded_flag[LUMA][y_tu * min_tu_width + xq_tu];
- const uint8_t pcmf = fc->tab.pcmf[LUMA][y_tu * min_tu_width + xp_tu] &&
- fc->tab.pcmf[LUMA][y_tu * min_tu_width + xq_tu];
uint8_t max_len_p, max_len_q;
- int bs;
-
- if (pcmf)
- bs = 0;
- else if (curr->pred_flag == PF_INTRA || left->pred_flag == PF_INTRA || curr->ciip_flag || left->ciip_flag)
- bs = 2;
- else if (curr_cbf_luma || left_cbf_luma)
- bs = 1;
- else if (off_x && ((off_x % 8) || !has_vertical_sb))
- bs = 0; ////inside a cu, not aligned to 8 or with no subblocks
- else
- bs = boundary_strength(lc, curr, left, rpl_left);
+ const int bs = deblock_bs(lc, x0 - 1, y0 + i, x0, y0 + i, rpl_left, 0, off_x, has_vertical_sb);
TAB_BS(fc->tab.vertical_bs[LUMA], x0, (y0 + i)) = bs;
@@ -561,11 +576,9 @@ static void vvc_deblock_bs_luma_horizontal(const VVCLocalContext *lc,
const int x0, const int y0, const int width, const int height)
{
const VVCFrameContext *fc = lc->fc;
- const MvField *tab_mvf = fc->tab.mvf;
+ const MvField *tab_mvf = fc->tab.mvf;
const int log2_min_pu_size = MIN_PU_LOG2;
- const int log2_min_tu_size = MIN_TU_LOG2;
const int min_pu_width = fc->ps.pps->min_pu_width;
- const int min_tu_width = fc->ps.pps->min_tu_width;
const int min_cb_log2 = fc->ps.sps->min_cb_log2_size_y;
const int min_cb_width = fc->ps.pps->min_cb_width;
const int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width +
@@ -577,6 +590,7 @@ static void vvc_deblock_bs_luma_horizontal(const VVCLocalContext *lc,
const int cb_x = fc->tab.cb_pos_x[LUMA][off_q];
const int cb_y = fc->tab.cb_pos_y[LUMA][off_q];
const int cb_height = fc->tab.cb_height[LUMA][off_q];
+ const int off_y = y0 - cb_y;
if (!is_intra) {
if (fc->tab.msf[off_q] || fc->tab.iaf[off_q])
@@ -596,34 +610,10 @@ static void vvc_deblock_bs_luma_horizontal(const VVCLocalContext *lc,
if (boundary_upper) {
const RefPicList *rpl_top =
(lc->boundary_flags & BOUNDARY_UPPER_SLICE) ? ff_vvc_get_ref_list(fc, fc->ref, x0, y0 - 1) : lc->sc->rpl;
- int yp_pu = (y0 - 1) >> log2_min_pu_size;
- int yq_pu = y0 >> log2_min_pu_size;
- int yp_tu = (y0 - 1) >> log2_min_tu_size;
- int yq_tu = y0 >> log2_min_tu_size;
for (int i = 0; i < width; i += 4) {
- const int off_y = y0 - cb_y;
- const int x_pu = (x0 + i) >> log2_min_pu_size;
- const int x_tu = (x0 + i) >> log2_min_tu_size;
- const MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
- const MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
- const uint8_t top_cbf_luma = fc->tab.tu_coded_flag[LUMA][yp_tu * min_tu_width + x_tu];
- const uint8_t curr_cbf_luma = fc->tab.tu_coded_flag[LUMA][yq_tu * min_tu_width + x_tu];
- const uint8_t pcmf = fc->tab.pcmf[LUMA][yp_tu * min_tu_width + x_tu] &&
- fc->tab.pcmf[LUMA][yq_tu * min_tu_width + x_tu];
uint8_t max_len_p, max_len_q;
- int bs;
-
- if (pcmf)
- bs = 0;
- else if (curr->pred_flag == PF_INTRA || top->pred_flag == PF_INTRA || curr->ciip_flag || top->ciip_flag)
- bs = 2;
- else if (curr_cbf_luma || top_cbf_luma)
- bs = 1;
- else if (off_y && ((off_y % 8) || !has_horizontal_sb))
- bs = 0; //inside a cu, not aligned to 8 or with no subblocks
- else
- bs = boundary_strength(lc, curr, top, rpl_top);
+ const int bs = deblock_bs(lc, x0 + i, y0 - 1, x0 + i, y0, rpl_top, 0, off_y, has_horizontal_sb);
TAB_BS(fc->tab.horizontal_bs[LUMA], x0 + i, y0) = bs;
@@ -642,12 +632,7 @@ static void vvc_deblock_bs_luma_horizontal(const VVCLocalContext *lc,
static void vvc_deblock_bs_chroma_vertical(const VVCLocalContext *lc,
const int x0, const int y0, const int width, const int height)
{
- const VVCFrameContext *fc = lc->fc;
- const MvField *tab_mvf = fc->tab.mvf;
- const int log2_min_pu_size = MIN_PU_LOG2;
- const int log2_min_tu_size = MIN_PU_LOG2;
- const int min_pu_width = fc->ps.pps->min_pu_width;
- const int min_tu_width = fc->ps.pps->min_tu_width;
+ const VVCFrameContext *fc = lc->fc;
int boundary_left;
// bs for vertical TU boundaries
@@ -662,34 +647,11 @@ static void vvc_deblock_bs_chroma_vertical(const VVCLocalContext *lc,
boundary_left = 0;
if (boundary_left) {
- const int xp_pu = (x0 - 1) >> log2_min_pu_size;
- const int xq_pu = x0 >> log2_min_pu_size;
- const int xp_tu = (x0 - 1) >> log2_min_tu_size;
- const int xq_tu = x0 >> log2_min_tu_size;
-
for (int i = 0; i < height; i += 2) {
- const int y_pu = (y0 + i) >> log2_min_pu_size;
- const int y_tu = (y0 + i) >> log2_min_tu_size;
- const MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
- const MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
- const int left_tu = y_tu * min_tu_width + xp_tu;
- const int curr_tu = y_tu * min_tu_width + xq_tu;
- const uint8_t pcmf = fc->tab.pcmf[CHROMA][left_tu] && fc->tab.pcmf[CHROMA][curr_tu];
-
- for (int c = CB; c <= CR; c++) {
- uint8_t cbf = fc->tab.tu_coded_flag[c][left_tu] |
- fc->tab.tu_coded_flag[c][curr_tu] |
- fc->tab.tu_joint_cbcr_residual_flag[left_tu] |
- fc->tab.tu_joint_cbcr_residual_flag[curr_tu];
- int bs = 0;
-
- if (pcmf)
- bs = 0;
- else if (curr->pred_flag == PF_INTRA || left->pred_flag == PF_INTRA || curr->ciip_flag || left->ciip_flag)
- bs = 2;
- else if (cbf)
- bs = 1;
- TAB_BS(fc->tab.vertical_bs[c], x0, (y0 + i)) = bs;
+ for (int c_idx = CB; c_idx <= CR; c_idx++) {
+ const int bs = deblock_bs(lc, x0 - 1, y0 + i, x0, y0 + i, NULL, c_idx, 0, 0);
+
+ TAB_BS(fc->tab.vertical_bs[c_idx], x0, (y0 + i)) = bs;
}
}
}
@@ -699,11 +661,6 @@ static void vvc_deblock_bs_chroma_horizontal(const VVCLocalContext *lc,
const int x0, const int y0, const int width, const int height)
{
const VVCFrameContext *fc = lc->fc;
- MvField *tab_mvf = fc->tab.mvf;
- const int log2_min_pu_size = MIN_PU_LOG2;
- const int log2_min_tu_size = MIN_PU_LOG2;
- const int min_pu_width = fc->ps.pps->min_pu_width;
- const int min_tu_width = fc->ps.pps->min_tu_width;
int boundary_upper;
boundary_upper = y0 > 0 && !(y0 & ((CHROMA_GRID << fc->ps.sps->vshift[1]) - 1));
@@ -717,34 +674,11 @@ static void vvc_deblock_bs_chroma_horizontal(const VVCLocalContext *lc,
boundary_upper = 0;
if (boundary_upper) {
- int yp_pu = (y0 - 1) >> log2_min_pu_size;
- int yq_pu = y0 >> log2_min_pu_size;
- int yp_tu = (y0 - 1) >> log2_min_tu_size;
- int yq_tu = y0 >> log2_min_tu_size;
-
for (int i = 0; i < width; i += 2) {
- const int x_pu = (x0 + i) >> log2_min_pu_size;
- const int x_tu = (x0 + i) >> log2_min_tu_size;
- const MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
- const MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
- const int top_tu = yp_tu * min_tu_width + x_tu;
- const int curr_tu = yq_tu * min_tu_width + x_tu;
- const uint8_t pcmf = fc->tab.pcmf[CHROMA][top_tu] && fc->tab.pcmf[CHROMA][curr_tu];
-
- for (int c = CB; c <= CR; c++) {
- uint8_t cbf = fc->tab.tu_coded_flag[c][top_tu] |
- fc->tab.tu_coded_flag[c][curr_tu] |
- fc->tab.tu_joint_cbcr_residual_flag[top_tu] |
- fc->tab.tu_joint_cbcr_residual_flag[curr_tu];
- int bs = 0;
-
- if (pcmf)
- bs = 0;
- else if (curr->pred_flag == PF_INTRA || top->pred_flag == PF_INTRA || curr->ciip_flag || top->ciip_flag)
- bs = 2;
- else if (cbf)
- bs = 1;
- TAB_BS(fc->tab.horizontal_bs[c], x0 + i, y0) = bs;
+ for (int c_idx = CB; c_idx <= CR; c_idx++) {
+ const int bs = deblock_bs(lc, x0 + i, y0 - 1, x0 + i, y0, NULL, c_idx, 0, 0);
+
+ TAB_BS(fc->tab.horizontal_bs[c_idx], x0 + i, y0) = bs;
}
}
}
--
2.25.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".
next parent reply other threads:[~2024-02-22 7:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240222071406.5714-1-nuomi2021@gmail.com>
2024-02-22 7:13 ` Nuo Mi [this message]
2024-02-22 7:13 ` [FFmpeg-devel] [PATCH 02/11] avcodec/vvcdec: set CuPredMode table for chroma Nuo Mi
2024-02-22 7:13 ` [FFmpeg-devel] [PATCH 03/11] avcodec/vvcdec: deblock_bs, fix intra check for IBC Nuo Mi
2024-02-22 7:13 ` [FFmpeg-devel] [PATCH 04/11] avcodec/vvcdec: cabac, fix non_inter_flag, pred_mode_flag, amvr_shift " Nuo Mi
2024-02-22 7:14 ` [FFmpeg-devel] [PATCH 05/11] avcodec/vvcdec: implement update_hmvp " Nuo Mi
2024-02-22 7:14 ` [FFmpeg-devel] [PATCH 06/11] avcodec/vvcdec: skip inter prediction for IBC blocks Nuo Mi
2024-02-22 7:14 ` [FFmpeg-devel] [PATCH 07/11] avcodec/vvcdec: ff_vvc_set_intra_mvf, refact to support dmvr tab Nuo Mi
2024-02-22 7:14 ` [FFmpeg-devel] [PATCH 08/11] avcodec/vvcdec: fix dual tree for skipped transform tree/unit Nuo Mi
2024-02-22 7:14 ` [FFmpeg-devel] [PATCH 09/11] avcodec/vvcdec: refact, rename !is_mvp to check_mer Nuo Mi
2024-02-22 7:14 ` [FFmpeg-devel] [PATCH 10/11] avcodec/vvcdec: add Intra Block Copy parser Nuo Mi
2024-02-22 7:14 ` [FFmpeg-devel] [PATCH 11/11] avcodec/vvcdec: add Intra Block Copy decoder Nuo Mi
2024-02-23 13:03 ` Nuo Mi
2024-02-24 12:33 ` Nuo Mi
2024-02-24 13:20 ` Ronald S. Bultje
2024-02-25 3:07 ` 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=TYSPR06MB6433650860DF55B7E0DA576EAA562@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