chromium/third_party/libaom/source/libaom/av1/encoder/nonrd_opt.h

/*
 * Copyright (c) 2022, Alliance for Open Media. All rights reserved.
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 */

#ifndef AOM_AV1_ENCODER_NONRD_OPT_H_
#define AOM_AV1_ENCODER_NONRD_OPT_H_

#include "av1/encoder/rdopt_utils.h"
#include "av1/encoder/rdopt.h"

#define RTC_INTER_MODES
#define RTC_INTRA_MODES
#define RTC_MODES
#define CALC_BIASED_RDCOST(rdcost)
#define NUM_COMP_INTER_MODES_RT
#define NUM_INTER_MODES
#define CAP_TX_SIZE_FOR_BSIZE_GT32(tx_mode_search_type, bsize)
#define TX_SIZE_FOR_BSIZE_GT32
#define FILTER_SEARCH_SIZE
#if !CONFIG_REALTIME_ONLY
#define MOTION_MODE_SEARCH_SIZE
#endif

extern int g_pick_inter_mode_cnt;
/*!\cond */
PRED_BUFFER;

BEST_PICKMODE;

REF_MODE;

COMP_REF_MODE;

struct estimate_block_intra_args {};
/*!\endcond */

/*!\brief Structure to store parameters and statistics used in non-rd inter mode
 * evaluation.
 */
InterModeSearchStateNonrd;

static const uint8_t b_width_log2_lookup[BLOCK_SIZES] =;
static const uint8_t b_height_log2_lookup[BLOCK_SIZES] =;

static const PREDICTION_MODE intra_mode_list[] =;

static const PREDICTION_MODE inter_mode_list[] =;

static const THR_MODES mode_idx[REF_FRAMES][RTC_MODES] =;

// GLOBALMV in the set below is in fact ZEROMV as we don't do global ME in RT
// mode
static const REF_MODE ref_mode_set[NUM_INTER_MODES] =;

static const COMP_REF_MODE comp_ref_mode_set[NUM_COMP_INTER_MODES_RT] =;

static const int_interpfilters filters_ref_set[9] =;

enum {};

// The original scan order (default_scan_8x8) is modified according to the extra
// transpose in hadamard c implementation, i.e., aom_hadamard_lp_8x8_c and
// aom_hadamard_8x8_c.
DECLARE_ALIGNED(16, static const int16_t, default_scan_8x8_transpose[64]) =;

// The original scan order (av1_default_iscan_8x8) is modified to match
// hadamard AVX2 implementation, i.e., aom_hadamard_lp_8x8_avx2 and
// aom_hadamard_8x8_avx2. Since hadamard AVX2 implementation will modify the
// order of coefficients, such that the normal scan order is no longer
// guaranteed to scan low coefficients first, therefore we modify the scan order
// accordingly.
// Note that this one has to be used together with default_scan_8x8_transpose.
DECLARE_ALIGNED(16, static const int16_t,
                av1_default_iscan_8x8_transpose[64]) =;

// The original scan order (default_scan_16x16) is modified according to the
// extra transpose in hadamard c implementation in lp case, i.e.,
// aom_hadamard_lp_16x16_c.
DECLARE_ALIGNED(16, static const int16_t,
                default_scan_lp_16x16_transpose[256]) =;

#if CONFIG_AV1_HIGHBITDEPTH
// The original scan order (default_scan_16x16) is modified according to the
// extra shift in hadamard c implementation in fp case, i.e.,
// aom_hadamard_16x16_c. Note that 16x16 lp and fp hadamard generate different
// outputs, so we handle them separately.
DECLARE_ALIGNED(16, static const int16_t,
                default_scan_fp_16x16_transpose[256]) = {
  0,   4,   2,   8,   6,   16,  20,  18,  12,  10,  64,  14,  24,  22,  32,
  36,  34,  28,  26,  68,  66,  72,  70,  80,  30,  40,  38,  48,  52,  50,
  44,  42,  84,  82,  76,  74,  128, 78,  88,  86,  96,  46,  56,  54,  1,
  5,   3,   60,  58,  100, 98,  92,  90,  132, 130, 136, 134, 144, 94,  104,
  102, 112, 62,  9,   7,   17,  21,  19,  13,  11,  116, 114, 108, 106, 148,
  146, 140, 138, 192, 142, 152, 150, 160, 110, 120, 118, 65,  15,  25,  23,
  33,  37,  35,  29,  27,  69,  67,  124, 122, 164, 162, 156, 154, 196, 194,
  200, 198, 208, 158, 168, 166, 176, 126, 73,  71,  81,  31,  41,  39,  49,
  53,  51,  45,  43,  85,  83,  77,  75,  180, 178, 172, 170, 212, 210, 204,
  202, 206, 216, 214, 224, 174, 184, 182, 129, 79,  89,  87,  97,  47,  57,
  55,  61,  59,  101, 99,  93,  91,  133, 131, 188, 186, 228, 226, 220, 218,
  222, 232, 230, 240, 190, 137, 135, 145, 95,  105, 103, 113, 63,  117, 115,
  109, 107, 149, 147, 141, 139, 244, 242, 236, 234, 238, 248, 246, 193, 143,
  153, 151, 161, 111, 121, 119, 125, 123, 165, 163, 157, 155, 197, 195, 252,
  250, 254, 201, 199, 209, 159, 169, 167, 177, 127, 181, 179, 173, 171, 213,
  211, 205, 203, 207, 217, 215, 225, 175, 185, 183, 189, 187, 229, 227, 221,
  219, 223, 233, 231, 241, 191, 245, 243, 237, 235, 239, 249, 247, 253, 251,
  255
};
#endif

