[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 1 | // 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] | 129f019e | 2013-05-28 23:38:02 | [diff] [blame] | 5 | #include "gpu/config/gpu_test_config.h" |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 6 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 10 | #include "base/logging.h" |
| 11 | #include "base/sys_info.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 12 | #include "gpu/config/gpu_info.h" |
| 13 | #include "gpu/config/gpu_info_collector.h" |
[email protected] | 129f019e | 2013-05-28 23:38:02 | [diff] [blame] | 14 | #include "gpu/config/gpu_test_expectations_parser.h" |
| 15 | |
thakis | 114a1ef | 2016-04-26 16:02:59 | [diff] [blame] | 16 | #if defined(OS_WIN) |
[email protected] | 3b886f4 | 2014-01-10 03:50:05 | [diff] [blame] | 17 | #include "base/win/windows_version.h" |
[email protected] | f5b7f6e | 2013-12-10 13:57:32 | [diff] [blame] | 18 | #endif |
| 19 | |
[email protected] | 129f019e | 2013-05-28 23:38:02 | [diff] [blame] | 20 | namespace gpu { |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 21 | |
| 22 | namespace { |
| 23 | |
| 24 | GPUTestConfig::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) |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 30 | int32_t major_version = 0; |
| 31 | int32_t minor_version = 0; |
| 32 | int32_t bugfix_version = 0; |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 33 | 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] | 4e50320 | 2014-05-23 11:08:53 | [diff] [blame] | 41 | if (major_version == 6 && (minor_version == 2 || minor_version == 3)) |
[email protected] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 42 | return GPUTestConfig::kOsWin8; |
wfh | 0355eead | 2015-07-22 04:15:00 | [diff] [blame] | 43 | if (major_version == 10) |
| 44 | return GPUTestConfig::kOsWin10; |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 45 | #elif defined(OS_MACOSX) |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 46 | int32_t major_version = 0; |
| 47 | int32_t minor_version = 0; |
| 48 | int32_t bugfix_version = 0; |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 49 | 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] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 59 | case 8: |
| 60 | return GPUTestConfig::kOsMacMountainLion; |
[email protected] | 710089b9 | 2014-02-04 01:16:09 | [diff] [blame] | 61 | case 9: |
| 62 | return GPUTestConfig::kOsMacMavericks; |
iceman | 3197ce8 | 2015-04-15 11:02:32 | [diff] [blame] | 63 | case 10: |
| 64 | return GPUTestConfig::kOsMacYosemite; |
bajones | 019b3c80 | 2015-11-18 19:36:58 | [diff] [blame] | 65 | case 11: |
| 66 | return GPUTestConfig::kOsMacElCapitan; |
erikchen | af3ffdd2 | 2016-07-21 22:34:56 | [diff] [blame] | 67 | case 12: |
| 68 | return GPUTestConfig::kOsMacSierra; |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 69 | } |
| 70 | } |
[email protected] | 67d96b6 | 2012-07-24 03:38:25 | [diff] [blame] | 71 | #elif defined(OS_ANDROID) |
| 72 | return GPUTestConfig::kOsAndroid; |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 73 | #endif |
| 74 | return GPUTestConfig::kOsUnknown; |
| 75 | } |
| 76 | |
| 77 | } // namespace anonymous |
| 78 | |
| 79 | GPUTestConfig::GPUTestConfig() |
[email protected] | b4ede660 | 2013-05-15 16:46:55 | [diff] [blame] | 80 | : validate_gpu_info_(true), |
| 81 | os_(kOsUnknown), |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 82 | gpu_device_id_(0), |
jmadill | 073a323 | 2015-07-22 21:10:52 | [diff] [blame] | 83 | build_type_(kBuildTypeUnknown), |
| 84 | api_(kAPIUnknown) {} |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 85 | |
vmpstr | 3b7b8b2 | 2016-03-01 23:00:20 | [diff] [blame] | 86 | GPUTestConfig::GPUTestConfig(const GPUTestConfig& other) = default; |
| 87 | |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 88 | GPUTestConfig::~GPUTestConfig() { |
| 89 | } |
| 90 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 91 | void GPUTestConfig::set_os(int32_t os) { |
[email protected] | 67d96b6 | 2012-07-24 03:38:25 | [diff] [blame] | 92 | DCHECK_EQ(0, os & ~(kOsAndroid | kOsWin | kOsMac | kOsLinux | kOsChromeOS)); |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 93 | os_ = os; |
| 94 | } |
| 95 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 96 | void GPUTestConfig::AddGPUVendor(uint32_t gpu_vendor) { |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 97 | 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 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 103 | void GPUTestConfig::set_gpu_device_id(uint32_t id) { |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 104 | gpu_device_id_ = id; |
| 105 | } |
| 106 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 107 | void GPUTestConfig::set_build_type(int32_t build_type) { |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 108 | DCHECK_EQ(0, build_type & ~(kBuildTypeRelease | kBuildTypeDebug)); |
| 109 | build_type_ = build_type; |
| 110 | } |
| 111 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 112 | void GPUTestConfig::set_api(int32_t api) { |
jmadill | 073a323 | 2015-07-22 21:10:52 | [diff] [blame] | 113 | DCHECK_EQ(0, api & ~(kAPID3D9 | kAPID3D11 | kAPIGLDesktop | kAPIGLES)); |
| 114 | api_ = api; |
| 115 | } |
| 116 | |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 117 | bool GPUTestConfig::IsValid() const { |
[email protected] | b4ede660 | 2013-05-15 16:46:55 | [diff] [blame] | 118 | if (!validate_gpu_info_) |
| 119 | return true; |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 120 | if (gpu_device_id_ != 0 && (gpu_vendor_.size() != 1 || gpu_vendor_[0] == 0)) |
| 121 | return false; |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | bool 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] | b4ede660 | 2013-05-15 16:46:55 | [diff] [blame] | 154 | void GPUTestConfig::DisableGPUInfoValidation() { |
| 155 | validate_gpu_info_ = false; |
| 156 | } |
| 157 | |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 158 | void GPUTestConfig::ClearGPUVendor() { |
| 159 | gpu_vendor_.clear(); |
| 160 | } |
| 161 | |
| 162 | GPUTestBotConfig::~GPUTestBotConfig() { |
| 163 | } |
| 164 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 165 | void GPUTestBotConfig::AddGPUVendor(uint32_t gpu_vendor) { |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 166 | DCHECK_EQ(0u, GPUTestConfig::gpu_vendor().size()); |
| 167 | GPUTestConfig::AddGPUVendor(gpu_vendor); |
| 168 | } |
| 169 | |
[email protected] | 129f019e | 2013-05-28 23:38:02 | [diff] [blame] | 170 | bool GPUTestBotConfig::SetGPUInfo(const GPUInfo& gpu_info) { |
[email protected] | b4ede660 | 2013-05-15 16:46:55 | [diff] [blame] | 171 | DCHECK(validate_gpu_info_); |
[email protected] | a094e2c | 2012-05-10 23:02:42 | [diff] [blame] | 172 | if (gpu_info.gpu.device_id == 0 || gpu_info.gpu.vendor_id == 0) |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 173 | return false; |
| 174 | ClearGPUVendor(); |
[email protected] | a094e2c | 2012-05-10 23:02:42 | [diff] [blame] | 175 | AddGPUVendor(gpu_info.gpu.vendor_id); |
| 176 | set_gpu_device_id(gpu_info.gpu.device_id); |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 177 | return true; |
| 178 | } |
| 179 | |
| 180 | bool GPUTestBotConfig::IsValid() const { |
| 181 | switch (os()) { |
| 182 | case kOsWinXP: |
| 183 | case kOsWinVista: |
| 184 | case kOsWin7: |
[email protected] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 185 | case kOsWin8: |
wfh | 0355eead | 2015-07-22 04:15:00 | [diff] [blame] | 186 | case kOsWin10: |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 187 | case kOsMacLeopard: |
| 188 | case kOsMacSnowLeopard: |
| 189 | case kOsMacLion: |
[email protected] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 190 | case kOsMacMountainLion: |
[email protected] | 710089b9 | 2014-02-04 01:16:09 | [diff] [blame] | 191 | case kOsMacMavericks: |
iceman | 3197ce8 | 2015-04-15 11:02:32 | [diff] [blame] | 192 | case kOsMacYosemite: |
bajones | 019b3c80 | 2015-11-18 19:36:58 | [diff] [blame] | 193 | case kOsMacElCapitan: |
erikchen | af3ffdd2 | 2016-07-21 22:34:56 | [diff] [blame] | 194 | case kOsMacSierra: |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 195 | case kOsLinux: |
| 196 | case kOsChromeOS: |
[email protected] | 67d96b6 | 2012-07-24 03:38:25 | [diff] [blame] | 197 | case kOsAndroid: |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 198 | break; |
| 199 | default: |
| 200 | return false; |
| 201 | } |
[email protected] | b4ede660 | 2013-05-15 16:46:55 | [diff] [blame] | 202 | 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] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 208 | switch (build_type()) { |
| 209 | case kBuildTypeRelease: |
| 210 | case kBuildTypeDebug: |
| 211 | break; |
| 212 | default: |
| 213 | return false; |
| 214 | } |
| 215 | return true; |
| 216 | } |
| 217 | |
| 218 | bool 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; |
jmadill | 073a323 | 2015-07-22 21:10:52 | [diff] [blame] | 240 | if (config.api() != 0 && (api() & config.api()) == 0) |
| 241 | return false; |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 242 | return true; |
| 243 | } |
| 244 | |
[email protected] | 830631c | 2012-06-13 05:06:08 | [diff] [blame] | 245 | bool 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] | 129f019e | 2013-05-28 23:38:02 | [diff] [blame] | 254 | bool GPUTestBotConfig::LoadCurrentConfig(const GPUInfo* gpu_info) { |
[email protected] | b018639 | 2012-01-28 02:12:14 | [diff] [blame] | 255 | bool rt; |
| 256 | if (gpu_info == NULL) { |
[email protected] | 129f019e | 2013-05-28 23:38:02 | [diff] [blame] | 257 | GPUInfo my_gpu_info; |
zmo | 84eae5e | 2014-09-05 01:36:23 | [diff] [blame] | 258 | CollectInfoResult result = CollectGpuID( |
| 259 | &my_gpu_info.gpu.vendor_id, &my_gpu_info.gpu.device_id); |
| 260 | if (result != kCollectInfoSuccess) { |
[email protected] | 4e50320 | 2014-05-23 11:08:53 | [diff] [blame] | 261 | LOG(ERROR) << "Fail to identify GPU"; |
[email protected] | b4ede660 | 2013-05-15 16:46:55 | [diff] [blame] | 262 | DisableGPUInfoValidation(); |
| 263 | rt = true; |
| 264 | } else { |
| 265 | rt = SetGPUInfo(my_gpu_info); |
| 266 | } |
[email protected] | b018639 | 2012-01-28 02:12:14 | [diff] [blame] | 267 | } else { |
| 268 | rt = SetGPUInfo(*gpu_info); |
| 269 | } |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 270 | set_os(GetCurrentOS()); |
[email protected] | 4e50320 | 2014-05-23 11:08:53 | [diff] [blame] | 271 | if (os() == kOsUnknown) { |
| 272 | LOG(ERROR) << "Unknown OS"; |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 273 | rt = false; |
[email protected] | 4e50320 | 2014-05-23 11:08:53 | [diff] [blame] | 274 | } |
[email protected] | 1a6ad5f | 2012-01-25 04:29:58 | [diff] [blame] | 275 | #if defined(NDEBUG) |
| 276 | set_build_type(kBuildTypeRelease); |
| 277 | #else |
| 278 | set_build_type(kBuildTypeDebug); |
| 279 | #endif |
| 280 | return rt; |
| 281 | } |
| 282 | |
[email protected] | 830631c | 2012-06-13 05:06:08 | [diff] [blame] | 283 | // static |
| 284 | bool 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 |
| 292 | bool 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] | f5b7f6e | 2013-12-10 13:57:32 | [diff] [blame] | 304 | // static |
| 305 | bool GPUTestBotConfig::GpuBlacklistedOnBot() { |
thakis | 114a1ef | 2016-04-26 16:02:59 | [diff] [blame] | 306 | #if defined(OS_WIN) |
[email protected] | 3b886f4 | 2014-01-10 03:50:05 | [diff] [blame] | 307 | // 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] | f5b7f6e | 2013-12-10 13:57:32 | [diff] [blame] | 311 | #endif |
[email protected] | f5b7f6e | 2013-12-10 13:57:32 | [diff] [blame] | 312 | return false; |
| 313 | } |
| 314 | |
[email protected] | 129f019e | 2013-05-28 23:38:02 | [diff] [blame] | 315 | } // namespace gpu |
| 316 | |