ext_inter: remove unnecessary rate parameters

Only use compmode_interinter_cost and compmode_interintra_cost in
handle_inter_mode() since outside the function they can be reflected
by the total rate.
Plus adding config flags to separate wedge/compound_segment from
ext_inter

Change-Id: I56b402aab3cf2337bae8d7e682f93cd8557f69a4
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 6fc0ae4..9452a7b 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -1937,7 +1937,7 @@
   return 0;
 }
 
-#if CONFIG_EXT_INTER
+#if CONFIG_EXT_INTER && (CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT)
 static int64_t estimate_yrd_for_sb(const AV1_COMP *const cpi, BLOCK_SIZE bs,
                                    MACROBLOCK *x, int *r, int64_t *d, int *s,
                                    int64_t *sse, int64_t ref_best_rd) {
@@ -1950,7 +1950,7 @@
   *sse = rd_stats.sse;
   return rd;
 }
-#endif  // CONFIG_EXT_INTER
+#endif  // CONFIG_EXT_INTER && (CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT)
 
 static void choose_largest_tx_size(const AV1_COMP *const cpi, MACROBLOCK *x,
                                    RD_STATS *rd_stats, int64_t ref_best_rd,
@@ -5051,7 +5051,7 @@
   }
 }
 
-#if CONFIG_EXT_INTER
+#if CONFIG_EXT_INTER && (CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT)
 static int get_interinter_compound_type_bits(BLOCK_SIZE bsize,
                                              COMPOUND_TYPE comp_type) {
   (void)bsize;
@@ -5066,7 +5066,7 @@
     default: assert(0); return 0;
   }
 }
-#endif  // CONFIG_EXT_INTER
+#endif  // CONFIG_EXT_INTER && (CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT)
 
 static int set_and_cost_bmi_mvs(
     const AV1_COMP *const cpi, MACROBLOCK *x, MACROBLOCKD *xd, int i,
@@ -8029,9 +8029,6 @@
   // Pointer to array of motion vectors to use for each ref and their rates
   // Should point to first of 2 arrays in 2D array
   int *single_newmv_rate;
-  // Pointers costs of compound inter-intra and inter-inter predictions
-  int *compmode_interintra_cost;
-  int *compmode_interinter_cost;
   // Pointer to array of predicted rate-distortion
   // Should point to first of 2 arrays in 2D array
   int64_t (*modelled_rd)[TOTAL_REFS_PER_FRAME];
@@ -8651,7 +8648,9 @@
   int rate_mv = 0;
 #if CONFIG_EXT_INTER
   int pred_exists = 1;
+#if CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT
   const int bw = block_size_wide[bsize];
+#endif  // ONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT
   int_mv single_newmv[TOTAL_REFS_PER_FRAME];
 #if CONFIG_INTERINTRA
   const unsigned int *const interintra_mode_cost =
@@ -8687,10 +8686,14 @@
   int16_t mode_ctx;
 
 #if CONFIG_EXT_INTER
-  *args->compmode_interintra_cost = 0;
+#if CONFIG_INTERINTRA
+  int compmode_interintra_cost = 0;
   mbmi->use_wedge_interintra = 0;
-  *args->compmode_interinter_cost = 0;
+#endif
+#if CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT
+  int compmode_interinter_cost = 0;
   mbmi->interinter_compound_type = COMPOUND_AVERAGE;
+#endif
 
 #if CONFIG_INTERINTRA
   if (!cm->allow_interintra_compound && is_comp_interintra_pred)
@@ -8888,6 +8891,7 @@
 #endif  // CONFIG_MOTION_VAR
 #endif  // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
 
+#if CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT
   if (is_comp_pred) {
     int rate_sum, rs2;
     int64_t dist_sum;
@@ -9033,13 +9037,14 @@
 
     pred_exists = 0;
 
-    *args->compmode_interinter_cost =
+    compmode_interinter_cost =
         av1_cost_literal(get_interinter_compound_type_bits(
             bsize, mbmi->interinter_compound_type)) +
         (masked_compound_used
              ? compound_type_cost[mbmi->interinter_compound_type]
              : 0);
   }
+#endif  // CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT
 
 #if CONFIG_INTERINTRA
   if (is_comp_interintra_pred) {
@@ -9179,20 +9184,19 @@
 #endif  // CONFIG_WEDGE
 
     pred_exists = 0;
-    *args->compmode_interintra_cost =
-        av1_cost_bit(cm->fc->interintra_prob[size_group_lookup[bsize]], 1);
-    *args->compmode_interintra_cost +=
+    compmode_interintra_cost =
+        av1_cost_bit(cm->fc->interintra_prob[size_group_lookup[bsize]], 1) +
         interintra_mode_cost[mbmi->interintra_mode];
     if (is_interintra_wedge_used(bsize)) {
-      *args->compmode_interintra_cost += av1_cost_bit(
+      compmode_interintra_cost += av1_cost_bit(
           cm->fc->wedge_interintra_prob[bsize], mbmi->use_wedge_interintra);
       if (mbmi->use_wedge_interintra) {
-        *args->compmode_interintra_cost +=
+        compmode_interintra_cost +=
             av1_cost_literal(get_interintra_wedge_bits(bsize));
       }
     }
   } else if (is_interintra_allowed(mbmi)) {
-    *args->compmode_interintra_cost =
+    compmode_interintra_cost =
         av1_cost_bit(cm->fc->interintra_prob[size_group_lookup[bsize]], 0);
   }
 #endif  // CONFIG_INTERINTRA
@@ -9240,6 +9244,18 @@
     }
   }
 
