Add 'do_average' to ConvolveParams structure

The 'ref' member of ConvolveParams currently serves two purposes:
* To indicate which component of a compound we're currently predicting,
  eg. for fetching interpolation filters with dual-filter enabled.
* To determine whether we should average into the destination buffer.

But there are two cases where we want to separate these out:
* In joint_motion_search, we want to try combining a fixed second
  prediction with various first predictions.
* When searching masked interinter compounds, we want to predict
  each component separately then try different combinations.

In these cases, we set 'ref' to 0 and use temporary variables to
make sure we use the correct interpolation filters. But this is
quite fragile.

This patch separates out the two uses into separate members.
This allows us to remove some temporary variables, but more
importantly gives easy fixes to two bugs in
build_inter_predictors_single_buf (used by rdopt):

* We previously set ref=0 but didn't fix up the interpolation filters
* For ZERO_ZEROMV modes, the second component would accidentally
  average into the (uninitialized!) second prediction buffer

BUG=aomedia:577
BUG=aomedia:584
BUG=aomedia:595

Change-Id: Ibc31d1ac701a029ea5efaa1197dd402bc4b7af1e
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 7212709..27a9403 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -5170,14 +5170,6 @@
   const int refs[2] = { mbmi->ref_frame[0], mbmi->ref_frame[1] };
   int_mv ref_mv[2];
   int ite, ref;
-#if CONFIG_DUAL_FILTER
-  InterpFilter interp_filter[4] = {
-    mbmi->interp_filter[0], mbmi->interp_filter[1], mbmi->interp_filter[2],
-    mbmi->interp_filter[3],
-  };
-#else
-  const InterpFilter interp_filter = mbmi->interp_filter;
-#endif  // CONFIG_DUAL_FILTER
   struct scale_factors sf;
   struct macroblockd_plane *const pd = &xd->plane[0];
 #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
@@ -5260,7 +5252,7 @@
                        // odd iterations search in the second. The predictor
                        // found for the 'other' reference frame is factored in.
     const int plane = 0;
-    ConvolveParams conv_params = get_conv_params(0, plane);
+    ConvolveParams conv_params = get_conv_params(!id, 0, plane);
 #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
     WarpTypesAllowed warp_types;
 #if CONFIG_GLOBAL_MOTION
@@ -5275,21 +5267,13 @@
     ref_yv12[0] = xd->plane[plane].pre[0];
     ref_yv12[1] = xd->plane[plane].pre[1];
 
-#if CONFIG_DUAL_FILTER
-    // reload the filter types
-    interp_filter[0] =
-        (id == 0) ? mbmi->interp_filter[2] : mbmi->interp_filter[0];
-    interp_filter[1] =
-        (id == 0) ? mbmi->interp_filter[3] : mbmi->interp_filter[1];
-#endif  // CONFIG_DUAL_FILTER
-
 // Get the prediction block from the 'other' reference frame.
 #if CONFIG_HIGHBITDEPTH
     if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
       second_pred = CONVERT_TO_BYTEPTR(second_pred_alloc_16);
       av1_highbd_build_inter_predictor(
           ref_yv12[!id].buf, ref_yv12[!id].stride, second_pred, pw,
-          &frame_mv[refs[!id]].as_mv, &sf, pw, ph, 0, interp_filter,
+          &frame_mv[refs[!id]].as_mv, &sf, pw, ph, 0, mbmi->interp_filter,
 #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
           &warp_types, p_col, p_row,
 #endif  // CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
@@ -5297,13 +5281,14 @@
     } else {
       second_pred = (uint8_t *)second_pred_alloc_16;
 #endif  // CONFIG_HIGHBITDEPTH
-      av1_build_inter_predictor(
-          ref_yv12[!id].buf, ref_yv12[!id].stride, second_pred, pw,
-          &frame_mv[refs[!id]].as_mv, &sf, pw, ph, &conv_params, interp_filter,
+      av1_build_inter_predictor(ref_yv12[!id].buf, ref_yv12[!id].stride,
+                                second_pred, pw, &frame_mv[refs[!id]].as_mv,
+                                &sf, pw, ph, &conv_params, mbmi->interp_filter,
 #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
-          &warp_types, p_col, p_row, plane, !id,
+                                &warp_types, p_col, p_row, plane, !id,
 #endif  // CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
-          MV_PRECISION_Q3, mi_col * MI_SIZE, mi_row * MI_SIZE, xd);
+                                MV_PRECISION_Q3, mi_col * MI_SIZE,
+                                mi_row * MI_SIZE, xd);
 #if CONFIG_HIGHBITDEPTH
     }
 #endif  // CONFIG_HIGHBITDEPTH
@@ -5889,14 +5874,6 @@
   MACROBLOCKD *xd = &x->e_mbd;
   MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
   const int other_ref = mbmi->ref_frame[!ref_idx];
-#if CONFIG_DUAL_FILTER
-  InterpFilter interp_filter[2] = {
-    (ref_idx == 0) ? mbmi->interp_filter[2] : mbmi->interp_filter[0],
-    (ref_idx == 0) ? mbmi->interp_filter[3] : mbmi->interp_filter[1]
-  };
-#else
-  const InterpFilter interp_filter = mbmi->interp_filter;
-#endif  // CONFIG_DUAL_FILTER
   struct scale_factors sf;
 #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
   struct macroblockd_plane *const pd = &xd->plane[0];
@@ -5943,7 +5920,7 @@
   struct buf_2d ref_yv12;
 
   const int plane = 0;
-  ConvolveParams conv_params = get_conv_params(0, plane);
+  ConvolveParams conv_params = get_conv_params(!ref_idx, 0, plane);
 #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
   WarpTypesAllowed warp_types;
 #if CONFIG_GLOBAL_MOTION
@@ -5962,7 +5939,7 @@
   if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
     av1_highbd_build_inter_predictor(
         ref_yv12.buf, ref_yv12.stride, second_pred, pw, other_mv, &sf, pw, ph,
-        0, interp_filter,
+        0, mbmi->interp_filter,
 #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
         &warp_types, p_col, p_row,
 #endif  // CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
@@ -5971,7 +5948,7 @@
 #endif  // CONFIG_HIGHBITDEPTH
     av1_build_inter_predictor(
         ref_yv12.buf, ref_yv12.stride, second_pred, pw, other_mv, &sf, pw, ph,
-        &conv_params, interp_filter,
+        &conv_params, mbmi->interp_filter,
 #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
         &warp_types, p_col, p_row, plane, !ref_idx,
 #endif  // CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION