Skip to content

Commit

Permalink
Merge branch 'rework-inter-search'
Browse files Browse the repository at this point in the history
  • Loading branch information
Arizer committed Dec 15, 2021
2 parents 9e40f43 + 51dd942 commit 96b00ff
Show file tree
Hide file tree
Showing 7 changed files with 716 additions and 527 deletions.
20 changes: 10 additions & 10 deletions src/rdo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,15 +1029,15 @@ uint32_t kvz_get_mvd_coding_cost_cabac(const encoder_state_t *state,
* \returns int
* Calculates Motion Vector cost and related costs using CABAC coding
*/
uint32_t kvz_calc_mvd_cost_cabac(const encoder_state_t * state,
int x,
int y,
int mv_shift,
int16_t mv_cand[2][2],
inter_merge_cand_t merge_cand[MRG_MAX_NUM_CANDS],
int16_t num_cand,
int32_t ref_idx,
uint32_t *bitcost)
double kvz_calc_mvd_cost_cabac(const encoder_state_t * state,
int x,
int y,
int mv_shift,
int16_t mv_cand[2][2],
inter_merge_cand_t merge_cand[MRG_MAX_NUM_CANDS],
int16_t num_cand,
int32_t ref_idx,
uint32_t *bitcost)
{
cabac_data_t state_cabac_copy;
cabac_data_t* cabac;
Expand Down Expand Up @@ -1174,7 +1174,7 @@ uint32_t kvz_calc_mvd_cost_cabac(const encoder_state_t * state,
*bitcost = (23 - state_cabac_copy.bits_left) + (state_cabac_copy.num_buffered_bytes << 3);

// Store bitcost before restoring cabac
return *bitcost * (uint32_t)(state->lambda_sqrt + 0.5);
return *bitcost * state->lambda_sqrt;
}

void kvz_close_rdcost_outfiles(void)
Expand Down
24 changes: 22 additions & 2 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ static double calc_mode_bits(const encoder_state_t *state,
}


// TODO: replace usages of this by the kvz_sort_indices_by_cost function.
/**
* \brief Sort modes and costs to ascending order according to costs.
*/
Expand All @@ -439,6 +440,25 @@ void kvz_sort_modes(int8_t *__restrict modes, double *__restrict costs, uint8_t
}


/**
* \brief Sort keys (indices) to ascending order according to costs.
*/
void kvz_sort_keys_by_cost(unit_stats_map_t *__restrict map)
{
// Size of sorted arrays is expected to be "small". No need for faster algorithm.
for (uint8_t i = 1; i < map->size; ++i) {
const int8_t cur_indx = map->keys[i];
const double cur_cost = map->cost[cur_indx];
uint8_t j = i;
while (j > 0 && cur_cost < map->cost[map->keys[j - 1]]) {
map->keys[j] = map->keys[j - 1];
--j;
}
map->keys[j] = cur_indx;
}
}


static uint8_t get_ctx_cu_split_model(const lcu_t *lcu, int x, int y, int depth)
{
vector2d_t lcu_cu = { SUB_SCU(x), SUB_SCU(y) };
Expand All @@ -462,8 +482,8 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth,
const encoder_control_t* ctrl = state->encoder_control;
const videoframe_t * const frame = state->tile->frame;
int cu_width = LCU_WIDTH >> depth;
double cost = MAX_INT;
double inter_zero_coeff_cost = MAX_INT;
double cost = MAX_DOUBLE;
double inter_zero_coeff_cost = MAX_DOUBLE;
uint32_t inter_bitcost = MAX_INT;
cu_info_t *cur_cu;

Expand Down
21 changes: 21 additions & 0 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,28 @@
#include "image.h"
#include "constraint.h"

#define MAX_UNIT_STATS_MAP_SIZE MAX(MAX_REF_PIC_COUNT, MRG_MAX_NUM_CANDS)

/**
* \brief Data collected during search processes.
*
* The intended use is to collect statistics of the
* searched coding/prediction units. Data related to
* a specific unit is found at index i. The arrays
* should be indexed by elements of the "keys" array
* that will be sorted by the RD costs of the units.
*/
typedef struct unit_stats_map_t {

cu_info_t unit[MAX_UNIT_STATS_MAP_SIZE]; //!< list of searched units
double cost[MAX_UNIT_STATS_MAP_SIZE]; //!< list of matching RD costs
uint32_t bits[MAX_UNIT_STATS_MAP_SIZE]; //!< list of matching bit costs
int8_t keys[MAX_UNIT_STATS_MAP_SIZE]; //!< list of keys (indices) to elements in the other arrays
int size; //!< number of active elements in the lists
} unit_stats_map_t;

void kvz_sort_modes(int8_t *__restrict modes, double *__restrict costs, uint8_t length);
void kvz_sort_keys_by_cost(unit_stats_map_t *__restrict map);

void kvz_search_lcu(encoder_state_t *state, int x, int y, const yuv_t *hor_buf, const yuv_t *ver_buf);

Expand Down

0 comments on commit 96b00ff

Please sign in to comment.