// The original scan order (av1_default_iscan_16x16) is modified to match
// hadamard AVX2 implementation, i.e., aom_hadamard_lp_16x16_avx2.
// Since hadamard AVX2 implementation will modify the order of coefficients,
// such that the normal scan order is no longer guaranteed to scan low
// coefficients first, therefore we modify the scan order accordingly. Note that
// this one has to be used together with default_scan_lp_16x16_transpose.
DECLARE_ALIGNED(16, static const int16_t,
                av1_default_iscan_lp_16x16_transpose[256]) =;

#if CONFIG_AV1_HIGHBITDEPTH
// The original scan order (av1_default_iscan_16x16) is modified to match
// hadamard AVX2 implementation, i.e., aom_hadamard_16x16_avx2.
// Since hadamard AVX2 implementation will modify the order of coefficients,
// such that the normal scan order is no longer guaranteed to scan low
// coefficients first, therefore we modify the scan order accordingly. Note that
// this one has to be used together with default_scan_fp_16x16_transpose.
DECLARE_ALIGNED(16, static const int16_t,
                av1_default_iscan_fp_16x16_transpose[256]) = {
  0,   44,  2,   46,  1,   45,  4,   64,  3,   63,  9,   69,  8,   68,  11,
  87,  5,   65,  7,   67,  6,   66,  13,  89,  12,  88,  18,  94,  17,  93,
  24,  116, 14,  90,  16,  92,  15,  91,  26,  118, 25,  117, 31,  123, 30,
  122, 41,  148, 27,  119, 29,  121, 28,  120, 43,  150, 42,  149, 48,  152,
  47,  151, 62,  177, 10,  86,  20,  96,  19,  95,  22,  114, 21,  113, 35,
  127, 34,  126, 37,  144, 23,  115, 33,  125, 32,  124, 39,  146, 38,  145,
  52,  156, 51,  155, 58,  173, 40,  147, 50,  154, 49,  153, 60,  175, 59,
  174, 73,  181, 72,  180, 83,  198, 61,  176, 71,  179, 70,  178, 85,  200,
  84,  199, 98,  202, 97,  201, 112, 219, 36,  143, 54,  158, 53,  157, 56,
  171, 55,  170, 77,  185, 76,  184, 79,  194, 57,  172, 75,  183, 74,  182,
  81,  196, 80,  195, 102, 206, 101, 205, 108, 215, 82,  197, 100, 204, 99,
  203, 110, 217, 109, 216, 131, 223, 130, 222, 140, 232, 111, 218, 129, 221,
  128, 220, 142, 234, 141, 233, 160, 236, 159, 235, 169, 245, 78,  193, 104,
  208, 103, 207, 106, 213, 105, 212, 135, 227, 134, 226, 136, 228, 107, 214,
  133, 225, 132, 224, 138, 230, 137, 229, 164, 240, 163, 239, 165, 241, 139,
  231, 162, 238, 161, 237, 167, 243, 166, 242, 189, 249, 188, 248, 190, 250,
  168, 244, 187, 247, 186, 246, 192, 252, 191, 251, 210, 254, 209, 253, 211,
  255
};
#endif

// For entropy coding, IDTX shares the scan orders of the other 2D-transforms,
// but the fastest way to calculate the IDTX transform (i.e. no transposes)
// results in coefficients that are a transposition of the entropy coding
// versions. These tables are used as substitute for the scan order for the
// faster version of IDTX.

// Must be used together with av1_fast_idtx_iscan_4x4
DECLARE_ALIGNED(16, static const int16_t,
                av1_fast_idtx_scan_4x4[16]) =;

// Must be used together with av1_fast_idtx_scan_4x4
DECLARE_ALIGNED(16, static const int16_t,
                av1_fast_idtx_iscan_4x4[16]) =;

static const SCAN_ORDER av1_fast_idtx_scan_order_4x4 =;

