From b0d616b03cb2fea351c1653dd90fd367c0a4a259 Mon Sep 17 00:00:00 2001 From: Joose Sainio Date: Tue, 21 Jun 2022 15:44:00 +0300 Subject: [PATCH] [dual-tree][tests] Fix some issues and enable cabac state test to test for dual tree --- src/encode_coding_tree.c | 2 +- src/search.c | 13 +++++++++---- src/search_intra.c | 2 +- tests/check_cabac_state_consistency.py | 16 ++++++++-------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/encode_coding_tree.c b/src/encode_coding_tree.c index 8e5303bd..6fa4b080 100644 --- a/src/encode_coding_tree.c +++ b/src/encode_coding_tree.c @@ -1747,7 +1747,7 @@ void uvg_encode_coding_tree( exit(1); } if (state->encoder_control->cabac_debug_file) { - fprintf(state->encoder_control->cabac_debug_file, "E %4d %4d %d", x, y, depth); + fprintf(state->encoder_control->cabac_debug_file, "E %4d %4d %d %d", x << (tree_type == UVG_CHROMA_T), y << (tree_type == UVG_CHROMA_T), depth, tree_type); fwrite(&cabac->ctx, 1, sizeof(cabac->ctx), state->encoder_control->cabac_debug_file); } diff --git a/src/search.c b/src/search.c index 15d6391c..9bcc83a3 100644 --- a/src/search.c +++ b/src/search.c @@ -589,7 +589,7 @@ static double cu_rd_cost_tr_split_accurate( unsigned chroma_ssd = 0; if(has_chroma) { - const vector2d_t lcu_px = { (x_px & ~7 ) / 2, (y_px & ~7) / 2 }; + const vector2d_t lcu_px = { (x_px >> (tree_type != UVG_CHROMA_T)) & ~3, (y_px >> (tree_type != UVG_CHROMA_T)) &~3 }; const int chroma_width = MAX(4, LCU_WIDTH >> (depth + 1)); int8_t scan_order = uvg_get_scan_order(pred_cu->type, pred_cu->intra.mode_chroma, depth); const unsigned index = xy_to_zorder(LCU_WIDTH_C, lcu_px.x, lcu_px.y); @@ -943,7 +943,7 @@ static double search_cu( intra_search.pred_cu.joint_cb_cr = 0; // TODO: This heavily relies to square CUs - if ((depth != 4 || (x % 8 && y % 8)) && state->encoder_control->chroma_format != UVG_CSP_400) { + if ((depth != 4 || (x % 8 && y % 8)) && state->encoder_control->chroma_format != UVG_CSP_400 && tree_type != UVG_LUMA_T) { // There is almost no benefit to doing the chroma mode search for // rd2. Possibly because the luma mode search already takes chroma // into account, so there is less of a chanse of luma mode being @@ -973,7 +973,12 @@ static double search_cu( &intra_search.pred_cu, lcu, tree_type); - intra_cost += uvg_cu_rd_cost_chroma(state, x_local, y_local, depth, &intra_search.pred_cu, lcu); + if(tree_type != UVG_CHROMA_T) { + intra_cost += uvg_cu_rd_cost_chroma(state, x_local, y_local, depth, &intra_search.pred_cu, lcu); + } + else { + intra_cost = intra_search.cost; + } intra_search.pred_cu.intra.mode = intra_mode; intra_search.pred_cu.violates_lfnst_constrained_chroma = false; intra_search.pred_cu.lfnst_last_scan_pos = false; @@ -1124,7 +1129,7 @@ static double search_cu( depth < pu_depth_inter.max); if(state->encoder_control->cabac_debug_file) { - fprintf(state->encoder_control->cabac_debug_file, "S %4d %4d %d", x, y, depth); + fprintf(state->encoder_control->cabac_debug_file, "S %4d %4d %d %d", x, y, depth, tree_type); fwrite(&state->search_cabac.ctx, 1, sizeof(state->search_cabac.ctx), state->encoder_control->cabac_debug_file); } diff --git a/src/search_intra.c b/src/search_intra.c index 5fc2737a..fda2f0f9 100644 --- a/src/search_intra.c +++ b/src/search_intra.c @@ -1628,7 +1628,7 @@ int8_t uvg_search_cu_intra_chroma( chroma_data[i].pred_cu.intra.mode_chroma = num_modes == 1 ? intra_mode : modes[i]; chroma_data[i].pred_cu.intra.mode = -1; chroma_data[i].cost = 0; - if(depth != 4) { + if(depth != 4 && tree_type == UVG_BOTH_T) { memcpy(chroma_data[i].lfnst_costs, search_data->lfnst_costs, sizeof(double) * 3); } } diff --git a/tests/check_cabac_state_consistency.py b/tests/check_cabac_state_consistency.py index 952f536a..4d7f970c 100644 --- a/tests/check_cabac_state_consistency.py +++ b/tests/check_cabac_state_consistency.py @@ -30,9 +30,9 @@ def main(state_file: Path, ctx_names: list, ctx_count: int = 332, ctx_size: int with open(state_file, "rb") as file: try: while True: - type_, x, y, depth = file.read(13).decode().split() + type_, x, y, depth, tree_type = file.read(15).decode().split() # Reset stored data at the beginning of the frame - if x == '0' and y == '0' and type_ == "S": + if x == '0' and y == '0' and type_ == "S" and tree_type != "2": if not was_zero_last: frame_num += 1 ctx_store = dict() @@ -44,14 +44,14 @@ def main(state_file: Path, ctx_names: list, ctx_count: int = 332, ctx_size: int ctx = file.read(ctx_count * ctx_size) if type_ == "S": # These shouldn't happen but just to make sure everything is working as intended - if ctx_store.get((x, y, depth)): + if ctx_store.get((x, y, depth, tree_type)): raise RuntimeError - ctx_store[(x, y, depth)] = ctx + ctx_store[(x, y, depth, tree_type)] = ctx else: - if (x, y, depth) in e_store: + if (x, y, depth, tree_type) in e_store: raise RuntimeError - e_store.add((x, y, depth)) - if (s_ctx := ctx_store[(x, y, depth)]) != ctx: + e_store.add((x, y, depth, tree_type)) + if (s_ctx := ctx_store[(x, y, depth, tree_type)]) != ctx: actual_problem = False for i in range(ctx_count): @@ -61,7 +61,7 @@ def main(state_file: Path, ctx_names: list, ctx_count: int = 332, ctx_size: int if ctx_names[i] in ignore_list: continue actual_problem = True - print(f"MISSMATCH in {ctx_names[i]} {frame_num=} {x=} {y=} {depth=}") + print(f"MISSMATCH in {ctx_names[i]} {frame_num=} {x=} {y=} {depth=} {tree_type=}") print( f"GOT : {int.from_bytes(temp_s[0:2], 'little')}:" f"{int.from_bytes(temp_s[2:4], 'little')} "