Commit f12cc4a4 authored by Angie Chiang's avatar Angie Chiang

Customize coding scheme for 1D transform

Observe 0.1% gain on lowres wo optimize_b before rebase

Change-Id: I0cb5b5e4be2563093efb2f6dfbefdce9b554e910
parent 2d3d0cd2
......@@ -2220,6 +2220,11 @@ void av1_average_tile_coef_cdfs(FRAME_CONTEXT *fc, FRAME_CONTEXT *ec_ctxs[],
#if BR_NODE
AVERAGE_TILE_CDFS(coeff_br_cdf)
#endif
#if CONFIG_CTX1D
AVERAGE_TILE_CDFS(eob_mode_cdf)
AVERAGE_TILE_CDFS(empty_line_cdf)
AVERAGE_TILE_CDFS(hv_eob_cdf)
#endif
#else
AVERAGE_TILE_CDFS(coef_head_cdfs)
AVERAGE_TILE_CDFS(coef_tail_cdfs)
......
......@@ -60,16 +60,25 @@ extern "C" {
#if CONFIG_LV_MAP
#define TXB_SKIP_CONTEXTS 13
#if CONFIG_CTX1D
#define EOB_COEF_CONTEXTS_2D 25
#define EOB_COEF_CONTEXTS_1D 25
#define EOB_COEF_CONTEXTS \
(EOB_COEF_CONTEXTS_2D + EOB_COEF_CONTEXTS_1D + EOB_COEF_CONTEXTS_1D)
#else // CONFIG_CTX1D
#define EOB_COEF_CONTEXTS 25
#endif // CONFIG_CTX1D
#if CONFIG_EXT_TX
#define SIG_COEF_CONTEXTS_2D 16
#define SIG_COEF_CONTEXTS_1D 16
#define SIG_COEF_CONTEXTS \
(SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D + SIG_COEF_CONTEXTS_1D)
#else
#else // CONFIG_EXT_TX
#define SIG_COEF_CONTEXTS_2D 16
#define SIG_COEF_CONTEXTS 16
#endif
#define EOB_COEF_CONTEXTS 25
#endif // CONFIG_EXT_TX
#define COEFF_BASE_CONTEXTS 42
#define DC_SIGN_CONTEXTS 3
......@@ -86,6 +95,11 @@ extern "C" {
#define BASE_CONTEXT_POSITION_NUM 12
#if CONFIG_CTX1D
#define EMPTY_LINE_CONTEXTS 5
#define HV_EOB_CONTEXTS 24
#endif // CONFIG_CTX1D
typedef enum TX_CLASS {
TX_CLASS_2D = 0,
TX_CLASS_HORIZ = 1,
......
This diff is collapsed.
......@@ -172,6 +172,11 @@ typedef struct frame_contexts {
#if BR_NODE
aom_prob coeff_br[TX_SIZES][PLANE_TYPES][BASE_RANGE_SETS][LEVEL_CONTEXTS];
#endif
#if CONFIG_CTX1D
aom_prob eob_mode[TX_SIZES][PLANE_TYPES][TX_CLASSES];
aom_prob empty_line[TX_SIZES][PLANE_TYPES][TX_CLASSES][EMPTY_LINE_CONTEXTS];
aom_prob hv_eob[TX_SIZES][PLANE_TYPES][TX_CLASSES][HV_EOB_CONTEXTS];
#endif // CONFIG_CTX1D
#if LV_MAP_PROB
aom_cdf_prob txb_skip_cdf[TX_SIZES][TXB_SKIP_CONTEXTS][CDF_SIZE(2)];
......@@ -188,6 +193,13 @@ typedef struct frame_contexts {
aom_cdf_prob coeff_br_cdf[TX_SIZES][PLANE_TYPES][BASE_RANGE_SETS]
[LEVEL_CONTEXTS][CDF_SIZE(2)];
#endif
#if CONFIG_CTX1D
aom_cdf_prob eob_mode_cdf[TX_SIZES][PLANE_TYPES][TX_CLASSES][CDF_SIZE(2)];
aom_cdf_prob empty_line_cdf[TX_SIZES][PLANE_TYPES][TX_CLASSES]
[EMPTY_LINE_CONTEXTS][CDF_SIZE(2)];
aom_cdf_prob hv_eob_cdf[TX_SIZES][PLANE_TYPES][TX_CLASSES][HV_EOB_CONTEXTS]
[CDF_SIZE(2)];
#endif // CONFIG_CTX1D
#endif // LV_MAP_PROB
#endif
......@@ -430,6 +442,12 @@ typedef struct FRAME_COUNTS {
unsigned int coeff_lps[TX_SIZES][PLANE_TYPES][LEVEL_CONTEXTS][2];
unsigned int coeff_br[TX_SIZES][PLANE_TYPES][BASE_RANGE_SETS][LEVEL_CONTEXTS]
[2];
#if CONFIG_CTX1D
unsigned int eob_mode[TX_SIZES][PLANE_TYPES][TX_CLASSES][2];
unsigned int empty_line[TX_SIZES][PLANE_TYPES][TX_CLASSES]
[EMPTY_LINE_CONTEXTS][2];
unsigned int hv_eob[TX_SIZES][PLANE_TYPES][TX_CLASSES][HV_EOB_CONTEXTS][2];
#endif // CONFIG_CTX1D
#endif // CONFIG_LV_MAP
av1_blockz_count_model blockz_count[TX_SIZES][PLANE_TYPES];
......
......@@ -210,6 +210,10 @@ typedef enum ATTRIBUTE_PACKED {
#define MAX_TX_DEPTH (TX_SIZES - TX_SIZE_CTX_MIN)
#if CONFIG_CTX1D
#define MAX_HVTX_SIZE (1 << 5)
#endif // CONFIG_CTX1D
#define MAX_TX_SIZE_LOG2 (5 + CONFIG_TX64X64)
#define MAX_TX_SIZE (1 << MAX_TX_SIZE_LOG2)
#define MIN_TX_SIZE_LOG2 2
......
......@@ -172,6 +172,44 @@ void av1_init_txb_probs(FRAME_CONTEXT *fc) {
#endif // BR_NODE
}
}
#if CONFIG_CTX1D
for (tx_size = 0; tx_size < TX_SIZES; ++tx_size) {
for (plane = 0; plane < PLANE_TYPES; ++plane) {
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class) {
fc->eob_mode_cdf[tx_size][plane][tx_class][0] = AOM_ICDF(
128 * (aom_cdf_prob)fc->eob_mode[tx_size][plane][tx_class]);
fc->eob_mode_cdf[tx_size][plane][tx_class][1] = AOM_ICDF(32768);
fc->eob_mode_cdf[tx_size][plane][tx_class][2] = AOM_ICDF(0);
}
}
}
for (tx_size = 0; tx_size < TX_SIZES; ++tx_size) {
for (plane = 0; plane < PLANE_TYPES; ++plane) {
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class) {
for (ctx = 0; ctx < EMPTY_LINE_CONTEXTS; ++ctx) {
fc->empty_line_cdf[tx_size][plane][tx_class][ctx][0] = AOM_ICDF(
128 *
(aom_cdf_prob)fc->empty_line[tx_size][plane][tx_class][ctx]);
fc->empty_line_cdf[tx_size][plane][tx_class][ctx][1] =
AOM_ICDF(32768);
fc->empty_line_cdf[tx_size][plane][tx_class][ctx][2] = AOM_ICDF(0);
}
}
}
}
for (tx_size = 0; tx_size < TX_SIZES; ++tx_size) {
for (plane = 0; plane < PLANE_TYPES; ++plane) {
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class) {
for (ctx = 0; ctx < HV_EOB_CONTEXTS; ++ctx) {
fc->hv_eob_cdf[tx_size][plane][tx_class][ctx][0] = AOM_ICDF(
128 * (aom_cdf_prob)fc->hv_eob[tx_size][plane][tx_class][ctx]);
fc->hv_eob_cdf[tx_size][plane][tx_class][ctx][1] = AOM_ICDF(32768);
fc->hv_eob_cdf[tx_size][plane][tx_class][ctx][2] = AOM_ICDF(0);
}
}
}
}
#endif // CONFIG_CTX1D
}
#endif // LV_MAP_PROB
......@@ -239,6 +277,34 @@ void av1_adapt_txb_probs(AV1_COMMON *cm, unsigned int count_sat,
#endif // BR_NODE
}
}
#if CONFIG_CTX1D
for (tx_size = 0; tx_size < TX_SIZES; ++tx_size) {
for (plane = 0; plane < PLANE_TYPES; ++plane)
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class)
fc->eob_mode[tx_size][plane][tx_class] =
merge_probs(pre_fc->eob_mode[tx_size][plane][tx_class],
counts->eob_mode[tx_size][plane][tx_class], count_sat,
update_factor);
}
for (tx_size = 0; tx_size < TX_SIZES; ++tx_size) {
for (plane = 0; plane < PLANE_TYPES; ++plane)
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class)
for (ctx = 0; ctx < EMPTY_LINE_CONTEXTS; ++ctx)
fc->empty_line[tx_size][plane][tx_class][ctx] =
merge_probs(pre_fc->empty_line[tx_size][plane][tx_class][ctx],
counts->empty_line[tx_size][plane][tx_class][ctx],
count_sat, update_factor);
}
for (tx_size = 0; tx_size < TX_SIZES; ++tx_size) {
for (plane = 0; plane < PLANE_TYPES; ++plane)
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class)
for (ctx = 0; ctx < HV_EOB_CONTEXTS; ++ctx)
fc->hv_eob[tx_size][plane][tx_class][ctx] =
merge_probs(pre_fc->hv_eob[tx_size][plane][tx_class][ctx],
counts->hv_eob[tx_size][plane][tx_class][ctx],
count_sat, update_factor);
}
#endif
}
void av1_init_lv_map(AV1_COMMON *cm) {
......
......@@ -367,11 +367,21 @@ static INLINE int get_eob_ctx(const tran_low_t *tcoeffs,
const int coeff_idx, // raster order
const TX_SIZE txs_ctx, TX_TYPE tx_type) {
(void)tcoeffs;
int offset = 0;
#if CONFIG_CTX1D
TX_CLASS tx_class = get_tx_class(tx_type);
if (tx_class == TX_CLASS_VERT)
offset = EOB_COEF_CONTEXTS_2D;
else if (tx_class == TX_CLASS_HORIZ)
offset = EOB_COEF_CONTEXTS_2D + EOB_COEF_CONTEXTS_1D;
#else
(void)tx_type;
if (txs_ctx == TX_4X4) return av1_coeff_band_4x4[coeff_idx];
if (txs_ctx == TX_8X8) return av1_coeff_band_8x8[coeff_idx];
if (txs_ctx == TX_16X16) return av1_coeff_band_16x16[coeff_idx];
if (txs_ctx == TX_32X32) return av1_coeff_band_32x32[coeff_idx];
#endif
if (txs_ctx == TX_4X4) return offset + av1_coeff_band_4x4[coeff_idx];
if (txs_ctx == TX_8X8) return offset + av1_coeff_band_8x8[coeff_idx];
if (txs_ctx == TX_16X16) return offset + av1_coeff_band_16x16[coeff_idx];
if (txs_ctx == TX_32X32) return offset + av1_coeff_band_32x32[coeff_idx];
assert(0);
return 0;
......@@ -467,4 +477,78 @@ void av1_adapt_txb_probs(AV1_COMMON *cm, unsigned int count_sat,
unsigned int update_factor);
void av1_init_lv_map(AV1_COMMON *cm);
#if CONFIG_CTX1D
static INLINE void get_eob_vert(int16_t *eob_ls, const tran_low_t *tcoeff,
int w, int h) {
for (int c = 0; c < w; ++c) {
eob_ls[c] = 0;
for (int r = h - 1; r >= 0; --r) {
int coeff_idx = r * w + c;
if (tcoeff[coeff_idx] != 0) {
eob_ls[c] = r + 1;
break;
}
}
}
}
static INLINE void get_eob_horiz(int16_t *eob_ls, const tran_low_t *tcoeff,
int w, int h) {
for (int r = 0; r < h; ++r) {
eob_ls[r] = 0;
for (int c = w - 1; c >= 0; --c) {
int coeff_idx = r * w + c;
if (tcoeff[coeff_idx] != 0) {
eob_ls[r] = c + 1;
break;
}
}
}
}
static INLINE int get_empty_line_ctx(int line_idx, int16_t *eob_ls) {
if (line_idx > 0) {
int prev_eob = eob_ls[line_idx - 1];
if (prev_eob == 0) {
return 1;
} else if (prev_eob < 3) {
return 2;
} else if (prev_eob < 6) {
return 3;
} else {
return 4;
}
} else {
return 0;
}
}
#define MAX_POS_CTX 8
static int pos_ctx[MAX_HVTX_SIZE] = {
0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7,
};
static INLINE int get_hv_eob_ctx(int line_idx, int pos, int16_t *eob_ls) {
if (line_idx > 0) {
int prev_eob = eob_ls[line_idx - 1];
int diff = pos + 1 - prev_eob;
int abs_diff = abs(diff);
int ctx_idx = pos_ctx[abs_diff];
assert(ctx_idx < MAX_POS_CTX);
if (diff < 0) {
ctx_idx += MAX_POS_CTX;
assert(ctx_idx >= MAX_POS_CTX);
assert(ctx_idx < 2 * MAX_POS_CTX);
}
return ctx_idx;
} else {
int ctx_idx = MAX_POS_CTX + MAX_POS_CTX + pos_ctx[pos];
assert(ctx_idx < HV_EOB_CONTEXTS);
assert(HV_EOB_CONTEXTS == MAX_POS_CTX * 3);
return ctx_idx;
}
}
#endif // CONFIG_CTX1D
#endif // AV1_COMMON_TXB_COMMON_H_
This diff is collapsed.
......@@ -78,6 +78,11 @@ typedef struct {
#if BR_NODE
int br_cost[BASE_RANGE_SETS][LEVEL_CONTEXTS][2];
#endif
#if CONFIG_CTX1D
int eob_mode_cost[TX_CLASSES][2];
int empty_line_cost[TX_CLASSES][EMPTY_LINE_CONTEXTS][2];
int hv_eob_cost[TX_CLASSES][HV_EOB_CONTEXTS][2];
#endif
} LV_MAP_COEFF_COST;
typedef struct {
......
This diff is collapsed.
......@@ -590,6 +590,24 @@ void av1_fill_coeff_costs(MACROBLOCK *x, FRAME_CONTEXT *fc) {
// load the base range cost
}
}
#if CONFIG_CTX1D
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class)
av1_cost_tokens_from_cdf(pcost->eob_mode_cost[tx_class],
fc->eob_mode_cdf[tx_size][plane][tx_class],
NULL);
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class)
for (int ctx = 0; ctx < EMPTY_LINE_CONTEXTS; ++ctx)
av1_cost_tokens_from_cdf(
pcost->empty_line_cost[tx_class][ctx],
fc->empty_line_cdf[tx_size][plane][tx_class][ctx], NULL);
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class)
for (int ctx = 0; ctx < HV_EOB_CONTEXTS; ++ctx)
av1_cost_tokens_from_cdf(
pcost->hv_eob_cost[tx_class][ctx],
fc->hv_eob_cdf[tx_size][plane][tx_class][ctx], NULL);
#endif // CONFIG_CTX1D
#else // LV_MAP_PROB
for (int ctx = 0; ctx < TXB_SKIP_CONTEXTS; ++ctx)
get_rate_cost(fc->txb_skip[tx_size][ctx], pcost->txb_skip_cost[ctx]);
......@@ -610,6 +628,22 @@ void av1_fill_coeff_costs(MACROBLOCK *x, FRAME_CONTEXT *fc) {
for (int ctx = 0; ctx < LEVEL_CONTEXTS; ++ctx)
get_rate_cost(fc->coeff_lps[tx_size][plane][ctx], pcost->lps_cost[ctx]);
#if CONFIG_CTX1D
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class)
get_rate_cost(fc->eob_mode[tx_size][plane][tx_class],
pcost->eob_mode_cost[tx_class]);
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class)
for (int ctx = 0; ctx < EMPTY_LINE_CONTEXTS; ++ctx)
get_rate_cost(fc->empty_line[tx_size][plane][tx_class][ctx],
pcost->empty_line_cost[tx_class][ctx]);
for (int tx_class = 0; tx_class < TX_CLASSES; ++tx_class)
for (int ctx = 0; ctx < HV_EOB_CONTEXTS; ++ctx)
get_rate_cost(fc->hv_eob[tx_size][plane][tx_class][ctx],
pcost->hv_eob_cost[tx_class][ctx]);
#endif // CONFIG_CTX1D
#endif // LV_MAP_PROB
}
}
......
......@@ -121,6 +121,7 @@ set(CONFIG_COMPOUND_ROUND 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_COMPOUND_SEGMENT 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_COMPOUND_SINGLEREF 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_CONVOLVE_ROUND 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_CTX1D 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_DAALA_DCT16 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_DAALA_DCT32 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_DAALA_DCT4 0 CACHE NUMBER "AV1 experiment flag.")
......
......@@ -214,6 +214,15 @@ if (CONFIG_TXK_SEL)
endif ()
endif ()
if (CONFIG_CTX1D)
if (NOT CONFIG_LV_MAP)
change_config_and_warn(CONFIG_LV_MAP 1 CONFIG_CTX1D)
endif ()
if (NOT CONFIG_EXT_TX)
change_config_and_warn(CONFIG_EXT_TX 1 CONFIG_CTX1D)
endif ()
endif ()
if (CONFIG_EXT_COMP_REFS)
if (NOT CONFIG_EXT_REFS)
change_config_and_warn(CONFIG_EXT_REFS 1 CONFIG_EXT_COMP_REFS)
......
......@@ -322,6 +322,7 @@ EXPERIMENT_LIST="
palette_throughput
ref_adapt
lv_map
ctx1d
txk_sel
mv_compress
segment_zeromv
......@@ -555,6 +556,8 @@ post_process_cmdline() {
enabled mrc_tx && enable_feature var_tx
enabled ext_delta_q && soft_enable delta_q
enabled txk_sel && soft_enable lv_map
enabled ctx1d && soft_enable lv_map
enabled ctx1d && soft_enable ext_tx
enabled compound_round && soft_enable convolve_round
enabled intra_edge && enable_feature ext_intra
enabled chroma_2x2 && disable_feature chroma_sub8x8
......
......@@ -880,6 +880,50 @@ int main(int argc, const char **argv) {
"default_coeff_br_cdf[TX_SIZES][PLANE_TYPES][BASE_RANGE_"
"SETS][LEVEL_CONTEXTS][CDF_SIZE(2)]");
#endif // BR_NODE
#if CONFIG_CTX1D
cts_each_dim[0] = TX_SIZES;
cts_each_dim[1] = PLANE_TYPES;
cts_each_dim[2] = TX_CLASSES;
cts_each_dim[3] = 2;
optimize_entropy_table(&fc.eob_mode[0][0][0][0], probsfile, 4, cts_each_dim,
NULL, 1,
"static const aom_prob "
"default_eob_mode[TX_SIZES][PLANE_TYPES][TX_CLASSES]");
optimize_cdf_table(&fc.eob_mode[0][0][0][0], probsfile, 4, cts_each_dim,
"static const aom_cdf_prob "
"default_eob_mode_cdf[TX_SIZES][PLANE_TYPES][TX_CLASSES]["
"CDF_SIZE(2)]");
cts_each_dim[0] = TX_SIZES;
cts_each_dim[1] = PLANE_TYPES;
cts_each_dim[2] = TX_CLASSES;
cts_each_dim[3] = EMPTY_LINE_CONTEXTS;
cts_each_dim[4] = 2;
optimize_entropy_table(&fc.empty_line[0][0][0][0][0], probsfile, 5,
cts_each_dim, NULL, 1,
"static const aom_prob "
"default_empty_line[TX_SIZES][PLANE_TYPES][TX_CLASSES]"
"[EMPTY_LINE_CONTEXTS]");
optimize_cdf_table(&fc.empty_line[0][0][0][0][0], probsfile, 5, cts_each_dim,
"static const aom_cdf_prob "
"default_empty_line_cdf[TX_SIZES][PLANE_TYPES][TX_CLASSES]"
"[EMPTY_LINE_CONTEXTS][CDF_SIZE(2)]");
cts_each_dim[0] = TX_SIZES;
cts_each_dim[1] = PLANE_TYPES;
cts_each_dim[2] = TX_CLASSES;
cts_each_dim[3] = HV_EOB_CONTEXTS;
cts_each_dim[4] = 2;
optimize_entropy_table(
&fc.hv_eob[0][0][0][0][0], probsfile, 5, cts_each_dim, NULL, 1,
"static const aom_prob "
"default_hv_eob[TX_SIZES][PLANE_TYPES][TX_CLASSES][HV_EOB_CONTEXTS]");
optimize_cdf_table(&fc.hv_eob[0][0][0][0][0], probsfile, 5, cts_each_dim,
"static const aom_cdf_prob "
"default_hv_eob_cdf[TX_SIZES][PLANE_TYPES][TX_CLASSES][HV_"
"EOB_CONTEXTS][CDF_SIZE(2)]");
#endif // CONFIG_CTX1D
#endif // CONFIG_LV_MAP
fclose(statsfile);
......
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