From 430c389f16e4d3ac68c8d458046eb76cf7286a57 Mon Sep 17 00:00:00 2001 From: Deb Mukherjee Date: Tue, 14 Oct 2014 13:51:22 -0700 Subject: [PATCH] Miscellaneous fixes for recent experiments Various cleanups for ext-tx, supertx, copy-coding experiments. Change-Id: I8703d5fee57b1310d8d1aa1f26908e9a427b0502 --- vp9/common/vp9_blockd.h | 11 ++++ vp9/encoder/vp9_bitstream.c | 4 +- vp9/encoder/vp9_encodeframe.c | 37 +++++++------ vp9/encoder/vp9_encodemb.c | 2 +- vp9/encoder/vp9_rdopt.c | 101 ++++++++++++++++++---------------- 5 files changed, 86 insertions(+), 69 deletions(-) diff --git a/vp9/common/vp9_blockd.h b/vp9/common/vp9_blockd.h index 9766b0982..a4eb80100 100644 --- a/vp9/common/vp9_blockd.h +++ b/vp9/common/vp9_blockd.h @@ -131,6 +131,17 @@ static INLINE int mi_width_log2(BLOCK_SIZE sb_type) { return mi_width_log2_lookup[sb_type]; } +#if CONFIG_SUPERTX +static INLINE TX_SIZE bsize_to_tx_size(BLOCK_SIZE bsize) { + const TX_SIZE tx_size_lookup[BLOCK_SIZES] = { + TX_4X4, TX_4X4, TX_4X4, + TX_8X8, TX_8X8, TX_8X8, + TX_16X16, TX_16X16, TX_16X16, + TX_32X32, TX_32X32, TX_32X32, TX_32X32}; + return tx_size_lookup[bsize]; +} +#endif + #if CONFIG_MASKED_INTERINTER #define MASK_BITS_SML 3 #define MASK_BITS_MED 4 diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 27d651a41..62f59b8bb 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -50,7 +50,7 @@ static int vp9_check_supertx(VP9_COMMON *cm, int mi_row, int mi_col, mi = cm->mi_grid_visible + (mi_row * cm->mi_stride + mi_col); - return mi[0]->mbmi.tx_size == b_width_log2(bsize) && + return mi[0]->mbmi.tx_size == bsize_to_tx_size(bsize) && mi[0]->mbmi.sb_type < bsize; } #endif @@ -613,7 +613,7 @@ static void write_modes_sb(VP9_COMP *cpi, cm->mi_rows, cm->mi_cols); if (!supertx_enabled && cm->frame_type != KEY_FRAME && partition != PARTITION_NONE && bsize <= BLOCK_32X32) { - TX_SIZE supertx_size = b_width_log2(bsize); + TX_SIZE supertx_size = bsize_to_tx_size(bsize); // b_width_log2(bsize); vp9_prob prob = partition == PARTITION_SPLIT ? cm->fc.supertxsplit_prob[supertx_size] : cm->fc.supertx_prob[supertx_size]; diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 8696b2eab..ff315f3fd 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -87,7 +87,7 @@ static void rd_supertx_sb(VP9_COMP *cpi, const TileInfo *const tile, int *tmp_rate, int64_t *tmp_dist, int *skippable, int64_t *sse, #if CONFIG_EXT_TX - int *best_tx, + EXT_TX_TYPE *best_tx, #endif PC_TREE *pc_tree); #endif @@ -1446,7 +1446,7 @@ static void encode_sb(VP9_COMP *cpi, const TileInfo *const tile, bsize <= BLOCK_32X32 && partition != PARTITION_NONE) { int supertx_enabled; - TX_SIZE supertx_size = b_width_log2(bsize); + TX_SIZE supertx_size = bsize_to_tx_size(bsize); supertx_enabled = check_supertx_sb(bsize, supertx_size, pc_tree); if (supertx_enabled) { const int mi_width = num_8x8_blocks_wide_lookup[bsize]; @@ -1496,7 +1496,7 @@ static void encode_sb(VP9_COMP *cpi, const TileInfo *const tile, cm->counts.supertxsplit[supertx_size][1]++; cm->counts.supertx_size[supertx_size]++; #if CONFIG_EXT_TX - if (supertx_size <= TX_16X16 && !xd->mi[0]->mbmi.skip) + if (supertx_size < TX_32X32 && !xd->mi[0]->mbmi.skip) ++cm->counts.ext_tx[xd->mi[0]->mbmi.ext_txfrm]; #endif (*tp)->token = EOSB_TOKEN; @@ -2725,7 +2725,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, #if CONFIG_SUPERTX if (cm->frame_type != KEY_FRAME && sum_rd < INT64_MAX) { - TX_SIZE supertx_size = b_width_log2(bsize); + TX_SIZE supertx_size = bsize_to_tx_size(bsize); // b_width_log2(bsize); best_partition = pc_tree->partitioning; pc_tree->partitioning = PARTITION_SPLIT; @@ -2736,7 +2736,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, int skippable = 1; int64_t sse = 0; #if CONFIG_EXT_TX - int best_tx = 0; + EXT_TX_TYPE best_tx = NORM; #endif tmp_rate = sum_rate_nocoef; @@ -2806,7 +2806,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, if (cm->frame_type != KEY_FRAME && sum_rd < INT64_MAX && i == 4 && bsize <= BLOCK_32X32) { - TX_SIZE supertx_size = b_width_log2(bsize); + TX_SIZE supertx_size = bsize_to_tx_size(bsize); best_partition = pc_tree->partitioning; pc_tree->partitioning = PARTITION_SPLIT; @@ -2817,7 +2817,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, int skippable = 1; int64_t sse = 0; #if CONFIG_EXT_TX - int best_tx = 0; + EXT_TX_TYPE best_tx = NORM; #endif tmp_rate = sum_rate_nocoef; @@ -2931,7 +2931,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, !abort_flag && sum_rd < INT64_MAX && bsize <= BLOCK_32X32) { - TX_SIZE supertx_size = b_width_log2(bsize); + TX_SIZE supertx_size = bsize_to_tx_size(bsize); best_partition = pc_tree->partitioning; pc_tree->partitioning = PARTITION_HORZ; @@ -2942,7 +2942,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, int skippable = 1; int64_t sse = 0; #if CONFIG_EXT_TX - int best_tx = 0; + EXT_TX_TYPE best_tx = NORM; #endif tmp_rate = sum_rate_nocoef; @@ -3050,7 +3050,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, !abort_flag && sum_rd < INT64_MAX && bsize <= BLOCK_32X32) { - TX_SIZE supertx_size = b_width_log2(bsize); + TX_SIZE supertx_size = bsize_to_tx_size(bsize); best_partition = pc_tree->partitioning; pc_tree->partitioning = PARTITION_VERT; @@ -3061,7 +3061,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, int skippable = 1; int64_t sse = 0; #if CONFIG_EXT_TX - int best_tx = 0; + EXT_TX_TYPE best_tx = NORM; #endif tmp_rate = sum_rate_nocoef; @@ -4380,7 +4380,7 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, } #if CONFIG_EXT_TX - if (mbmi->tx_size <= TX_16X16 && + if (mbmi->tx_size < TX_32X32 && is_inter_block(mbmi) && bsize >= BLOCK_8X8 && !mbmi->skip && @@ -4812,7 +4812,7 @@ static void rd_supertx_sb(VP9_COMP *cpi, const TileInfo *const tile, int *tmp_rate, int64_t *tmp_dist, int *skippable, int64_t *sse, #if CONFIG_EXT_TX - int *best_tx, + EXT_TX_TYPE *best_tx, #endif PC_TREE *pc_tree) { VP9_COMMON *const cm = &cpi->common; @@ -4835,11 +4835,12 @@ static void rd_supertx_sb(VP9_COMP *cpi, const TileInfo *const tile, set_offsets(cpi, tile, mi_row, mi_col, bsize); #if CONFIG_EXT_TX - *best_tx = 0; + *best_tx = NORM; #endif for (plane = 0; plane < MAX_MB_PLANE; ++plane) { - TX_SIZE tx_size = plane ? (b_width_log2(bsize) - 1) : b_width_log2(bsize); + TX_SIZE tx_size = + plane ? (bsize_to_tx_size(bsize) - 1) : bsize_to_tx_size(bsize); vp9_subtract_plane(x, bsize, plane); #if CONFIG_EXT_TX if (bsize <= BLOCK_16X16 && plane == 0) { @@ -4867,8 +4868,8 @@ static void rd_supertx_sb(VP9_COMP *cpi, const TileInfo *const tile, xd->mi[0]->mbmi.ext_txfrm = best_tx_nostx; } else { #endif - txfm_rd_in_plane_supertx(x, &this_rate, &this_dist, &pnskip, &pnsse, - INT64_MAX, plane, bsize, tx_size, 0); + txfm_rd_in_plane_supertx(x, &this_rate, &this_dist, &pnskip, &pnsse, + INT64_MAX, plane, bsize, tx_size, 0); #if CONFIG_EXT_TX } #endif @@ -4884,7 +4885,7 @@ static void rd_supertx_sb(VP9_COMP *cpi, const TileInfo *const tile, #if CONFIG_EXT_TX if (bsize <= BLOCK_16X16) *tmp_rate -= vp9_cost_bit(cm->fc.ext_tx_prob, *best_tx); - *best_tx = 0; + *best_tx = NORM; #endif } else { if (RDCOST(x->rdmult, x->rddiv, *tmp_rate - base_rate, *tmp_dist) diff --git a/vp9/encoder/vp9_encodemb.c b/vp9/encoder/vp9_encodemb.c index e3e3af897..ada09b3fe 100644 --- a/vp9/encoder/vp9_encodemb.c +++ b/vp9/encoder/vp9_encodemb.c @@ -593,7 +593,7 @@ void vp9_encode_sb_supertx(MACROBLOCK *x, BLOCK_SIZE bsize) { vp9_subtract_plane(x, bsize, plane); vp9_get_entropy_contexts(bsize, tx_size, pd, ctx.ta[plane], ctx.tl[plane]); - encode_block(plane, 0, plane_size, b_width_log2(plane_size), &arg); + encode_block(plane, 0, plane_size, bsize_to_tx_size(plane_size), &arg); } } #endif diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 82a14ae64..4721e30cf 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -3594,7 +3594,7 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, for (i = 0; i < EXT_TX_TYPES; i++) { mbmi->ext_txfrm = i; inter_super_block_yrd(cpi, x, &rate_y_tx, &distortion_y_tx, &dummy, psse, - bsize, txfm_cache, INT64_MAX); + bsize, txfm_cache, INT64_MAX); assert(rate_y_tx != INT_MAX); if (mbmi->tx_size < TX_32X32) rate_y_tx += vp9_cost_bit(cm->fc.ext_tx_prob, i); @@ -4529,8 +4529,11 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, int64_t tx_cache[TX_MODES]; int i; #if CONFIG_EXT_TX - int tx_type, rate2_tx, this_skip2_tx, best_tx_size, best_tx_type; + EXT_TX_TYPE tx_type, best_tx_type; + TX_SIZE best_tx_size; + int rate2_tx, this_skip2_tx; int64_t distortion2_tx, bestrd_tx = INT64_MAX; + uint8_t tmp_zcoeff_blk[256]; #endif *mbmi = *inter_ref_list[copy_mode - REF0]; @@ -4557,67 +4560,67 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, for (i = 0; i < TX_MODES; ++i) tx_cache[i] = INT64_MAX; #if CONFIG_EXT_TX - for (tx_type = 0; tx_type < 2; tx_type++) { + for (tx_type = NORM; tx_type < EXT_TX_TYPES; tx_type++) { mbmi->ext_txfrm = tx_type; #endif - inter_super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable_y, &ssey, - bsize, tx_cache, INT64_MAX); - super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &skippable_uv, &sseuv, - bsize, INT64_MAX); + inter_super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable_y, &ssey, + bsize, tx_cache, INT64_MAX); + super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &skippable_uv, &sseuv, + bsize, INT64_MAX); - rate2 = rate_y + rate_uv; - distortion2 = distortion_y + distortion_uv; - skippable = skippable_y && skippable_uv; - total_sse = ssey + sseuv; + rate2 = rate_y + rate_uv; + distortion2 = distortion_y + distortion_uv; + skippable = skippable_y && skippable_uv; + total_sse = ssey + sseuv; - if (skippable) { - vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); + if (skippable) { + vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); - rate2 -= (rate_y + rate_uv); - rate_y = 0; - rate_uv = 0; - if (skip_prob) { - int prob_skip_cost = vp9_cost_bit(skip_prob, 1); - rate2 += prob_skip_cost; - } - } else if (!xd->lossless) { - if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) < - RDCOST(x->rdmult, x->rddiv, 0, total_sse)) { - rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); - } else { - rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); - distortion2 = total_sse; - assert(total_sse >= 0); rate2 -= (rate_y + rate_uv); rate_y = 0; rate_uv = 0; - this_skip2 = 1; + if (skip_prob) { + int prob_skip_cost = vp9_cost_bit(skip_prob, 1); + rate2 += prob_skip_cost; + } + } else if (!xd->lossless) { + if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) < + RDCOST(x->rdmult, x->rddiv, 0, total_sse)) { + rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); + this_skip2 = 0; + } else { + rate2 = vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); + distortion2 = total_sse; + assert(total_sse >= 0); + rate_y = 0; + rate_uv = 0; + this_skip2 = 1; + } + } else { + rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); } - } else { - rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); - } #if CONFIG_EXT_TX - if (mbmi->tx_size <= TX_16X16 && !this_skip2) + if (mbmi->tx_size < TX_32X32 && !this_skip2) rate2 += vp9_cost_bit(cm->fc.ext_tx_prob, tx_type); this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); - if (tx_type == 0 || this_rd < (bestrd_tx * 0.97)) { + if (tx_type == NORM || this_rd < (bestrd_tx * 0.97)) { bestrd_tx = this_rd; best_tx_type = tx_type; best_tx_size = mbmi->tx_size; rate2_tx = rate2; distortion2_tx = distortion2; this_skip2_tx = this_skip2; + vpx_memcpy(tmp_zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], + sizeof(uint8_t) * ctx->num_4x4_blk); } } - if (best_tx_size <= TX_16X16) + if (best_tx_size < TX_32X32) mbmi->ext_txfrm = best_tx_type; else - mbmi->ext_txfrm = 0; - - inter_super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable_y, &ssey, - bsize, tx_cache, INT64_MAX); - super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &skippable_uv, &sseuv, - bsize, INT64_MAX); + mbmi->ext_txfrm = NORM; + mbmi->tx_size = best_tx_size; + vpx_memcpy(x->zcoeff_blk[mbmi->tx_size], tmp_zcoeff_blk, + sizeof(uint8_t) * ctx->num_4x4_blk); rate2 = rate2_tx; distortion2 = distortion2_tx; @@ -4638,7 +4641,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); if (this_rd < best_rd) { - int max_plane = MAX_MB_PLANE; + // int max_plane = MAX_MB_PLANE; *returnrate = rate2; *returndistortion = distortion2; @@ -4655,8 +4658,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, best_rd = this_rd; best_mbmode = *mbmi; best_skip2 = this_skip2; - if (!x->select_tx_size) - swap_block_ptr(x, ctx, 1, 0, 0, max_plane); + // if (!x->select_tx_size) swap_block_ptr(x, ctx, 1, 0, 0, max_plane); vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], sizeof(uint8_t) * ctx->num_4x4_blk); } @@ -4681,9 +4683,12 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, return INT64_MAX; *mbmi = best_mbmode; - x->skip |= best_skip2; - ctx->skip = x->skip; - ctx->mic = *xd->mi[0]; + if (mbmi->copy_mode != NOREF) { + x->skip = best_skip2; + ctx->skip = x->skip; + ctx->mic = *xd->mi[0]; + } + set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); if (!x->skip) { for (i = 0; i < TX_MODES; i++) { @@ -5038,7 +5043,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, if (ref_frame == INTRA_FRAME) { int rate; #if CONFIG_EXT_TX - mbmi->ext_txfrm = 0; + mbmi->ext_txfrm = NORM; #endif if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate, &rate_y, &distortion_y, best_rd) >= best_rd)