Splitting partition_probs array into two arrays.

We only update partition_probs for inter frames but they are constant
for key frames. It is not necessary to have constants inside frame
context and copy them every time. This change reduces FRAME_CONTEXT size
by at least 48 bytes.


Change-Id: If70a53be51043f37fe7d113853217937710932a7
This commit is contained in:
Dmitry Kovalev 2013-11-01 18:23:06 -07:00
parent dd45530ee6
commit dde8069e57
6 changed files with 94 additions and 90 deletions

View File

@ -161,9 +161,8 @@ static const vp9_prob default_if_uv_probs[INTRA_MODES][INTRA_MODES - 1] = {
{ 101, 21, 107, 181, 192, 103, 19, 67, 125 } // y = tm { 101, 21, 107, 181, 192, 103, 19, 67, 125 } // y = tm
}; };
static const vp9_prob default_partition_probs[FRAME_TYPES][PARTITION_CONTEXTS] const vp9_prob vp9_kf_partition_probs[PARTITION_CONTEXTS]
[PARTITION_TYPES - 1] = { [PARTITION_TYPES - 1] = {
{ // frame_type = keyframe
// 8x8 -> 4x4 // 8x8 -> 4x4
{ 158, 97, 94 }, // a/l both not split { 158, 97, 94 }, // a/l both not split
{ 93, 24, 99 }, // a split, l not split { 93, 24, 99 }, // a split, l not split
@ -184,7 +183,10 @@ static const vp9_prob default_partition_probs[FRAME_TYPES][PARTITION_CONTEXTS]
{ 68, 11, 27 }, // a split, l not split { 68, 11, 27 }, // a split, l not split
{ 57, 15, 9 }, // l split, a not split { 57, 15, 9 }, // l split, a not split
{ 12, 3, 3 }, // a/l both split { 12, 3, 3 }, // a/l both split
}, { // frame_type = interframe };
static const vp9_prob default_partition_probs[PARTITION_CONTEXTS]
[PARTITION_TYPES - 1] = {
// 8x8 -> 4x4 // 8x8 -> 4x4
{ 199, 122, 141 }, // a/l both not split { 199, 122, 141 }, // a/l both not split
{ 147, 63, 159 }, // a split, l not split { 147, 63, 159 }, // a split, l not split
@ -205,7 +207,6 @@ static const vp9_prob default_partition_probs[FRAME_TYPES][PARTITION_CONTEXTS]
{ 72, 16, 44 }, // a split, l not split { 72, 16, 44 }, // a split, l not split
{ 58, 32, 12 }, // l split, a not split { 58, 32, 12 }, // l split, a not split
{ 10, 7, 6 }, // a/l both split { 10, 7, 6 }, // a/l both split
}
}; };
static const vp9_prob default_inter_mode_probs[INTER_MODE_CONTEXTS] static const vp9_prob default_inter_mode_probs[INTER_MODE_CONTEXTS]
@ -404,10 +405,8 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) {
fc->uv_mode_prob[i], 0); fc->uv_mode_prob[i], 0);
for (i = 0; i < PARTITION_CONTEXTS; i++) for (i = 0; i < PARTITION_CONTEXTS; i++)
update_mode_probs(PARTITION_TYPES, vp9_partition_tree, update_mode_probs(PARTITION_TYPES, vp9_partition_tree, counts->partition[i],
counts->partition[i], pre_fc->partition_prob[i], fc->partition_prob[i], 0);
pre_fc->partition_prob[INTER_FRAME][i],
fc->partition_prob[INTER_FRAME][i], 0);
if (cm->mcomp_filter_type == SWITCHABLE) { if (cm->mcomp_filter_type == SWITCHABLE) {
for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)

View File

@ -38,6 +38,9 @@ extern const vp9_prob vp9_kf_uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
extern const vp9_prob vp9_kf_y_mode_prob[INTRA_MODES][INTRA_MODES] extern const vp9_prob vp9_kf_y_mode_prob[INTRA_MODES][INTRA_MODES]
[INTRA_MODES - 1]; [INTRA_MODES - 1];
extern const vp9_prob vp9_kf_partition_probs[PARTITION_CONTEXTS]
[PARTITION_TYPES - 1];
extern const vp9_tree_index vp9_intra_mode_tree[TREE_SIZE(INTRA_MODES)]; extern const vp9_tree_index vp9_intra_mode_tree[TREE_SIZE(INTRA_MODES)];
extern struct vp9_token vp9_intra_mode_encodings[INTRA_MODES]; extern struct vp9_token vp9_intra_mode_encodings[INTRA_MODES];

View File

@ -41,7 +41,7 @@
typedef struct frame_contexts { typedef struct frame_contexts {
vp9_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1]; vp9_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1];
vp9_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1]; vp9_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
vp9_prob partition_prob[FRAME_TYPES][PARTITION_CONTEXTS][PARTITION_TYPES - 1]; vp9_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1];
vp9_coeff_probs_model coef_probs[TX_SIZES][BLOCK_TYPES]; vp9_coeff_probs_model coef_probs[TX_SIZES][BLOCK_TYPES];
vp9_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS] vp9_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
[SWITCHABLE_FILTERS - 1]; [SWITCHABLE_FILTERS - 1];
@ -245,6 +245,11 @@ static int mi_cols_aligned_to_sb(int n_mis) {
return ALIGN_POWER_OF_TWO(n_mis, MI_BLOCK_SIZE_LOG2); return ALIGN_POWER_OF_TWO(n_mis, MI_BLOCK_SIZE_LOG2);
} }
static INLINE const vp9_prob* get_partition_probs(VP9_COMMON *cm, int ctx) {
return cm->frame_type == KEY_FRAME ? vp9_kf_partition_probs[ctx]
: cm->fc.partition_prob[ctx];
}
static INLINE void set_skip_context( static INLINE void set_skip_context(
MACROBLOCKD *xd, MACROBLOCKD *xd,
ENTROPY_CONTEXT *above_context[MAX_MB_PLANE], ENTROPY_CONTEXT *above_context[MAX_MB_PLANE],

View File

@ -448,21 +448,30 @@ static void decode_modes_b(VP9_COMMON *const cm, MACROBLOCKD *const xd,
xd->corrupted |= vp9_reader_has_error(r); xd->corrupted |= vp9_reader_has_error(r);
} }
static PARTITION_TYPE read_partition(int hbs, int mi_rows, int mi_cols, static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, int hbs,
int mi_row, int mi_col, int mi_row, int mi_col, BLOCK_SIZE bsize,
vp9_prob probs[PARTITION_TYPES - 1],
vp9_reader *r) { vp9_reader *r) {
const int has_rows = (mi_row + hbs) < mi_rows; const int ctx = partition_plane_context(xd->above_seg_context,
const int has_cols = (mi_col + hbs) < mi_cols; xd->left_seg_context,
mi_row, mi_col, bsize);
const vp9_prob *const probs = get_partition_probs(cm, ctx);
const int has_rows = (mi_row + hbs) < cm->mi_rows;
const int has_cols = (mi_col + hbs) < cm->mi_cols;
PARTITION_TYPE p;
if (has_rows && has_cols) if (has_rows && has_cols)
return treed_read(r, vp9_partition_tree, probs); p = treed_read(r, vp9_partition_tree, probs);
else if (!has_rows && has_cols) else if (!has_rows && has_cols)
return vp9_read(r, probs[1]) ? PARTITION_SPLIT : PARTITION_HORZ; p = vp9_read(r, probs[1]) ? PARTITION_SPLIT : PARTITION_HORZ;
else if (has_rows && !has_cols) else if (has_rows && !has_cols)
return vp9_read(r, probs[2]) ? PARTITION_SPLIT : PARTITION_VERT; p = vp9_read(r, probs[2]) ? PARTITION_SPLIT : PARTITION_VERT;
else else
return PARTITION_SPLIT; p = PARTITION_SPLIT;
if (!cm->frame_parallel_decoding_mode)
++cm->counts.partition[ctx][p];
return p;
} }
static void decode_modes_sb(VP9_COMMON *const cm, MACROBLOCKD *const xd, static void decode_modes_sb(VP9_COMMON *const cm, MACROBLOCKD *const xd,
@ -472,19 +481,11 @@ static void decode_modes_sb(VP9_COMMON *const cm, MACROBLOCKD *const xd,
const int hbs = num_8x8_blocks_wide_lookup[bsize] / 2; const int hbs = num_8x8_blocks_wide_lookup[bsize] / 2;
PARTITION_TYPE partition; PARTITION_TYPE partition;
BLOCK_SIZE subsize; BLOCK_SIZE subsize;
int ctx;
if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
return; return;
ctx = partition_plane_context(xd->above_seg_context, xd->left_seg_context, partition = read_partition(cm, xd, hbs, mi_row, mi_col, bsize, r);
mi_row, mi_col, bsize);
partition = read_partition(hbs, cm->mi_rows, cm->mi_cols, mi_row, mi_col,
cm->fc.partition_prob[cm->frame_type][ctx], r);
if (!cm->frame_parallel_decoding_mode)
++cm->counts.partition[ctx][partition];
subsize = get_subsize(bsize, partition); subsize = get_subsize(bsize, partition);
if (subsize < BLOCK_8X8) { if (subsize < BLOCK_8X8) {
decode_modes_b(cm, xd, tile, mi_row, mi_col, r, subsize); decode_modes_b(cm, xd, tile, mi_row, mi_col, r, subsize);
@ -1209,7 +1210,7 @@ static int read_compressed_header(VP9D_COMP *pbi, const uint8_t *data,
for (j = 0; j < PARTITION_CONTEXTS; ++j) for (j = 0; j < PARTITION_CONTEXTS; ++j)
for (i = 0; i < PARTITION_TYPES - 1; ++i) for (i = 0; i < PARTITION_TYPES - 1; ++i)
vp9_diff_update_prob(&r, &fc->partition_prob[INTER_FRAME][j][i]); vp9_diff_update_prob(&r, &fc->partition_prob[j][i]);
read_mv_probs(&r, nmvc, cm->allow_high_precision_mv); read_mv_probs(&r, nmvc, cm->allow_high_precision_mv);
} }

View File

@ -578,25 +578,26 @@ static void write_modes_b(VP9_COMP *cpi, const TileInfo *const tile,
pack_mb_tokens(bc, tok, tok_end); pack_mb_tokens(bc, tok, tok_end);
} }
static void write_partition(PARTITION_TYPE partition, static void write_partition(VP9_COMP *cpi, int hbs, int mi_row, int mi_col,
int hbs, int mi_rows, int mi_cols, PARTITION_TYPE p, BLOCK_SIZE bsize, vp9_writer *w) {
int mi_row, int mi_col, VP9_COMMON *const cm = &cpi->common;
vp9_prob probs[PARTITION_TYPES - 1], const int ctx = partition_plane_context(cpi->above_seg_context,
vp9_writer *w) { cpi->left_seg_context,
const int has_rows = (mi_row + hbs) < mi_rows; mi_row, mi_col, bsize);
const int has_cols = (mi_col + hbs) < mi_cols; const vp9_prob *const probs = get_partition_probs(cm, ctx);
const int has_rows = (mi_row + hbs) < cm->mi_rows;
const int has_cols = (mi_col + hbs) < cm->mi_cols;
if (has_rows && has_cols) { if (has_rows && has_cols) {
write_token(w, vp9_partition_tree, probs, write_token(w, vp9_partition_tree, probs, &vp9_partition_encodings[p]);
&vp9_partition_encodings[partition]);
} else if (!has_rows && has_cols) { } else if (!has_rows && has_cols) {
assert(partition == PARTITION_SPLIT || partition == PARTITION_HORZ); assert(p == PARTITION_SPLIT || p == PARTITION_HORZ);
vp9_write(w, partition == PARTITION_SPLIT, probs[1]); vp9_write(w, p == PARTITION_SPLIT, probs[1]);
} else if (has_rows && !has_cols) { } else if (has_rows && !has_cols) {
assert(partition == PARTITION_SPLIT || partition == PARTITION_VERT); assert(p == PARTITION_SPLIT || p == PARTITION_VERT);
vp9_write(w, partition == PARTITION_SPLIT, probs[2]); vp9_write(w, p == PARTITION_SPLIT, probs[2]);
} else { } else {
assert(partition == PARTITION_SPLIT); assert(p == PARTITION_SPLIT);
} }
} }
@ -623,11 +624,7 @@ static void write_modes_sb(VP9_COMP *cpi, const TileInfo *const tile,
if (index > 0) if (index > 0)
return; return;
} else { } else {
const int ctx = partition_plane_context(cpi->above_seg_context, write_partition(cpi, bs, mi_row, mi_col, partition, bsize, bc);
cpi->left_seg_context,
mi_row, mi_col, bsize);
write_partition(partition, bs, cm->mi_rows, cm->mi_cols, mi_row, mi_col,
cm->fc.partition_prob[cm->frame_type][ctx], bc);
} }
subsize = get_subsize(bsize, partition); subsize = get_subsize(bsize, partition);
@ -1452,7 +1449,7 @@ static size_t write_compressed_header(VP9_COMP *cpi, uint8_t *data) {
for (i = 0; i < PARTITION_CONTEXTS; ++i) { for (i = 0; i < PARTITION_CONTEXTS; ++i) {
unsigned int bct[PARTITION_TYPES - 1][2]; unsigned int bct[PARTITION_TYPES - 1][2];
update_mode(&header_bc, PARTITION_TYPES, vp9_partition_tree, update_mode(&header_bc, PARTITION_TYPES, vp9_partition_tree,
fc->partition_prob[cm->frame_type][i], bct, fc->partition_prob[i], bct,
(unsigned int *)cpi->partition_count[i]); (unsigned int *)cpi->partition_count[i]);
} }

View File

@ -251,8 +251,7 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi) {
fill_token_costs(cpi->mb.token_costs, cm->fc.coef_probs); fill_token_costs(cpi->mb.token_costs, cm->fc.coef_probs);
for (i = 0; i < PARTITION_CONTEXTS; i++) for (i = 0; i < PARTITION_CONTEXTS; i++)
vp9_cost_tokens(cpi->mb.partition_cost[i], vp9_cost_tokens(cpi->mb.partition_cost[i], get_partition_probs(cm, i),
cm->fc.partition_prob[cm->frame_type][i],
vp9_partition_tree); vp9_partition_tree);
/*rough estimate for costing*/ /*rough estimate for costing*/