From 3a81a389c3ebd3d0213017bedb5168a375d417b5 Mon Sep 17 00:00:00 2001 From: siivonek Date: Mon, 6 Dec 2021 19:12:08 +0200 Subject: [PATCH] [mrl] Fix issues transmitting multi ref idx during search. Change multi ref idx type to uint. --- src/encode_coding_tree.c | 2 +- src/intra.c | 15 ++++++++------- src/intra.h | 3 ++- src/search.c | 8 ++++---- src/search_intra.c | 13 ++++++------- src/search_intra.h | 2 +- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/encode_coding_tree.c b/src/encode_coding_tree.c index 19f5f8b9..618d942b 100644 --- a/src/encode_coding_tree.c +++ b/src/encode_coding_tree.c @@ -856,7 +856,7 @@ static void encode_intra_coding_unit(encoder_state_t * const state, bool allow_isp = enough_samples; // Code MRL related bits - int multi_ref_idx = cur_cu->intra.multi_ref_idx; + int multi_ref_idx = cur_cu->type == CU_INTRA ? cur_cu->intra.multi_ref_idx : 0; bool enable_mrl = state->encoder_control->cfg.mrl; if (cur_cu->type == CU_INTRA && (y % LCU_WIDTH) != 0 && !cur_cu->bdpcmMode && enable_mrl) { diff --git a/src/intra.c b/src/intra.c index 44a34cb3..d8cc7858 100644 --- a/src/intra.c +++ b/src/intra.c @@ -967,7 +967,7 @@ void kvz_intra_build_reference( kvz_intra_references *const refs, bool entropy_sync, kvz_pixel *extra_ref_lines, - int8_t multi_ref_idx) + uint8_t multi_ref_idx) { assert(!(extra_ref_lines == NULL && multi_ref_idx != 0) && "Trying to use MRL with NULL extra references."); @@ -1012,7 +1012,7 @@ static void intra_recon_tb_leaf( int x_scu = SUB_SCU(x); int y_scu = SUB_SCU(y); const vector2d_t lcu_px = {x_scu >> shift, y_scu >> shift }; - uint8_t multi_ref_index = multi_ref_idx; + uint8_t multi_ref_index = color == COLOR_Y ? multi_ref_idx : 0; kvz_intra_references refs; // Extra reference lines for use with MRL. Extra lines needed only for left edge. @@ -1097,6 +1097,7 @@ void kvz_intra_recon_cu( int8_t mode_chroma, cu_info_t *cur_cu, cclm_parameters_t *cclm_params, + uint8_t multi_ref_idx, lcu_t *lcu) { const vector2d_t lcu_px = { SUB_SCU(x), SUB_SCU(y) }; @@ -1104,7 +1105,7 @@ void kvz_intra_recon_cu( if (cur_cu == NULL) { cur_cu = LCU_GET_CU_AT_PX(lcu, lcu_px.x, lcu_px.y); } - uint8_t multi_ref_index = cur_cu->intra.multi_ref_idx; + uint8_t multi_ref_index = multi_ref_idx; // Reset CBFs because CBFs might have been set // for depth earlier @@ -1122,10 +1123,10 @@ void kvz_intra_recon_cu( const int32_t x2 = x + offset; const int32_t y2 = y + offset; - kvz_intra_recon_cu(state, x, y, depth + 1, mode_luma, mode_chroma, NULL, NULL, lcu); - kvz_intra_recon_cu(state, x2, y, depth + 1, mode_luma, mode_chroma, NULL, NULL, lcu); - kvz_intra_recon_cu(state, x, y2, depth + 1, mode_luma, mode_chroma, NULL, NULL, lcu); - kvz_intra_recon_cu(state, x2, y2, depth + 1, mode_luma, mode_chroma, NULL, NULL, lcu); + kvz_intra_recon_cu(state, x, y, depth + 1, mode_luma, mode_chroma, NULL, NULL, multi_ref_index, lcu); + kvz_intra_recon_cu(state, x2, y, depth + 1, mode_luma, mode_chroma, NULL, NULL, multi_ref_index, lcu); + kvz_intra_recon_cu(state, x, y2, depth + 1, mode_luma, mode_chroma, NULL, NULL, multi_ref_index, lcu); + kvz_intra_recon_cu(state, x2, y2, depth + 1, mode_luma, mode_chroma, NULL, NULL, multi_ref_index, lcu); // Propagate coded block flags from child CUs to parent CU. uint16_t child_cbfs[3] = { diff --git a/src/intra.h b/src/intra.h index b5c81a7f..1d05fea0 100644 --- a/src/intra.h +++ b/src/intra.h @@ -99,7 +99,7 @@ void kvz_intra_build_reference( kvz_intra_references *const refs, bool entropy_sync, kvz_pixel *extra_refs, - int8_t multi_ref_idx); + uint8_t multi_ref_idx); /** * \brief Generate intra predictions. @@ -129,6 +129,7 @@ void kvz_intra_recon_cu( int8_t mode_chroma, cu_info_t *cur_cu, cclm_parameters_t* cclm_params, + uint8_t multi_ref_idx, lcu_t *lcu); diff --git a/src/search.c b/src/search.c index b5612182..13fa66a7 100644 --- a/src/search.c +++ b/src/search.c @@ -724,7 +724,7 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth, int8_t intra_mode; int8_t intra_trafo; double intra_cost; - int8_t multi_ref_index = 0; + uint8_t multi_ref_index = 0; kvz_search_cu_intra(state, x, y, depth, lcu, &intra_mode, &intra_trafo, &intra_cost, &multi_ref_index); if (intra_cost < cost) { @@ -749,7 +749,7 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth, x, y, depth, cur_cu->intra.mode, -1, // skip chroma - NULL, NULL, lcu); + NULL, NULL, cur_cu->intra.multi_ref_idx, lcu); downsample_cclm_rec( state, x, y, cu_width / 2, cu_width / 2, lcu->rec.y, lcu->left_ref.y[64] @@ -771,7 +771,7 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth, x & ~7, y & ~7, // TODO: as does this depth, -1, cur_cu->intra.mode_chroma, // skip luma - NULL, cclm_params, lcu); + NULL, cclm_params, 0, lcu); } } else if (cur_cu->type == CU_INTER) { @@ -931,7 +931,7 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth, x, y, depth, cur_cu->intra.mode, mode_chroma, - NULL,NULL, lcu); + NULL,NULL, 0, lcu); cost += kvz_cu_rd_cost_luma(state, x_local, y_local, depth, cur_cu, lcu); if (has_chroma) { diff --git a/src/search_intra.c b/src/search_intra.c index c7ec0bfa..5f4ae144 100644 --- a/src/search_intra.c +++ b/src/search_intra.c @@ -333,7 +333,7 @@ static double search_intra_trdepth(encoder_state_t * const state, x_px, y_px, depth, intra_mode, -1, - pred_cu, cclm_params, lcu); + pred_cu, cclm_params, pred_cu->intra.multi_ref_idx, lcu); // TODO: Not sure if this should be 0 or 1 but at least seems to work with 1 if (pred_cu->tr_idx > 1) @@ -361,7 +361,7 @@ static double search_intra_trdepth(encoder_state_t * const state, x_px, y_px, depth, -1, chroma_mode, - pred_cu, cclm_params, lcu); + pred_cu, cclm_params, 0, lcu); best_rd_cost += kvz_cu_rd_cost_chroma(state, lcu_px.x, lcu_px.y, depth, pred_cu, lcu); } pred_cu->tr_skip = best_tr_idx == MTS_SKIP; @@ -716,7 +716,7 @@ static int8_t search_intra_rdo(encoder_state_t * const state, int modes_to_check, int8_t modes[67], int8_t trafo[67], double costs[67], lcu_t *lcu, - int8_t multi_ref_idx) + uint8_t multi_ref_idx) { const int tr_depth = CLIP(1, MAX_PU_DEPTH, depth + state->encoder_control->cfg.tr_depth_intra); const int width = LCU_WIDTH >> depth; @@ -901,7 +901,7 @@ int8_t kvz_search_intra_chroma_rdo(encoder_state_t * const state, x_px, y_px, depth, -1, chroma.mode, // skip luma - NULL, NULL, lcu); + NULL, NULL, 0, lcu); } else { @@ -934,8 +934,7 @@ int8_t kvz_search_intra_chroma_rdo(encoder_state_t * const state, x_px, y_px, depth, -1, chroma.mode, // skip luma - NULL, cclm_params, lcu - ); + NULL, cclm_params, 0, lcu); } chroma.cost = kvz_cu_rd_cost_chroma(state, lcu_px.x, lcu_px.y, depth, tr_cu, lcu); @@ -1025,7 +1024,7 @@ void kvz_search_cu_intra(encoder_state_t * const state, int8_t *mode_out, int8_t *trafo_out, double *cost_out, - int8_t *multi_ref_idx_out) + uint8_t *multi_ref_idx_out) { const vector2d_t lcu_px = { SUB_SCU(x_px), SUB_SCU(y_px) }; const int8_t cu_width = LCU_WIDTH >> depth; diff --git a/src/search_intra.h b/src/search_intra.h index df55f5f9..f7ce24c0 100644 --- a/src/search_intra.h +++ b/src/search_intra.h @@ -60,6 +60,6 @@ void kvz_search_cu_intra(encoder_state_t * const state, int8_t *mode_out, int8_t *trafo_out, double *cost_out, - int8_t *multi_ref_idx_out); + uint8_t *multi_ref_idx_out); #endif // SEARCH_INTRA_H_