Refactor save_context restore_context in rd_pick_partition.

This is a cosmetic patch that removes a great deal of conditional
compilation around CONFIG_VAR_TX from the partition search function.

Change-Id: I9dcef9d4fe6847b793c77bdf565a5cacbdfacd59
This commit is contained in:
Geza Lore
2016-01-27 15:29:17 +00:00
committed by Julia Robson
parent 51f951292a
commit 24659dbca3

View File

@@ -1941,15 +1941,24 @@ static void update_stats(VP10_COMMON *cm, ThreadData *td
} }
} }
static void restore_context(MACROBLOCK *const x, int mi_row, int mi_col,
ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], typedef struct {
ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], ENTROPY_CONTEXT a[16 * MAX_MB_PLANE];
PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], ENTROPY_CONTEXT l[16 * MAX_MB_PLANE];
PARTITION_CONTEXT sa[8];
PARTITION_CONTEXT sl[8];
#if CONFIG_VAR_TX #if CONFIG_VAR_TX
TXFM_CONTEXT ta[8], TXFM_CONTEXT tl[8], TXFM_CONTEXT *p_ta;
TXFM_CONTEXT *p_tl;
TXFM_CONTEXT ta[8];
TXFM_CONTEXT tl[8];
#endif #endif
BLOCK_SIZE bsize) { } RD_SEARCH_MACROBLOCK_CONTEXT;
MACROBLOCKD *const xd = &x->e_mbd;
static void restore_context(MACROBLOCK *x,
const RD_SEARCH_MACROBLOCK_CONTEXT *ctx,
int mi_row, int mi_col, BLOCK_SIZE bsize) {
MACROBLOCKD *xd = &x->e_mbd;
int p; int p;
const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
@@ -1958,37 +1967,34 @@ static void restore_context(MACROBLOCK *const x, int mi_row, int mi_col,
for (p = 0; p < MAX_MB_PLANE; p++) { for (p = 0; p < MAX_MB_PLANE; p++) {
memcpy( memcpy(
xd->above_context[p] + ((mi_col * 2) >> xd->plane[p].subsampling_x), xd->above_context[p] + ((mi_col * 2) >> xd->plane[p].subsampling_x),
a + num_4x4_blocks_wide * p, ctx->a + num_4x4_blocks_wide * p,
(sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >>
xd->plane[p].subsampling_x); xd->plane[p].subsampling_x);
memcpy( memcpy(
xd->left_context[p] xd->left_context[p]
+ ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y),
l + num_4x4_blocks_high * p, ctx->l + num_4x4_blocks_high * p,
(sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >>
xd->plane[p].subsampling_y); xd->plane[p].subsampling_y);
} }
memcpy(xd->above_seg_context + mi_col, sa, memcpy(xd->above_seg_context + mi_col, ctx->sa,
sizeof(*xd->above_seg_context) * mi_width); sizeof(*xd->above_seg_context) * mi_width);
memcpy(xd->left_seg_context + (mi_row & MI_MASK), sl, memcpy(xd->left_seg_context + (mi_row & MI_MASK), ctx->sl,
sizeof(xd->left_seg_context[0]) * mi_height); sizeof(xd->left_seg_context[0]) * mi_height);
#if CONFIG_VAR_TX #if CONFIG_VAR_TX
memcpy(xd->above_txfm_context, ta, xd->above_txfm_context = ctx->p_ta;
xd->left_txfm_context = ctx->p_tl;
memcpy(xd->above_txfm_context, ctx->ta,
sizeof(*xd->above_txfm_context) * mi_width); sizeof(*xd->above_txfm_context) * mi_width);
memcpy(xd->left_txfm_context, tl, memcpy(xd->left_txfm_context, ctx->tl,
sizeof(*xd->left_txfm_context) * mi_height); sizeof(*xd->left_txfm_context) * mi_height);
#endif #endif
} }
static void save_context(MACROBLOCK *const x, int mi_row, int mi_col, static void save_context(const MACROBLOCK *x,
ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], RD_SEARCH_MACROBLOCK_CONTEXT *ctx,
ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], int mi_row, int mi_col, BLOCK_SIZE bsize) {
PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], const MACROBLOCKD *xd = &x->e_mbd;
#if CONFIG_VAR_TX
TXFM_CONTEXT ta[8], TXFM_CONTEXT tl[8],
#endif
BLOCK_SIZE bsize) {
const MACROBLOCKD *const xd = &x->e_mbd;
int p; int p;
const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
@@ -1998,26 +2004,28 @@ static void save_context(MACROBLOCK *const x, int mi_row, int mi_col,
// buffer the above/left context information of the block in search. // buffer the above/left context information of the block in search.
for (p = 0; p < MAX_MB_PLANE; ++p) { for (p = 0; p < MAX_MB_PLANE; ++p) {
memcpy( memcpy(
a + num_4x4_blocks_wide * p, ctx->a + num_4x4_blocks_wide * p,
xd->above_context[p] + (mi_col * 2 >> xd->plane[p].subsampling_x), xd->above_context[p] + (mi_col * 2 >> xd->plane[p].subsampling_x),
(sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >>
xd->plane[p].subsampling_x); xd->plane[p].subsampling_x);
memcpy( memcpy(
l + num_4x4_blocks_high * p, ctx->l + num_4x4_blocks_high * p,
xd->left_context[p] xd->left_context[p]
+ ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y),
(sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >>
xd->plane[p].subsampling_y); xd->plane[p].subsampling_y);
} }
memcpy(sa, xd->above_seg_context + mi_col, memcpy(ctx->sa, xd->above_seg_context + mi_col,
sizeof(*xd->above_seg_context) * mi_width); sizeof(*xd->above_seg_context) * mi_width);
memcpy(sl, xd->left_seg_context + (mi_row & MI_MASK), memcpy(ctx->sl, xd->left_seg_context + (mi_row & MI_MASK),
sizeof(xd->left_seg_context[0]) * mi_height); sizeof(xd->left_seg_context[0]) * mi_height);
#if CONFIG_VAR_TX #if CONFIG_VAR_TX
memcpy(ta, xd->above_txfm_context, memcpy(ctx->ta, xd->above_txfm_context,
sizeof(*xd->above_txfm_context) * mi_width); sizeof(*xd->above_txfm_context) * mi_width);
memcpy(tl, xd->left_txfm_context, memcpy(ctx->tl, xd->left_txfm_context,
sizeof(*xd->left_txfm_context) * mi_height); sizeof(*xd->left_txfm_context) * mi_height);
ctx->p_ta = xd->above_txfm_context;
ctx->p_tl = xd->left_txfm_context;
#endif #endif
} }
@@ -2299,11 +2307,7 @@ static void rd_use_partition(VP10_COMP *cpi,
int i, pl; int i, pl;
PARTITION_TYPE partition = PARTITION_NONE; PARTITION_TYPE partition = PARTITION_NONE;
BLOCK_SIZE subsize; BLOCK_SIZE subsize;
ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; RD_SEARCH_MACROBLOCK_CONTEXT x_ctx;
PARTITION_CONTEXT sl[8], sa[8];
#if CONFIG_VAR_TX
TXFM_CONTEXT tl[8], ta[8];
#endif
RD_COST last_part_rdc, none_rdc, chosen_rdc; RD_COST last_part_rdc, none_rdc, chosen_rdc;
BLOCK_SIZE sub_subsize = BLOCK_4X4; BLOCK_SIZE sub_subsize = BLOCK_4X4;
int splits_below = 0; int splits_below = 0;
@@ -2329,16 +2333,14 @@ static void rd_use_partition(VP10_COMP *cpi,
partition = partition_lookup[bsl][bs_type]; partition = partition_lookup[bsl][bs_type];
subsize = get_subsize(bsize, partition); subsize = get_subsize(bsize, partition);
pc_tree->partitioning = partition;
#if CONFIG_VAR_TX #if CONFIG_VAR_TX
xd->above_txfm_context = cm->above_txfm_context + mi_col; xd->above_txfm_context = cm->above_txfm_context + mi_col;
xd->left_txfm_context = xd->left_txfm_context_buffer + (mi_row & MI_MASK); xd->left_txfm_context = xd->left_txfm_context_buffer + (mi_row & MI_MASK);
#endif #endif
pc_tree->partitioning = partition;
save_context(x, mi_row, mi_col, a, l, sa, sl, save_context(x, &x_ctx, mi_row, mi_col, bsize);
#if CONFIG_VAR_TX
ta, tl,
#endif
bsize);
if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) { if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) {
set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
@@ -2384,11 +2386,8 @@ static void rd_use_partition(VP10_COMP *cpi,
#endif #endif
} }
restore_context(x, mi_row, mi_col, a, l, sa, sl, restore_context(x, &x_ctx, mi_row, mi_col, bsize);
#if CONFIG_VAR_TX
ta, tl,
#endif
bsize);
mi_8x8[0]->mbmi.sb_type = bs_type; mi_8x8[0]->mbmi.sb_type = bs_type;
pc_tree->partitioning = partition; pc_tree->partitioning = partition;
} }
@@ -2556,11 +2555,9 @@ static void rd_use_partition(VP10_COMP *cpi,
#if CONFIG_SUPERTX #if CONFIG_SUPERTX
chosen_rate_nocoef = 0; chosen_rate_nocoef = 0;
#endif #endif
restore_context(x, mi_row, mi_col, a, l, sa, sl,
#if CONFIG_VAR_TX restore_context(x, &x_ctx, mi_row, mi_col, bsize);
ta, tl,
#endif
bsize);
pc_tree->partitioning = PARTITION_SPLIT; pc_tree->partitioning = PARTITION_SPLIT;
// Split partition. // Split partition.
@@ -2571,20 +2568,12 @@ static void rd_use_partition(VP10_COMP *cpi,
#if CONFIG_SUPERTX #if CONFIG_SUPERTX
int rt_nocoef = 0; int rt_nocoef = 0;
#endif #endif
ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; RD_SEARCH_MACROBLOCK_CONTEXT x_ctx;
PARTITION_CONTEXT sl[8], sa[8];
#if CONFIG_VAR_TX
TXFM_CONTEXT tl[8], ta[8];
#endif
if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols))
continue; continue;
save_context(x, mi_row, mi_col, a, l, sa, sl, save_context(x, &x_ctx, mi_row, mi_col, bsize);
#if CONFIG_VAR_TX
ta, tl,
#endif
bsize);
pc_tree->split[i]->partitioning = PARTITION_NONE; pc_tree->split[i]->partitioning = PARTITION_NONE;
rd_pick_sb_modes(cpi, tile_data, x, rd_pick_sb_modes(cpi, tile_data, x,
mi_row + y_idx, mi_col + x_idx, &tmp_rdc, mi_row + y_idx, mi_col + x_idx, &tmp_rdc,
@@ -2593,11 +2582,7 @@ static void rd_use_partition(VP10_COMP *cpi,
#endif #endif
split_subsize, &pc_tree->split[i]->none, INT64_MAX); split_subsize, &pc_tree->split[i]->none, INT64_MAX);
restore_context(x, mi_row, mi_col, a, l, sa, sl, restore_context(x, &x_ctx, mi_row, mi_col, bsize);
#if CONFIG_VAR_TX
ta, tl,
#endif
bsize);
if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) {
vp10_rd_cost_reset(&chosen_rdc); vp10_rd_cost_reset(&chosen_rdc);
@@ -2655,15 +2640,7 @@ static void rd_use_partition(VP10_COMP *cpi,
#endif #endif
} }
#if CONFIG_VAR_TX restore_context(x, &x_ctx, mi_row, mi_col, bsize);
xd->above_txfm_context = cm->above_txfm_context + mi_col;
xd->left_txfm_context = xd->left_txfm_context_buffer + (mi_row & MI_MASK);
#endif
restore_context(x, mi_row, mi_col, a, l, sa, sl,
#if CONFIG_VAR_TX
ta, tl,
#endif
bsize);
// We must have chosen a partitioning and encoding or we'll fail later on. // We must have chosen a partitioning and encoding or we'll fail later on.
// No other opportunities for success. // No other opportunities for success.
@@ -2939,11 +2916,7 @@ static void rd_pick_partition(VP10_COMP *cpi, ThreadData *td,
MACROBLOCK *const x = &td->mb; MACROBLOCK *const x = &td->mb;
MACROBLOCKD *const xd = &x->e_mbd; MACROBLOCKD *const xd = &x->e_mbd;
const int mi_step = num_8x8_blocks_wide_lookup[bsize] / 2; const int mi_step = num_8x8_blocks_wide_lookup[bsize] / 2;
ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; RD_SEARCH_MACROBLOCK_CONTEXT x_ctx;
PARTITION_CONTEXT sl[8], sa[8];
#if CONFIG_VAR_TX
TXFM_CONTEXT tl[8], ta[8];
#endif
TOKENEXTRA *tp_orig = *tp; TOKENEXTRA *tp_orig = *tp;
PICK_MODE_CONTEXT *ctx = &pc_tree->none; PICK_MODE_CONTEXT *ctx = &pc_tree->none;
int i; int i;
@@ -3020,11 +2993,10 @@ static void rd_pick_partition(VP10_COMP *cpi, ThreadData *td,
#if CONFIG_VAR_TX #if CONFIG_VAR_TX
xd->above_txfm_context = cm->above_txfm_context + mi_col; xd->above_txfm_context = cm->above_txfm_context + mi_col;
xd->left_txfm_context = xd->left_txfm_context_buffer + (mi_row & MI_MASK); xd->left_txfm_context = xd->left_txfm_context_buffer + (mi_row & MI_MASK);
save_context(x, mi_row, mi_col, a, l, sa, sl, ta, tl, bsize);
#else
save_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
#endif #endif
save_context(x, &x_ctx, mi_row, mi_col, bsize);
#if CONFIG_FP_MB_STATS #if CONFIG_FP_MB_STATS
if (cpi->use_fp_mb_stats) { if (cpi->use_fp_mb_stats) {
set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
@@ -3178,13 +3150,8 @@ static void rd_pick_partition(VP10_COMP *cpi, ThreadData *td,
#endif #endif
} }
} }
#if CONFIG_VAR_TX
xd->above_txfm_context = cm->above_txfm_context + mi_col; restore_context(x, &x_ctx, mi_row, mi_col, bsize);
xd->left_txfm_context = xd->left_txfm_context_buffer + (mi_row & MI_MASK);
restore_context(x, mi_row, mi_col, a, l, sa, sl, ta, tl, bsize);
#else
restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
#endif // CONFIG_VAR_TX
} }
// store estimated motion vector // store estimated motion vector
@@ -3232,14 +3199,9 @@ static void rd_pick_partition(VP10_COMP *cpi, ThreadData *td,
TX_TYPE best_tx = DCT_DCT; TX_TYPE best_tx = DCT_DCT;
tmp_rate = sum_rate_nocoef; tmp_rate = sum_rate_nocoef;
tmp_dist = 0; tmp_dist = 0;
#if CONFIG_VAR_TX
xd->above_txfm_context = cm->above_txfm_context + mi_col; restore_context(x, &x_ctx, mi_row, mi_col, bsize);
xd->left_txfm_context =
xd->left_txfm_context_buffer + (mi_row & MI_MASK);
restore_context(x, mi_row, mi_col, a, l, sa, sl, ta, tl, bsize);
#else
restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
#endif // CONFIG_VAR_TX
rd_supertx_sb(cpi, td, tile_info, mi_row, mi_col, bsize, rd_supertx_sb(cpi, td, tile_info, mi_row, mi_col, bsize,
&tmp_rate, &tmp_dist, &tmp_rate, &tmp_dist,
&best_tx, &best_tx,
@@ -3326,14 +3288,9 @@ static void rd_pick_partition(VP10_COMP *cpi, ThreadData *td,
tmp_rate = sum_rate_nocoef; tmp_rate = sum_rate_nocoef;
tmp_dist = 0; tmp_dist = 0;
#if CONFIG_VAR_TX
xd->above_txfm_context = cm->above_txfm_context + mi_col; restore_context(x, &x_ctx, mi_row, mi_col, bsize);
xd->left_txfm_context =
xd->left_txfm_context_buffer + (mi_row & MI_MASK);
restore_context(x, mi_row, mi_col, a, l, sa, sl, ta, tl, bsize);
#else
restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
#endif // CONFIG_VAR_TX
rd_supertx_sb(cpi, td, tile_info, mi_row, mi_col, bsize, rd_supertx_sb(cpi, td, tile_info, mi_row, mi_col, bsize,
&tmp_rate, &tmp_dist, &tmp_rate, &tmp_dist,
&best_tx, &best_tx,
@@ -3380,13 +3337,8 @@ static void rd_pick_partition(VP10_COMP *cpi, ThreadData *td,
if (cpi->sf.less_rectangular_check) if (cpi->sf.less_rectangular_check)
do_rect &= !partition_none_allowed; do_rect &= !partition_none_allowed;
} }
#if CONFIG_VAR_TX
xd->above_txfm_context = cm->above_txfm_context + mi_col; restore_context(x, &x_ctx, mi_row, mi_col, bsize);
xd->left_txfm_context = xd->left_txfm_context_buffer + (mi_row & MI_MASK);
restore_context(x, mi_row, mi_col, a, l, sa, sl, ta, tl, bsize);
#else
restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
#endif
} // if (do_split) } // if (do_split)
// PARTITION_HORZ // PARTITION_HORZ
@@ -3466,13 +3418,9 @@ static void rd_pick_partition(VP10_COMP *cpi, ThreadData *td,
TX_TYPE best_tx = DCT_DCT; TX_TYPE best_tx = DCT_DCT;
tmp_rate = sum_rate_nocoef; tmp_rate = sum_rate_nocoef;
tmp_dist = 0; tmp_dist = 0;
#if CONFIG_VAR_TX
xd->above_txfm_context = cm->above_txfm_context + mi_col; restore_context(x, &x_ctx, mi_row, mi_col, bsize);
xd->left_txfm_context = xd->left_txfm_context_buffer + (mi_row & 0x07);
restore_context(x, mi_row, mi_col, a, l, sa, sl, ta, tl, bsize);
#else
restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
#endif // CONFIG_VAR_TX
rd_supertx_sb(cpi, td, tile_info, mi_row, mi_col, bsize, rd_supertx_sb(cpi, td, tile_info, mi_row, mi_col, bsize,
&tmp_rate, &tmp_dist, &tmp_rate, &tmp_dist,
&best_tx, &best_tx,
@@ -3511,13 +3459,8 @@ static void rd_pick_partition(VP10_COMP *cpi, ThreadData *td,
pc_tree->partitioning = PARTITION_HORZ; pc_tree->partitioning = PARTITION_HORZ;
} }
} }
#if CONFIG_VAR_TX
xd->above_txfm_context = cm->above_txfm_context + mi_col; restore_context(x, &x_ctx, mi_row, mi_col, bsize);
xd->left_txfm_context = xd->left_txfm_context_buffer + (mi_row & MI_MASK);
restore_context(x, mi_row, mi_col, a, l, sa, sl, ta, tl, bsize);
#else
restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
#endif
} }
// PARTITION_VERT // PARTITION_VERT
if (partition_vert_allowed && if (partition_vert_allowed &&
@@ -3594,13 +3537,9 @@ static void rd_pick_partition(VP10_COMP *cpi, ThreadData *td,
tmp_rate = sum_rate_nocoef; tmp_rate = sum_rate_nocoef;
tmp_dist = 0; tmp_dist = 0;
#if CONFIG_VAR_TX
xd->above_txfm_context = cm->above_txfm_context + mi_col; restore_context(x, &x_ctx, mi_row, mi_col, bsize);
xd->left_txfm_context = xd->left_txfm_context_buffer + (mi_row & 0x07);
restore_context(x, mi_row, mi_col, a, l, sa, sl, ta, tl, bsize);
#else
restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
#endif // CONFIG_VAR_TX
rd_supertx_sb(cpi, td, tile_info, mi_row, mi_col, bsize, rd_supertx_sb(cpi, td, tile_info, mi_row, mi_col, bsize,
&tmp_rate, &tmp_dist, &tmp_rate, &tmp_dist,
&best_tx, &best_tx,
@@ -3640,13 +3579,8 @@ static void rd_pick_partition(VP10_COMP *cpi, ThreadData *td,
pc_tree->partitioning = PARTITION_VERT; pc_tree->partitioning = PARTITION_VERT;
} }
} }
#if CONFIG_VAR_TX
xd->above_txfm_context = cm->above_txfm_context + mi_col; restore_context(x, &x_ctx, mi_row, mi_col, bsize);
xd->left_txfm_context = xd->left_txfm_context_buffer + (mi_row & MI_MASK);
restore_context(x, mi_row, mi_col, a, l, sa, sl, ta, tl, bsize);
#else
restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
#endif
} }
// TODO(jbb): This code added so that we avoid static analysis // TODO(jbb): This code added so that we avoid static analysis