Commit a575d236 authored by Debargha Mukherjee's avatar Debargha Mukherjee Committed by Yue Chen

Make global motion multithreaded

Handles AVxEncoderThreadTest failures.

Change-Id: I81ea730a4fcd4a95fab198ee98b346a450d24b88
parent 1cf0b7e9
......@@ -1039,7 +1039,8 @@ static void update_filter_type_count(FRAME_COUNTS *counts,
#endif
#if CONFIG_GLOBAL_MOTION
static void update_global_motion_used(PREDICTION_MODE mode, BLOCK_SIZE bsize,
const MB_MODE_INFO *mbmi, AV1_COMP *cpi) {
const MB_MODE_INFO *mbmi,
RD_COUNTS *rdc) {
if (mode == ZEROMV
#if CONFIG_EXT_INTER
|| mode == ZERO_ZEROMV
......@@ -1049,7 +1050,7 @@ static void update_global_motion_used(PREDICTION_MODE mode, BLOCK_SIZE bsize,
num_4x4_blocks_wide_lookup[bsize] * num_4x4_blocks_high_lookup[bsize];
int ref;
for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
cpi->global_motion_used[mbmi->ref_frame[ref]] += num_4x4s;
rdc->global_motion_used[mbmi->ref_frame[ref]] += num_4x4s;
}
}
}
......@@ -1265,7 +1266,7 @@ static void update_state(const AV1_COMP *const cpi, ThreadData *td,
if (bsize >= BLOCK_8X8) {
// TODO(sarahparker): global motion stats need to be handled per-tile
// to be compatible with tile-based threading.
update_global_motion_used(mbmi->mode, bsize, mbmi, (AV1_COMP *)cpi);
update_global_motion_used(mbmi->mode, bsize, mbmi, rdc);
} else {
const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
......@@ -1273,8 +1274,7 @@ static void update_state(const AV1_COMP *const cpi, ThreadData *td,
for (idy = 0; idy < 2; idy += num_4x4_h) {
for (idx = 0; idx < 2; idx += num_4x4_w) {
const int j = idy * 2 + idx;
update_global_motion_used(mi->bmi[j].as_mode, bsize, mbmi,
(AV1_COMP *)cpi);
update_global_motion_used(mi->bmi[j].as_mode, bsize, mbmi, rdc);
}
}
}
......@@ -1431,7 +1431,7 @@ static void update_state_supertx(const AV1_COMP *const cpi, ThreadData *td,
if (bsize >= BLOCK_8X8) {
// TODO(sarahparker): global motion stats need to be handled per-tile
// to be compatible with tile-based threading.
update_global_motion_used(mbmi->mode, bsize, mbmi, (AV1_COMP *)cpi);
update_global_motion_used(mbmi->mode, bsize, mbmi, rdc);
} else {
const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
......@@ -1439,8 +1439,7 @@ static void update_state_supertx(const AV1_COMP *const cpi, ThreadData *td,
for (idy = 0; idy < 2; idy += num_4x4_h) {
for (idx = 0; idx < 2; idx += num_4x4_w) {
const int j = idy * 2 + idx;
update_global_motion_used(mi->bmi[j].as_mode, bsize, mbmi,
(AV1_COMP *)cpi);
update_global_motion_used(mi->bmi[j].as_mode, bsize, mbmi, rdc);
}
}
}
......@@ -5208,7 +5207,7 @@ static void encode_frame_internal(AV1_COMP *cpi) {
av1_zero(rdc->comp_pred_diff);
#if CONFIG_GLOBAL_MOTION
av1_zero(cpi->global_motion_used);
av1_zero(rdc->global_motion_used);
if (cpi->common.frame_type == INTER_FRAME && cpi->source &&
!cpi->global_motion_search_done) {
YV12_BUFFER_CONFIG *ref_buf;
......
......@@ -3062,17 +3062,18 @@ static int scale_down(AV1_COMP *cpi, int q) {
static int recode_loop_test_global_motion(AV1_COMP *cpi) {
int i;
int recode = 0;
RD_COUNTS *const rdc = &cpi->td.rd_counts;
AV1_COMMON *const cm = &cpi->common;
for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
if (cm->global_motion[i].wmtype != IDENTITY &&
cpi->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR <
rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR <
cpi->gmparams_cost[i]) {
set_default_warp_params(&cm->global_motion[i]);
cpi->gmparams_cost[i] = 0;
#if CONFIG_REF_MV
recode = 1;
#else
recode |= (cpi->global_motion_used[i] > 0);
recode |= (rdc->global_motion_used[i] > 0);
#endif
}
}
......
......@@ -309,6 +309,10 @@ typedef struct TileDataEnc {
typedef struct RD_COUNTS {
av1_coeff_count coef_counts[TX_SIZES][PLANE_TYPES];
int64_t comp_pred_diff[REFERENCE_MODES];
#if CONFIG_GLOBAL_MOTION
// Stores number of 4x4 blocks using global motion per reference frame.
int global_motion_used[TOTAL_REFS_PER_FRAME];
#endif // CONFIG_GLOBAL_MOTION
} RD_COUNTS;
typedef struct ThreadData {
......@@ -665,8 +669,6 @@ typedef struct AV1_COMP {
int arf_map[MAX_EXT_ARFS + 1];
#endif // CONFIG_EXT_REFS
#if CONFIG_GLOBAL_MOTION
// Stores number of 4x4 blocks using global motion per reference frame.
int global_motion_used[TOTAL_REFS_PER_FRAME];
int global_motion_search_done;
#endif
#if CONFIG_REFERENCE_BUFFER
......
......@@ -20,6 +20,12 @@ static void accumulate_rd_opt(ThreadData *td, ThreadData *td_t) {
for (i = 0; i < REFERENCE_MODES; i++)
td->rd_counts.comp_pred_diff[i] += td_t->rd_counts.comp_pred_diff[i];
#if CONFIG_GLOBAL_MOTION
for (i = 0; i < TOTAL_REFS_PER_FRAME; i++)
td->rd_counts.global_motion_used[i] +=
td_t->rd_counts.global_motion_used[i];
#endif // CONFIG_GLOBAL_MOTION
for (i = 0; i < TX_SIZES; i++)
for (j = 0; j < PLANE_TYPES; j++)
for (k = 0; k < REF_TYPES; k++)
......
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