Refactor/Change the entropy context for transforms The change makes the entropy context for transforms use the same mechanism as with and without lv_map. For the non-lv-map case the context is now based on the the larger transform dim for 2:1 rect transforms. The context is now the average for 4:1 rect transforms for both lv-map and non-lv-map cases. There is one small fix for level map for getting the correct rate when skip is set. BDRATE: lowres, 30 frames, speed 1: -0.15% gain for the non-lv-map case on the baseline. Change-Id: I06a583d33bef68202d72a88e077f8d31cc5e7fe4
diff --git a/av1/common/entropy.h b/av1/common/entropy.h index 6cf0399..624df57 100644 --- a/av1/common/entropy.h +++ b/av1/common/entropy.h
@@ -376,6 +376,11 @@ return mode_mv_merge_probs(pre_prob, ct); } +static INLINE TX_SIZE get_txsize_entropy_ctx(TX_SIZE txsize) { + return (TX_SIZE)((txsize_sqr_map[txsize] + txsize_sqr_up_map[txsize] + 1) >> + 1); +} + void av1_average_tile_coef_cdfs(struct frame_contexts *fc, struct frame_contexts *ec_ctxs[], aom_cdf_prob *cdf_ptrs[], int num_tiles);
diff --git a/av1/common/txb_common.h b/av1/common/txb_common.h index bd59555..f83c907 100644 --- a/av1/common/txb_common.h +++ b/av1/common/txb_common.h
@@ -30,10 +30,6 @@ int dc_sign_ctx; } TXB_CTX; -static INLINE TX_SIZE get_txsize_context(TX_SIZE tx_size) { - return txsize_sqr_up_map[tx_size]; -} - static const int base_level_count_to_index[13] = { 0, 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, };
diff --git a/av1/decoder/decodetxb.c b/av1/decoder/decodetxb.c index 9f38d71..477d98e 100644 --- a/av1/decoder/decodetxb.c +++ b/av1/decoder/decodetxb.c
@@ -66,7 +66,7 @@ #else FRAME_COUNTS *const counts = xd->counts; #endif - const TX_SIZE txs_ctx = get_txsize_context(tx_size); + const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size); const PLANE_TYPE plane_type = get_plane_type(plane); MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; const int seg_eob = av1_get_max_eob(tx_size);
diff --git a/av1/decoder/detokenize.c b/av1/decoder/detokenize.c index 6355cc0..c2a918a 100644 --- a/av1/decoder/detokenize.c +++ b/av1/decoder/detokenize.c
@@ -117,7 +117,7 @@ #endif // CONFIG_AOM_QM (void)tx_type; int band, c = 0; - const TX_SIZE tx_size_ctx = txsize_sqr_map[tx_size]; + const TX_SIZE tx_size_ctx = get_txsize_entropy_ctx(tx_size); aom_cdf_prob(*coef_head_cdfs)[COEFF_CONTEXTS][CDF_SIZE(ENTROPY_TOKENS)] = ec_ctx->coef_head_cdfs[tx_size_ctx][type][ref]; aom_cdf_prob(*coef_tail_cdfs)[COEFF_CONTEXTS][CDF_SIZE(ENTROPY_TOKENS)] =
diff --git a/av1/encoder/encodemb.c b/av1/encoder/encodemb.c index 5cc107a..14120e8 100644 --- a/av1/encoder/encodemb.c +++ b/av1/encoder/encodemb.c
@@ -171,9 +171,9 @@ int i, final_eob = 0; const int cat6_bits = av1_get_cat6_extrabits_size(tx_size, xd->bd); int(*head_token_costs)[COEFF_CONTEXTS][TAIL_TOKENS] = - mb->token_head_costs[txsize_sqr_map[tx_size]][plane_type][ref]; + mb->token_head_costs[get_txsize_entropy_ctx(tx_size)][plane_type][ref]; int(*tail_token_costs)[COEFF_CONTEXTS][TAIL_TOKENS] = - mb->token_tail_costs[txsize_sqr_map[tx_size]][plane_type][ref]; + mb->token_tail_costs[get_txsize_entropy_ctx(tx_size)][plane_type][ref]; const int64_t rdmult = (mb->rdmult * plane_rd_mult[ref][plane_type]) >> 1; int64_t rate0, rate1;
diff --git a/av1/encoder/encodetxb.c b/av1/encoder/encodetxb.c index cbdc9f6..bf35d93 100644 --- a/av1/encoder/encodetxb.c +++ b/av1/encoder/encodetxb.c
@@ -147,7 +147,7 @@ int16_t eob_pt = get_eob_pos_token(eob, &eob_extra); int16_t dummy; int16_t max_eob_pt = get_eob_pos_token(seg_eob, &dummy); - TX_SIZE txs_ctx = get_txsize_context(tx_size); + TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size); for (int i = 1; i < max_eob_pt; i++) { int eob_pos_ctx = av1_get_eob_pos_ctx(tx_type, i); @@ -322,7 +322,7 @@ uint16_t eob, TXB_CTX *txb_ctx) { MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; const PLANE_TYPE plane_type = get_plane_type(plane); - const TX_SIZE txs_ctx = get_txsize_context(tx_size); + const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size); const TX_TYPE tx_type = av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size); const SCAN_ORDER *const scan_order = get_scan(cm, tx_size, tx_type, mbmi); @@ -646,7 +646,7 @@ int blk_row, int blk_col, int block, TX_SIZE tx_size, TXB_CTX *txb_ctx) { MACROBLOCKD *const xd = &x->e_mbd; - TX_SIZE txs_ctx = get_txsize_context(tx_size); + TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size); const PLANE_TYPE plane_type = get_plane_type(plane); const TX_TYPE tx_type = av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size); @@ -2084,7 +2084,7 @@ TXB_CTX *txb_ctx, int fast_mode) { MACROBLOCKD *const xd = &x->e_mbd; const PLANE_TYPE plane_type = get_plane_type(plane); - const TX_SIZE txs_ctx = get_txsize_context(tx_size); + const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size); const TX_TYPE tx_type = av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size); const MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; @@ -2200,7 +2200,7 @@ DECLARE_ALIGNED(16, uint8_t, level_counts[MAX_TX_SQUARE]); const uint8_t allow_update_cdf = args->allow_update_cdf; - TX_SIZE txsize_ctx = get_txsize_context(tx_size); + TX_SIZE txsize_ctx = get_txsize_entropy_ctx(tx_size); FRAME_CONTEXT *ec_ctx = xd->tile_ctx; memcpy(tcoeff, qcoeff, sizeof(*tcoeff) * seg_eob);
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c index 405e8af..bcf1dd9 100644 --- a/av1/encoder/rdopt.c +++ b/av1/encoder/rdopt.c
@@ -1620,7 +1620,7 @@ const uint16_t *band_count = &band_count_table[tx_size][1]; const int eob = p->eobs[block]; const tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); - const TX_SIZE tx_size_ctx = txsize_sqr_map[tx_size]; + const TX_SIZE tx_size_ctx = get_txsize_entropy_ctx(tx_size); uint8_t token_cache[MAX_TX_SQUARE]; int pt = combine_entropy_contexts(*a, *l); int c, cost; @@ -3852,14 +3852,14 @@ if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; #if CONFIG_LV_MAP - TX_SIZE txs_ctx = get_txsize_context(tx_size); + TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size); TXB_CTX txb_ctx; get_txb_ctx(plane_bsize, tx_size, plane, pta, ptl, &txb_ctx); zero_blk_rate = x->coeff_costs[txs_ctx][get_plane_type(plane)] .txb_skip_cost[txb_ctx.txb_skip_ctx][1]; #else - TX_SIZE tx_size_ctx = txsize_sqr_map[tx_size]; + TX_SIZE tx_size_ctx = get_txsize_entropy_ctx(tx_size); int coeff_ctx = get_entropy_context(tx_size, pta, ptl); zero_blk_rate = x->token_head_costs[tx_size_ctx][pd->plane_type][1][0][coeff_ctx][0]; @@ -4291,7 +4291,7 @@ ENTROPY_CONTEXT *ta = above_ctx + blk_col; ENTROPY_CONTEXT *tl = left_ctx + blk_row; #if CONFIG_LV_MAP - const TX_SIZE txs_ctx = get_txsize_context(tx_size); + const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size); TXB_CTX txb_ctx; get_txb_ctx(plane_bsize, tx_size, plane, ta, tl, &txb_ctx); @@ -4299,7 +4299,7 @@ .txb_skip_cost[txb_ctx.txb_skip_ctx][1]; #else const int coeff_ctx = get_entropy_context(tx_size, ta, tl); - const TX_SIZE tx_size_ctx = txsize_sqr_map[tx_size]; + const TX_SIZE tx_size_ctx = get_txsize_entropy_ctx(tx_size); const int zero_blk_rate = x->token_head_costs[tx_size_ctx][pd->plane_type][1][0][coeff_ctx][0]; #endif // CONFIG_LV_MAP @@ -4720,7 +4720,7 @@ (void)cpi; // Rate. - const int tx_size_ctx = txsize_sqr_map[tx_size]; + const int tx_size_ctx = get_txsize_entropy_ctx(tx_size); ENTROPY_CONTEXT ctxa[2 * MAX_MIB_SIZE]; ENTROPY_CONTEXT ctxl[2 * MAX_MIB_SIZE]; av1_get_entropy_contexts(bsize, 0, &xd->plane[0], ctxa, ctxl);
diff --git a/av1/encoder/tokenize.c b/av1/encoder/tokenize.c index 4f60778..6ff425d 100644 --- a/av1/encoder/tokenize.c +++ b/av1/encoder/tokenize.c
@@ -430,10 +430,10 @@ FRAME_CONTEXT *ec_ctx = xd->tile_ctx; aom_cdf_prob( *const coef_head_cdfs)[COEFF_CONTEXTS][CDF_SIZE(ENTROPY_TOKENS)] = - ec_ctx->coef_head_cdfs[txsize_sqr_map[tx_size]][type][ref]; + ec_ctx->coef_head_cdfs[get_txsize_entropy_ctx(tx_size)][type][ref]; aom_cdf_prob( *const coef_tail_cdfs)[COEFF_CONTEXTS][CDF_SIZE(ENTROPY_TOKENS)] = - ec_ctx->coef_tail_cdfs[txsize_sqr_map[tx_size]][type][ref]; + ec_ctx->coef_tail_cdfs[get_txsize_entropy_ctx(tx_size)][type][ref]; int8_t eob_val; int8_t first_val = 1; const int seg_eob = av1_get_tx_eob(&cpi->common.seg, segment_id, tx_size);