Coverage Report

Created: 2026-05-30 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavif/ext/aom/av1/encoder/model_rd.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2020, Alliance for Open Media. All rights reserved.
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#ifndef AOM_AV1_ENCODER_MODEL_RD_H_
13
#define AOM_AV1_ENCODER_MODEL_RD_H_
14
15
#include "aom/aom_integer.h"
16
#include "av1/encoder/block.h"
17
#include "av1/encoder/encoder.h"
18
#include "av1/encoder/pustats.h"
19
#include "av1/encoder/rdopt_utils.h"
20
#include "config/aom_dsp_rtcd.h"
21
22
#ifdef __cplusplus
23
extern "C" {
24
#endif
25
26
// 0: Legacy model
27
// 1: Curve fit model
28
// 2: Surface fit model
29
// 3: DNN regression model
30
// 4: Full rd model
31
278k
#define MODELRD_TYPE_INTERP_FILTER 1
32
0
#define MODELRD_TYPE_TX_SEARCH_PRUNE 1
33
734k
#define MODELRD_TYPE_MASKED_COMPOUND 1
34
0
#define MODELRD_TYPE_INTERINTRA 1
35
#define MODELRD_TYPE_INTRA 1
36
55.8k
#define MODELRD_TYPE_MOTION_MODE_RD 1
37
38
typedef void (*model_rd_for_sb_type)(
39
    const AV1_COMP *const cpi, BLOCK_SIZE bsize, MACROBLOCK *x, MACROBLOCKD *xd,
40
    int plane_from, int plane_to, int *out_rate_sum, int64_t *out_dist_sum,
41
    uint8_t *skip_txfm_sb, int64_t *skip_sse_sb, int *plane_rate,
42
    int64_t *plane_sse, int64_t *plane_dist);
43
typedef void (*model_rd_from_sse_type)(const AV1_COMP *const cpi,
44
                                       const MACROBLOCK *const x,
45
                                       BLOCK_SIZE plane_bsize, int plane,
46
                                       int64_t sse, int num_samples, int *rate,
47
                                       int64_t *dist);
48
49
static int64_t calculate_sse(MACROBLOCKD *const xd,
50
                             const struct macroblock_plane *p,
51
                             struct macroblockd_plane *pd, const int bw,
52
907k
                             const int bh) {
53
907k
  int64_t sse = 0;
54
907k
  const int shift = xd->bd - 8;
55
907k
#if CONFIG_AV1_HIGHBITDEPTH
56
907k
  if (is_cur_buf_hbd(xd)) {
57
159k
    sse = aom_highbd_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride,
58
159k
                         bw, bh);
59
747k
  } else {
60
747k
    sse =
61
747k
        aom_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride, bw, bh);
62
747k
  }
63
#else
64
  sse = aom_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride, bw, bh);
65
#endif
66
907k
  sse = ROUND_POWER_OF_TWO(sse, shift * 2);
67
907k
  return sse;
68
907k
}
Unexecuted instantiation: av1_cx_iface.c:calculate_sse
Unexecuted instantiation: allintra_vis.c:calculate_sse
Unexecuted instantiation: encodeframe.c:calculate_sse
Unexecuted instantiation: encoder.c:calculate_sse
Unexecuted instantiation: encoder_utils.c:calculate_sse
Unexecuted instantiation: ethread.c:calculate_sse
Unexecuted instantiation: palette.c:calculate_sse
Unexecuted instantiation: partition_search.c:calculate_sse
rdopt.c:calculate_sse
Line
Count
Source
52
117k
                             const int bh) {
53
117k
  int64_t sse = 0;
54
117k
  const int shift = xd->bd - 8;
55
117k
#if CONFIG_AV1_HIGHBITDEPTH
56
117k
  if (is_cur_buf_hbd(xd)) {
57
26.4k
    sse = aom_highbd_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride,
58
26.4k
                         bw, bh);
59
90.6k
  } else {
60
90.6k
    sse =
61
90.6k
        aom_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride, bw, bh);
62
90.6k
  }
63
#else
64
  sse = aom_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride, bw, bh);
65
#endif
66
117k
  sse = ROUND_POWER_OF_TWO(sse, shift * 2);
67
117k
  return sse;
68
117k
}
Unexecuted instantiation: nonrd_pickmode.c:calculate_sse
Unexecuted instantiation: superres_scale.c:calculate_sse
Unexecuted instantiation: svc_layercontext.c:calculate_sse
Unexecuted instantiation: temporal_filter.c:calculate_sse
Unexecuted instantiation: tx_search.c:calculate_sse
Unexecuted instantiation: intra_mode_search.c:calculate_sse
compound_type.c:calculate_sse
Line
Count
Source
52
511k
                             const int bh) {
53
511k
  int64_t sse = 0;
54
511k
  const int shift = xd->bd - 8;
55
511k
#if CONFIG_AV1_HIGHBITDEPTH
56
511k
  if (is_cur_buf_hbd(xd)) {
57
83.5k
    sse = aom_highbd_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride,
58
83.5k
                         bw, bh);
59
428k
  } else {
60
428k
    sse =
61
428k
        aom_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride, bw, bh);
