Change gm_get_motion_vector

Since gm_get_motion_vector is trying to give a motion vector for
"the frame as a whole", it makes more sense for it to calculate
the motion of the *center* of the block rather than the top-left
corner of the frame.

In theory, this change should also help the encoder make better
decisions on when to use global motion. It avoids an issue
where, early in the frame, NEARESTMV looks like a good way to use
the global motion vector *without* paying the rate cost applied
to the first few global motion blocks in each frame. This seems
to lead to a better overall result.

Change-Id: Ia5c6259ceb8b4ff3d00a5d553e1d18bdb802da59
diff --git a/av1/common/mv.h b/av1/common/mv.h
index c7fb424..2b50c61 100644
--- a/av1/common/mv.h
+++ b/av1/common/mv.h
@@ -149,18 +149,27 @@
 // Convert a global motion translation vector (which may have more bits than a
 // regular motion vector) into a motion vector
 static INLINE int_mv gm_get_motion_vector(const WarpedMotionParams *gm,
-                                          int allow_hp) {
+                                          int allow_hp, int x, int y) {
   int_mv res;
-  res.as_mv.row = allow_hp ? (int16_t)ROUND_POWER_OF_TWO_SIGNED(
-                                 gm->wmmat[1], WARPEDMODEL_PREC_BITS - 3)
-                           : (int16_t)ROUND_POWER_OF_TWO_SIGNED(
-                                 gm->wmmat[1], WARPEDMODEL_PREC_BITS - 2) *
-                                 2;
-  res.as_mv.col = allow_hp ? (int16_t)ROUND_POWER_OF_TWO_SIGNED(
-                                 gm->wmmat[0], WARPEDMODEL_PREC_BITS - 3)
-                           : (int16_t)ROUND_POWER_OF_TWO_SIGNED(
-                                 gm->wmmat[0], WARPEDMODEL_PREC_BITS - 2) *
-                                 2;
+  const int32_t *mat = gm->wmmat;
+  // Project the center point of the frame and use that to derive the
+  // motion vector. Assume the model is an AFFINE or ROTZOOM model
+  int xc, yc;
+  int shift = allow_hp ? WARPEDMODEL_PREC_BITS - 3 : WARPEDMODEL_PREC_BITS - 2;
+  int scale = allow_hp ? 0 : 1;
+
+  if (gm->wmtype == ROTZOOM) {
+    assert(gm->wmmat[5] == gm->wmmat[2]);
+    assert(gm->wmmat[4] == -gm->wmmat[3]);
+  }
+  xc = mat[2] * x + mat[3] * y + mat[0];
+  yc = mat[4] * x + mat[5] * y + mat[1];
+
+  int tx = (ROUND_POWER_OF_TWO_SIGNED(xc, shift) << scale) - (x << 3);
+  int ty = (ROUND_POWER_OF_TWO_SIGNED(yc, shift) << scale) - (y << 3);
+
+  res.as_mv.row = ty;
+  res.as_mv.col = tx;
   return res;
 }
 
diff --git a/av1/common/mvref_common.c b/av1/common/mvref_common.c
index 39a8cb4..defeb96 100644
--- a/av1/common/mvref_common.c
+++ b/av1/common/mvref_common.c
@@ -891,16 +891,22 @@
 #if CONFIG_REF_MV
   av1_set_ref_frame(rf, ref_frame);
   zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[rf[0]],
-                                          cm->allow_high_precision_mv)
+                                          cm->allow_high_precision_mv,
+                                          mi_col * MI_SIZE + MI_SIZE / 2,
+                                          mi_row * MI_SIZE + MI_SIZE / 2)
                          .as_int;
   zeromv[1].as_int = (rf[1] != NONE_FRAME)
                          ? gm_get_motion_vector(&cm->global_motion[rf[1]],
-                                                cm->allow_high_precision_mv)
+                                                cm->allow_high_precision_mv,
+                                                mi_col * MI_SIZE + MI_SIZE / 2,
+                                                mi_row * MI_SIZE + MI_SIZE / 2)
                                .as_int
                          : 0;
 #else
   zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame],
-                                          cm->allow_high_precision_mv)
+                                          cm->allow_high_precision_mv,
+                                          mi_col * MI_SIZE + MI_SIZE / 2,
+                                          mi_row * MI_SIZE + MI_SIZE / 2)
                          .as_int;
   zeromv[1].as_int = 0;
 #endif  // CONFIG_REF_MV
