Commit ceebb701 authored by Debargha Mukherjee's avatar Debargha Mukherjee

Refactor expand dry_run types to return coef rate

Adds the functionality to return the rate cost due to
coefficients without doing full search of all modes.
This will be subsequently used in various experiments,
including in new_quant experiment to search quantization
profiles at the superblock level without repeating the
full mode/partition search.

Change-Id: I4aad3f3f0c8b8dfdea38f8f4f094a98283f47f08
parent 607048d6
......@@ -61,8 +61,9 @@
#endif // CONFIG_AOM_HIGHBITDEPTH
static void encode_superblock(AV1_COMP *cpi, ThreadData *td, TOKENEXTRA **t,
int output_enabled, int mi_row, int mi_col,
BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx);
RUN_TYPE dry_run, int mi_row, int mi_col,
BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx,
int *rate);
#if CONFIG_SUPERTX
static int check_intra_b(PICK_MODE_CONTEXT *ctx);
......@@ -80,13 +81,13 @@ static int check_supertx_sb(BLOCK_SIZE bsize, TX_SIZE supertx_size,
static void predict_sb_complex(AV1_COMP *cpi, ThreadData *td,
const TileInfo *const tile, int mi_row,
int mi_col, int mi_row_ori, int mi_col_ori,
int output_enabled, BLOCK_SIZE bsize,
RUN_TYPE dry_run, BLOCK_SIZE bsize,
BLOCK_SIZE top_bsize, uint8_t *dst_buf[3],
int dst_stride[3], PC_TREE *pc_tree);
static void update_state_sb_supertx(AV1_COMP *cpi, ThreadData *td,
const TileInfo *const tile, int mi_row,
int mi_col, BLOCK_SIZE bsize,
int output_enabled, PC_TREE *pc_tree);
RUN_TYPE dry_run, PC_TREE *pc_tree);
static void rd_supertx_sb(AV1_COMP *cpi, ThreadData *td,
const TileInfo *const tile, int mi_row, int mi_col,
BLOCK_SIZE bsize, int *tmp_rate, int64_t *tmp_dist,
......@@ -1025,7 +1026,7 @@ static void update_global_motion_used(PREDICTION_MODE mode,
static void update_state(AV1_COMP *cpi, ThreadData *td, PICK_MODE_CONTEXT *ctx,
int mi_row, int mi_col, BLOCK_SIZE bsize,
int output_enabled) {
RUN_TYPE dry_run) {
int i, x_idx, y;
AV1_COMMON *const cm = &cpi->common;
RD_COUNTS *const rdc = &td->rd_counts;
......@@ -1139,7 +1140,7 @@ static void update_state(AV1_COMP *cpi, ThreadData *td, PICK_MODE_CONTEXT *ctx,
sizeof(uint8_t) * ctx->num_4x4_blk);
#endif
if (!output_enabled) return;
if (dry_run) return;
#if CONFIG_INTERNAL_STATS
if (frame_is_intra_only(cm)) {
......@@ -1208,7 +1209,7 @@ static void update_state(AV1_COMP *cpi, ThreadData *td, PICK_MODE_CONTEXT *ctx,
#if CONFIG_SUPERTX
static void update_state_supertx(AV1_COMP *cpi, ThreadData *td,
PICK_MODE_CONTEXT *ctx, int mi_row, int mi_col,
BLOCK_SIZE bsize, int output_enabled) {
BLOCK_SIZE bsize, RUN_TYPE dry_run) {
int y, x_idx;
#if CONFIG_VAR_TX || CONFIG_REF_MV
int i;
......@@ -1316,7 +1317,7 @@ static void update_state_supertx(AV1_COMP *cpi, ThreadData *td,
// Turn motion variation off for supertx
mbmi->motion_variation = SIMPLE_TRANSLATION;
if (!output_enabled) return;
if (dry_run) return;
if (!frame_is_intra_only(cm)) {
av1_update_mv_count(td);
......@@ -1354,7 +1355,7 @@ static void update_state_supertx(AV1_COMP *cpi, ThreadData *td,
static void update_state_sb_supertx(AV1_COMP *cpi, ThreadData *td,
const TileInfo *const tile, int mi_row,
int mi_col, BLOCK_SIZE bsize,
int output_enabled, PC_TREE *pc_tree) {
RUN_TYPE dry_run, PC_TREE *pc_tree) {
AV1_COMMON *const cm = &cpi->common;
MACROBLOCK *const x = &td->mb;
MACROBLOCKD *const xd = &x->e_mbd;
......@@ -1378,27 +1379,27 @@ static void update_state_sb_supertx(AV1_COMP *cpi, ThreadData *td,
case PARTITION_NONE:
set_offsets_supertx(cpi, td, tile, mi_row, mi_col, subsize);
update_state_supertx(cpi, td, &pc_tree->none, mi_row, mi_col, subsize,
output_enabled);
dry_run);
break;
case PARTITION_VERT:
set_offsets_supertx(cpi, td, tile, mi_row, mi_col, subsize);
update_state_supertx(cpi, td, &pc_tree->vertical[0], mi_row, mi_col,
subsize, output_enabled);
subsize, dry_run);
if (mi_col + hbs < cm->mi_cols && bsize > BLOCK_8X8) {
set_offsets_supertx(cpi, td, tile, mi_row, mi_col + hbs, subsize);
update_state_supertx(cpi, td, &pc_tree->vertical[1], mi_row,
mi_col + hbs, subsize, output_enabled);
mi_col + hbs, subsize, dry_run);
}
pmc = &pc_tree->vertical_supertx;
break;
case PARTITION_HORZ:
set_offsets_supertx(cpi, td, tile, mi_row, mi_col, subsize);
update_state_supertx(cpi, td, &pc_tree->horizontal[0], mi_row, mi_col,
subsize, output_enabled);
subsize, dry_run);
if (mi_row + hbs < cm->mi_rows && bsize > BLOCK_8X8) {
set_offsets_supertx(cpi, td, tile, mi_row + hbs, mi_col, subsize);
update_state_supertx(cpi, td, &pc_tree->horizontal[1], mi_row + hbs,
mi_col, subsize, output_enabled);
mi_col, subsize, dry_run);
}
pmc = &pc_tree->horizontal_supertx;
break;
......@@ -1406,20 +1407,20 @@ static void update_state_sb_supertx(AV1_COMP *cpi, ThreadData *td,
if (bsize == BLOCK_8X8) {
set_offsets_supertx(cpi, td, tile, mi_row, mi_col, subsize);
update_state_supertx(cpi, td, pc_tree->leaf_split[0], mi_row, mi_col,
subsize, output_enabled);
subsize, dry_run);
} else {
set_offsets_supertx(cpi, td, tile, mi_row, mi_col, subsize);
update_state_sb_supertx(cpi, td, tile, mi_row, mi_col, subsize,
output_enabled, pc_tree->split[0]);
update_state_sb_supertx(cpi, td, tile, mi_row, mi_col, subsize, dry_run,
pc_tree->split[0]);
set_offsets_supertx(cpi, td, tile, mi_row, mi_col + hbs, subsize);
update_state_sb_supertx(cpi, td, tile, mi_row, mi_col + hbs, subsize,
output_enabled, pc_tree->split[1]);
dry_run, pc_tree->split[1]);
set_offsets_supertx(cpi, td, tile, mi_row + hbs, mi_col, subsize);
update_state_sb_supertx(cpi, td, tile, mi_row + hbs, mi_col, subsize,
output_enabled, pc_tree->split[2]);
dry_run, pc_tree->split[2]);
set_offsets_supertx(cpi, td, tile, mi_row + hbs, mi_col + hbs, subsize);
update_state_sb_supertx(cpi, td, tile, mi_row + hbs, mi_col + hbs,
subsize, output_enabled, pc_tree->split[3]);
subsize, dry_run, pc_tree->split[3]);
}
pmc = &pc_tree->split_supertx;
break;
......@@ -1427,49 +1428,49 @@ static void update_state_sb_supertx(AV1_COMP *cpi, ThreadData *td,
case PARTITION_HORZ_A:
set_offsets_supertx(cpi, td, tile, mi_row, mi_col, bsize2);
update_state_supertx(cpi, td, &pc_tree->horizontala[0], mi_row, mi_col,
bsize2, output_enabled);
bsize2, dry_run);
set_offsets_supertx(cpi, td, tile, mi_row, mi_col + hbs, bsize2);
update_state_supertx(cpi, td, &pc_tree->horizontala[1], mi_row,
mi_col + hbs, bsize2, output_enabled);
mi_col + hbs, bsize2, dry_run);
set_offsets_supertx(cpi, td, tile, mi_row + hbs, mi_col, subsize);
update_state_supertx(cpi, td, &pc_tree->horizontala[2], mi_row + hbs,
mi_col, subsize, output_enabled);
mi_col, subsize, dry_run);
pmc = &pc_tree->horizontala_supertx;
break;
case PARTITION_HORZ_B:
set_offsets_supertx(cpi, td, tile, mi_row, mi_col, subsize);
update_state_supertx(cpi, td, &pc_tree->horizontalb[0], mi_row, mi_col,
subsize, output_enabled);
subsize, dry_run);
set_offsets_supertx(cpi, td, tile, mi_row + hbs, mi_col, bsize2);
update_state_supertx(cpi, td, &pc_tree->horizontalb[1], mi_row + hbs,
mi_col, bsize2, output_enabled);
mi_col, bsize2, dry_run);
set_offsets_supertx(cpi, td, tile, mi_row + hbs, mi_col + hbs, bsize2);
update_state_supertx(cpi, td, &pc_tree->horizontalb[2], mi_row + hbs,
mi_col + hbs, bsize2, output_enabled);
mi_col + hbs, bsize2, dry_run);
pmc = &pc_tree->horizontalb_supertx;
break;
case PARTITION_VERT_A:
set_offsets_supertx(cpi, td, tile, mi_row, mi_col, bsize2);
update_state_supertx(cpi, td, &pc_tree->verticala[0], mi_row, mi_col,
bsize2, output_enabled);
bsize2, dry_run);
set_offsets_supertx(cpi, td, tile, mi_row + hbs, mi_col, bsize2);
update_state_supertx(cpi, td, &pc_tree->verticala[1], mi_row + hbs,
mi_col, bsize2, output_enabled);
mi_col, bsize2, dry_run);
set_offsets_supertx(cpi, td, tile, mi_row, mi_col + hbs, subsize);
update_state_supertx(cpi, td, &pc_tree->verticala[2], mi_row,
mi_col + hbs, subsize, output_enabled);
mi_col + hbs, subsize, dry_run);
pmc = &pc_tree->verticala_supertx;
break;
case PARTITION_VERT_B:
set_offsets_supertx(cpi, td, tile, mi_row, mi_col, subsize);
update_state_supertx(cpi, td, &pc_tree->verticalb[0], mi_row, mi_col,
subsize, output_enabled);
subsize, dry_run);
set_offsets_supertx(cpi, td, tile, mi_row, mi_col + hbs, bsize2);
update_state_supertx(cpi, td, &pc_tree->verticalb[1], mi_row,
mi_col + hbs, bsize2, output_enabled);
mi_col + hbs, bsize2, dry_run);
set_offsets_supertx(cpi, td, tile, mi_row + hbs, mi_col + hbs, bsize2);
update_state_supertx(cpi, td, &pc_tree->verticalb[2], mi_row + hbs,
mi_col + hbs, bsize2, output_enabled);
mi_col + hbs, bsize2, dry_run);
pmc = &pc_tree->verticalb_supertx;
break;
#endif // CONFIG_EXT_PARTITION_TYPES
......@@ -2109,21 +2110,21 @@ static void save_context(const MACROBLOCK *x, RD_SEARCH_MACROBLOCK_CONTEXT *ctx,
}
static void encode_b(AV1_COMP *cpi, const TileInfo *const tile, ThreadData *td,
TOKENEXTRA **tp, int mi_row, int mi_col,
int output_enabled, BLOCK_SIZE bsize,
TOKENEXTRA **tp, int mi_row, int mi_col, RUN_TYPE dry_run,
BLOCK_SIZE bsize,
#if CONFIG_EXT_PARTITION_TYPES
PARTITION_TYPE partition,
#endif
PICK_MODE_CONTEXT *ctx) {
PICK_MODE_CONTEXT *ctx, int *rate) {
MACROBLOCK *const x = &td->mb;
set_offsets(cpi, tile, x, mi_row, mi_col, bsize);
#if CONFIG_EXT_PARTITION_TYPES
x->e_mbd.mi[0]->mbmi.partition = partition;
#endif
update_state(cpi, td, ctx, mi_row, mi_col, bsize, output_enabled);
encode_superblock(cpi, td, tp, output_enabled, mi_row, mi_col, bsize, ctx);
update_state(cpi, td, ctx, mi_row, mi_col, bsize, dry_run);
encode_superblock(cpi, td, tp, dry_run, mi_row, mi_col, bsize, ctx, rate);
if (output_enabled) {
if (!dry_run) {
#if CONFIG_SUPERTX
update_stats(&cpi->common, td, 0);
#else
......@@ -2133,8 +2134,8 @@ static void encode_b(AV1_COMP *cpi, const TileInfo *const tile, ThreadData *td,
}
static void encode_sb(AV1_COMP *cpi, ThreadData *td, const TileInfo *const tile,
TOKENEXTRA **tp, int mi_row, int mi_col,
int output_enabled, BLOCK_SIZE bsize, PC_TREE *pc_tree) {
TOKENEXTRA **tp, int mi_row, int mi_col, RUN_TYPE dry_run,
BLOCK_SIZE bsize, PC_TREE *pc_tree, int *rate) {
const AV1_COMMON *const cm = &cpi->common;
MACROBLOCK *const x = &td->mb;
MACROBLOCKD *const xd = &x->e_mbd;
......@@ -2151,7 +2152,7 @@ static void encode_sb(AV1_COMP *cpi, ThreadData *td, const TileInfo *const tile,
if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return;
if (output_enabled) td->counts->partition[ctx][partition]++;
if (!dry_run) td->counts->partition[ctx][partition]++;
#if CONFIG_SUPERTX
if (!frame_is_intra_only(cm) && bsize <= MAX_SUPERTX_BLOCK_SIZE &&
......@@ -2167,33 +2168,34 @@ static void encode_sb(AV1_COMP *cpi, ThreadData *td, const TileInfo *const tile,
int dst_stride[3];
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,
output_enabled, pc_tree);
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);
for (i = 0; i < MAX_MB_PLANE; i++) {
dst_buf[i] = xd->plane[i].dst.buf;
dst_stride[i] = xd->plane[i].dst.stride;
}
predict_sb_complex(cpi, td, tile, mi_row, mi_col, mi_row, mi_col,
output_enabled, bsize, bsize, dst_buf, dst_stride,
pc_tree);
predict_sb_complex(cpi, td, tile, mi_row, mi_col, mi_row, mi_col, dry_run,
bsize, bsize, dst_buf, dst_stride, pc_tree);
set_offsets_without_segment_id(cpi, tile, x, mi_row, mi_col, bsize);
set_segment_id_supertx(cpi, x, mi_row, mi_col, bsize);
if (!x->skip) {
int this_rate = 0;
x->skip_optimize = 0;
x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct;
av1_encode_sb_supertx(x, bsize);
av1_tokenize_sb_supertx(cpi, td, tp, !output_enabled, bsize);
av1_tokenize_sb_supertx(cpi, td, tp, dry_run, bsize, rate);
if (rate) *rate += this_rate;
} else {
xd->mi[0]->mbmi.skip = 1;
if (output_enabled) td->counts->skip[av1_get_skip_context(xd)][1]++;
if (!dry_run) td->counts->skip[av1_get_skip_context(xd)][1]++;
reset_skip_context(xd, bsize);
}
if (output_enabled) {
if (!dry_run) {
for (y_idx = 0; y_idx < mi_height; y_idx++)
for (x_idx = 0; x_idx < mi_width; x_idx++) {
if ((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width >
......@@ -2234,7 +2236,7 @@ static void encode_sb(AV1_COMP *cpi, ThreadData *td, const TileInfo *const tile,
#endif // CONFIG_VAR_TX
return;
} else {
if (output_enabled) {
if (!dry_run) {
td->counts->supertx[partition_supertx_context_lookup[partition]]
[supertx_size][0]++;
}
......@@ -2244,93 +2246,91 @@ static void encode_sb(AV1_COMP *cpi, ThreadData *td, const TileInfo *const tile,
switch (partition) {
case PARTITION_NONE:
encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, subsize,
encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize,
#if CONFIG_EXT_PARTITION_TYPES
partition,
#endif
&pc_tree->none);
&pc_tree->none, rate);
break;
case PARTITION_VERT:
encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, subsize,
encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize,
#if CONFIG_EXT_PARTITION_TYPES
partition,
#endif
&pc_tree->vertical[0]);
&pc_tree->vertical[0], rate);
if (mi_col + hbs < cm->mi_cols && bsize > BLOCK_8X8) {
encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, output_enabled,
subsize,
encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, dry_run, subsize,
#if CONFIG_EXT_PARTITION_TYPES
partition,
#endif
&pc_tree->vertical[1]);
&pc_tree->vertical[1], rate);
}
break;
case PARTITION_HORZ:
encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, subsize,
encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize,
#if CONFIG_EXT_PARTITION_TYPES
partition,
#endif
&pc_tree->horizontal[0]);
&pc_tree->horizontal[0], rate);
if (mi_row + hbs < cm->mi_rows && bsize > BLOCK_8X8) {
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, output_enabled,
subsize,
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, dry_run, subsize,
#if CONFIG_EXT_PARTITION_TYPES
partition,
#endif
&pc_tree->horizontal[1]);
&pc_tree->horizontal[1], rate);
}
break;
case PARTITION_SPLIT:
if (bsize == BLOCK_8X8) {
encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, subsize,
encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize,
#if CONFIG_EXT_PARTITION_TYPES
partition,
#endif
pc_tree->leaf_split[0]);
pc_tree->leaf_split[0], rate);
} else {
encode_sb(cpi, td, tile, tp, mi_row, mi_col, output_enabled, subsize,
pc_tree->split[0]);
encode_sb(cpi, td, tile, tp, mi_row, mi_col + hbs, output_enabled,
subsize, pc_tree->split[1]);
encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col, output_enabled,
subsize, pc_tree->split[2]);
encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs, output_enabled,
subsize, pc_tree->split[3]);
encode_sb(cpi, td, tile, tp, mi_row, mi_col, dry_run, subsize,
pc_tree->split[0], rate);
encode_sb(cpi, td, tile, tp, mi_row, mi_col + hbs, dry_run, subsize,
pc_tree->split[1], rate);
encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col, dry_run, subsize,
pc_tree->split[2], rate);
encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs, dry_run,
subsize, pc_tree->split[3], rate);
}
break;
#if CONFIG_EXT_PARTITION_TYPES
case PARTITION_HORZ_A:
encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, bsize2,
partition, &pc_tree->horizontala[0]);
encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, output_enabled, bsize2,
partition, &pc_tree->horizontala[1]);
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, output_enabled, subsize,
partition, &pc_tree->horizontala[2]);
encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, bsize2, partition,
&pc_tree->horizontala[0], rate);
encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, dry_run, bsize2,
partition, &pc_tree->horizontala[1], rate);
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, dry_run, subsize,
partition, &pc_tree->horizontala[2], rate);
break;
case PARTITION_HORZ_B:
encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, subsize,
partition, &pc_tree->horizontalb[0]);
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, output_enabled, bsize2,
partition, &pc_tree->horizontalb[1]);
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col + hbs, output_enabled,
bsize2, partition, &pc_tree->horizontalb[2]);
encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize, partition,
&pc_tree->horizontalb[0], rate);
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, dry_run, bsize2,
partition, &pc_tree->horizontalb[1], rate);
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col + hbs, dry_run, bsize2,
partition, &pc_tree->horizontalb[2], rate);
break;
case PARTITION_VERT_A:
encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, bsize2,
partition, &pc_tree->verticala[0]);
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, output_enabled, bsize2,
partition, &pc_tree->verticala[1]);
encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, output_enabled, subsize,
partition, &pc_tree->verticala[2]);
encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, bsize2, partition,
&pc_tree->verticala[0], rate);
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, dry_run, bsize2,
partition, &pc_tree->verticala[1], rate);
encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, dry_run, subsize,
partition, &pc_tree->verticala[2], rate);
break;
case PARTITION_VERT_B:
encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, subsize,
partition, &pc_tree->verticalb[0]);
encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, output_enabled, bsize2,
partition, &pc_tree->verticalb[1]);
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col + hbs, output_enabled,
bsize2, partition, &pc_tree->verticalb[2]);
encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize, partition,
&pc_tree->verticalb[0], rate);
encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, dry_run, bsize2,
partition, &pc_tree->verticalb[1], rate);
encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col + hbs, dry_run, bsize2,
partition, &pc_tree->verticalb[2], rate);
break;
#endif // CONFIG_EXT_PARTITION_TYPES
default: assert(0 && "Invalid partition type."); break;
......@@ -2545,8 +2545,9 @@ static void rd_use_partition(AV1_COMP *cpi, ThreadData *td,
#endif
PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0];
av1_rd_cost_init(&tmp_rdc);
update_state(cpi, td, ctx, mi_row, mi_col, subsize, 0);
encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, ctx);
update_state(cpi, td, ctx, mi_row, mi_col, subsize, 1);
encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row, mi_col, subsize,
ctx, NULL);
rd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col, &tmp_rdc,
#if CONFIG_SUPERTX
&rt_nocoef,
......@@ -2587,8 +2588,9 @@ static void rd_use_partition(AV1_COMP *cpi, ThreadData *td,
#endif
PICK_MODE_CONTEXT *ctx = &pc_tree->vertical[0];
av1_rd_cost_init(&tmp_rdc);
update_state(cpi, td, ctx, mi_row, mi_col, subsize, 0);
encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, ctx);
update_state(cpi, td, ctx, mi_row, mi_col, subsize, 1);
encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row, mi_col, subsize,
ctx, NULL);
rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + hbs, &tmp_rdc,
#if CONFIG_SUPERTX
&rt_nocoef,
......@@ -2741,8 +2743,8 @@ static void rd_use_partition(AV1_COMP *cpi, ThreadData *td,
#endif
if (i != 3)
encode_sb(cpi, td, tile_info, tp, mi_row + y_idx, mi_col + x_idx, 0,
split_subsize, pc_tree->split[i]);
encode_sb(cpi, td, tile_info, tp, mi_row + y_idx, mi_col + x_idx,
OUTPUT_ENABLED, split_subsize, pc_tree->split[i], NULL);
chosen_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE];
#if CONFIG_SUPERTX
......@@ -2785,9 +2787,17 @@ static void rd_use_partition(AV1_COMP *cpi, ThreadData *td,
assert(chosen_rdc.rate < INT_MAX && chosen_rdc.dist < INT64_MAX);
if (do_recon) {
int output_enabled = (bsize == cm->sb_size);
encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, bsize,
pc_tree);
if (bsize == cm->sb_size) {
// NOTE: To get estimate for rate due to the tokens, use:
// int rate_coeffs = 0;
// encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, DRY_RUN_COSTCOEFFS,
// bsize, pc_tree, &rate_coeffs);
encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, OUTPUT_ENABLED, bsize,
pc_tree, NULL);
} else {
encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, DRY_RUN_NORMAL, bsize,
pc_tree, NULL);
}
}
*rate = chosen_rdc.rate;
......@@ -3136,8 +3146,9 @@ static void rd_test_partition3(
if (sum_rdc.rdcost < best_rdc->rdcost) {
#endif
PICK_MODE_CONTEXT *ctx = &ctxs[0];
update_state(cpi, td, ctx, mi_row0, mi_col0, subsize0, 0);
encode_superblock(cpi, td, tp, 0, mi_row0, mi_col0, subsize0, ctx);
update_state(cpi, td, ctx, mi_row0, mi_col0, subsize0, 1);
encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row0, mi_col0, subsize0,
ctx, NULL);
if (cpi->sf.adaptive_motion_search) load_pred_mv(x, ctx);
......@@ -3176,8 +3187,9 @@ static void rd_test_partition3(
if (sum_rdc.rdcost < best_rdc->rdcost) {
#endif
PICK_MODE_CONTEXT *ctx = &ctxs[1];
update_state(cpi, td, ctx, mi_row1, mi_col1, subsize1, 0);
encode_superblock(cpi, td, tp, 0, mi_row1, mi_col1, subsize1, ctx);
update_state(cpi, td, ctx, mi_row1, mi_col1, subsize1, 1);
encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row1, mi_col1, subsize1,
ctx, NULL);
if (cpi->sf.adaptive_motion_search) load_pred_mv(x, ctx);
......@@ -3788,8 +3800,9 @@ static void rd_pick_partition(AV1_COMP *cpi, ThreadData *td,
#endif // CONFIG_SUPERTX
mi_row + mi_step < cm->mi_rows && bsize > BLOCK_8X8) {
PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0];
update_state(cpi, td, ctx, mi_row, mi_col, subsize, 0);
encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, ctx);
update_state(cpi, td, ctx, mi_row, mi_col, subsize, 1);
encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row, mi_col, subsize,
ctx, NULL);
if (cpi->sf.adaptive_motion_search) load_pred_mv(x, ctx);
......@@ -3924,9 +3937,9 @@ static void rd_pick_partition(AV1_COMP *cpi, ThreadData *td,
if (sum_rdc.rdcost < best_rdc.rdcost &&
#endif // CONFIG_SUPERTX
mi_col + mi_step < cm->mi_cols && bsize > BLOCK_8X8) {
update_state(cpi, td, &pc_tree->vertical[0], mi_row, mi_col, subsize, 0);
encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize,
&pc_tree->vertical[0]);
update_state(cpi, td, &pc_tree->vertical[0], mi_row, mi_col, subsize, 1);
encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row, mi_col, subsize,
&pc_tree->vertical[0], NULL);
if (cpi->sf.adaptive_motion_search) load_pred_mv(x, ctx);
......@@ -4099,9 +4112,13 @@ static void rd_pick_partition(AV1_COMP *cpi, ThreadData *td,
if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX &&
pc_tree->index != 3) {
int output_enabled = (bsize == cm->sb_size);
encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, bsize,
pc_tree);
if (bsize == cm->sb_size) {
encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, OUTPUT_ENABLED, bsize,
pc_tree, NULL);
} else {
encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, DRY_RUN_NORMAL, bsize,
pc_tree, NULL);
}
}
if (bsize == cm->sb_size) {
......@@ -5000,8 +5017,9 @@ static void tx_partition_set_contexts(AV1_COMMON *cm, MACROBLOCKD *xd,
#endif
static void encode_superblock(AV1_COMP *cpi, ThreadData *td, TOKENEXTRA **t,
int output_enabled, int mi_row, int mi_col,
BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) {
RUN_TYPE dry_run, int mi_row, int mi_col,
BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx,
int *rate) {
AV1_COMMON *const cm = &cpi->common;
MACROBLOCK *const x = &td->mb;
MACROBLOCKD *const xd = &x->e_mbd;
......@@ -5023,12 +5041,12 @@ static void encode_superblock(AV1_COMP *cpi, ThreadData *td, TOKENEXTRA **t,
mbmi->skip = 1;
for (plane = 0; plane < MAX_MB_PLANE; ++plane)
av1_encode_intra_block_plane(x, AOMMAX(bsize, BLOCK_8X8), plane, 1);
if (output_enabled)
if (!dry_run)
sum_intra_stats(td->counts, mi, xd->above_mi, xd->left_mi,
frame_is_intra_only(cm));
#if CONFIG_EXT_INTRA
if (output_enabled && bsize >= BLOCK_8X8) {
if (!dry_run && bsize >= BLOCK_8X8) {
FRAME_COUNTS *counts = td->counts;
if (mbmi->mode == DC_PRED && mbmi->palette_mode_info.palette_size[0] == 0)
++counts->ext_intra[0][mbmi->ext_intra_mode_info.use_ext_intra_mode[0]];
......@@ -5046,18 +5064,18 @@ static void encode_superblock(AV1_COMP *cpi, ThreadData *td, TOKENEXTRA **t,
}
#endif // CONFIG_EXT_INTRA
if (bsize >= BLOCK_8X8 && output_enabled) {
if (bsize >= BLOCK_8X8 && !dry_run) {
for (plane = 0; plane <= 1; ++plane) {
if (mbmi->palette_mode_info.palette_size[plane] > 0) {
mbmi->palette_mode_info.palette_first_color_idx[plane] =
xd->plane[plane].color_index_map[0];
// TODO(huisu): this increases the use of token buffer. Needs stretch
// test to verify.
av1_tokenize_palette_sb(td, bsize, plane, t);
av1_tokenize_palette_sb(cpi, td, plane, t, dry_run, bsize, rate);
}
}
}
av1_tokenize_sb(cpi, td, t, !output_enabled, AOMMAX(bsize, BLOCK_8X8));
av1_tokenize_sb(cpi, td, t, dry_run, AOMMAX(bsize, BLOCK_8X8), rate);
} else {
int ref;
const int is_compound = has_second_ref(mbmi);
......@@ -5129,17 +5147,17 @@ static void encode_superblock(AV1_COMP *cpi, ThreadData *td, TOKENEXTRA **t,
#if CONFIG_VAR_TX
#if CONFIG_EXT_TX && CONFIG_RECT_TX
if (is_rect_tx(mbmi->tx_size))