1 // Copyright 2020 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #pragma once 15 16 #include "aemu/base/Compiler.h" 17 18 #include <stdbool.h> 19 #include <stdio.h> 20 #include <stdlib.h> 21 #include <string> 22 #include <string.h> 23 #include <vector> 24 25 // gpuinfo is designed to collect information about the GPUs 26 // installed on the host system for the purposes of 27 // automatically determining which renderer to select, 28 // in the cases where the GPU drivers are known to have issues 29 // running the emulator. 30 31 // The main entry points: 32 33 // host_gpu_blacklisted_async() does the two steps above, 34 // but on a different thread, with a timeout in case 35 // the started processes hang or what not. 36 void async_query_host_gpu_start(); 37 bool async_query_host_gpu_blacklisted(); 38 bool async_query_host_gpu_AngleWhitelisted(); 39 bool async_query_host_gpu_SyncBlacklisted(); 40 bool async_query_host_gpu_VulkanBlacklisted(); 41 42 // Below is the implementation. 43 44 struct GpuInfoView{ 45 const char* make; 46 const char* model; 47 const char* device_id; 48 const char* revision_id; 49 const char* version; 50 const char* renderer; 51 const char* os; 52 }; 53 // We keep a blacklist of known crashy GPU drivers 54 // as a static const list with items of this type: 55 using BlacklistEntry = GpuInfoView; 56 // We keep a whitelist to use Angle for buggy 57 // GPU drivers 58 using WhitelistEntry = GpuInfoView; 59 60 // GpuInfo/GpuInfoList are the representation of parsed information 61 // about the system's GPU.s 62 class GpuInfo { 63 public: GpuInfo()64 GpuInfo() : current_gpu(false) { } GpuInfo(const std::string & _make,const std::string & _model,const std::string & _device_id,const std::string & _revision_id,const std::string & _version,const std::string & _renderer)65 GpuInfo(const std::string& _make, 66 const std::string& _model, 67 const std::string& _device_id, 68 const std::string& _revision_id, 69 const std::string& _version, 70 const std::string& _renderer) : 71 current_gpu(false), 72 make(_make), 73 model(_model), 74 device_id(_device_id), 75 revision_id(_revision_id), 76 version(_version), 77 renderer(_renderer) { } 78 79 bool current_gpu; 80 81 void addDll(std::string dll_str); 82 83 std::string make; 84 std::string model; 85 std::string device_id; 86 std::string revision_id; 87 std::string version; 88 std::string renderer; 89 90 std::vector<std::string> dlls; 91 std::string os; 92 }; 93 94 class GpuInfoList { 95 public: 96 GpuInfoList() = default; 97 void addGpu(); 98 GpuInfo& currGpu(); 99 std::string dump() const; 100 void clear(); 101 102 std::vector<GpuInfo> infos; 103 104 bool blacklist_status = false; 105 bool Anglelist_status = false; 106 bool SyncBlacklist_status = false; 107 bool VulkanBlacklist_status = false; 108 109 DISALLOW_COPY_ASSIGN_AND_MOVE(GpuInfoList); 110 }; 111 112 // Below are helper functions that can be useful in various 113 // contexts (e.g., unit testing). 114 115 // gpuinfo_query_blacklist(): 116 // Function to query a given blacklist of GPU's. 117 // The blacklist |list| (of length |size|) attempts 118 // to match all non-NULL entry fields exactly against 119 // info of all GPU's in |gpulist|. If there is any match, 120 // the host system is considered on the blacklist. 121 // (Null blacklist entry fields are ignored and 122 // essentially act as wildcards). 123 bool gpuinfo_query_blacklist(GpuInfoList* gpulist, 124 const BlacklistEntry* list, 125 int size); 126 127 // Platform-specific information parsing functions. 128 void parse_gpu_info_list_linux(const std::string& contents, GpuInfoList* gpulist); 129 void parse_gpu_info_list_windows(const std::string& contents, GpuInfoList* gpulist); 130 131 // If we actually switched to software, call this. 132 void setGpuBlacklistStatus(bool switchedToSoftware); 133 134 // Return a fully loaded global GPU info list. 135 const GpuInfoList& globalGpuInfoList(); 136