@@ -987,7 +993,9 @@
 
 #if CONFIG_GLOBAL_MOTION
   zeromv.as_int =
-      gm_get_motion_vector(&cm->global_motion[ref], cm->allow_high_precision_mv)
+      gm_get_motion_vector(&cm->global_motion[ref], cm->allow_high_precision_mv,
+                           mi_col * MI_SIZE + MI_SIZE / 2,
+                           mi_row * MI_SIZE + MI_SIZE / 2)
           .as_int;
 #else
   zeromv.as_int = 0;
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index 39cb2cc..fc21bc4 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -1271,8 +1271,9 @@
                             PREDICTION_MODE mode,
                             MV_REFERENCE_FRAME ref_frame[2], int block,
                             int_mv mv[2], int_mv ref_mv[2],
-                            int_mv nearest_mv[2], int_mv near_mv[2],
-                            int is_compound, int allow_hp, aom_reader *r) {
+                            int_mv nearest_mv[2], int_mv near_mv[2], int mi_row,
+                            int mi_col, int is_compound, int allow_hp,
+                            aom_reader *r) {
   int i;
   int ret = 1;
 #if CONFIG_EC_ADAPT
@@ -1295,6 +1296,8 @@
 #endif  // CONFIG_REF_MV
   (void)ref_frame;
   (void)cm;
+  (void)mi_row;
+  (void)mi_col;
 
   switch (mode) {
 #if CONFIG_EXT_INTER
@@ -1350,11 +1353,15 @@
     case ZEROMV: {
 #if CONFIG_GLOBAL_MOTION
       mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]],
-                                          cm->allow_high_precision_mv)
+                                          cm->allow_high_precision_mv,
+                                          mi_col * MI_SIZE + MI_SIZE / 2,
+                                          mi_row * MI_SIZE + MI_SIZE / 2)
                          .as_int;
       if (is_compound)
         mv[1].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[1]],
-                                            cm->allow_high_precision_mv)
+                                            cm->allow_high_precision_mv,
+                                            mi_col * MI_SIZE + MI_SIZE / 2,
+                                            mi_row * MI_SIZE + MI_SIZE / 2)
                            .as_int;
 #else
       mv[0].as_int = 0;
@@ -1503,10 +1510,14 @@
       assert(is_compound);
 #if CONFIG_GLOBAL_MOTION
       mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]],
-                                          cm->allow_high_precision_mv)
+                                          cm->allow_high_precision_mv,
+                                          mi_col * MI_SIZE + MI_SIZE / 2,
+                                          mi_row * MI_SIZE + MI_SIZE / 2)
                          .as_int;
       mv[1].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[1]],
-                                          cm->allow_high_precision_mv)
+                                          cm->allow_high_precision_mv,
+                                          mi_col * MI_SIZE + MI_SIZE / 2,
+                                          mi_row * MI_SIZE + MI_SIZE / 2)
                          .as_int;
 #else
       mv[0].as_int = 0;
@@ -1613,13 +1624,18 @@
       av1_set_ref_frame(rf, ref_frame);
 #if CONFIG_GLOBAL_MOTION
       zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[rf[0]],
-                                              cm->allow_high_precision_mv)
+                                              cm->allow_high_precision_mv,
+                                              mi_col * MI_SIZE + MI_SIZE / 2,
+                                              mi_row * MI_SIZE + MI_SIZE / 2)
                              .as_int;
-      zeromv[1].as_int = (rf[1] != NONE_FRAME)
-                             ? gm_get_motion_vector(&cm->global_motion[rf[1]],
-                                                    cm->allow_high_precision_mv)
-                                   .as_int
-                             : 0;
+      zeromv[1].as_int =
+          (rf[1] != NONE_FRAME)
+              ? gm_get_motion_vector(&cm->global_motion[rf[1]],
+                                     cm->allow_high_precision_mv,
+                                     mi_col * MI_SIZE + MI_SIZE / 2,
+                                     mi_row * MI_SIZE + MI_SIZE / 2)
+                    .as_int
+              : 0;
 #else
       zeromv[0].as_int = zeromv[1].as_int = 0;
 #endif
@@ -1843,7 +1859,8 @@
 #else
                        ref_mv_s8,
 #endif  // CONFIG_EXT_INTER