+#if CONFIG_EXT_INTER
+#if CONFIG_INTERINTRA
+  rd_stats->rate += compmode_interintra_cost;
+#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
+  rate2_bmc_nocoeff += compmode_interintra_cost;
+#endif
+#endif
+#if CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT
+  rd_stats->rate += compmode_interinter_cost;
+#endif
+#endif
+
   ret_val = motion_mode_rd(cpi, x, bsize, rd_stats, rd_stats_y, rd_stats_uv,
                            disable_skip, mode_mv, mi_row, mi_col, args,
                            ref_best_rd, refs, rate_mv,
@@ -9917,8 +9933,6 @@
     NULL,
     NULL,
     NULL,
-    NULL,
-    NULL,
 #else   // CONFIG_EXT_INTER
     NULL,
 #endif  // CONFIG_EXT_INTER
@@ -10229,10 +10243,6 @@
     int64_t this_rd = INT64_MAX;
     int disable_skip = 0;
     int compmode_cost = 0;
-#if CONFIG_EXT_INTER
-    int compmode_interintra_cost = 0;
-    int compmode_interinter_cost = 0;
-#endif  // CONFIG_EXT_INTER
     int rate2 = 0, rate_y = 0, rate_uv = 0;
     int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0;
     int skippable = 0;
@@ -10657,18 +10667,11 @@
         args.single_newmv = single_newmv;
 #if CONFIG_EXT_INTER
         args.single_newmv_rate = single_newmv_rate;
-        args.compmode_interintra_cost = &compmode_interintra_cost;
-        args.compmode_interinter_cost = &compmode_interinter_cost;
         args.modelled_rd = modelled_rd;
 #endif  // CONFIG_EXT_INTER
         this_rd = handle_inter_mode(cpi, x, bsize, &rd_stats, &rd_stats_y,
                                     &rd_stats_uv, &disable_skip, frame_mv,
                                     mi_row, mi_col, &args, best_rd);
-// Prevent pointers from escaping local scope
-#if CONFIG_EXT_INTER
-        args.compmode_interintra_cost = NULL;
-        args.compmode_interinter_cost = NULL;
-#endif  // CONFIG_EXT_INTER
 
         rate2 = rd_stats.rate;
         skippable = rd_stats.skip;
@@ -10740,10 +10743,6 @@
           int ref;
           int_mv cur_mv;
           RD_STATS tmp_rd_stats, tmp_rd_stats_y, tmp_rd_stats_uv;
-#if CONFIG_EXT_INTER
-          int tmp_compmode_interintra_cost = 0;
-          int tmp_compmode_interinter_cost = 0;
-#endif  // CONFIG_EXT_INTER
 
           av1_invalid_rd_stats(&tmp_rd_stats);
           x->skip = 0;
@@ -10821,8 +10820,6 @@
             args.single_newmv = dummy_single_newmv;
 #if CONFIG_EXT_INTER
             args.single_newmv_rate = dummy_single_newmv_rate;
-            args.compmode_interintra_cost = &tmp_compmode_interintra_cost;
-            args.compmode_interinter_cost = &tmp_compmode_interinter_cost;
             args.modelled_rd = NULL;
 #endif  // CONFIG_EXT_INTER
             tmp_alt_rd = handle_inter_mode(
@@ -10832,8 +10829,6 @@
             args.single_newmv = NULL;
 #if CONFIG_EXT_INTER
             args.single_newmv_rate = NULL;
-            args.compmode_interintra_cost = NULL;
-            args.compmode_interinter_cost = NULL;
 #endif  // CONFIG_EXT_INTER
           }
 
@@ -10898,10 +10893,6 @@
               memcpy(x->blk_skip_drl[i], x->blk_skip[i],
                      sizeof(uint8_t) * ctx->num_4x4_blk);
 #endif  // CONFIG_VAR_TX
-#if CONFIG_EXT_INTER
-            compmode_interintra_cost = tmp_compmode_interintra_cost;
-            compmode_interinter_cost = tmp_compmode_interinter_cost;
-#endif  // CONFIG_EXT_INTER
           } else {
             *mbmi = backup_mbmi;
             x->skip = backup_skip;
@@ -10932,15 +10923,6 @@
       if (cm->reference_mode == REFERENCE_MODE_SELECT) rate2 += compmode_cost;
     }
 
-#if CONFIG_EXT_INTER
-    rate2 += compmode_interintra_cost;
-    if (cm->reference_mode != SINGLE_REFERENCE && comp_pred)
-#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
-      if (mbmi->motion_mode == SIMPLE_TRANSLATION)
-#endif  // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
-        rate2 += compmode_interinter_cost;
-#endif  // CONFIG_EXT_INTER
-
     // Estimate the reference frame signaling cost and add it
     // to the rolling cost variable.
     if (comp_pred) {