Enable reuse_best_prediction_for_part_ab sf in allintra encode
The speed feature reuse_best_prediction_for_part_ab is
modified to support intra mode pruning, for ab partitions in
intra frames, in allintra encoding for speed >= 1.
For AVIF still image encode,
Instruction Count BD-Rate Loss(%)
cpu-used Reduction(%) psnr ssim
1 8.641 0.0799 0.0913
2 6.840 0.0644 0.0791
3 5.986 0.0539 0.0441
4 2.462 0.0262 0.0294
5 1.902 0.0263 0.0305
6 0.000 -0.0005 -0.0033
BUG=aomedia:2959
STATS_CHANGED
Change-Id: Ib2b1830c3ec9fef83a7d024a387b8d5c79899922
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 56ee891..cb6fa97 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -1169,10 +1169,11 @@
*/
IntraBCHashInfo intrabc_hash_info;
- /*! \brief Whether to reuse the mode stored in intermode_cache. */
- int use_intermode_cache;
- /*! \brief The mode to reuse during \ref av1_rd_pick_inter_mode. */
- const MB_MODE_INFO *intermode_cache;
+ /*! \brief Whether to reuse the mode stored in mb_mode_cache. */
+ int use_mb_mode_cache;
+ /*! \brief The mode to reuse during \ref av1_rd_pick_intra_mode_sb and
+ * \ref av1_rd_pick_inter_mode. */
+ const MB_MODE_INFO *mb_mode_cache;
/**@}*/
/*****************************************************************************
diff --git a/av1/encoder/intra_mode_search.c b/av1/encoder/intra_mode_search.c
index 9cb0f4a..875e99e 100644
--- a/av1/encoder/intra_mode_search.c
+++ b/av1/encoder/intra_mode_search.c
@@ -140,11 +140,23 @@
mbmi->mode = DC_PRED;
mbmi->palette_mode_info.palette_size[0] = 0;
+ // Skip the evaluation of filter-intra if cached MB_MODE_INFO does not have
+ // filter-intra as winner.
+ if (x->use_mb_mode_cache &&
+ x->mb_mode_cache->filter_intra_mode_info.use_filter_intra == 0)
+ return 0;
+
for (mode = 0; mode < FILTER_INTRA_MODES; ++mode) {
int64_t this_rd;
RD_STATS tokenonly_rd_stats;
mbmi->filter_intra_mode_info.filter_intra_mode = mode;
+ // Skip the evaluation of modes, which are not matching with the winner mode
+ // in x->mb_mode_cache.
+ if (x->use_mb_mode_cache &&
+ mode != x->mb_mode_cache->filter_intra_mode_info.filter_intra_mode)
+ continue;
+
if (model_intra_yrd_and_prune(cpi, x, bsize, best_model_rd)) {
continue;
}
@@ -1142,6 +1154,10 @@
continue;
mbmi->angle_delta[PLANE_TYPE_Y] = 0;
+ // Skip the evaluation of modes, which are not matching with the winner mode
+ // in x->mb_mode_cache.
+ if (x->use_mb_mode_cache && mbmi->mode != x->mb_mode_cache->mode) continue;
+
is_directional_mode = av1_is_directional_mode(mbmi->mode);
if (is_directional_mode && directional_mode_skip_mask[mbmi->mode]) continue;
if (is_directional_mode && av1_use_angle_delta(bsize) &&
diff --git a/av1/encoder/partition_search.c b/av1/encoder/partition_search.c
index 122a12d..7549943 100644
--- a/av1/encoder/partition_search.c
+++ b/av1/encoder/partition_search.c
@@ -2307,15 +2307,15 @@
// Loop over sub-partitions in AB partition type.
for (int i = 0; i < SUB_PARTITIONS_AB; i++) {
if (mode_cache && mode_cache[i]) {
- x->use_intermode_cache = 1;
- x->intermode_cache = mode_cache[i];
+ x->use_mb_mode_cache = 1;
+ x->mb_mode_cache = mode_cache[i];
}
const int mode_search_success =
rd_try_subblock(cpi, td, tile_data, tp, i == SUB_PARTITIONS_AB - 1,
ab_mi_pos[i][0], ab_mi_pos[i][1], ab_subsize[i],
*best_rdc, &sum_rdc, partition, ctxs[i]);
- x->use_intermode_cache = 0;
- x->intermode_cache = NULL;
+ x->use_mb_mode_cache = 0;
+ x->mb_mode_cache = NULL;
if (!mode_search_success) {
return false;
}
@@ -2988,7 +2988,7 @@
// Even if the contexts don't match, we can still speed up by reusing the
// previous prediction mode.
const MB_MODE_INFO *mode_cache[3] = { NULL, NULL, NULL };
- if (cpi->sf.inter_sf.reuse_best_prediction_for_part_ab) {
+ if (cpi->sf.part_sf.reuse_best_prediction_for_part_ab) {
set_mode_cache_for_partition_ab(mode_cache, pc_tree, ab_part_type);
}
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 8c0fb36..a9a1184 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -3763,7 +3763,7 @@
// compound ref.
if (skip_ref_frame_mask & (1 << ref_frame) &&
!is_ref_frame_used_by_compound_ref(ref_frame, skip_ref_frame_mask) &&
- !is_ref_frame_used_in_cache(ref_frame, x->intermode_cache)) {
+ !is_ref_frame_used_in_cache(ref_frame, x->mb_mode_cache)) {
continue;
}
assert(get_ref_frame_yv12_buf(cm, ref_frame) != NULL);
@@ -3789,7 +3789,7 @@
}
if (skip_ref_frame_mask & (1 << ref_frame) &&
- !is_ref_frame_used_in_cache(ref_frame, x->intermode_cache)) {
+ !is_ref_frame_used_in_cache(ref_frame, x->mb_mode_cache)) {
continue;
}
// Ref mv list population is not required, when compound references are
@@ -4025,8 +4025,8 @@
}
// Reuse the prediction mode in cache
- if (x->use_intermode_cache) {
- const MB_MODE_INFO *cached_mi = x->intermode_cache;
+ if (x->use_mb_mode_cache) {
+ const MB_MODE_INFO *cached_mi = x->mb_mode_cache;
const PREDICTION_MODE cached_mode = cached_mi->mode;
const MV_REFERENCE_FRAME *cached_frame = cached_mi->ref_frame;
const int cached_mode_is_single = cached_frame[1] <= INTRA_FRAME;
@@ -4121,12 +4121,12 @@
}
// If we are reusing the prediction from cache, and the current frame is
// required by the cache, then we cannot prune it.
- if (is_ref_frame_used_in_cache(ref_type, x->intermode_cache)) {
+ if (is_ref_frame_used_in_cache(ref_type, x->mb_mode_cache)) {
skip_ref = 0;
// If the cache only needs the current reference type for compound
// prediction, then we can skip motion mode search.
skip_motion_mode = (ref_type <= ALTREF_FRAME &&
- x->intermode_cache->ref_frame[1] > INTRA_FRAME);
+ x->mb_mode_cache->ref_frame[1] > INTRA_FRAME);
}
if (skip_ref) return 1;
}
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index 4b3d6b9..3336b6e 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -319,6 +319,7 @@
// speed feature accordingly
sf->part_sf.simple_motion_search_split = allow_screen_content_tools ? 1 : 2;
sf->part_sf.ml_predict_breakout_level = use_hbd ? 2 : 3;
+ sf->part_sf.reuse_best_prediction_for_part_ab = 1;
sf->mv_sf.exhaustive_searches_thresh <<= 1;
@@ -768,6 +769,8 @@
sf->hl_sf.recode_loop = ALLOW_RECODE_KFARFGF;
sf->part_sf.allow_partition_search_skip = 1;
+ sf->part_sf.reuse_best_prediction_for_part_ab =
+ !frame_is_intra_only(&cpi->common);
sf->mv_sf.auto_mv_step_size = 1;
sf->mv_sf.simple_motion_subpel_force_stop = QUARTER_PEL;
@@ -786,7 +789,6 @@
sf->inter_sf.prune_compound_using_neighbors = 1;
sf->inter_sf.prune_comp_using_best_single_mode_ref = 2;
sf->inter_sf.prune_comp_type_by_comp_avg = 2;
- sf->inter_sf.reuse_best_prediction_for_part_ab = 1;
sf->inter_sf.selective_ref_frame = 3;
sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_DISABLED;
// Enable fast search only for COMPOUND_DIFFWTD type.
@@ -1456,6 +1458,7 @@
part_sf->ml_predict_breakout_level = 0;
part_sf->prune_sub_8x8_partition_level = 0;
part_sf->simple_motion_search_rect_split = 0;
+ part_sf->reuse_best_prediction_for_part_ab = 0;
}
static AOM_INLINE void init_mv_sf(MV_SPEED_FEATURES *mv_sf) {
@@ -1516,7 +1519,6 @@
inter_sf->txfm_rd_gate_level = 0;
inter_sf->prune_inter_modes_if_skippable = 0;
inter_sf->disable_masked_comp = 0;
- inter_sf->reuse_best_prediction_for_part_ab = 0;
inter_sf->enable_fast_compound_mode_search = 0;
inter_sf->reuse_mask_search_results = 0;
}
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index 0da1377..53c6898 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -511,6 +511,10 @@
// Prune rectangular split based on simple motion search split/no_split score.
// 0: disable pruning, 1: enable pruning
int simple_motion_search_rect_split;
+
+ // Reuse the best prediction modes found in PARTITION_SPLIT and PARTITION_RECT
+ // when encoding PARTITION_AB.
+ int reuse_best_prediction_for_part_ab;
} PARTITION_SPEED_FEATURES;
typedef struct MV_SPEED_FEATURES {
@@ -751,10 +755,6 @@
// Enable/disable masked compound.
int disable_masked_comp;
- // Reuse the best prediction modes found in PARTITION_SPLIT and PARTITION_RECT
- // when encoding PARTITION_AB.
- int reuse_best_prediction_for_part_ab;
-
// Enable/disable the fast compound mode search.
int enable_fast_compound_mode_search;