-                       nearest_sub8x8, near_sub8x8, is_compound, allow_hp, r)) {
+                       nearest_sub8x8, near_sub8x8, mi_row, mi_col, is_compound,
+                       allow_hp, r)) {
           xd->corrupted |= 1;
           break;
         };
@@ -1892,7 +1909,7 @@
 #else
                    ref_mv,
 #endif  // CONFIG_EXT_INTER
-                   nearestmv, nearmv, is_compound, allow_hp, r);
+                   nearestmv, nearmv, mi_row, mi_col, is_compound, allow_hp, r);
   }
 
 #if CONFIG_EXT_INTER
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 6c9f9f6..d788276 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -1401,6 +1401,8 @@
 #else
   const int unify_bsize = 0;
 #endif
+  (void)mi_row;
+  (void)mi_col;
 
   if (seg->update_map) {
     if (seg->temporal_update) {
@@ -1792,6 +1794,8 @@
 #else
   const int unify_bsize = 0;
 #endif
+  (void)mi_row;
+  (void)mi_col;
 
 #if CONFIG_EC_ADAPT
   FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 545a95d..d67d749 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -1900,8 +1900,8 @@
   } else {
     if (bsize >= BLOCK_8X8 || unify_bsize) {
       if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
-        av1_rd_pick_inter_mode_sb_seg_skip(cpi, tile_data, x, rd_cost, bsize,
-                                           ctx, best_rd);
+        av1_rd_pick_inter_mode_sb_seg_skip(cpi, tile_data, x, mi_row, mi_col,
+                                           rd_cost, bsize, ctx, best_rd);
 #if CONFIG_SUPERTX
         *totalrate_nocoef = rd_cost->rate;
 #endif  // CONFIG_SUPERTX
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 6d341a7..54a3225 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -4976,7 +4976,8 @@
 #if CONFIG_EXT_INTER
     int_mv compound_seg_newmvs[2],
 #endif  // CONFIG_EXT_INTER
-    int_mv *best_ref_mv[2], const int *mvjcost, int *mvcost[2]) {
+    int_mv *best_ref_mv[2], const int *mvjcost, int *mvcost[2], int mi_row,
+    int mi_col) {
   MODE_INFO *const mic = xd->mi[0];
   const MB_MODE_INFO *const mbmi = &mic->mbmi;
   const MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
@@ -4986,6 +4987,8 @@
   const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type];
   const int is_compound = has_second_ref(mbmi);
   int mode_ctx;
+  (void)mi_row;
+  (void)mi_col;
 
   switch (mode) {
     case NEWMV:
@@ -5033,7 +5036,8 @@
         this_mv[ref].as_int =
             gm_get_motion_vector(
                 &cpi->common.global_motion[mbmi->ref_frame[ref]],
-                cpi->common.allow_high_precision_mv)
+                cpi->common.allow_high_precision_mv,
+                mi_col * MI_SIZE + MI_SIZE / 2, mi_row * MI_SIZE + MI_SIZE / 2)
                 .as_int;
         thismvcost += GLOBAL_MOTION_RATE(cpi, mbmi->ref_frame[ref]);
 #else
@@ -5090,11 +5094,15 @@
 #if CONFIG_GLOBAL_MOTION
       this_mv[0].as_int =
           gm_get_motion_vector(&cpi->common.global_motion[mbmi->ref_frame[0]],
-                               cpi->common.allow_high_precision_mv)
+                               cpi->common.allow_high_precision_mv,
+                               mi_col * MI_SIZE + MI_SIZE / 2,
+                               mi_row * MI_SIZE + MI_SIZE / 2)
               .as_int;
       this_mv[1].as_int =
           gm_get_motion_vector(&cpi->common.global_motion[mbmi->ref_frame[1]],
-                               cpi->common.allow_high_precision_mv)
+                               cpi->common.allow_high_precision_mv,
+                               mi_col * MI_SIZE + MI_SIZE / 2,
+                               mi_row * MI_SIZE + MI_SIZE / 2)
               .as_int;
       thismvcost += GLOBAL_MOTION_RATE(cpi, mbmi->ref_frame[0]) +
                     GLOBAL_MOTION_RATE(cpi, mbmi->ref_frame[1]);
