Offset sub8x8 chroma component buffer pointers

Offset the buffer pointers of sub8x8 chroma components to support
the coding process at bottom right 8x8 block.

Change-Id: Ide17ee31ce064484371194cbbade88603d114a2e
diff --git a/av1/common/av1_loopfilter.c b/av1/common/av1_loopfilter.c
index 102a027..3f3b9b0 100644
--- a/av1/common/av1_loopfilter.c
+++ b/av1/common/av1_loopfilter.c
@@ -2198,7 +2198,7 @@
     for (mi_col = 0; mi_col < cm->mi_cols; mi_col += cm->mib_size) {
       int plane;
 
-      av1_setup_dst_planes(planes, frame_buffer, mi_row, mi_col);
+      av1_setup_dst_planes(planes, cm->sb_size, frame_buffer, mi_row, mi_col);
 
       for (plane = 0; plane < num_planes; ++plane) {
         av1_filter_block_plane_non420_ver(cm, &planes[plane], mi + mi_col,
diff --git a/av1/common/cdef.c b/av1/common/cdef.c
index 70ad766..53dff98 100644
--- a/av1/common/cdef.c
+++ b/av1/common/cdef.c
@@ -188,7 +188,7 @@
       xd->plane[2].subsampling_x == xd->plane[2].subsampling_y;
   nvsb = (cm->mi_rows + MAX_MIB_SIZE - 1) / MAX_MIB_SIZE;
   nhsb = (cm->mi_cols + MAX_MIB_SIZE - 1) / MAX_MIB_SIZE;
-  av1_setup_dst_planes(xd->plane, frame, 0, 0);
+  av1_setup_dst_planes(xd->plane, cm->sb_size, frame, 0, 0);
   row_dering = aom_malloc(sizeof(*row_dering) * (nhsb + 2) * 2);
   memset(row_dering, 1, sizeof(*row_dering) * (nhsb + 2) * 2);
   prev_row_dering = row_dering + 1;
diff --git a/av1/common/onyxc_int.h b/av1/common/onyxc_int.h
index 53a3800..69c4879 100644
--- a/av1/common/onyxc_int.h
+++ b/av1/common/onyxc_int.h
@@ -574,11 +574,18 @@
 }
 
 static INLINE void set_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col) {
-  const int above_idx = mi_col * 2;
-  const int left_idx = (mi_row * 2) & MAX_MIB_MASK_2;
   int i;
   for (i = 0; i < MAX_MB_PLANE; ++i) {
     struct macroblockd_plane *const pd = &xd->plane[i];
+#if CONFIG_CHROMA_SUB8X8
+    if (xd->mi[0]->mbmi.sb_type < BLOCK_8X8) {
+      // Offset the buffer pointer
+      if (pd->subsampling_y && (mi_row & 0x01)) mi_row -= 1;
+      if (pd->subsampling_x && (mi_col & 0x01)) mi_col -= 1;
+    }
+#endif
+    int above_idx = mi_col * 2;
+    int left_idx = (mi_row * 2) & MAX_MIB_MASK_2;
     pd->above_context = &xd->above_context[i][above_idx >> pd->subsampling_x];
     pd->left_context = &xd->left_context[i][left_idx >> pd->subsampling_y];
   }
diff --git a/av1/common/reconinter.c b/av1/common/reconinter.c
index 906c9be..82480be 100644
--- a/av1/common/reconinter.c
+++ b/av1/common/reconinter.c
@@ -1340,8 +1340,8 @@
 }
 
 void av1_setup_dst_planes(struct macroblockd_plane planes[MAX_MB_PLANE],
-                          const YV12_BUFFER_CONFIG *src, int mi_row,
-                          int mi_col) {
+                          BLOCK_SIZE bsize, const YV12_BUFFER_CONFIG *src,
+                          int mi_row, int mi_col) {
   uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
                                            src->v_buffer };
   const int widths[MAX_MB_PLANE] = { src->y_crop_width, src->uv_crop_width,
@@ -1354,8 +1354,8 @@
 
   for (i = 0; i < MAX_MB_PLANE; ++i) {
     struct macroblockd_plane *const pd = &planes[i];
-    setup_pred_plane(&pd->dst, buffers[i], widths[i], heights[i], strides[i],
-                     mi_row, mi_col, NULL, pd->subsampling_x,
+    setup_pred_plane(&pd->dst, bsize, buffers[i], widths[i], heights[i],
+                     strides[i], mi_row, mi_col, NULL, pd->subsampling_x,
                      pd->subsampling_y);
   }
 }
@@ -1375,9 +1375,9 @@
                                         src->uv_stride };
     for (i = 0; i < MAX_MB_PLANE; ++i) {
       struct macroblockd_plane *const pd = &xd->plane[i];
-      setup_pred_plane(&pd->pre[idx], buffers[i], widths[i], heights[i],
-                       strides[i], mi_row, mi_col, sf, pd->subsampling_x,
-                       pd->subsampling_y);
+      setup_pred_plane(&pd->pre[idx], xd->mi[0]->mbmi.sb_type, buffers[i],
+                       widths[i], heights[i], strides[i], mi_row, mi_col, sf,
+                       pd->subsampling_x, pd->subsampling_y);
     }
   }
 }
