Commit 57b8ff68 authored by Yue Chen's avatar Yue Chen

Optimizations for filter_intra

Reduce number of modes from 10 to 6, and disable fi modes in UV.
To reduce complexity, apply filter directly without subtracting
the estimated means.

Change-Id: Iaf78d92d31e4a7cc30ea7863b57a9611c5f503e6
parent 54671902
......@@ -185,24 +185,16 @@ if (aom_config("CONFIG_FILTER_INTRA") eq "yes") {
add_proto qw/void av1_dc_filter_predictor/, "uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint8_t *above, const uint8_t *left";
add_proto qw/void av1_v_filter_predictor/, "uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint8_t *above, const uint8_t *left";
add_proto qw/void av1_h_filter_predictor/, "uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint8_t *above, const uint8_t *left";
add_proto qw/void av1_d45_filter_predictor/, "uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint8_t *above, const uint8_t *left";
add_proto qw/void av1_d135_filter_predictor/, "uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint8_t *above, const uint8_t *left";
add_proto qw/void av1_d117_filter_predictor/, "uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint8_t *above, const uint8_t *left";
add_proto qw/void av1_d153_filter_predictor/, "uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint8_t *above, const uint8_t *left";
add_proto qw/void av1_d207_filter_predictor/, "uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint8_t *above, const uint8_t *left";
add_proto qw/void av1_d63_filter_predictor/, "uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint8_t *above, const uint8_t *left";
add_proto qw/void av1_paeth_filter_predictor/, "uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint8_t *above, const uint8_t *left";
# High bitdepth functions
if (aom_config("CONFIG_HIGHBITDEPTH") eq "yes") {
add_proto qw/void av1_highbd_dc_filter_predictor/, "uint16_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint16_t *above, const uint16_t *left, int bd";
add_proto qw/void av1_highbd_v_filter_predictor/, "uint16_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint16_t *above, const uint16_t *left, int bd";
add_proto qw/void av1_highbd_h_filter_predictor/, "uint16_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint16_t *above, const uint16_t *left, int bd";
add_proto qw/void av1_highbd_d45_filter_predictor/, "uint16_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint16_t *above, const uint16_t *left, int bd";
add_proto qw/void av1_highbd_d135_filter_predictor/, "uint16_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint16_t *above, const uint16_t *left, int bd";
add_proto qw/void av1_highbd_d117_filter_predictor/, "uint16_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint16_t *above, const uint16_t *left, int bd";
add_proto qw/void av1_highbd_d153_filter_predictor/, "uint16_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint16_t *above, const uint16_t *left, int bd";
add_proto qw/void av1_highbd_d207_filter_predictor/, "uint16_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint16_t *above, const uint16_t *left, int bd";
add_proto qw/void av1_highbd_d63_filter_predictor/, "uint16_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint16_t *above, const uint16_t *left, int bd";
add_proto qw/void av1_highbd_paeth_filter_predictor/, "uint16_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint16_t *above, const uint16_t *left, int bd";
}
}
......
......@@ -261,6 +261,10 @@ typedef struct {
uint8_t use_filter_intra_mode[PLANE_TYPES];
FILTER_INTRA_MODE filter_intra_mode[PLANE_TYPES];
} FILTER_INTRA_MODE_INFO;
static const PREDICTION_MODE fimode_to_intradir[FILTER_INTRA_MODES] = {
DC_PRED, V_PRED, H_PRED, D117_PRED, D153_PRED, DC_PRED
};
#endif // CONFIG_FILTER_INTRA
#if CONFIG_RD_DEBUG
......
This diff is collapsed.
......@@ -616,12 +616,8 @@ typedef enum ATTRIBUTE_PACKED {
FILTER_DC_PRED,
FILTER_V_PRED,
FILTER_H_PRED,
FILTER_D45_PRED,
FILTER_D135_PRED,
FILTER_D117_PRED,
FILTER_D153_PRED,
FILTER_D207_PRED,
FILTER_D63_PRED,
FILTER_PAETH_PRED,
FILTER_INTRA_MODES,
} FILTER_INTRA_MODE;
......
This diff is collapsed.
......@@ -859,8 +859,7 @@ static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
#if CONFIG_FILTER_INTRA
static void read_filter_intra_mode_info(AV1_COMMON *const cm,
MACROBLOCKD *const xd, int mi_row,
int mi_col, aom_reader *r) {
MACROBLOCKD *const xd, aom_reader *r) {
MODE_INFO *const mi = xd->mi[0];
MB_MODE_INFO *const mbmi = &mi->mbmi;
FRAME_COUNTS *counts = xd->counts;
......@@ -880,26 +879,6 @@ static void read_filter_intra_mode_info(AV1_COMMON *const cm,
->filter_intra[0][filter_intra_mode_info->use_filter_intra_mode[0]];
}
}
if (!is_chroma_reference(mi_row, mi_col, mbmi->sb_type,
xd->plane[1].subsampling_x,
xd->plane[1].subsampling_y))
return;
if (mbmi->uv_mode == UV_DC_PRED &&
mbmi->palette_mode_info.palette_size[1] == 0) {
filter_intra_mode_info->use_filter_intra_mode[1] =
aom_read(r, cm->fc->filter_intra_probs[1], ACCT_STR);
if (filter_intra_mode_info->use_filter_intra_mode[1]) {
filter_intra_mode_info->filter_intra_mode[1] =
aom_read_symbol(r, xd->tile_ctx->filter_intra_mode_cdf[1],
FILTER_INTRA_MODES, ACCT_STR);
}
if (counts) {
++counts
->filter_intra[1][filter_intra_mode_info->use_filter_intra_mode[1]];
}
}
}
#endif // CONFIG_FILTER_INTRA
......@@ -971,9 +950,21 @@ void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd,
r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size],
av1_num_ext_tx_set[tx_set_type], ACCT_STR)];
} else if (ALLOW_INTRA_EXT_TX) {
#if CONFIG_FILTER_INTRA
PREDICTION_MODE intra_dir;
if (mbmi->filter_intra_mode_info.use_filter_intra_mode[0])
intra_dir = fimode_to_intradir[mbmi->filter_intra_mode_info
.filter_intra_mode[0]];
else
intra_dir = mbmi->mode;
*tx_type = av1_ext_tx_inv[tx_set_type][aom_read_symbol(
r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][intra_dir],
av1_num_ext_tx_set[tx_set_type], ACCT_STR)];
#else
*tx_type = av1_ext_tx_inv[tx_set_type][aom_read_symbol(
r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][mbmi->mode],
av1_num_ext_tx_set[tx_set_type], ACCT_STR)];
#endif
}
#else
// only signal tx_type when lgt is not allowed or not selected
......@@ -1276,7 +1267,7 @@ static void read_intra_frame_mode_info(AV1_COMMON *const cm,
#if CONFIG_FILTER_INTRA
mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0;
mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0;
read_filter_intra_mode_info(cm, xd, mi_row, mi_col, r);
read_filter_intra_mode_info(cm, xd, r);
#endif // CONFIG_FILTER_INTRA
#if !CONFIG_TXK_SEL
......@@ -1812,7 +1803,7 @@ static void read_intra_block_mode_info(AV1_COMMON *const cm, const int mi_row,
#if CONFIG_FILTER_INTRA
mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0;
mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0;
read_filter_intra_mode_info(cm, xd, mi_row, mi_col, r);
read_filter_intra_mode_info(cm, xd, r);
#endif // CONFIG_FILTER_INTRA
}
......
......@@ -1048,7 +1048,6 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd,
static void write_filter_intra_mode_info(const AV1_COMMON *const cm,
const MACROBLOCKD *xd,
const MB_MODE_INFO *const mbmi,
int mi_row, int mi_col,
aom_writer *w) {
if (mbmi->mode == DC_PRED && mbmi->palette_mode_info.palette_size[0] == 0) {
aom_write(w, mbmi->filter_intra_mode_info.use_filter_intra_mode[0],
......@@ -1060,23 +1059,6 @@ static void write_filter_intra_mode_info(const AV1_COMMON *const cm,
FILTER_INTRA_MODES);
}
}
if (!is_chroma_reference(mi_row, mi_col, mbmi->sb_type,
xd->plane[1].subsampling_x,
xd->plane[1].subsampling_y))
return;
if (mbmi->uv_mode == UV_DC_PRED &&
mbmi->palette_mode_info.palette_size[1] == 0) {
aom_write(w, mbmi->filter_intra_mode_info.use_filter_intra_mode[1],
cm->fc->filter_intra_probs[1]);
if (mbmi->filter_intra_mode_info.use_filter_intra_mode[1]) {
const FILTER_INTRA_MODE mode =
mbmi->filter_intra_mode_info.filter_intra_mode[1];
aom_write_symbol(w, mode, xd->tile_ctx->filter_intra_mode_cdf[1],
FILTER_INTRA_MODES);
}
}
}
#endif // CONFIG_FILTER_INTRA
......@@ -1389,10 +1371,23 @@ void av1_write_tx_type(const AV1_COMMON *const cm, const MACROBLOCKD *xd,
ec_ctx->inter_ext_tx_cdf[eset][square_tx_size],
av1_num_ext_tx_set[tx_set_type]);
} else if (ALLOW_INTRA_EXT_TX) {
#if CONFIG_FILTER_INTRA
PREDICTION_MODE intra_dir;
if (mbmi->filter_intra_mode_info.use_filter_intra_mode[0])
intra_dir = fimode_to_intradir[mbmi->filter_intra_mode_info
.filter_intra_mode[0]];
else
intra_dir = mbmi->mode;
aom_write_symbol(
w, av1_ext_tx_ind[tx_set_type][tx_type],
ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][intra_dir],
av1_num_ext_tx_set[tx_set_type]);
#else
aom_write_symbol(
w, av1_ext_tx_ind[tx_set_type][tx_type],
ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][mbmi->mode],
av1_num_ext_tx_set[tx_set_type]);
#endif
}
#else
// only signal tx_type when lgt is not allowed or not selected
......@@ -1618,7 +1613,7 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const int mi_row,
if (av1_allow_palette(cm->allow_screen_content_tools, bsize))
write_palette_mode_info(cm, xd, mi, w);
#if CONFIG_FILTER_INTRA
write_filter_intra_mode_info(cm, xd, mbmi, mi_row, mi_col, w);
write_filter_intra_mode_info(cm, xd, mbmi, w);
#endif // CONFIG_FILTER_INTRA
} else {
int16_t mode_ctx;
......@@ -1937,7 +1932,7 @@ static void write_mb_modes_kf(AV1_COMMON *cm, MACROBLOCKD *xd,
if (av1_allow_palette(cm->allow_screen_content_tools, bsize))
write_palette_mode_info(cm, xd, mi, w);
#if CONFIG_FILTER_INTRA
write_filter_intra_mode_info(cm, xd, mbmi, mi_row, mi_col, w);
write_filter_intra_mode_info(cm, xd, mbmi, w);
#endif // CONFIG_FILTER_INTRA
#if !CONFIG_TXK_SEL
......
......@@ -4245,25 +4245,14 @@ static void sum_intra_stats(FRAME_COUNTS *counts, MACROBLOCKD *xd,
const int use_filter_intra_mode =
mbmi->filter_intra_mode_info.use_filter_intra_mode[0];
++counts->filter_intra[0][use_filter_intra_mode];
#if CONFIG_ENTROPY_STATS
++counts->filter_intra_mode[0][mbmi->filter_intra_mode_info
.filter_intra_mode[0]];
#endif // CONFIG_ENTROPY_STATS
update_cdf(fc->filter_intra_mode_cdf[0],
mbmi->filter_intra_mode_info.filter_intra_mode[0],
FILTER_INTRA_MODES);
}
if (mbmi->uv_mode == UV_DC_PRED &&
is_chroma_reference(mi_row, mi_col, bsize, xd->plane[1].subsampling_x,
xd->plane[1].subsampling_y) &&
mbmi->palette_mode_info.palette_size[1] == 0) {
const int use_filter_intra_mode =
mbmi->filter_intra_mode_info.use_filter_intra_mode[1];
++counts->filter_intra[1][use_filter_intra_mode];
++counts->filter_intra_mode[1][mbmi->filter_intra_mode_info
.filter_intra_mode[1]];
update_cdf(fc->filter_intra_mode_cdf[1],
mbmi->filter_intra_mode_info.filter_intra_mode[1],
FILTER_INTRA_MODES);
}
#endif // CONFIG_FILTER_INTRA
if (!is_chroma_reference(mi_row, mi_col, bsize, xd->plane[1].subsampling_x,
......@@ -4506,6 +4495,22 @@ void av1_update_tx_type_count(const AV1_COMMON *cm, MACROBLOCKD *xd,
++counts->inter_ext_tx[eset][txsize_sqr_map[tx_size]][tx_type];
#endif // CONFIG_ENTROPY_STATS
} else {
#if CONFIG_FILTER_INTRA
PREDICTION_MODE intra_dir;
if (mbmi->filter_intra_mode_info.use_filter_intra_mode[0])
intra_dir = fimode_to_intradir[mbmi->filter_intra_mode_info
.filter_intra_mode[0]];
else
intra_dir = mbmi->mode;
#if CONFIG_ENTROPY_STATS
++counts
->intra_ext_tx[eset][txsize_sqr_map[tx_size]][intra_dir][tx_type];
#endif // CONFIG_ENTROPY_STATS
update_cdf(
fc->intra_ext_tx_cdf[eset][txsize_sqr_map[tx_size]][intra_dir],
av1_ext_tx_ind[tx_set_type][tx_type],
av1_num_ext_tx_set[tx_set_type]);
#else
#if CONFIG_ENTROPY_STATS
++counts->intra_ext_tx[eset][txsize_sqr_map[tx_size]][mbmi->mode]
[tx_type];
......@@ -4514,6 +4519,7 @@ void av1_update_tx_type_count(const AV1_COMMON *cm, MACROBLOCKD *xd,
fc->intra_ext_tx_cdf[eset][txsize_sqr_map[tx_size]][mbmi->mode],
av1_ext_tx_ind[tx_set_type][tx_type],
av1_num_ext_tx_set[tx_set_type]);
#endif
}
#else
(void)tx_type;
......
......@@ -143,10 +143,8 @@ void av1_fill_mode_rates(AV1_COMMON *const cm, MACROBLOCK *x,
NULL);
#if CONFIG_FILTER_INTRA
for (i = 0; i < 2; ++i) {
av1_cost_tokens_from_cdf(x->filter_intra_mode_cost[i],
fc->filter_intra_mode_cdf[i], NULL);
}
av1_cost_tokens_from_cdf(x->filter_intra_mode_cost[0],
fc->filter_intra_mode_cdf[0], NULL);
#endif
for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
......
This diff is collapsed.
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