OSDN Git Service

i965_pciids: add kbl-y refresh PCI ID
[android-x86/hardware-intel-common-vaapi.git] / test / i965_avce_context_test.cpp
1 /*
2  * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 #include "i965_avce_test_common.h"
26 #include "i965_streamable.h"
27 #include "i965_test_fixture.h"
28
29 #include <map>
30 #include <tuple>
31 #include <vector>
32
33 namespace AVC {
34 namespace Encode {
35
36 class AVCEContextTest
37     : public I965TestFixture
38     , public ::testing::WithParamInterface<
39         std::tuple<VAProfile, VAEntrypoint> >
40 {
41 protected:
42     void SetUp()
43     {
44         I965TestFixture::SetUp();
45         std::tie(profile, entrypoint) = GetParam();
46     }
47
48     void TearDown()
49     {
50         if (context != VA_INVALID_ID)
51             destroyContext(context);
52         if (config != VA_INVALID_ID)
53             destroyConfig(config);
54         I965TestFixture::TearDown();
55     }
56
57     operator struct intel_encoder_context const *()
58     {
59         if (config == VA_INVALID_ID) return NULL;
60
61         struct i965_driver_data *i965(*this);
62         if (not i965) return NULL;
63
64         if (IS_GEN9(i965->intel.device_info)
65             ||IS_GEN10(i965->intel.device_info))
66             is_gen9 = true;
67
68         struct object_context const *obj_context = CONTEXT(context);
69         if (not obj_context) return NULL;
70
71         return reinterpret_cast<struct intel_encoder_context const *>(
72             obj_context->hw_context);
73     }
74
75     VAProfile       profile;
76     VAEntrypoint    entrypoint;
77     VAConfigID      config = VA_INVALID_ID;
78     VAContextID     context = VA_INVALID_ID;
79     bool            is_gen9 = false;
80     int             min_resolution_width_height = I965_MIN_CODEC_ENC_RESOLUTION_WIDTH_HEIGHT;
81 };
82
83 TEST_P(AVCEContextTest, RateControl)
84 {
85     if (not IsSupported(profile, entrypoint)) {
86         RecordProperty("skipped", true);
87         std::cout << "[  SKIPPED ] " << getFullTestName()
88             << " is unsupported on this hardware" << std::endl;
89         return;
90     }
91
92     static const std::vector<unsigned> rateControls = {
93         VA_RC_NONE, VA_RC_CBR, VA_RC_VBR, VA_RC_VCM, VA_RC_CQP,
94         VA_RC_VBR_CONSTRAINED, VA_RC_MB,
95     };
96
97     struct i965_driver_data *i965(*this);
98     ASSERT_PTR(i965);
99
100     const std::map<VAEntrypoint, unsigned> supportedBRC = {
101         {VAEntrypointEncSlice, i965->codec_info->h264_brc_mode},
102         {VAEntrypointEncSliceLP, i965->codec_info->lp_h264_brc_mode},
103         {VAEntrypointFEI, VA_RC_CQP},
104         {VAEntrypointStats, VA_ATTRIB_NOT_SUPPORTED},
105     };
106
107     for (auto rc : rateControls) {
108         ConfigAttribs attribs(1, {type:VAConfigAttribRateControl, value:rc});
109
110         const VAStatus expect =
111             (rc & supportedBRC.at(entrypoint)) ?
112             VA_STATUS_SUCCESS : VA_STATUS_ERROR_INVALID_VALUE;
113
114         config = createConfig(profile, entrypoint, attribs, expect);
115         if (expect != VA_STATUS_SUCCESS) continue;
116
117         context = createContext(
118             config,
119             min_resolution_width_height,
120             min_resolution_width_height);
121
122         if (HasFailure()) continue;
123
124         struct intel_encoder_context const *hw_context(*this);
125         EXPECT_PTR(hw_context);
126         if (HasFailure()) continue;
127
128         EXPECT_EQ(rc, hw_context->rate_control_mode);
129
130         destroyContext(context);
131         destroyConfig(config);
132         context = VA_INVALID_ID;
133         config = VA_INVALID_ID;
134     }
135 }
136
137 TEST_P(AVCEContextTest, Codec)
138 {
139     if (not IsSupported(profile, entrypoint)) {
140         RecordProperty("skipped", true);
141         std::cout << "[  SKIPPED ] " << getFullTestName()
142             << " is unsupported on this hardware" << std::endl;
143         return;
144     }
145
146     static const std::map<VAProfile, int> codecs = {
147         {VAProfileH264ConstrainedBaseline, CODEC_H264},
148         {VAProfileH264Main, CODEC_H264},
149         {VAProfileH264High, CODEC_H264},
150         {VAProfileH264MultiviewHigh, CODEC_H264_MVC},
151         {VAProfileH264StereoHigh, CODEC_H264_MVC},
152     };
153
154     ASSERT_NO_FAILURE(
155         config = createConfig(profile, entrypoint);
156         context = createContext(
157             config,
158             min_resolution_width_height,
159             min_resolution_width_height);
160     );
161
162     struct intel_encoder_context const *hw_context(*this);
163     ASSERT_PTR(hw_context);
164
165     EXPECT_EQ(codecs.at(profile), hw_context->codec);
166 }
167
168 TEST_P(AVCEContextTest, LowPowerMode)
169 {
170     if (not IsSupported(profile, entrypoint)) {
171         RecordProperty("skipped", true);
172         std::cout << "[  SKIPPED ] " << getFullTestName()
173             << " is unsupported on this hardware" << std::endl;
174         return;
175     }
176
177     ASSERT_NO_FAILURE(
178         config = createConfig(profile, entrypoint);
179         context = createContext(
180             config,
181             min_resolution_width_height,
182             min_resolution_width_height);
183     );
184
185     struct intel_encoder_context const *hw_context(*this);
186     ASSERT_PTR(hw_context);
187
188     EXPECT_EQ(
189         (entrypoint == VAEntrypointEncSliceLP ? 1u : 0u),
190         hw_context->low_power_mode
191     );
192 }
193
194 TEST_P(AVCEContextTest, ROINotSpecified)
195 {
196     if (not IsSupported(profile, entrypoint)) {
197         RecordProperty("skipped", true);
198         std::cout << "[  SKIPPED ] " << getFullTestName()
199             << " is unsupported on this hardware" << std::endl;
200         return;
201     }
202
203     // The lack of the VAConfigAttribEncROI config attribute
204     // will disable it.
205     ASSERT_NO_FAILURE(
206         config = createConfig(profile, entrypoint);
207         context = createContext(
208             config,
209             min_resolution_width_height,
210             min_resolution_width_height);
211     );
212
213     struct intel_encoder_context const *hw_context(*this);
214     ASSERT_PTR(hw_context);
215
216     EXPECT_EQ(0u, hw_context->context_roi);
217 }
218
219 TEST_P(AVCEContextTest, ROISpecified)
220 {
221     if (not IsSupported(profile, entrypoint)) {
222         RecordProperty("skipped", true);
223         std::cout << "[  SKIPPED ] " << getFullTestName()
224             << " is unsupported on this hardware" << std::endl;
225         return;
226     }
227
228     static const std::map<VAProfile, unsigned> roiSupport = {
229         {VAProfileH264ConstrainedBaseline, 1}, {VAProfileH264Main, 1},
230         {VAProfileH264High, 1}, {VAProfileH264MultiviewHigh, 0},
231         {VAProfileH264StereoHigh, 0},
232     };
233
234     // The presence of the VAConfigAttribEncROI config attribute
235     // will enable it for supported profile
236     ConfigAttribs attribs(1, {type:VAConfigAttribEncROI});
237     ASSERT_NO_FAILURE(
238         config = createConfig(profile, entrypoint, attribs);
239         context = createContext(
240             config,
241             min_resolution_width_height,
242             min_resolution_width_height);
243     );
244
245     struct intel_encoder_context const *hw_context(*this);
246     ASSERT_PTR(hw_context);
247
248     EXPECT_EQ(roiSupport.at(profile), hw_context->context_roi);
249 }
250
251 TEST_P(AVCEContextTest, QualityRange)
252 {
253     if (not IsSupported(profile, entrypoint)) {
254         RecordProperty("skipped", true);
255         std::cout << "[  SKIPPED ] " << getFullTestName()
256             << " is unsupported on this hardware" << std::endl;
257         return;
258     }
259
260     ASSERT_NO_FAILURE(
261         config = createConfig(profile, entrypoint);
262         context = createContext(
263             config,
264             min_resolution_width_height,
265             min_resolution_width_height);
266     );
267
268     struct intel_encoder_context const *hw_context(*this);
269     ASSERT_PTR(hw_context);
270
271     std::map<VAProfile, unsigned> qranges;
272     if(is_gen9) {
273         qranges = {
274             {VAProfileH264ConstrainedBaseline, entrypoint == VAEntrypointEncSliceLP
275                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE_AVC},
276             {VAProfileH264Main, entrypoint == VAEntrypointEncSliceLP
277                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE_AVC},
278             {VAProfileH264High, entrypoint == VAEntrypointEncSliceLP
279                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE_AVC},
280             {VAProfileH264MultiviewHigh, ENCODER_QUALITY_RANGE_AVC},
281             {VAProfileH264StereoHigh, ENCODER_QUALITY_RANGE_AVC},
282         };
283     }else {
284         qranges = {
285             {VAProfileH264ConstrainedBaseline, entrypoint == VAEntrypointEncSliceLP
286                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE},
287             {VAProfileH264Main, entrypoint == VAEntrypointEncSliceLP
288                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE},
289             {VAProfileH264High, entrypoint == VAEntrypointEncSliceLP
290                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE},
291             {VAProfileH264MultiviewHigh, 1u},
292             {VAProfileH264StereoHigh, 1u},
293         };
294     }
295
296     EXPECT_EQ(qranges.at(profile), hw_context->quality_range);
297 }
298
299 INSTANTIATE_TEST_CASE_P(
300     AVCEncode, AVCEContextTest, ::testing::Values(
301         std::make_tuple(VAProfileH264ConstrainedBaseline, VAEntrypointEncSlice),
302         std::make_tuple(VAProfileH264ConstrainedBaseline, VAEntrypointEncSliceLP),
303         std::make_tuple(VAProfileH264ConstrainedBaseline, VAEntrypointFEI),
304         std::make_tuple(VAProfileH264ConstrainedBaseline, VAEntrypointStats),
305         std::make_tuple(VAProfileH264Main, VAEntrypointEncSlice),
306         std::make_tuple(VAProfileH264Main, VAEntrypointEncSliceLP),
307         std::make_tuple(VAProfileH264Main, VAEntrypointFEI),
308         std::make_tuple(VAProfileH264Main, VAEntrypointStats),
309         std::make_tuple(VAProfileH264High, VAEntrypointEncSlice),
310         std::make_tuple(VAProfileH264High, VAEntrypointEncSliceLP),
311         std::make_tuple(VAProfileH264High, VAEntrypointFEI),
312         std::make_tuple(VAProfileH264High, VAEntrypointStats),
313         std::make_tuple(VAProfileH264MultiviewHigh, VAEntrypointEncSlice),
314         std::make_tuple(VAProfileH264StereoHigh, VAEntrypointEncSlice)
315     )
316 );
317
318 } // namespace Encode
319 } // namespace AVC