@@ -1923,9 +1923,9 @@
 
     for (j = 0; j < MAX_MB_PLANE; ++j) {
       struct macroblockd_plane *const pd = &xd->plane[j];
-      setup_pred_plane(&pd->dst, tmp_buf[j], tmp_width[j], tmp_height[j],
-                       tmp_stride[j], 0, i, NULL, pd->subsampling_x,
-                       pd->subsampling_y);
+      setup_pred_plane(&pd->dst, AOMMAX(a_bsize, BLOCK_8X8), tmp_buf[j],
+                       tmp_width[j], tmp_height[j], tmp_stride[j], 0, i, NULL,
+                       pd->subsampling_x, pd->subsampling_y);
     }
     for (ref = 0; ref < 1 + has_second_ref(above_mbmi); ++ref) {
       const MV_REFERENCE_FRAME frame = above_mbmi->ref_frame[ref];
@@ -2004,9 +2004,9 @@
 
     for (j = 0; j < MAX_MB_PLANE; ++j) {
       struct macroblockd_plane *const pd = &xd->plane[j];
-      setup_pred_plane(&pd->dst, tmp_buf[j], tmp_width[j], tmp_height[j],
-                       tmp_stride[j], i, 0, NULL, pd->subsampling_x,
-                       pd->subsampling_y);
+      setup_pred_plane(&pd->dst, AOMMAX(l_bsize, BLOCK_8X8), tmp_buf[j],
+                       tmp_width[j], tmp_height[j], tmp_stride[j], i, 0, NULL,
+                       pd->subsampling_x, pd->subsampling_y);
     }
     for (ref = 0; ref < 1 + has_second_ref(left_mbmi); ++ref) {
       const MV_REFERENCE_FRAME frame = left_mbmi->ref_frame[ref];
@@ -2088,7 +2088,8 @@
                                       dst_width1, dst_height1, dst_stride1);
   av1_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, get_frame_new_buffer(cm), mi_row, mi_col);
+  av1_setup_dst_planes(xd->plane, xd->mi[0]->mbmi.sb_type,
+                       get_frame_new_buffer(cm), mi_row, mi_col);
   av1_build_obmc_inter_prediction(cm, xd, mi_row, mi_col, dst_buf1, dst_stride1,
                                   dst_buf2, dst_stride2);
 }
@@ -2133,9 +2134,10 @@
 
     for (j = 0; j < MAX_MB_PLANE; ++j) {
       struct macroblockd_plane *const pd = &xd->plane[j];
-      setup_pred_plane(&pd->dst, tmp_buf[j], tmp_width[j], tmp_height[j],
-                       tmp_stride[j], (xd->n8_h >> 1), i, NULL,
-                       pd->subsampling_x, pd->subsampling_y);
+      setup_pred_plane(&pd->dst, AOMMAX(mbmi->sb_type, BLOCK_8X8), tmp_buf[j],
+                       tmp_width[j], tmp_height[j], tmp_stride[j],
+                       (xd->n8_h >> 1), i, NULL, pd->subsampling_x,
+                       pd->subsampling_y);
     }
     for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
       const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
