shithub: libvpx

Download patch

ref: 2f28f9072e30f04cd16395733c8e6adc19b1a358
parent: 44354ee7bfa01caf97e6c0a92c4a39c474fa5a7e
author: Jingning Han <jingning@google.com>
date: Wed Jul 6 09:56:02 EDT 2016

Enable coeff optimization for intra modes

This further improves the coding performance by
lowres 0.3%
midres 0.5%
hdres  0.6%

Change-Id: I6a03b6da210b9cbc261474bad4a103e0ba021c68

--- a/vp9/encoder/vp9_encodemb.c
+++ b/vp9/encoder/vp9_encodemb.c
@@ -643,7 +643,6 @@
   struct encode_b_args *const args = arg;
   MACROBLOCK *const x = args->x;
   MACROBLOCKD *const xd = &x->e_mbd;
-  struct optimize_ctx *const ctx = args->ctx;
   struct macroblock_plane *const p = &x->plane[plane];
   struct macroblockd_plane *const pd = &xd->plane[plane];
   tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
@@ -650,8 +649,8 @@
   uint8_t *dst;
   ENTROPY_CONTEXT *a, *l;
   dst = &pd->dst.buf[4 * row * pd->dst.stride + 4 * col];
-  a = &ctx->ta[plane][col];
-  l = &ctx->tl[plane][row];
+  a = &args->ta[col];
+  l = &args->tl[row];
 
   // TODO(jingning): per transformed block zero forcing only enabled for
   // luma component. will integrate chroma components as well.
@@ -790,7 +789,7 @@
   MACROBLOCKD *const xd = &x->e_mbd;
   struct optimize_ctx ctx;
   MODE_INFO *mi = xd->mi[0];
-  struct encode_b_args arg = {x, &ctx, &mi->skip};
+  struct encode_b_args arg = {x, 1, NULL, NULL, &mi->skip};
   int plane;
 
   mi->skip = 1;
@@ -807,7 +806,12 @@
       const TX_SIZE tx_size = plane ? get_uv_tx_size(mi, pd) : mi->tx_size;
       vp9_get_entropy_contexts(bsize, tx_size, pd,
                                ctx.ta[plane], ctx.tl[plane]);
+      arg.enable_coeff_opt = 1;
+    } else {
+      arg.enable_coeff_opt = 0;
     }
+    arg.ta = ctx.ta[plane];
+    arg.tl = ctx.tl[plane];
 
     vp9_foreach_transformed_block_in_plane(xd, bsize, plane, encode_block,
                                            &arg);
@@ -836,7 +840,6 @@
   uint16_t *eob = &p->eobs[block];
   const int src_stride = p->src.stride;
   const int dst_stride = pd->dst.stride;
-  struct optimize_ctx *const ctx = args->ctx;
   ENTROPY_CONTEXT *a = NULL;
   ENTROPY_CONTEXT *l = NULL;
   int entropy_ctx = 0;
@@ -843,9 +846,9 @@
   dst = &pd->dst.buf[4 * (row * dst_stride + col)];
   src = &p->src.buf[4 * (row * src_stride + col)];
   src_diff = &p->src_diff[4 * (row * diff_stride + col)];
-  if (args->ctx != NULL) {
-    a = &ctx->ta[plane][col];
-    l = &ctx->tl[plane][row];
+  if (args->enable_coeff_opt) {
+    a = &args->ta[col];
+    l = &args->tl[row];
     entropy_ctx = combine_entropy_contexts(*a, *l);
   }
 
@@ -970,7 +973,7 @@
                                 eob, scan_order->scan);
         }
       }
-      if (args->ctx != NULL && !x->skip_recode) {
+      if (args->enable_coeff_opt && !x->skip_recode) {
        *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0;
       }
       if (!x->skip_encode && *eob)
@@ -990,7 +993,7 @@
                                 eob, scan_order->scan);
         }
       }
-      if (args->ctx != NULL && !x->skip_recode) {
+      if (args->enable_coeff_opt && !x->skip_recode) {
         *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0;
       }
       if (!x->skip_encode && *eob)
@@ -1010,7 +1013,7 @@
                                 eob, scan_order->scan);
         }
       }
-      if (args->ctx != NULL && !x->skip_recode) {
+      if (args->enable_coeff_opt && !x->skip_recode) {
         *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0;
       }
       if (!x->skip_encode && *eob)
@@ -1033,7 +1036,7 @@
                                 eob, scan_order->scan);
         }
       }
-      if (args->ctx != NULL && !x->skip_recode) {
+      if (args->enable_coeff_opt && !x->skip_recode) {
         *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0;
       }
       if (!x->skip_encode && *eob) {
@@ -1058,7 +1061,9 @@
                                   int enable_optimize_b) {
   const MACROBLOCKD *const xd = &x->e_mbd;
   struct optimize_ctx ctx;
-  struct encode_b_args arg = {x, NULL, &xd->mi[0]->skip};
+  struct encode_b_args arg = {x, enable_optimize_b,
+                              ctx.ta[plane], ctx.tl[plane],
+                              &xd->mi[0]->skip};
 
   if (enable_optimize_b && x->optimize &&
       (!x->skip_recode || !x->skip_optimize)) {
@@ -1066,7 +1071,8 @@
     const TX_SIZE tx_size = plane ? get_uv_tx_size(xd->mi[0], pd) :
         xd->mi[0]->tx_size;
     vp9_get_entropy_contexts(bsize, tx_size, pd, ctx.ta[plane], ctx.tl[plane]);
-    arg.ctx = &ctx;
+  } else {
+    arg.enable_coeff_opt = 0;
   }
 
   vp9_foreach_transformed_block_in_plane(xd, bsize, plane,
--- a/vp9/encoder/vp9_encodemb.h
+++ b/vp9/encoder/vp9_encodemb.h
@@ -20,7 +20,9 @@
 
 struct encode_b_args {
   MACROBLOCK *x;
-  struct optimize_ctx *ctx;
+  int enable_coeff_opt;
+  ENTROPY_CONTEXT *ta;
+  ENTROPY_CONTEXT *tl;
   int8_t *skip;
 };
 int vp9_optimize_b(MACROBLOCK *mb, int plane, int block,
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -602,7 +602,8 @@
     return;
 
   if (!is_inter_block(mi)) {
-    struct encode_b_args intra_arg = {x, NULL, &mi->skip};
+    struct encode_b_args intra_arg = {x, args->cpi->sf.quant_coeff_opt,
+                                      args->t_above, args->t_left, &mi->skip};
     vp9_encode_block_intra(plane, block, blk_row, blk_col, plane_bsize, tx_size,
                            &intra_arg);
     if (args->cpi->sf.txfm_domain_distortion) {