Consolidate compound mode rate-distortion search
Remove redundant search routes. The target is to unify the rate
distortion search for compound modes eventually.
STATS_CHANGED
Change-Id: Ie1cdc49cb532525e5affeb682130e516dc1cedbc
diff --git a/av1/encoder/compound_type.c b/av1/encoder/compound_type.c
index 1f693c7..8a84168 100644
--- a/av1/encoder/compound_type.c
+++ b/av1/encoder/compound_type.c
@@ -844,10 +844,12 @@
}
// Computes the valid compound_types to be evaluated
-static INLINE int compute_valid_comp_types(
- MACROBLOCK *x, const AV1_COMP *const cpi, int *try_average_and_distwtd_comp,
- BLOCK_SIZE bsize, int masked_compound_used, int mode_search_mask,
- COMPOUND_TYPE *valid_comp_types) {
+static INLINE int compute_valid_comp_types(MACROBLOCK *x,
+ const AV1_COMP *const cpi,
+ BLOCK_SIZE bsize,
+ int masked_compound_used,
+ int mode_search_mask,
+ COMPOUND_TYPE *valid_comp_types) {
const AV1_COMMON *cm = &cpi->common;
int valid_type_count = 0;
int comp_type, valid_check;
@@ -858,15 +860,13 @@
((mode_search_mask & (1 << COMPOUND_DISTWTD)) &&
cm->seq_params.order_hint_info.enable_dist_wtd_comp == 1 &&
cpi->sf.inter_sf.use_dist_wtd_comp_flag != DIST_WTD_COMP_DISABLED);
- *try_average_and_distwtd_comp = try_average_comp && try_distwtd_comp;
// Check if COMPOUND_AVERAGE and COMPOUND_DISTWTD are valid cases
for (comp_type = COMPOUND_AVERAGE; comp_type <= COMPOUND_DISTWTD;
comp_type++) {
valid_check =
(comp_type == COMPOUND_AVERAGE) ? try_average_comp : try_distwtd_comp;
- if (!*try_average_and_distwtd_comp && valid_check &&
- is_interinter_compound_used(comp_type, bsize))
+ if (valid_check && is_interinter_compound_used(comp_type, bsize))
valid_comp_types[valid_type_count++] = comp_type;
}
// Check if COMPOUND_WEDGE and COMPOUND_DIFFWTD are valid cases
@@ -974,25 +974,6 @@
}
}
-// Choose the better of the two COMPOUND_AVERAGE,
-// COMPOUND_DISTWTD based on modeled cost
-static int find_best_avg_distwtd_comp_type(MACROBLOCK *x, int *comp_model_rate,
- int64_t *comp_model_dist,
- int rate_mv, int64_t *best_rd) {
- int64_t est_rd[2];
- est_rd[COMPOUND_AVERAGE] =
- RDCOST(x->rdmult, comp_model_rate[COMPOUND_AVERAGE] + rate_mv,
- comp_model_dist[COMPOUND_AVERAGE]);
- est_rd[COMPOUND_DISTWTD] =
- RDCOST(x->rdmult, comp_model_rate[COMPOUND_DISTWTD] + rate_mv,
- comp_model_dist[COMPOUND_DISTWTD]);
- int best_type = (est_rd[COMPOUND_AVERAGE] <= est_rd[COMPOUND_DISTWTD])
- ? COMPOUND_AVERAGE
- : COMPOUND_DISTWTD;
- *best_rd = est_rd[best_type];
- return best_type;
-}
-
static INLINE void save_comp_rd_search_stat(
MACROBLOCK *x, const MB_MODE_INFO *const mbmi, const int32_t *comp_rate,
const int64_t *comp_dist, const int32_t *comp_model_rate,
@@ -1308,13 +1289,11 @@
COMPOUND_AVERAGE, COMPOUND_DISTWTD, COMPOUND_WEDGE, COMPOUND_DIFFWTD
};
int valid_type_count = 0;
- int try_average_and_distwtd_comp = 0;
// compute_valid_comp_types() returns the number of valid compound types to be
// evaluated and populates the same in the local array valid_comp_types[].
// It also sets the flag 'try_average_and_distwtd_comp'
valid_type_count = compute_valid_comp_types(
- x, cpi, &try_average_and_distwtd_comp, bsize, masked_compound_used,
- mode_search_mask, valid_comp_types);
+ x, cpi, bsize, masked_compound_used, mode_search_mask, valid_comp_types);
// The following context indices are independent of compound type
const int comp_group_idx_ctx = get_comp_group_idx_context(xd);
@@ -1336,98 +1315,6 @@
comp_rate, comp_dist, comp_rs2,
rate_mv, rd, match_index);
}
- // Special handling if both compound_average and compound_distwtd
- // are to be searched. In this case, first estimate between the two
- // modes and then call estimate_yrd_for_sb() only for the better of
- // the two.
- if (try_average_and_distwtd_comp) {
- int est_rate[2];
- int64_t est_dist[2], est_rd;
- COMPOUND_TYPE best_type;
- // Since modelled rate and dist are separately stored,
- // compute better of COMPOUND_AVERAGE and COMPOUND_DISTWTD
- // using the stored stats.
- if ((comp_model_rate[COMPOUND_AVERAGE] != INT_MAX) &&
- comp_model_rate[COMPOUND_DISTWTD] != INT_MAX) {
- // Choose the better of the COMPOUND_AVERAGE,
- // COMPOUND_DISTWTD on modeled cost.
- best_type = find_best_avg_distwtd_comp_type(
- x, comp_model_rate, comp_model_dist, *rate_mv, &est_rd);
- update_mbmi_for_compound_type(mbmi, best_type);
- if (comp_rate[best_type] != INT_MAX)
- best_rd_cur = RDCOST(
- x->rdmult,
- masked_type_cost[best_type] + *rate_mv + comp_rate[best_type],
- comp_dist[best_type]);
- comp_model_rd_cur = est_rd;
- // Update stats for best compound type
- if (best_rd_cur < *rd) {
- update_best_info(mbmi, rd, &best_type_stats, best_rd_cur,
- comp_model_rd_cur, masked_type_cost[best_type]);
- }
- restore_dst_buf(xd, *tmp_dst, 1);
- } else {
- int64_t sse_y[COMPOUND_DISTWTD + 1];
- // Calculate model_rd for COMPOUND_AVERAGE and COMPOUND_DISTWTD
- for (int comp_type = COMPOUND_AVERAGE; comp_type <= COMPOUND_DISTWTD;
- comp_type++) {
- update_mbmi_for_compound_type(mbmi, comp_type);
- av1_enc_build_inter_predictor(cm, xd, mi_row, mi_col, orig_dst, bsize,
- AOM_PLANE_Y, AOM_PLANE_Y);
- model_rd_sb_fn[MODELRD_CURVFIT](
- cpi, bsize, x, xd, 0, 0, &est_rate[comp_type], &est_dist[comp_type],
- NULL, NULL, NULL, NULL, NULL);
- est_rate[comp_type] += masked_type_cost[comp_type];
- comp_model_rate[comp_type] = est_rate[comp_type];
- comp_model_dist[comp_type] = est_dist[comp_type];
- sse_y[comp_type] = x->pred_sse[xd->mi[0]->ref_frame[0]];
- if (comp_type == COMPOUND_AVERAGE) {
- *is_luma_interp_done = 1;
- restore_dst_buf(xd, *tmp_dst, 1);
- }
- }
- // Choose the better of the two based on modeled cost and call
- // estimate_yrd_for_sb() for that one.
- best_type = find_best_avg_distwtd_comp_type(
- x, comp_model_rate, comp_model_dist, *rate_mv, &est_rd);
- update_mbmi_for_compound_type(mbmi, best_type);
- if (best_type == COMPOUND_AVERAGE) restore_dst_buf(xd, *orig_dst, 1);
- rs2 = masked_type_cost[best_type];
- RD_STATS est_rd_stats;
- const int64_t mode_rd = RDCOST(x->rdmult, rs2 + *rate_mv, 0);
- const int64_t tmp_rd_thresh = AOMMIN(*rd, rd_thresh) - mode_rd;
- int64_t est_rd_ = INT64_MAX;
- int eval_txfm = 1;
- // Check if the mode is good enough based on skip rd
- if (cpi->sf.inter_sf.txfm_rd_gate_level) {
- int64_t skip_rd =
- RDCOST(x->rdmult, rs2 + *rate_mv, (sse_y[best_type] << 4));
- eval_txfm = check_txfm_eval(x, bsize, ref_skip_rd, skip_rd,
- cpi->sf.inter_sf.txfm_rd_gate_level, 1);
- }
- // Evaluate further if skip rd is low enough
- if (eval_txfm) {
- est_rd_ =
- estimate_yrd_for_sb(cpi, bsize, x, tmp_rd_thresh, &est_rd_stats);
- }
-
- if (est_rd_ != INT64_MAX) {
- best_rd_cur = RDCOST(x->rdmult, rs2 + *rate_mv + est_rd_stats.rate,
- est_rd_stats.dist);
- // Backup rate and distortion for future reuse
- backup_stats(best_type, comp_rate, comp_dist, comp_model_rate,
- comp_model_dist, est_rate[best_type], est_dist[best_type],
- &est_rd_stats, comp_rs2, rs2);
- comp_model_rd_cur = est_rd;
- }
- if (best_type == COMPOUND_AVERAGE) restore_dst_buf(xd, *tmp_dst, 1);
- // Update stats for best compound type
- if (best_rd_cur < *rd) {
- update_best_info(mbmi, rd, &best_type_stats, best_rd_cur,
- comp_model_rd_cur, rs2);
- }
- }
- }
// If COMPOUND_AVERAGE is not valid, use the spare buffer
if (valid_comp_types[0] != COMPOUND_AVERAGE) restore_dst_buf(xd, *tmp_dst, 1);