62
428k
  }
63
#else
64
  sse = aom_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride, bw, bh);
65
#endif
66
511k
  sse = ROUND_POWER_OF_TWO(sse, shift * 2);
67
511k
  return sse;
68
511k
}
Unexecuted instantiation: encode_strategy.c:calculate_sse
interp_search.c:calculate_sse
Line
Count
Source
52
278k
                             const int bh) {
53
278k
  int64_t sse = 0;
54
278k
  const int shift = xd->bd - 8;
55
278k
#if CONFIG_AV1_HIGHBITDEPTH
56
278k
  if (is_cur_buf_hbd(xd)) {
57
49.6k
    sse = aom_highbd_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride,
58
49.6k
                         bw, bh);
59
228k
  } else {
60
228k
    sse =
61
228k
        aom_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride, bw, bh);
62
228k
  }
63
#else
64
  sse = aom_sse(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride, bw, bh);
65
#endif
66
278k
  sse = ROUND_POWER_OF_TWO(sse, shift * 2);
67
278k
  return sse;
68
278k
}
69
70
static inline int64_t compute_sse_plane(MACROBLOCK *x, MACROBLOCKD *xd,
71
250k
                                        int plane, const BLOCK_SIZE bsize) {
72
250k
  struct macroblockd_plane *const pd = &xd->plane[plane];
73
250k
  const BLOCK_SIZE plane_bsize =
74
250k
      get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
75
250k
  int bw, bh;
76
250k
  const struct macroblock_plane *const p = &x->plane[plane];
77
250k
  get_txb_dimensions(xd, plane, plane_bsize, 0, 0, plane_bsize, NULL, NULL, &bw,
78
250k
                     &bh);
79
80
250k
  int64_t sse = calculate_sse(xd, p, pd, bw, bh);
81
82
250k
  return sse;
83
250k
}
Unexecuted instantiation: av1_cx_iface.c:compute_sse_plane
Unexecuted instantiation: allintra_vis.c:compute_sse_plane
Unexecuted instantiation: encodeframe.c:compute_sse_plane
Unexecuted instantiation: encoder.c:compute_sse_plane
Unexecuted instantiation: encoder_utils.c:compute_sse_plane
Unexecuted instantiation: ethread.c:compute_sse_plane
Unexecuted instantiation: palette.c:compute_sse_plane
Unexecuted instantiation: partition_search.c:compute_sse_plane
Unexecuted instantiation: rdopt.c:compute_sse_plane
Unexecuted instantiation: nonrd_pickmode.c:compute_sse_plane
Unexecuted instantiation: superres_scale.c:compute_sse_plane
Unexecuted instantiation: svc_layercontext.c:compute_sse_plane
Unexecuted instantiation: temporal_filter.c:compute_sse_plane
Unexecuted instantiation: tx_search.c:compute_sse_plane
Unexecuted instantiation: intra_mode_search.c:compute_sse_plane
compound_type.c:compute_sse_plane
Line
Count
Source
71
250k
                                        int plane, const BLOCK_SIZE bsize) {
72
250k
  struct macroblockd_plane *const pd = &xd->plane[plane];
73
250k
  const BLOCK_SIZE plane_bsize =
74
250k
      get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
75
250k
  int bw, bh;
76
250k
  const struct macroblock_plane *const p = &x->plane[plane];
77
250k
  get_txb_dimensions(xd, plane, plane_bsize, 0, 0, plane_bsize, NULL, NULL, &bw,
78
250k
                     &bh);
79
80
250k
  int64_t sse = calculate_sse(xd, p, pd, bw, bh);
81
82
250k
  return sse;
83
250k
}
Unexecuted instantiation: encode_strategy.c:compute_sse_plane
Unexecuted instantiation: interp_search.c:compute_sse_plane
84
85
static inline void model_rd_from_sse(const AV1_COMP *const cpi,
86
                                     const MACROBLOCK *const x,
87
                                     BLOCK_SIZE plane_bsize, int plane,
88
                                     int64_t sse, int num_samples, int *rate,
89
0
                                     int64_t *dist) {
90
0
  (void)num_samples;
91
0
  const MACROBLOCKD *const xd = &x->e_mbd;
92
0
  const struct macroblock_plane *const p = &x->plane[plane];
93
0
  const int dequant_shift = (is_cur_buf_hbd(xd)) ? xd->bd - 5 : 3;
94
95
  // Fast approximate the modelling function.
96
0
  if (cpi->sf.rd_sf.simple_model_rd_from_var) {
97
0
    const int64_t square_error = sse;
98
0
    int quantizer = p->dequant_QTX[1] >> dequant_shift;
99
0
    if (quantizer < 120)
100
0
      *rate = (int)AOMMIN(
101
0
          (square_error * (280 - quantizer)) >> (16 - AV1_PROB_COST_SHIFT),
102
0
          INT_MAX);
103
0
    else
104
0
      *rate = 0;
105
0
    assert(*rate >= 0);
106
0
    *dist = (square_error * quantizer) >> 8;
107
0
  } else {
108
0
    av1_model_rd_from_var_lapndz(sse, num_pels_log2_lookup[plane_bsize],
109
0
                                 p->dequant_QTX[1] >> dequant_shift, rate,
110
0
                                 dist);
111
0
  }
112
0
  *dist <<= 4;
113
0
}
Unexecuted instantiation: av1_cx_iface.c:model_rd_from_sse
Unexecuted instantiation: allintra_vis.c:model_rd_from_sse
Unexecuted instantiation: encodeframe.c:model_rd_from_sse
Unexecuted instantiation: encoder.c:model_rd_from_sse
Unexecuted instantiation: encoder_utils.c:model_rd_from_sse
Unexecuted instantiation: ethread.c:model_rd_from_sse
Unexecuted instantiation: palette.c:model_rd_from_sse
Unexecuted instantiation: partition_search.c:model_rd_from_sse
Unexecuted instantiation: rdopt.c:model_rd_from_sse
Unexecuted instantiation: nonrd_pickmode.c:model_rd_from_sse
Unexecuted instantiation: superres_scale.c:model_rd_from_sse
Unexecuted instantiation: svc_layercontext.c:model_rd_from_sse
Unexecuted instantiation: temporal_filter.c:model_rd_from_sse
Unexecuted instantiation: tx_search.c:model_rd_from_sse
Unexecuted instantiation: intra_mode_search.c:model_rd_from_sse
Unexecuted instantiation: compound_type.c:model_rd_from_sse
Unexecuted instantiation: encode_strategy.c:model_rd_from_sse
Unexecuted instantiation: interp_search.c:model_rd_from_sse
114
115
// Fits a curve for rate and distortion using as feature:
116
// log2(sse_norm/qstep^2)
117
static inline void model_rd_with_curvfit(const AV1_COMP *const cpi,
118
                                         const MACROBLOCK *const x,
119
                                         BLOCK_SIZE plane_bsize, int plane,
120
                                         int64_t sse, int num_samples,
121
3.35M
                                         int *rate, int64_t *dist) {
122
3.35M
  (void)cpi;
123
3.35M
  (void)plane_bsize;
124
3.35M
  const MACROBLOCKD *const xd = &x->e_mbd;
125
3.35M
  const struct macroblock_plane *const p = &x->plane[plane];
126
3.35M
  const int dequant_shift = (is_cur_buf_hbd(xd)) ? xd->bd - 5 : 3;
127
3.35M
  const int qstep = AOMMAX(p->dequant_QTX[1] >> dequant_shift, 1);
128
129
3.35M
  if (sse == 0) {
130
139
    if (rate) *rate = 0;
131
139
    if (dist) *dist = 0;
132
139
    return;
133
139
  }
134
3.35M
  const double sse_norm = (double)sse / num_samples;
135
3.35M
  const double qstepsqr = (double)qstep * qstep;
136
3.35M
  const double xqr = log2(sse_norm / qstepsqr);
137
3.35M
  double rate_f, dist_by_sse_norm_f;
138
3.35M
  av1_model_rd_curvfit(plane_bsize, sse_norm, xqr, &rate_f,
139
3.35M
                       &dist_by_sse_norm_f);
140
141
3.35M
  const double dist_f = dist_by_sse_norm_f * sse_norm;
142
3.35M
  int rate_i = (int)(AOMMAX(0.0, rate_f * num_samples) + 0.5);
143
3.35M
  int64_t dist_i = (int64_t)(AOMMAX(0.0, dist_f * num_samples) + 0.5);
144
145
  // Check if skip is better
146
3.35M
  if (rate_i == 0) {
147
109
    dist_i = sse << 4;
148
3.35M
  } else if (RDCOST(x->rdmult, rate_i, dist_i) >=
149
3.35M
             RDCOST(x->rdmult, 0, sse << 4)) {
150
19.8k
    rate_i = 0;
151
19.8k
    dist_i = sse << 4;
152
19.8k
  }
153
154
3.37M
  if (rate) *rate = rate_i;
155
3.37M
  if (dist) *dist = dist_i;
156
3.35M
}
Unexecuted instantiation: av1_cx_iface.c:model_rd_with_curvfit
Unexecuted instantiation: allintra_vis.c:model_rd_with_curvfit
Unexecuted instantiation: encodeframe.c:model_rd_with_curvfit
Unexecuted instantiation: encoder.c:model_rd_with_curvfit
Unexecuted instantiation: encoder_utils.c:model_rd_with_curvfit
Unexecuted instantiation: ethread.c:model_rd_with_curvfit
Unexecuted instantiation: palette.c:model_rd_with_curvfit
Unexecuted instantiation: partition_search.c:model_rd_with_curvfit
rdopt.c:model_rd_with_curvfit
Line
Count
Source
121
117k
                                         int *rate, int64_t *dist) {
122
117k
  (void)cpi;
123
117k
  (void)plane_bsize;
124
117k
  const MACROBLOCKD *const xd = &x->e_mbd;
125
117k
  const struct macroblock_plane *const p = &x->plane[plane];
126
117k
  const int dequant_shift = (is_cur_buf_hbd(xd)) ? xd->bd - 5 : 3;
127
117k
  const int qstep = AOMMAX(p->dequant_QTX[1] >> dequant_shift, 1);
128
129
117k
  if (sse == 0) {
130
80
    if (rate) *rate = 0;
131
80
    if (dist) *dist = 0;
132
80
    return;
133
80
  }
134
117k
  const double sse_norm = (double)sse / num_samples;
135
117k
  const double qstepsqr = (double)qstep * qstep;
136
117k
  const double xqr = log2(sse_norm / qstepsqr);
137
117k
  double rate_f, dist_by_sse_norm_f;
138
117k
  av1_model_rd_curvfit(plane_bsize, sse_norm, xqr, &rate_f,
139
117k
                       &dist_by_sse_norm_f);
140
141
117k
  const double dist_f = dist_by_sse_norm_f * sse_norm;
142
117k
  int rate_i = (int)(AOMMAX(0.0, rate_f * num_samples) + 0.5);
143
117k
  int64_t dist_i = (int64_t)(AOMMAX(0.0, dist_f * num_samples) + 0.5);
144
145
  // Check if skip is better
146
117k
  if (rate_i == 0) {
147
0
    dist_i = sse << 4;
148
117k
  } else if (RDCOST(x->rdmult, rate_i, dist_i) >=
149
117k
             RDCOST(x->rdmult, 0, sse << 4)) {
150
3.46k
    rate_i = 0;
151
3.46k
    dist_i = sse << 4;
152
3.46k
  }
153
154
117k
  if (rate) *rate = rate_i;
155
117k
  if (dist) *dist = dist_i;
156
117k
}
nonrd_pickmode.c:model_rd_with_curvfit
Line
Count
Source
121
2.22M
                                         int *rate, int64_t *dist) {
122
2.22M
  (void)cpi;
123
2.22M
  (void)plane_bsize;
124
2.22M
  const MACROBLOCKD *const xd = &x->e_mbd;
125
2.22M
  const struct macroblock_plane *const p = &x->plane[plane];
126
2.22M
  const int dequant_shift = (is_cur_buf_hbd(xd)) ? xd->bd - 5 : 3;
127
2.22M
  const int qstep = AOMMAX(p->dequant_QTX[1] >> dequant_shift, 1);
128
129
2.22M
  if (sse == 0) {
130
39
    if (rate) *rate = 0;
131
39
    if (dist) *dist = 0;
132
39
    return;
133
39
  }
134
2.22M
  const double sse_norm = (double)sse / num_samples;
135
2.22M
  const double qstepsqr = (double)qstep * qstep;
136
2.22M
  const double xqr = log2(sse_norm / qstepsqr);
137
2.22M
  double rate_f, dist_by_sse_norm_f;
138
2.22M
  av1_model_rd_curvfit(plane_bsize, sse_norm, xqr, &rate_f,
139
2.22M
                       &dist_by_sse_norm_f);
140
141
2.22M
  const double dist_f = dist_by_sse_norm_f * sse_norm;
142
2.22M
  int rate_i = (int)(AOMMAX(0.0, rate_f * num_samples) + 0.5);
143
2.22M
  int64_t dist_i = (int64_t)(AOMMAX(0.0, dist_f * num_samples) + 0.5);
144
145
  // Check if skip is better
146
2.22M
  if (rate_i == 0) {
147
66
    dist_i = sse << 4;
148
2.22M
  } else if (RDCOST(x->rdmult, rate_i, dist_i) >=
149
2.22M
             RDCOST(x->rdmult, 0, sse << 4)) {
150
2.72k
    rate_i = 0;
151
2.72k
    dist_i = sse << 4;
152
2.72k
  }
153
154
2.24M
  if (rate) *rate = rate_i;
155
2.24M
  if (dist) *dist = dist_i;
156
2.22M
}
Unexecuted instantiation: superres_scale.c:model_rd_with_curvfit
Unexecuted instantiation: svc_layercontext.c:model_rd_with_curvfit
Unexecuted instantiation: temporal_filter.c:model_rd_with_curvfit
Unexecuted instantiation: tx_search.c:model_rd_with_curvfit
Unexecuted instantiation: intra_mode_search.c:model_rd_with_curvfit
compound_type.c:model_rd_with_curvfit
Line
Count
Source
121
733k
                                         int *rate, int64_t *dist) {
122
733k
  (void)cpi;
123
733k
  (void)plane_bsize;
124
733k
  const MACROBLOCKD *const xd = &x->e_mbd;
125
733k
  const struct macroblock_plane *const p = &x->plane[plane];
126
733k
  const int dequant_shift = (is_cur_buf_hbd(xd)) ? xd->bd - 5 : 3;
127
733k
  const int qstep = AOMMAX(p->dequant_QTX[1] >> dequant_shift, 1);
128
129
733k
  if (sse == 0) {
130
8
    if (rate) *rate = 0;
131
8
    if (dist) *dist = 0;
132
8
    return;
133
8
  }
134
733k
  const double sse_norm = (double)sse / num_samples;
135
733k
  const double qstepsqr = (double)qstep * qstep;
136
733k
  const double xqr = log2(sse_norm / qstepsqr);
137
733k
  double rate_f, dist_by_sse_norm_f;
138
733k
  av1_model_rd_curvfit(plane_bsize, sse_norm, xqr, &rate_f,
139
733k
                       &dist_by_sse_norm_f);
140
141
733k
  const double dist_f = dist_by_sse_norm_f * sse_norm;
142
733k
  int rate_i = (int)(AOMMAX(0.0, rate_f * num_samples) + 0.5);
143
733k
  int64_t dist_i = (int64_t)(AOMMAX(0.0, dist_f * num_samples) + 0.5);
144
145
  // Check if skip is better
146
733k
  if (rate_i == 0) {
147
14
    dist_i = sse << 4;
148
733k
  } else if (RDCOST(x->rdmult, rate_i, dist_i) >=
149
733k
             RDCOST(x->rdmult, 0, sse << 4)) {
150
10.2k
    rate_i = 0;
151
10.2k
    dist_i = sse << 4;
152
10.2k
  }
153
154
733k
  if (rate) *rate = rate_i;
155
733k
  if (dist) *dist = dist_i;
156
733k
}
Unexecuted instantiation: encode_strategy.c:model_rd_with_curvfit
interp_search.c:model_rd_with_curvfit
Line
Count
Source
121
278k
                                         int *rate, int64_t *dist) {
122
278k
  (void)cpi;
123
278k
  (void)plane_bsize;
124
278k
  const MACROBLOCKD *const xd = &x->e_mbd;
125
278k
  const struct macroblock_plane *const p = &x->plane[plane];
126
278k
  const int dequant_shift = (is_cur_buf_hbd(xd)) ? xd->bd - 5 : 3;
127
278k
  const int qstep = AOMMAX(p->dequant_QTX[1] >> dequant_shift, 1);
128
129
278k
  if (sse == 0) {
130
12
    if (rate) *rate = 0;
131
12
    if (dist) *dist = 0;
132
12
    return;
133
12
  }
134
278k
  const double sse_norm = (double)sse / num_samples;
135
278k
  const double qstepsqr = (double)qstep * qstep;
136
278k
  const double xqr = log2(sse_norm / qstepsqr);
137
278k
  double rate_f, dist_by_sse_norm_f;
138
278k
  av1_model_rd_curvfit(plane_bsize, sse_norm, xqr, &rate_f,
139
278k
                       &dist_by_sse_norm_f);
140
141
278k
  const double dist_f = dist_by_sse_norm_f * sse_norm;
142
278k
  int rate_i = (int)(AOMMAX(0.0, rate_f * num_samples) + 0.5);
143
278k
  int64_t dist_i = (int64_t)(AOMMAX(0.0, dist_f * num_samples) + 0.5);
144
145
  // Check if skip is better
146
278k
  if (rate_i == 0) {
147
29
    dist_i = sse << 4;
148
278k
  } else if (RDCOST(x->rdmult, rate_i, dist_i) >=
149
278k
             RDCOST(x->rdmult, 0, sse << 4)) {
150
3.35k
    rate_i = 0;
151
3.35k
    dist_i = sse << 4;
152
3.35k
  }
153
154
278k
  if (rate) *rate = rate_i;
155
278k
  if (dist) *dist = dist_i;
156
278k
}
157
158
static inline void model_rd_for_sb(const AV1_COMP *const cpi, BLOCK_SIZE bsize,
159
                                   MACROBLOCK *x, MACROBLOCKD *xd,
160
                                   int plane_from, int plane_to,
161
                                   int *out_rate_sum, int64_t *out_dist_sum,
162
                                   uint8_t *skip_txfm_sb, int64_t *skip_sse_sb,
163
                                   int *plane_rate, int64_t *plane_sse,
164
0
                                   int64_t *plane_dist) {
165
  // Note our transform coeffs are 8 times an orthogonal transform.
166
  // Hence quantizer step is also 8 times. To get effective quantizer
167
  // we need to divide by 8 before sending to modeling function.
168
0
  int plane;
169
0
  const int ref = xd->mi[0]->ref_frame[0];
170
171
0
  int64_t rate_sum = 0;
172
0
  int64_t dist_sum = 0;
173
0
  int64_t total_sse = 0;
174
175
0
  assert(bsize < BLOCK_SIZES_ALL);
176
177
0
  for (plane = plane_from; plane <= plane_to; ++plane) {
178
0
    if (plane && !xd->is_chroma_ref) break;
179
0
    struct macroblock_plane *const p = &x->plane[plane];
180
0
    struct macroblockd_plane *const pd = &xd->plane[plane];
181
0
    const BLOCK_SIZE plane_bsize =
182
0
        get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
183
0
    assert(plane_bsize < BLOCK_SIZES_ALL);
184
0
    const int bw = block_size_wide[plane_bsize];
185
0
    const int bh = block_size_high[plane_bsize];
186
0
    int64_t sse;
187
0
    int rate;
188
0
    int64_t dist;
189
190
0
    sse = calculate_sse(xd, p, pd, bw, bh);
191
192
0
    model_rd_from_sse(cpi, x, plane_bsize, plane, sse, bw * bh, &rate, &dist);
193
194
0
    if (plane == 0) x->pred_sse[ref] = (unsigned int)AOMMIN(sse, UINT_MAX);
195
196
0
    total_sse += sse;
197
0
    rate_sum += rate;
198
0
    dist_sum += dist;
199
0
    if (plane_rate) plane_rate[plane] = rate;
200
0
    if (plane_sse) plane_sse[plane] = sse;
201
0
    if (plane_dist) plane_dist[plane] = dist;
202
0
    assert(rate_sum >= 0);
203
0
  }
204
205
0
  if (skip_txfm_sb) *skip_txfm_sb = total_sse == 0;
206
0
  if (skip_sse_sb) *skip_sse_sb = total_sse << 4;
207
0
  rate_sum = AOMMIN(rate_sum, INT_MAX);
208
0
  *out_rate_sum = (int)rate_sum;
209
0
  *out_dist_sum = dist_sum;
210
0
}
Unexecuted instantiation: av1_cx_iface.c:model_rd_for_sb
Unexecuted instantiation: allintra_vis.c:model_rd_for_sb
Unexecuted instantiation: encodeframe.c:model_rd_for_sb
Unexecuted instantiation: encoder.c:model_rd_for_sb
Unexecuted instantiation: encoder_utils.c:model_rd_for_sb
Unexecuted instantiation: ethread.c:model_rd_for_sb
Unexecuted instantiation: palette.c:model_rd_for_sb
Unexecuted instantiation: partition_search.c:model_rd_for_sb
Unexecuted instantiation: rdopt.c:model_rd_for_sb
Unexecuted instantiation: nonrd_pickmode.c:model_rd_for_sb
Unexecuted instantiation: superres_scale.c:model_rd_for_sb
Unexecuted instantiation: svc_layercontext.c:model_rd_for_sb
Unexecuted instantiation: temporal_filter.c:model_rd_for_sb
Unexecuted instantiation: tx_search.c:model_rd_for_sb
Unexecuted instantiation: intra_mode_search.c:model_rd_for_sb
Unexecuted instantiation: compound_type.c:model_rd_for_sb
Unexecuted instantiation: encode_strategy.c:model_rd_for_sb
Unexecuted instantiation: interp_search.c:model_rd_for_sb
211
212
static inline void model_rd_for_sb_with_curvfit(
213
    const AV1_COMP *const cpi, BLOCK_SIZE bsize, MACROBLOCK *x, MACROBLOCKD *xd,
214
    int plane_from, int plane_to, int *out_rate_sum, int64_t *out_dist_sum,
215
    uint8_t *skip_txfm_sb, int64_t *skip_sse_sb, int *plane_rate,
216
603k
    int64_t *plane_sse, int64_t *plane_dist) {
217
  // Note our transform coeffs are 8 times an orthogonal transform.
218
  // Hence quantizer step is also 8 times. To get effective quantizer
219
  // we need to divide by 8 before sending to modeling function.
220
603k
  const int ref = xd->mi[0]->ref_frame[0];
221
222
603k
  int64_t rate_sum = 0;
223
603k
  int64_t dist_sum = 0;
224
603k
  int64_t total_sse = 0;
225
226
1.26M
  for (int plane = plane_from; plane <= plane_to; ++plane) {
227
657k
    if (plane && !xd->is_chroma_ref) break;
228
657k
    struct macroblockd_plane *const pd = &xd->plane[plane];
229
657k
    const BLOCK_SIZE plane_bsize =
230
657k
        get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
231
657k
    int64_t dist, sse;
232
657k
    int rate;
233
657k
    int bw, bh;
234
657k
    const struct macroblock_plane *const p = &x->plane[plane];
235
657k
    get_txb_dimensions(xd, plane, plane_bsize, 0, 0, plane_bsize, NULL, NULL,
236
657k
                       &bw, &bh);
237
238
657k
    sse = calculate_sse(xd, p, pd, bw, bh);
239
657k
    model_rd_with_curvfit(cpi, x, plane_bsize, plane, sse, bw * bh, &rate,
240
657k
                          &dist);
241
242
657k
    if (plane == 0) x->pred_sse[ref] = (unsigned int)AOMMIN(sse, UINT_MAX);
243
244
657k
    total_sse += sse;
245
657k
    rate_sum += rate;
246
657k
    dist_sum += dist;
247
248
657k
    if (plane_rate) plane_rate[plane] = rate;
249
657k
    if (plane_sse) plane_sse[plane] = sse;
250
657k
    if (plane_dist) plane_dist[plane] = dist;
251
657k
  }
252
253
603k
  if (skip_txfm_sb) *skip_txfm_sb = rate_sum == 0;
254
603k
  if (skip_sse_sb) *skip_sse_sb = total_sse << 4;
255
603k
  *out_rate_sum = (int)rate_sum;
256
603k
  *out_dist_sum = dist_sum;
257
603k
}
Unexecuted instantiation: av1_cx_iface.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: allintra_vis.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: encodeframe.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: encoder.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: encoder_utils.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: ethread.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: palette.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: partition_search.c:model_rd_for_sb_with_curvfit
rdopt.c:model_rd_for_sb_with_curvfit
Line
Count
Source
216
63.2k
    int64_t *plane_sse, int64_t *plane_dist) {
217
  // Note our transform coeffs are 8 times an orthogonal transform.
218
  // Hence quantizer step is also 8 times. To get effective quantizer
219
  // we need to divide by 8 before sending to modeling function.
220
63.2k
  const int ref = xd->mi[0]->ref_frame[0];
221
222
63.2k
  int64_t rate_sum = 0;
223
63.2k
  int64_t dist_sum = 0;
224
63.2k
  int64_t total_sse = 0;
225
226
180k
  for (int plane = plane_from; plane <= plane_to; ++plane) {
227
117k
    if (plane && !xd->is_chroma_ref) break;
228
117k
    struct macroblockd_plane *const pd = &xd->plane[plane];
229
117k
    const BLOCK_SIZE plane_bsize =
230
117k
        get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
231
117k
    int64_t dist, sse;
232
117k
    int rate;
233
117k
    int bw, bh;
234
117k
    const struct macroblock_plane *const p = &x->plane[plane];
235
117k
    get_txb_dimensions(xd, plane, plane_bsize, 0, 0, plane_bsize, NULL, NULL,
236
117k
                       &bw, &bh);
237
238
117k
    sse = calculate_sse(xd, p, pd, bw, bh);
239
117k
    model_rd_with_curvfit(cpi, x, plane_bsize, plane, sse, bw * bh, &rate,
240
117k
                          &dist);
241
242
117k
    if (plane == 0) x->pred_sse[ref] = (unsigned int)AOMMIN(sse, UINT_MAX);
243
244
117k
    total_sse += sse;
245
117k
    rate_sum += rate;
246
117k
    dist_sum += dist;
247
248
117k
    if (plane_rate) plane_rate[plane] = rate;
249
117k
    if (plane_sse) plane_sse[plane] = sse;
250
117k
    if (plane_dist) plane_dist[plane] = dist;
251
117k
  }
252
253
63.2k
  if (skip_txfm_sb) *skip_txfm_sb = rate_sum == 0;
254
63.2k
  if (skip_sse_sb) *skip_sse_sb = total_sse << 4;
255
63.2k
  *out_rate_sum = (int)rate_sum;
256
63.2k
  *out_dist_sum = dist_sum;
257
63.2k
}
Unexecuted instantiation: nonrd_pickmode.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: superres_scale.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: svc_layercontext.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: temporal_filter.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: tx_search.c:model_rd_for_sb_with_curvfit
Unexecuted instantiation: intra_mode_search.c:model_rd_for_sb_with_curvfit
compound_type.c:model_rd_for_sb_with_curvfit
Line
Count
Source
216
261k
    int64_t *plane_sse, int64_t *plane_dist) {
217
  // Note our transform coeffs are 8 times an orthogonal transform.
218
  // Hence quantizer step is also 8 times. To get effective quantizer
219
  // we need to divide by 8 before sending to modeling function.
220
261k
  const int ref = xd->mi[0]->ref_frame[0];
221
222
261k
  int64_t rate_sum = 0;
223
261k
  int64_t dist_sum = 0;
224
261k
  int64_t total_sse = 0;
225
226
523k
  for (int plane = plane_from; plane <= plane_to; ++plane) {
227
261k
    if (plane && !xd->is_chroma_ref) break;
228
261k
    struct macroblockd_plane *const pd = &xd->plane[plane];
229
261k
    const BLOCK_SIZE plane_bsize =
230
261k
        get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
231
261k
    int64_t dist, sse;
232
261k
    int rate;
233
261k
    int bw, bh;
234
261k
    const struct macroblock_plane *const p = &x->plane[plane];
235
261k
    get_txb_dimensions(xd, plane, plane_bsize, 0, 0, plane_bsize, NULL, NULL,
236
261k
                       &bw, &bh);
237
238
261k
    sse = calculate_sse(xd, p, pd, bw, bh);
239
261k
    model_rd_with_curvfit(cpi, x, plane_bsize, plane, sse, bw * bh, &rate,
240
261k
                          &dist);
241
242
261k
    if (plane == 0) x->pred_sse[ref] = (unsigned int)AOMMIN(sse, UINT_MAX);
243
244
261k
    total_sse += sse;
245
261k
    rate_sum += rate;
246
261k
    dist_sum += dist;
247
248
261k
    if (plane_rate) plane_rate[plane] = rate;
249
261k
    if (plane_sse) plane_sse[plane] = sse;
250
261k
    if (plane_dist) plane_dist[plane] = dist;
251
261k
  }
252
253
261k
  if (skip_txfm_sb) *skip_txfm_sb = rate_sum == 0;
254
261k
  if (skip_sse_sb) *skip_sse_sb = total_sse << 4;
255
261k
  *out_rate_sum = (int)rate_sum;
256
261k
  *out_dist_sum = dist_sum;
257
261k
}
Unexecuted instantiation: encode_strategy.c:model_rd_for_sb_with_curvfit
interp_search.c:model_rd_for_sb_with_curvfit
Line
Count
Source
216
278k
    int64_t *plane_sse, int64_t *plane_dist) {
217
  // Note our transform coeffs are 8 times an orthogonal transform.
218
  // Hence quantizer step is also 8 times. To get effective quantizer
219
  // we need to divide by 8 before sending to modeling function.
220
278k
  const int ref = xd->mi[0]->ref_frame[0];
221
222
278k
  int64_t rate_sum = 0;
223
278k
  int64_t dist_sum = 0;
224
278k
  int64_t total_sse = 0;
225
226
557k
  for (int plane = plane_from; plane <= plane_to; ++plane) {
227
278k
    if (plane && !xd->is_chroma_ref) break;
228
278k
    struct macroblockd_plane *const pd = &xd->plane[plane];
229
278k
    const BLOCK_SIZE plane_bsize =
230
278k
        get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
231
278k
    int64_t dist, sse;
232
278k
    int rate;
233
278k
    int bw, bh;
234
278k
    const struct macroblock_plane *const p = &x->plane[plane];
235
278k
    get_txb_dimensions(xd, plane, plane_bsize, 0, 0, plane_bsize, NULL, NULL,
236
278k
                       &bw, &bh);
237
238
278k
    sse = calculate_sse(xd, p, pd, bw, bh);
239
278k
    model_rd_with_curvfit(cpi, x, plane_bsize, plane, sse, bw * bh, &rate,
240
278k
                          &dist);
241
242
278k
    if (plane == 0) x->pred_sse[ref] = (unsigned int)AOMMIN(sse, UINT_MAX);
243
244
278k
    total_sse += sse;
245
278k
    rate_sum += rate;
246
278k
    dist_sum += dist;
247
248
278k
    if (plane_rate) plane_rate[plane] = rate;
249
278k
    if (plane_sse) plane_sse[plane] = sse;
250
278k
    if (plane_dist) plane_dist[plane] = dist;
251
278k
  }
252
253
278k
  if (skip_txfm_sb) *skip_txfm_sb = rate_sum == 0;
254
278k
  if (skip_sse_sb) *skip_sse_sb = total_sse << 4;
255
278k
  *out_rate_sum = (int)rate_sum;
256
278k
  *out_dist_sum = dist_sum;
257
278k
}
258
259
enum { MODELRD_LEGACY, MODELRD_CURVFIT, MODELRD_TYPES } UENUM1BYTE(ModelRdType);
260
261
static const model_rd_for_sb_type model_rd_sb_fn[MODELRD_TYPES] = {
262
  model_rd_for_sb, model_rd_for_sb_with_curvfit
263
};
264
265
static const model_rd_from_sse_type model_rd_sse_fn[MODELRD_TYPES] = {
266
  model_rd_from_sse, model_rd_with_curvfit
267
};
268
269
#ifdef __cplusplus
270
}  // extern "C"
271
#endif
272
#endif  // AOM_AV1_ENCODER_MODEL_RD_H_