intrabc: use its own mv cost table

To faciliate using intrabc on interframes.

Change-Id: Ibfe376190adf24d15198c5fb548e1050e191a3d6
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index dfb0b2e..2f72a28 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -615,6 +615,9 @@
 #if CONFIG_INTRABC
   // A flag to indicate if intrabc is ever used in current frame.
   int intrabc_used;
+  int dv_cost[2][MV_VALS];
+  // TODO(huisu@google.com): we can update dv_joint_cost per SB.
+  int dv_joint_cost[MV_JOINTS];
 #endif  // CONFIG_INTRABC
 } AV1_COMP;
 
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 4173020..f2daad7 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -715,10 +715,9 @@
 #if CONFIG_INTRABC
   if (frame_is_intra_only(cm) && cm->allow_screen_content_tools &&
       cpi->oxcf.pass != 1) {
-    av1_build_nmv_cost_table(
-        x->nmv_vec_cost[0],
-        cm->allow_high_precision_mv ? x->nmvcost_hp[0] : x->nmvcost[0],
-        &cm->fc->ndvc, MV_SUBPEL_NONE);
+    int *dvcost[2] = { &cpi->dv_cost[0][MV_MAX], &cpi->dv_cost[1][MV_MAX] };
+    av1_build_nmv_cost_table(cpi->dv_joint_cost, dvcost, &cm->fc->ndvc,
+                             MV_SUBPEL_NONE);
   }
 #endif
 
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 4954c8f..b86c8d8 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -8873,11 +8873,12 @@
     x->skip = 0;
     av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, bsize);
 
-    assert(x->mvcost == x->mv_cost_stack[0]);
+    int *dvcost[2] = { (int *)&cpi->dv_cost[0][MV_MAX],
+                       (int *)&cpi->dv_cost[1][MV_MAX] };
     // TODO(aconverse@google.com): The full motion field defining discount
     // in MV_COST_WEIGHT is too large. Explore other values.
-    int rate_mv = av1_mv_bit_cost(&dv, &dv_ref.as_mv, x->nmvjointcost,
-                                  x->mvcost, MV_COST_WEIGHT_SUB);
+    int rate_mv = av1_mv_bit_cost(&dv, &dv_ref.as_mv, cpi->dv_joint_cost,
+                                  dvcost, MV_COST_WEIGHT_SUB);
     const int rate_mode = x->intrabc_cost[1];
     RD_STATS rd_stats, rd_stats_uv;
     av1_subtract_plane(x, bsize, 0);