Optimize interpolation filter selection

In interpolation filter selection, chroma (V component)
rd evaluation is exited if intermediate rd cost is more
than best rd cost. This change reduces the chroma MC
evaluations in filter selection.
Observed ~0.6% encode time reduction for 20 frames of
night 720p30 content with speed=1

Change-Id: I6f3b909ae8f992b34b678107e820f143be0ee2cd
diff --git a/av1/common/reconinter.c b/av1/common/reconinter.c
index b9f0b57..b6a36f1 100644
--- a/av1/common/reconinter.c
+++ b/av1/common/reconinter.c
@@ -994,32 +994,34 @@
 void av1_build_inter_predictors_sby(const AV1_COMMON *cm, MACROBLOCKD *xd,
                                     int mi_row, int mi_col, BUFFER_SET *ctx,
                                     BLOCK_SIZE bsize) {
-  build_inter_predictors_for_planes(cm, xd, bsize, mi_row, mi_col, 0, 0);
-
-  if (is_interintra_pred(xd->mi[0])) {
-    BUFFER_SET default_ctx = { { xd->plane[0].dst.buf, NULL, NULL },
-                               { xd->plane[0].dst.stride, 0, 0 } };
-    if (!ctx) ctx = &default_ctx;
-    av1_build_interintra_predictors_sbp(cm, xd, xd->plane[0].dst.buf,
-                                        xd->plane[0].dst.stride, ctx, 0, bsize);
-  }
+  av1_build_inter_predictors_sbp(cm, xd, mi_row, mi_col, ctx, bsize, 0);
 }
 
 void av1_build_inter_predictors_sbuv(const AV1_COMMON *cm, MACROBLOCKD *xd,
                                      int mi_row, int mi_col, BUFFER_SET *ctx,
                                      BLOCK_SIZE bsize) {
-  build_inter_predictors_for_planes(cm, xd, bsize, mi_row, mi_col, 1,
-                                    MAX_MB_PLANE - 1);
+  for (int plane_idx = 1; plane_idx < MAX_MB_PLANE; plane_idx++) {
+    av1_build_inter_predictors_sbp(cm, xd, mi_row, mi_col, ctx, bsize,
+                                   plane_idx);
+  }
+}
+
+void av1_build_inter_predictors_sbp(const AV1_COMMON *cm, MACROBLOCKD *xd,
+                                    int mi_row, int mi_col, BUFFER_SET *ctx,
+                                    BLOCK_SIZE bsize, int plane_idx) {
+  build_inter_predictors_for_planes(cm, xd, bsize, mi_row, mi_col, plane_idx,
+                                    plane_idx);
 
   if (is_interintra_pred(xd->mi[0])) {
-    BUFFER_SET default_ctx = {
-      { NULL, xd->plane[1].dst.buf, xd->plane[2].dst.buf },
-      { 0, xd->plane[1].dst.stride, xd->plane[2].dst.stride }
-    };
-    if (!ctx) ctx = &default_ctx;
-    av1_build_interintra_predictors_sbuv(
-        cm, xd, xd->plane[1].dst.buf, xd->plane[2].dst.buf,
-        xd->plane[1].dst.stride, xd->plane[2].dst.stride, ctx, bsize);
+    BUFFER_SET default_ctx = { { NULL, NULL, NULL }, { 0, 0, 0 } };
+    if (!ctx) {
+      default_ctx.plane[plane_idx] = xd->plane[plane_idx].dst.buf;
+      default_ctx.stride[plane_idx] = xd->plane[plane_idx].dst.stride;
+      ctx = &default_ctx;
+    }
+    av1_build_interintra_predictors_sbp(cm, xd, xd->plane[plane_idx].dst.buf,
+                                        xd->plane[plane_idx].dst.stride, ctx,
+                                        plane_idx, bsize);
   }
 }
 
diff --git a/av1/common/reconinter.h b/av1/common/reconinter.h
index 6a3def2..855ef81 100644
--- a/av1/common/reconinter.h
+++ b/av1/common/reconinter.h
@@ -245,6 +245,10 @@
                                      int mi_row, int mi_col, BUFFER_SET *ctx,
                                      BLOCK_SIZE bsize);
 
+void av1_build_inter_predictors_sbp(const AV1_COMMON *cm, MACROBLOCKD *xd,
+                                    int mi_row, int mi_col, BUFFER_SET *ctx,
+                                    BLOCK_SIZE bsize, int plane_idx);
+
 void av1_build_inter_predictors_sb(const AV1_COMMON *cm, MACROBLOCKD *xd,
                                    int mi_row, int mi_col, BUFFER_SET *ctx,
                                    BLOCK_SIZE bsize);
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 031446c..4b16f48 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -7663,29 +7663,31 @@
                     &tmp_skip_sse, NULL, NULL, NULL);
 #endif
     if (num_planes > 1) {
-      int64_t tmp_y_rd = RDCOST(x->rdmult, tmp_rs + tmp_rate, tmp_dist);
-      if (tmp_y_rd > *rd) {
-        mbmi->interp_filters = last_best;
-        return 0;
-      }
       int tmp_rate_uv, tmp_skip_sb_uv;
       int64_t tmp_dist_uv, tmp_skip_sse_uv;
-      av1_build_inter_predictors_sbuv(cm, xd, mi_row, mi_col, orig_dst, bsize);
-      for (int plane = 1; plane < num_planes; ++plane)
+      for (int plane = 1; plane < num_planes; ++plane) {
+        int64_t tmp_rd = RDCOST(x->rdmult, tmp_rs + tmp_rate, tmp_dist);
+        if (tmp_rd >= *rd) {
+          mbmi->interp_filters = last_best;
+          return 0;
+        }
+        av1_build_inter_predictors_sbp(cm, xd, mi_row, mi_col, orig_dst, bsize,
+                                       plane);
         av1_subtract_plane(x, bsize, plane);
 #if DNN_BASED_RD_INTERP_FILTER
-      model_rd_for_sb_with_dnn(cpi, bsize, x, xd, 1, num_planes - 1,
-                               &tmp_rate_uv, &tmp_dist_uv, &tmp_skip_sb_uv,
-                               &tmp_skip_sse_uv, NULL, NULL, NULL);
+        model_rd_for_sb_with_dnn(cpi, bsize, x, xd, plane, plane, &tmp_rate_uv,
+                                 &tmp_dist_uv, &tmp_skip_sb_uv,
+                                 &tmp_skip_sse_uv, NULL, NULL, NULL);
 #else
-      model_rd_for_sb(cpi, bsize, x, xd, 1, num_planes - 1, &tmp_rate_uv,
-                      &tmp_dist_uv, &tmp_skip_sb_uv, &tmp_skip_sse_uv, NULL,
-                      NULL, NULL);
+        model_rd_for_sb(cpi, bsize, x, xd, plane, plane, &tmp_rate_uv,
+                        &tmp_dist_uv, &tmp_skip_sb_uv, &tmp_skip_sse_uv, NULL,
+                        NULL, NULL);
 #endif
-      tmp_rate += tmp_rate_uv;
-      tmp_skip_sb &= tmp_skip_sb_uv;
-      tmp_dist += tmp_dist_uv;
-      tmp_skip_sse += tmp_skip_sse_uv;
+        tmp_rate += tmp_rate_uv;
+        tmp_skip_sb &= tmp_skip_sb_uv;
+        tmp_dist += tmp_dist_uv;
+        tmp_skip_sse += tmp_skip_sse_uv;
+      }
     }
   } else {
     tmp_rate = *rate;