Commit cad9fb52 authored by Hui Su's avatar Hui Su

Do not allocate leaf nodes in pc tree when CB4x4 is on

Change-Id: Idbde50deab816b669ca362e3e739c76a7f434f2c
parent 8efee2f5
......@@ -197,8 +197,6 @@ static void free_tree_contexts(PC_TREE *tree) {
// represents the state of our search.
void av1_setup_pc_tree(AV1_COMMON *cm, ThreadData *td) {
int i, j;
// TODO(jingning): The pc_tree allocation is redundant. We can take out all
// the leaf nodes after cb4x4 mode is enabled.
#if CONFIG_CB4X4
#if CONFIG_EXT_PARTITION
const int tree_nodes_inc = 1024;
......@@ -219,20 +217,21 @@ void av1_setup_pc_tree(AV1_COMMON *cm, ThreadData *td) {
#endif // CONFIG_EXT_PARTITION
int pc_tree_index = 0;
PC_TREE *this_pc;
PICK_MODE_CONTEXT *this_leaf;
int square_index = 1;
int nodes;
#if !CONFIG_CB4X4
aom_free(td->leaf_tree);
CHECK_MEM_ERROR(cm, td->leaf_tree,
aom_calloc(leaf_nodes, sizeof(*td->leaf_tree)));
PICK_MODE_CONTEXT *this_leaf = &td->leaf_tree[0];
#endif
aom_free(td->pc_tree);
CHECK_MEM_ERROR(cm, td->pc_tree,
aom_calloc(tree_nodes, sizeof(*td->pc_tree)));
this_pc = &td->pc_tree[0];
this_leaf = &td->leaf_tree[0];
#if !CONFIG_CB4X4
// 4x4 blocks smaller than 8x8 but in the same 8x8 block share the same
// context so we only need to allocate 1 for each 8x8 block.
for (i = 0; i < leaf_nodes; ++i) {
......@@ -242,6 +241,7 @@ void av1_setup_pc_tree(AV1_COMMON *cm, ThreadData *td) {
alloc_mode_context(cm, 16, &td->leaf_tree[i]);
#endif
}
#endif
// Sets up all the leaf nodes in the tree.
for (pc_tree_index = 0; pc_tree_index < leaf_nodes; ++pc_tree_index) {
......@@ -252,8 +252,10 @@ void av1_setup_pc_tree(AV1_COMMON *cm, ThreadData *td) {
#else
alloc_tree_contexts(cm, tree, 4);
#endif
#if !CONFIG_CB4X4
tree->leaf_split[0] = this_leaf++;
for (j = 1; j < 4; j++) tree->leaf_split[j] = tree->leaf_split[0];
#endif
}
// Each node has 4 leaf nodes, fill each block_size level of the tree
......@@ -291,29 +293,28 @@ void av1_free_pc_tree(ThreadData *td) {
#else
const int tree_nodes_inc = 256;
#endif // CONFIG_EXT_PARTITION
const int leaf_factor = 4;
#else
const int tree_nodes_inc = 0;
const int leaf_factor = 1;
#endif
#if CONFIG_EXT_PARTITION
const int leaf_nodes = 256 * leaf_factor;
const int tree_nodes = tree_nodes_inc + 256 + 64 + 16 + 4 + 1;
#else
const int leaf_nodes = 64 * leaf_factor;
const int tree_nodes = tree_nodes_inc + 64 + 16 + 4 + 1;
#endif // CONFIG_EXT_PARTITION
int i;
// Set up all 4x4 mode contexts
for (i = 0; i < leaf_nodes; ++i) free_mode_context(&td->leaf_tree[i]);
// Sets up all the leaf nodes in the tree.
for (i = 0; i < tree_nodes; ++i) free_tree_contexts(&td->pc_tree[i]);
aom_free(td->pc_tree);
td->pc_tree = NULL;
#if !CONFIG_CB4X4
const int leaf_factor = 1;
#if CONFIG_EXT_PARTITION
const int leaf_nodes = 256 * leaf_factor;
#else
const int leaf_nodes = 64 * leaf_factor;
#endif // CONFIG_EXT_PARTITION
for (i = 0; i < leaf_nodes; ++i) free_mode_context(&td->leaf_tree[i]);
aom_free(td->leaf_tree);
td->leaf_tree = NULL;
#endif
}
......@@ -85,6 +85,7 @@ typedef struct PC_TREE {
PICK_MODE_CONTEXT horizontal4[4];
PICK_MODE_CONTEXT vertical4[4];
#endif
// TODO(jingning): remove leaf_split[] when cb4x4 experiment flag is removed.
union {
struct PC_TREE *split[4];
PICK_MODE_CONTEXT *leaf_split[4];
......
......@@ -4524,8 +4524,10 @@ static void encode_rd_sb_row(AV1_COMP *cpi, ThreadData *td,
#endif
if (sf->adaptive_pred_interp_filter) {
#if !CONFIG_CB4X4
for (i = 0; i < leaf_nodes; ++i)
td->leaf_tree[i].pred_interp_filter = SWITCHABLE;
#endif
for (i = 0; i < leaf_nodes; ++i) {
td->pc_tree[i].vertical[0].pred_interp_filter = SWITCHABLE;
......
......@@ -339,8 +339,9 @@ typedef struct ThreadData {
MACROBLOCK mb;
RD_COUNTS rd_counts;
FRAME_COUNTS *counts;
#if !CONFIG_CB4X4
PICK_MODE_CONTEXT *leaf_tree;
#endif
PC_TREE *pc_tree;
PC_TREE *pc_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1];
#if CONFIG_MOTION_VAR
......
......@@ -81,8 +81,10 @@ void av1_encode_tiles_mt(AV1_COMP *cpi) {
aom_memalign(32, sizeof(*thread_data->td)));
av1_zero(*thread_data->td);
// Set up pc_tree.
// Set up pc_tree.
#if !CONFIG_CB4X4
thread_data->td->leaf_tree = NULL;
#endif
thread_data->td->pc_tree = NULL;
av1_setup_pc_tree(cm, thread_data->td);
......
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