Commit f0463bb8 authored by Hui Su's avatar Hui Su
Browse files

hash-me: use precise mv cost calculation

0.12% gain on screen_content testset; also simplified the code a bit.

Change-Id: If3ecca55d73a69f86320c0a4ea052a831d89d15a
parent 6b51a40d
......@@ -2551,34 +2551,6 @@ static int is_exhaustive_allowed(const AV1_COMP *const cpi, MACROBLOCK *x) {
(*x->ex_search_count_ptr <= max_ex) && !cpi->rc.is_src_frame_alt_ref;
}
#if CONFIG_HASH_ME
#define MAX_HASH_MV_TABLE_SIZE 5
static void add_to_sort_table(block_hash block_hashes[MAX_HASH_MV_TABLE_SIZE],
int costs[MAX_HASH_MV_TABLE_SIZE], int *existing,
int max_size, block_hash curr_block,
int curr_cost) {
if (*existing < max_size) {
block_hashes[*existing] = curr_block;
costs[*existing] = curr_cost;
(*existing)++;
} else {
int max_cost = 0;
int max_cost_idx = 0;
for (int i = 0; i < max_size; i++) {
if (costs[i] > max_cost) {
max_cost = costs[i];
max_cost_idx = i;
}
}
if (curr_cost < max_cost) {
block_hashes[max_cost_idx] = curr_block;
costs[max_cost_idx] = curr_cost;
}
}
}
#endif
#if CONFIG_HASH_ME
int av1_full_pixel_search(const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
MV *mvp_full, int step_param, int error_per_bit,
......@@ -2675,10 +2647,6 @@ int av1_full_pixel_search(const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
block_width == 32 || block_width == 64 || block_width == 128) {
uint8_t *what = x->plane[0].src.buf;
const int what_stride = x->plane[0].src.stride;
block_hash block_hashes[MAX_HASH_MV_TABLE_SIZE];
int costs[MAX_HASH_MV_TABLE_SIZE];
int existing = 0;
int i;
uint32_t hash_value1, hash_value2;
MV best_hash_mv;
int best_hash_cost = INT_MAX;
......@@ -2698,21 +2666,17 @@ int av1_full_pixel_search(const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
break;
}
#if CONFIG_INTRABC
MACROBLOCKD *const xd = &x->e_mbd;
const TileInfo *tile = &xd->tile;
const int mi_col = x_pos / MI_SIZE;
const int mi_row = y_pos / MI_SIZE;
#endif // CONFIG_INTRABC
Iterator iterator =
av1_hash_get_first_iterator(ref_frame_hash, hash_value1);
for (i = 0; i < count; i++, iterator_increment(&iterator)) {
for (int i = 0; i < count; i++, iterator_increment(&iterator)) {
block_hash ref_block_hash = *(block_hash *)(iterator_get(&iterator));
if (hash_value2 == ref_block_hash.hash_value2) {
// for intra, make sure the prediction is from valid area
// not predict from current block.
#if CONFIG_INTRABC
// For intra, make sure the prediction is from valid area.
if (intra) {
const TileInfo *tile = &x->e_mbd.tile;
const int mi_col = x_pos / MI_SIZE;
const int mi_row = y_pos / MI_SIZE;
const MV dv = { 8 * (ref_block_hash.y - y_pos),
8 * (ref_block_hash.x - x_pos) };
if (!av1_is_dv_valid(dv, tile, mi_row, mi_col, bsize,
......@@ -2720,31 +2684,18 @@ int av1_full_pixel_search(const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
continue;
}
#endif // CONFIG_INTRABC
int refCost =
abs(ref_block_hash.x - x_pos) + abs(ref_block_hash.y - y_pos);
add_to_sort_table(block_hashes, costs, &existing,
MAX_HASH_MV_TABLE_SIZE, ref_block_hash, refCost);
}
}
if (existing == 0) {
break;
}
for (i = 0; i < existing; i++) {
MV hash_mv;
hash_mv.col = block_hashes[i].x - x_pos;
hash_mv.row = block_hashes[i].y - y_pos;
if (!is_mv_in(&x->mv_limits, &hash_mv)) {
continue;
}
int currHashCost = av1_get_mvpred_var(x, &hash_mv, ref_mv, fn_ptr, 1);
if (currHashCost < best_hash_cost) {
best_hash_cost = currHashCost;
best_hash_mv = hash_mv;
MV hash_mv;
hash_mv.col = ref_block_hash.x - x_pos;
hash_mv.row = ref_block_hash.y - y_pos;
if (!is_mv_in(&x->mv_limits, &hash_mv)) continue;
const int refCost =
av1_get_mvpred_var(x, &hash_mv, ref_mv, fn_ptr, 1);
if (refCost < best_hash_cost) {
best_hash_cost = refCost;
best_hash_mv = hash_mv;
}
}
}
if (best_hash_cost < var) {
x->second_best_mv = x->best_mv;
x->best_mv.as_mv = best_hash_mv;
......
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