Simplify cdef skipping approach
skip_cdef_curr_sb was removed from MB_MODE_INFO. Set cdef_strength
directly, and simplified the setting. No stats change. Overall, saw
negligible speed change.
Change-Id: I290702d1fd2d07f9592934a40c17914a0b446a78
diff --git a/av1/common/blockd.h b/av1/common/blockd.h
index 88557b0..79849c4 100644
--- a/av1/common/blockd.h
+++ b/av1/common/blockd.h
@@ -326,9 +326,6 @@
int8_t cdef_strength : 4;
/**@}*/
- /*! \brief Skip CDEF for this superblock */
- uint8_t skip_cdef_curr_sb;
-
#if CONFIG_RD_DEBUG
/*! \brief RD info used for debugging */
RD_STATS rd_stats;
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 54ac13d..1a28285 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -523,15 +523,15 @@
set_cb_offsets(td->mb.cb_offset, 0, 0);
// Initialize the flag to skip cdef to 1.
+ const int block64_in_sb = (sb_size == BLOCK_128X128) ? 2 : 1;
if (sf->rt_sf.skip_cdef_sb) {
// If 128x128 block is used, we need to set the flag for all 4 64x64 sub
// "blocks".
- const int block64_in_sb = (sb_size == BLOCK_128X128) ? 2 : 1;
for (int r = 0; r < block64_in_sb; ++r) {
for (int c = 0; c < block64_in_sb; ++c) {
const int idx_in_sb =
r * MI_SIZE_64X64 * cm->mi_params.mi_stride + c * MI_SIZE_64X64;
- if (mi[idx_in_sb]) mi[idx_in_sb]->skip_cdef_curr_sb = 1;
+ if (mi[idx_in_sb]) mi[idx_in_sb]->cdef_strength = 1;
}
}
}
@@ -545,16 +545,15 @@
end_timing(cpi, nonrd_use_partition_time);
#endif
- if (sf->rt_sf.skip_cdef_sb) {
+ if (sf->rt_sf.skip_cdef_sb && block64_in_sb == 2) {
// If 128x128 block is used, we need to set the flag for all 4 64x64 sub
// "blocks".
- const int block64_in_sb = (sb_size == BLOCK_128X128) ? 2 : 1;
- const int skip = mi[0]->skip_cdef_curr_sb;
+ const int skip = mi[0]->cdef_strength;
for (int r = 0; r < block64_in_sb; ++r) {
for (int c = 0; c < block64_in_sb; ++c) {
const int idx_in_sb =
r * MI_SIZE_64X64 * cm->mi_params.mi_stride + c * MI_SIZE_64X64;
- if (mi[idx_in_sb]) mi[idx_in_sb]->skip_cdef_curr_sb = skip;
+ if (mi[idx_in_sb]) mi[idx_in_sb]->cdef_strength = skip;
}
}
}
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 0bfe362..63a56f2 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -2165,9 +2165,8 @@
// Find CDEF parameters
av1_cdef_search(&cpi->mt_info, &cm->cur_frame->buf, cpi->source, cm, xd,
cpi->sf.lpf_sf.cdef_pick_method, cpi->td.mb.rdmult,
- cpi->sf.rt_sf.skip_cdef_sb, cpi->rc.frames_since_key,
- cpi->oxcf.tool_cfg.cdef_control, use_screen_content_model,
- cpi->svc.non_reference_frame);
+ cpi->sf.rt_sf.skip_cdef_sb, cpi->oxcf.tool_cfg.cdef_control,
+ use_screen_content_model, cpi->svc.non_reference_frame);
// Apply the filter
if (!cpi->svc.non_reference_frame) {
diff --git a/av1/encoder/partition_search.c b/av1/encoder/partition_search.c
index 1e56e07..985b296 100644
--- a/av1/encoder/partition_search.c
+++ b/av1/encoder/partition_search.c
@@ -2338,6 +2338,12 @@
#endif
}
if (cpi->sf.rt_sf.skip_cdef_sb) {
+ // cdef_strength is initialized to 1 which means skip_cdef, and is updated
+ // here. Check to see is skipping cdef is allowed.
+ const int allow_cdef_skipping =
+ cpi->rc.frames_since_key > 10 && !cpi->rc.high_source_sad &&
+ !(x->color_sensitivity[0] || x->color_sensitivity[1]);
+
// Find the corresponding 64x64 block. It'll be the 128x128 block if that's
// the block size.
const int mi_row_sb = mi_row - mi_row % MI_SIZE_64X64;
@@ -2347,12 +2353,11 @@
get_mi_grid_idx(&cm->mi_params, mi_row_sb, mi_col_sb);
// Do not skip if intra or new mv is picked, or color sensitivity is set.
// Never skip on slide/scene change.
- mi_sb[0]->skip_cdef_curr_sb =
- mi_sb[0]->skip_cdef_curr_sb && !cpi->rc.high_source_sad &&
- !(x->color_sensitivity[0] || x->color_sensitivity[1]) &&
+ mi_sb[0]->cdef_strength =
+ mi_sb[0]->cdef_strength && allow_cdef_skipping &&
!(mbmi->mode < INTRA_MODES || mbmi->mode == NEWMV);
// Store in the pickmode context.
- ctx->mic.skip_cdef_curr_sb = mi_sb[0]->skip_cdef_curr_sb;
+ ctx->mic.cdef_strength = mi_sb[0]->cdef_strength;
}
x->rdmult = orig_rdmult;
ctx->rd_stats.rate = rd_cost->rate;
diff --git a/av1/encoder/pickcdef.c b/av1/encoder/pickcdef.c
index adbb07c..3659650 100644
--- a/av1/encoder/pickcdef.c
+++ b/av1/encoder/pickcdef.c
@@ -508,7 +508,7 @@
}
static void pick_cdef_from_qp(AV1_COMMON *const cm, int skip_cdef,
- int frames_since_key, int is_screen_content) {
+ int is_screen_content) {
const int bd = cm->seq_params->bit_depth;
const int q =
av1_ac_quant_QTX(cm->quant_params.base_qindex, 0, bd) >> (bd - 8);
@@ -574,10 +574,14 @@
cdef_info->cdef_uv_strengths[0] =
predicted_uv_f1 * CDEF_SEC_STRENGTHS + predicted_uv_f2;
+ // mbmi->cdef_strength is already set in the encoding stage. We don't need to
+ // set it again here.
if (skip_cdef) {
cdef_info->cdef_strengths[1] = 0;
cdef_info->cdef_uv_strengths[1] = 0;
+ return;
}
+
const CommonModeInfoParams *const mi_params = &cm->mi_params;
const int nvfb = (mi_params->mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
const int nhfb = (mi_params->mi_cols + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
@@ -586,10 +590,6 @@
for (int c = 0; c < nhfb; ++c) {
MB_MODE_INFO *current_mbmi = mbmi[MI_SIZE_64X64 * c];
current_mbmi->cdef_strength = 0;
- if (skip_cdef && current_mbmi->skip_cdef_curr_sb &&
- frames_since_key > 10) {
- current_mbmi->cdef_strength = 1;
- }
}
mbmi += MI_SIZE_64X64 * mi_params->mi_stride;
}
@@ -598,9 +598,8 @@
void av1_cdef_search(MultiThreadInfo *mt_info, const YV12_BUFFER_CONFIG *frame,
const YV12_BUFFER_CONFIG *ref, AV1_COMMON *cm,
MACROBLOCKD *xd, CDEF_PICK_METHOD pick_method, int rdmult,
- int skip_cdef_feature, int frames_since_key,
- CDEF_CONTROL cdef_control, const int is_screen_content,
- int non_reference_frame) {
+ int skip_cdef_feature, CDEF_CONTROL cdef_control,
+ const int is_screen_content, int non_reference_frame) {
assert(cdef_control != CDEF_NONE);
if (cdef_control == CDEF_REFERENCE && non_reference_frame) {
CdefInfo *const cdef_info = &cm->cdef_info;
@@ -612,8 +611,7 @@
}
if (pick_method == CDEF_PICK_FROM_Q) {
- pick_cdef_from_qp(cm, skip_cdef_feature, frames_since_key,
- is_screen_content);
+ pick_cdef_from_qp(cm, skip_cdef_feature, is_screen_content);
return;
}
const CommonModeInfoParams *const mi_params = &cm->mi_params;
diff --git a/av1/encoder/pickcdef.h b/av1/encoder/pickcdef.h
index e070a8a..278de38 100644
--- a/av1/encoder/pickcdef.h
+++ b/av1/encoder/pickcdef.h
@@ -226,7 +226,6 @@
* \param[in] pick_method The method used to select params
* \param[in] rdmult rd multiplier to use in making param choices
* \param[in] skip_cdef_feature Speed feature to skip cdef
- * \param[in] frames_since_key Number of frames since key frame
* \param[in] cdef_control Parameter that controls CDEF application
* \param[in] is_screen_content Whether it is screen content type
* \param[in] non_reference_frame Indicates if current frame is
@@ -247,9 +246,8 @@
const YV12_BUFFER_CONFIG *frame,
const YV12_BUFFER_CONFIG *ref, AV1_COMMON *cm,
MACROBLOCKD *xd, CDEF_PICK_METHOD pick_method, int rdmult,
- int skip_cdef_feature, int frames_since_key,
- CDEF_CONTROL cdef_control, const int is_screen_content,
- int non_reference_frame);
+ int skip_cdef_feature, CDEF_CONTROL cdef_control,
+ const int is_screen_content, int non_reference_frame);
#ifdef __cplusplus
} // extern "C"