Add pointers to temp buffers in 'xd'.

Based on comments in
https://aomedia-review.googlesource.com/c/aom/+/70022

This avoids passing the temp buffer pointers and/or 'x' all the way
through the call chain.

BUG=aomedia:2135

Change-Id: I32f0a0b006d9fb24ee1b85ff1f33012bdb0eeb42
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 30f5277..03cedef 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -191,11 +191,10 @@
   (void)tx_size;
 }
 
-static void predict_inter_block_void(AV1_COMMON *const cm, const ThreadData *td,
+static void predict_inter_block_void(AV1_COMMON *const cm,
                                      MACROBLOCKD *const xd, int mi_row,
                                      int mi_col, BLOCK_SIZE bsize) {
   (void)cm;
-  (void)td;
   (void)xd;
   (void)mi_row;
   (void)mi_col;
@@ -625,7 +624,6 @@
 }
 
 static INLINE void dec_build_inter_predictors(const AV1_COMMON *cm,
-                                              CONV_BUF_TYPE *tmp_conv_dst,
                                               MACROBLOCKD *xd, int plane,
                                               const MB_MODE_INFO *mi,
                                               int build_for_obmc, int bw,
@@ -692,7 +690,7 @@
         int tmp_dst_stride = 8;
         assert(bw < 8 || bh < 8);
         ConvolveParams conv_params = get_conv_params_no_round(
-            0, plane, tmp_conv_dst, tmp_dst_stride, is_compound, xd->bd);
+            0, plane, xd->tmp_conv_dst, tmp_dst_stride, is_compound, xd->bd);
         conv_params.use_jnt_comp_avg = 0;
         struct buf_2d *const dst_buf = &pd->dst;
         uint8_t *dst = dst_buf->buf + dst_buf->stride * y + x;
@@ -796,7 +794,7 @@
     }
 
     ConvolveParams conv_params = get_conv_params_no_round(
-        0, plane, tmp_conv_dst, MAX_SB_SIZE, is_compound, xd->bd);
+        0, plane, xd->tmp_conv_dst, MAX_SB_SIZE, is_compound, xd->bd);
     av1_jnt_comp_weight_assign(cm, mi, 0, &conv_params.fwd_offset,
                                &conv_params.bck_offset,
                                &conv_params.use_jnt_comp_avg, is_compound);
@@ -829,9 +827,11 @@
   }
 }
 
-static void dec_build_inter_predictors_for_planes(
-    const AV1_COMMON *cm, const ThreadData *td, MACROBLOCKD *xd,
-    BLOCK_SIZE bsize, int mi_row, int mi_col, int plane_from, int plane_to) {
+static void dec_build_inter_predictors_for_planes(const AV1_COMMON *cm,
+                                                  MACROBLOCKD *xd,
+                                                  BLOCK_SIZE bsize, int mi_row,
+                                                  int mi_col, int plane_from,
+                                                  int plane_to) {
   int plane;
   const int mi_x = mi_col * MI_SIZE;
   const int mi_y = mi_row * MI_SIZE;
@@ -844,18 +844,15 @@
                              pd->subsampling_y))
       continue;
 