@@ -5348,10 +5356,13 @@
     const int16_t compound_mode_context[TOTAL_REFS_PER_FRAME],
 #endif  // CONFIG_REF_MV && CONFIG_EXT_INTER
     int_mv frame_mv[MB_MODE_COUNT][TOTAL_REFS_PER_FRAME], int this_mode,
-    const MV_REFERENCE_FRAME ref_frames[2], const BLOCK_SIZE bsize, int block) {
+    const MV_REFERENCE_FRAME ref_frames[2], const BLOCK_SIZE bsize, int block,
+    int mi_row, int mi_col) {
   int_mv zeromv[2];
   int comp_pred_mode = ref_frames[1] > INTRA_FRAME;
   int cur_frm;
+  (void)mi_row;
+  (void)mi_col;
   for (cur_frm = 0; cur_frm < 1 + comp_pred_mode; cur_frm++) {
 #if CONFIG_GLOBAL_MOTION
     if (this_mode == ZEROMV
@@ -5361,7 +5372,9 @@
         )
       zeromv[cur_frm].as_int =
           gm_get_motion_vector(&cpi->common.global_motion[ref_frames[cur_frm]],
-                               cpi->common.allow_high_precision_mv)
+                               cpi->common.allow_high_precision_mv,
+                               mi_col * MI_SIZE + MI_SIZE / 2,
+                               mi_row * MI_SIZE + MI_SIZE / 2)
               .as_int;
     else
 #endif  // CONFIG_GLOBAL_MOTION
@@ -5821,8 +5834,9 @@
 #endif  // CONFIG_EXT_INTER
 #if CONFIG_GLOBAL_MOTION
         frame_mv[ZEROMV][frame].as_int =
-            gm_get_motion_vector(&cm->global_motion[frame],
-                                 cm->allow_high_precision_mv)
+            gm_get_motion_vector(
+                &cm->global_motion[frame], cm->allow_high_precision_mv,
+                mi_col * MI_SIZE + MI_SIZE / 2, mi_row * MI_SIZE + MI_SIZE / 2)
                 .as_int;
 #else   // CONFIG_GLOBAL_MOTION
         frame_mv[ZEROMV][frame].as_int = 0;
@@ -5854,7 +5868,9 @@
 #if CONFIG_GLOBAL_MOTION
           frame_mv[ZERO_ZEROMV][frame].as_int =
               gm_get_motion_vector(&cm->global_motion[frame],
-                                   cm->allow_high_precision_mv)
+                                   cm->allow_high_precision_mv,
+                                   mi_col * MI_SIZE + MI_SIZE / 2,
+                                   mi_row * MI_SIZE + MI_SIZE / 2)
                   .as_int;
 #else
           frame_mv[ZERO_ZEROMV][frame].as_int = 0;
@@ -5981,7 +5997,7 @@
                                   mbmi_ext->compound_mode_context,
 #endif  // CONFIG_REF_MV && CONFIG_EXT_INTER
                                   frame_mv, this_mode, mbmi->ref_frame, bsize,
-                                  index))
+                                  index, mi_row, mi_col))
             continue;
 
         memcpy(orig_pre, pd->pre, sizeof(orig_pre));
@@ -6240,7 +6256,7 @@
 #else
             seg_mvs[index],
 #endif  // CONFIG_EXT_INTER
