Cosmetic changes in av1_cdef_search() Change-Id: I10ce0bcf852de1d42185b95679a0608a5995f2da
diff --git a/av1/encoder/pickcdef.c b/av1/encoder/pickcdef.c index 2fd2053..b17cf63 100644 --- a/av1/encoder/pickcdef.c +++ b/av1/encoder/pickcdef.c
@@ -15,6 +15,7 @@ #include "config/aom_scale_rtcd.h" #include "aom/aom_integer.h" +#include "aom_ports/system_state.h" #include "av1/common/cdef.h" #include "av1/common/onyxc_int.h" #include "av1/common/reconinter.h" @@ -301,51 +302,33 @@ void av1_cdef_search(YV12_BUFFER_CONFIG *frame, const YV12_BUFFER_CONFIG *ref, AV1_COMMON *cm, MACROBLOCKD *xd, int fast) { CdefInfo *const cdef_info = &cm->cdef_info; - int r, c; - int fbr, fbc; uint16_t *src[3]; uint16_t *ref_coeff[3]; static cdef_list dlist[MI_SIZE_128X128 * MI_SIZE_128X128]; int dir[CDEF_NBLOCKS][CDEF_NBLOCKS] = { { 0 } }; int var[CDEF_NBLOCKS][CDEF_NBLOCKS] = { { 0 } }; + const int nvfb = (cm->mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64; + const int nhfb = (cm->mi_cols + MI_SIZE_64X64 - 1) / MI_SIZE_64X64; + int *sb_index = aom_malloc(nvfb * nhfb * sizeof(*sb_index)); + int *selected_strength = aom_malloc(nvfb * nhfb * sizeof(*sb_index)); + const int pri_damping = 3 + (cm->base_qindex >> 6); + const int sec_damping = 3 + (cm->base_qindex >> 6); + const int total_strengths = fast ? REDUCED_TOTAL_STRENGTHS : TOTAL_STRENGTHS; + DECLARE_ALIGNED(32, uint16_t, tmp_dst[1 << (MAX_SB_SIZE_LOG2 * 2)]); + const int num_planes = av1_num_planes(cm); + av1_setup_dst_planes(xd->plane, cm->seq_params.sb_size, frame, 0, 0, 0, + num_planes); + uint64_t(*mse[2])[TOTAL_STRENGTHS]; + mse[0] = aom_malloc(sizeof(**mse) * nvfb * nhfb); + mse[1] = aom_malloc(sizeof(**mse) * nvfb * nhfb); + int stride[3]; int bsize[3]; int mi_wide_l2[3]; int mi_high_l2[3]; int xdec[3]; int ydec[3]; - int pli; - int cdef_count; - int coeff_shift = AOMMAX(cm->seq_params.bit_depth - 8, 0); - uint64_t best_tot_mse = (uint64_t)1 << 63; - uint64_t tot_mse; - int sb_count; - int nvfb = (cm->mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64; - int nhfb = (cm->mi_cols + MI_SIZE_64X64 - 1) / MI_SIZE_64X64; - int *sb_index = aom_malloc(nvfb * nhfb * sizeof(*sb_index)); - int *selected_strength = aom_malloc(nvfb * nhfb * sizeof(*sb_index)); - uint64_t(*mse[2])[TOTAL_STRENGTHS]; - int pri_damping = 3 + (cm->base_qindex >> 6); - int sec_damping = 3 + (cm->base_qindex >> 6); - int i; - int nb_strengths; - int nb_strength_bits; - int quantizer; - double lambda; - const int num_planes = av1_num_planes(cm); - const int total_strengths = fast ? REDUCED_TOTAL_STRENGTHS : TOTAL_STRENGTHS; - DECLARE_ALIGNED(32, uint16_t, inbuf[CDEF_INBUF_SIZE]); - uint16_t *in; - DECLARE_ALIGNED(32, uint16_t, tmp_dst[1 << (MAX_SB_SIZE_LOG2 * 2)]); - quantizer = av1_ac_quant_Q3(cm->base_qindex, 0, cm->seq_params.bit_depth) >> - (cm->seq_params.bit_depth - 8); - lambda = .12 * quantizer * quantizer / 256.; - - av1_setup_dst_planes(xd->plane, cm->seq_params.sb_size, frame, 0, 0, 0, - num_planes); - mse[0] = aom_malloc(sizeof(**mse) * nvfb * nhfb); - mse[1] = aom_malloc(sizeof(**mse) * nvfb * nhfb); - for (pli = 0; pli < num_planes; pli++) { + for (int pli = 0; pli < num_planes; pli++) { uint8_t *ref_buffer; int ref_stride; switch (pli) { @@ -378,35 +361,31 @@ (cm->mi_rows * MI_SIZE) >> xd->plane[pli].subsampling_y; const int frame_width = (cm->mi_cols * MI_SIZE) >> xd->plane[pli].subsampling_x; - - for (r = 0; r < frame_height; ++r) { - for (c = 0; c < frame_width; ++c) { + const int plane_sride = stride[pli]; + const int dst_stride = xd->plane[pli].dst.stride; + for (int r = 0; r < frame_height; ++r) { + for (int c = 0; c < frame_width; ++c) { if (cm->seq_params.use_highbitdepth) { - src[pli][r * stride[pli] + c] = CONVERT_TO_SHORTPTR( - xd->plane[pli].dst.buf)[r * xd->plane[pli].dst.stride + c]; - ref_coeff[pli][r * stride[pli] + c] = + src[pli][r * plane_sride + c] = + CONVERT_TO_SHORTPTR(xd->plane[pli].dst.buf)[r * dst_stride + c]; + ref_coeff[pli][r * plane_sride + c] = CONVERT_TO_SHORTPTR(ref_buffer)[r * ref_stride + c]; } else { - src[pli][r * stride[pli] + c] = - xd->plane[pli].dst.buf[r * xd->plane[pli].dst.stride + c]; - ref_coeff[pli][r * stride[pli] + c] = ref_buffer[r * ref_stride + c]; + src[pli][r * plane_sride + c] = + xd->plane[pli].dst.buf[r * dst_stride + c]; + ref_coeff[pli][r * plane_sride + c] = ref_buffer[r * ref_stride + c]; } } } } - in = inbuf + CDEF_VBORDER * CDEF_BSTRIDE + CDEF_HBORDER; - sb_count = 0; - for (fbr = 0; fbr < nvfb; ++fbr) { - for (fbc = 0; fbc < nhfb; ++fbc) { - int nvb, nhb; - int gi; - int dirinit = 0; - nhb = AOMMIN(MI_SIZE_64X64, cm->mi_cols - MI_SIZE_64X64 * fbc); - nvb = AOMMIN(MI_SIZE_64X64, cm->mi_rows - MI_SIZE_64X64 * fbr); - int hb_step = 1; - int vb_step = 1; - BLOCK_SIZE bs = BLOCK_64X64; - MB_MODE_INFO *const mbmi = + + DECLARE_ALIGNED(32, uint16_t, inbuf[CDEF_INBUF_SIZE]); + uint16_t *const in = inbuf + CDEF_VBORDER * CDEF_BSTRIDE + CDEF_HBORDER; + const int coeff_shift = AOMMAX(cm->seq_params.bit_depth - 8, 0); + int sb_count = 0; + for (int fbr = 0; fbr < nvfb; ++fbr) { + for (int fbc = 0; fbc < nhfb; ++fbc) { + const MB_MODE_INFO *const mbmi = cm->mi_grid_visible[MI_SIZE_64X64 * fbr * cm->mi_stride + MI_SIZE_64X64 * fbc]; if (((fbc & 1) && @@ -414,6 +393,12 @@ ((fbr & 1) && (mbmi->sb_type == BLOCK_128X128 || mbmi->sb_type == BLOCK_64X128))) continue; + + int nhb = AOMMIN(MI_SIZE_64X64, cm->mi_cols - MI_SIZE_64X64 * fbc); + int nvb = AOMMIN(MI_SIZE_64X64, cm->mi_rows - MI_SIZE_64X64 * fbr); + int hb_step = 1; + int vb_step = 1; + BLOCK_SIZE bs = BLOCK_64X64; if (mbmi->sb_type == BLOCK_128X128 || mbmi->sb_type == BLOCK_128X64 || mbmi->sb_type == BLOCK_64X128) bs = mbmi->sb_type; @@ -425,29 +410,29 @@ nvb = AOMMIN(MI_SIZE_128X128, cm->mi_rows - MI_SIZE_64X64 * fbr); vb_step = 2; } + // No filtering if the entire filter block is skipped if (sb_all_skip(cm, fbr * MI_SIZE_64X64, fbc * MI_SIZE_64X64)) continue; - cdef_count = cdef_compute_sb_list(cm, fbr * MI_SIZE_64X64, - fbc * MI_SIZE_64X64, dlist, bs); - for (pli = 0; pli < num_planes; pli++) { - for (i = 0; i < CDEF_INBUF_SIZE; i++) inbuf[i] = CDEF_VERY_LARGE; - for (gi = 0; gi < total_strengths; gi++) { - int threshold; - uint64_t curr_mse; - int sec_strength; - threshold = gi / CDEF_SEC_STRENGTHS; + const int cdef_count = cdef_compute_sb_list( + cm, fbr * MI_SIZE_64X64, fbc * MI_SIZE_64X64, dlist, bs); + + int dirinit = 0; + for (int pli = 0; pli < num_planes; pli++) { + for (int i = 0; i < CDEF_INBUF_SIZE; i++) inbuf[i] = CDEF_VERY_LARGE; + for (int gi = 0; gi < total_strengths; gi++) { + int threshold = gi / CDEF_SEC_STRENGTHS; if (fast) threshold = priconv[threshold]; /* We avoid filtering the pixels for which some of the pixels to average are outside the frame. We could change the filter instead, but it would add special cases for any future vectorization. */ - int yoff = CDEF_VBORDER * (fbr != 0); - int xoff = CDEF_HBORDER * (fbc != 0); - int ysize = (nvb << mi_high_l2[pli]) + - CDEF_VBORDER * (fbr + vb_step < nvfb) + yoff; - int xsize = (nhb << mi_wide_l2[pli]) + - CDEF_HBORDER * (fbc + hb_step < nhfb) + xoff; - sec_strength = gi % CDEF_SEC_STRENGTHS; + const int yoff = CDEF_VBORDER * (fbr != 0); + const int xoff = CDEF_HBORDER * (fbc != 0); + const int ysize = (nvb << mi_high_l2[pli]) + + CDEF_VBORDER * (fbr + vb_step < nvfb) + yoff; + const int xsize = (nhb << mi_wide_l2[pli]) + + CDEF_HBORDER * (fbc + hb_step < nhfb) + xoff; + const int sec_strength = gi % CDEF_SEC_STRENGTHS; copy_sb16_16(&in[(-yoff * CDEF_BSTRIDE - xoff)], CDEF_BSTRIDE, src[pli], (fbr * MI_SIZE_64X64 << mi_high_l2[pli]) - yoff, @@ -457,7 +442,7 @@ dir, &dirinit, var, pli, dlist, cdef_count, threshold, sec_strength + (sec_strength == 3), pri_damping, sec_damping, coeff_shift); - curr_mse = compute_cdef_dist( + const uint64_t curr_mse = compute_cdef_dist( ref_coeff[pli] + (fbr * MI_SIZE_64X64 << mi_high_l2[pli]) * stride[pli] + (fbc * MI_SIZE_64X64 << mi_wide_l2[pli]), @@ -474,19 +459,28 @@ sb_count++; } } - nb_strength_bits = 0; + /* Search for different number of signalling bits. */ - for (i = 0; i <= 3; i++) { - int j; + int nb_strengths; + int nb_strength_bits = 0; + uint64_t best_tot_mse = (uint64_t)1 << 63; + const int quantizer = + av1_ac_quant_Q3(cm->base_qindex, 0, cm->seq_params.bit_depth) >> + (cm->seq_params.bit_depth - 8); + aom_clear_system_state(); + const double lambda = .12 * quantizer * quantizer / 256.; + for (int i = 0; i <= 3; i++) { int best_lev0[CDEF_MAX_STRENGTHS]; int best_lev1[CDEF_MAX_STRENGTHS] = { 0 }; nb_strengths = 1 << i; - if (num_planes >= 3) + uint64_t tot_mse; + if (num_planes >= 3) { tot_mse = joint_strength_search_dual(best_lev0, best_lev1, nb_strengths, mse, sb_count, fast); - else + } else { tot_mse = joint_strength_search(best_lev0, nb_strengths, mse[0], sb_count, fast); + } /* Count superblock signalling cost. */ tot_mse += (uint64_t)(sb_count * lambda * i); /* Count header signalling cost. */ @@ -494,7 +488,7 @@ if (tot_mse < best_tot_mse) { best_tot_mse = tot_mse; nb_strength_bits = i; - for (j = 0; j < 1 << nb_strength_bits; j++) { + for (int j = 0; j < 1 << nb_strength_bits; j++) { cdef_info->cdef_strengths[j] = best_lev0[j]; cdef_info->cdef_uv_strengths[j] = best_lev1[j]; } @@ -504,12 +498,10 @@ cdef_info->cdef_bits = nb_strength_bits; cdef_info->nb_cdef_strengths = nb_strengths; - for (i = 0; i < sb_count; i++) { - int gi; - int best_gi; + for (int i = 0; i < sb_count; i++) { uint64_t best_mse = (uint64_t)1 << 63; - best_gi = 0; - for (gi = 0; gi < cdef_info->nb_cdef_strengths; gi++) { + int best_gi = 0; + for (int gi = 0; gi < cdef_info->nb_cdef_strengths; gi++) { uint64_t curr = mse[0][i][cdef_info->cdef_strengths[gi]]; if (num_planes >= 3) curr += mse[1][i][cdef_info->cdef_uv_strengths[gi]]; if (curr < best_mse) { @@ -533,11 +525,13 @@ (cdef_info->cdef_uv_strengths[j] % CDEF_SEC_STRENGTHS); } } + cdef_info->cdef_pri_damping = pri_damping; cdef_info->cdef_sec_damping = sec_damping; + aom_free(mse[0]); aom_free(mse[1]); - for (pli = 0; pli < num_planes; pli++) { + for (int pli = 0; pli < num_planes; pli++) { aom_free(src[pli]); aom_free(ref_coeff[pli]); }