@@ -2240,8 +2242,9 @@
 
     for (j = 0; j < MAX_MB_PLANE; ++j) {
       struct macroblockd_plane *const pd = &xd->plane[j];
-      setup_pred_plane(&pd->dst, tmp_buf[j], tmp_width[j], tmp_height[j],
-                       tmp_stride[j], i, xd->n8_w >> 1, NULL, pd->subsampling_x,
+      setup_pred_plane(&pd->dst, AOMMAX(mbmi->sb_type, BLOCK_8X8), tmp_buf[j],
+                       tmp_width[j], tmp_height[j], tmp_stride[j], i,
+                       xd->n8_w >> 1, NULL, pd->subsampling_x,
                        pd->subsampling_y);
     }
     for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
@@ -2458,16 +2461,20 @@
   }
 #endif  // CONFIG_HIGHBITDEPTH
 
+  const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
   av1_build_prediction_by_bottom_preds(cm, xd, mi_row, mi_col, dst_buf1,
                                        dst_width1, dst_height1, dst_stride1);
   av1_build_prediction_by_right_preds(cm, xd, mi_row, mi_col, dst_buf2,
                                       dst_width2, dst_height2, dst_stride2);
-  av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
+  av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
+                       mi_col);
   av1_merge_dst_bottom_right_preds(cm, xd, mi_row, mi_col, dst_buf1,
                                    dst_stride1, dst_buf2, dst_stride2);
-  av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
+  av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
+                       mi_col);
   av1_build_obmc_inter_predictors_sb(cm, xd, mi_row, mi_col);
-  av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
+  av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
+                       mi_col);
 }
 #endif  // CONFIG_NCOBMC
 #endif  // CONFIG_MOTION_VAR
diff --git a/av1/common/reconinter.h b/av1/common/reconinter.h
index e4b7c72..d59ad03 100644
--- a/av1/common/reconinter.h
+++ b/av1/common/reconinter.h
@@ -599,11 +599,21 @@
   return y * stride + x;
 }
 
-static INLINE void setup_pred_plane(struct buf_2d *dst, uint8_t *src, int width,
-                                    int height, int stride, int mi_row,
-                                    int mi_col,
+static INLINE void setup_pred_plane(struct buf_2d *dst, BLOCK_SIZE bsize,
+                                    uint8_t *src, int width, int height,
+                                    int stride, int mi_row, int mi_col,
                                     const struct scale_factors *scale,
                                     int subsampling_x, int subsampling_y) {
+#if CONFIG_CHROMA_SUB8X8
+  if (bsize < BLOCK_8X8) {
+    // Offset the buffer pointer
+    if (subsampling_y && (mi_row & 0x01)) mi_row -= 1;
+    if (subsampling_x && (mi_col & 0x01)) mi_col -= 1;
+  }
+#else
+  (void)bsize;
+#endif
+
   const int x = (MI_SIZE * mi_col) >> subsampling_x;
   const int y = (MI_SIZE * mi_row) >> subsampling_y;
   dst->buf = src + scaled_buffer_offset(x, y, stride, scale);
@@ -614,8 +624,8 @@
 }
 
 void av1_setup_dst_planes(struct macroblockd_plane planes[MAX_MB_PLANE],
-                          const YV12_BUFFER_CONFIG *src, int mi_row,
-                          int mi_col);
+                          BLOCK_SIZE bsize, const YV12_BUFFER_CONFIG *src,
+                          int mi_row, int mi_col);
 
 void av1_setup_pre_planes(MACROBLOCKD *xd, int idx,
                           const YV12_BUFFER_CONFIG *src, int mi_row, int mi_col,
diff --git a/av1/common/thread_common.c b/av1/common/thread_common.c
index 6090e55..ca8b1b3 100644
--- a/av1/common/thread_common.c
+++ b/av1/common/thread_common.c
@@ -160,8 +160,8 @@
       LOOP_FILTER_MASK lfm;
       int plane;
 
-      av1_setup_dst_planes(lf_data->planes, lf_data->frame_buffer, mi_row,
-                           mi_col);
+      av1_setup_dst_planes(lf_data->planes, lf_data->cm->sb_size,
+                           lf_data->frame_buffer, mi_row, mi_col);
       av1_setup_mask(lf_data->cm, mi_row, mi_col, mi + mi_col,
                      lf_data->cm->mi_stride, &lfm);
 
@@ -206,8 +206,8 @@
       // the outer loop to column-based and remove the synchronizations here.
       sync_read(lf_sync, r, c);
 
-      av1_setup_dst_planes(lf_data->planes, lf_data->frame_buffer, mi_row,
-                           mi_col);
+      av1_setup_dst_planes(lf_data->planes, lf_data->cm->sb_size,
+                           lf_data->frame_buffer, mi_row, mi_col);
       av1_setup_mask(lf_data->cm, mi_row, mi_col, mi + mi_col,
                      lf_data->cm->mi_stride, &lfm);
 #if CONFIG_EXT_PARTITION_TYPES
@@ -258,8 +258,8 @@
 
       sync_read(lf_sync, r, c);
 
-      av1_setup_dst_planes(lf_data->planes, lf_data->frame_buffer, mi_row,
-                           mi_col);
+      av1_setup_dst_planes(lf_data->planes, lf_data->cm->sb_size,
+                           lf_data->frame_buffer, mi_row, mi_col);
 #if CONFIG_EXT_PARTITION_TYPES
       for (plane = 0; plane < num_planes; ++plane) {
         av1_filter_block_plane_non420_ver(lf_data->cm, &lf_data->planes[plane],
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 6fdf6ab..6455c5f 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -726,7 +726,8 @@
 #endif  // CONFIG_DEPENDENT_HORZTILES
                  cm->mi_rows, cm->mi_cols);
 
-  av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
+  av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
+                       mi_col);
 }
 
 #if CONFIG_SUPERTX
