av1_convolve_optimz_test.cc 12.2 KB
Newer Older
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
 * 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.
10
11
12
13
 */

#include "third_party/googletest/src/include/gtest/gtest.h"

Yaowu Xu's avatar
Yaowu Xu committed
14
#include "./av1_rtcd.h"
15
16
17
18
19
20
21
22
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"

namespace {

using std::tr1::tuple;
23
using libaom_test::ACMRandom;
24

25
typedef void (*ConvInit)();
clang-format's avatar
clang-format committed
26
typedef void (*conv_filter_t)(const uint8_t *, int, uint8_t *, int, int, int,
27
28
                              const InterpFilterParams, const int, int,
                              ConvolveParams *);
Yaowu Xu's avatar
Yaowu Xu committed
29
#if CONFIG_AOM_HIGHBITDEPTH
clang-format's avatar
clang-format committed
30
31
32
typedef void (*hbd_conv_filter_t)(const uint16_t *, int, uint16_t *, int, int,
                                  int, const InterpFilterParams, const int, int,
                                  int, int);
33
34
#endif

35
// Test parameter list:
36
37
//  <convolve_horiz_func, convolve_vert_func,
//  <width, height>, filter_params, subpel_x_q4, avg>
38
typedef tuple<int, int> BlockDimension;
39
40
typedef tuple<ConvInit, conv_filter_t, conv_filter_t, BlockDimension,
              InterpFilter, int, int>
clang-format's avatar
clang-format committed
41
    ConvParams;
Yaowu Xu's avatar
Yaowu Xu committed
42
#if CONFIG_AOM_HIGHBITDEPTH
43
44
45
46
// Test parameter list:
//  <convolve_horiz_func, convolve_vert_func,
//  <width, height>, filter_params, subpel_x_q4, avg, bit_dpeth>
typedef tuple<hbd_conv_filter_t, hbd_conv_filter_t, BlockDimension,
clang-format's avatar
clang-format committed
47
48
              InterpFilter, int, int, int>
    HbdConvParams;
49
#endif
50
51
52
53
54
55
56
57
58
59
60
61

// Note:
//  src_ and src_ref_ have special boundary requirement
//  dst_ and dst_ref_ don't
const size_t maxWidth = 256;
const size_t maxHeight = 256;
const size_t maxBlockSize = maxWidth * maxHeight;
const int horizOffset = 32;
const int vertiOffset = 32;
const int stride = 128;
const int x_step_q4 = 16;

Yaowu Xu's avatar
Yaowu Xu committed
62
class AV1ConvolveOptimzTest : public ::testing::TestWithParam<ConvParams> {
63
 public:
Yaowu Xu's avatar
Yaowu Xu committed
64
  virtual ~AV1ConvolveOptimzTest() {}
65
  virtual void SetUp() {
66
67
68
69
70
    ConvInit conv_init = GET_PARAM(0);
    conv_init();
    conv_horiz_ = GET_PARAM(1);
    conv_vert_ = GET_PARAM(2);
    BlockDimension block = GET_PARAM(3);
71
72
    width_ = std::tr1::get<0>(block);
    height_ = std::tr1::get<1>(block);
73
74
    filter_ = GET_PARAM(4);
    subpel_ = GET_PARAM(5);
75
    int ref = GET_PARAM(6);
76
77
    const int plane = 0;
    conv_params_ = get_conv_params(ref, plane);
78
79
80
81
82
83
84
85
86
87
88
89

    alloc_ = new uint8_t[maxBlockSize * 4];
    src_ = alloc_ + (vertiOffset * maxWidth);
    src_ += horizOffset;
    src_ref_ = src_ + maxBlockSize;

    dst_ = alloc_ + 2 * maxBlockSize;
    dst_ref_ = alloc_ + 3 * maxBlockSize;
  }

  virtual void TearDown() {
    delete[] alloc_;
90
    libaom_test::ClearSystemState();
91
92
93
94
  }

 protected:
  void RunHorizFilterBitExactCheck();
95
  void RunVertFilterBitExactCheck();
96
97

