Better workaround for Bug 1089.

Don't initialize first pass costs for a number of symbols where first
pass probabilities aren't initialized.

This brings a 1.22x first pass speedup.

https://bugs.chromium.org/p/webm/issues/detail?id=1089

Change-Id: I97438c357bd88f52f5a15c697031cf0c3cc8f510
This commit is contained in:
Alex Converse 2016-02-17 13:39:44 -08:00
parent fdc977afc6
commit 09f9c5d7f9
4 changed files with 34 additions and 28 deletions

View File

@ -728,10 +728,8 @@ static const vp9_coeff_probs_model default_coef_probs_32x32[PLANE_TYPES] = {
}; };
static void extend_to_full_distribution(vpx_prob *probs, vpx_prob p) { static void extend_to_full_distribution(vpx_prob *probs, vpx_prob p) {
// TODO(aconverse): model[PIVOT_NODE] should never be zero. assert(p != 0);
// https://code.google.com/p/webm/issues/detail?id=1089 memcpy(probs, vp9_pareto8_full[p - 1], MODEL_NODES * sizeof(vpx_prob));
memcpy(probs, vp9_pareto8_full[p == 0 ? 254 : p - 1],
MODEL_NODES * sizeof(vpx_prob));
} }
void vp9_model_to_full_probs(const vpx_prob *model, vpx_prob *full) { void vp9_model_to_full_probs(const vpx_prob *model, vpx_prob *full) {

View File

@ -12,9 +12,8 @@
#include "vp9/encoder/vp9_cost.h" #include "vp9/encoder/vp9_cost.h"
/* round(-log2(i/256.) * (1 << VP9_PROB_COST_SHIFT)) /* round(-log2(i/256.) * (1 << VP9_PROB_COST_SHIFT))
Begins and ends with a bogus entry to satisfy use of prob=0 in the firstpass. Begins with a bogus entry for simpler addressing. */
https://code.google.com/p/webm/issues/detail?id=1089 */ const uint16_t vp9_prob_cost[256] = {
const uint16_t vp9_prob_cost[257] = {
4096, 4096, 3584, 3284, 3072, 2907, 2772, 2659, 2560, 2473, 2395, 2325, 4096, 4096, 3584, 3284, 3072, 2907, 2772, 2659, 2560, 2473, 2395, 2325,
2260, 2201, 2147, 2096, 2048, 2003, 1961, 1921, 1883, 1847, 1813, 1780, 2260, 2201, 2147, 2096, 2048, 2003, 1961, 1921, 1883, 1847, 1813, 1780,
1748, 1718, 1689, 1661, 1635, 1609, 1584, 1559, 1536, 1513, 1491, 1470, 1748, 1718, 1689, 1661, 1635, 1609, 1584, 1559, 1536, 1513, 1491, 1470,
@ -36,13 +35,14 @@ const uint16_t vp9_prob_cost[257] = {
125, 122, 119, 115, 112, 109, 105, 102, 99, 95, 92, 89, 125, 122, 119, 115, 112, 109, 105, 102, 99, 95, 92, 89,
86, 82, 79, 76, 73, 70, 66, 63, 60, 57, 54, 51, 86, 82, 79, 76, 73, 70, 66, 63, 60, 57, 54, 51,
48, 45, 42, 38, 35, 32, 29, 26, 23, 20, 18, 15, 48, 45, 42, 38, 35, 32, 29, 26, 23, 20, 18, 15,
12, 9, 6, 3, 3}; 12, 9, 6, 3};
static void cost(int *costs, vpx_tree tree, const vpx_prob *probs, static void cost(int *costs, vpx_tree tree, const vpx_prob *probs,
int i, int c) { int i, int c) {
const vpx_prob prob = probs[i / 2]; const vpx_prob prob = probs[i / 2];
int b; int b;
assert(prob != 0);
for (b = 0; b <= 1; ++b) { for (b = 0; b <= 1; ++b) {
const int cc = c + vp9_cost_bit(prob, b); const int cc = c + vp9_cost_bit(prob, b);
const vpx_tree_index ii = tree[i + b]; const vpx_tree_index ii = tree[i + b];

View File

@ -18,7 +18,7 @@
extern "C" { extern "C" {
#endif #endif
extern const uint16_t vp9_prob_cost[257]; extern const uint16_t vp9_prob_cost[256];
// The factor to scale from cost in bits to cost in vp9_prob_cost units. // The factor to scale from cost in bits to cost in vp9_prob_cost units.
#define VP9_PROB_COST_SHIFT 9 #define VP9_PROB_COST_SHIFT 9

View File

@ -286,6 +286,13 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi) {
set_block_thresholds(cm, rd); set_block_thresholds(cm, rd);
set_partition_probs(cm, xd); set_partition_probs(cm, xd);
if (cpi->oxcf.pass == 1) {
if (!frame_is_intra_only(cm))
vp9_build_nmv_cost_table(
x->nmvjointcost,
cm->allow_high_precision_mv ? x->nmvcost_hp : x->nmvcost,
&cm->fc->nmvc, cm->allow_high_precision_mv);
} else {
if (!cpi->sf.use_nonrd_pick_mode || cm->frame_type == KEY_FRAME) if (!cpi->sf.use_nonrd_pick_mode || cm->frame_type == KEY_FRAME)
fill_token_costs(x->token_costs, cm->fc->coef_probs); fill_token_costs(x->token_costs, cm->fc->coef_probs);
@ -301,9 +308,9 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi) {
fill_mode_costs(cpi); fill_mode_costs(cpi);
if (!frame_is_intra_only(cm)) { if (!frame_is_intra_only(cm)) {
vp9_build_nmv_cost_table(x->nmvjointcost, vp9_build_nmv_cost_table(
cm->allow_high_precision_mv ? x->nmvcost_hp x->nmvjointcost,
: x->nmvcost, cm->allow_high_precision_mv ? x->nmvcost_hp : x->nmvcost,
&cm->fc->nmvc, cm->allow_high_precision_mv); &cm->fc->nmvc, cm->allow_high_precision_mv);
for (i = 0; i < INTER_MODE_CONTEXTS; ++i) for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
@ -312,6 +319,7 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi) {
} }
} }
} }
}
static void model_rd_norm(int xsq_q10, int *r_q10, int *d_q10) { static void model_rd_norm(int xsq_q10, int *r_q10, int *d_q10) {
// NOTE: The tables below must be of the same size. // NOTE: The tables below must be of the same size.