@@ -799,7 +800,8 @@
 #endif  // CONFIG_DEPENDENT_HORZTILES
                  cm->mi_rows, cm->mi_cols);
 
-  av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
+  av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
+                       mi_col);
 }
 
 static void set_param_topblock(AV1_COMMON *const cm, MACROBLOCKD *const xd,
@@ -2304,7 +2306,8 @@
 #endif  // CONFIG_EXT_TX
     }
 
-    av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
+    av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
+                         mi_col);
     for (i = 0; i < MAX_MB_PLANE; i++) {
       dst_buf[i] = xd->plane[i].dst.buf;
       dst_stride[i] = xd->plane[i].dst.stride;
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 2f345d1..cac1aaf 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -285,7 +285,8 @@
 #endif
 
   // Set up destination pointers.
-  av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
+  av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
+                       mi_col);
 
   // Set up limit values for MV components.
   // Mv beyond the range do not produce new/different prediction block.
@@ -1829,8 +1830,8 @@
   x->e_mbd.cur_buf = src;
 
   for (i = 0; i < MAX_MB_PLANE; i++)
-    setup_pred_plane(&x->plane[i].src, buffers[i], widths[i], heights[i],
-                     strides[i], mi_row, mi_col, NULL,
+    setup_pred_plane(&x->plane[i].src, x->e_mbd.mi[0]->mbmi.sb_type, buffers[i],
+                     widths[i], heights[i], strides[i], mi_row, mi_col, NULL,
                      x->e_mbd.plane[i].subsampling_x,
                      x->e_mbd.plane[i].subsampling_y);
 }
@@ -2473,8 +2474,8 @@
   check_ncobmc = is_inter_block(mbmi) && motion_allowed >= OBMC_CAUSAL;
   if (!dry_run && check_ncobmc) {
     av1_check_ncobmc_rd(cpi, x, mi_row, mi_col);
-    av1_setup_dst_planes(x->e_mbd.plane, get_frame_new_buffer(&cpi->common),
-                         mi_row, mi_col);
+    av1_setup_dst_planes(x->e_mbd.plane, bsize,
+                         get_frame_new_buffer(&cpi->common), mi_row, mi_col);
   }
 #endif
   encode_superblock(cpi, td, tp, dry_run, mi_row, mi_col, bsize, ctx, rate);