 private:
98
  void PrepFilterBuffer();
99
  void DiffFilterBuffer();
100
101
  conv_filter_t conv_horiz_;
  conv_filter_t conv_vert_;
102
103
104
105
106
107
108
109
110
  uint8_t *alloc_;
  uint8_t *src_;
  uint8_t *dst_;
  uint8_t *src_ref_;
  uint8_t *dst_ref_;
  int width_;
  int height_;
  int filter_;
  int subpel_;
111
  ConvolveParams conv_params_;
112
113
};

114
void AV1ConvolveOptimzTest::PrepFilterBuffer() {
115
116
117
  int r, c;
  ACMRandom rnd(ACMRandom::DeterministicSeed());

118
  memset(alloc_, 0, 4 * maxBlockSize * sizeof(alloc_[0]));
119

120
121
122
123
  uint8_t *src_ptr = src_;
  uint8_t *dst_ptr = dst_;
  uint8_t *src_ref_ptr = src_ref_;
  uint8_t *dst_ref_ptr = dst_ref_;
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

  for (r = 0; r < height_; ++r) {
    for (c = 0; c < width_; ++c) {
      src_ptr[c] = rnd.Rand8();
      src_ref_ptr[c] = src_ptr[c];
      dst_ptr[c] = rnd.Rand8();
      dst_ref_ptr[c] = dst_ptr[c];
    }
    src_ptr += stride;
    src_ref_ptr += stride;
    dst_ptr += stride;
    dst_ref_ptr += stride;
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
139
void AV1ConvolveOptimzTest::DiffFilterBuffer() {
140
  int r, c;
141
142
143
144
  const uint8_t *dst_ptr = dst_;
  const uint8_t *dst_ref_ptr = dst_ref_;
  for (r = 0; r < height_; ++r) {
    for (c = 0; c < width_; ++c) {
145
      EXPECT_EQ((uint8_t)dst_ref_ptr[c], (uint8_t)dst_ptr[c])
clang-format's avatar
clang-format committed
146
147
148
149
150
          << "Error at row: " << r << " col: " << c << " "
          << "w = " << width_ << " "
          << "h = " << height_ << " "
          << "filter group index = " << filter_ << " "
          << "filter index = " << subpel_;
151
152
153
154
155
156
    }
    dst_ptr += stride;
    dst_ref_ptr += stride;
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
157
void AV1ConvolveOptimzTest::RunHorizFilterBitExactCheck() {
158
  PrepFilterBuffer();
159

Yaowu Xu's avatar
Yaowu Xu committed
160
  InterpFilterParams filter_params = av1_get_interp_filter_params(filter_);
161

Yaowu Xu's avatar
Yaowu Xu committed
162
  av1_convolve_horiz_c(src_ref_, stride, dst_ref_, stride, width_, height_,
163
                       filter_params, subpel_, x_step_q4, &conv_params_);
164

clang-format's avatar
clang-format committed
165
  conv_horiz_(src_, stride, dst_, stride, width_, height_, filter_params,
166
              subpel_, x_step_q4, &conv_params_);
167

168
  DiffFilterBuffer();
169
170
171
172
173
174

  // Note:
  // Here we need calculate a height which is different from the specified one
  // and test again.
  int intermediate_height =
      (((height_ - 1) * 16 + subpel_) >> SUBPEL_BITS) + filter_params.taps;
175
  PrepFilterBuffer();
176

Yaowu Xu's avatar
Yaowu Xu committed
177
178
  av1_convolve_horiz_c(src_ref_, stride, dst_ref_, stride, width_,
                       intermediate_height, filter_params, subpel_, x_step_q4,
179
                       &conv_params_);
180

clang-format's avatar
clang-format committed
181
  conv_horiz_(src_, stride, dst_, stride, width_, intermediate_height,
182
              filter_params, subpel_, x_step_q4, &conv_params_);
183

184
  DiffFilterBuffer();
185
186
}

Yaowu Xu's avatar
Yaowu Xu committed
187
void AV1ConvolveOptimzTest::RunVertFilterBitExactCheck() {
188
  PrepFilterBuffer();
189

Yaowu Xu's avatar
Yaowu Xu committed
190
  InterpFilterParams filter_params = av1_get_interp_filter_params(filter_);
191

Yaowu Xu's avatar
Yaowu Xu committed
192
  av1_convolve_vert_c(src_ref_, stride, dst_ref_, stride, width_, height_,
193
                      filter_params, subpel_, x_step_q4, &conv_params_);
194

clang-format's avatar
clang-format committed
195
  conv_vert_(src_, stride, dst_, stride, width_, height_, filter_params,
196
             subpel_, x_step_q4, &conv_params_);
197

198
  DiffFilterBuffer();
199
200
}

Yaowu Xu's avatar
Yaowu Xu committed
201
TEST_P(AV1ConvolveOptimzTest, HorizBitExactCheck) {
202
203
  RunHorizFilterBitExactCheck();
}
Yaowu Xu's avatar
Yaowu Xu committed
204
TEST_P(AV1ConvolveOptimzTest, VerticalBitExactCheck) {
205
206
  RunVertFilterBitExactCheck();
}
207
208
209

using std::tr1::make_tuple;

210
#if (HAVE_SSSE3 || HAVE_SSE4_1) && CONFIG_DUAL_FILTER
211
const BlockDimension kBlockDim[] = {
clang-format's avatar
clang-format committed
212
213
214
215
216
217
  make_tuple(2, 2),    make_tuple(2, 4),    make_tuple(4, 4),
  make_tuple(4, 8),    make_tuple(8, 4),    make_tuple(8, 8),
  make_tuple(8, 16),   make_tuple(16, 8),   make_tuple(16, 16),
  make_tuple(16, 32),  make_tuple(32, 16),  make_tuple(32, 32),
  make_tuple(32, 64),  make_tuple(64, 32),  make_tuple(64, 64),
  make_tuple(64, 128), make_tuple(128, 64), make_tuple(128, 128),
218
};
219

220
// 10/12-tap filters
James Zern's avatar
James Zern committed
221
const InterpFilter kFilter[] = { 6, 4, 2 };
222

clang-format's avatar
clang-format committed
223
const int kSubpelQ4[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
224

clang-format's avatar
clang-format committed
225
const int kAvg[] = { 0, 1 };
226
#endif
227

228
#if HAVE_SSSE3 && CONFIG_DUAL_FILTER
229
INSTANTIATE_TEST_CASE_P(
Yaowu Xu's avatar
Yaowu Xu committed
230
    SSSE3, AV1ConvolveOptimzTest,
231
232
    ::testing::Combine(::testing::Values(av1_convolve_init_ssse3),
                       ::testing::Values(av1_convolve_horiz_ssse3),
Yaowu Xu's avatar
Yaowu Xu committed
233
                       ::testing::Values(av1_convolve_vert_ssse3),
clang-format's avatar
clang-format committed
234
235
236
237
                       ::testing::ValuesIn(kBlockDim),
                       ::testing::ValuesIn(kFilter),
                       ::testing::ValuesIn(kSubpelQ4),
                       ::testing::ValuesIn(kAvg)));
238
#endif  // HAVE_SSSE3 && CONFIG_DUAL_FILTER
239

Yaowu Xu's avatar
Yaowu Xu committed
240
#if CONFIG_AOM_HIGHBITDEPTH
241
typedef ::testing::TestWithParam<HbdConvParams> TestWithHbdConvParams;
Yaowu Xu's avatar
Yaowu Xu committed
242
class AV1HbdConvolveOptimzTest : public TestWithHbdConvParams {
243
 public:
Yaowu Xu's avatar
Yaowu Xu committed
244
  virtual ~AV1HbdConvolveOptimzTest() {}
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
  virtual void SetUp() {
    conv_horiz_ = GET_PARAM(0);
    conv_vert_ = GET_PARAM(1);
    BlockDimension block = GET_PARAM(2);
    width_ = std::tr1::get<0>(block);
    height_ = std::tr1::get<1>(block);
    filter_ = GET_PARAM(3);
    subpel_ = GET_PARAM(4);
    avg_ = GET_PARAM(5);
    bit_depth_ = GET_PARAM(6);

    alloc_ = new uint16_t[maxBlockSize * 4];
    src_ = alloc_ + (vertiOffset * maxWidth);
    src_ += horizOffset;
    src_ref_ = src_ + maxBlockSize;

    dst_ = alloc_ + 2 * maxBlockSize;
    dst_ref_ = alloc_ + 3 * maxBlockSize;
  }

  virtual void TearDown() {
    delete[] alloc_;
267
    libaom_test::ClearSystemState();
268
269
270
271
272
273
274
  }

 protected:
  void RunHorizFilterBitExactCheck();
  void RunVertFilterBitExactCheck();

 private:
275
  void PrepFilterBuffer();
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
  void DiffFilterBuffer();
  hbd_conv_filter_t conv_horiz_;
  hbd_conv_filter_t conv_vert_;
  uint16_t *alloc_;
  uint16_t *src_;
  uint16_t *dst_;
  uint16_t *src_ref_;
  uint16_t *dst_ref_;
  int width_;
  int height_;
  int filter_;
  int subpel_;
  int avg_;
  int bit_depth_;
};

292
void AV1HbdConvolveOptimzTest::PrepFilterBuffer() {
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
  int r, c;
  ACMRandom rnd(ACMRandom::DeterministicSeed());

  memset(alloc_, 0, 4 * maxBlockSize * sizeof(alloc_[0]));

  uint16_t *src_ptr = src_;
  uint16_t *dst_ptr = dst_;
  uint16_t *dst_ref_ptr = dst_ref_;
  uint16_t hbd_mask = (1 << bit_depth_) - 1;

  for (r = 0; r < height_; ++r) {
    for (c = 0; c < width_; ++c) {
      src_ptr[c] = rnd.Rand16() & hbd_mask;
      dst_ptr[c] = rnd.Rand16() & hbd_mask;
      dst_ref_ptr[c] = dst_ptr[c];
    }
    src_ptr += stride;
    dst_ptr += stride;
    dst_ref_ptr += stride;
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
315
void AV1HbdConvolveOptimzTest::DiffFilterBuffer() {
316
317
318
319
320
321
  int r, c;
  const uint16_t *dst_ptr = dst_;
  const uint16_t *dst_ref_ptr = dst_ref_;
  for (r = 0; r < height_; ++r) {
    for (c = 0; c < width_; ++c) {
      EXPECT_EQ((uint16_t)dst_ref_ptr[c], (uint16_t)dst_ptr[c])
clang-format's avatar
clang-format committed
322
323
324
325
326
327
          << "Error at row: " << r << " col: " << c << " "
          << "w = " << width_ << " "
          << "h = " << height_ << " "
          << "filter group index = " << filter_ << " "
          << "filter index = " << subpel_ << " "
          << "bit depth = " << bit_depth_;
328
329
330
331
332
333
    }
    dst_ptr += stride;
    dst_ref_ptr += stride;
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
334
void AV1HbdConvolveOptimzTest::RunHorizFilterBitExactCheck() {
335
  PrepFilterBuffer();
336

Yaowu Xu's avatar
Yaowu Xu committed
337
  InterpFilterParams filter_params = av1_get_interp_filter_params(filter_);
338

Yaowu Xu's avatar
Yaowu Xu committed
339
340
341
  av1_highbd_convolve_horiz_c(src_, stride, dst_ref_, stride, width_, height_,
                              filter_params, subpel_, x_step_q4, avg_,
                              bit_depth_);
342

clang-format's avatar
clang-format committed
343
344
  conv_horiz_(src_, stride, dst_, stride, width_, height_, filter_params,
              subpel_, x_step_q4, avg_, bit_depth_);
345
346
347
348
349
350
351
352

  DiffFilterBuffer();

  // Note:
  // Here we need calculate a height which is different from the specified one
  // and test again.
  int intermediate_height =
      (((height_ - 1) * 16 + subpel_) >> SUBPEL_BITS) + filter_params.taps;
353
  PrepFilterBuffer();
354

Yaowu Xu's avatar
Yaowu Xu committed
355
356
357
  av1_highbd_convolve_horiz_c(src_, stride, dst_ref_, stride, width_,
                              intermediate_height, filter_params, subpel_,
                              x_step_q4, avg_, bit_depth_);
358
359
360
361
362
363
364

  conv_horiz_(src_, stride, dst_, stride, width_, intermediate_height,
              filter_params, subpel_, x_step_q4, avg_, bit_depth_);

  DiffFilterBuffer();
}

Yaowu Xu's avatar
Yaowu Xu committed
365
void AV1HbdConvolveOptimzTest::RunVertFilterBitExactCheck() {
366
  PrepFilterBuffer();
367

Yaowu Xu's avatar
Yaowu Xu committed
368
  InterpFilterParams filter_params = av1_get_interp_filter_params(filter_);
369

Yaowu Xu's avatar
Yaowu Xu committed
370
371
372
  av1_highbd_convolve_vert_c(src_, stride, dst_ref_, stride, width_, height_,
                             filter_params, subpel_, x_step_q4, avg_,
                             bit_depth_);
373

clang-format's avatar
clang-format committed
374
375
  conv_vert_(src_, stride, dst_, stride, width_, height_, filter_params,
             subpel_, x_step_q4, avg_, bit_depth_);
376
377
378
379

  DiffFilterBuffer();
}

Yaowu Xu's avatar
Yaowu Xu committed
380
TEST_P(AV1HbdConvolveOptimzTest, HorizBitExactCheck) {
381
382
  RunHorizFilterBitExactCheck();
}
Yaowu Xu's avatar
Yaowu Xu committed
383
TEST_P(AV1HbdConvolveOptimzTest, VertBitExactCheck) {
384
385
386
  RunVertFilterBitExactCheck();
}

387
#if HAVE_SSE4_1 && CONFIG_DUAL_FILTER
388

clang-format's avatar
clang-format committed
389
const int kBitdepth[] = { 10, 12 };
390
391

INSTANTIATE_TEST_CASE_P(
Yaowu Xu's avatar
Yaowu Xu committed
392
393
394
    SSE4_1, AV1HbdConvolveOptimzTest,
    ::testing::Combine(::testing::Values(av1_highbd_convolve_horiz_sse4_1),
                       ::testing::Values(av1_highbd_convolve_vert_sse4_1),
clang-format's avatar
clang-format committed
395
396
397
398
399
                       ::testing::ValuesIn(kBlockDim),
                       ::testing::ValuesIn(kFilter),
                       ::testing::ValuesIn(kSubpelQ4),
                       ::testing::ValuesIn(kAvg),
                       ::testing::ValuesIn(kBitdepth)));
400
#endif  // HAVE_SSE4_1 && CONFIG_DUAL_FILTER
Yaowu Xu's avatar
Yaowu Xu committed
401
#endif  // CONFIG_AOM_HIGHBITDEPTH
402
}  // namespace