Commit 1a7f0a8c authored by Jingning Han's avatar Jingning Han

Conditionally skip inverse transform in transform block RD

When the lower bound of a transform block rate-distortion cost is
above the current best rd cost, the only possibility that this
particular coding mode will be chosen is to fall back to all skip
mode. Hence there is no need to estimate the transform block rate
cost, distortion, etc. Obtain the sum of squared distance between
the prediction and the source would be sufficient.

This speeds up the encoding process by 5% - 10%.

Change-Id: I728728c3a42aafefd34641f0be69b3e2a9b9bbb2
parent 7abe9db7
......@@ -328,6 +328,7 @@ typedef struct RD_STATS {
int skip; // sse should equal to dist when skip == 1
int64_t ref_rdcost;
int zero_rate;
uint8_t invalid_rate;
#if CONFIG_DIST_8X8 && CONFIG_CB4X4
int64_t dist_y;
#endif
......
......@@ -458,6 +458,7 @@ static INLINE void av1_init_rd_stats(RD_STATS *rd_stats) {
rd_stats->sse = 0;
rd_stats->skip = 1;
rd_stats->zero_rate = 0;
rd_stats->invalid_rate = 0;
rd_stats->ref_rdcost = INT64_MAX;
#if CONFIG_DIST_8X8 && CONFIG_CB4X4
rd_stats->dist_y = 0;
......@@ -487,6 +488,7 @@ static INLINE void av1_invalid_rd_stats(RD_STATS *rd_stats) {
rd_stats->sse = INT64_MAX;
rd_stats->skip = 0;
rd_stats->zero_rate = 0;
rd_stats->invalid_rate = 1;
rd_stats->ref_rdcost = INT64_MAX;
#if CONFIG_DIST_8X8 && CONFIG_CB4X4
rd_stats->dist_y = INT64_MAX;
......@@ -515,6 +517,7 @@ static INLINE void av1_merge_rd_stats(RD_STATS *rd_stats_dst,
rd_stats_dst->dist += rd_stats_src->dist;
rd_stats_dst->sse += rd_stats_src->sse;
rd_stats_dst->skip &= rd_stats_src->skip;
rd_stats_dst->invalid_rate &= rd_stats_src->invalid_rate;
#if CONFIG_DIST_8X8 && CONFIG_CB4X4
rd_stats_dst->dist_y += rd_stats_src->dist_y;
#endif
......
......@@ -4346,6 +4346,22 @@ void av1_tx_block_rd_b(const AV1_COMP *cpi, MACROBLOCK *x, TX_SIZE tx_size,
int coeff_ctx = get_entropy_context(tx_size, a, l);
tmp = pixel_diff_dist(x, plane, diff, diff_stride, blk_row, blk_col,
plane_bsize, txm_bsize);
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
tmp = ROUND_POWER_OF_TWO(tmp, (xd->bd - 8) * 2);
#endif // CONFIG_HIGHBITDEPTH
rd_stats->sse += tmp << 4;
if (rd_stats->invalid_rate) {
rd_stats->dist += tmp << 4;
rd_stats->rate += rd_stats->zero_rate;
rd_stats->skip = 1;
return;
}
// TODO(any): Use av1_dist_block to compute distortion
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
......@@ -4373,30 +4389,30 @@ void av1_tx_block_rd_b(const AV1_COMP *cpi, MACROBLOCK *x, TX_SIZE tx_size,
const int shift = (MAX_TX_SCALE - av1_get_tx_scale(tx_size)) * 2;
tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
const int buffer_length = tx_size_2d[tx_size];
int64_t tmp_dist;
int64_t tmp_dist, tmp_sse;
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
tmp_dist =
av1_highbd_block_error(coeff, dqcoeff, buffer_length, &tmp, xd->bd) >>
shift;
tmp_dist = av1_highbd_block_error(coeff, dqcoeff, buffer_length, &tmp_sse,
xd->bd) >>
shift;
else
#endif
tmp_dist = av1_block_error(coeff, dqcoeff, buffer_length, &tmp) >> shift;
tmp_dist =
av1_block_error(coeff, dqcoeff, buffer_length, &tmp_sse) >> shift;
if (RDCOST(x->rdmult, 0, tmp_dist) < rd_stats->ref_rdcost) {
av1_optimize_b(cm, x, plane, blk_row, blk_col, block, plane_bsize, tx_size,
a, l);
} else {
rd_stats->rate += rd_stats->zero_rate;
rd_stats->dist += tmp_sse >> shift;
rd_stats->sse += tmp_sse >> shift;
rd_stats->skip = 1;
rd_stats->invalid_rate = 1;
return;
}
#endif // DISABLE_TRELLISQ_SEARCH
tmp = pixel_diff_dist(x, plane, diff, diff_stride, blk_row, blk_col,
plane_bsize, txm_bsize);
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
tmp = ROUND_POWER_OF_TWO(tmp, (xd->bd - 8) * 2);
#endif // CONFIG_HIGHBITDEPTH
rd_stats->sse += tmp * 16;
const int eob = p->eobs[block];
#if CONFIG_LGT
......
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