@@ -2539,7 +2540,8 @@
       update_state_sb_supertx(cpi, td, tile, mi_row, mi_col, bsize, dry_run,
                               pc_tree);
 
-      av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
+      av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
+                           mi_col);
       for (i = 0; i < MAX_MB_PLANE; i++) {
         dst_buf[i] = xd->plane[i].dst.buf;
         dst_stride[i] = xd->plane[i].dst.stride;
@@ -7009,7 +7011,8 @@
   set_skip_context(xd, mi_row, mi_col);
   set_mode_info_offsets(cpi, x, xd, mi_row, mi_col);
   update_state_sb_supertx(cpi, td, tile, mi_row, mi_col, bsize, 1, pc_tree);
-  av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
+  av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
+                       mi_col);
   for (plane = 0; plane < MAX_MB_PLANE; plane++) {
     dst_buf[plane] = xd->plane[plane].dst.buf;
     dst_stride[plane] = xd->plane[plane].dst.stride;
diff --git a/av1/encoder/firstpass.c b/av1/encoder/firstpass.c
index 4d3425f..e35a54e 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -518,6 +518,10 @@
 
   aom_clear_system_state();
 
+  xd->mi = cm->mi_grid_visible;
+  xd->mi[0] = cm->mi;
+  x->e_mbd.mi[0]->mbmi.sb_type = BLOCK_16X16;
+
   intra_factor = 0.0;
   brightness_factor = 0.0;
   neutral_count = 0.0;
@@ -528,7 +532,7 @@
   av1_setup_block_planes(&x->e_mbd, cm->subsampling_x, cm->subsampling_y);
 
   av1_setup_src_planes(x, cpi->source, 0, 0);
-  av1_setup_dst_planes(xd->plane, new_yv12, 0, 0);
+  av1_setup_dst_planes(xd->plane, cm->sb_size, new_yv12, 0, 0);
 
   if (!frame_is_intra_only(cm)) {
     av1_setup_pre_planes(xd, 0, first_ref_buf, 0, 0, NULL);
diff --git a/av1/encoder/mcomp.c b/av1/encoder/mcomp.c
index ae8f04e..d069eef 100644
--- a/av1/encoder/mcomp.c
+++ b/av1/encoder/mcomp.c
@@ -2573,10 +2573,11 @@
   if (use_upsampled_ref) {
     int ref = xd->mi[0]->mbmi.ref_frame[is_second];
     const YV12_BUFFER_CONFIG *upsampled_ref = get_upsampled_ref(cpi, ref);
-    setup_pred_plane(&pd->pre[is_second], upsampled_ref->y_buffer,
-                     upsampled_ref->y_crop_width, upsampled_ref->y_crop_height,
-                     upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3),
-                     NULL, pd->subsampling_x, pd->subsampling_y);
+    setup_pred_plane(&pd->pre[is_second], mbmi->sb_type,
+                     upsampled_ref->y_buffer, upsampled_ref->y_crop_width,
+                     upsampled_ref->y_crop_height, upsampled_ref->y_stride,
+                     (mi_row << 3), (mi_col << 3), NULL, pd->subsampling_x,
+                     pd->subsampling_y);
   }
   y = pd->pre[is_second].buf;
   y_stride = pd->pre[is_second].stride;
@@ -3073,10 +3074,11 @@
   if (use_upsampled_ref) {
     int ref = xd->mi[0]->mbmi.ref_frame[is_second];
     const YV12_BUFFER_CONFIG *upsampled_ref = get_upsampled_ref(cpi, ref);
-    setup_pred_plane(&pd->pre[is_second], upsampled_ref->y_buffer,
-                     upsampled_ref->y_crop_width, upsampled_ref->y_crop_height,
-                     upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3),
-                     NULL, pd->subsampling_x, pd->subsampling_y);
+    setup_pred_plane(&pd->pre[is_second], mbmi->sb_type,
+                     upsampled_ref->y_buffer, upsampled_ref->y_crop_width,
+                     upsampled_ref->y_crop_height, upsampled_ref->y_stride,
+                     (mi_row << 3), (mi_col << 3), NULL, pd->subsampling_x,
+                     pd->subsampling_y);
   }
   y = pd->pre[is_second].buf;
   y_stride = pd->pre[is_second].stride;
