Commit e11f21af authored by Scott LaVarnway's avatar Scott LaVarnway

MODE_INFO size reduction

Declared the bmi in MODE_INFO as a union instead of B_MODE_INFO.
This reduced the memory footprint by 518,400 bytes for 1080
resolutions.  The decoder performance improved by ~4% for the
clip used and the encoder showed very small improvements. (0.5%)
This reduction was first mentioned to me by John K. and in a
later discussion by Yaowu.
This is WIP.

Change-Id: I8e175fdbc46d28c35277302a04bee4540efc8d29
parent 6d82d2d2
......@@ -165,14 +165,16 @@ typedef struct
unsigned char segment_id; /* Which set of segmentation parameters should be used for this MB */
} MB_MODE_INFO;
typedef struct
{
MB_MODE_INFO mbmi;
B_MODE_INFO bmi[16];
union
{
B_PREDICTION_MODE as_mode;
int_mv mv;
} bmi[16];
} MODE_INFO;
typedef struct
{
short *qcoeff;
......@@ -195,7 +197,6 @@ typedef struct
int eob;
B_MODE_INFO bmi;
} BLOCKD;
typedef struct
......@@ -279,4 +280,24 @@ typedef struct
extern void vp8_build_block_doffsets(MACROBLOCKD *x);
extern void vp8_setup_block_dptrs(MACROBLOCKD *x);
static void update_blockd_bmi(MACROBLOCKD *xd)
{
int i;
if (xd->mode_info_context->mbmi.mode == SPLITMV)
{
for (i = 0; i < 16; i++)
{
BLOCKD *d = &xd->block[i];
d->bmi.mv.as_int = xd->mode_info_context->bmi[i].mv.as_int;
}
}else if (xd->mode_info_context->mbmi.mode == B_PRED)
{
for (i = 0; i < 16; i++)
{
BLOCKD *d = &xd->block[i];
d->bmi.mode = xd->mode_info_context->bmi[i].as_mode;
}
}
}
#endif /* __INC_BLOCKD_H */
......@@ -97,7 +97,7 @@ void vp8_print_modes_and_motion_vectors(MODE_INFO *mi, int rows, int cols, int f
bindex = (b_row & 3) * 4 + (b_col & 3);
if (mi[mb_index].mbmi.mode == B_PRED)
fprintf(mvs, "%2d ", mi[mb_index].bmi[bindex].mode);
fprintf(mvs, "%2d ", mi[mb_index].bmi[bindex].as_mode);
else
fprintf(mvs, "xx ");
......
......@@ -153,26 +153,3 @@ vp8_prob *vp8_mv_ref_probs(
return p;
}
const B_MODE_INFO *vp8_left_bmi(const MODE_INFO *cur_mb, int b)
{
if (!(b & 3))
{
/* On L edge, get from MB to left of us */
--cur_mb;
b += 4;
}
return cur_mb->bmi + b - 1;
}
const B_MODE_INFO *vp8_above_bmi(const MODE_INFO *cur_mb, int b, int mi_stride)
{
if (!(b >> 2))
{
/* On top edge, get from MB above us */
cur_mb -= mi_stride;
b += 16;
}
return cur_mb->bmi + b - 4;
}
......@@ -85,10 +85,60 @@ vp8_prob *vp8_mv_ref_probs(
vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
);
const B_MODE_INFO *vp8_left_bmi(const MODE_INFO *cur_mb, int b);
extern const unsigned char vp8_mbsplit_offset[4][16];
const B_MODE_INFO *vp8_above_bmi(const MODE_INFO *cur_mb, int b, int mi_stride);
extern const unsigned char vp8_mbsplit_offset[4][16];
static int left_block_mv(const MODE_INFO *cur_mb, int b)
{
if (!(b & 3))
{
/* On L edge, get from MB to left of us */
--cur_mb;
if(cur_mb->mbmi.mode != SPLITMV)
return cur_mb->mbmi.mv.as_int;
b += 4;
}
return (cur_mb->bmi + b - 1)->mv.as_int;
}
static int above_block_mv(const MODE_INFO *cur_mb, int b, int mi_stride)
{
if (!(b >> 2))
{
/* On top edge, get from MB above us */
cur_mb -= mi_stride;
if(cur_mb->mbmi.mode != SPLITMV)
return cur_mb->mbmi.mv.as_int;
b += 16;
}
return (cur_mb->bmi + b - 4)->mv.as_int;
}
static B_PREDICTION_MODE left_block_mode(const MODE_INFO *cur_mb, int b)
{
if (!(b & 3))
{
/* On L edge, get from MB to left of us */
--cur_mb;
b += 4;
}
return (cur_mb->bmi + b - 1)->as_mode;
}
static B_PREDICTION_MODE above_block_mode(const MODE_INFO *cur_mb, int b, int mi_stride)
{
if (!(b >> 2))
{
/* On top edge, get from MB above us */
cur_mb -= mi_stride;
b += 16;
}
return (cur_mb->bmi + b - 4)->as_mode;
}
#endif
......@@ -94,10 +94,10 @@ static void vp8_kfread_modes(VP8D_COMP *pbi, MODE_INFO *m, int mb_row, int mb_co
do
{
const B_PREDICTION_MODE A = vp8_above_bmi(m, i, mis)->mode;
const B_PREDICTION_MODE L = vp8_left_bmi(m, i)->mode;
const B_PREDICTION_MODE A = above_block_mode(m, i, mis);
const B_PREDICTION_MODE L = left_block_mode(m, i);
m->bmi[i].mode = (B_PREDICTION_MODE) vp8_read_bmode(bc, pbi->common.kf_bmode_prob [A] [L]);
m->bmi[i].as_mode = (B_PREDICTION_MODE) vp8_read_bmode(bc, pbi->common.kf_bmode_prob [A] [L]);
}
while (++i < 16);
}
......@@ -127,7 +127,7 @@ static void vp8_kfread_modes(VP8D_COMP *pbi, MODE_INFO *m, int mb_row, int mb_co
do
{
m->bmi[i].mode = (B_PREDICTION_MODE)BMode;
m->bmi[i].as_mode = (B_PREDICTION_MODE)BMode;
}
while (++i < 16);
}
......@@ -354,12 +354,15 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
do /* for each subset j */
{
int_mv leftmv, abovemv;
B_MODE_INFO bmi;
int k; /* first block in subset j */
int mv_contz;
k = vp8_mbsplit_offset[s][j];
mv_contz = vp8_mv_cont(&(vp8_left_bmi(mi, k)->mv.as_mv), &(vp8_above_bmi(mi, k, mis)->mv.as_mv));
leftmv.as_int = left_block_mv(mi, k);
abovemv.as_int = above_block_mv(mi, k, mis);
mv_contz = vp8_mv_cont(&(leftmv.as_mv), &(abovemv.as_mv));
switch (bmi.mode = (B_PREDICTION_MODE) sub_mv_ref(bc, vp8_sub_mv_ref_prob2 [mv_contz])) /*pc->fc.sub_mv_ref_prob))*/
{
......@@ -372,13 +375,13 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
#endif
break;
case LEFT4X4:
bmi.mv.as_int = vp8_left_bmi(mi, k)->mv.as_int;
bmi.mv.as_int = leftmv.as_int;
#ifdef VPX_MODE_COUNT
vp8_mv_cont_count[mv_contz][0]++;
#endif
break;
case ABOVE4X4:
bmi.mv.as_int = vp8_above_bmi(mi, k, mis)->mv.as_int;
bmi.mv.as_int = abovemv.as_int;
#ifdef VPX_MODE_COUNT
vp8_mv_cont_count[mv_contz][1]++;
#endif
......@@ -409,9 +412,8 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
fill_offset = &mbsplit_fill_offset[s][(unsigned char)j * mbsplit_fill_count[s]];
do {
mi->bmi[ *fill_offset] = bmi;
mi->bmi[ *fill_offset].mv.as_int = bmi.mv.as_int;
fill_offset++;
}while (--fill_count);
}
......@@ -485,20 +487,16 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
}
else
{
/* MB is intra coded */
int j = 0;
do
{
mi->bmi[j].mv.as_int = 0;
}
while (++j < 16);
/* required for left and above block mv */
mbmi->mv.as_int = 0;
/* MB is intra coded */
if ((mbmi->mode = (MB_PREDICTION_MODE) vp8_read_ymode(bc, pbi->common.fc.ymode_prob)) == B_PRED)
{
j = 0;
int j = 0;
do
{
mi->bmi[j].mode = (B_PREDICTION_MODE)vp8_read_bmode(bc, pbi->common.fc.bmode_prob);
mi->bmi[j].as_mode = (B_PREDICTION_MODE)vp8_read_bmode(bc, pbi->common.fc.bmode_prob);
}
while (++j < 16);
}
......
......@@ -399,14 +399,7 @@ decode_mb_row(VP8D_COMP *pbi, VP8_COMMON *pc, int mb_row, MACROBLOCKD *xd)
}
#endif
if (xd->mode_info_context->mbmi.mode == SPLITMV || xd->mode_info_context->mbmi.mode == B_PRED)
{
for (i = 0; i < 16; i++)
{
BLOCKD *d = &xd->block[i];
vpx_memcpy(&d->bmi, &xd->mode_info_context->bmi[i], sizeof(B_MODE_INFO));
}
}
update_blockd_bmi(xd);
xd->dst.y_buffer = pc->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
xd->dst.u_buffer = pc->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
......
......@@ -187,7 +187,6 @@ static void decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd, int mb_row, int m
{
BLOCKD *b = &xd->block[i];
vp8mt_predict_intra4x4(pbi, xd, b->bmi.mode, b->predictor, mb_row, mb_col, i);
if (xd->eobs[i] > 1)
{
DEQUANT_INVOKE(&pbi->dequant, idct_add)
......@@ -288,14 +287,7 @@ static THREAD_FUNCTION thread_decoding_proc(void *p_data)
}
}
if (xd->mode_info_context->mbmi.mode == SPLITMV || xd->mode_info_context->mbmi.mode == B_PRED)
{
for (i = 0; i < 16; i++)
{
BLOCKD *d = &xd->block[i];
vpx_memcpy(&d->bmi, &xd->mode_info_context->bmi[i], sizeof(B_MODE_INFO));
}
}
update_blockd_bmi(xd);
/* Distance of Mb to the various image edges.
* These are specified to 8th pel as they are always compared to values that are in 1/8th pel units
......@@ -776,14 +768,7 @@ void vp8mt_decode_mb_rows( VP8D_COMP *pbi, MACROBLOCKD *xd)
}
}
if (xd->mode_info_context->mbmi.mode == SPLITMV || xd->mode_info_context->mbmi.mode == B_PRED)
{
for (i = 0; i < 16; i++)
{
BLOCKD *d = &xd->block[i];
vpx_memcpy(&d->bmi, &xd->mode_info_context->bmi[i], sizeof(B_MODE_INFO));
}
}
update_blockd_bmi(xd);
/* Distance of Mb to the various image edges.
* These are specified to 8th pel as they are always compared to values that are in 1/8th pel units
......
......@@ -948,8 +948,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
int j = 0;
do
write_bmode(w, m->bmi[j].mode, pc->fc.bmode_prob);
write_bmode(w, m->bmi[j].as_mode, pc->fc.bmode_prob);
while (++j < 16);
}
......@@ -1016,14 +1015,16 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
const int *const L = vp8_mbsplits [mi->partitioning];
int k = -1; /* first block in subset j */
int mv_contz;
int_mv leftmv, abovemv;
while (j != L[++k])
if (k >= 16)
assert(0);
leftmv.as_int = left_block_mv(m, k);
abovemv.as_int = above_block_mv(m, k, mis);
mv_contz = vp8_mv_cont(&(leftmv.as_mv), &(abovemv.as_mv));
mv_contz = vp8_mv_cont
(&(vp8_left_bmi(m, k)->mv.as_mv),
&(vp8_above_bmi(m, k, mis)->mv.as_mv));
write_sub_mv_ref(w, b->mode, vp8_sub_mv_ref_prob2 [mv_contz]); //pc->fc.sub_mv_ref_prob);
if (b->mode == NEW4X4)
......@@ -1099,9 +1100,9 @@ static void write_kfmodes(VP8_COMP *cpi)
do
{
const B_PREDICTION_MODE A = vp8_above_bmi(m, i, mis)->mode;
const B_PREDICTION_MODE L = vp8_left_bmi(m, i)->mode;
const int bm = m->bmi[i].mode;
const B_PREDICTION_MODE A = above_block_mode(m, i, mis);
const B_PREDICTION_MODE L = left_block_mode(m, i);
const int bm = m->bmi[i].as_mode;
#ifdef ENTROPY_STATS
++intra_mode_stats [A] [L] [bm];
......
......@@ -477,8 +477,24 @@ void encode_mb_row(VP8_COMP *cpi,
x->mb_activity_ptr++;
x->mb_norm_activity_ptr++;
for (i = 0; i < 16; i++)
vpx_memcpy(&xd->mode_info_context->bmi[i], &xd->block[i].bmi, sizeof(xd->block[i].bmi));
if(cm->frame_type != INTRA_FRAME)
{
if (xd->mode_info_context->mbmi.mode != B_PRED)
{
for (i = 0; i < 16; i++)
xd->mode_info_context->bmi[i].mv.as_int = xd->block[i].bmi.mv.as_int;
}else
{
for (i = 0; i < 16; i++)
xd->mode_info_context->bmi[i].as_mode = xd->block[i].bmi.mode;
}
}
else
{
if(xd->mode_info_context->mbmi.mode != B_PRED)
for (i = 0; i < 16; i++)
xd->mode_info_context->bmi[i].as_mode = xd->block[i].bmi.mode;
}
// adjust to the next column of macroblocks
x->src.y_buffer += 16;
......
......@@ -88,7 +88,6 @@ void vp8_encode_intra16x16mby(const VP8_ENCODER_RTCD *rtcd, MACROBLOCK *x)
switch (x->e_mbd.mode_info_context->mbmi.mode)
{
case DC_PRED:
d->bmi.mode = B_DC_PRED;
break;
......@@ -104,7 +103,6 @@ void vp8_encode_intra16x16mby(const VP8_ENCODER_RTCD *rtcd, MACROBLOCK *x)
default:
d->bmi.mode = B_DC_PRED;
break;
}
}
}
......
......@@ -234,8 +234,23 @@ THREAD_FUNCTION thread_encoding_proc(void *p_data)
x->mb_activity_ptr++;
x->mb_norm_activity_ptr++;
for (i = 0; i < 16; i++)
vpx_memcpy(&xd->mode_info_context->bmi[i], &xd->block[i].bmi, sizeof(xd->block[i].bmi));
if(cm->frame_type != INTRA_FRAME)
{
if (xd->mode_info_context->mbmi.mode != B_PRED)
{
for (i = 0; i < 16; i++)
xd->mode_info_context->bmi[i].mv.as_int = xd->block[i].bmi.mv.as_int;
}else
{
for (i = 0; i < 16; i++)
xd->mode_info_context->bmi[i].as_mode = xd->block[i].bmi.mode;
}
}
else {
if(xd->mode_info_context->mbmi.mode != B_PRED)
for (i = 0; i < 16; i++)
xd->mode_info_context->bmi[i].as_mode = xd->block[i].bmi.mode;
}
// adjust to the next column of macroblocks
x->src.y_buffer += 16;
......
......@@ -214,7 +214,6 @@ static int pick_intra4x4block(
*best_mode = mode;
}
}
b->bmi.mode = (B_PREDICTION_MODE)(*best_mode);
vp8_encode_intra4x4block(rtcd, x, ib);
return best_rd;
......@@ -241,8 +240,9 @@ int vp8_pick_intra4x4mby_modes
{
MODE_INFO *const mic = xd->mode_info_context;
const int mis = xd->mode_info_stride;
const B_PREDICTION_MODE A = vp8_above_bmi(mic, i, mis)->mode;
const B_PREDICTION_MODE L = vp8_left_bmi(mic, i)->mode;
const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
const B_PREDICTION_MODE L = left_block_mode(mic, i);
B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(d);
......@@ -250,8 +250,7 @@ int vp8_pick_intra4x4mby_modes
cost += r;
distortion += d;
mic->bmi[i].mode = xd->block[i].bmi.mode = best_mode;
mic->bmi[i].as_mode = xd->block[i].bmi.mode = best_mode;
// Break out case where we have already exceeded best so far value
// that was passed in
......@@ -272,9 +271,6 @@ int vp8_pick_intra4x4mby_modes
error = INT_MAX;
}
for (i = 0; i < 16; i++)
xd->block[i].bmi.mv.as_int = 0;
return error;
}
......@@ -432,9 +428,9 @@ static void update_mvcount(VP8_COMP *cpi, MACROBLOCKD *xd, int_mv *best_ref_mv)
* therefore, only need to modify MVcount in NEWMV mode. */
if (xd->mode_info_context->mbmi.mode == NEWMV)
{
cpi->MVcount[0][mv_max+((xd->block[0].bmi.mv.as_mv.row -
cpi->MVcount[0][mv_max+((xd->mode_info_context->mbmi.mv.as_mv.row -
best_ref_mv->as_mv.row) >> 1)]++;
cpi->MVcount[1][mv_max+((xd->block[0].bmi.mv.as_mv.col -
cpi->MVcount[1][mv_max+((xd->mode_info_context->mbmi.mv.as_mv.col -
best_ref_mv->as_mv.col) >> 1)]++;
}
}
......@@ -966,11 +962,11 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
// macroblock modes
vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_INFO));
if (x->e_mbd.mode_info_context->mbmi.mode == B_PRED)
if (x->e_mbd.mode_info_context->mbmi.mode <= B_PRED)
for (i = 0; i < 16; i++)
{
vpx_memcpy(&x->e_mbd.block[i].bmi, &best_bmodes[i], sizeof(B_MODE_INFO));
x->e_mbd.block[i].bmi.mode = best_bmodes[i].mode;
}
else
{
......
......@@ -646,7 +646,6 @@ static int rd_pick_intra4x4block(
vpx_memcpy(best_dqcoeff, b->dqcoeff, 32);
}
}
b->bmi.mode = (B_PREDICTION_MODE)(*best_mode);
IDCT_INVOKE(IF_RTCD(&cpi->rtcd.common->idct), idct16)(best_dqcoeff, b->diff, 32);
......@@ -688,8 +687,8 @@ int vp8_rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate,
if (mb->e_mbd.frame_type == KEY_FRAME)
{
const B_PREDICTION_MODE A = vp8_above_bmi(mic, i, mis)->mode;
const B_PREDICTION_MODE L = vp8_left_bmi(mic, i)->mode;
const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
const B_PREDICTION_MODE L = left_block_mode(mic, i);
bmode_costs = mb->bmode_costs[A][L];
}
......@@ -702,7 +701,8 @@ int vp8_rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate,
cost += r;
distortion += d;
tot_rate_y += ry;
mic->bmi[i].mode = xd->block[i].bmi.mode = best_mode;
mic->bmi[i].as_mode = best_mode;
if(total_rd >= (long long)best_rd)
break;
......@@ -850,17 +850,8 @@ int vp8_cost_mv_ref(MB_PREDICTION_MODE m, const int near_mv_ref_ct[4])
void vp8_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, int_mv *mv)
{
int i;
x->e_mbd.mode_info_context->mbmi.mode = mb;
x->e_mbd.mode_info_context->mbmi.mv.as_int = mv->as_int;
for (i = 0; i < 16; i++)
{
B_MODE_INFO *bmi = &x->e_mbd.block[i].bmi;
bmi->mode = (B_PREDICTION_MODE) mb;
bmi->mv.as_int = mv->as_int;
}
}
static int labels2mode(
......@@ -908,10 +899,10 @@ static int labels2mode(
thismvcost = vp8_mv_bit_cost(this_mv, best_ref_mv, mvcost, 102);
break;
case LEFT4X4:
this_mv->as_int = col ? d[-1].bmi.mv.as_int : vp8_left_bmi(mic, i)->mv.as_int;
this_mv->as_int = col ? d[-1].bmi.mv.as_int : left_block_mv(mic, i);
break;
case ABOVE4X4:
this_mv->as_int = row ? d[-4].bmi.mv.as_int : vp8_above_bmi(mic, i, mis)->mv.as_int;
this_mv->as_int = row ? d[-4].bmi.mv.as_int : above_block_mv(mic, i, mis);
break;
case ZERO4X4:
this_mv->as_int = 0;
......@@ -923,8 +914,9 @@ static int labels2mode(
if (m == ABOVE4X4) // replace above with left if same
{
int_mv left_mv;
left_mv.as_int = col ? d[-1].bmi.mv.as_int :
vp8_left_bmi(mic, i)->mv.as_int;
left_block_mv(mic, i);
if (left_mv.as_int == this_mv->as_int)
m = LEFT4X4;
......@@ -1408,6 +1400,7 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
BLOCKD *bd = &x->e_mbd.block[i];
bd->bmi.mv.as_mv = bsi.mvs[i].as_mv;
bd->bmi.mode = bsi.modes[i];
bd->eob = bsi.eobs[i];
}
......@@ -2317,6 +2310,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
if (this_mode <= B_PRED)
{
x->e_mbd.mode_info_context->mbmi.uv_mode = uv_intra_mode;
/* required for left and above block mv */
x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
}
other_cost += ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame];
......@@ -2408,27 +2403,22 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
return;
}
if(best_mbmode.mode <= B_PRED)
{
int i;
for (i = 0; i < 16; i++)
{
best_bmodes[i].mv.as_int = 0;
}
}
// macroblock modes
vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_INFO));
for (i = 0; i < 16; i++)
if (best_mbmode.mode == B_PRED)
{
vpx_memcpy(&x->e_mbd.block[i].bmi, &best_bmodes[i], sizeof(B_MODE_INFO));
for (i = 0; i < 16; i++)
x->e_mbd.block[i].bmi.mode = best_bmodes[i].mode;
}
if (best_mbmode.mode == SPLITMV)
{
for (i = 0; i < 16; i++)
x->e_mbd.block[i].bmi.mv.as_int = best_bmodes[i].mv.as_int;
vpx_memcpy(x->partition_info, &best_partition, sizeof(PARTITION_INFO));
x->e_mbd.mode_info_context->mbmi.mv.as_int =
x->partition_info->bmi[15].mv.as_int;
}
......
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