Commit 59526ead authored by Angie Chiang's avatar Angie Chiang Committed by Gerrit Code Review
Browse files

Merge changes I3bc782d6,I8359e849,Iae50d0b0,Id1704d88,Ia69f13c4, ... into nextgenv2

* changes:
  Add av1_ prefix on ###_rd_stats functions
  Use init_rd_stats() in encodeframe.c
  Add transform block coefficient cost in RD_STATS for debugging
  Add helper functions to modify RD_STATS
  Add mi_row and mi_col into mbmi to facilitate rd_debug process
  Add token cost comparison in write_modes_b()
parents 653fdd6d c0feea8a
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
#endif #endif
#include "aom_dsp/prob.h" #include "aom_dsp/prob.h"
#if CONFIG_RD_DEBUG
#include "av1/encoder/cost.h"
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -39,6 +43,8 @@ typedef struct daala_writer aom_writer; ...@@ -39,6 +43,8 @@ typedef struct daala_writer aom_writer;
typedef struct aom_dk_writer aom_writer; typedef struct aom_dk_writer aom_writer;
#endif #endif
typedef struct TOKEN_STATS { int64_t cost; } TOKEN_STATS;
static INLINE void aom_start_encode(aom_writer *bc, uint8_t *buffer) { static INLINE void aom_start_encode(aom_writer *bc, uint8_t *buffer) {
#if CONFIG_ANS #if CONFIG_ANS
(void)bc; (void)bc;
...@@ -72,10 +78,25 @@ static INLINE void aom_write(aom_writer *br, int bit, int probability) { ...@@ -72,10 +78,25 @@ static INLINE void aom_write(aom_writer *br, int bit, int probability) {
#endif #endif
} }
static INLINE void aom_write_record(aom_writer *br, int bit, int probability,
TOKEN_STATS *token_stats) {
aom_write(br, bit, probability);
#if CONFIG_RD_DEBUG
token_stats->cost += av1_cost_bit(probability, bit);
#else
(void)token_stats;
#endif
}
static INLINE void aom_write_bit(aom_writer *w, int bit) { static INLINE void aom_write_bit(aom_writer *w, int bit) {
aom_write(w, bit, 128); // aom_prob_half aom_write(w, bit, 128); // aom_prob_half
} }
static INLINE void aom_write_bit_record(aom_writer *w, int bit,
TOKEN_STATS *token_stats) {
aom_write_record(w, bit, 128, token_stats); // aom_prob_half
}
static INLINE void aom_write_literal(aom_writer *w, int data, int bits) { static INLINE void aom_write_literal(aom_writer *w, int data, int bits) {
int bit; int bit;
...@@ -92,6 +113,18 @@ static INLINE void aom_write_tree_bits(aom_writer *w, const aom_tree_index *tr, ...@@ -92,6 +113,18 @@ static INLINE void aom_write_tree_bits(aom_writer *w, const aom_tree_index *tr,
} while (len); } while (len);
} }
static INLINE void aom_write_tree_bits_record(aom_writer *w,
const aom_tree_index *tr,
const aom_prob *probs, int bits,
int len, aom_tree_index i,
TOKEN_STATS *token_stats) {
do {
const int bit = (bits >> --len) & 1;
aom_write_record(w, bit, probs[i >> 1], token_stats);
i = tr[i + bit];
} while (len);
}
static INLINE void aom_write_tree(aom_writer *w, const aom_tree_index *tree, static INLINE void aom_write_tree(aom_writer *w, const aom_tree_index *tree,
const aom_prob *probs, int bits, int len, const aom_prob *probs, int bits, int len,
aom_tree_index i) { aom_tree_index i) {
...@@ -102,6 +135,19 @@ static INLINE void aom_write_tree(aom_writer *w, const aom_tree_index *tree, ...@@ -102,6 +135,19 @@ static INLINE void aom_write_tree(aom_writer *w, const aom_tree_index *tree,
#endif #endif
} }
static INLINE void aom_write_tree_record(aom_writer *w,
const aom_tree_index *tree,
const aom_prob *probs, int bits,
int len, aom_tree_index i,
TOKEN_STATS *token_stats) {
#if CONFIG_DAALA_EC
(void)token_stats;
daala_write_tree_bits(w, tree, probs, bits, len, i);
#else
aom_write_tree_bits_record(w, tree, probs, bits, len, i, token_stats);
#endif
}
#if CONFIG_EC_MULTISYMBOL #if CONFIG_EC_MULTISYMBOL
static INLINE void aom_write_symbol(aom_writer *w, int symb, aom_cdf_prob *cdf, static INLINE void aom_write_symbol(aom_writer *w, int symb, aom_cdf_prob *cdf,
int nsymbs) { int nsymbs) {
......
...@@ -250,6 +250,12 @@ typedef struct { ...@@ -250,6 +250,12 @@ typedef struct {
#if CONFIG_DELTA_Q #if CONFIG_DELTA_Q
int current_q_index; int current_q_index;
#endif #endif
#if CONFIG_RD_DEBUG
int64_t txb_cost_y;
int64_t txb_cost_uv;
int mi_row;
int mi_col;
#endif
} MB_MODE_INFO; } MB_MODE_INFO;
typedef struct MODE_INFO { typedef struct MODE_INFO {
......
...@@ -442,6 +442,10 @@ static MB_MODE_INFO *set_offsets(AV1_COMMON *const cm, MACROBLOCKD *const xd, ...@@ -442,6 +442,10 @@ static MB_MODE_INFO *set_offsets(AV1_COMMON *const cm, MACROBLOCKD *const xd,
// TODO(slavarnway): Generate sb_type based on bwl and bhl, instead of // TODO(slavarnway): Generate sb_type based on bwl and bhl, instead of
// passing bsize from decode_partition(). // passing bsize from decode_partition().
xd->mi[0]->mbmi.sb_type = bsize; xd->mi[0]->mbmi.sb_type = bsize;
#if CONFIG_RD_DEBUG
xd->mi[0]->mbmi.mi_row = mi_row;
xd->mi[0]->mbmi.mi_col = mi_col;
#endif
for (y = 0; y < y_mis; ++y) for (y = 0; y < y_mis; ++y)
for (x = !y; x < x_mis; ++x) xd->mi[y * cm->mi_stride + x] = xd->mi[0]; for (x = !y; x < x_mis; ++x) xd->mi[y * cm->mi_stride + x] = xd->mi[0];
......
...@@ -717,7 +717,8 @@ static void update_supertx_probs(AV1_COMMON *cm, int probwt, aom_writer *w) { ...@@ -717,7 +717,8 @@ static void update_supertx_probs(AV1_COMMON *cm, int probwt, aom_writer *w) {
static void pack_mb_tokens(aom_writer *w, const TOKENEXTRA **tp, static void pack_mb_tokens(aom_writer *w, const TOKENEXTRA **tp,
const TOKENEXTRA *const stop, const TOKENEXTRA *const stop,
aom_bit_depth_t bit_depth, const TX_SIZE tx_size) { aom_bit_depth_t bit_depth, const TX_SIZE tx_size,
TOKEN_STATS *token_stats) {
const TOKENEXTRA *p = *tp; const TOKENEXTRA *p = *tp;
#if CONFIG_VAR_TX #if CONFIG_VAR_TX
int count = 0; int count = 0;
...@@ -745,10 +746,11 @@ static void pack_mb_tokens(aom_writer *w, const TOKENEXTRA **tp, ...@@ -745,10 +746,11 @@ static void pack_mb_tokens(aom_writer *w, const TOKENEXTRA **tp,
#if CONFIG_EC_MULTISYMBOL #if CONFIG_EC_MULTISYMBOL
/* skip one or two nodes */ /* skip one or two nodes */
if (!p->skip_eob_node) aom_write(w, token != EOB_TOKEN, p->context_tree[0]); if (!p->skip_eob_node)
aom_write_record(w, token != EOB_TOKEN, p->context_tree[0], token_stats);
if (token != EOB_TOKEN) { if (token != EOB_TOKEN) {
aom_write(w, token != ZERO_TOKEN, p->context_tree[1]); aom_write_record(w, token != ZERO_TOKEN, p->context_tree[1], token_stats);
if (token != ZERO_TOKEN) { if (token != ZERO_TOKEN) {
aom_write_symbol(w, token - ONE_TOKEN, *p->token_cdf, aom_write_symbol(w, token - ONE_TOKEN, *p->token_cdf,
...@@ -760,19 +762,21 @@ static void pack_mb_tokens(aom_writer *w, const TOKENEXTRA **tp, ...@@ -760,19 +762,21 @@ static void pack_mb_tokens(aom_writer *w, const TOKENEXTRA **tp,
if (p->skip_eob_node) if (p->skip_eob_node)
coef_length -= p->skip_eob_node; coef_length -= p->skip_eob_node;
else else
aom_write(w, token != EOB_TOKEN, p->context_tree[0]); aom_write_record(w, token != EOB_TOKEN, p->context_tree[0], token_stats);
if (token != EOB_TOKEN) { if (token != EOB_TOKEN) {
aom_write(w, token != ZERO_TOKEN, p->context_tree[1]); aom_write_record(w, token != ZERO_TOKEN, p->context_tree[1], token_stats);
if (token != ZERO_TOKEN) { if (token != ZERO_TOKEN) {
aom_write(w, token != ONE_TOKEN, p->context_tree[2]); aom_write_record(w, token != ONE_TOKEN, p->context_tree[2],
token_stats);
if (token != ONE_TOKEN) { if (token != ONE_TOKEN) {
const int unconstrained_len = UNCONSTRAINED_NODES - p->skip_eob_node; const int unconstrained_len = UNCONSTRAINED_NODES - p->skip_eob_node;
aom_write_tree(w, av1_coef_con_tree, aom_write_tree_record(
av1_pareto8_full[p->context_tree[PIVOT_NODE] - 1], w, av1_coef_con_tree,
coef_value, coef_length - unconstrained_len, 0); av1_pareto8_full[p->context_tree[PIVOT_NODE] - 1], coef_value,
coef_length - unconstrained_len, 0, token_stats);
} }
} }
} }
...@@ -800,12 +804,12 @@ static void pack_mb_tokens(aom_writer *w, const TOKENEXTRA **tp, ...@@ -800,12 +804,12 @@ static void pack_mb_tokens(aom_writer *w, const TOKENEXTRA **tp,
--skip_bits; --skip_bits;
assert(!bb); assert(!bb);
} else { } else {
aom_write(w, bb, pb[index]); aom_write_record(w, bb, pb[index], token_stats);
} }
} }
} }
aom_write_bit(w, bit_string & 1); aom_write_bit_record(w, bit_string & 1, token_stats);
} }
++p; ++p;
...@@ -824,7 +828,7 @@ static void pack_txb_tokens(aom_writer *w, const TOKENEXTRA **tp, ...@@ -824,7 +828,7 @@ static void pack_txb_tokens(aom_writer *w, const TOKENEXTRA **tp,
MB_MODE_INFO *mbmi, int plane, MB_MODE_INFO *mbmi, int plane,
BLOCK_SIZE plane_bsize, aom_bit_depth_t bit_depth, BLOCK_SIZE plane_bsize, aom_bit_depth_t bit_depth,
int block, int blk_row, int blk_col, int block, int blk_row, int blk_col,
TX_SIZE tx_size) { TX_SIZE tx_size, TOKEN_STATS *token_stats) {
const struct macroblockd_plane *const pd = &xd->plane[plane]; const struct macroblockd_plane *const pd = &xd->plane[plane];
const BLOCK_SIZE bsize = txsize_to_bsize[tx_size]; const BLOCK_SIZE bsize = txsize_to_bsize[tx_size];
const int tx_row = blk_row >> (1 - pd->subsampling_y); const int tx_row = blk_row >> (1 - pd->subsampling_y);
...@@ -840,7 +844,7 @@ static void pack_txb_tokens(aom_writer *w, const TOKENEXTRA **tp, ...@@ -840,7 +844,7 @@ static void pack_txb_tokens(aom_writer *w, const TOKENEXTRA **tp,
: mbmi->inter_tx_size[tx_row][tx_col]; : mbmi->inter_tx_size[tx_row][tx_col];
if (tx_size == plane_tx_size) { if (tx_size == plane_tx_size) {
pack_mb_tokens(w, tp, tok_end, bit_depth, tx_size); pack_mb_tokens(w, tp, tok_end, bit_depth, tx_size, token_stats);
} else { } else {
const int bsl = block_size_wide[bsize] >> (tx_size_wide_log2[0] + 1); const int bsl = block_size_wide[bsize] >> (tx_size_wide_log2[0] + 1);
int i; int i;
...@@ -856,7 +860,7 @@ static void pack_txb_tokens(aom_writer *w, const TOKENEXTRA **tp, ...@@ -856,7 +860,7 @@ static void pack_txb_tokens(aom_writer *w, const TOKENEXTRA **tp,
if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue; if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue;
pack_txb_tokens(w, tp, tok_end, xd, mbmi, plane, plane_bsize, bit_depth, pack_txb_tokens(w, tp, tok_end, xd, mbmi, plane, plane_bsize, bit_depth,
block, offsetr, offsetc, sub_txs); block, offsetr, offsetc, sub_txs, token_stats);
block += step; block += step;
} }
} }
...@@ -1725,6 +1729,20 @@ static void write_mb_modes_kf(AV1_COMMON *cm, const MACROBLOCKD *xd, ...@@ -1725,6 +1729,20 @@ static void write_mb_modes_kf(AV1_COMMON *cm, const MACROBLOCKD *xd,
write_modes_b(cpi, tile, w, tok, tok_end, mi_row, mi_col) write_modes_b(cpi, tile, w, tok, tok_end, mi_row, mi_col)
#endif // CONFIG_SUPERTX #endif // CONFIG_SUPERTX
#if CONFIG_RD_DEBUG
static void dump_mode_info(MODE_INFO *mi) {
printf("\nmi->mbmi.mi_row == %d\n", mi->mbmi.mi_row);
printf("&& mi->mbmi.mi_col == %d\n", mi->mbmi.mi_col);
printf("&& mi->mbmi.sb_type == %d\n", mi->mbmi.sb_type);
printf("&& mi->mbmi.tx_size == %d\n", mi->mbmi.tx_size);
if (mi->mbmi.sb_type >= BLOCK_8X8) {
printf("&& mi->mbmi.mode == %d\n", mi->mbmi.mode);
} else {
printf("&& mi->bmi[0].as_mode == %d\n", mi->bmi[0].as_mode);
}
}
#endif
static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile, static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile,
aom_writer *w, const TOKENEXTRA **tok, aom_writer *w, const TOKENEXTRA **tok,
const TOKENEXTRA *const tok_end, const TOKENEXTRA *const tok_end,
...@@ -1737,6 +1755,10 @@ static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile, ...@@ -1737,6 +1755,10 @@ static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile,
MODE_INFO *m; MODE_INFO *m;
int plane; int plane;
int bh, bw; int bh, bw;
#if CONFIG_RD_DEBUG
int64_t txb_cost_y = 0;
int64_t txb_cost_uv = 0;
#endif
#if CONFIG_RANS #if CONFIG_RANS
(void)tok; (void)tok;
(void)tok_end; (void)tok_end;
...@@ -1836,11 +1858,18 @@ static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile, ...@@ -1836,11 +1858,18 @@ static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile,
#if CONFIG_EXT_TX && CONFIG_RECT_TX #if CONFIG_EXT_TX && CONFIG_RECT_TX
TX_SIZE tx_size = TX_SIZE tx_size =
plane ? get_uv_tx_size(mbmi, &xd->plane[plane]) : mbmi->tx_size; plane ? get_uv_tx_size(mbmi, &xd->plane[plane]) : mbmi->tx_size;
#endif
TOKEN_STATS token_stats;
token_stats.cost = 0;
#if CONFIG_EXT_TX && CONFIG_RECT_TX
if (is_inter_block(mbmi) && !is_rect_tx(tx_size)) { if (is_inter_block(mbmi) && !is_rect_tx(tx_size))
#else #else
if (is_inter_block(mbmi)) { if (is_inter_block(mbmi))
#endif #endif
{
const TX_SIZE max_tx_size = max_txsize_lookup[plane_bsize]; const TX_SIZE max_tx_size = max_txsize_lookup[plane_bsize];
int block = 0; int block = 0;
const int step = const int step =
...@@ -1850,7 +1879,8 @@ static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile, ...@@ -1850,7 +1879,8 @@ static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile,
for (row = 0; row < num_4x4_h; row += bkh) { for (row = 0; row < num_4x4_h; row += bkh) {
for (col = 0; col < num_4x4_w; col += bkw) { for (col = 0; col < num_4x4_w; col += bkw) {
pack_txb_tokens(w, tok, tok_end, xd, mbmi, plane, plane_bsize, pack_txb_tokens(w, tok, tok_end, xd, mbmi, plane, plane_bsize,
cm->bit_depth, block, row, col, max_tx_size); cm->bit_depth, block, row, col, max_tx_size,
&token_stats);
block += step; block += step;
} }
} }
...@@ -1862,17 +1892,40 @@ static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile, ...@@ -1862,17 +1892,40 @@ static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile,
for (row = 0; row < num_4x4_h; row += bkh) for (row = 0; row < num_4x4_h; row += bkh)
for (col = 0; col < num_4x4_w; col += bkw) for (col = 0; col < num_4x4_w; col += bkw)
pack_mb_tokens(w, tok, tok_end, cm->bit_depth, tx); pack_mb_tokens(w, tok, tok_end, cm->bit_depth, tx, &token_stats);
} }
#else #else
TX_SIZE tx = TX_SIZE tx =
plane ? get_uv_tx_size(&m->mbmi, &xd->plane[plane]) : m->mbmi.tx_size; plane ? get_uv_tx_size(&m->mbmi, &xd->plane[plane]) : m->mbmi.tx_size;
pack_mb_tokens(w, tok, tok_end, cm->bit_depth, tx); TOKEN_STATS token_stats;
token_stats.cost = 0;
pack_mb_tokens(w, tok, tok_end, cm->bit_depth, tx, &token_stats);
#endif // CONFIG_VAR_TX #endif // CONFIG_VAR_TX
#if CONFIG_RD_DEBUG
if (plane == 0)
txb_cost_y += token_stats.cost;
else
txb_cost_uv += token_stats.cost;
#else
(void)token_stats;
#endif
assert(*tok < tok_end && (*tok)->token == EOSB_TOKEN); assert(*tok < tok_end && (*tok)->token == EOSB_TOKEN);
(*tok)++; (*tok)++;
} }
} }
#if CONFIG_RD_DEBUG
if (m->mbmi.txb_cost_y != txb_cost_y) {
dump_mode_info(m);
assert(0);
}
if (m->mbmi.txb_cost_uv != txb_cost_uv) {
dump_mode_info(m);
assert(0);
}
#endif
} }
static void write_partition(const AV1_COMMON *const cm, static void write_partition(const AV1_COMMON *const cm,
...@@ -2070,9 +2123,11 @@ static void write_modes_sb(AV1_COMP *const cpi, const TileInfo *const tile, ...@@ -2070,9 +2123,11 @@ static void write_modes_sb(AV1_COMP *const cpi, const TileInfo *const tile,
BLOCK_SIZE txb_size = txsize_to_bsize[tx]; BLOCK_SIZE txb_size = txsize_to_bsize[tx];
int bw = num_4x4_blocks_wide_lookup[txb_size]; int bw = num_4x4_blocks_wide_lookup[txb_size];
TOKEN_STATS token_stats;
token_stats.cost = 0;
for (row = 0; row < num_4x4_h; row += bw) for (row = 0; row < num_4x4_h; row += bw)
for (col = 0; col < num_4x4_w; col += bw) for (col = 0; col < num_4x4_w; col += bw)
pack_mb_tokens(w, tok, tok_end, cm->bit_depth, tx); pack_mb_tokens(w, tok, tok_end, cm->bit_depth, tx, &token_stats);
assert(*tok < tok_end && (*tok)->token == EOSB_TOKEN); assert(*tok < tok_end && (*tok)->token == EOSB_TOKEN);
(*tok)++; (*tok)++;
} }
......
...@@ -1634,6 +1634,10 @@ static void rd_pick_sb_modes(const AV1_COMP *const cpi, TileDataEnc *tile_data, ...@@ -1634,6 +1634,10 @@ static void rd_pick_sb_modes(const AV1_COMP *const cpi, TileDataEnc *tile_data,
set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
mbmi = &xd->mi[0]->mbmi; mbmi = &xd->mi[0]->mbmi;
mbmi->sb_type = bsize; mbmi->sb_type = bsize;
#if CONFIG_RD_DEBUG
mbmi->mi_row = mi_row;
mbmi->mi_col = mi_col;
#endif
#if CONFIG_SUPERTX #if CONFIG_SUPERTX
// We set tx_size here as skip blocks would otherwise not set it. // We set tx_size here as skip blocks would otherwise not set it.
// tx_size needs to be set at this point as supertx_enable in // tx_size needs to be set at this point as supertx_enable in
...@@ -6181,11 +6185,7 @@ static void rd_supertx_sb(const AV1_COMP *const cpi, ThreadData *td, ...@@ -6181,11 +6185,7 @@ static void rd_supertx_sb(const AV1_COMP *const cpi, ThreadData *td,
const struct macroblockd_plane *const pd = &xd->plane[plane]; const struct macroblockd_plane *const pd = &xd->plane[plane];
int coeff_ctx = 1; int coeff_ctx = 1;
RD_STATS this_rd_stats; RD_STATS this_rd_stats;
av1_init_rd_stats(&this_rd_stats);
this_rd_stats.rate = 0;
this_rd_stats.dist = 0;
this_rd_stats.sse = 0;
this_rd_stats.skip = 1;
tx_size = max_txsize_lookup[bsize]; tx_size = max_txsize_lookup[bsize];
tx_size = tx_size =
...@@ -6240,10 +6240,7 @@ static void rd_supertx_sb(const AV1_COMP *const cpi, ThreadData *td, ...@@ -6240,10 +6240,7 @@ static void rd_supertx_sb(const AV1_COMP *const cpi, ThreadData *td,
mbmi->tx_type = tx_type; mbmi->tx_type = tx_type;
#if CONFIG_VAR_TX #if CONFIG_VAR_TX
this_rd_stats.rate = 0; av1_init_rd_stats(&this_rd_stats);
this_rd_stats.dist = 0;
this_rd_stats.sse = 0;
this_rd_stats.skip = 1;
av1_get_entropy_contexts(bsize, tx_size, pd, ctxa, ctxl); av1_get_entropy_contexts(bsize, tx_size, pd, ctxa, ctxl);
coeff_ctx = combine_entropy_contexts(ctxa[0], ctxl[0]); coeff_ctx = combine_entropy_contexts(ctxa[0], ctxl[0]);
......
...@@ -2936,6 +2936,7 @@ void av1_tx_block_rd_b(const AV1_COMP *cpi, MACROBLOCK *x, TX_SIZE tx_size, ...@@ -2936,6 +2936,7 @@ void av1_tx_block_rd_b(const AV1_COMP *cpi, MACROBLOCK *x, TX_SIZE tx_size,
int max_blocks_wide = block_size_wide[plane_bsize]; int max_blocks_wide = block_size_wide[plane_bsize];
const int diff_stride = max_blocks_wide; const int diff_stride = max_blocks_wide;
const int16_t *diff = &p->src_diff[4 * (blk_row * diff_stride + blk_col)]; const int16_t *diff = &p->src_diff[4 * (blk_row * diff_stride + blk_col)];
int txb_coeff_cost;
#if CONFIG_EXT_TX #if CONFIG_EXT_TX
assert(tx_size < TX_SIZES); assert(tx_size < TX_SIZES);
#endif // CONFIG_EXT_TX #endif // CONFIG_EXT_TX
...@@ -3035,9 +3036,13 @@ void av1_tx_block_rd_b(const AV1_COMP *cpi, MACROBLOCK *x, TX_SIZE tx_size, ...@@ -3035,9 +3036,13 @@ void av1_tx_block_rd_b(const AV1_COMP *cpi, MACROBLOCK *x, TX_SIZE tx_size,
} }
} }
rd_stats->dist += tmp * 16; rd_stats->dist += tmp * 16;
rd_stats->rate += av1_cost_coeffs(cm, x, plane, block, coeff_ctx, tx_size, txb_coeff_cost = av1_cost_coeffs(cm, x, plane, block, coeff_ctx, tx_size,
scan_order->scan, scan_order->neighbors, 0); scan_order->scan, scan_order->neighbors, 0);
rd_stats->rate += txb_coeff_cost;
rd_stats->skip &= (p->eobs[block] == 0); rd_stats->skip &= (p->eobs[block] == 0);
#if CONFIG_RD_DEBUG
rd_stats->txb_coeff_cost[plane] += txb_coeff_cost;
#endif
} }
static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row, static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
...@@ -3067,12 +3072,11 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row, ...@@ -3067,12 +3072,11 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
txfm_partition_context(tx_above + (blk_col >> 1), txfm_partition_context(tx_above + (blk_col >> 1),
tx_left + (blk_row >> 1), mbmi->sb_type, tx_size); tx_left + (blk_row >> 1), mbmi->sb_type, tx_size);
int64_t sum_dist = 0, sum_bsse = 0;
int64_t sum_rd = INT64_MAX; int64_t sum_rd = INT64_MAX;
int sum_rate = 0;
int all_skip = 1;
int tmp_eob = 0; int tmp_eob = 0;
int zero_blk_rate; int zero_blk_rate;
RD_STATS sum_rd_stats;
av1_init_rd_stats(&sum_rd_stats);
#if CONFIG_EXT_TX #if CONFIG_EXT_TX
assert(tx_size < TX_SIZES); assert(tx_size < TX_SIZES);
...@@ -3085,10 +3089,7 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row, ...@@ -3085,10 +3089,7 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
coeff_ctx = get_entropy_context(tx_size, pta, ptl); coeff_ctx = get_entropy_context(tx_size, pta, ptl);
rd_stats->rate = 0; av1_init_rd_stats(rd_stats);
rd_stats->dist = 0;
rd_stats->sse = 0;
rd_stats->skip = 1;
if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return;
...@@ -3129,7 +3130,8 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row, ...@@ -3129,7 +3130,8 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
int this_cost_valid = 1; int this_cost_valid = 1;
int64_t tmp_rd = 0; int64_t tmp_rd = 0;
sum_rate = av1_cost_bit(cpi->common.fc->txfm_partition_prob[ctx], 1); sum_rd_stats.rate =
av1_cost_bit(cpi->common.fc->txfm_partition_prob[ctx], 1);
#if CONFIG_EXT_TX #if CONFIG_EXT_TX
assert(tx_size < TX_SIZES); assert(tx_size < TX_SIZES);
#endif // CONFIG_EXT_TX #endif // CONFIG_EXT_TX
...@@ -3143,12 +3145,10 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row, ...@@ -3143,12 +3145,10 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
depth + 1, plane_bsize, ta, tl, tx_above, tx_left, depth + 1, plane_bsize, ta, tl, tx_above, tx_left,
&this_rd_stats, ref_best_rd - tmp_rd, &this_cost_valid); &this_rd_stats, ref_best_rd - tmp_rd, &this_cost_valid);
sum_rate += this_rd_stats.rate; av1_merge_rd_stats(&sum_rd_stats, &this_rd_stats);
sum_dist += this_rd_stats.dist;
sum_bsse += this_rd_stats.sse;
all_skip &= this_rd_stats.skip;
tmp_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); tmp_rd =
RDCOST(x->rdmult, x->rddiv, sum_rd_stats.rate, sum_rd_stats.dist);
if (this_rd < tmp_rd) break; if (this_rd < tmp_rd) break;
block += sub_step; block += sub_step;
} }
...@@ -3169,10 +3169,7 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row, ...@@ -3169,10 +3169,7 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
if (this_rd == INT64_MAX) *is_cost_valid = 0; if (this_rd == INT64_MAX) *is_cost_valid = 0;
x->blk_skip[plane][blk_row * bw + blk_col] = rd_stats->skip; x->blk_skip[plane][blk_row * bw + blk_col] = rd_stats->skip;
} else { } else {
rd_stats->rate = sum_rate; *rd_stats = sum_rd_stats;
rd_stats->dist = sum_dist;
rd_stats->sse = sum_bsse;
rd_stats->skip = all_skip;
if (sum_rd == INT64_MAX) *is_cost_valid = 0; if (sum_rd == INT64_MAX) *is_cost_valid = 0;
} }
} }
...@@ -3186,10 +3183,7 @@ static void inter_block_yrd(const AV1_COMP *cpi, MACROBLOCK *x, ...@@ -3186,10 +3183,7 @@ static void inter_block_yrd(const AV1_COMP *cpi, MACROBLOCK *x,
if (ref_best_rd < 0) is_cost_valid = 0; if (ref_best_rd < 0) is_cost_valid = 0;
rd_stats->rate = 0; av1_init_rd_stats(rd_stats);