ref: 2f58faffa40036e0c8dfb8b4351a0ce0b11eb9ee
parent: 242157c756314827ad9244952c7253e8900b9626
author: Jingning Han <[email protected]>
date: Tue Jul 23 11:53:09 EDT 2013
Make coeff_optimize initialized per-plane This commit makes the initialization of trellis coeff optimization a per-plane operation, thereby eliminating the redundant steps in encode_sby and encode_sbuv. It makes the encoder at speed 0 slightly faster. Change-Id: Iffe9faca6a109dafc0dd69dc7273cbdec19b17cd
--- a/vp9/encoder/vp9_encodemb.c
+++ b/vp9/encoder/vp9_encodemb.c
@@ -370,33 +370,44 @@
args->ctx);
}
-void vp9_optimize_init(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
- struct optimize_ctx *ctx) {
- int p;
+void optimize_init_b(int plane, BLOCK_SIZE_TYPE bsize, void *arg) {
+ const struct encode_b_args* const args = arg;
+ const MACROBLOCKD *xd = &args->x->e_mbd;
+ const struct macroblockd_plane* const pd = &xd->plane[plane];
+ const int bwl = b_width_log2(bsize) - pd->subsampling_x;
+ const int bhl = b_height_log2(bsize) - pd->subsampling_y;
+ const int bw = 1 << bwl, bh = 1 << bhl;
+ const MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
+ const TX_SIZE tx_size = plane ? get_uv_tx_size(mbmi) : mbmi->txfm_size;
+ int i;
- for (p = 0; p < MAX_MB_PLANE; p++) {
- const struct macroblockd_plane* const plane = &xd->plane[p];
- const int bwl = b_width_log2(bsize) - plane->subsampling_x;
- const int bhl = b_height_log2(bsize) - plane->subsampling_y;
- const MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
- const TX_SIZE tx_size = p ? get_uv_tx_size(mbmi)
- : mbmi->txfm_size;
- int i, j;
-
- for (i = 0; i < 1 << bwl; i += 1 << tx_size) {
- int c = 0;
- ctx->ta[p][i] = 0;
- for (j = 0; j < 1 << tx_size && !c; j++) {
- c = ctx->ta[p][i] |= plane->above_context[i + j];
- }
- }
- for (i = 0; i < 1 << bhl; i += 1 << tx_size) {
- int c = 0;
- ctx->tl[p][i] = 0;
- for (j = 0; j < 1 << tx_size && !c; j++) {
- c = ctx->tl[p][i] |= plane->left_context[i + j];
- }
- }
+ switch (tx_size) {
+ case TX_4X4:
+ vpx_memcpy(args->ctx->ta[plane], pd->above_context,
+ sizeof(ENTROPY_CONTEXT) * bw);
+ vpx_memcpy(args->ctx->tl[plane], pd->left_context,
+ sizeof(ENTROPY_CONTEXT) * bh);
+ break;
+ case TX_8X8:
+ for (i = 0; i < bw; i += 2)
+ args->ctx->ta[plane][i] = !!*(uint16_t *)&pd->above_context[i];
+ for (i = 0; i < bh; i += 2)
+ args->ctx->tl[plane][i] = !!*(uint16_t *)&pd->left_context[i];
+ break;
+ case TX_16X16:
+ for (i = 0; i < bw; i += 4)
+ args->ctx->ta[plane][i] = !!*(uint32_t *)&pd->above_context[i];
+ for (i = 0; i < bh; i += 4)
+ args->ctx->tl[plane][i] = !!*(uint32_t *)&pd->left_context[i];
+ break;
+ case TX_32X32:
+ for (i = 0; i < bw; i += 8)
+ args->ctx->ta[plane][i] = !!*(uint64_t *)&pd->above_context[i];
+ for (i = 0; i < bh; i += 8)
+ args->ctx->tl[plane][i] = !!*(uint64_t *)&pd->left_context[i];
+ break;
+ default:
+ assert(0);
}
}
@@ -403,7 +414,7 @@
void vp9_optimize_sby(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
struct optimize_ctx ctx;
struct encode_b_args arg = {cm, x, &ctx};
- vp9_optimize_init(&x->e_mbd, bsize, &ctx);
+ optimize_init_b(0, bsize, &arg);
foreach_transformed_block_in_plane(&x->e_mbd, bsize, 0, optimize_block, &arg);
}
@@ -411,7 +422,10 @@
BLOCK_SIZE_TYPE bsize) {
struct optimize_ctx ctx;
struct encode_b_args arg = {cm, x, &ctx};
- vp9_optimize_init(&x->e_mbd, bsize, &ctx);
+ int i;
+ for (i = 1; i < MAX_MB_PLANE; ++i)
+ optimize_init_b(i, bsize, &arg);
+
foreach_transformed_block_uv(&x->e_mbd, bsize, optimize_block, &arg);
}
@@ -553,7 +567,7 @@
vp9_subtract_sby(x, bsize);
if (x->optimize)
- vp9_optimize_init(xd, bsize, &ctx);
+ optimize_init_b(0, bsize, &arg);
foreach_transformed_block_in_plane(xd, bsize, 0, encode_block, &arg);
}
@@ -564,8 +578,11 @@
struct encode_b_args arg = {cm, x, &ctx};
vp9_subtract_sbuv(x, bsize);
- if (x->optimize)
- vp9_optimize_init(xd, bsize, &ctx);
+ if (x->optimize) {
+ int i;
+ for (i = 1; i < MAX_MB_PLANE; ++i)
+ optimize_init_b(i, bsize, &arg);
+ }
foreach_transformed_block_uv(xd, bsize, encode_block, &arg);
}
@@ -576,8 +593,12 @@
struct encode_b_args arg = {cm, x, &ctx};
vp9_subtract_sb(x, bsize);
- if (x->optimize)
- vp9_optimize_init(xd, bsize, &ctx);
+
+ if (x->optimize) {
+ int i;
+ for (i = 0; i < MAX_MB_PLANE; ++i)
+ optimize_init_b(i, bsize, &arg);
+ }
foreach_transformed_block(xd, bsize, encode_block, &arg);
}
--- a/vp9/encoder/vp9_encodemb.h
+++ b/vp9/encoder/vp9_encodemb.h
@@ -33,8 +33,6 @@
struct optimize_ctx *ctx;
};
-void vp9_optimize_init(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
- struct optimize_ctx *ctx);
void vp9_optimize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
int ss_txfrm_size, VP9_COMMON *cm, MACROBLOCK *x,
struct optimize_ctx *ctx);