-            bsi->ref_mv, x->nmvjointcost, x->mvcost);
+            bsi->ref_mv, x->nmvjointcost, x->mvcost, mi_row, mi_col);
 
         for (ref = 0; ref < 1 + has_second_rf; ++ref) {
           bsi->rdstat[index][mode_idx].mvs[ref].as_int =
@@ -6459,14 +6475,14 @@
       if (has_second_rf)
         bsi->ref_mv[1]->as_int = bsi->rdstat[index][mode_idx].ref_mv[1].as_int;
 #endif  // CONFIG_EXT_INTER
-      set_and_cost_bmi_mvs(cpi, x, xd, index, mode_selected,
-                           mode_mv[mode_selected], frame_mv,
+      set_and_cost_bmi_mvs(
+          cpi, x, xd, index, mode_selected, mode_mv[mode_selected], frame_mv,
 #if CONFIG_EXT_INTER
-                           seg_mvs[index][mv_idx], compound_seg_newmvs[index],
+          seg_mvs[index][mv_idx], compound_seg_newmvs[index],
 #else
-                           seg_mvs[index],
+          seg_mvs[index],
 #endif  // CONFIG_EXT_INTER
-                           bsi->ref_mv, x->nmvjointcost, x->mvcost);
+          bsi->ref_mv, x->nmvjointcost, x->mvcost, mi_row, mi_col);
 
       br += bsi->rdstat[index][mode_idx].brate;
       bd += bsi->rdstat[index][mode_idx].bdist;
@@ -9576,8 +9592,9 @@
     frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
 #if CONFIG_GLOBAL_MOTION
     frame_mv[ZEROMV][ref_frame].as_int =
-        gm_get_motion_vector(&cm->global_motion[ref_frame],
-                             cm->allow_high_precision_mv)
+        gm_get_motion_vector(
+            &cm->global_motion[ref_frame], cm->allow_high_precision_mv,
+            mi_col * MI_SIZE + MI_SIZE / 2, mi_row * MI_SIZE + MI_SIZE / 2)
             .as_int;
 #else   // CONFIG_GLOBAL_MOTION
     frame_mv[ZEROMV][ref_frame].as_int = 0;
@@ -9587,8 +9604,9 @@
     frame_mv[NEW_NEWMV][ref_frame].as_int = INVALID_MV;
 #if CONFIG_GLOBAL_MOTION
     frame_mv[ZERO_ZEROMV][ref_frame].as_int =
-        gm_get_motion_vector(&cm->global_motion[ref_frame],
-                             cm->allow_high_precision_mv)
+        gm_get_motion_vector(
+            &cm->global_motion[ref_frame], cm->allow_high_precision_mv,
+            mi_col * MI_SIZE + MI_SIZE / 2, mi_row * MI_SIZE + MI_SIZE / 2)
             .as_int;
 #else   // CONFIG_GLOBAL_MOTION
     frame_mv[ZERO_ZEROMV][ref_frame].as_int = 0;
@@ -9691,7 +9709,9 @@
       mode_skip_mask[ALTREF_FRAME] = ~INTER_NEAREST_NEAR_ZERO;
 #if CONFIG_GLOBAL_MOTION
       zeromv.as_int = gm_get_motion_vector(&cm->global_motion[ALTREF_FRAME],
-                                           cm->allow_high_precision_mv)
+                                           cm->allow_high_precision_mv,
+                                           mi_col * MI_SIZE + MI_SIZE / 2,
+                                           mi_row * MI_SIZE + MI_SIZE / 2)
                           .as_int;
 #else
       zeromv.as_int = 0;
@@ -9942,7 +9962,8 @@
 #if CONFIG_REF_MV && CONFIG_EXT_INTER
                               mbmi_ext->compound_mode_context,
 #endif  // CONFIG_REF_MV && CONFIG_EXT_INTER
-                              frame_mv, this_mode, ref_frames, bsize, -1))
+                              frame_mv, this_mode, ref_frames, bsize, -1,
+                              mi_row, mi_col))
         continue;
     }
 
@@ -10869,13 +10890,18 @@
 #endif  // CONFIG_REF_MV
 #if CONFIG_GLOBAL_MOTION
     zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[refs[0]],
-                                            cm->allow_high_precision_mv)
+                                            cm->allow_high_precision_mv,
+                                            mi_col * MI_SIZE + MI_SIZE / 2,
+                                            mi_row * MI_SIZE + MI_SIZE / 2)
                            .as_int;
-    zeromv[1].as_int = comp_pred_mode
-                           ? gm_get_motion_vector(&cm->global_motion[refs[1]],
-                                                  cm->allow_high_precision_mv)
-                                 .as_int
-                           : 0;
+    zeromv[1].as_int =
+        comp_pred_mode
+            ? gm_get_motion_vector(&cm->global_motion[refs[1]],
+                                   cm->allow_high_precision_mv,
+                                   mi_col * MI_SIZE + MI_SIZE / 2,
+                                   mi_row * MI_SIZE + MI_SIZE / 2)
+                  .as_int
+            : 0;
 #else
     zeromv[0].as_int = 0;
     zeromv[1].as_int = 0;
@@ -10984,13 +11010,18 @@
       int_mv zeromv[2];
 #if CONFIG_GLOBAL_MOTION
       zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[refs[0]],
