Fix multi-threading mismatch issues

With row-mt multi-threading enabled, loop restoration
type rate information was not updated consistently before
calling av1_pick_filter_restoration. This caused a mismatch
between multi-threading runs. It is fixed by updating the
rate information inside av1_pick_filter_restoration.

Change-Id: I643d9e5b2890b2c206bac2d5a559f2ff505449c0
diff --git a/av1/encoder/pickrst.c b/av1/encoder/pickrst.c
index f76146d..9afc72a 100644
--- a/av1/encoder/pickrst.c
+++ b/av1/encoder/pickrst.c
@@ -1700,9 +1700,12 @@
 
 void av1_pick_filter_restoration(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi) {
   AV1_COMMON *const cm = &cpi->common;
+  MACROBLOCK *const x = &cpi->td.mb;
   const int num_planes = av1_num_planes(cm);
   assert(!cm->features.all_lossless);
 
+  av1_fill_lr_rates(&x->mode_costs, x->e_mbd.tile_ctx);
+
   int ntiles[2];
   for (int is_uv = 0; is_uv < 2; ++is_uv)
     ntiles[is_uv] = rest_tiles_in_plane(cm, is_uv);
@@ -1717,14 +1720,14 @@
   // problem, as these elements are ignored later, but in order to quiet
   // Valgrind's warnings we initialise the array below.
   memset(rusi, 0, sizeof(*rusi) * ntiles[0]);
-  cpi->td.mb.rdmult = cpi->rd.RDMULT;
+  x->rdmult = cpi->rd.RDMULT;
 
   RestSearchCtxt rsc;
   const int plane_start = AOM_PLANE_Y;
   const int plane_end = num_planes > 1 ? AOM_PLANE_V : AOM_PLANE_Y;
   for (int plane = plane_start; plane <= plane_end; ++plane) {
-    init_rsc(src, &cpi->common, &cpi->td.mb, &cpi->sf, plane, rusi,
-             &cpi->trial_frame_rst, &rsc);
+    init_rsc(src, &cpi->common, x, &cpi->sf, plane, rusi, &cpi->trial_frame_rst,
+             &rsc);
 
     const int plane_ntiles = ntiles[plane > 0];
     const RestorationType num_rtypes =
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 61e8b25..ded64c6 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -209,12 +209,6 @@
     av1_cost_tokens_from_cdf(mode_costs->angle_delta_cost[i],
                              fc->angle_delta_cdf[i], NULL);
   }
-  av1_cost_tokens_from_cdf(mode_costs->switchable_restore_cost,
-                           fc->switchable_restore_cdf, NULL);
-  av1_cost_tokens_from_cdf(mode_costs->wiener_restore_cost,
-                           fc->wiener_restore_cdf, NULL);
-  av1_cost_tokens_from_cdf(mode_costs->sgrproj_restore_cost,
-                           fc->sgrproj_restore_cdf, NULL);
   av1_cost_tokens_from_cdf(mode_costs->intrabc_cost, fc->intrabc_cdf, NULL);
 
   if (!frame_is_intra_only(cm)) {
@@ -321,6 +315,15 @@
   }
 }
 
+void av1_fill_lr_rates(ModeCosts *mode_costs, FRAME_CONTEXT *fc) {
+  av1_cost_tokens_from_cdf(mode_costs->switchable_restore_cost,
+                           fc->switchable_restore_cdf, NULL);
+  av1_cost_tokens_from_cdf(mode_costs->wiener_restore_cost,
+                           fc->wiener_restore_cdf, NULL);
+  av1_cost_tokens_from_cdf(mode_costs->sgrproj_restore_cost,
+                           fc->sgrproj_restore_cdf, NULL);
+}
+
 // Values are now correlated to quantizer.
 static int sad_per_bit_lut_8[QINDEX_RANGE];
 static int sad_per_bit_lut_10[QINDEX_RANGE];
diff --git a/av1/encoder/rd.h b/av1/encoder/rd.h
index 8409b41..1310561 100644
--- a/av1/encoder/rd.h
+++ b/av1/encoder/rd.h
@@ -355,6 +355,8 @@
 void av1_fill_mode_rates(AV1_COMMON *const cm, ModeCosts *mode_costs,
                          FRAME_CONTEXT *fc);
 
+void av1_fill_lr_rates(ModeCosts *mode_costs, FRAME_CONTEXT *fc);
+
 void av1_fill_coeff_costs(CoeffCosts *coeff_costs, FRAME_CONTEXT *fc,
                           const int num_planes);