diff --git a/av1/encoder/pickcdef.c b/av1/encoder/pickcdef.c
index bafc554..da64fb4 100644
--- a/av1/encoder/pickcdef.c
+++ b/av1/encoder/pickcdef.c
@@ -312,7 +312,7 @@
       av1_ac_quant(cm->base_qindex, 0, cm->bit_depth) >> (cm->bit_depth - 8);
   lambda = .12 * quantizer * quantizer / 256.;
 
-  av1_setup_dst_planes(xd->plane, frame, 0, 0);
+  av1_setup_dst_planes(xd->plane, cm->sb_size, frame, 0, 0);
   mse[0] = aom_malloc(sizeof(**mse) * nvsb * nhsb);
   mse[1] = aom_malloc(sizeof(**mse) * nvsb * nhsb);
   for (pli = 0; pli < nplanes; pli++) {
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 0663ed8..f06e569 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -799,7 +799,7 @@
   dst[1].stride = dst[2].stride = src->uv_stride;
 
   for (i = 0; i < MAX_MB_PLANE; ++i) {
-    setup_pred_plane(dst + i, dst[i].buf,
+    setup_pred_plane(dst + i, xd->mi[0]->mbmi.sb_type, dst[i].buf,
                      i ? src->uv_crop_width : src->y_crop_width,
                      i ? src->uv_crop_height : src->y_crop_height,
                      dst[i].stride, mi_row, mi_col, i ? scale_uv : scale,
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index ff05537..5c69d9f 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -5658,7 +5658,7 @@
             get_upsampled_ref(cpi, refs[id]);
 
         // Set pred for Y plane
-        setup_pred_plane(&pd->pre[0], upsampled_ref->y_buffer,
+        setup_pred_plane(&pd->pre[0], bsize, upsampled_ref->y_buffer,
                          upsampled_ref->y_crop_width,
                          upsampled_ref->y_crop_height, upsampled_ref->y_stride,
                          (mi_row << 3), (mi_col << 3), NULL, pd->subsampling_x,
@@ -6102,7 +6102,7 @@
 
               // Set pred for Y plane
               setup_pred_plane(
-                  &pd->pre[0], upsampled_ref->y_buffer,
+                  &pd->pre[0], bsize, upsampled_ref->y_buffer,
                   upsampled_ref->y_crop_width, upsampled_ref->y_crop_height,
                   upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3), NULL,
                   pd->subsampling_x, pd->subsampling_y);
@@ -7025,7 +7025,7 @@
 
           // Set pred for Y plane
           setup_pred_plane(
-              &pd->pre[ref_idx], upsampled_ref->y_buffer,
+              &pd->pre[ref_idx], bsize, upsampled_ref->y_buffer,
               upsampled_ref->y_crop_width, upsampled_ref->y_crop_height,
               upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3), NULL,
               pd->subsampling_x, pd->subsampling_y);
@@ -9840,7 +9840,8 @@
     av1_build_prediction_by_left_preds(cm, xd, mi_row, mi_col,
                                        args.left_pred_buf, dst_width2,
                                        dst_height2, args.left_pred_stride);
-    av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
+    av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
+                         mi_col);
     x->mask_buf = mask2d_buf;
     x->wsrc_buf = weighted_src_buf;
     calc_target_weighted_pred(cm, x, xd, mi_row, mi_col, args.above_pred_buf[0],
@@ -12656,8 +12657,8 @@
     av1_setup_pre_planes(xd, ref, cfg, mi_row, mi_col,
                          &xd->block_refs[ref]->sf);
   }
-  av1_setup_dst_planes(x->e_mbd.plane, get_frame_new_buffer(&cpi->common),
-                       mi_row, mi_col);
+  av1_setup_dst_planes(x->e_mbd.plane, bsize,
+                       get_frame_new_buffer(&cpi->common), mi_row, mi_col);
 
   av1_build_inter_predictors_sb(xd, mi_row, mi_col, NULL, bsize);