-                                              cm->allow_high_precision_mv)
+                                              cm->allow_high_precision_mv,
+                                              mi_col * MI_SIZE + MI_SIZE / 2,
+                                              mi_row * MI_SIZE + MI_SIZE / 2)
                              .as_int;
-      zeromv[1].as_int = comp_pred_mode
-                             ? gm_get_motion_vector(&cm->global_motion[refs[1]],
-                                                    cm->allow_high_precision_mv)
-                                   .as_int
-                             : 0;
+      zeromv[1].as_int =
+          comp_pred_mode
+              ? gm_get_motion_vector(&cm->global_motion[refs[1]],
+                                     cm->allow_high_precision_mv,
+                                     mi_col * MI_SIZE + MI_SIZE / 2,
+                                     mi_row * MI_SIZE + MI_SIZE / 2)
+                    .as_int
+              : 0;
 #else
       zeromv[0].as_int = 0;
       zeromv[1].as_int = 0;
@@ -11033,10 +11064,14 @@
       const MV_REFERENCE_FRAME refs[2] = { best_mbmode.ref_frame[0],
                                            best_mbmode.ref_frame[1] };
       zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[refs[0]],
-                                              cm->allow_high_precision_mv)
+                                              cm->allow_high_precision_mv,
+                                              mi_col * MI_SIZE + MI_SIZE / 2,
+                                              mi_row * MI_SIZE + MI_SIZE / 2)
                              .as_int;
       zeromv[1].as_int = gm_get_motion_vector(&cm->global_motion[refs[1]],
-                                              cm->allow_high_precision_mv)
+                                              cm->allow_high_precision_mv,
+                                              mi_col * MI_SIZE + MI_SIZE / 2,
+                                              mi_row * MI_SIZE + MI_SIZE / 2)
                              .as_int;
       lower_mv_precision(&zeromv[0].as_mv, cm->allow_high_precision_mv);
       lower_mv_precision(&zeromv[1].as_mv, cm->allow_high_precision_mv);
@@ -11149,6 +11184,7 @@
 
 void av1_rd_pick_inter_mode_sb_seg_skip(const AV1_COMP *cpi,
                                         TileDataEnc *tile_data, MACROBLOCK *x,
+                                        int mi_row, int mi_col,
                                         RD_COST *rd_cost, BLOCK_SIZE bsize,
                                         PICK_MODE_CONTEXT *ctx,
                                         int64_t best_rd_so_far) {
@@ -11166,6 +11202,8 @@
   int64_t this_rd = INT64_MAX;
   int rate2 = 0;
   const int64_t distortion2 = 0;
+  (void)mi_row;
+  (void)mi_col;
 
   estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp,
                            &comp_mode_p);
@@ -11194,8 +11232,9 @@
   mbmi->ref_frame[1] = NONE_FRAME;
 #if CONFIG_GLOBAL_MOTION
   mbmi->mv[0].as_int =
-      gm_get_motion_vector(&cm->global_motion[mbmi->ref_frame[0]],
-                           cm->allow_high_precision_mv)
+      gm_get_motion_vector(
+          &cm->global_motion[mbmi->ref_frame[0]], cm->allow_high_precision_mv,
+          mi_col * MI_SIZE + MI_SIZE / 2, mi_row * MI_SIZE + MI_SIZE / 2)
           .as_int;
 #else   // CONFIG_GLOBAL_MOTION
   mbmi->mv[0].as_int = 0;
diff --git a/av1/encoder/rdopt.h b/av1/encoder/rdopt.h
index dc450f6..81decfb 100644
--- a/av1/encoder/rdopt.h
+++ b/av1/encoder/rdopt.h
@@ -159,8 +159,8 @@
 
 void av1_rd_pick_inter_mode_sb_seg_skip(
     const struct AV1_COMP *cpi, struct TileDataEnc *tile_data,
-    struct macroblock *x, struct RD_COST *rd_cost, BLOCK_SIZE bsize,
-    PICK_MODE_CONTEXT *ctx, int64_t best_rd_so_far);
+    struct macroblock *x, int mi_row, int mi_col, struct RD_COST *rd_cost,
+    BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, int64_t best_rd_so_far);
 
 int av1_internal_image_edge(const struct AV1_COMP *cpi);
 int av1_active_h_edge(const struct AV1_COMP *cpi, int mi_row, int mi_step);