1 // 2 // Copyright 2022 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // system_info_util.h: 7 // Implementation of common test utilities for operating with SystemInfo. 8 // 9 10 #include "system_info_util.h" 11 12 #include "common/debug.h" 13 #include "common/string_utils.h" 14 #include "gpu_info_util/SystemInfo.h" 15 #include "util/util_gl.h" 16 17 using namespace angle; 18 19 namespace 20 { 21 findGPU(const SystemInfo & systemInfo,bool lowPower)22size_t findGPU(const SystemInfo &systemInfo, bool lowPower) 23 { 24 if (systemInfo.gpus.size() < 2) 25 { 26 return 0; 27 } 28 for (size_t i = 0; i < systemInfo.gpus.size(); ++i) 29 { 30 if (lowPower && IsIntel(systemInfo.gpus[i].vendorId)) 31 { 32 return i; 33 } 34 // Return the high power GPU, i.e any non-intel GPU 35 else if (!lowPower && !IsIntel(systemInfo.gpus[i].vendorId)) 36 { 37 return i; 38 } 39 } 40 // Can't find GPU 41 ASSERT(false); 42 return 0; 43 } 44 45 } // namespace 46 FindLowPowerGPU(const SystemInfo & systemInfo)47size_t FindLowPowerGPU(const SystemInfo &systemInfo) 48 { 49 return findGPU(systemInfo, true); 50 } 51 FindHighPowerGPU(const SystemInfo & systemInfo)52size_t FindHighPowerGPU(const SystemInfo &systemInfo) 53 { 54 return findGPU(systemInfo, false); 55 } 56 FindActiveOpenGLGPU(const SystemInfo & systemInfo)57size_t FindActiveOpenGLGPU(const SystemInfo &systemInfo) 58 { 59 char *renderer = (char *)glGetString(GL_RENDERER); 60 std::string rendererString(renderer); 61 for (size_t i = 0; i < systemInfo.gpus.size(); ++i) 62 { 63 std::vector<std::string> vendorTokens; 64 angle::SplitStringAlongWhitespace(VendorName(systemInfo.gpus[i].vendorId), &vendorTokens); 65 for (std::string &token : vendorTokens) 66 { 67 if (rendererString.find(token) != std::string::npos) 68 { 69 return i; 70 } 71 } 72 } 73 // Can't find active GPU 74 ASSERT(false); 75 return 0; 76 } 77