Commit cc307515 authored by Jim Bankoski's avatar Jim Bankoski Committed by Gerrit Code Review
Browse files

Merge "WIP: Remove giant value cost table"

parents 8619274e b3c66f8a
......@@ -81,6 +81,7 @@ typedef struct {
const vp9_prob *prob;
int len;
int base_val;
const int16_t *cost;
} vp9_extra_bit;
// indexed by token value
......
......@@ -147,9 +147,15 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
int next = eob, sz = 0;
int64_t rdmult = mb->rdmult * plane_rd_mult[type], rddiv = mb->rddiv;
int64_t rd_cost0, rd_cost1;
int rate0, rate1, error0, error1, t0, t1;
int rate0, rate1, error0, error1;
int16_t t0, t1;
EXTRABIT e0;
int best, band, pt, i, final_eob;
const int16_t *dct_value_cost;
#if CONFIG_VP9_HIGHBITDEPTH
const int16_t *cat6_high_cost = vp9_get_high_cost_table(xd->bd);
#else
const int16_t *cat6_high_cost = vp9_get_high_cost_table(8);
#endif
assert((!type && !plane) || (type && plane));
assert(eob <= default_eob);
......@@ -166,17 +172,6 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
tokens[eob][0].qc = 0;
tokens[eob][1] = tokens[eob][0];
#if CONFIG_VP9_HIGHBITDEPTH
if (xd->bd == 12) {
dct_value_cost = vp9_dct_value_cost_high12_ptr;
} else if (xd->bd == 10) {
dct_value_cost = vp9_dct_value_cost_high10_ptr;
} else {
dct_value_cost = vp9_dct_value_cost_ptr;
}
#else
dct_value_cost = vp9_dct_value_cost_ptr;
#endif
for (i = 0; i < eob; i++)
token_cache[scan[i]] =
vp9_pt_energy_class[vp9_get_token(qcoeff[scan[i]])];
......@@ -193,7 +188,7 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
/* Evaluate the first possibility for this state. */
rate0 = tokens[next][0].rate;
rate1 = tokens[next][1].rate;
t0 = vp9_get_token(x);
vp9_get_token_extra(x, &t0, &e0);
/* Consider both possible successor states. */
if (next < default_eob) {
band = band_translate[i + 1];
......@@ -206,7 +201,7 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
UPDATE_RD_COST();
/* And pick the best. */
best = rd_cost1 < rd_cost0;
base_bits = dct_value_cost[x];
base_bits = vp9_get_cost(t0, e0, cat6_high_cost);
dx = mul * (dqcoeff[rc] - coeff[rc]);
#if CONFIG_VP9_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
......@@ -244,8 +239,10 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
*/
t0 = tokens[next][0].token == EOB_TOKEN ? EOB_TOKEN : ZERO_TOKEN;
t1 = tokens[next][1].token == EOB_TOKEN ? EOB_TOKEN : ZERO_TOKEN;
e0 = 0;
} else {
t0 = t1 = vp9_get_token(x);
vp9_get_token_extra(x, &t0, &e0);
t1 = t0;
}
if (next < default_eob) {
band = band_translate[i + 1];
......@@ -264,7 +261,7 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
UPDATE_RD_COST();
/* And pick the best. */
best = rd_cost1 < rd_cost0;
base_bits = dct_value_cost[x];
base_bits = vp9_get_cost(t0, e0, cat6_high_cost);
if (shortcut) {
#if CONFIG_VP9_HIGHBITDEPTH
......
......@@ -186,7 +186,6 @@ void vp9_initialize_enc(void) {
if (!init_done) {
vp9_rtcd();
vp9_init_intra_predictors();
vp9_tokenize_initialize();
vp9_init_me_luts();
vp9_rc_init_minq_luts();
vp9_entropy_mv_init();
......
......@@ -360,6 +360,12 @@ static INLINE int cost_coeffs(MACROBLOCK *x,
uint8_t token_cache[32 * 32];
int pt = combine_entropy_contexts(*A, *L);
int c, cost;
#if CONFIG_VP9_HIGHBITDEPTH
const int16_t *cat6_high_cost = vp9_get_high_cost_table(xd->bd);
#else
const int16_t *cat6_high_cost = vp9_get_high_cost_table(8);
#endif
// Check for consistency of tx_size with mode info
assert(type == PLANE_TYPE_Y ? mbmi->tx_size == tx_size
: get_uv_tx_size(mbmi, pd) == tx_size);
......@@ -373,23 +379,29 @@ static INLINE int cost_coeffs(MACROBLOCK *x,
// dc token
int v = qcoeff[0];
int prev_t = vp9_get_token(v);
cost = (*token_costs)[0][pt][prev_t] + vp9_dct_value_cost_ptr[v];
int16_t prev_t;
EXTRABIT e;
vp9_get_token_extra(v, &prev_t, &e);
cost = (*token_costs)[0][pt][prev_t] +
vp9_get_cost(prev_t, e, cat6_high_cost);
token_cache[0] = vp9_pt_energy_class[prev_t];
++token_costs;
// ac tokens
for (c = 1; c < eob; c++) {
const int rc = scan[c];
int t;
int16_t t;
v = qcoeff[rc];
t = vp9_get_token(v);
vp9_get_token_extra(v, &t, &e);
if (use_fast_coef_costing) {
cost += (*token_costs)[!prev_t][!prev_t][t] + vp9_dct_value_cost_ptr[v];
cost += (*token_costs)[!prev_t][!prev_t][t] +
vp9_get_cost(t, e, cat6_high_cost);
} else {
pt = get_coef_context(nb, token_cache, c);
cost += (*token_costs)[!prev_t][pt][t] + vp9_dct_value_cost_ptr[v];
cost += (*token_costs)[!prev_t][pt][t] +
vp9_get_cost(t, e, cat6_high_cost);
token_cache[rc] = vp9_pt_energy_class[t];
}
prev_t = t;
......
This diff is collapsed.
......@@ -20,8 +20,6 @@
extern "C" {
#endif
void vp9_tokenize_initialize();
#define EOSB_TOKEN 127 // Not signalled, encoder only
#if CONFIG_VP9_HIGHBITDEPTH
......@@ -63,11 +61,29 @@ extern const int16_t *vp9_dct_value_cost_ptr;
*/
extern const TOKENVALUE *vp9_dct_value_tokens_ptr;
extern const TOKENVALUE *vp9_dct_cat_lt_10_value_tokens;
extern const int16_t vp9_cat6_low_cost[256];
extern const int16_t vp9_cat6_high_cost[128];
extern const int16_t vp9_cat6_high10_high_cost[512];
extern const int16_t vp9_cat6_high12_high_cost[2048];
static INLINE int16_t vp9_get_cost(uint8_t token, EXTRABIT extrabits,
const int16_t *cat6_high_table) {
if (token != CATEGORY6_TOKEN)
return vp9_extra_bits[token].cost[extrabits];
return vp9_cat6_low_cost[extrabits & 0xff]
+ cat6_high_table[extrabits >> 8];
}
#if CONFIG_VP9_HIGHBITDEPTH
extern const int16_t *vp9_dct_value_cost_high10_ptr;
extern const TOKENVALUE *vp9_dct_value_tokens_high10_ptr;
extern const int16_t *vp9_dct_value_cost_high12_ptr;
extern const TOKENVALUE *vp9_dct_value_tokens_high12_ptr;
static INLINE const int16_t* vp9_get_high_cost_table(int bit_depth) {
return bit_depth == 8 ? vp9_cat6_high_cost
: (bit_depth == 10 ? vp9_cat6_high10_high_cost :
vp9_cat6_high12_high_cost);
}
#else
static INLINE const int16_t* vp9_get_high_cost_table(int bit_depth) {
(void) bit_depth;
return vp9_cat6_high_cost;
}
#endif // CONFIG_VP9_HIGHBITDEPTH
static INLINE void vp9_get_token_extra(int v, int16_t *token, EXTRABIT *extra) {
......
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