blob: 8d5cb59f42d0f39bb7d40ccad17dcd9f7dceb4db [file] [log] [blame]
[email protected]1a6ad5f2012-01-25 04:29:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]129f019e2013-05-28 23:38:025#include "gpu/config/gpu_test_config.h"
[email protected]1a6ad5f2012-01-25 04:29:586
avif15d60a2015-12-21 17:06:337#include <stddef.h>
8#include <stdint.h>
9
[email protected]1a6ad5f2012-01-25 04:29:5810#include "base/logging.h"
11#include "base/sys_info.h"
[email protected]d7b5cc72013-05-23 20:05:0012#include "gpu/config/gpu_info.h"
13#include "gpu/config/gpu_info_collector.h"
[email protected]129f019e2013-05-28 23:38:0214#include "gpu/config/gpu_test_expectations_parser.h"
15
thakis114a1ef2016-04-26 16:02:5916#if defined(OS_WIN)
[email protected]3b886f42014-01-10 03:50:0517#include "base/win/windows_version.h"
[email protected]f5b7f6e2013-12-10 13:57:3218#endif
19
[email protected]129f019e2013-05-28 23:38:0220namespace gpu {
[email protected]1a6ad5f2012-01-25 04:29:5821
22namespace {
23
24GPUTestConfig::OS GetCurrentOS() {
25#if defined(OS_CHROMEOS)
26 return GPUTestConfig::kOsChromeOS;
27#elif defined(OS_LINUX) || defined(OS_OPENBSD)
28 return GPUTestConfig::kOsLinux;
29#elif defined(OS_WIN)
avif15d60a2015-12-21 17:06:3330 int32_t major_version = 0;
31 int32_t minor_version = 0;
32 int32_t bugfix_version = 0;
[email protected]1a6ad5f2012-01-25 04:29:5833 base::SysInfo::OperatingSystemVersionNumbers(
34 &major_version, &minor_version, &bugfix_version);
35 if (major_version == 5)
36 return GPUTestConfig::kOsWinXP;
37 if (major_version == 6 && minor_version == 0)
38 return GPUTestConfig::kOsWinVista;
39 if (major_version == 6 && minor_version == 1)
40 return GPUTestConfig::kOsWin7;
[email protected]4e503202014-05-23 11:08:5341 if (major_version == 6 && (minor_version == 2 || minor_version == 3))
[email protected]c9fc22f2012-11-16 23:39:5642 return GPUTestConfig::kOsWin8;
wfh0355eead2015-07-22 04:15:0043 if (major_version == 10)
44 return GPUTestConfig::kOsWin10;
[email protected]1a6ad5f2012-01-25 04:29:5845#elif defined(OS_MACOSX)
avif15d60a2015-12-21 17:06:3346 int32_t major_version = 0;
47 int32_t minor_version = 0;
48 int32_t bugfix_version = 0;
[email protected]1a6ad5f2012-01-25 04:29:5849 base::SysInfo::OperatingSystemVersionNumbers(
50 &major_version, &minor_version, &bugfix_version);
51 if (major_version == 10) {
52 switch (minor_version) {
53 case 5:
54 return GPUTestConfig::kOsMacLeopard;
55 case 6:
56 return GPUTestConfig::kOsMacSnowLeopard;
57 case 7:
58 return GPUTestConfig::kOsMacLion;
[email protected]c9fc22f2012-11-16 23:39:5659 case 8:
60 return GPUTestConfig::kOsMacMountainLion;
[email protected]710089b92014-02-04 01:16:0961 case 9:
62 return GPUTestConfig::kOsMacMavericks;
iceman3197ce82015-04-15 11:02:3263 case 10:
64 return GPUTestConfig::kOsMacYosemite;
bajones019b3c802015-11-18 19:36:5865 case 11:
66 return GPUTestConfig::kOsMacElCapitan;
erikchenaf3ffdd22016-07-21 22:34:5667 case 12:
68 return GPUTestConfig::kOsMacSierra;
[email protected]1a6ad5f2012-01-25 04:29:5869 }
70 }
[email protected]67d96b62012-07-24 03:38:2571#elif defined(OS_ANDROID)
72 return GPUTestConfig::kOsAndroid;
[email protected]1a6ad5f2012-01-25 04:29:5873#endif
74 return GPUTestConfig::kOsUnknown;
75}
76
77} // namespace anonymous
78
79GPUTestConfig::GPUTestConfig()
[email protected]b4ede6602013-05-15 16:46:5580 : validate_gpu_info_(true),
81 os_(kOsUnknown),
[email protected]1a6ad5f2012-01-25 04:29:5882 gpu_device_id_(0),
jmadill073a3232015-07-22 21:10:5283 build_type_(kBuildTypeUnknown),
84 api_(kAPIUnknown) {}
[email protected]1a6ad5f2012-01-25 04:29:5885
vmpstr3b7b8b22016-03-01 23:00:2086GPUTestConfig::GPUTestConfig(const GPUTestConfig& other) = default;
87
[email protected]1a6ad5f2012-01-25 04:29:5888GPUTestConfig::~GPUTestConfig() {
89}
90
avif15d60a2015-12-21 17:06:3391void GPUTestConfig::set_os(int32_t os) {
[email protected]67d96b62012-07-24 03:38:2592 DCHECK_EQ(0, os & ~(kOsAndroid | kOsWin | kOsMac | kOsLinux | kOsChromeOS));
[email protected]1a6ad5f2012-01-25 04:29:5893 os_ = os;
94}
95
avif15d60a2015-12-21 17:06:3396void GPUTestConfig::AddGPUVendor(uint32_t gpu_vendor) {
[email protected]1a6ad5f2012-01-25 04:29:5897 DCHECK_NE(0u, gpu_vendor);
98 for (size_t i = 0; i < gpu_vendor_.size(); ++i)
99 DCHECK_NE(gpu_vendor_[i], gpu_vendor);
100 gpu_vendor_.push_back(gpu_vendor);
101}
102
avif15d60a2015-12-21 17:06:33103void GPUTestConfig::set_gpu_device_id(uint32_t id) {
[email protected]1a6ad5f2012-01-25 04:29:58104 gpu_device_id_ = id;
105}
106
avif15d60a2015-12-21 17:06:33107void GPUTestConfig::set_build_type(int32_t build_type) {
[email protected]1a6ad5f2012-01-25 04:29:58108 DCHECK_EQ(0, build_type & ~(kBuildTypeRelease | kBuildTypeDebug));
109 build_type_ = build_type;
110}
111
avif15d60a2015-12-21 17:06:33112void GPUTestConfig::set_api(int32_t api) {
jmadill073a3232015-07-22 21:10:52113 DCHECK_EQ(0, api & ~(kAPID3D9 | kAPID3D11 | kAPIGLDesktop | kAPIGLES));
114 api_ = api;
115}
116
[email protected]1a6ad5f2012-01-25 04:29:58117bool GPUTestConfig::IsValid() const {
[email protected]b4ede6602013-05-15 16:46:55118 if (!validate_gpu_info_)
119 return true;
[email protected]1a6ad5f2012-01-25 04:29:58120 if (gpu_device_id_ != 0 && (gpu_vendor_.size() != 1 || gpu_vendor_[0] == 0))
121 return false;
122 return true;
123}
124
125bool GPUTestConfig::OverlapsWith(const GPUTestConfig& config) const {
126 DCHECK(IsValid());
127 DCHECK(config.IsValid());
128 if (config.os_ != kOsUnknown && os_ != kOsUnknown &&
129 (os_ & config.os_) == 0)
130 return false;
131 if (config.gpu_vendor_.size() > 0 && gpu_vendor_.size() > 0) {
132 bool shared = false;
133 for (size_t i = 0; i < config.gpu_vendor_.size() && !shared; ++i) {
134 for (size_t j = 0; j < gpu_vendor_.size(); ++j) {
135 if (config.gpu_vendor_[i] == gpu_vendor_[j]) {
136 shared = true;
137 break;
138 }
139 }
140 }
141 if (!shared)
142 return false;
143 }
144 if (config.gpu_device_id_ != 0 && gpu_device_id_ != 0 &&
145 gpu_device_id_ != config.gpu_device_id_)
146 return false;
147 if (config.build_type_ != kBuildTypeUnknown &&
148 build_type_ != kBuildTypeUnknown &&
149 (build_type_ & config.build_type_) == 0)
150 return false;
151 return true;
152}
153
[email protected]b4ede6602013-05-15 16:46:55154void GPUTestConfig::DisableGPUInfoValidation() {
155 validate_gpu_info_ = false;
156}
157
[email protected]1a6ad5f2012-01-25 04:29:58158void GPUTestConfig::ClearGPUVendor() {
159 gpu_vendor_.clear();
160}
161
162GPUTestBotConfig::~GPUTestBotConfig() {
163}
164
avif15d60a2015-12-21 17:06:33165void GPUTestBotConfig::AddGPUVendor(uint32_t gpu_vendor) {
[email protected]1a6ad5f2012-01-25 04:29:58166 DCHECK_EQ(0u, GPUTestConfig::gpu_vendor().size());
167 GPUTestConfig::AddGPUVendor(gpu_vendor);
168}
169
[email protected]129f019e2013-05-28 23:38:02170bool GPUTestBotConfig::SetGPUInfo(const GPUInfo& gpu_info) {
[email protected]b4ede6602013-05-15 16:46:55171 DCHECK(validate_gpu_info_);
[email protected]a094e2c2012-05-10 23:02:42172 if (gpu_info.gpu.device_id == 0 || gpu_info.gpu.vendor_id == 0)
[email protected]1a6ad5f2012-01-25 04:29:58173 return false;
174 ClearGPUVendor();
[email protected]a094e2c2012-05-10 23:02:42175 AddGPUVendor(gpu_info.gpu.vendor_id);
176 set_gpu_device_id(gpu_info.gpu.device_id);
[email protected]1a6ad5f2012-01-25 04:29:58177 return true;
178}
179
180bool GPUTestBotConfig::IsValid() const {
181 switch (os()) {
182 case kOsWinXP:
183 case kOsWinVista:
184 case kOsWin7:
[email protected]c9fc22f2012-11-16 23:39:56185 case kOsWin8:
wfh0355eead2015-07-22 04:15:00186 case kOsWin10:
[email protected]1a6ad5f2012-01-25 04:29:58187 case kOsMacLeopard:
188 case kOsMacSnowLeopard:
189 case kOsMacLion:
[email protected]c9fc22f2012-11-16 23:39:56190 case kOsMacMountainLion:
[email protected]710089b92014-02-04 01:16:09191 case kOsMacMavericks:
iceman3197ce82015-04-15 11:02:32192 case kOsMacYosemite:
bajones019b3c802015-11-18 19:36:58193 case kOsMacElCapitan:
erikchenaf3ffdd22016-07-21 22:34:56194 case kOsMacSierra:
[email protected]1a6ad5f2012-01-25 04:29:58195 case kOsLinux:
196 case kOsChromeOS:
[email protected]67d96b62012-07-24 03:38:25197 case kOsAndroid:
[email protected]1a6ad5f2012-01-25 04:29:58198 break;
199 default:
200 return false;
201 }
[email protected]b4ede6602013-05-15 16:46:55202 if (validate_gpu_info_) {
203 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0)
204 return false;
205 if (gpu_device_id() == 0)
206 return false;
207 }
[email protected]1a6ad5f2012-01-25 04:29:58208 switch (build_type()) {
209 case kBuildTypeRelease:
210 case kBuildTypeDebug:
211 break;
212 default:
213 return false;
214 }
215 return true;
216}
217
218bool GPUTestBotConfig::Matches(const GPUTestConfig& config) const {
219 DCHECK(IsValid());
220 DCHECK(config.IsValid());
221 if (config.os() != kOsUnknown && (os() & config.os()) == 0)
222 return false;
223 if (config.gpu_vendor().size() > 0) {
224 bool contained = false;
225 for (size_t i = 0; i < config.gpu_vendor().size(); ++i) {
226 if (config.gpu_vendor()[i] == gpu_vendor()[0]) {
227 contained = true;
228 break;
229 }
230 }
231 if (!contained)
232 return false;
233 }
234 if (config.gpu_device_id() != 0 &&
235 gpu_device_id() != config.gpu_device_id())
236 return false;
237 if (config.build_type() != kBuildTypeUnknown &&
238 (build_type() & config.build_type()) == 0)
239 return false;
jmadill073a3232015-07-22 21:10:52240 if (config.api() != 0 && (api() & config.api()) == 0)
241 return false;
[email protected]1a6ad5f2012-01-25 04:29:58242 return true;
243}
244
[email protected]830631c2012-06-13 05:06:08245bool GPUTestBotConfig::Matches(const std::string& config_data) const {
246 GPUTestExpectationsParser parser;
247 GPUTestConfig config;
248
249 if (!parser.ParseConfig(config_data, &config))
250 return false;
251 return Matches(config);
252}
253
[email protected]129f019e2013-05-28 23:38:02254bool GPUTestBotConfig::LoadCurrentConfig(const GPUInfo* gpu_info) {
[email protected]b0186392012-01-28 02:12:14255 bool rt;
256 if (gpu_info == NULL) {
[email protected]129f019e2013-05-28 23:38:02257 GPUInfo my_gpu_info;
zmo84eae5e2014-09-05 01:36:23258 CollectInfoResult result = CollectGpuID(
259 &my_gpu_info.gpu.vendor_id, &my_gpu_info.gpu.device_id);
260 if (result != kCollectInfoSuccess) {
[email protected]4e503202014-05-23 11:08:53261 LOG(ERROR) << "Fail to identify GPU";
[email protected]b4ede6602013-05-15 16:46:55262 DisableGPUInfoValidation();
263 rt = true;
264 } else {
265 rt = SetGPUInfo(my_gpu_info);
266 }
[email protected]b0186392012-01-28 02:12:14267 } else {
268 rt = SetGPUInfo(*gpu_info);
269 }
[email protected]1a6ad5f2012-01-25 04:29:58270 set_os(GetCurrentOS());
[email protected]4e503202014-05-23 11:08:53271 if (os() == kOsUnknown) {
272 LOG(ERROR) << "Unknown OS";
[email protected]1a6ad5f2012-01-25 04:29:58273 rt = false;
[email protected]4e503202014-05-23 11:08:53274 }
[email protected]1a6ad5f2012-01-25 04:29:58275#if defined(NDEBUG)
276 set_build_type(kBuildTypeRelease);
277#else
278 set_build_type(kBuildTypeDebug);
279#endif
280 return rt;
281}
282
[email protected]830631c2012-06-13 05:06:08283// static
284bool GPUTestBotConfig::CurrentConfigMatches(const std::string& config_data) {
285 GPUTestBotConfig my_config;
286 if (!my_config.LoadCurrentConfig(NULL))
287 return false;
288 return my_config.Matches(config_data);
289}
290
291// static
292bool GPUTestBotConfig::CurrentConfigMatches(
293 const std::vector<std::string>& configs) {
294 GPUTestBotConfig my_config;
295 if (!my_config.LoadCurrentConfig(NULL))
296 return false;
297 for (size_t i = 0 ; i < configs.size(); ++i) {
298 if (my_config.Matches(configs[i]))
299 return true;
300 }
301 return false;
302}
303
[email protected]f5b7f6e2013-12-10 13:57:32304// static
305bool GPUTestBotConfig::GpuBlacklistedOnBot() {
thakis114a1ef2016-04-26 16:02:59306#if defined(OS_WIN)
[email protected]3b886f42014-01-10 03:50:05307 // Blacklist rule #79 disables all Gpu acceleration before Windows 7.
308 if (base::win::GetVersion() <= base::win::VERSION_VISTA) {
309 return true;
310 }
[email protected]f5b7f6e2013-12-10 13:57:32311#endif
[email protected]f5b7f6e2013-12-10 13:57:32312 return false;
313}
314
[email protected]129f019e2013-05-28 23:38:02315} // namespace gpu
316