// Must be used together with av1_fast_idtx_iscan_8x8
DECLARE_ALIGNED(16, static const int16_t, av1_fast_idtx_scan_8x8[64]) =;

// Must be used together with av1_fast_idtx_scan_8x8
DECLARE_ALIGNED(16, static const int16_t, av1_fast_idtx_iscan_8x8[64]) =;

static const SCAN_ORDER av1_fast_idtx_scan_order_8x8 =;

// Must be used together with av1_fast_idtx_iscan_16x16
DECLARE_ALIGNED(16, static const int16_t, av1_fast_idtx_scan_16x16[256]) =;

// Must be used together with av1_fast_idtx_scan_16x16
DECLARE_ALIGNED(16, static const int16_t, av1_fast_idtx_iscan_16x16[256]) =;

// Indicates the blocks for which RD model should be based on special logic
static inline int get_model_rd_flag(const AV1_COMP *cpi, const MACROBLOCKD *xd,
                                    BLOCK_SIZE bsize) {}
/*!\brief Finds predicted motion vectors for a block.
 *
 * \ingroup nonrd_mode_search
 * \callgraph
 * \callergraph
 * Finds predicted motion vectors for a block from a certain reference frame.
 * First, it fills reference MV stack, then picks the test from the stack and
 * predicts the final MV for a block for each mode.
 * \param[in]    cpi                      Top-level encoder structure
 * \param[in]    x                        Pointer to structure holding all the
 *                                        data for the current macroblock
 * \param[in]    ref_frame                Reference frame for which to find
 *                                        ref MVs
 * \param[out]   frame_mv                 Predicted MVs for a block
 * \param[in]    yv12_mb                  Buffer to hold predicted block
 * \param[in]    bsize                    Current block size
 * \param[in]    force_skip_low_temp_var  Flag indicating possible mode search
 *                                        prune for low temporal variance block
 * \param[in]    skip_pred_mv             Flag indicating to skip av1_mv_pred
 * \param[out]   use_scaled_ref_frame     Flag to indicate if scaled reference
 *                                        frame is used.
 *
 * \remark Nothing is returned. Instead, predicted MVs are placed into
 * \c frame_mv array, and use_scaled_ref_frame is set.
 */
static inline void find_predictors(
    AV1_COMP *cpi, MACROBLOCK *x, MV_REFERENCE_FRAME ref_frame,
    int_mv frame_mv[MB_MODE_COUNT][REF_FRAMES],
    struct buf_2d yv12_mb[8][MAX_MB_PLANE], BLOCK_SIZE bsize,
    int force_skip_low_temp_var, int skip_pred_mv, bool *use_scaled_ref_frame) {}

static inline void init_mbmi_nonrd(MB_MODE_INFO *mbmi,
                                   PREDICTION_MODE pred_mode,
                                   MV_REFERENCE_FRAME ref_frame0,
                                   MV_REFERENCE_FRAME ref_frame1,
                                   const AV1_COMMON *cm) {}

static inline void init_estimate_block_intra_args(
    struct estimate_block_intra_args *args, AV1_COMP *cpi, MACROBLOCK *x) {}

static inline int get_pred_buffer(PRED_BUFFER *p, int len) {}

static inline void free_pred_buffer(PRED_BUFFER *p) {}

#if CONFIG_INTERNAL_STATS
static inline void store_coding_context_nonrd(MACROBLOCK *x,
                                              PICK_MODE_CONTEXT *ctx,
                                              int mode_index) {
#else
static inline void store_coding_context_nonrd(MACROBLOCK *x,
                                              PICK_MODE_CONTEXT *ctx) {}

void av1_block_yrd(MACROBLOCK *x, RD_STATS *this_rdc, int *skippable,
                   BLOCK_SIZE bsize, TX_SIZE tx_size);

void av1_block_yrd_idtx(MACROBLOCK *x, const uint8_t *const pred_buf,
                        int pred_stride, RD_STATS *this_rdc, int *skippable,
                        BLOCK_SIZE bsize, TX_SIZE tx_size);

int64_t av1_model_rd_for_sb_uv(AV1_COMP *cpi, BLOCK_SIZE plane_bsize,
                               MACROBLOCK *x, MACROBLOCKD *xd,
                               RD_STATS *this_rdc, int start_plane,
                               int stop_plane);

void av1_estimate_block_intra(int plane, int block, int row, int col,
                              BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
                              void *arg);

void av1_estimate_intra_mode(AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
                             int best_early_term, unsigned int ref_cost_intra,
                             int reuse_prediction, struct buf_2d *orig_dst,
                             PRED_BUFFER *tmp_buffers,
                             PRED_BUFFER **this_mode_pred, RD_STATS *best_rdc,
                             BEST_PICKMODE *best_pickmode,
                             PICK_MODE_CONTEXT *ctx);

#endif  // AOM_AV1_ENCODER_NONRD_OPT_H_