Commit ae7c458a authored by Sarah Parker's avatar Sarah Parker

Turn off global motion for sub8x8 blocks

Lowres: 0.03% improvement, 1% improvement on waterfall_cif.y4m
Midres: 0.085% overall improvement, 1.253% improvement on station2_480p25.y4m
Change-Id: I3872934d978bb4ca828c6b9acd2fdb951d9da299
parent 614411fc
......@@ -13,6 +13,7 @@
#define AV1_COMMON_MV_H_
#include "av1/common/common.h"
#include "av1/common/common_data.h"
#include "aom_dsp/aom_filter.h"
#ifdef __cplusplus
......@@ -146,12 +147,37 @@ typedef struct {
#define GM_VERTRAPEZOID_BITS \
(GM_AFFINE_BITS - GM_ABS_ALPHA_BITS + GM_ABS_ROW3HOMO_BITS)
// Use global motion parameters for sub8x8 blocks
#define GLOBAL_SUB8X8_USED 0
static INLINE int block_center_x(int mi_col, BLOCK_SIZE bs) {
const int bw = block_size_wide[bs];
return mi_col * MI_SIZE + AOMMAX(bw, MI_SIZE) / 2;
}
static INLINE int block_center_y(int mi_row, BLOCK_SIZE bs) {
const int bh = block_size_high[bs];
return mi_row * MI_SIZE + AOMMAX(bh, MI_SIZE) / 2;
}
// 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 x, int y) {
int allow_hp, BLOCK_SIZE bsize,
int mi_col, int mi_row) {
#if !GLOBAL_SUB8X8_USED
if (bsize < BLOCK_8X8) {
int_mv res_zero;
res_zero.as_mv.row = 0;
res_zero.as_mv.col = 0;
return res_zero;
}
#endif
int_mv res;
const int32_t *mat = gm->wmmat;
const int x = block_center_x(mi_col, bsize);
const int y = block_center_y(mi_row, bsize);
int xc, yc;
int shift = allow_hp ? WARPEDMODEL_PREC_BITS - 3 : WARPEDMODEL_PREC_BITS - 2;
int scale = allow_hp ? 0 : 1;
......
......@@ -940,24 +940,21 @@ void av1_find_mv_refs(const AV1_COMMON *cm, const MACROBLOCKD *xd,
#if CONFIG_GLOBAL_MOTION
#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,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
.as_int;
zeromv[0].as_int =
gm_get_motion_vector(&cm->global_motion[rf[0]],
cm->allow_high_precision_mv, bsize, mi_col, mi_row)
.as_int;
zeromv[1].as_int = (rf[1] != NONE_FRAME)
? gm_get_motion_vector(&cm->global_motion[rf[1]],
cm->allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
bsize, mi_col, mi_row)
.as_int
: 0;
#else
zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame],
cm->allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
.as_int;
zeromv[0].as_int =
gm_get_motion_vector(&cm->global_motion[ref_frame],
cm->allow_high_precision_mv, bsize, mi_col, mi_row)
.as_int;
zeromv[1].as_int = 0;
#endif // CONFIG_REF_MV
#else
......@@ -1044,8 +1041,7 @@ void av1_append_sub8x8_mvs_for_idx(const AV1_COMMON *cm, MACROBLOCKD *xd,
#if CONFIG_GLOBAL_MOTION
zeromv.as_int =
gm_get_motion_vector(&cm->global_motion[ref], cm->allow_high_precision_mv,
block_center_x(mi_col, mi->mbmi.sb_type),
block_center_y(mi_row, mi->mbmi.sb_type))
mi->mbmi.sb_type, mi_col, mi_row)
.as_int;
#else
zeromv.as_int = 0;
......
......@@ -255,18 +255,6 @@ static const POSITION mv_ref_blocks[BLOCK_SIZES][MVREF_NEIGHBOURS] = {
};
#endif
#if CONFIG_GLOBAL_MOTION
static INLINE int block_center_x(int mi_col, BLOCK_SIZE bs) {
const int bw = block_size_wide[bs];
return mi_col * MI_SIZE + AOMMAX(bw, MI_SIZE) / 2;
}
static INLINE int block_center_y(int mi_row, BLOCK_SIZE bs) {
const int bh = block_size_high[bs];
return mi_row * MI_SIZE + AOMMAX(bh, MI_SIZE) / 2;
}
#endif // CONFIG_GLOBAL_MOTION
static const int idx_n_column_to_subblock[4][2] = {
{ 1, 2 }, { 1, 3 }, { 3, 2 }, { 3, 3 }
};
......
......@@ -767,6 +767,20 @@ void av1_highbd_build_inter_predictor(
}
#endif // CONFIG_AOM_HIGHBITDEPTH
#if CONFIG_GLOBAL_MOTION
static INLINE int is_global_mv_block(const MODE_INFO *mi, int block,
TransformationType type) {
PREDICTION_MODE mode = get_y_mode(mi, block);
#if GLOBAL_SUB8X8_USED
const int block_size_allowed = 1;
#else
const BLOCK_SIZE bsize = mi->mbmi.sb_type;
const int block_size_allowed = (bsize >= BLOCK_8X8);
#endif // GLOBAL_SUB8X8_USED
return mode == ZEROMV && type > TRANSLATION && block_size_allowed;
}
#endif // CONFIG_GLOBAL_MOTION
void av1_build_inter_predictor(const uint8_t *src, int src_stride, uint8_t *dst,
int dst_stride, const MV *src_mv,
const struct scale_factors *sf, int w, int h,
......@@ -822,8 +836,7 @@ void build_inter_predictors(MACROBLOCKD *xd, int plane,
int is_global[2];
for (ref = 0; ref < 1 + is_compound; ++ref) {
WarpedMotionParams *const wm = &xd->global_motion[mi->mbmi.ref_frame[ref]];
is_global[ref] =
(get_y_mode(mi, block) == ZEROMV && wm->wmtype > TRANSLATION);
is_global[ref] = is_global_mv_block(mi, block, wm->wmtype);
}
#endif // CONFIG_GLOBAL_MOTION
......@@ -2750,8 +2763,7 @@ static void build_inter_predictors_single_buf(MACROBLOCKD *xd, int plane,
ConvolveParams conv_params = get_conv_params(0, plane);
#if CONFIG_GLOBAL_MOTION
WarpedMotionParams *const wm = &xd->global_motion[mi->mbmi.ref_frame[ref]];
const int is_global =
(get_y_mode(mi, block) == ZEROMV && wm->wmtype > TRANSLATION);
const int is_global = is_global_mv_block(mi, block, wm->wmtype);
#endif // CONFIG_GLOBAL_MOTION
if (is_scaled) {
......
......@@ -1359,15 +1359,13 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
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,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
cm->allow_high_precision_mv, bsize,
mi_col, mi_row)
.as_int;
if (is_compound)
mv[1].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[1]],
cm->allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
cm->allow_high_precision_mv, bsize,
mi_col, mi_row)
.as_int;
#else
mv[0].as_int = 0;
......@@ -1516,14 +1514,12 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
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,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
cm->allow_high_precision_mv, bsize,
mi_col, mi_row)
.as_int;
mv[1].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[1]],
cm->allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
cm->allow_high_precision_mv, bsize,
mi_col, mi_row)
.as_int;
#else
mv[0].as_int = 0;
......@@ -1631,17 +1627,14 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
#if CONFIG_GLOBAL_MOTION
zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[rf[0]],
cm->allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
bsize, mi_col, mi_row)
.as_int;
zeromv[1].as_int =
(rf[1] != NONE_FRAME)
? gm_get_motion_vector(&cm->global_motion[rf[1]],
cm->allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
.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,
bsize, mi_col, mi_row)
.as_int
: 0;
#else
zeromv[0].as_int = zeromv[1].as_int = 0;
#endif
......
......@@ -5045,9 +5045,8 @@ static int set_and_cost_bmi_mvs(
this_mv[ref].as_int =
gm_get_motion_vector(
&cpi->common.global_motion[mbmi->ref_frame[ref]],
cpi->common.allow_high_precision_mv,
block_center_x(mi_col, mbmi->sb_type),
block_center_y(mi_row, mbmi->sb_type))
cpi->common.allow_high_precision_mv, mbmi->sb_type, mi_col,
mi_row)
.as_int;
thismvcost += GLOBAL_MOTION_RATE(cpi, mbmi->ref_frame[ref]);
#else
......@@ -5105,14 +5104,12 @@ static int set_and_cost_bmi_mvs(
this_mv[0].as_int =
gm_get_motion_vector(&cpi->common.global_motion[mbmi->ref_frame[0]],
cpi->common.allow_high_precision_mv,
block_center_x(mi_col, mbmi->sb_type),
block_center_y(mi_row, mbmi->sb_type))
mbmi->sb_type, mi_col, mi_row)
.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,
block_center_x(mi_col, mbmi->sb_type),
block_center_y(mi_row, mbmi->sb_type))
mbmi->sb_type, mi_col, mi_row)
.as_int;
thismvcost += GLOBAL_MOTION_RATE(cpi, mbmi->ref_frame[0]) +
GLOBAL_MOTION_RATE(cpi, mbmi->ref_frame[1]);
......@@ -5382,9 +5379,8 @@ static int check_best_zero_mv(
)
zeromv[cur_frm].as_int =
gm_get_motion_vector(&cpi->common.global_motion[ref_frames[cur_frm]],
cpi->common.allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
cpi->common.allow_high_precision_mv, bsize,
mi_col, mi_row)
.as_int;
else
#endif // CONFIG_GLOBAL_MOTION
......@@ -5845,9 +5841,8 @@ static int64_t rd_pick_inter_best_sub8x8_mode(
#if CONFIG_GLOBAL_MOTION
frame_mv[ZEROMV][frame].as_int =
gm_get_motion_vector(&cm->global_motion[frame],
cm->allow_high_precision_mv,
block_center_x(mi_col, mbmi->sb_type),
block_center_y(mi_row, mbmi->sb_type))
cm->allow_high_precision_mv, mbmi->sb_type,
mi_col, mi_row)
.as_int;
#else // CONFIG_GLOBAL_MOTION
frame_mv[ZEROMV][frame].as_int = 0;
......@@ -5879,9 +5874,8 @@ static int64_t rd_pick_inter_best_sub8x8_mode(
#if CONFIG_GLOBAL_MOTION
frame_mv[ZERO_ZEROMV][frame].as_int =
gm_get_motion_vector(&cm->global_motion[frame],
cm->allow_high_precision_mv,
block_center_x(mi_col, mbmi->sb_type),
block_center_y(mi_row, mbmi->sb_type))
cm->allow_high_precision_mv, mbmi->sb_type,
mi_col, mi_row)
.as_int;
#else
frame_mv[ZERO_ZEROMV][frame].as_int = 0;
......@@ -9607,9 +9601,8 @@ void av1_rd_pick_inter_mode_sb(const AV1_COMP *cpi, TileDataEnc *tile_data,
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,
block_center_x(mi_col, bsize), block_center_y(mi_row, bsize))
gm_get_motion_vector(&cm->global_motion[ref_frame],
cm->allow_high_precision_mv, bsize, mi_col, mi_row)
.as_int;
#else // CONFIG_GLOBAL_MOTION
frame_mv[ZEROMV][ref_frame].as_int = 0;
......@@ -9619,9 +9612,8 @@ void av1_rd_pick_inter_mode_sb(const AV1_COMP *cpi, TileDataEnc *tile_data,
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,
block_center_x(mi_col, bsize), block_center_y(mi_row, bsize))
gm_get_motion_vector(&cm->global_motion[ref_frame],
cm->allow_high_precision_mv, bsize, mi_col, mi_row)
.as_int;
#else // CONFIG_GLOBAL_MOTION
frame_mv[ZERO_ZEROMV][ref_frame].as_int = 0;
......@@ -9728,9 +9720,8 @@ void av1_rd_pick_inter_mode_sb(const AV1_COMP *cpi, TileDataEnc *tile_data,
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,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
cm->allow_high_precision_mv, bsize,
mi_col, mi_row)
.as_int;
#else
zeromv.as_int = 0;
......@@ -10924,16 +10915,14 @@ PALETTE_EXIT:
const uint8_t rf_type = av1_ref_frame_type(best_mbmode.ref_frame);
#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,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
.as_int;
zeromv[0].as_int =
gm_get_motion_vector(&cm->global_motion[refs[0]],
cm->allow_high_precision_mv, bsize, mi_col, mi_row)
.as_int;
zeromv[1].as_int = comp_pred_mode
? gm_get_motion_vector(&cm->global_motion[refs[1]],
cm->allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
bsize, mi_col, mi_row)
.as_int
: 0;
#else
......@@ -11045,17 +11034,14 @@ PALETTE_EXIT:
#if CONFIG_GLOBAL_MOTION
zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[refs[0]],
cm->allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
bsize, mi_col, mi_row)
.as_int;
zeromv[1].as_int =
comp_pred_mode
? gm_get_motion_vector(&cm->global_motion[refs[1]],
cm->allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
.as_int
: 0;
zeromv[1].as_int = comp_pred_mode
? gm_get_motion_vector(&cm->global_motion[refs[1]],
cm->allow_high_precision_mv,
bsize, mi_col, mi_row)
.as_int
: 0;
#else
zeromv[0].as_int = 0;
zeromv[1].as_int = 0;
......@@ -11099,13 +11085,11 @@ PALETTE_EXIT:
best_mbmode.ref_frame[1] };
zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[refs[0]],
cm->allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
bsize, mi_col, mi_row)
.as_int;
zeromv[1].as_int = gm_get_motion_vector(&cm->global_motion[refs[1]],
cm->allow_high_precision_mv,
block_center_x(mi_col, bsize),
block_center_y(mi_row, bsize))
bsize, mi_col, mi_row)
.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);
......@@ -11266,9 +11250,8 @@ void av1_rd_pick_inter_mode_sb_seg_skip(const AV1_COMP *cpi,
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,
block_center_x(mi_col, bsize), block_center_y(mi_row, bsize))
gm_get_motion_vector(&cm->global_motion[mbmi->ref_frame[0]],
cm->allow_high_precision_mv, bsize, mi_col, mi_row)
.as_int;
#else // CONFIG_GLOBAL_MOTION
mbmi->mv[0].as_int = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment