Fix another rebase mistake

This commit is contained in:
Joose Sainio 2022-06-13 13:30:33 +03:00
parent 2cbba030dc
commit 66fef4934e
2 changed files with 194 additions and 126 deletions

View file

@ -516,7 +516,7 @@ static void encode_chroma_tu(encoder_state_t* const state, int x, int y, int dep
// TODO: transform skip for chroma blocks
CABAC_BIN(cabac, (cur_pu->tr_skip >> COLOR_U) & 1, "transform_skip_flag");
}
uvg_encode_coeff_nxn(state, &state->cabac, coeff_u, width_c, COLOR_U, *scan_idx, NULL, cur_pu);
uvg_encode_coeff_nxn(state, &state->cabac, coeff_u, width_c, COLOR_U, *scan_idx, cur_pu, NULL);
}
if (cbf_is_set(cur_pu->cbf, depth, COLOR_V)) {
@ -524,7 +524,7 @@ static void encode_chroma_tu(encoder_state_t* const state, int x, int y, int dep
cabac->cur_ctx = &cabac->ctx.transform_skip_model_chroma;
CABAC_BIN(cabac, (cur_pu->tr_skip >> COLOR_V) & 1, "transform_skip_flag");
}
uvg_encode_coeff_nxn(state, &state->cabac, coeff_v, width_c, COLOR_V, *scan_idx, NULL, cur_pu);
uvg_encode_coeff_nxn(state, &state->cabac, coeff_v, width_c, COLOR_V, *scan_idx, cur_pu, NULL);
}
}
else {
@ -533,7 +533,7 @@ static void encode_chroma_tu(encoder_state_t* const state, int x, int y, int dep
cabac->cur_ctx = &cabac->ctx.transform_skip_model_chroma;
CABAC_BIN(cabac, 0, "transform_skip_flag");
}
uvg_encode_coeff_nxn(state, &state->cabac, coeff_uv, width_c, COLOR_V, *scan_idx, NULL, cur_pu);
uvg_encode_coeff_nxn(state, &state->cabac, coeff_uv, width_c, COLOR_V, *scan_idx, cur_pu, NULL);
}
}

View file

