Fix jccr and chroma mode search

This commit is contained in:
Joose Sainio 2022-04-14 11:29:56 +03:00
parent 24faf0024d
commit f4dc3ab43b
4 changed files with 35 additions and 14 deletions

View file

@ -1589,7 +1589,7 @@ void kvz_intra_recon_cu(
intra_recon_tb_leaf(state, x, y, depth, lcu, COLOR_V, search_data);
}
kvz_quantize_lcu_residual(state, has_luma, has_chroma,
kvz_quantize_lcu_residual(state, has_luma, has_chroma && !(search_data->pred_cu.joint_cb_cr & 3),
search_data->pred_cu.joint_cb_cr != 4 && state->encoder_control->cfg.jccr && (x % 8 == 0 && y % 8 == 0),
x, y, depth, cur_cu, lcu, false);
}

View file

@ -996,21 +996,23 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth,
// rd2. Possibly because the luma mode search already takes chroma
// into account, so there is less of a chanse of luma mode being
// really bad for chroma.
cur_cu->joint_cb_cr = 0;
intra_search.pred_cu.intra.mode_chroma = cur_cu->intra.mode_chroma; // skip luma
if (ctrl->cfg.rdo >= 3 && !cur_cu->intra.mip_flag) {
cur_cu->intra.mode_chroma = kvz_search_cu_intra_chroma(state, x, y, depth, lcu, intra_search.cclm_parameters);
cur_cu->intra.mode_chroma = kvz_search_cu_intra_chroma(state, x, y, depth, lcu, &intra_search);
if (intra_search.pred_cu.joint_cb_cr == 0) intra_search.pred_cu.joint_cb_cr = 4;
else cur_cu->joint_cb_cr = intra_search.pred_cu.joint_cb_cr;
lcu_fill_cu_info(lcu, x_local, y_local, cu_width, cu_width, cur_cu);
}
intra_search.pred_cu.intra.mode_chroma = intra_search.pred_cu.intra.mode;
intra_search.pred_cu.intra.mode = -1; // skip luma
intra_search.pred_cu.joint_cb_cr = 0;
kvz_intra_recon_cu(state,
x & ~7, y & ~7, // TODO: as does this
depth, &intra_search,
NULL,
lcu);
cur_cu->intra.mode_chroma = intra_search.pred_cu.intra.mode_chroma;
cur_cu->joint_cb_cr = intra_search.pred_cu.joint_cb_cr;
if(depth != 0 && state->encoder_control->cfg.jccr) {
if(depth != 0 && state->encoder_control->cfg.jccr && ctrl->cfg.rdo < 3) {
kvz_select_jccr_mode(state,
x & ~7, y & ~7,
depth,
@ -1018,6 +1020,16 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth,
lcu,
NULL);
}
else if(depth != 0 && state->encoder_control->cfg.jccr && cur_cu->joint_cb_cr & 3) {
assert(cur_cu->joint_cb_cr < 4);
const vector2d_t lcu_px = { (x_local & ~7) / 2, (y_local & ~7) / 2 };
int lcu_width = LCU_WIDTH_C;
const int index = lcu_px.x + lcu_px.y * lcu_width;
const int width = (depth < MAX_DEPTH) ? LCU_WIDTH >> (depth + 1) : LCU_WIDTH >> depth;
kvz_pixels_blit(&lcu->rec.joint_u[index], &lcu->rec.u[index], width, width, lcu_width, lcu_width);
kvz_pixels_blit(&lcu->rec.joint_v[index], &lcu->rec.v[index], width, width, lcu_width, lcu_width);
}
}
} else if (cur_cu->type == CU_INTER) {

View file

@ -927,14 +927,14 @@ int8_t kvz_search_intra_chroma_rdo(
kvz_intra_recon_cu(state,
x_px, y_px,
depth, &chroma_data[i],
NULL,
&chroma_data[i].pred_cu,
lcu);
}
if(tr_cu->depth != tr_cu->tr_depth || !state->encoder_control->cfg.jccr) {
chroma_data[i].cost = kvz_cu_rd_cost_chroma(state, lcu_px.x, lcu_px.y, depth, tr_cu, lcu);
chroma_data[i].cost = kvz_cu_rd_cost_chroma(state, lcu_px.x, lcu_px.y, depth, &chroma_data[i].pred_cu, lcu);
} else {
kvz_select_jccr_mode(state, lcu_px.x, lcu_px.y, depth, tr_cu, lcu, &chroma_data[i].cost);
kvz_select_jccr_mode(state, lcu_px.x, lcu_px.y, depth, &chroma_data[i].pred_cu, lcu, &chroma_data[i].cost);
}
double mode_bits = kvz_chroma_mode_bits(state, mode, chroma_data[i].pred_cu.intra.mode);
@ -951,7 +951,7 @@ int8_t kvz_search_intra_chroma_rdo(
int8_t kvz_search_cu_intra_chroma(encoder_state_t * const state,
const int x_px, const int y_px,
const int depth, lcu_t *lcu, cclm_parameters_t *best_cclm)
const int depth, lcu_t *lcu, intra_search_data_t *search_data)
{
const vector2d_t lcu_px = { SUB_SCU(x_px), SUB_SCU(y_px) };
@ -987,6 +987,7 @@ int8_t kvz_search_cu_intra_chroma(encoder_state_t * const state,
for (int i = 0; i < num_modes; i++) {
chroma_data[i].pred_cu = *cur_pu;
chroma_data[i].pred_cu.intra.mode_chroma = modes[i];
chroma_data[i].pred_cu.intra.mode = -1;
}
// Don't do rough mode search if all modes are selected.
// FIXME: It might make more sense to only disable rough search if
@ -1019,7 +1020,7 @@ int8_t kvz_search_cu_intra_chroma(encoder_state_t * const state,
if (num_modes > 1) {
intra_mode_chroma = kvz_search_intra_chroma_rdo(state, x_px, y_px, depth, num_modes, lcu, chroma_data);
}
*search_data = chroma_data[0];
return intra_mode_chroma;
}
@ -1199,7 +1200,15 @@ void kvz_search_cu_intra(
search_data[0].pred_cu.mts_last_scan_pos = false;
}
else {
sort_modes(search_data, number_of_modes);
double best_cost = MAX_INT;
int best_mode = 0;
for (int mode = 0; mode < number_of_modes; mode++) {
if (search_data[mode].cost < best_cost) {
best_cost = search_data[mode].cost;
best_mode = mode;
}
}
search_data[0] = search_data[best_mode];
}
*mode_out = search_data[0];
}

View file

@ -50,7 +50,7 @@ double kvz_chroma_mode_bits(const encoder_state_t *state,
int8_t kvz_search_cu_intra_chroma(encoder_state_t * const state,
const int x_px, const int y_px,
const int depth, lcu_t *lcu, cclm_parameters_t* best_cclm);
const int depth, lcu_t *lcu, intra_search_data_t* best_cclm);
void kvz_search_cu_intra(
encoder_state_t * const state,