-    dec_build_inter_predictors(cm, td->tmp_conv_dst, xd, plane, xd->mi[0], 0,
-                               bw, bh, mi_x, mi_y);
+    dec_build_inter_predictors(cm, xd, plane, xd->mi[0], 0, bw, bh, mi_x, mi_y);
   }
 }
 
 static void dec_build_inter_predictors_sby(const AV1_COMMON *cm,
-                                           const ThreadData *td,
                                            MACROBLOCKD *xd, int mi_row,
                                            int mi_col, BUFFER_SET *ctx,
                                            BLOCK_SIZE bsize) {
-  dec_build_inter_predictors_for_planes(cm, td, xd, bsize, mi_row, mi_col, 0,
-                                        0);
+  dec_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 },
@@ -867,11 +864,10 @@
 }
 
 static void dec_build_inter_predictors_sbuv(const AV1_COMMON *cm,
-                                            const ThreadData *td,
                                             MACROBLOCKD *xd, int mi_row,
                                             int mi_col, BUFFER_SET *ctx,
                                             BLOCK_SIZE bsize) {
-  dec_build_inter_predictors_for_planes(cm, td, xd, bsize, mi_row, mi_col, 1,
+  dec_build_inter_predictors_for_planes(cm, xd, bsize, mi_row, mi_col, 1,
                                         MAX_MB_PLANE - 1);
 
   if (is_interintra_pred(xd->mi[0])) {
@@ -886,14 +882,13 @@
   }
 }
 
-static void dec_build_inter_predictors_sb(const AV1_COMMON *cm,
-                                          const ThreadData *td, MACROBLOCKD *xd,
+static void dec_build_inter_predictors_sb(const AV1_COMMON *cm, MACROBLOCKD *xd,
                                           int mi_row, int mi_col,
                                           BUFFER_SET *ctx, BLOCK_SIZE bsize) {
   const int num_planes = av1_num_planes(cm);
-  dec_build_inter_predictors_sby(cm, td, xd, mi_row, mi_col, ctx, bsize);
+  dec_build_inter_predictors_sby(cm, xd, mi_row, mi_col, ctx, bsize);
   if (num_planes > 1)
-    dec_build_inter_predictors_sbuv(cm, td, xd, mi_row, mi_col, ctx, bsize);
+    dec_build_inter_predictors_sbuv(cm, xd, mi_row, mi_col, ctx, bsize);
 }
 
 static INLINE void dec_build_prediction_by_above_pred(
@@ -918,14 +913,14 @@
                    block_size_high[BLOCK_64X64] >> (pd->subsampling_y + 1));
 
     if (av1_skip_u4x4_pred_in_obmc(bsize, pd, 0)) continue;
-    dec_build_inter_predictors(ctxt->cm, ctxt->tmp_conv_dst, xd, j,
-                               &backup_mbmi, 1, bw, bh, mi_x, mi_y);
+    dec_build_inter_predictors(ctxt->cm, xd, j, &backup_mbmi, 1, bw, bh, mi_x,
+                               mi_y);
   }
 }
 
 static void dec_build_prediction_by_above_preds(
-    const AV1_COMMON *cm, const ThreadData *td, MACROBLOCKD *xd, int mi_row,
-    int mi_col, uint8_t *tmp_buf[MAX_MB_PLANE], int tmp_width[MAX_MB_PLANE],
+    const AV1_COMMON *cm, MACROBLOCKD *xd, int mi_row, int mi_col,
+    uint8_t *tmp_buf[MAX_MB_PLANE], int tmp_width[MAX_MB_PLANE],
     int tmp_height[MAX_MB_PLANE], int tmp_stride[MAX_MB_PLANE]) {
   if (!xd->up_available) return;
 
@@ -936,11 +931,10 @@
   int pred_height = AOMMIN(this_height / 2, 32);
   xd->mb_to_bottom_edge += (this_height - pred_height) * 8;
 
-  struct build_prediction_ctxt ctxt = {
-    cm,         td->tmp_conv_dst, mi_row,
-    mi_col,     tmp_buf,          tmp_width,
-    tmp_height, tmp_stride,       xd->mb_to_right_edge
-  };
+  struct build_prediction_ctxt ctxt = { cm,         mi_row,
+                                        mi_col,     tmp_buf,
+                                        tmp_width,  tmp_height,
+                                        tmp_stride, xd->mb_to_right_edge };
   BLOCK_SIZE bsize = xd->mi[0]->sb_type;
   foreach_overlappable_nb_above(cm, xd, mi_col,
                                 max_neighbor_obmc[mi_size_wide_log2[bsize]],
@@ -972,14 +966,14 @@
     int bh = (left_mi_height << MI_SIZE_LOG2) >> pd->subsampling_y;
 
     if (av1_skip_u4x4_pred_in_obmc(bsize, pd, 1)) continue;
-    dec_build_inter_predictors(ctxt->cm, ctxt->tmp_conv_dst, xd, j,
-                               &backup_mbmi, 1, bw, bh, mi_x, mi_y);
+    dec_build_inter_predictors(ctxt->cm, xd, j, &backup_mbmi, 1, bw, bh, mi_x,
+                               mi_y);
   }
 }
 
 static void dec_build_prediction_by_left_preds(
-    const AV1_COMMON *cm, const ThreadData *td, MACROBLOCKD *xd, int mi_row,
-    int mi_col, uint8_t *tmp_buf[MAX_MB_PLANE], int tmp_width[MAX_MB_PLANE],
+    const AV1_COMMON *cm, MACROBLOCKD *xd, int mi_row, int mi_col,
+    uint8_t *tmp_buf[MAX_MB_PLANE], int tmp_width[MAX_MB_PLANE],
     int tmp_height[MAX_MB_PLANE], int tmp_stride[MAX_MB_PLANE]) {
   if (!xd->left_available) return;
 
@@ -990,11 +984,10 @@
   int pred_width = AOMMIN(this_width / 2, 32);
   xd->mb_to_right_edge += (this_width - pred_width) * 8;
 
-  struct build_prediction_ctxt ctxt = {
-    cm,         td->tmp_conv_dst, mi_row,
-    mi_col,     tmp_buf,          tmp_width,
-    tmp_height, tmp_stride,       xd->mb_to_bottom_edge
-  };
+  struct build_prediction_ctxt ctxt = { cm,         mi_row,
+                                        mi_col,     tmp_buf,
+                                        tmp_width,  tmp_height,
+                                        tmp_stride, xd->mb_to_bottom_edge };
   BLOCK_SIZE bsize = xd->mi[0]->sb_type;
   foreach_overlappable_nb_left(cm, xd, mi_row,
                                max_neighbor_obmc[mi_size_high_log2[bsize]],
@@ -1006,7 +999,6 @@
 }
 
 static void dec_build_obmc_inter_predictors_sb(const AV1_COMMON *cm,
-                                               const ThreadData *td,
                                                MACROBLOCKD *xd, int mi_row,
                                                int mi_col) {
   const int num_planes = av1_num_planes(cm);
@@ -1020,27 +1012,27 @@
 
   if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
     int len = sizeof(uint16_t);
-    dst_buf1[0] = CONVERT_TO_BYTEPTR(td->tmp_obmc_bufs[0]);
+    dst_buf1[0] = CONVERT_TO_BYTEPTR(xd->tmp_obmc_bufs[0]);
     dst_buf1[1] =
-        CONVERT_TO_BYTEPTR(td->tmp_obmc_bufs[0] + MAX_SB_SQUARE * len);
+        CONVERT_TO_BYTEPTR(xd->tmp_obmc_bufs[0] + MAX_SB_SQUARE * len);
     dst_buf1[2] =
-        CONVERT_TO_BYTEPTR(td->tmp_obmc_bufs[0] + MAX_SB_SQUARE * 2 * len);
-    dst_buf2[0] = CONVERT_TO_BYTEPTR(td->tmp_obmc_bufs[1]);
+        CONVERT_TO_BYTEPTR(xd->tmp_obmc_bufs[0] + MAX_SB_SQUARE * 2 * len);
+    dst_buf2[0] = CONVERT_TO_BYTEPTR(xd->tmp_obmc_bufs[1]);
     dst_buf2[1] =
-        CONVERT_TO_BYTEPTR(td->tmp_obmc_bufs[1] + MAX_SB_SQUARE * len);
+        CONVERT_TO_BYTEPTR(xd->tmp_obmc_bufs[1] + MAX_SB_SQUARE * len);
     dst_buf2[2] =
-        CONVERT_TO_BYTEPTR(td->tmp_obmc_bufs[1] + MAX_SB_SQUARE * 2 * len);
+        CONVERT_TO_BYTEPTR(xd->tmp_obmc_bufs[1] + MAX_SB_SQUARE * 2 * len);
   } else {
-    dst_buf1[0] = td->tmp_obmc_bufs[0];
-    dst_buf1[1] = td->tmp_obmc_bufs[0] + MAX_SB_SQUARE;
-    dst_buf1[2] = td->tmp_obmc_bufs[0] + MAX_SB_SQUARE * 2;
-    dst_buf2[0] = td->tmp_obmc_bufs[1];
-    dst_buf2[1] = td->tmp_obmc_bufs[1] + MAX_SB_SQUARE;
-    dst_buf2[2] = td->tmp_obmc_bufs[1] + MAX_SB_SQUARE * 2;
+    dst_buf1[0] = xd->tmp_obmc_bufs[0];
+    dst_buf1[1] = xd->tmp_obmc_bufs[0] + MAX_SB_SQUARE;
+    dst_buf1[2] = xd->tmp_obmc_bufs[0] + MAX_SB_SQUARE * 2;
+    dst_buf2[0] = xd->tmp_obmc_bufs[1];
+    dst_buf2[1] = xd->tmp_obmc_bufs[1] + MAX_SB_SQUARE;
+    dst_buf2[2] = xd->tmp_obmc_bufs[1] + MAX_SB_SQUARE * 2;
   }
-  dec_build_prediction_by_above_preds(cm, td, xd, mi_row, mi_col, dst_buf1,
+  dec_build_prediction_by_above_preds(cm, xd, mi_row, mi_col, dst_buf1,
                                       dst_width1, dst_height1, dst_stride1);
-  dec_build_prediction_by_left_preds(cm, td, xd, mi_row, mi_col, dst_buf2,
+  dec_build_prediction_by_left_preds(cm, xd, mi_row, mi_col, dst_buf2,
                                      dst_width2, dst_height2, dst_stride2);
   av1_setup_dst_planes(xd->plane, xd->mi[0]->sb_type, get_frame_new_buffer(cm),
                        mi_row, mi_col, 0, num_planes);
@@ -1055,9 +1047,8 @@
   }
 }
 
-static void predict_inter_block(AV1_COMMON *const cm, const ThreadData *td,
-                                MACROBLOCKD *const xd, int mi_row, int mi_col,
-                                BLOCK_SIZE bsize) {
+static void predict_inter_block(AV1_COMMON *const cm, MACROBLOCKD *const xd,
+                                int mi_row, int mi_col, BLOCK_SIZE bsize) {
   MB_MODE_INFO *mbmi = xd->mi[0];
   const int num_planes = av1_num_planes(cm);
   for (int ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
@@ -1075,9 +1066,9 @@
     }
   }
 
-  dec_build_inter_predictors_sb(cm, td, xd, mi_row, mi_col, NULL, bsize);
+  dec_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, bsize);
   if (mbmi->motion_mode == OBMC_CAUSAL) {
-    dec_build_obmc_inter_predictors_sb(cm, td, xd, mi_row, mi_col);
+    dec_build_obmc_inter_predictors_sb(cm, xd, mi_row, mi_col);
   }
 #if CONFIG_MISMATCH_DEBUG
   for (int plane = 0; plane < num_planes; ++plane) {
@@ -1164,7 +1155,7 @@
       }
     }
   } else {
-    td->predict_inter_block_visit(cm, td, xd, mi_row, mi_col, bsize);
+    td->predict_inter_block_visit(cm, xd, mi_row, mi_col, bsize);
     // Reconstruction
     if (!mbmi->skip) {
       int eobtotal = 0;
@@ -2923,6 +2914,11 @@
   td->xd.corrupted = 0;
   td->xd.mc_buf[0] = td->mc_buf[0];
   td->xd.mc_buf[1] = td->mc_buf[1];
+  td->xd.tmp_conv_dst = td->tmp_conv_dst;
+  for (int j = 0; j < 2; ++j) {
+    td->xd.tmp_obmc_bufs[j] = td->tmp_obmc_bufs[j];
+  }
+
   for (tile_row = tile_rows_start; tile_row < tile_rows_end; ++tile_row) {
     const int row = inv_row_order ? tile_rows - 1 - tile_row : tile_row;
 
@@ -3417,6 +3413,10 @@
     thread_data->td->xd.corrupted = 0;
     thread_data->td->xd.mc_buf[0] = thread_data->td->mc_buf[0];
     thread_data->td->xd.mc_buf[1] = thread_data->td->mc_buf[1];
+    thread_data->td->xd.tmp_conv_dst = thread_data->td->tmp_conv_dst;
+    for (int j = 0; j < 2; ++j) {
+      thread_data->td->xd.tmp_obmc_bufs[j] = thread_data->td->tmp_obmc_bufs[j];
+    }
     winterface->sync(worker);
 
     worker->hook = worker_hook;