Commit d5d9b6ca authored by Alex Converse's avatar Alex Converse

intrabc: Fix mode and MV cost

objective-1-fast 1st KF: -0.07 BDRATE-PSNR
twitch-1 1st KF: -0.04 BDRATE-PSNR

Change-Id: I089900514c40f3b8b77708dac2c8bfbce2f540ff
parent 6b2584c6
......@@ -74,7 +74,7 @@ static void encode_mv_component(aom_writer *w, int comp, nmv_component *mvcomp,
static void build_nmv_component_cost_table(int *mvcost,
const nmv_component *const mvcomp,
int usehp) {
MvSubpelPrecision precision) {
int i, v;
int sign_cost[2], class_cost[MV_CLASSES], class0_cost[CLASS0_SIZE];
int bits_cost[MV_OFFSET_BITS][2];
......@@ -94,7 +94,7 @@ static void build_nmv_component_cost_table(int *mvcost,
av1_cost_tokens(class0_fp_cost[i], mvcomp->class0_fp[i], av1_mv_fp_tree);
av1_cost_tokens(fp_cost, mvcomp->fp, av1_mv_fp_tree);
if (usehp) {
if (precision > MV_SUBPEL_LOW_PRECISION) {
class0_hp_cost[0] = av1_cost_zero(mvcomp->class0_hp);
class0_hp_cost[1] = av1_cost_one(mvcomp->class0_hp);
hp_cost[0] = av1_cost_zero(mvcomp->hp);
......@@ -115,16 +115,21 @@ static void build_nmv_component_cost_table(int *mvcost,
const int b = c + CLASS0_BITS - 1; /* number of bits */
for (i = 0; i < b; ++i) cost += bits_cost[i][((d >> i) & 1)];
}
if (c == MV_CLASS_0) {
cost += class0_fp_cost[d][f];
} else {
cost += fp_cost[f];
}
if (usehp) {
#if CONFIG_INTRABC
if (precision > MV_SUBPEL_NONE)
#endif // CONFIG_INTRABC
{
if (c == MV_CLASS_0) {
cost += class0_hp_cost[e];
cost += class0_fp_cost[d][f];
} else {
cost += hp_cost[e];
cost += fp_cost[f];
}
if (precision > MV_SUBPEL_LOW_PRECISION) {
if (c == MV_CLASS_0) {
cost += class0_hp_cost[e];
} else {
cost += hp_cost[e];
}
}
}
mvcost[v] = cost + sign_cost[0];
......@@ -243,10 +248,11 @@ void av1_encode_dv(aom_writer *w, const MV *mv, const MV *ref,
#endif // CONFIG_INTRABC
void av1_build_nmv_cost_table(int *mvjoint, int *mvcost[2],
const nmv_context *ctx, int usehp) {
const nmv_context *ctx,
MvSubpelPrecision precision) {
av1_cost_tokens(mvjoint, ctx->joints, av1_mv_joint_tree);
build_nmv_component_cost_table(mvcost[0], &ctx->comps[0], usehp);
build_nmv_component_cost_table(mvcost[1], &ctx->comps[1], usehp);
build_nmv_component_cost_table(mvcost[0], &ctx->comps[0], precision);
build_nmv_component_cost_table(mvcost[1], &ctx->comps[1], precision);
}
#if CONFIG_EXT_INTER
......
......@@ -27,7 +27,8 @@ void av1_encode_mv(AV1_COMP *cpi, aom_writer *w, const MV *mv, const MV *ref,
nmv_context *mvctx, int usehp);
void av1_build_nmv_cost_table(int *mvjoint, int *mvcost[2],
const nmv_context *mvctx, int usehp);
const nmv_context *mvctx,
MvSubpelPrecision precision);
void av1_update_mv_count(ThreadData *td);
......
......@@ -367,6 +367,16 @@ void av1_initialize_rd_consts(AV1_COMP *cpi) {
x->mvcost = x->mv_cost_stack[0];
x->nmvjointcost = x->nmv_vec_cost[0];
#if CONFIG_INTRABC
if (frame_is_intra_only(cm) && cm->allow_screen_content_tools &&
cpi->oxcf.pass != 1) {
av1_build_nmv_cost_table(
x->nmv_vec_cost[0],
cm->allow_high_precision_mv ? x->nmvcost_hp[0] : x->nmvcost[0],
&cm->fc->ndvc, MV_SUBPEL_NONE);
}
#endif
if (cpi->oxcf.pass != 1) {
av1_fill_token_costs(x->token_costs, cm->fc->coef_probs);
......
......@@ -8232,12 +8232,12 @@ static int64_t rd_pick_intrabc_mode_sb(const AV1_COMP *cpi, MACROBLOCK *x,
x->skip = 0;
av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, bsize);
assert(x->mvcost == x->mv_cost_stack[0]);
// TODO(aconverse@google.com): The full motion field defining discount
// in MV_COST_WEIGHT is too large. Explore other values.
int rate_mv = av1_mv_bit_cost(&dv, &dv_ref.as_mv, x->nmvjointcost,
x->mvcost, MV_COST_WEIGHT);
const PREDICTION_MODE A = av1_above_block_mode(mi, xd->above_mi, 0);
const PREDICTION_MODE L = av1_left_block_mode(mi, xd->left_mi, 0);
const int rate_mode = cpi->y_mode_costs[A][L][DC_PRED] +
av1_cost_bit(ec_ctx->intrabc_prob, 1);
x->mvcost, MV_COST_WEIGHT_SUB);
const int rate_mode = av1_cost_bit(ec_ctx->intrabc_prob, 1);
RD_STATS rd_stats, rd_stats_uv;
av1_subtract_plane(x, bsize, 0);
......
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