@ -396,13 +396,19 @@ static double search_intra_trdepth(
{
pred_cu->mts_last_scan_pos = 0;
pred_cu->violates_mts_coeff_constraint = 0;
}
const int max_tb_size = TR_MAX_WIDTH;
// LFNST search params
const int max_lfnst_idx = width > max_tb_size || height > max_tb_size ? 0 : 2;
const int max_lfnst_idx = width > max_tb_size || height > max_tb_size ?
0 :
2;
int start_idx = 0;
int end_idx = state->encoder_control->cfg.lfnst && depth == pred_cu->tr_depth ? max_lfnst_idx : 0;
int end_idx = state->encoder_control->cfg.lfnst && depth == pred_cu->
tr_depth ?
max_lfnst_idx :
0;
for (int lfnst_idx = start_idx; lfnst_idx <= end_idx; lfnst_idx++) {
// Initialize lfnst variables
@ -417,7 +423,8 @@ static double search_intra_trdepth(
pred_cu->mts_last_scan_pos = 0;
pred_cu->violates_mts_coeff_constraint = 0;
if (trafo == MTS_SKIP && width > (1 << state->encoder_control->cfg.trskip_max_size)) {
if (trafo == MTS_SKIP && width > (
1 << state->encoder_control->cfg.trskip_max_size)) {
//TODO: parametrize that this is not hardcoded
// TODO: this probably should currently trip for chroma?
continue;
@ -427,19 +434,21 @@ static double search_intra_trdepth(
if (pred_cu->lfnst_idx > 0 && pred_cu->tr_idx > 0) {
continue;
}
uvg_intra_recon_cu(state,
x_px, y_px,
depth, search_data,
uvg_intra_recon_cu(
state,
x_px,
y_px,
depth,
search_data,
pred_cu,
lcu);
if (trafo != 0 && !cbf_is_set(pred_cu->cbf, depth, COLOR_Y)) continue;
// TODO: Not sure if this should be 0 or 1 but at least seems to work with 1
derive_mts_constraints(pred_cu, lcu, depth, lcu_px);
if (pred_cu->tr_idx > 1)
{
if (pred_cu->violates_mts_coeff_constraint || !pred_cu->mts_last_scan_pos)
{
if (pred_cu->tr_idx > 1) {
if (pred_cu->violates_mts_coeff_constraint || !pred_cu->
mts_last_scan_pos) {
continue;
}
}
@ -448,25 +457,42 @@ static double search_intra_trdepth(
// Temp constraints. Updating the actual pred_cu constraints here will break things later
bool constraints[2] = {pred_cu->violates_lfnst_constrained[0],
pred_cu->lfnst_last_scan_pos};
derive_lfnst_constraints(pred_cu, lcu, depth, COLOR_Y, lcu_px, constraints);
derive_lfnst_constraints(
pred_cu,
lcu,
depth,
COLOR_Y,
lcu_px,
constraints);
if (constraints[0] || !constraints[1]) {
continue;
}
}
double rd_cost = uvg_cu_rd_cost_luma(state, lcu_px.x, lcu_px.y, depth, pred_cu, lcu);
double rd_cost = uvg_cu_rd_cost_luma(
state,
lcu_px.x,
lcu_px.y,
depth,
pred_cu,
lcu);
double mts_bits = 0;
if (num_transforms > 1 && trafo != MTS_SKIP && width <= 32 /*&& height <= 32*/
&& !pred_cu->violates_mts_coeff_constraint && pred_cu->mts_last_scan_pos) {
if (num_transforms > 1 && trafo != MTS_SKIP && width <= 32
/*&& height <= 32*/
&& !pred_cu->violates_mts_coeff_constraint && pred_cu->
mts_last_scan_pos) {
bool symbol = trafo != 0;
int ctx_idx = 0;
mts_bits += CTX_ENTROPY_FBITS(&state->search_cabac.ctx.mts_idx_model[ctx_idx], symbol);
mts_bits += CTX_ENTROPY_FBITS(
&state->search_cabac.ctx.mts_idx_model[ctx_idx],
symbol);
ctx_idx++;
for (int i = 0; i < 3 && symbol; i++, ctx_idx++)
{
for (int i = 0; i < 3 && symbol; i++, ctx_idx++) {
symbol = trafo > i + MTS_DST7_DST7 ? 1 : 0;
mts_bits += CTX_ENTROPY_FBITS(&state->search_cabac.ctx.mts_idx_model[ctx_idx], symbol);
mts_bits += CTX_ENTROPY_FBITS(
&state->search_cabac.ctx.mts_idx_model[ctx_idx],
symbol);
}
}
@ -478,20 +504,31 @@ static double search_intra_trdepth(
best_rd_cost = rd_cost;
best_lfnst_idx = pred_cu->lfnst_idx;
best_tr_idx = pred_cu->tr_idx;
if (best_tr_idx == MTS_SKIP) break; // Very unlikely that further search is necessary if skip seems best option
if (best_tr_idx == MTS_SKIP) break;
// Very unlikely that further search is necessary if skip seems best option
}
} // end mts index loop (tr_idx)
if (reconstruct_chroma) {
int8_t luma_mode = pred_cu->intra.mode;
pred_cu->intra.mode = -1;
pred_cu->intra.mode_chroma = chroma_mode;
pred_cu->joint_cb_cr = 4; // TODO: Maybe check the jccr mode here also but holy shit is the interface of search_intra_rdo bad currently
uvg_intra_recon_cu(state,
x_px, y_px,
depth, search_data,
pred_cu->joint_cb_cr = 4;
// TODO: Maybe check the jccr mode here also but holy shit is the interface of search_intra_rdo bad currently
uvg_intra_recon_cu(
state,
x_px,
y_px,
depth,
search_data,
pred_cu,
lcu);
best_rd_cost += uvg_cu_rd_cost_chroma(
state,
lcu_px.x,
lcu_px.y,
depth,
pred_cu,
lcu);
best_rd_cost += uvg_cu_rd_cost_chroma(state, lcu_px.x, lcu_px.y, depth, pred_cu, lcu);
pred_cu->intra.mode = luma_mode;
// Check lfnst constraints for chroma
@ -499,19 +536,32 @@ static double search_intra_trdepth(
// Temp constraints. Updating the actual pred_cu constraints here will break things later
bool constraints[2] = {pred_cu->violates_lfnst_constrained[1],
pred_cu->lfnst_last_scan_pos};
derive_lfnst_constraints(pred_cu, lcu, depth, COLOR_U, lcu_px, constraints);
derive_lfnst_constraints(
pred_cu,
lcu,
depth,
COLOR_U,
lcu_px,
constraints);
if (constraints[0] || !constraints[1]) {
best_lfnst_idx = 0;
continue;
}
derive_lfnst_constraints(pred_cu, lcu, depth, COLOR_V, lcu_px, constraints);
derive_lfnst_constraints(
pred_cu,
lcu,
depth,
COLOR_V,
lcu_px,
constraints);
if (constraints[0] || !constraints[1]) {
best_lfnst_idx = 0;
continue;
}
}
}
if (best_tr_idx == MTS_SKIP) break; // Very unlikely that further search is necessary if skip seems best option
if (best_tr_idx == MTS_SKIP) break;
// Very unlikely that further search is necessary if skip seems best option
} // end lfnst_index loop
pred_cu->tr_skip = best_tr_idx == MTS_SKIP;
@ -531,13 +581,31 @@ static double search_intra_trdepth(
nosplit_cbf = pred_cu->cbf;
uvg_pixels_blit(lcu->rec.y, nosplit_pixels.y, width, width, LCU_WIDTH, width);
uvg_pixels_blit(
lcu->rec.y,
nosplit_pixels.y,
width,
width,
LCU_WIDTH,
width);
if (reconstruct_chroma) {
uvg_pixels_blit(lcu->rec.u, nosplit_pixels.u, width_c, width_c, LCU_WIDTH_C, width_c);
uvg_pixels_blit(lcu->rec.v, nosplit_pixels.v, width_c, width_c, LCU_WIDTH_C, width_c);
}
uvg_pixels_blit(
lcu->rec.u,
nosplit_pixels.u,
width_c,
width_c,
LCU_WIDTH_C,
width_c);
uvg_pixels_blit(
lcu->rec.v,
nosplit_pixels.v,
width_c,
width_c,
LCU_WIDTH_C,
width_c);
}
}
}
// Recurse further if all of the following:
// - Current depth is less than maximum depth of the search (max_depth).