Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The WebM project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <string.h> |
| 12 | |
| 13 | #include "third_party/googletest/src/include/gtest/gtest.h" |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 14 | |
| 15 | #include "./vpx_config.h" |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 16 | #include "test/acm_random.h" |
| 17 | #include "test/clear_system_state.h" |
| 18 | #include "test/register_state_check.h" |
| 19 | #include "test/util.h" |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 20 | #include "vp8/common/blockd.h" |
| 21 | #include "vp8/common/onyx.h" |
| 22 | #include "vp8/encoder/block.h" |
| 23 | #include "vp8/encoder/onyx_int.h" |
| 24 | #include "vp8/encoder/quantize.h" |
| 25 | #include "vpx/vpx_integer.h" |
| 26 | #include "vpx_mem/vpx_mem.h" |
| 27 | |
| 28 | namespace { |
Yaowu Xu | 0818a7c | 2016-08-11 09:39:47 -0700 | [diff] [blame^] | 29 | #if !CONFIG_AOM_QM |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 30 | |
| 31 | const int kNumBlocks = 25; |
| 32 | const int kNumBlockEntries = 16; |
| 33 | |
| 34 | typedef void (*VP8Quantize)(BLOCK *b, BLOCKD *d); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 35 | |
| 36 | typedef std::tr1::tuple<VP8Quantize, VP8Quantize> VP8QuantizeParam; |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 37 | |
| 38 | using libvpx_test::ACMRandom; |
| 39 | using std::tr1::make_tuple; |
| 40 | |
| 41 | // Create and populate a VP8_COMP instance which has a complete set of |
| 42 | // quantization inputs as well as a second MACROBLOCKD for output. |
| 43 | class QuantizeTestBase { |
| 44 | public: |
| 45 | virtual ~QuantizeTestBase() { |
| 46 | vp8_remove_compressor(&vp8_comp_); |
| 47 | vp8_comp_ = NULL; |
| 48 | vpx_free(macroblockd_dst_); |
| 49 | macroblockd_dst_ = NULL; |
| 50 | libvpx_test::ClearSystemState(); |
| 51 | } |
| 52 | |
| 53 | protected: |
| 54 | void SetupCompressor() { |
| 55 | rnd_.Reset(ACMRandom::DeterministicSeed()); |
| 56 | |
| 57 | // The full configuration is necessary to generate the quantization tables. |
Johann | ee30dd0 | 2014-11-25 12:06:56 -0800 | [diff] [blame] | 58 | VP8_CONFIG vp8_config; |
James Zern | f58011a | 2015-04-23 20:47:40 -0700 | [diff] [blame] | 59 | memset(&vp8_config, 0, sizeof(vp8_config)); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 60 | |
Johann | ee30dd0 | 2014-11-25 12:06:56 -0800 | [diff] [blame] | 61 | vp8_comp_ = vp8_create_compressor(&vp8_config); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 62 | |
| 63 | // Set the tables based on a quantizer of 0. |
| 64 | vp8_set_quantizer(vp8_comp_, 0); |
| 65 | |
| 66 | // Set up all the block/blockd pointers for the mb in vp8_comp_. |
| 67 | vp8cx_frame_init_quantizer(vp8_comp_); |
| 68 | |
| 69 | // Copy macroblockd from the reference to get pre-set-up dequant values. |
Johann | dae280d | 2014-11-04 10:32:51 -0800 | [diff] [blame] | 70 | macroblockd_dst_ = reinterpret_cast<MACROBLOCKD *>( |
| 71 | vpx_memalign(32, sizeof(*macroblockd_dst_))); |
James Zern | f274c21 | 2015-04-23 20:42:19 -0700 | [diff] [blame] | 72 | memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_)); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 73 | // Fix block pointers - currently they point to the blocks in the reference |
| 74 | // structure. |
| 75 | vp8_setup_block_dptrs(macroblockd_dst_); |
| 76 | } |
| 77 | |
| 78 | void UpdateQuantizer(int q) { |
| 79 | vp8_set_quantizer(vp8_comp_, q); |
| 80 | |
James Zern | f274c21 | 2015-04-23 20:42:19 -0700 | [diff] [blame] | 81 | memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_)); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 82 | vp8_setup_block_dptrs(macroblockd_dst_); |
| 83 | } |
| 84 | |
| 85 | void FillCoeffConstant(int16_t c) { |
| 86 | for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) { |
| 87 | vp8_comp_->mb.coeff[i] = c; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | void FillCoeffRandom() { |
| 92 | for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) { |
| 93 | vp8_comp_->mb.coeff[i] = rnd_.Rand8(); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void CheckOutput() { |
| 98 | EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.qcoeff, macroblockd_dst_->qcoeff, |
| 99 | sizeof(*macroblockd_dst_->qcoeff) * kNumBlocks * |
| 100 | kNumBlockEntries)) |
| 101 | << "qcoeff mismatch"; |
| 102 | EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.dqcoeff, macroblockd_dst_->dqcoeff, |
| 103 | sizeof(*macroblockd_dst_->dqcoeff) * kNumBlocks * |
| 104 | kNumBlockEntries)) |
| 105 | << "dqcoeff mismatch"; |
| 106 | EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.eobs, macroblockd_dst_->eobs, |
| 107 | sizeof(*macroblockd_dst_->eobs) * kNumBlocks)) |
| 108 | << "eobs mismatch"; |
| 109 | } |
| 110 | |
| 111 | VP8_COMP *vp8_comp_; |
| 112 | MACROBLOCKD *macroblockd_dst_; |
| 113 | |
| 114 | private: |
| 115 | ACMRandom rnd_; |
| 116 | }; |
| 117 | |
| 118 | class QuantizeTest : public QuantizeTestBase, |
| 119 | public ::testing::TestWithParam<VP8QuantizeParam> { |
| 120 | protected: |
| 121 | virtual void SetUp() { |
| 122 | SetupCompressor(); |
| 123 | asm_quant_ = GET_PARAM(0); |
| 124 | c_quant_ = GET_PARAM(1); |
| 125 | } |
| 126 | |
| 127 | void RunComparison() { |
| 128 | for (int i = 0; i < kNumBlocks; ++i) { |
| 129 | ASM_REGISTER_STATE_CHECK( |
| 130 | c_quant_(&vp8_comp_->mb.block[i], &vp8_comp_->mb.e_mbd.block[i])); |
| 131 | ASM_REGISTER_STATE_CHECK( |
| 132 | asm_quant_(&vp8_comp_->mb.block[i], ¯oblockd_dst_->block[i])); |
| 133 | } |
| 134 | |
| 135 | CheckOutput(); |
| 136 | } |
| 137 | |
| 138 | private: |
| 139 | VP8Quantize asm_quant_; |
| 140 | VP8Quantize c_quant_; |
| 141 | }; |
| 142 | |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 143 | TEST_P(QuantizeTest, TestZeroInput) { |
| 144 | FillCoeffConstant(0); |
| 145 | RunComparison(); |
| 146 | } |
| 147 | |
Johann | 08ad7e4 | 2014-11-20 13:24:55 -0800 | [diff] [blame] | 148 | TEST_P(QuantizeTest, TestLargeNegativeInput) { |
| 149 | FillCoeffConstant(0); |
| 150 | // Generate a qcoeff which contains 512/-512 (0x0100/0xFE00) to catch issues |
| 151 | // like BUG=883 where the constant being compared was incorrectly initialized. |
| 152 | vp8_comp_->mb.coeff[0] = -8191; |
| 153 | RunComparison(); |
| 154 | } |
| 155 | |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 156 | TEST_P(QuantizeTest, TestRandomInput) { |
| 157 | FillCoeffRandom(); |
| 158 | RunComparison(); |
| 159 | } |
| 160 | |
| 161 | TEST_P(QuantizeTest, TestMultipleQ) { |
| 162 | for (int q = 0; q < QINDEX_RANGE; ++q) { |
| 163 | UpdateQuantizer(q); |
| 164 | FillCoeffRandom(); |
| 165 | RunComparison(); |
| 166 | } |
| 167 | } |
| 168 | |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 169 | #if HAVE_SSE2 |
| 170 | INSTANTIATE_TEST_CASE_P( |
| 171 | SSE2, QuantizeTest, |
| 172 | ::testing::Values( |
Johann | 9c6ce43 | 2014-11-04 08:20:25 -0800 | [diff] [blame] | 173 | make_tuple(&vp8_fast_quantize_b_sse2, &vp8_fast_quantize_b_c), |
| 174 | make_tuple(&vp8_regular_quantize_b_sse2, &vp8_regular_quantize_b_c))); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 175 | #endif // HAVE_SSE2 |
| 176 | |
| 177 | #if HAVE_SSSE3 |
| 178 | INSTANTIATE_TEST_CASE_P(SSSE3, QuantizeTest, |
Johann | 9c6ce43 | 2014-11-04 08:20:25 -0800 | [diff] [blame] | 179 | ::testing::Values(make_tuple(&vp8_fast_quantize_b_ssse3, |
| 180 | &vp8_fast_quantize_b_c))); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 181 | #endif // HAVE_SSSE3 |
| 182 | |
| 183 | #if HAVE_SSE4_1 |
Johann | 9c6ce43 | 2014-11-04 08:20:25 -0800 | [diff] [blame] | 184 | INSTANTIATE_TEST_CASE_P( |
| 185 | SSE4_1, QuantizeTest, |
| 186 | ::testing::Values(make_tuple(&vp8_regular_quantize_b_sse4_1, |
| 187 | &vp8_regular_quantize_b_c))); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 188 | #endif // HAVE_SSE4_1 |
| 189 | |
Johann | d1b64de | 2014-11-05 10:58:26 -0800 | [diff] [blame] | 190 | #if HAVE_NEON |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 191 | INSTANTIATE_TEST_CASE_P(NEON, QuantizeTest, |
Johann | 9c6ce43 | 2014-11-04 08:20:25 -0800 | [diff] [blame] | 192 | ::testing::Values(make_tuple(&vp8_fast_quantize_b_neon, |
| 193 | &vp8_fast_quantize_b_c))); |
Johann | d1b64de | 2014-11-05 10:58:26 -0800 | [diff] [blame] | 194 | #endif // HAVE_NEON |
Parag Salasakar | 56aa0da | 2015-07-30 10:56:40 +0530 | [diff] [blame] | 195 | |
| 196 | #if HAVE_MSA |
| 197 | INSTANTIATE_TEST_CASE_P( |
| 198 | MSA, QuantizeTest, |
| 199 | ::testing::Values( |
| 200 | make_tuple(&vp8_fast_quantize_b_msa, &vp8_fast_quantize_b_c), |
| 201 | make_tuple(&vp8_regular_quantize_b_msa, &vp8_regular_quantize_b_c))); |
| 202 | #endif // HAVE_MSA |
Yaowu Xu | 0818a7c | 2016-08-11 09:39:47 -0700 | [diff] [blame^] | 203 | #endif // CONFIG_AOM_QM |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 204 | } // namespace |